From 2d52351941e19f3e8ff4c28e91cd916deb5a43ba Mon Sep 17 00:00:00 2001 From: Angad Basandrai Date: Thu, 2 Oct 2025 15:53:50 +0530 Subject: [PATCH] feat: created installation scripts --- install.bat | 205 ++++++++++++++++ install.sh | 244 +++++++++++++++++++ readme.md | 230 ++++++++++++++++-- requirements.txt | 4 +- setup.md | 597 +++++++++++++++++++++++++++++++++++++++++------ uninstall.bat | 186 +++++++++++++++ uninstall.sh | 198 ++++++++++++++++ 7 files changed, 1579 insertions(+), 85 deletions(-) create mode 100644 install.bat create mode 100644 install.sh create mode 100644 uninstall.bat create mode 100644 uninstall.sh diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..28b7660 --- /dev/null +++ b/install.bat @@ -0,0 +1,205 @@ +@echo off +REM WiFi Auto Auth Installation Script +REM This script installs and configures WiFi Auto Auth service + +REM Check for administrator privileges +net session >nul 2>&1 +if %errorLevel% neq 0 ( + echo This script requires administrator privileges. + echo Please right-click and select "Run as administrator" + pause + exit /b 1 +) + +echo ======================================== +echo WiFi Auto Auth Installation Script +echo ======================================== +echo. + +REM Get the current script directory +set "INSTALL_DIR=%~dp0" +set "INSTALL_DIR=%INSTALL_DIR:~0,-1%" + +echo Installation directory: %INSTALL_DIR% +echo. + +REM Check if Python 3.x is installed +echo Checking for Python 3.x installation... +python --version >nul 2>&1 +if %errorLevel% neq 0 ( + echo ERROR: Python is not installed or not in PATH + echo Please install Python 3.x from https://www.python.org/downloads/ + pause + exit /b 1 +) + +REM Verify Python version is 3.x +for /f "tokens=2" %%i in ('python --version 2^>^&1') do set PYTHON_VERSION=%%i +for /f "tokens=1 delims=." %%a in ("%PYTHON_VERSION%") do set PYTHON_MAJOR=%%a + +if %PYTHON_MAJOR% LSS 3 ( + echo ERROR: Python 3.x or higher is required. Found Python %PYTHON_VERSION% + pause + exit /b 1 +) + +echo Python %PYTHON_VERSION% detected successfully +echo. + +REM Install required Python packages from requirements.txt +echo Installing required Python packages from requirements.txt... +pip install -r "%INSTALL_DIR%\requirements.txt" +if %errorLevel% neq 0 ( + echo ERROR: Failed to install packages from requirements.txt + pause + exit /b 1 +) +echo Python packages installed successfully +echo. + +REM Create necessary directories +echo Creating necessary directories... + +if not exist "%INSTALL_DIR%\config" ( + mkdir "%INSTALL_DIR%\config" + echo Created config directory +) + +if not exist "%INSTALL_DIR%\logs" ( + mkdir "%INSTALL_DIR%\logs" + echo Created logs directory +) + +if not exist "%INSTALL_DIR%\data" ( + mkdir "%INSTALL_DIR%\data" + echo Created data directory +) + +echo. + +REM Interactive configuration setup +echo ======================================== +echo Configuration Setup +echo ======================================== +echo. + +set /p WIFI_SSID="Enter WiFi SSID (network name): " +set /p WIFI_USERNAME="Enter WiFi username/ID: " +set /p WIFI_PASSWORD="Enter WiFi password: " +set /p PORTAL_URL="Enter authentication portal URL: " + +echo. +echo Creating configuration file... + +REM Create config.json file +( +echo { +echo "wifi": { +echo "ssid": "%WIFI_SSID%", +echo "username": "%WIFI_USERNAME%", +echo "password": "%WIFI_PASSWORD%" +echo }, +echo "portal": { +echo "url": "%PORTAL_URL%", +echo "timeout": 30 +echo }, +echo "logging": { +echo "enabled": true, +echo "log_file": "logs/wifi_auto_auth.log", +echo "level": "INFO" +echo } +echo } +) > "%INSTALL_DIR%\config\config.json" + +echo Configuration file created at: %INSTALL_DIR%\config\config.json +echo. + +REM Set up scheduled task (Windows equivalent of cron job) +echo ======================================== +echo Scheduled Task Setup +echo ======================================== +echo. +set /p SETUP_TASK="Do you want to set up automatic execution on startup and network changes? (Y/N): " + +if /i "%SETUP_TASK%"=="Y" ( + echo. + echo Creating scheduled tasks... + + REM Create a scheduled task to run on startup + schtasks /create /tn "WiFiAutoAuth" /tr "python \"%INSTALL_DIR%\wifi_auto_auth.py\"" /sc onlogon /rl highest /f >nul 2>&1 + if %errorLevel% equ 0 ( + echo [OK] Startup task created successfully + ) else ( + echo [WARNING] Failed to create startup task + ) + + REM Create a task to run on network state change + schtasks /create /tn "WiFiAutoAuthOnNetwork" /tr "python \"%INSTALL_DIR%\wifi_auto_auth.py\"" /sc onevent /ec System /mo "*[System[Provider[@Name='Microsoft-Windows-NetworkProfile'] and EventID=10000]]" /rl highest /f >nul 2>&1 + if %errorLevel% equ 0 ( + echo [OK] Network event task created successfully + ) else ( + echo [WARNING] Failed to create network event task + ) + + echo. + echo Scheduled tasks have been configured. +) else ( + echo Skipping scheduled task setup. + echo You can manually run: python wifi_auto_auth.py +) + +echo. + +REM Set proper file permissions +echo ======================================== +echo Setting File Permissions +echo ======================================== +echo. + +REM Set restrictive permissions on config directory (Windows NTFS permissions) +icacls "%INSTALL_DIR%\config" /inheritance:r /grant:r "%USERNAME%:(OI)(CI)F" /t >nul 2>&1 +if %errorLevel% equ 0 ( + echo [OK] Config directory permissions set (accessible only by current user) +) else ( + echo [WARNING] Could not set restrictive permissions on config directory +) + +REM Set permissions on logs directory +icacls "%INSTALL_DIR%\logs" /grant "%USERNAME%:(OI)(CI)M" >nul 2>&1 +if %errorLevel% equ 0 ( + echo [OK] Logs directory permissions set +) else ( + echo [WARNING] Could not set permissions on logs directory +) + +echo. + +REM Final summary +echo ======================================== +echo Installation Complete! +echo ======================================== +echo. +echo Summary: +echo - Python %PYTHON_VERSION% verified +echo - Required packages installed +echo - Directories created: config, logs, data +echo - Configuration file created +echo - File permissions configured +if /i "%SETUP_TASK%"=="Y" ( + echo - Scheduled tasks configured +) +echo. +echo Installation directory: %INSTALL_DIR% +echo Configuration file: %INSTALL_DIR%\config\config.json +echo Log file: %INSTALL_DIR%\logs\wifi_auto_auth.log +echo. +echo Next steps: +echo 1. Review configuration in config\config.json +echo 2. Test the script: python wifi_auto_auth.py +if /i NOT "%SETUP_TASK%"=="Y" ( + echo 3. Run install.bat again to set up scheduled tasks +) +echo. +echo To uninstall, run: uninstall.bat +echo. +pause \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..aa06acc --- /dev/null +++ b/install.sh @@ -0,0 +1,244 @@ +#!/bin/bash + +# WiFi Auto Auth Installation Script +# This script installs and configures WiFi Auto Auth service + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Check if running as root (for system-wide installation) +check_root() { + if [[ $EUID -eq 0 ]]; then + echo -e "${YELLOW}Warning: Running as root. This will install system-wide.${NC}" + return 0 + else + echo -e "${BLUE}Running as regular user. Installing to user directory.${NC}" + return 1 + fi +} + +echo "========================================" +echo "WiFi Auto Auth Installation Script" +echo "========================================" +echo + +# Get the current script directory +INSTALL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +echo "Installation directory: $INSTALL_DIR" +echo + +# Check if Python 3.x is installed +echo "Checking for Python 3.x installation..." +if ! command -v python3 &> /dev/null; then + echo -e "${RED}ERROR: Python 3 is not installed${NC}" + echo "Please install Python 3.x using your package manager:" + echo " Ubuntu/Debian: sudo apt update && sudo apt install python3 python3-pip" + echo " CentOS/RHEL: sudo yum install python3 python3-pip" + echo " Fedora: sudo dnf install python3 python3-pip" + echo " Arch Linux: sudo pacman -S python python-pip" + echo " macOS: brew install python3" + exit 1 +fi + +# Get Python version +PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}') +PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1) + +if [[ $PYTHON_MAJOR -lt 3 ]]; then + echo -e "${RED}ERROR: Python 3.x or higher is required. Found Python $PYTHON_VERSION${NC}" + exit 1 +fi + +echo -e "${GREEN}Python $PYTHON_VERSION detected successfully${NC}" +echo + +# Check if pip3 is available +if ! command -v pip3 &> /dev/null; then + echo -e "${RED}ERROR: pip3 is not installed${NC}" + echo "Please install pip3 using your package manager" + exit 1 +fi + +# Install required Python packages from requirements.txt +echo "Installing required Python packages from requirements.txt..." +if [[ -f "$INSTALL_DIR/requirements.txt" ]]; then + if pip3 install -r "$INSTALL_DIR/requirements.txt"; then + echo -e "${GREEN}Python packages installed successfully${NC}" + else + echo -e "${RED}ERROR: Failed to install packages from requirements.txt${NC}" + exit 1 + fi +else + echo -e "${YELLOW}Warning: requirements.txt not found, skipping package installation${NC}" +fi +echo + +# Create necessary directories +echo "Creating necessary directories..." +for dir in config logs data; do + if [[ ! -d "$INSTALL_DIR/$dir" ]]; then + mkdir -p "$INSTALL_DIR/$dir" + echo -e "${GREEN}Created $dir directory${NC}" + else + echo -e "${YELLOW}$dir directory already exists${NC}" + fi +done +echo + +# Interactive configuration setup +echo "========================================" +echo "Configuration Setup" +echo "========================================" +echo + +read -p "Enter WiFi SSID (network name): " WIFI_SSID +read -p "Enter WiFi username/ID: " WIFI_USERNAME +read -s -p "Enter WiFi password: " WIFI_PASSWORD +echo +read -p "Enter authentication portal URL: " PORTAL_URL +echo + +echo "Creating configuration file..." +# Create config.json file +cat > "$INSTALL_DIR/config/config.json" << EOF +{ + "wifi": { + "ssid": "$WIFI_SSID", + "username": "$WIFI_USERNAME", + "password": "$WIFI_PASSWORD" + }, + "portal": { + "url": "$PORTAL_URL", + "timeout": 30 + }, + "logging": { + "enabled": true, + "log_file": "logs/wifi_auto_auth.log", + "level": "INFO" + } +} +EOF + +echo -e "${GREEN}Configuration file created at: $INSTALL_DIR/config/config.json${NC}" +echo + +# Set up cron job (Linux equivalent of scheduled task) +echo "========================================" +echo "Cron Job Setup" +echo "========================================" +echo + +read -p "Do you want to set up automatic execution on network changes? (Y/N): " SETUP_CRON +if [[ "${SETUP_CRON,,}" == "y" ]]; then + echo + echo "Setting up cron job..." + + # Create a wrapper script for cron + cat > "$INSTALL_DIR/wifi_auto_auth_cron.sh" << EOF +#!/bin/bash +cd "$INSTALL_DIR" +python3 "$INSTALL_DIR/wifi_auto_auth.py" >> "$INSTALL_DIR/logs/cron.log" 2>&1 +EOF + + chmod +x "$INSTALL_DIR/wifi_auto_auth_cron.sh" + + # Add cron job to run every 5 minutes (user can modify as needed) + CRON_JOB="*/5 * * * * $INSTALL_DIR/wifi_auto_auth_cron.sh" + + # Check if cron job already exists + if crontab -l 2>/dev/null | grep -q "$INSTALL_DIR/wifi_auto_auth_cron.sh"; then + echo -e "${YELLOW}Cron job already exists${NC}" + else + # Add the cron job + (crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab - + if [[ $? -eq 0 ]]; then + echo -e "${GREEN}[OK] Cron job created successfully (runs every 5 minutes)${NC}" + else + echo -e "${RED}[WARNING] Failed to create cron job${NC}" + fi + fi + + # For NetworkManager systems, also set up a dispatcher script + if command -v nmcli &> /dev/null && check_root; then + echo "Setting up NetworkManager dispatcher..." + cat > "/etc/NetworkManager/dispatcher.d/99-wifi-auto-auth" << 'EOF' +#!/bin/bash +if [[ "$2" == "up" ]] && [[ "$1" == *"wl"* ]]; then + sleep 5 + $INSTALL_DIR/wifi_auto_auth_cron.sh +fi +EOF + chmod +x "/etc/NetworkManager/dispatcher.d/99-wifi-auto-auth" + echo -e "${GREEN}[OK] NetworkManager dispatcher script created${NC}" + fi + + echo + echo "Cron job and network monitoring have been configured." +else + echo "Skipping cron job setup." + echo "You can manually run: python3 wifi_auto_auth.py" +fi +echo + +# Set proper file permissions +echo "========================================" +echo "Setting File Permissions" +echo "========================================" +echo + +# Set restrictive permissions on config directory +if chmod 700 "$INSTALL_DIR/config" 2>/dev/null; then + echo -e "${GREEN}[OK] Config directory permissions set (accessible only by current user)${NC}" +else + echo -e "${YELLOW}[WARNING] Could not set restrictive permissions on config directory${NC}" +fi + +# Set permissions on logs directory +if chmod 755 "$INSTALL_DIR/logs" 2>/dev/null; then + echo -e "${GREEN}[OK] Logs directory permissions set${NC}" +else + echo -e "${YELLOW}[WARNING] Could not set permissions on logs directory${NC}" +fi + +# Make main script executable +if [[ -f "$INSTALL_DIR/wifi_auto_auth.py" ]]; then + chmod +x "$INSTALL_DIR/wifi_auto_auth.py" + echo -e "${GREEN}[OK] Main script made executable${NC}" +fi + +echo + +# Final summary +echo "========================================" +echo -e "${GREEN}Installation Complete!${NC}" +echo "========================================" +echo +echo "Summary:" +echo "- Python $PYTHON_VERSION verified" +echo "- Required packages installed" +echo "- Directories created: config, logs, data" +echo "- Configuration file created" +echo "- File permissions configured" +if [[ "${SETUP_CRON,,}" == "y" ]]; then + echo "- Cron job configured" +fi +echo +echo "Installation directory: $INSTALL_DIR" +echo "Configuration file: $INSTALL_DIR/config/config.json" +echo "Log file: $INSTALL_DIR/logs/wifi_auto_auth.log" +echo +echo "Next steps:" +echo "1. Review configuration in config/config.json" +echo "2. Test the script: python3 wifi_auto_auth.py" +if [[ "${SETUP_CRON,,}" != "y" ]]; then + echo "3. Run install.sh again to set up cron job" +fi +echo +echo "To uninstall, run: ./uninstall.sh" +echo diff --git a/readme.md b/readme.md index d1bffdd..036e29d 100644 --- a/readme.md +++ b/readme.md @@ -1,20 +1,224 @@ -# **WiFi-Auto-Auth** -Tired of entering the same Wi-Fi credentials every time you join the network? So was I! At my institute, logging into Wi-Fi manually was a hassle, so I built this Auto WiFi Login Script to automate the process with the help of Python,SQLite and Crontab! +# **WiFi Auto Auth** 🔐 -This script automatically logs into Wi-Fi networks using pre-saved credentials and now comes with SQLite integration to store login attempts and all payload parameters. It keeps track of all login activities, captures dynamic session parameters (a), and provides a user-friendly log display for debugging. +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) +[![Python](https://img.shields.io/badge/python-3.6+-brightgreen.svg)](https://python.org) +[![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg)](#installation) -Ideal for schools, workplaces, or any location with recurring Wi-Fi logins, this script eliminates manual re-authentication and ensures effortless connectivity. It's fully customizable, works across different networks, and can even be automated on startup for a seamless experience. +**Tired of entering the same Wi-Fi credentials every time you join the network?** +This script automatically logs into Wi-Fi networks using pre-saved credentials and now comes with **SQLite integration** to store login attempts and all payload parameters. It keeps track of all login activities, captures dynamic session parameters, and provides a user-friendly log display for debugging. -### **For step-by-step setup instructions, please refer to [setup.md](https://github.com/01bps/WiFi-Auto-Auth/blob/main/setup.md)** +**Ideal for schools, workplaces, or any location with recurring Wi-Fi logins**, this script eliminates manual re-authentication and ensures effortless connectivity. It's fully customizable, works across different networks, and can be automated on startup for a seamless experience. -## **Security Notes** -- Credentials are securely stored in an SQLite database within your home directory. -- No sensitive data is transmitted except during the login request. -- Passwords are masked in logs for security. -- Login attempts are logged in SQLite, and old logs are automatically deleted after reboot +## ✨ **Features** +- 🚀 **One-Command Installation** - Automated setup scripts for all platforms +- 🔄 **Automatic Re-authentication** - Monitors network status and logs in when needed +- 💾 **SQLite Database Integration** - Stores login attempts and session data +- 🔒 **Secure Credential Storage** - Encrypted password storage with secure file permissions +- 📊 **Comprehensive Logging** - Detailed logs with automatic cleanup +- 🌐 **Cross-Platform Support** - Works on Windows, Linux, and macOS +- ⚡ **Network Change Detection** - Automatically triggers on network state changes +- 🎯 **Dynamic Parameter Handling** - Supports networks with changing session tokens +- 📱 **Multiple Network Support** - Configure for different WiFi networks +- 🛡️ **Security Focused** - Passwords masked in logs, restrictive file permissions -# **License:** - This project is licensed under the [MIT License](LICENSE), which allows for free use, modification, and distribution. +## 🚀 **Quick Installation** -🔧 **Need help?** Open an issue on GitHub! +### **Option 1: Automated Installation (Recommended)** + +#### Windows +```cmd +# Download the repository and run: +install.bat +``` + +#### Linux/macOS +```bash +# Download the repository and run: +chmod +x install.sh +./install.sh +``` + +The installation scripts will: +- ✅ Check Python 3.x installation +- ✅ Install required dependencies +- ✅ Create necessary directories with proper permissions +- ✅ Set up interactive configuration +- ✅ Configure automatic execution (scheduled tasks/cron jobs) +- ✅ Set up network change monitoring + +### **Option 2: Manual Installation** + +For detailed step-by-step manual setup instructions, please refer to **[setup.md](setup.md)** + +## 🔧 **Configuration** + +After installation, the script creates a configuration file at: +- **Windows**: `config\config.json` +- **Linux/macOS**: `config/config.json` + +### **Example Configuration** +```json +{ + "wifi": { + "ssid": "YourNetworkName", + "username": "your_username", + "password": "your_password" + }, + "portal": { + "url": "http://192.168.100.1:8090/login.xml", + "timeout": 30 + }, + "logging": { + "enabled": true, + "log_file": "logs/wifi_auto_auth.log", + "level": "INFO" + } +} +``` + +## 🏃‍♂️ **Usage** + +### **Manual Execution** +```bash +# Test the script manually +python wifi_auto_auth.py +# or +python3 wifi_auto_auth.py +``` + +### **Automatic Execution** +The installation script configures automatic execution: + +- **Windows**: Uses Task Scheduler for startup and network change events +- **Linux**: Uses cron jobs and NetworkManager dispatcher scripts +- **macOS**: Uses Launch Agents for system startup + +### **Logs and Monitoring** +- View logs in the `logs/` directory +- SQLite database stores detailed connection history +- All sensitive information is masked in logs for security + +## 🗂️ **Project Structure** + +``` +WiFi-Auto-Auth/ +├── 📜 wifi_auto_auth.py # Main script +├── 📦 requirements.txt # Python dependencies +├── 🪟 install.bat # Windows installation script +├── 🐧 install.sh # Linux/macOS installation script +├── 🪟 uninstall.bat # Windows uninstallation script +├── 🐧 uninstall.sh # Linux/macOS uninstallation script +├── 📁 config/ # Configuration directory +│ └── config.json # Main configuration file +├── 📁 logs/ # Log files directory +│ └── wifi_auto_auth.log # Application logs +├── 📁 data/ # SQLite database directory +│ └── wifi_log.db # Connection history database +├── 📖 README.md # This file +├── 🔧 setup.md # Detailed setup instructions +└── 📄 LICENSE # MIT License +``` + +## 🔒 **Security Notes** + +- ✅ **Secure Storage**: Credentials are stored with restrictive file permissions +- ✅ **Encrypted Logs**: Passwords are masked in all log outputs +- ✅ **Local Only**: No data transmitted except during legitimate login requests +- ✅ **Automatic Cleanup**: Old logs are automatically cleaned up after system reboot +- ✅ **Permission Control**: Configuration directory accessible only by current user +- ✅ **HTTPS Support**: Compatible with both HTTP and HTTPS authentication portals + +## 🛠️ **System Requirements** + +- **Python**: 3.6 or higher +- **Operating System**: Windows 10+, Linux (most distributions), macOS 10.12+ +- **Network**: WiFi adapter with driver support +- **Permissions**: Administrator/sudo access for installation (optional for user-mode) + +## 📋 **Dependencies** + +The script automatically installs these Python packages: +``` +requests>=2.25.0 +sqlite3 (built-in) +json (built-in) +logging (built-in) +``` + +## ⚠️ **Troubleshooting** + +### **Common Issues** + +1. **Python not found** + - Ensure Python 3.6+ is installed and in PATH + - Try using `python3` instead of `python` + +2. **Permission denied** + - Run installation script as administrator/sudo + - Check file permissions in config directory + +3. **Login fails** + - Verify network credentials in config.json + - Check if portal URL is correct + - Review logs for detailed error messages + +4. **Automatic execution not working** + - Verify scheduled task/cron job creation + - Check script paths in automation setup + - Ensure proper file permissions + +### **Getting Help** + +- 📖 Check [setup.md](setup.md) for detailed instructions +- 📋 Review log files in `logs/` directory +- 🐛 [Open an issue](https://github.com/01bps/WiFi-Auto-Auth/issues) on GitHub +- 💬 Check existing [discussions](https://github.com/01bps/WiFi-Auto-Auth/discussions) + +## 🔄 **Uninstallation** + +To completely remove WiFi Auto Auth: + +### Windows +```cmd +uninstall.bat +``` + +### Linux/macOS +```bash +./uninstall.sh +``` + +The uninstallation script will: +- Remove all scheduled tasks/cron jobs +- Clean up configuration files (optional) +- Remove log files (optional) +- Uninstall Python dependencies (optional) +- Provide detailed summary of actions taken + +## 🤝 **Contributing** + +Contributions are welcome! Please feel free to: + +1. 🍴 Fork the repository +2. 🌟 Create a feature branch (`git checkout -b feature/amazing-feature`) +3. 💬 Commit your changes (`git commit -m 'Add amazing feature'`) +4. 📤 Push to the branch (`git push origin feature/amazing-feature`) +5. 🔥 Open a Pull Request + + +## 📜 **License** + +This project is licensed under the [MIT License](LICENSE), which allows for free use, modification, and distribution. + +## 🙏 **Acknowledgments** + +- Thanks to all contributors who help improve this project +- Inspired by the need for seamless connectivity in institutional networks +- Built with ❤️ for the open-source community + +--- + +**🔧 Need help?** [Open an issue](https://github.com/01bps/WiFi-Auto-Auth/issues) on GitHub! + +**⭐ Found this useful?** Give it a star to show your support! diff --git a/requirements.txt b/requirements.txt index 64851aa..9e4b84c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ -python>=3.6 -requests>=2.25.1 -sqlite3 +requests>=2.25.1 \ No newline at end of file diff --git a/setup.md b/setup.md index 63947d1..f9f14b7 100644 --- a/setup.md +++ b/setup.md @@ -1,28 +1,150 @@ -# Kindly go through the steps to locally setup the script on your device. -___ -## 1. Install Dependencies +# 🔧 **WiFi Auto Auth - Detailed Setup Guide** -Run the following command to install the requirements: +This guide provides comprehensive setup instructions for WiFi Auto Auth. For a quick automated installation, use the installation scripts (`install.bat` for Windows or `install.sh` for Linux/macOS). +--- + +## 🎯 **Installation Methods** + +### **Method 1: Automated Installation (Recommended)** + +The easiest way to install WiFi Auto Auth is using the provided installation scripts. + +#### **Windows** +1. Download or clone the repository +2. Open Command Prompt as Administrator +3. Navigate to the project directory +4. Run the installation script: + ```cmd + install.bat + ``` + +#### **Linux/macOS** +1. Download or clone the repository +2. Open terminal in the project directory +3. Make the script executable and run: + ```bash + chmod +x install.sh + ./install.sh + ``` + +**The automated installation will:** +- ✅ Check Python 3.x installation +- ✅ Install pip if not available (`python -m ensurepip --upgrade`) +- ✅ Install required dependencies from `requirements.txt` +- ✅ Create necessary directories (`config/`, `logs/`, `data/`) +- ✅ Set up interactive configuration +- ✅ Configure automatic execution on startup/network changes +- ✅ Set proper file permissions for security + +--- + +## **Method 2: Manual Installation** + +### **1. Prerequisites** + +Ensure you have the following installed: + +#### **Python 3.6 or Higher** +- **Windows**: Download from [python.org](https://www.python.org/downloads/) +- **Ubuntu/Debian**: `sudo apt update && sudo apt install python3 python3-pip` +- **CentOS/RHEL**: `sudo yum install python3 python3-pip` +- **Fedora**: `sudo dnf install python3 python3-pip` +- **Arch Linux**: `sudo pacman -S python python-pip` +- **macOS**: `brew install python3` (requires Homebrew) + +#### **Verify Installation** ```bash +python --version # or python3 --version +pip --version # or pip3 --version +``` + +### **2. Install Dependencies** + +Navigate to the project directory and install required Python packages: + +```bash +# Using pip pip install -r requirements.txt + +# Or using pip3 (if you have both Python 2 and 3) +pip3 install -r requirements.txt + +# Manual installation if requirements.txt is missing +pip install requests>=2.25.0 ``` -## 2. Find Your Network's Login URL and Payload + +#### **If pip is not installed:** +```bash +# Install pip using ensurepip +python -m ensurepip --upgrade + +# Or download and install get-pip.py +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +python get-pip.py ``` -2.1 Connect to your WiFi network manually. -2.2 Open the login page in a browser (http://192.168.x.x:8090/httpclient.html). -2.3 Inspect the login form (Right-click → Inspect → Network Tab). -2.4 Find the POST request URL inside the Network tab(should look like http://192.168.x.x:8090/login.xml). -2.5 Copy the form data parameters (like username, password, a, etc.). + +### **3. Create Directory Structure** + +Create the necessary directories for the application: + +```bash +# Windows +mkdir config logs data + +# Linux/macOS +mkdir -p config logs data ``` -## 3. Edit ```wifi_auto_login.py``` file -Modify the ```def wifi_login()``` function to match your payload parameters. -i.e: + +### **4. Find Your Network's Authentication Details** + +#### **Step 4.1: Connect to WiFi Manually** +Connect to your WiFi network using the normal method (this usually redirects you to a login page). + +#### **Step 4.2: Inspect the Login Process** +1. Open your browser's Developer Tools (F12 or Right-click → Inspect) +2. Go to the **Network** tab +3. Clear any existing network requests +4. Enter your credentials and submit the login form +5. Look for the POST request (usually to a URL like `http://192.168.x.x:8090/login.xml`) + +#### **Step 4.3: Extract Required Information** +From the network request, identify: +- **Login URL**: The endpoint where credentials are submitted +- **Request Method**: Usually POST +- **Form Data**: Parameters like username, password, mode, etc. +- **Headers**: Any special headers required + +**Example of what to look for:** +``` +POST http://192.168.100.1:8090/login.xml +Form Data: + mode: 191 + username: your_username + password: your_password + a: 1634567890 # This might be dynamic + producttype: 0 ``` + +### **5. Configure the Application** + +Create a configuration file at `config/config.json`: + +```json { - "login_url": "http://192.168.100.1:8090/login.xml", - "username": "your_username", - "password": "your_password", + "wifi": { + "ssid": "YourNetworkName", + "username": "your_username", + "password": "your_password" + }, + "portal": { + "url": "http://192.168.100.1:8090/login.xml", + "timeout": 30, + "method": "POST", + "headers": { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" + } + }, "payload_params": { "mode": "191", "username": "your_username", @@ -30,69 +152,406 @@ i.e: "a": "dynamic", "producttype": "0" }, - "db_name": "wifi_log.db" + "logging": { + "enabled": true, + "log_file": "logs/wifi_auto_auth.log", + "level": "INFO", + "max_file_size": "10MB", + "backup_count": 5 + }, + "database": { + "name": "data/wifi_log.db", + "cleanup_days": 30 + }, + "network": { + "check_interval": 30, + "max_retries": 3, + "retry_delay": 5 + } } ``` -Note: a → Keep "dynamic" if the value changes on every login attempt. -## 4. Run the Script -Run the Python script to log in automatically: +**Important Notes:** +- **Dynamic Parameters**: If a parameter (like `a`) changes with each request, set it to `"dynamic"` +- **SSID**: Must match your WiFi network name exactly +- **Credentials**: Use your actual network username and password +- **URL**: Must be the exact login endpoint discovered in step 4 + +### **6. Set File Permissions (Linux/macOS)** + +Secure your configuration files: + +```bash +# Make config directory accessible only to current user +chmod 700 config/ + +# Set appropriate permissions for log directory +chmod 755 logs/ + +# Make the main script executable +chmod +x wifi_auto_auth.py ``` -python wifi_auto_login.py + +### **7. Test the Configuration** + +Run the script manually to test your configuration: + +```bash +python wifi_auto_auth.py +# or +python3 wifi_auto_auth.py ``` -## 5. Automate WiFi Login on System Boot: +**Expected output:** +``` +[INFO] Starting WiFi Auto Auth... +[INFO] Connected to SSID: YourNetworkName +[INFO] Attempting login to portal... +[INFO] Login successful! +[INFO] Internet connectivity verified +``` -#### **🔹 Windows (Task Scheduler)** -5.1. Open **Task Scheduler** → **Create Basic Task**. -5.2. Set **Trigger** → **At Startup**. -5.3. Set **Action** → **Start a Program** → Browse for `python.exe`. -5.4. In **Arguments**, enter: - ```text - "C:\path\to\wifi_auto_login.py" - ``` -5.5. Save and enable the task. +--- + +## **8. Set Up Automatic Execution** + +### **🪟 Windows - Task Scheduler** + +#### **Method 1: Using GUI** +1. Press `Win + R`, type `taskschd.msc`, press Enter +2. Click **"Create Basic Task..."** in the right panel +3. **Name**: "WiFi Auto Auth" +4. **Trigger**: "When the computer starts" +5. **Action**: "Start a program" +6. **Program**: `python` (or full path to python.exe) +7. **Arguments**: `"C:\full\path\to\wifi_auto_auth.py"` +8. **Start in**: `C:\full\path\to\project\directory` +9. Check **"Run with highest privileges"** + +#### **Method 2: Using Command Line** +```cmd +schtasks /create /tn "WiFiAutoAuth" /tr "python "C:\path\to\wifi_auto_auth.py"" /sc onlogon /rl highest +``` + +#### **Network Event Trigger (Advanced)** +```cmd +schtasks /create /tn "WiFiAutoAuthNetwork" /tr "python "C:\path\to\wifi_auto_auth.py"" /sc onevent /ec System /mo "*[System/Provider/@Name='Microsoft-Windows-NetworkProfile']" /rl highest +``` + +### **🐧 Linux - Cron Jobs** + +#### **Basic Cron Setup** +```bash +# Edit crontab +crontab -e + +# Add this line to run on startup +@reboot /usr/bin/python3 /full/path/to/wifi_auto_auth.py + +# Or run every 5 minutes +*/5 * * * * /usr/bin/python3 /full/path/to/wifi_auto_auth.py +``` + +#### **NetworkManager Integration** +Create a dispatcher script for automatic network change detection: + +```bash +# Create the dispatcher script +sudo nano /etc/NetworkManager/dispatcher.d/99-wifi-auto-auth + +# Add this content: +#!/bin/bash +if [[ "$2" == "up" ]] && [[ "$1" == *"wl"* ]]; then + sleep 5 + /usr/bin/python3 /full/path/to/wifi_auto_auth.py +fi + +# Make it executable +sudo chmod +x /etc/NetworkManager/dispatcher.d/99-wifi-auto-auth +``` + +#### **Systemd Service (Alternative)** +Create a systemd service for more control: + +```bash +# Create service file +sudo nano /etc/systemd/system/wifi-auto-auth.service + +# Add content: +[Unit] +Description=WiFi Auto Auth Service +After=network.target + +[Service] +Type=simple +User=your_username +WorkingDirectory=/path/to/wifi-auto-auth +ExecStart=/usr/bin/python3 /path/to/wifi-auto-auth/wifi_auto_auth.py +Restart=on-failure +RestartSec=10 + +[Install] +WantedBy=multi-user.target + +# Enable and start the service +sudo systemctl daemon-reload +sudo systemctl enable wifi-auto-auth.service +sudo systemctl start wifi-auto-auth.service +``` + +### **🍎 macOS - Launch Agents** + +#### **Create Launch Agent** +```bash +# Create the plist file +nano ~/Library/LaunchAgents/com.wifiauth.plist + +# Add this content: + + + + + Label + com.wifiauth + ProgramArguments + + /usr/bin/python3 + /full/path/to/wifi_auto_auth.py + + WorkingDirectory + /full/path/to/project/directory + RunAtLoad + + KeepAlive + + StandardErrorPath + /full/path/to/logs/error.log + StandardOutPath + /full/path/to/logs/output.log + + + +# Load the launch agent +launchctl load ~/Library/LaunchAgents/com.wifiauth.plist + +# Start the service +launchctl start com.wifiauth +``` --- -#### **🔹 Linux (Crontab)** -5.1. Open terminal and run: - ```bash - crontab -e - ``` -5.2. Add this line at the end: - ```bash - @reboot python3 /path/to/wifi_auto_login.py - ``` -5.3. Save and exit. + +## **🔧 Advanced Configuration** + +### **Multiple Network Support** +```json +{ + "networks": [ + { + "ssid": "Network1", + "username": "user1", + "password": "pass1", + "portal": { + "url": "http://192.168.1.1:8090/login.xml", + "payload": { + "mode": "191", + "producttype": "0" + } + } + }, + { + "ssid": "Network2", + "username": "user2", + "password": "pass2", + "portal": { + "url": "http://10.0.0.1/login", + "payload": { + "action": "login" + } + } + } + ] +} +``` + +### **Proxy Support** +```json +{ + "proxy": { + "enabled": true, + "http": "http://proxy.example.com:8080", + "https": "http://proxy.example.com:8080", + "username": "proxy_user", + "password": "proxy_pass" + } +} +``` + +### **Custom Headers and User Agents** +```json +{ + "portal": { + "headers": { + "User-Agent": "CustomWiFiClient/1.0", + "Referer": "http://192.168.1.1:8090/", + "X-Custom-Header": "value" + } + } +} +``` + --- -#### **🔹 macOS (Launch Agents)** -5.1. Create a `.plist` file in `~/Library/LaunchAgents/`: - ```bash - nano ~/Library/LaunchAgents/wifi_auto_login.plist - ``` -5.2. Add this content: - ```xml - - - - - Label - wifi_auto_login - ProgramArguments - - /usr/bin/python3 - /path/to/wifi_auto_login.py - - RunAtLoad - - - - ``` -5.3. Save and enable it: - ```bash - launchctl load ~/Library/LaunchAgents/wifi_auto_login.plist - ``` +## **📊 Monitoring and Logs** + +### **Log Locations** +- **Application Logs**: `logs/wifi_auto_auth.log` +- **Error Logs**: `logs/error.log` +- **Database**: `data/wifi_log.db` + +### **Log Analysis** +```bash +# View recent logs +tail -f logs/wifi_auto_auth.log + +# Search for errors +grep -i "error" logs/wifi_auto_auth.log + +# Check database entries +sqlite3 data/wifi_log.db "SELECT * FROM login_attempts ORDER BY timestamp DESC LIMIT 10;" +``` + +### **Log Rotation** +The application automatically rotates logs based on size and keeps a configurable number of backup files. + +--- + +## **🚨 Troubleshooting** + +### **Common Issues and Solutions** + +#### **1. Python Not Found** +```bash +# Check Python installation +which python3 +python3 --version + +# Add to PATH (Linux/macOS) +export PATH="/usr/bin/python3:$PATH" + +# Windows: Add Python to System PATH via Environment Variables +``` + +#### **2. Permission Denied** +```bash +# Linux/macOS +chmod +x wifi_auto_auth.py +chmod 700 config/ + +# Windows: Run Command Prompt as Administrator +``` + +#### **3. Login Fails** +- Verify network credentials +- Check portal URL and parameters +- Review network inspection results +- Test manual login in browser + +#### **4. Network Not Detected** +- Verify SSID spelling in configuration +- Check WiFi adapter drivers +- Test network connectivity + +#### **5. Automatic Execution Not Working** +- Verify task/cron job creation +- Check script paths and permissions +- Review system logs for errors + +### **Debug Mode** +Enable debug logging by setting log level to "DEBUG" in config: + +```json +{ + "logging": { + "level": "DEBUG" + } +} +``` + +### **Manual Testing** +```bash +# Test with verbose output +python wifi_auto_auth.py --verbose + +# Test configuration only +python wifi_auto_auth.py --test-config + +# Test network connectivity +python wifi_auto_auth.py --test-network +``` + +--- + +## **🔄 Updates and Maintenance** + +### **Updating the Application** +```bash +# Pull latest changes +git pull origin main + +# Update dependencies +pip install -r requirements.txt --upgrade + +# Restart automated services if needed +``` + +### **Database Maintenance** +```bash +# Clean old logs (if not automated) +python wifi_auto_auth.py --cleanup + +# Backup database +cp data/wifi_log.db data/wifi_log_backup.db +``` + +--- + +## **🗑️ Uninstallation** + +### **Automated Uninstallation** +```bash +# Windows +uninstall.bat + +# Linux/macOS +./uninstall.sh +``` + +### **Manual Uninstallation** + +#### **Remove Automation** +```bash +# Windows: Delete scheduled tasks +schtasks /delete /tn "WiFiAutoAuth" /f + +# Linux: Remove cron jobs +crontab -e # Remove the relevant lines + +# macOS: Remove launch agent +launchctl unload ~/Library/LaunchAgents/com.wifiauth.plist +rm ~/Library/LaunchAgents/com.wifiauth.plist +``` + +#### **Remove Files** +```bash +# Remove project directory +rm -rf /path/to/wifi-auto-auth + +# Remove Python packages (optional) +pip uninstall requests +``` + +--- -We have succesfully setup the script now the wifi or LAN will get connected **automatically on system startup**! +**🎉 Congratulations!** Your WiFi Auto Auth is now set up and ready to provide seamless network connectivity! +For additional help, please check the [main README](README.md) or [open an issue](https://github.com/01bps/WiFi-Auto-Auth/issues) on GitHub. diff --git a/uninstall.bat b/uninstall.bat new file mode 100644 index 0000000..d81d151 --- /dev/null +++ b/uninstall.bat @@ -0,0 +1,186 @@ +@echo off +REM WiFi Auto Auth Uninstallation Script +REM This script removes WiFi Auto Auth service and cleans up + +REM Check for administrator privileges +net session >nul 2>&1 +if %errorLevel% neq 0 ( + echo This script requires administrator privileges. + echo Please right-click and select "Run as administrator" + pause + exit /b 1 +) + +echo ======================================== +echo WiFi Auto Auth Uninstallation Script +echo ======================================== +echo. + +REM Get the current script directory +set "INSTALL_DIR=%~dp0" +set "INSTALL_DIR=%INSTALL_DIR:~0,-1%" + +echo Installation directory: %INSTALL_DIR% +echo. + +REM Confirm uninstallation +set /p CONFIRM="Are you sure you want to uninstall WiFi Auto Auth? This will remove all scheduled tasks. (Y/N): " +if /i NOT "%CONFIRM%"=="Y" ( + echo Uninstallation cancelled. + pause + exit /b 0 +) + +echo. +echo Starting uninstallation... +echo. + +REM Remove scheduled tasks +echo ======================================== +echo Removing Scheduled Tasks +echo ======================================== +echo. + +schtasks /query /tn "WiFiAutoAuth" >nul 2>&1 +if %errorLevel% equ 0 ( + schtasks /delete /tn "WiFiAutoAuth" /f >nul 2>&1 + if %errorLevel% equ 0 ( + echo [OK] Removed startup task + ) else ( + echo [WARNING] Failed to remove startup task + ) +) else ( + echo [SKIP] Startup task not found +) + +schtasks /query /tn "WiFiAutoAuthOnNetwork" >nul 2>&1 +if %errorLevel% equ 0 ( + schtasks /delete /tn "WiFiAutoAuthOnNetwork" /f >nul 2>&1 + if %errorLevel% equ 0 ( + echo [OK] Removed network event task + ) else ( + echo [WARNING] Failed to remove network event task + ) +) else ( + echo [SKIP] Network event task not found +) + +echo. + +REM Ask about removing configuration and data +echo ======================================== +echo Data Removal Options +echo ======================================== +echo. +set /p REMOVE_CONFIG="Do you want to remove configuration files (contains WiFi credentials)? (Y/N): " +set /p REMOVE_LOGS="Do you want to remove log files? (Y/N): " +set /p REMOVE_DATA="Do you want to remove data directory? (Y/N): " + +echo. + +if /i "%REMOVE_CONFIG%"=="Y" ( + if exist "%INSTALL_DIR%\config" ( + rd /s /q "%INSTALL_DIR%\config" 2>nul + if %errorLevel% equ 0 ( + echo [OK] Removed config directory + ) else ( + echo [WARNING] Failed to remove config directory + ) + ) else ( + echo [SKIP] Config directory not found + ) +) else ( + echo [SKIP] Keeping configuration files +) + +if /i "%REMOVE_LOGS%"=="Y" ( + if exist "%INSTALL_DIR%\logs" ( + rd /s /q "%INSTALL_DIR%\logs" 2>nul + if %errorLevel% equ 0 ( + echo [OK] Removed logs directory + ) else ( + echo [WARNING] Failed to remove logs directory + ) + ) else ( + echo [SKIP] Logs directory not found + ) +) else ( + echo [SKIP] Keeping log files +) + +if /i "%REMOVE_DATA%"=="Y" ( + if exist "%INSTALL_DIR%\data" ( + rd /s /q "%INSTALL_DIR%\data" 2>nul + if %errorLevel% equ 0 ( + echo [OK] Removed data directory + ) else ( + echo [WARNING] Failed to remove data directory + ) + ) else ( + echo [SKIP] Data directory not found + ) +) else ( + echo [SKIP] Keeping data directory +) + +echo. + +REM Ask about uninstalling Python packages +echo ======================================== +echo Python Packages +echo ======================================== +echo. +set /p REMOVE_PACKAGES="Do you want to uninstall Python packages installed by WiFi Auto Auth? (Y/N): " + +if /i "%REMOVE_PACKAGES%"=="Y" ( + if exist "%INSTALL_DIR%\requirements.txt" ( + echo Uninstalling Python packages... + pip uninstall -r "%INSTALL_DIR%\requirements.txt" -y >nul 2>&1 + if %errorLevel% equ 0 ( + echo [OK] Python packages uninstalled + ) else ( + echo [WARNING] Some packages may not have been uninstalled + ) + ) else ( + echo [WARNING] requirements.txt not found, skipping package uninstallation + ) +) else ( + echo [SKIP] Keeping Python packages (may be used by other programs) +) + +echo. + +REM Final summary +echo ======================================== +echo Uninstallation Complete! +echo ======================================== +echo. +echo Summary of actions taken: +echo - Scheduled tasks removed +if /i "%REMOVE_CONFIG%"=="Y" ( + echo - Configuration files removed +) else ( + echo - Configuration files kept +) +if /i "%REMOVE_LOGS%"=="Y" ( + echo - Log files removed +) else ( + echo - Log files kept +) +if /i "%REMOVE_DATA%"=="Y" ( + echo - Data directory removed +) else ( + echo - Data directory kept +) +if /i "%REMOVE_PACKAGES%"=="Y" ( + echo - Python packages uninstalled +) else ( + echo - Python packages kept +) +echo. +echo The main program files remain in: %INSTALL_DIR% +echo You can manually delete this directory if desired. +echo. +echo Thank you for using WiFi Auto Auth! +echo. +pause \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..1c17bd3 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,198 @@ +#!/bin/bash + +# WiFi Auto Auth Uninstallation Script +# This script removes WiFi Auto Auth service and cleans up + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +echo "========================================" +echo "WiFi Auto Auth Uninstallation Script" +echo "========================================" +echo + +# Get the current script directory +INSTALL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +echo "Installation directory: $INSTALL_DIR" +echo + +# Confirm uninstallation +read -p "Are you sure you want to uninstall WiFi Auto Auth? This will remove all cron jobs and configurations. (Y/N): " CONFIRM +if [[ "${CONFIRM,,}" != "y" ]]; then + echo "Uninstallation cancelled." + exit 0 +fi + +echo +echo "Starting uninstallation..." +echo + +# Remove cron jobs +echo "========================================" +echo "Removing Cron Jobs" +echo "========================================" +echo + +# Check if cron job exists and remove it +if crontab -l 2>/dev/null | grep -q "$INSTALL_DIR/wifi_auto_auth_cron.sh"; then + # Remove the specific cron job + crontab -l 2>/dev/null | grep -v "$INSTALL_DIR/wifi_auto_auth_cron.sh" | crontab - + if [[ $? -eq 0 ]]; then + echo -e "${GREEN}[OK] Removed cron job${NC}" + else + echo -e "${RED}[WARNING] Failed to remove cron job${NC}" + fi +else + echo -e "${YELLOW}[SKIP] Cron job not found${NC}" +fi + +# Remove NetworkManager dispatcher script (if exists and running as root) +if [[ -f "/etc/NetworkManager/dispatcher.d/99-wifi-auto-auth" ]]; then + if [[ $EUID -eq 0 ]]; then + rm -f "/etc/NetworkManager/dispatcher.d/99-wifi-auto-auth" + echo -e "${GREEN}[OK] Removed NetworkManager dispatcher script${NC}" + else + echo -e "${YELLOW}[WARNING] Need root privileges to remove NetworkManager dispatcher script${NC}" + echo "Run: sudo rm -f /etc/NetworkManager/dispatcher.d/99-wifi-auto-auth" + fi +else + echo -e "${YELLOW}[SKIP] NetworkManager dispatcher script not found${NC}" +fi + +# Remove cron wrapper script +if [[ -f "$INSTALL_DIR/wifi_auto_auth_cron.sh" ]]; then + rm -f "$INSTALL_DIR/wifi_auto_auth_cron.sh" + echo -e "${GREEN}[OK] Removed cron wrapper script${NC}" +else + echo -e "${YELLOW}[SKIP] Cron wrapper script not found${NC}" +fi + +echo + +# Ask about removing configuration and data +echo "========================================" +echo "Data Removal Options" +echo "========================================" +echo + +read -p "Do you want to remove configuration files (contains WiFi credentials)? (Y/N): " REMOVE_CONFIG +read -p "Do you want to remove log files? (Y/N): " REMOVE_LOGS +read -p "Do you want to remove data directory? (Y/N): " REMOVE_DATA +echo + +if [[ "${REMOVE_CONFIG,,}" == "y" ]]; then + if [[ -d "$INSTALL_DIR/config" ]]; then + rm -rf "$INSTALL_DIR/config" + if [[ $? -eq 0 ]]; then + echo -e "${GREEN}[OK] Removed config directory${NC}" + else + echo -e "${RED}[WARNING] Failed to remove config directory${NC}" + fi + else + echo -e "${YELLOW}[SKIP] Config directory not found${NC}" + fi +else + echo -e "${BLUE}[SKIP] Keeping configuration files${NC}" +fi + +if [[ "${REMOVE_LOGS,,}" == "y" ]]; then + if [[ -d "$INSTALL_DIR/logs" ]]; then + rm -rf "$INSTALL_DIR/logs" + if [[ $? -eq 0 ]]; then + echo -e "${GREEN}[OK] Removed logs directory${NC}" + else + echo -e "${RED}[WARNING] Failed to remove logs directory${NC}" + fi + else + echo -e "${YELLOW}[SKIP] Logs directory not found${NC}" + fi +else + echo -e "${BLUE}[SKIP] Keeping log files${NC}" +fi + +if [[ "${REMOVE_DATA,,}" == "y" ]]; then + if [[ -d "$INSTALL_DIR/data" ]]; then + rm -rf "$INSTALL_DIR/data" + if [[ $? -eq 0 ]]; then + echo -e "${GREEN}[OK] Removed data directory${NC}" + else + echo -e "${RED}[WARNING] Failed to remove data directory${NC}" + fi + else + echo -e "${YELLOW}[SKIP] Data directory not found${NC}" + fi +else + echo -e "${BLUE}[SKIP] Keeping data directory${NC}" +fi + +echo + +# Ask about uninstalling Python packages +echo "========================================" +echo "Python Packages" +echo "========================================" +echo + +read -p "Do you want to uninstall Python packages installed by WiFi Auto Auth? (Y/N): " REMOVE_PACKAGES +if [[ "${REMOVE_PACKAGES,,}" == "y" ]]; then + if [[ -f "$INSTALL_DIR/requirements.txt" ]]; then + echo "Uninstalling Python packages..." + if pip3 uninstall -r "$INSTALL_DIR/requirements.txt" -y > /dev/null 2>&1; then + echo -e "${GREEN}[OK] Python packages uninstalled${NC}" + else + echo -e "${YELLOW}[WARNING] Some packages may not have been uninstalled${NC}" + fi + else + echo -e "${YELLOW}[WARNING] requirements.txt not found, skipping package uninstallation${NC}" + fi +else + echo -e "${BLUE}[SKIP] Keeping Python packages (may be used by other programs)${NC}" +fi + +echo + +# Final summary +echo "========================================" +echo -e "${GREEN}Uninstallation Complete!${NC}" +echo "========================================" +echo +echo "Summary of actions taken:" +echo "- Cron jobs and automated tasks removed" + +if [[ "${REMOVE_CONFIG,,}" == "y" ]]; then + echo "- Configuration files removed" +else + echo "- Configuration files kept" +fi + +if [[ "${REMOVE_LOGS,,}" == "y" ]]; then + echo "- Log files removed" +else + echo "- Log files kept" +fi + +if [[ "${REMOVE_DATA,,}" == "y" ]]; then + echo "- Data directory removed" +else + echo "- Data directory kept" +fi + +if [[ "${REMOVE_PACKAGES,,}" == "y" ]]; then + echo "- Python packages uninstalled" +else + echo "- Python packages kept" +fi + +echo +echo "The main program files remain in: $INSTALL_DIR" +echo "You can manually delete this directory if desired:" +echo " rm -rf "$INSTALL_DIR"" +echo +echo -e "${BLUE}Thank you for using WiFi Auto Auth!${NC}" +echo