Spaces:
Runtime error
Runtime error
| from flask import Flask, render_template_string, request, jsonify | |
| import os | |
| app = Flask(__name__) | |
| # ခုနက ဆောက်ထားတဲ့ HTML UI ကို ဒီနေရာမှာ တိုက်ရိုက် သိမ်းထားပါမယ် | |
| HTML_TEMPLATE = """ | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>SSH UDP Custom Tester</title> | |
| <style> | |
| body { | |
| font-family: 'Segoe UI', Arial, sans-serif; | |
| background-color: #121212; | |
| color: #ffffff; | |
| margin: 0; | |
| padding: 20px; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| min-height: 100vh; | |
| } | |
| .app-container { | |
| width: 100%; | |
| max-width: 450px; | |
| background-color: #1e1e1e; | |
| border-radius: 15px; | |
| padding: 25px; | |
| box-shadow: 0 10px 30px rgba(0,0,0,0.7); | |
| border: 1px solid #2d2d2d; | |
| } | |
| .header { text-align: center; margin-bottom: 20px; } | |
| .header h2 { margin: 0; color: #00e676; } | |
| .status-box { | |
| text-align: center; background-color: #2a2a2a; padding: 12px; | |
| border-radius: 8px; margin-bottom: 20px; font-weight: bold; color: #ff5252; | |
| } | |
| .form-group { margin-bottom: 12px; } | |
| .form-group label { display: block; margin-bottom: 5px; font-size: 13px; color: #aaa; } | |
| .form-control { | |
| width: 100%; padding: 10px; background-color: #2a2a2a; | |
| border: 1px solid #3a3a3a; border-radius: 6px; color: white; box-sizing: border-box; | |
| } | |
| .row { display: flex; gap: 10px; } | |
| .btn-start { | |
| width: 100%; padding: 14px; background-color: #00e676; color: #121212; | |
| border: none; border-radius: 6px; font-size: 16px; font-weight: bold; | |
| cursor: pointer; margin-top: 15px; | |
| } | |
| .log-box { | |
| width: 100%; height: 120px; background-color: #0a0a0a; | |
| border-radius: 6px; padding: 10px; font-family: monospace; | |
| font-size: 12px; color: #00ff00; overflow-y: auto; box-sizing: border-box; | |
| margin-top: 15px; white-space: pre-line; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="app-container"> | |
| <div class="header"> | |
| <h2>SSH UDP CUSTOM</h2> | |
| <p style="color: #777; margin: 5px 0;">Hugging Face Test Server</p> | |
| </div> | |
| <div class="status-box" id="statusText">DISCONNECTED</div> | |
| <div class="row"> | |
| <div class="form-group" style="flex: 2;"> | |
| <label>SSH Host (IP)</label> | |
| <input type="text" class="form-control" id="sshHost" value="128.199.10.5"> | |
| </div> | |
| <div class="form-group" style="flex: 1;"> | |
| <label>SSH Port</label> | |
| <input type="text" class="form-control" id="sshPort" value="22"> | |
| </div> | |
| </div> | |
| <div class="row"> | |
| <div class="form-group" style="width: 50%;"> | |
| <label>Username</label> | |
| <input type="text" class="form-control" id="sshUser" value="vpnmm"> | |
| </div> | |
| <div class="form-group" style="width: 50%;"> | |
| <label>Password</label> | |
| <input type="password" class="form-control" id="sshPass" value="1234"> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <label>UDP Custom Port</label> | |
| <input type="text" class="form-control" id="udpPort" value="7300"> | |
| </div> | |
| <button class="btn-start" id="connectBtn" onclick="startTest()">START TEST</button> | |
| <div class="log-box" id="logBox">Hugging Face Client Initialized... Ready to test UDP connection.</div> | |
| </div> | |
| <script> | |
| let isConnected = false; | |
| async function startTest() { | |
| const logBox = document.getElementById('logBox'); | |
| const statusText = document.getElementById('statusText'); | |
| const connectBtn = document.getElementById('connectBtn'); | |
| if (!isConnected) { | |
| statusText.innerText = "CONNECTING..."; | |
| statusText.style.color = "#ffeb3b"; | |
| logBox.innerHTML += "\\n[i] Sending configuration to Python Backend..."; | |
| // Backend (app.py) ဆီကို Data လှမ်းပို့ခြင်း | |
| const payload = { | |
| host: document.getElementById('sshHost').value, | |
| port: document.getElementById('sshPort').value, | |
| user: document.getElementById('sshUser').value, | |
| pass: document.getElementById('sshPass').value, | |
| udp: document.getElementById('udpPort').value | |
| }; | |
| try { | |
| const response = await fetch('/connect', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify(payload) | |
| }); | |
| const data = await response.json(); | |
| statusText.innerText = "CONNECTED (TEST)"; | |
| statusText.style.color = "#00e676"; | |
| connectBtn.innerText = "STOP"; | |
| connectBtn.style.backgroundColor = "#ff5252"; | |
| logBox.innerHTML += `\\n[+] Backend Response: ${data.message}`; | |
| logBox.innerHTML += `\\n[+] Handshake successfully simulated on Port ${payload.udp}!`; | |
| } catch (error) { | |
| logBox.innerHTML += "\\n[-] Error connecting to backend."; | |
| } | |
| isConnected = true; | |
| } else { | |
| statusText.innerText = "DISCONNECTED"; | |
| statusText.style.color = "#ff5252"; | |
| connectBtn.innerText = "START TEST"; | |
| connectBtn.style.backgroundColor = "#00e676"; | |
| logBox.innerHTML += "\\n[-] Test Stopped."; | |
| isConnected = false; | |
| } | |
| logBox.scrollTop = logBox.scrollHeight; | |
| } | |
| </script> | |
| </body> | |
| </html> | |
| """ | |
| def home(): | |
| return render_template_string(HTML_TEMPLATE) | |
| def connect(): | |
| data = request.json | |
| # ဤနေရာတွင် စမ်းသပ်မှုအဖြစ် Terminal Log ထုတ်ပြခြင်း ဖြစ်ပါတယ် | |
| print(f"Testing UDP Custom Connection to {data['host']}:{data['udp']} via User: {data['user']}") | |
| return jsonify({"status": "success", "message": f"Server received configuration for host {data['host']}"}) | |
| if __name__ == '__main__': | |
| # Hugging Face သည် Port 7860 ကို သုံးသောကြောင့် ၎င်းအတိုင်း ဖွင့်ပေးရပါမည် | |
| app.run(host='0.0.0.0', port=7860) | |