Spaces:
Runtime error
Runtime error
File size: 9,472 Bytes
1b9b049 b86e5bd 1b9b049 b86e5bd 1b9b049 b86e5bd 1b9b049 b86e5bd 1b9b049 a47f620 1b9b049 b86e5bd 1b9b049 b86e5bd 1b9b049 b86e5bd 1b9b049 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | 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"""
<div class="status-indicator status-running">
<h4>๐ข Status: Running</h4>
<p>Proxy Server is running at {proxy_manager.proxy_server.host}:{proxy_manager.proxy_server.port}</p>
</div>
"""
return status_html, "โ
Proxy Server started successfully"
else:
status_html = """
<div class="status-indicator status-stopped">
<h4>๐ด Status: Stopped</h4>
<p>Failed to start Proxy Server - check logs for details</p>
</div>
"""
return status_html, "โ Failed to start Proxy Server"
def stop_proxy_server():
"""Stop proxy server"""
proxy_manager.stop_server()
status_html = """
<div class="status-indicator status-stopped">
<h4>๐ด Status: Stopped</h4>
<p>Proxy Server stopped</p>
</div>
"""
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"""
<div class="status-indicator status-running">
<h4>๐ข Status: Running</h4>
<p>Proxy Server restarted successfully at {proxy_manager.proxy_server.host}:{proxy_manager.proxy_server.port}</p>
</div>
"""
return status_html, "๐ Proxy Server restarted successfully"
else:
status_html = """
<div class="status-indicator status-stopped">
<h4>๐ด Status: Stopped</h4>
<p>Failed to restart Proxy Server</p>
</div>
"""
return status_html, "โ Failed to restart Proxy Server"
def get_server_status():
"""Get current server status"""
if proxy_manager.is_running():
status_html = f"""
<div class="status-indicator status-running">
<h4>๐ข Status: Running</h4>
<p>Proxy Server is running at {proxy_manager.proxy_server.host}:{proxy_manager.proxy_server.port}</p>
</div>
"""
else:
status_html = """
<div class="status-indicator status-stopped">
<h4>๐ด Status: Stopped</h4>
<p>Proxy Server is not running</p>
</div>
"""
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("""
<div class="main-container">
<div style="text-align: center; margin-bottom: 30px;">
<h1>๐ SOCKS5 Proxy Server Dashboard</h1>
<p style="color: #6c757d;">SOCKS5 Proxy Server Management System with Usage Monitoring</p>
<div style="margin-top: 10px;">
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; color: #007bff; font-weight: bold;">Built with anycoder</a>
</div>
</div>
</div>
""")
# Current status
with gr.Row():
with gr.Column(scale=1):
gr.HTML('<h3>๐ฎ Controls</h3>')
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('<h3>๐ Usage Statistics</h3>')
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
) |