import gradio as gr import threading import socket import time import json import requests from datetime import datetime from typing import Dict, List, Optional import logging from utils import SOCKS5ProxyServer, ProxyManager from config import * # Create proxy manager proxy_manager = ProxyManager() def start_proxy_server(): """Start proxy server""" success = proxy_manager.start_server() if success: status_html = f"""

đŸŸĸ Status: Running

Proxy Server is running at {proxy_manager.proxy_server.host}:{proxy_manager.proxy_server.port}

""" return status_html, "✅ Proxy Server started successfully" else: status_html = """

🔴 Status: Stopped

Failed to start Proxy Server - check logs for details

""" return status_html, "❌ Failed to start Proxy Server" def stop_proxy_server(): """Stop proxy server""" proxy_manager.stop_server() status_html = """

🔴 Status: Stopped

Proxy Server stopped

""" return status_html, "🛑 Proxy Server stopped" def restart_proxy_server(): """Restart proxy server""" proxy_manager.stop_server() time.sleep(1) success = proxy_manager.start_server() if success: status_html = f"""

đŸŸĸ Status: Running

Proxy Server restarted successfully at {proxy_manager.proxy_server.host}:{proxy_manager.proxy_server.port}

""" return status_html, "🔄 Proxy Server restarted successfully" else: status_html = """

🔴 Status: Stopped

Failed to restart Proxy Server

""" return status_html, "❌ Failed to restart Proxy Server" def get_server_status(): """Get current server status""" if proxy_manager.is_running(): status_html = f"""

đŸŸĸ Status: Running

Proxy Server is running at {proxy_manager.proxy_server.host}:{proxy_manager.proxy_server.port}

""" else: status_html = """

🔴 Status: Stopped

Proxy Server is not running

""" return status_html def get_current_proxy_url(): """Get current proxy URL""" if proxy_manager.is_running(): return f"socks5://localhost:{PROXY_PORT}" return "Not connected" def get_server_info(): """Get server information""" return json.dumps(proxy_manager.get_server_info(), indent=2, ensure_ascii=False) def get_usage_stats(): """Get usage statistics""" return json.dumps(proxy_manager.get_usage_stats(), indent=2, ensure_ascii=False) def get_user_stats(): """Get user statistics""" return json.dumps(proxy_manager.get_user_stats(), indent=2, ensure_ascii=False) def get_connection_logs(): """Get connection logs""" return json.dumps(proxy_manager.get_recent_logs(), indent=2, ensure_ascii=False) def refresh_all(): """Refresh all data""" return ( get_current_proxy_url(), get_server_status(), get_server_info(), get_usage_stats(), get_user_stats(), get_connection_logs() ) def setup_interface(): """Create Gradio interface""" # Custom CSS for styling css = """ .main-container { max-width: 1200px; margin: auto; padding: 20px; } .status-indicator { padding: 10px; border-radius: 5px; margin: 5px 0; } .status-running { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .status-stopped { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } .info-box { background-color: #e9ecef; padding: 15px; border-radius: 5px; margin: 10px 0; border-left: 4px solid #007bff; } .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 20px 0; } .stat-card { background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); border: 1px solid #dee2e6; } .stat-number { font-size: 24px; font-weight: bold; color: #007bff; } .stat-label { color: #6c757d; font-size: 14px; } """ with gr.Blocks(css=css, title="SOCKS5 Proxy Dashboard", theme=gr.themes.Soft()) as demo: gr.HTML("""

🔒 SOCKS5 Proxy Server Dashboard

SOCKS5 Proxy Server Management System with Usage Monitoring

Built with anycoder
""") # Current status with gr.Row(): with gr.Column(scale=1): gr.HTML('

🎮 Controls

') with gr.Row(): start_btn = gr.Button("â–ļī¸ Start", variant="primary", size="lg") stop_btn = gr.Button("âšī¸ Stop", variant="stop", size="lg") restart_btn = gr.Button("🔄 Restart", variant="secondary", size="lg") status_html = gr.HTML() proxy_url_output = gr.Textbox( label="🌐 Current Proxy URL", value=get_current_proxy_url, interactive=False, elem_classes=["info-box"] ) # Show server status server_status_output = gr.HTML() with gr.Column(scale=2): gr.HTML('

📊 Usage Statistics

') with gr.Row(): total_connections = gr.Number(label="📈 Total Connections", value=0) active_connections = gr.Number(label="🔗 Active Connections", value=0) bandwidth_used = gr.Number(label="📊 Bandwidth Used (MB)", value=0) # User data with gr.Tab("đŸ‘Ĩ Users"): user_stats = gr.JSON( label="All User Data", value=get_user_stats ) # Server data with gr.Tab("đŸ–Ĩī¸ Server Info"): server_info = gr.JSON( label="Server Information", value=get_server_info ) # Usage statistics with gr.Tab("📊 Statistics"): usage_stats = gr.JSON( label="Usage Statistics", value=get_usage_stats ) # Logs with gr.Tab("📝 Logs"): logs = gr.JSON( label="Recent Connection Logs", value=get_connection_logs ) # Refresh button with gr.Row(): refresh_btn = gr.Button("🔄 Refresh All Data", variant="primary") # Bind events start_btn.click(start_proxy_server, outputs=[server_status_output, proxy_url_output]) stop_btn.click(stop_proxy_server, outputs=[server_status_output, proxy_url_output]) restart_btn.click(restart_proxy_server, outputs=[server_status_output, proxy_url_output]) refresh_btn.click( refresh_all, outputs=[ proxy_url_output, server_status_output, server_info, usage_stats, user_stats, logs ] ) # Auto update data demo.load( lambda: refresh_all(), outputs=[ proxy_url_output, server_status_output, server_info, usage_stats, user_stats, logs ] ) return demo if __name__ == "__main__": # Create interface demo = setup_interface() # Try to start proxy server automatically and show result print("Starting SOCKS5 Proxy Server...") success = proxy_manager.start_server() if success: print(f"✅ SOCKS5 Proxy Server started successfully at {proxy_manager.proxy_server.host}:{proxy_manager.proxy_server.port}") else: print("❌ Failed to start SOCKS5 Proxy Server - please check logs") # Start UI with appropriate settings demo.launch( server_name="0.0.0.0", server_port=8080, show_api=False, share=False, ssr_mode=False, inbrowser=False, debug=False )