From 7d079f9b375f59e18467e02679defe82cc2af861 Mon Sep 17 00:00:00 2001 From: TheMaddax Date: Thu, 5 Mar 2026 12:34:06 -0700 Subject: [PATCH] Add simplified VPN manager script for Proxmox Colocation only --- vpn-manager.command | 184 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100755 vpn-manager.command diff --git a/vpn-manager.command b/vpn-manager.command new file mode 100755 index 0000000..445c76b --- /dev/null +++ b/vpn-manager.command @@ -0,0 +1,184 @@ +#!/bin/bash + +# Get the directory where this script is located +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# VPN Configuration +VPN_CONFIG="$HOME/wg1.conf" +VPN_NAME="Proxmox Colocation VPN" +VPN_IP="10.6.0.3" +VPN_NETWORK="10.6.0.0/24, 10.4.0.0/24" + +# Function to get active VPN interface +get_active_vpn() { + sudo wg show interfaces 2>/dev/null +} + +# Function to show detailed status +show_status() { + echo "🔍 Checking VPN connection..." + echo "" + + local active_interface=$(get_active_vpn) + + if [ -z "$active_interface" ]; then + echo "🔴 VPN not connected" + return + fi + + echo "đŸŸĸ VPN Connected:" + echo "" + sudo wg show + echo "" + + # Show routing information + echo "📡 Network Routes:" + netstat -rn | grep -E "10\.(4|6)\.0" | awk '{printf " %-20s -> %s\n", $1, $NF}' +} + +# Function to connect VPN +connect_vpn() { + if [ ! -f "$VPN_CONFIG" ]; then + echo "❌ Configuration file not found: $VPN_CONFIG" + return 1 + fi + + echo "🔄 Connecting to $VPN_NAME..." + result=$(sudo wg-quick up "$VPN_CONFIG" 2>&1) + + if [ $? -eq 0 ]; then + echo "✅ Connected Successfully!" + echo " VPN IP: $VPN_IP" + echo " Networks: $VPN_NETWORK" + sleep 1 + return 0 + else + if echo "$result" | grep -q "already exists"; then + echo "â„šī¸ VPN is already connected" + return 0 + else + echo "❌ Failed to connect:" + echo "$result" | head -5 + return 1 + fi + fi +} + +# Function to disconnect VPN +disconnect_vpn() { + if [ ! -f "$VPN_CONFIG" ]; then + echo "❌ Configuration file not found: $VPN_CONFIG" + return 1 + fi + + echo "🔄 Disconnecting $VPN_NAME..." + result=$(sudo wg-quick down "$VPN_CONFIG" 2>&1) + + if [ $? -eq 0 ]; then + echo "✅ Disconnected Successfully!" + return 0 + else + if echo "$result" | grep -q "is not a WireGuard interface"; then + echo "â„šī¸ VPN is not connected" + return 0 + else + echo "❌ Failed to disconnect:" + echo "$result" | head -5 + return 1 + fi + fi +} + +# Function to test connectivity +test_connectivity() { + local active_interface=$(get_active_vpn) + + if [ -z "$active_interface" ]; then + echo "❌ VPN not connected. Please connect first." + return + fi + + echo "🔍 Testing connectivity..." + echo "" + + # Test internal network (10.4.0.0/24) + echo "Testing Internal Network (10.4.0.0/24):" + if ping -c 1 -W 2 10.4.0.1 >/dev/null 2>&1; then + echo " ✅ Gateway (10.4.0.1): Reachable" + else + echo " âš ī¸ Gateway (10.4.0.1): Not reachable" + fi + + if ping -c 1 -W 2 10.4.0.148 >/dev/null 2>&1; then + echo " ✅ Proxmox Host (10.4.0.148): Reachable" + else + echo " âš ī¸ Proxmox Host (10.4.0.148): Not reachable" + fi + + if ping -c 1 -W 2 10.4.0.205 >/dev/null 2>&1; then + echo " ✅ DeafGain Server (10.4.0.205): Reachable" + else + echo " âš ī¸ DeafGain Server (10.4.0.205): Not reachable" + fi +} + +# Clear screen and show header +clear +echo "==================================================" +echo "🔐 WireGuard VPN Manager - Proxmox Colocation" +echo "==================================================" +echo "" + +# Main menu +while true; do + # Check VPN status + active_interface=$(get_active_vpn) + + if [ -n "$active_interface" ]; then + echo "đŸŸĸ Status: VPN Connected" + else + echo "🔴 Status: VPN Disconnected" + fi + echo "" + + echo "Options:" + echo "1) Connect to VPN" + echo "2) Disconnect from VPN" + echo "3) Show Detailed Status" + echo "4) Test Connectivity" + echo "5) Quit" + echo "" + read -p "Enter your choice (1-5): " choice + + case $choice in + 1) + echo "" + connect_vpn + ;; + 2) + echo "" + disconnect_vpn + ;; + 3) + echo "" + show_status + ;; + 4) + echo "" + test_connectivity + ;; + 5) + echo "" + echo "👋 Goodbye!" + exit 0 + ;; + *) + echo "" + echo "❌ Invalid choice. Please enter 1-5." + ;; + esac + + echo "" + echo "==================================================" + echo "" +done