Sophos Automatic Login & Authentication

This Python script automates the login process for a Sophos internet web authentication portal. It ensures uninterrupted connectivity by automatically re-authenticating you every 2 minutes to prevent logout.

Download Latest Release

Features

SQLite IntegrationCredentials are securely stored in an SQLite database.
Automatic ID SwitchingAutomatically switches to the next available ID if the current one fails or reaches its data limit.
Command-Line ArgumentsSupports various system arguments for automation and management.
Credential ManagementAdd, edit, delete, import, and export credentials.
Interactive MenuUser-friendly menu for managing credentials and starting the auto-login process.
CSV Import/ExportEasily import/export credentials to/from a CSV file.
Auto-Logout HandlingEnsures seamless reconnection by automatically logging in when disconnected.
Cross-Platform CompatibilityWorks on both Windows and Unix-based systems.
Daemon ModeRun the auto-login process in the background (Unix-like systems only).
Connection CheckPeriodically checks for internet connectivity and logs in if disconnected.
Scheduled Re-loginPerforms a scheduled re-login every 30 minutes to maintain connection.

Quick Start

Using Pre-built Executable

You can download the latest pre-built executable from the Releases section without installing Python or any dependencies:

  1. Go to the Releases section on GitHub
  2. Download the executable for your operating system (Windows, macOS, or Linux)
  3. Run the downloaded file:
    • Windows: Double-click the autologin.exe file
    • macOS:
      • Extract the downloaded autologin-mac.zip file
      • Option 1: Remove the quarantine attribute by opening Terminal, navigating to the extraction location, and running xattr -d com.apple.quarantine autologin before executing it
      • Option 2: Right-click on the extracted file, select "Open" from the context menu, then confirm the security dialog
    • Linux:
      • Extract the downloaded autologin-linux.zip file
      • Open Terminal, navigate to the extraction location and run ./autologin

Building from Source

If you prefer to run the Python script directly:

  1. Clone the repository:
    git clone https://github.com/tashifkhan/sophos-auto-login.git
    cd sophos-auto-login
  2. Install the required dependencies:
    pip install -r requirements.txt
  3. Run the script:
    python autologin.py

Command-Line Usage

The script supports the following command-line arguments:

--start or -s
Start the auto-login process immediately [Screenshot]
--add or -a
Add new credentials to the database [Screenshot]
--edit or -e
Edit existing credentials
--delete or -del
Delete credentials from the database
--export [path] or -x [path]
Export credentials to a CSV file (optional path)
--import [path] or -i [path]
Import credentials from a CSV file
--show or -l
Display all stored credentials
--daemon or -d
Run the auto-login process in background mode (must be used with --start)
--exit or -q
Stop the daemon process and logout all credentials
--logout or -lo
Logout from all credentials without stopping the daemon process
--speedtest or -t
Run a speed test to measure your current internet connection performance
--status or -st
Display the current status of the daemon process [Screenshot]

Examples

# Start the auto-login process
python autologin.py --start

# Run in daemon mode (background process)
python autologin.py --start --daemon

# Stop the daemon process
python autologin.py --exit

# Add new credentials
python autologin.py --add

# Import credentials from CSV
python autologin.py --import credentials.csv

Interactive Menu

If you run the script without any command-line arguments, it will present an interactive menu:

python autologin.py

This menu allows you to easily manage credentials and start the auto-login process without remembering specific commands. See an example screenshot of the interactive menu.

Options include:

  • Starting the auto-login process
  • Adding, editing, or deleting credentials
  • Showing all stored credentials
  • Importing/Exporting credentials via CSV
  • Running a speed test
  • Exiting the application

Daemon Mode

The daemon mode allows you to run the auto-login process in the background without keeping a terminal window open. This feature is only available on Unix-like systems (Linux, macOS).

When running in daemon mode:

  • The process detaches from the terminal and runs in the background
  • All output is redirected to a log file in ~/.sophos-autologin/sophos-autologin.log
  • A PID file is created at ~/.sophos-autologin/sophos-autologin.pid

Starting the Daemon

python autologin.py --start --daemon

Checking Daemon Status

You can check if the daemon is running using the --status argument:

python autologin.py --status

See an example screenshot of the status output.

Stopping the Daemon

python autologin.py --exit

Alternatively, you can use the following command to find and kill the process:

kill $(cat ~/.sophos-autologin/sophos-autologin.pid)

Screenshots

Here are some examples of the script in action:

Interactive Menu

Interactive Menu

The main interactive menu providing various options.

Starting Auto-Login

Start Auto-Login via CLI

Output when starting the auto-login process using --start.

Daemon Status

Daemon Status via CLI

Checking the status of the background daemon process using --status.

Exit Daemon

Exit Daemon via CLI

Stopping the daemon process and logging out using --exit.

Logout

Logout via CLI

Logging out from all active sessions using --logout.

Speed Test

Speed Test via CLI

Running an internet speed test using --speedtest.

Additional Features

Automatic ID Switching

The script automatically switches to the next available ID in the database if:

  • The current ID reaches its data limit
  • The current ID fails to log in

This ensures uninterrupted connectivity.

Internet Connection Check

The script periodically checks for internet connectivity every 90 seconds. If the internet connection is lost, the script will attempt to log in again.

Scheduled Re-login

To ensure continuous connectivity, the script performs a scheduled re-login every 30 minutes, even if the internet connection is active.

Importing Previous CSV Files

If you have previously used the CSV-based version of this script, you can directly import your existing CSV files:

python autologin.py --import credentials.csv

Creating an Executable

To create an executable from the Python script, follow these steps:

  1. Clone the repository and navigate to the project directory:
    git clone https://github.com/tashifkhan/sophos-auto-login.git
    cd sophos-auto-login
  2. Install the required dependencies:
    pip install -r requirements.txt
  3. Install PyInstaller:
    pip install pyinstaller
  4. Create the executable:
    # For MacOS / Linux
    pyinstaller --onefile --add-data "db/credentials.db:." autologin.py
    
    # For Windows
    pyinstaller --onefile --add-data "db/credentials.db;." autologin.py

This will create an executable file in the dist directory that you can run directly.

macOS and Linux Setup

On Unix-based systems like macOS and Linux, you can set up the script to run as a standalone application with a virtual environment. This approach is more lightweight than creating an executable and provides better integration with the system.

Step 1: Creating a Virtual Environment

A virtual environment isolates the script's dependencies from the system Python:

# Navigate to the project directory
cd sophos-auto-login

# Create a virtual environment
python3 -m venv venv

# Activate the virtual environment
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Step 2: Creating an Executable Script

Make the Python script executable with a shebang line:

  1. Add a shebang line to point to your virtual environment's Python interpreter:
    #!/path/to/sophos-auto-login/venv/bin/python3
    
    # Rest of your autologin.py content...

    You can find the correct path by running:

    which python

    while your virtual environment is activated.

  2. Make the script executable:
    chmod +x autologin.py
  3. Now you can run the script directly:
    ./autologin.py

Step 3: Creating a Launcher (Optional)

You can create a shell script to easily run your application:

#!/bin/bash
# Save this as run_sophos.sh

# Navigate to the script directory
cd /path/to/sophos-auto-login

# Activate virtual environment and run the script
source venv/bin/activate
./autologin.py "$@"

Make the launcher executable:

chmod +x run_sophos.sh

Step 4: Creating a System Service (Linux)

On Linux, you can create a systemd service to run the script at startup:

[Unit]
Description=Sophos Auto Login Service
After=network.target

[Service]
ExecStart=/path/to/sophos-auto-login/venv/bin/python3 /path/to/sophos-auto-login/autologin.py --start --daemon
WorkingDirectory=/path/to/sophos-auto-login
Restart=always
RestartSec=10
User=your_username

[Install]
WantedBy=multi-user.target

Save this file as sophos-autologin.service in /etc/systemd/system/ and run:

sudo systemctl enable sophos-autologin.service
sudo systemctl start sophos-autologin.service

Step 5: Creating a Launch Agent (macOS)

On macOS, you can create a Launch Agent to automatically start the script at login:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.sophosautologin</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/sophos-auto-login/venv/bin/python3</string>
        <string>/path/to/sophos-auto-login/autologin.py</string>
        <string>--start</string>
        <string>--daemon</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/Users/your_username/.sophos-autologin/error.log</string>
    <key>StandardOutPath</key>
    <string>/Users/your_username/.sophos-autologin/output.log</string>
    <key>WorkingDirectory</key>
    <string>/path/to/sophos-auto-login</string>
</dict>
</plist>

Save this file as com.user.sophosautologin.plist in ~/Library/LaunchAgents/ and run:

launchctl load ~/Library/LaunchAgents/com.user.sophosautologin.plist

Step 6: Using Aliases for Quick Access

Add an alias to your shell configuration file (~/.bashrc, ~/.zshrc, etc.):

# Add this to your shell configuration file
alias sophos-login="cd /path/to/sophos-auto-login && source venv/bin/activate && ./autologin.py"
alias sophos-start="sophos-login --start"
alias sophos-stop="sophos-login --exit"

After saving, reload your configuration:

source ~/.bashrc  # or ~/.zshrc depending on your shell

Now you can use simple commands from anywhere:

sophos-start    # Start the auto-login process
sophos-stop     # Stop the process and logout