likhonsheikh commited on
Commit
7d5f6e8
·
1 Parent(s): 437b07f

Ultra-minimal version - zero dependencies, multiple tabs

Browse files
Files changed (3) hide show
  1. app.py +111 -50
  2. app_minimal_final.py +181 -0
  3. requirements.txt +1 -2
app.py CHANGED
@@ -1,22 +1,22 @@
1
  #!/usr/bin/env python3
2
  """
3
- Ultra-minimal static web server for OpenVPN config
4
- No external dependencies except built-in Python modules
5
  """
6
 
7
- import http.server
8
- import socketserver
9
  import json
10
  from urllib.parse import parse_qs, urlparse
11
  from datetime import datetime
12
 
13
- class OpenVPNConfigHandler(http.server.SimpleHTTPRequestHandler):
14
  def do_GET(self):
15
  if self.path == '/':
16
  self.send_response(200)
17
  self.send_header('Content-type', 'text/html')
18
  self.end_headers()
19
- html_content = """<!DOCTYPE html>
 
20
  <html>
21
  <head>
22
  <title>OpenVPN Configuration Manager</title>
@@ -29,56 +29,116 @@ class OpenVPNConfigHandler(http.server.SimpleHTTPRequestHandler):
29
  input, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
30
  button { background: #2563eb; color: white; padding: 12px 24px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; }
31
  button:hover { background: #1d4ed8; }
32
- .output { margin-top: 20px; }
33
- textarea { width: 100%; height: 300px; font-family: monospace; border: 1px solid #ddd; border-radius: 5px; padding: 10px; }
 
 
 
 
34
  </style>
35
  </head>
36
  <body>
37
  <div class="container">
38
- <h1>🔒 OpenVPN Configuration Generator</h1>
39
- <form id="configForm">
 
 
 
 
 
 
 
 
40
  <div class="form-group">
41
- <label for="clientName">Client Name:</label>
42
- <input type="text" id="clientName" name="clientName" value="client1" required>
43
  </div>
44
  <div class="form-group">
45
- <label for="serverHost">Server Host:</label>
46
- <input type="text" id="serverHost" name="serverHost" value="vpn.example.com" required>
47
  </div>
48
  <div class="form-group">
49
- <label for="serverPort">Server Port:</label>
50
- <input type="number" id="serverPort" name="serverPort" value="1194" required>
51
  </div>
52
  <div class="form-group">
53
- <label for="protocol">Protocol:</label>
54
- <select id="protocol" name="protocol">
55
  <option value="udp">UDP</option>
56
  <option value="tcp">TCP</option>
57
  </select>
58
  </div>
59
- <button type="submit">Generate Configuration</button>
60
- </form>
61
- <div class="output">
62
- <label for="configOutput">Generated Configuration:</label>
63
- <textarea id="configOutput" readonly></textarea>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  </div>
65
  </div>
 
66
  <script>
67
- document.getElementById('configForm').addEventListener('submit', function(e) {
68
- e.preventDefault();
69
- const formData = new FormData(this);
70
- const config = generateConfig(
71
- formData.get('clientName'),
72
- formData.get('serverHost'),
73
- formData.get('serverPort'),
74
- formData.get('protocol')
75
- );
76
- document.getElementById('configOutput').value = config;
77
- });
 
 
78
 
79
- function generateConfig(clientName, serverHost, serverPort, protocol) {
 
 
 
 
80
  const now = new Date().toLocaleString();
81
- return `# OpenVPN Client Configuration
 
82
  # Generated: ${now}
83
  # Client: ${clientName}
84
 
@@ -95,26 +155,27 @@ cipher AES-256-GCM
95
  auth SHA256
96
  verb 3
97
 
98
- # Security Notes:
99
  # - Use strong ciphers (AES-256-GCM)
100
  # - Enable certificate verification
101
- # - Keep certificates secure
102
- # - Update regularly`;
 
103
  }
104
  </script>
105
  </body>
106
- </html>"""
107
- self.wfile.write(html_content.encode())
108
- else:
109
- super().do_GET()
110
 
111
  def log_message(self, format, *args):
112
- # Suppress log messages to keep output clean
113
- pass
 
 
 
 
 
114
 
115
  if __name__ == "__main__":
116
- PORT = 7860
117
- with socketserver.TCPServer(("", PORT), OpenVPNConfigHandler) as httpd:
118
- print(f"OpenVPN Configuration Manager running on port {PORT}")
119
- print("Access at: http://localhost:7860")
120
- httpd.serve_forever()
 
1
  #!/usr/bin/env python3
2
  """
3
+ Ultra-minimal OpenVPN Config Manager
4
+ No external dependencies - Python built-in only
5
  """
6
 
7
+ from http.server import HTTPServer, BaseHTTPRequestHandler
 
8
  import json
9
  from urllib.parse import parse_qs, urlparse
10
  from datetime import datetime
11
 
12
+ class OpenVPNHandler(BaseHTTPRequestHandler):
13
  def do_GET(self):
14
  if self.path == '/':
15
  self.send_response(200)
16
  self.send_header('Content-type', 'text/html')
17
  self.end_headers()
18
+
19
+ html = '''<!DOCTYPE html>
20
  <html>
21
  <head>
22
  <title>OpenVPN Configuration Manager</title>
 
29
  input, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
30
  button { background: #2563eb; color: white; padding: 12px 24px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; }
31
  button:hover { background: #1d4ed8; }
32
+ .tabs { display: flex; margin-bottom: 20px; }
33
+ .tab { padding: 10px 20px; background: #e5e7eb; border: none; cursor: pointer; }
34
+ .tab.active { background: #2563eb; color: white; }
35
+ .tab-content { display: none; }
36
+ .tab-content.active { display: block; }
37
+ .config-output { width: 100%; height: 200px; font-family: monospace; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
38
  </style>
39
  </head>
40
  <body>
41
  <div class="container">
42
+ <h1>🔒 OpenVPN Configuration Manager</h1>
43
+
44
+ <div class="tabs">
45
+ <button class="tab active" onclick="showTab('client')">Client Config</button>
46
+ <button class="tab" onclick="showTab('server')">Server Config</button>
47
+ <button class="tab" onclick="showTab('guide')">Deployment Guide</button>
48
+ </div>
49
+
50
+ <div id="client" class="tab-content active">
51
+ <h3>Generate Client Configuration</h3>
52
  <div class="form-group">
53
+ <label>Client Name:</label>
54
+ <input type="text" id="clientName" value="client1">
55
  </div>
56
  <div class="form-group">
57
+ <label>Server Host:</label>
58
+ <input type="text" id="serverHost" value="vpn.example.com">
59
  </div>
60
  <div class="form-group">
61
+ <label>Port:</label>
62
+ <input type="number" id="serverPort" value="1194">
63
  </div>
64
  <div class="form-group">
65
+ <label>Protocol:</label>
66
+ <select id="protocol">
67
  <option value="udp">UDP</option>
68
  <option value="tcp">TCP</option>
69
  </select>
70
  </div>
71
+ <button onclick="generateConfig()">Generate Configuration</button>
72
+ <div class="form-group">
73
+ <label>Generated Configuration:</label>
74
+ <textarea id="clientConfig" class="config-output" readonly></textarea>
75
+ </div>
76
+ </div>
77
+
78
+ <div id="server" class="tab-content">
79
+ <h3>Server Configuration</h3>
80
+ <textarea class="config-output" readonly>server 10.8.0.0 255.255.255.0
81
+ port 1194
82
+ proto udp
83
+ dev tun
84
+ ca ca.crt
85
+ cert server.crt
86
+ key server.key
87
+ dh dh.pem
88
+ user nobody
89
+ group nogroup
90
+ persist-key
91
+ persist-tun
92
+ push "redirect-gateway def1 bypass-dhcp"
93
+ push "dhcp-option DNS 8.8.8.8"
94
+ keepalive 10 120
95
+ cipher AES-256-GCM
96
+ auth SHA256
97
+ verb 3
98
+ mute 20</textarea>
99
+ </div>
100
+
101
+ <div id="guide" class="tab-content">
102
+ <h3>Deployment Guide</h3>
103
+ <div style="padding: 10px; background: #f9f9f9; border-radius: 5px;">
104
+ <h4>Server Setup:</h4>
105
+ <pre>1. Install OpenVPN: sudo apt install openvpn
106
+ 2. Copy server config to /etc/openvpn/server.conf
107
+ 3. Generate certificates using easy-rsa
108
+ 4. Start OpenVPN: sudo systemctl start openvpn@server</pre>
109
+
110
+ <h4>Client Setup:</h4>
111
+ <pre>1. Generate client config using this tool
112
+ 2. Save as .ovpn file
113
+ 3. Import to OpenVPN client
114
+ 4. Connect to server</pre>
115
+ </div>
116
  </div>
117
  </div>
118
+
119
  <script>
120
+ function showTab(tabName) {
121
+ // Hide all tab contents
122
+ document.querySelectorAll('.tab-content').forEach(content => {
123
+ content.classList.remove('active');
124
+ });
125
+ // Remove active class from all tabs
126
+ document.querySelectorAll('.tab').forEach(tab => {
127
+ tab.classList.remove('active');
128
+ });
129
+ // Show selected tab
130
+ document.getElementById(tabName).classList.add('active');
131
+ event.target.classList.add('active');
132
+ }
133
 
134
+ function generateConfig() {
135
+ const clientName = document.getElementById('clientName').value;
136
+ const serverHost = document.getElementById('serverHost').value;
137
+ const serverPort = document.getElementById('serverPort').value;
138
+ const protocol = document.getElementById('protocol').value;
139
  const now = new Date().toLocaleString();
140
+
141
+ const config = `# OpenVPN Client Configuration
142
  # Generated: ${now}
143
  # Client: ${clientName}
144
 
 
155
  auth SHA256
156
  verb 3
157
 
158
+ # Security notes:
159
  # - Use strong ciphers (AES-256-GCM)
160
  # - Enable certificate verification
161
+ # - Keep certificates secure`;
162
+
163
+ document.getElementById('clientConfig').value = config;
164
  }
165
  </script>
166
  </body>
167
+ </html>'''
168
+
169
+ self.wfile.write(html.encode())
 
170
 
171
  def log_message(self, format, *args):
172
+ pass # Suppress log messages
173
+
174
+ def run_server():
175
+ port = 7860
176
+ server = HTTPServer(('0.0.0.0', port), OpenVPNHandler)
177
+ print(f"Server running on port {port}")
178
+ server.serve_forever()
179
 
180
  if __name__ == "__main__":
181
+ run_server()
 
 
 
 
app_minimal_final.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Ultra-minimal OpenVPN Config Manager
4
+ No external dependencies - Python built-in only
5
+ """
6
+
7
+ from http.server import HTTPServer, BaseHTTPRequestHandler
8
+ import json
9
+ from urllib.parse import parse_qs, urlparse
10
+ from datetime import datetime
11
+
12
+ class OpenVPNHandler(BaseHTTPRequestHandler):
13
+ def do_GET(self):
14
+ if self.path == '/':
15
+ self.send_response(200)
16
+ self.send_header('Content-type', 'text/html')
17
+ self.end_headers()
18
+
19
+ html = '''<!DOCTYPE html>
20
+ <html>
21
+ <head>
22
+ <title>OpenVPN Configuration Manager</title>
23
+ <style>
24
+ body { font-family: Arial, sans-serif; margin: 40px; background: #f5f5f5; }
25
+ .container { max-width: 800px; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
26
+ h1 { color: #2563eb; text-align: center; }
27
+ .form-group { margin: 20px 0; }
28
+ label { display: block; margin-bottom: 5px; font-weight: bold; }
29
+ input, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
30
+ button { background: #2563eb; color: white; padding: 12px 24px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; }
31
+ button:hover { background: #1d4ed8; }
32
+ .tabs { display: flex; margin-bottom: 20px; }
33
+ .tab { padding: 10px 20px; background: #e5e7eb; border: none; cursor: pointer; }
34
+ .tab.active { background: #2563eb; color: white; }
35
+ .tab-content { display: none; }
36
+ .tab-content.active { display: block; }
37
+ .config-output { width: 100%; height: 200px; font-family: monospace; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <div class="container">
42
+ <h1>🔒 OpenVPN Configuration Manager</h1>
43
+
44
+ <div class="tabs">
45
+ <button class="tab active" onclick="showTab('client')">Client Config</button>
46
+ <button class="tab" onclick="showTab('server')">Server Config</button>
47
+ <button class="tab" onclick="showTab('guide')">Deployment Guide</button>
48
+ </div>
49
+
50
+ <div id="client" class="tab-content active">
51
+ <h3>Generate Client Configuration</h3>
52
+ <div class="form-group">
53
+ <label>Client Name:</label>
54
+ <input type="text" id="clientName" value="client1">
55
+ </div>
56
+ <div class="form-group">
57
+ <label>Server Host:</label>
58
+ <input type="text" id="serverHost" value="vpn.example.com">
59
+ </div>
60
+ <div class="form-group">
61
+ <label>Port:</label>
62
+ <input type="number" id="serverPort" value="1194">
63
+ </div>
64
+ <div class="form-group">
65
+ <label>Protocol:</label>
66
+ <select id="protocol">
67
+ <option value="udp">UDP</option>
68
+ <option value="tcp">TCP</option>
69
+ </select>
70
+ </div>
71
+ <button onclick="generateConfig()">Generate Configuration</button>
72
+ <div class="form-group">
73
+ <label>Generated Configuration:</label>
74
+ <textarea id="clientConfig" class="config-output" readonly></textarea>
75
+ </div>
76
+ </div>
77
+
78
+ <div id="server" class="tab-content">
79
+ <h3>Server Configuration</h3>
80
+ <textarea class="config-output" readonly>server 10.8.0.0 255.255.255.0
81
+ port 1194
82
+ proto udp
83
+ dev tun
84
+ ca ca.crt
85
+ cert server.crt
86
+ key server.key
87
+ dh dh.pem
88
+ user nobody
89
+ group nogroup
90
+ persist-key
91
+ persist-tun
92
+ push "redirect-gateway def1 bypass-dhcp"
93
+ push "dhcp-option DNS 8.8.8.8"
94
+ keepalive 10 120
95
+ cipher AES-256-GCM
96
+ auth SHA256
97
+ verb 3
98
+ mute 20</textarea>
99
+ </div>
100
+
101
+ <div id="guide" class="tab-content">
102
+ <h3>Deployment Guide</h3>
103
+ <div style="padding: 10px; background: #f9f9f9; border-radius: 5px;">
104
+ <h4>Server Setup:</h4>
105
+ <pre>1. Install OpenVPN: sudo apt install openvpn
106
+ 2. Copy server config to /etc/openvpn/server.conf
107
+ 3. Generate certificates using easy-rsa
108
+ 4. Start OpenVPN: sudo systemctl start openvpn@server</pre>
109
+
110
+ <h4>Client Setup:</h4>
111
+ <pre>1. Generate client config using this tool
112
+ 2. Save as .ovpn file
113
+ 3. Import to OpenVPN client
114
+ 4. Connect to server</pre>
115
+ </div>
116
+ </div>
117
+ </div>
118
+
119
+ <script>
120
+ function showTab(tabName) {
121
+ // Hide all tab contents
122
+ document.querySelectorAll('.tab-content').forEach(content => {
123
+ content.classList.remove('active');
124
+ });
125
+ // Remove active class from all tabs
126
+ document.querySelectorAll('.tab').forEach(tab => {
127
+ tab.classList.remove('active');
128
+ });
129
+ // Show selected tab
130
+ document.getElementById(tabName).classList.add('active');
131
+ event.target.classList.add('active');
132
+ }
133
+
134
+ function generateConfig() {
135
+ const clientName = document.getElementById('clientName').value;
136
+ const serverHost = document.getElementById('serverHost').value;
137
+ const serverPort = document.getElementById('serverPort').value;
138
+ const protocol = document.getElementById('protocol').value;
139
+ const now = new Date().toLocaleString();
140
+
141
+ const config = `# OpenVPN Client Configuration
142
+ # Generated: ${now}
143
+ # Client: ${clientName}
144
+
145
+ client
146
+ dev tun
147
+ proto ${protocol}
148
+ remote ${serverHost} ${serverPort}
149
+ resolv-retry infinite
150
+ nobind
151
+ persist-key
152
+ persist-tun
153
+ remote-cert-tls server
154
+ cipher AES-256-GCM
155
+ auth SHA256
156
+ verb 3
157
+
158
+ # Security notes:
159
+ # - Use strong ciphers (AES-256-GCM)
160
+ # - Enable certificate verification
161
+ # - Keep certificates secure`;
162
+
163
+ document.getElementById('clientConfig').value = config;
164
+ }
165
+ </script>
166
+ </body>
167
+ </html>'''
168
+
169
+ self.wfile.write(html.encode())
170
+
171
+ def log_message(self, format, *args):
172
+ pass # Suppress log messages
173
+
174
+ def run_server():
175
+ port = 7860
176
+ server = HTTPServer(('0.0.0.0', port), OpenVPNHandler)
177
+ print(f"Server running on port {port}")
178
+ server.serve_forever()
179
+
180
+ if __name__ == "__main__":
181
+ run_server()
requirements.txt CHANGED
@@ -1,2 +1 @@
1
- gradio==4.15.0
2
- huggingface_hub==0.16.0
 
1
+ # No dependencies - using only Python built-in modules