Phoe2004 commited on
Commit
3f1edfb
·
verified ·
1 Parent(s): ad8b011

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +172 -0
app.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template_string, request, jsonify
2
+ import os
3
+
4
+ app = Flask(__name__)
5
+
6
+ # ခုနက ဆောက်ထားတဲ့ HTML UI ကို ဒီနေရာမှာ တိုက်ရိုက် သိမ်းထားပါမယ်
7
+ HTML_TEMPLATE = """
8
+ <!DOCTYPE html>
9
+ <html lang="en">
10
+ <head>
11
+ <meta charset="UTF-8">
12
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
13
+ <title>SSH UDP Custom Tester</title>
14
+ <style>
15
+ body {
16
+ font-family: 'Segoe UI', Arial, sans-serif;
17
+ background-color: #121212;
18
+ color: #ffffff;
19
+ margin: 0;
20
+ padding: 20px;
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ min-height: 100vh;
25
+ }
26
+ .app-container {
27
+ width: 100%;
28
+ max-width: 450px;
29
+ background-color: #1e1e1e;
30
+ border-radius: 15px;
31
+ padding: 25px;
32
+ box-shadow: 0 10px 30px rgba(0,0,0,0.7);
33
+ border: 1px solid #2d2d2d;
34
+ }
35
+ .header { text-align: center; margin-bottom: 20px; }
36
+ .header h2 { margin: 0; color: #00e676; }
37
+ .status-box {
38
+ text-align: center; background-color: #2a2a2a; padding: 12px;
39
+ border-radius: 8px; margin-bottom: 20px; font-weight: bold; color: #ff5252;
40
+ }
41
+ .form-group { margin-bottom: 12px; }
42
+ .form-group label { display: block; margin-bottom: 5px; font-size: 13px; color: #aaa; }
43
+ .form-control {
44
+ width: 100%; padding: 10px; background-color: #2a2a2a;
45
+ border: 1px solid #3a3a3a; border-radius: 6px; color: white; box-sizing: border-box;
46
+ }
47
+ .row { display: flex; gap: 10px; }
48
+ .btn-start {
49
+ width: 100%; padding: 14px; background-color: #00e676; color: #121212;
50
+ border: none; border-radius: 6px; font-size: 16px; font-weight: bold;
51
+ cursor: pointer; margin-top: 15px;
52
+ }
53
+ .log-box {
54
+ width: 100%; height: 120px; background-color: #0a0a0a;
55
+ border-radius: 6px; padding: 10px; font-family: monospace;
56
+ font-size: 12px; color: #00ff00; overflow-y: auto; box-sizing: border-box;
57
+ margin-top: 15px; white-space: pre-line;
58
+ }
59
+ </style>
60
+ </head>
61
+ <body>
62
+
63
+ <div class="app-container">
64
+ <div class="header">
65
+ <h2>SSH UDP CUSTOM</h2>
66
+ <p style="color: #777; margin: 5px 0;">Hugging Face Test Server</p>
67
+ </div>
68
+
69
+ <div class="status-box" id="statusText">DISCONNECTED</div>
70
+
71
+ <div class="row">
72
+ <div class="form-group" style="flex: 2;">
73
+ <label>SSH Host (IP)</label>
74
+ <input type="text" class="form-control" id="sshHost" value="128.199.10.5">
75
+ </div>
76
+ <div class="form-group" style="flex: 1;">
77
+ <label>SSH Port</label>
78
+ <input type="text" class="form-control" id="sshPort" value="22">
79
+ </div>
80
+ </div>
81
+
82
+ <div class="row">
83
+ <div class="form-group" style="width: 50%;">
84
+ <label>Username</label>
85
+ <input type="text" class="form-control" id="sshUser" value="vpnmm">
86
+ </div>
87
+ <div class="form-group" style="width: 50%;">
88
+ <label>Password</label>
89
+ <input type="password" class="form-control" id="sshPass" value="1234">
90
+ </div>
91
+ </div>
92
+
93
+ <div class="form-group">
94
+ <label>UDP Custom Port</label>
95
+ <input type="text" class="form-control" id="udpPort" value="7300">
96
+ </div>
97
+
98
+ <button class="btn-start" id="connectBtn" onclick="startTest()">START TEST</button>
99
+
100
+ <div class="log-box" id="logBox">Hugging Face Client Initialized...&#10;Ready to test UDP connection.</div>
101
+ </div>
102
+
103
+ <script>
104
+ let isConnected = false;
105
+
106
+ async function startTest() {
107
+ const logBox = document.getElementById('logBox');
108
+ const statusText = document.getElementById('statusText');
109
+ const connectBtn = document.getElementById('connectBtn');
110
+
111
+ if (!isConnected) {
112
+ statusText.innerText = "CONNECTING...";
113
+ statusText.style.color = "#ffeb3b";
114
+ logBox.innerHTML += "\\n[i] Sending configuration to Python Backend...";
115
+
116
+ // Backend (app.py) ဆီကို Data လှမ်းပို့ခြင်း
117
+ const payload = {
118
+ host: document.getElementById('sshHost').value,
119
+ port: document.getElementById('sshPort').value,
120
+ user: document.getElementById('sshUser').value,
121
+ pass: document.getElementById('sshPass').value,
122
+ udp: document.getElementById('udpPort').value
123
+ };
124
+
125
+ try {
126
+ const response = await fetch('/connect', {
127
+ method: 'POST',
128
+ headers: { 'Content-Type': 'application/json' },
129
+ body: JSON.stringify(payload)
130
+ });
131
+ const data = await response.json();
132
+
133
+ statusText.innerText = "CONNECTED (TEST)";
134
+ statusText.style.color = "#00e676";
135
+ connectBtn.innerText = "STOP";
136
+ connectBtn.style.backgroundColor = "#ff5252";
137
+ logBox.innerHTML += `\\n[+] Backend Response: ${data.message}`;
138
+ logBox.innerHTML += `\\n[+] Handshake successfully simulated on Port ${payload.udp}!`;
139
+ } catch (error) {
140
+ logBox.innerHTML += "\\n[-] Error connecting to backend.";
141
+ }
142
+ isConnected = true;
143
+ } else {
144
+ statusText.innerText = "DISCONNECTED";
145
+ statusText.style.color = "#ff5252";
146
+ connectBtn.innerText = "START TEST";
147
+ connectBtn.style.backgroundColor = "#00e676";
148
+ logBox.innerHTML += "\\n[-] Test Stopped.";
149
+ isConnected = false;
150
+ }
151
+ logBox.scrollTop = logBox.scrollHeight;
152
+ }
153
+ </script>
154
+ </body>
155
+ </html>
156
+ """
157
+
158
+ @app.route('/')
159
+ def home():
160
+ return render_template_string(HTML_TEMPLATE)
161
+
162
+ @app.route('/connect', methods=['POST'])
163
+ def connect():
164
+ data = request.json
165
+ # ဤနေရာတွင် စမ်းသပ်မှုအဖြစ် Terminal Log ထုတ်ပြခြင်း ဖြစ်ပါတယ်
166
+ print(f"Testing UDP Custom Connection to {data['host']}:{data['udp']} via User: {data['user']}")
167
+ return jsonify({"status": "success", "message": f"Server received configuration for host {data['host']}"})
168
+
169
+ if __name__ == '__main__':
170
+ # Hugging Face သည် Port 7860 ကို သုံးသောကြောင့် ၎င်းအတိုင်း ဖွင့်ပေးရပါမည်
171
+ app.run(host='0.0.0.0', port=7860)
172
+