likhonsheikh commited on
Commit
437b07f
·
1 Parent(s): 2a1eda7

Revert to working static version to fix build error

Browse files
Files changed (1) hide show
  1. app.py +96 -196
app.py CHANGED
@@ -1,22 +1,91 @@
1
  #!/usr/bin/env python3
2
  """
3
- OpenVPN Configuration Manager for Hugging Face Spaces
4
- Full-featured version with Gradio interface
5
  """
6
 
7
- import gradio as gr
 
 
 
8
  from datetime import datetime
9
 
10
- def create_openvpn_config(client_name, server_host, server_port, protocol):
11
- """Generate OpenVPN client configuration"""
12
- config = f"""# OpenVPN Client Configuration
13
- # Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
14
- # Client: {client_name}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  client
17
  dev tun
18
- proto {protocol}
19
- remote {server_host} {server_port}
20
  resolv-retry infinite
21
  nobind
22
  persist-key
@@ -26,195 +95,26 @@ cipher AES-256-GCM
26
  auth SHA256
27
  verb 3
28
 
29
- # Security recommendations:
30
  # - Use strong ciphers (AES-256-GCM)
31
  # - Enable certificate verification
32
  # - Keep certificates secure
33
- # - Update regularly
34
- """
35
- return config
36
-
37
- def generate_ca_script():
38
- """Generate CA certificate setup script"""
39
- return """#!/bin/bash
40
- # Certificate Authority Setup Script for OpenVPN
41
- # Run this script on your OpenVPN server
42
-
43
- # Generate CA private key
44
- openssl genrsa -out ca.key 4096
45
-
46
- # Generate CA certificate
47
- openssl req -new -x509 -days 3650 -key ca.key -out ca.crt \\
48
- -subj "/C=US/ST=State/L=City/O=Organization/CN=CA"
49
-
50
- # Generate server certificate
51
- openssl genrsa -out server.key 4096
52
- openssl req -new -key server.key -out server.csr \\
53
- -subj "/C=US/ST=State/L=City/O=Organization/CN=server"
54
- openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt
55
-
56
- # Generate client certificate
57
- openssl genrsa -out client.key 4096
58
- openssl req -new -key client.key -out client.csr \\
59
- -subj "/C=US/ST=State/L=City/O=Organization/CN=client"
60
- openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt
61
-
62
- echo "Certificates generated successfully!"
63
- """
64
-
65
- def generate_server_config():
66
- """Generate server configuration"""
67
- return """# OpenVPN Server Configuration
68
-
69
- # Network settings
70
- port 1194
71
- proto udp
72
- dev tun
73
-
74
- # Certificates
75
- ca ca.crt
76
- cert server.crt
77
- key server.key
78
- dh dh.pem
79
-
80
- # Network configuration
81
- server 10.8.0.0 255.255.255.0
82
- ifconfig-pool-persist ipp.txt
83
-
84
- # Keepalive
85
- keepalive 10 120
86
-
87
- # Compression
88
- comp-lzo
89
-
90
- # User permissions
91
- user nobody
92
- group nogroup
93
-
94
- # Security
95
- cipher AES-256-GCM
96
- auth SHA256
97
- tls-auth ta.key 0
98
-
99
- # Logging
100
- log-append /var/log/openvpn.log
101
- verb 3
102
- """
103
-
104
- def main():
105
- """Main Gradio interface"""
106
-
107
- with gr.Blocks(title="OpenVPN Configuration Manager", theme=gr.themes.Soft()) as demo:
108
- gr.Markdown("# 🔒 OpenVPN Configuration Manager")
109
- gr.Markdown("Generate OpenVPN configurations, certificates, and deployment guides")
110
-
111
- with gr.Tab("Client Configuration"):
112
- with gr.Row():
113
- with gr.Column():
114
- client_name = gr.Textbox(value="client1", label="Client Name")
115
- server_host = gr.Textbox(value="vpn.example.com", label="Server Host")
116
- server_port = gr.Number(value=1194, label="Port", minimum=1, maximum=65535)
117
- protocol = gr.Radio(["udp", "tcp"], value="udp", label="Protocol")
118
-
119
- config_output = gr.Textbox(label="Client Configuration", lines=20, interactive=False)
120
-
121
- gr.Button("Generate Client Config", variant="primary").click(
122
- create_openvpn_config,
123
- inputs=[client_name, server_host, server_port, protocol],
124
- outputs=[config_output]
125
- )
126
-
127
- with gr.Tab("Server Configuration"):
128
- server_config = gr.Textbox(
129
- label="Server Configuration",
130
- lines=25,
131
- value=generate_server_config(),
132
- interactive=False
133
- )
134
- gr.Markdown("**Save this as `/etc/openvpn/server.conf` on your server**")
135
-
136
- with gr.Tab("Certificate Scripts"):
137
- ca_script_btn = gr.Button("Generate CA Script")
138
- ca_script_output = gr.Textbox(
139
- label="CA Setup Script",
140
- lines=20,
141
- value=generate_ca_script(),
142
- interactive=False
143
- )
144
-
145
- with gr.Tab("Deployment Guide"):
146
- gr.Markdown("""
147
- ## 🚀 Deployment Instructions
148
-
149
- ### Server Setup:
150
- 1. **Install OpenVPN:**
151
- ```bash
152
- sudo apt update
153
- sudo apt install openvpn easy-rsa
154
- ```
155
-
156
- 2. **Generate Certificates:**
157
- - Run the CA script from the "Certificate Scripts" tab
158
- - This creates all necessary certificates
159
-
160
- 3. **Configure Firewall:**
161
- ```bash
162
- sudo ufw allow 1194/udp
163
- sudo ufw allow ssh
164
- ```
165
-
166
- 4. **Start OpenVPN:**
167
- ```bash
168
- sudo systemctl start openvpn@server
169
- sudo systemctl enable openvpn@server
170
- ```
171
-
172
- ### Client Setup:
173
- 1. **Download Configuration:**
174
- - Use the "Client Configuration" tab to generate your config
175
- - Save as `client.ovpn`
176
-
177
- 2. **Import to Client:**
178
- - OpenVPN GUI (Windows)
179
- - Tunnelblick (macOS)
180
- - NetworkManager (Linux)
181
-
182
- ### Security Best Practices:
183
- - ✅ Use strong ciphers (AES-256-GCM)
184
- - ✅ Enable certificate verification
185
- - ✅ Keep private keys secure
186
- - ✅ Regular certificate rotation
187
- - ✅ Monitor logs for suspicious activity
188
- - ✅ Use fail2ban for protection
189
- """)
190
-
191
- with gr.Tab("Troubleshooting"):
192
- gr.Markdown("""
193
- ## 🔧 Common Issues & Solutions
194
-
195
- ### Connection Problems:
196
- - **No internet access:** Check routing and IP forwarding
197
- - **Cannot connect to server:** Verify firewall and port settings
198
- - **Slow performance:** Try different protocols (UDP vs TCP)
199
-
200
- ### Certificate Issues:
201
- - **Certificate verification failed:** Check CA certificate matches
202
- - **Key errors:** Ensure all certificate files are present
203
- - **Expired certificates:** Regenerate using CA script
204
-
205
- ### Performance:
206
- - **Use UDP for better performance**
207
- - **Enable compression for slower connections**
208
- - **Monitor bandwidth usage**
209
- """)
210
 
211
- return demo
 
 
212
 
213
  if __name__ == "__main__":
214
- demo = main()
215
- demo.launch(
216
- server_name="0.0.0.0",
217
- server_port=7860,
218
- show_error=True,
219
- quiet=False
220
- )
 
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>
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
+ .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
 
85
  client
86
  dev tun
87
+ proto ${protocol}
88
+ remote ${serverHost} ${serverPort}
89
  resolv-retry infinite
90
  nobind
91
  persist-key
 
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()