feat: initial TailScan implementation

This commit is contained in:
Pizza committed 2026-04-01 16:00:23 -06:00
1 parent fc03a9ff2a
commit 91f8687509
1 file changed
+38 -96
+38 -96
View File
@@ -1,109 +1,51 @@
#!/usr/bin/env bash
# TailScan — First-time setup and launch script
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "=== TailScan Setup ==="
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
info() { echo -e "${GREEN}[+]${NC} $1"; }
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
error() { echo -e "${RED}[✗]${NC} $1"; exit 1; }
# Install nmap if missing
if ! command -v nmap &>/dev/null; then
echo "Installing nmap..."
if command -v apt-get &>/dev/null; then
sudo apt-get install -y nmap
elif command -v dnf &>/dev/null; then
sudo dnf install -y nmap
elif command -v yum &>/dev/null; then
sudo yum install -y nmap
else
echo "WARNING: Could not install nmap automatically. Install it manually."
fi
fi
echo ""
echo " ████████╗ █████╗ ██╗██╗ ███████╗ ██████╗ █████╗ ███╗ ██╗"
echo " ██╔══╝██╔══██╗██║██║ ██╔════╝██╔════╝██╔══██╗████╗ ██║"
echo " ██║ ███████║██║██║ ███████╗██║ ███████║██╔██╗ ██║"
echo " ██║ ██╔══██║██║██║ ╚════██║██║ ██╔══██║██║╚██╗██║"
echo " ██║ ██║ ██║██║███████╗███████║╚██████╗██║ ██║██║ ╚████║"
echo " ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚══════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝"
echo ""
echo " TailScan — Tailscale Network Scanner"
echo ""
# Install Python deps
if ! command -v pip3 &>/dev/null; then
echo "ERROR: pip3 not found. Install Python 3.11+ first."
exit 1
fi
# ── Check .env ──────────────────────────────────────────────────────────────
if [ ! -f ".env" ]; then
warn ".env not found. Copying .env.example → .env"
echo "Installing Python dependencies..."
pip3 install -r requirements.txt -q
# Check .env exists
if [ ! -f .env ]; then
if [ -f .env.example ]; then
cp .env.example .env
echo ""
echo " ⚠ Please edit .env and fill in your Tailscale OAuth credentials:"
echo " - TS_CLIENT_ID"
echo " - TS_CLIENT_SECRET"
echo " - BASE_URL (your Tailscale IP:8080)"
echo ""
echo " Then run ./start.sh again."
echo ""
exit 1
echo "✅ Created .env from .env.example"
echo "👉 Edit .env and fill in your Tailscale OAuth credentials, then re-run ./start.sh"
exit 0
fi
fi
# Check if placeholders are still in .env
if grep -q "your_oauth_client_id" .env; then
error ".env still has placeholder values. Edit .env before running start.sh."
# Validate .env
if grep -q "your_client_id_here" .env 2>/dev/null; then
echo "ERROR: .env not configured. Edit .env and fill in TAILSCALE_CLIENT_ID etc."
exit 1
fi
# ── Check tailscale ─────────────────────────────────────────────────────────
info "Checking Tailscale..."
if ! command -v tailscale &>/dev/null; then
error "tailscale CLI not found. Install Tailscale first: https://tailscale.com/download"
fi
TS_IP=$(tailscale ip -4 2>/dev/null || echo "")
if [ -z "$TS_IP" ]; then
warn "Could not detect Tailscale IP — is Tailscale connected?"
else
info "Tailscale IP: $TS_IP"
fi
# ── Install nmap if missing ─────────────────────────────────────────────────
if ! command -v nmap &>/dev/null; then
info "Installing nmap..."
if command -v apt-get &>/dev/null; then
sudo apt-get install -y nmap
elif command -v yum &>/dev/null; then
sudo yum install -y nmap
elif command -v dnf &>/dev/null; then
sudo dnf install -y nmap
elif command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm nmap
elif command -v brew &>/dev/null; then
brew install nmap
else
warn "Could not install nmap automatically. Please install it manually."
fi
else
info "nmap is installed: $(nmap --version | head -1)"
fi
# ── Python check ────────────────────────────────────────────────────────────
info "Checking Python..."
if command -v python3 &>/dev/null; then
PYTHON=python3
elif command -v python &>/dev/null; then
PYTHON=python
else
error "Python 3 not found. Please install Python 3.10+"
fi
PY_VERSION=$($PYTHON --version 2>&1 | awk '{print $2}')
info "Python: $PY_VERSION"
# ── Virtual environment ──────────────────────────────────────────────────────
if [ ! -d "venv" ]; then
info "Creating virtual environment..."
$PYTHON -m venv venv
fi
info "Activating venv and installing dependencies..."
source venv/bin/activate
pip install --upgrade pip -q
pip install -r requirements.txt -q
info "Dependencies installed."
# ── Launch ───────────────────────────────────────────────────────────────────
echo ""
info "Starting TailScan on port 8080..."
if [ -n "$TS_IP" ]; then
info "Open in browser: http://${TS_IP}:8080"
fi
echo "Starting TailScan on port 8080..."
echo "Access at: http://$(tailscale ip -4 2>/dev/null || echo '<tailscale-ip>'):8080"
echo ""
exec python main.py
# Run (needs sudo for nmap raw sockets)
sudo python3 main.py