OpenVPN / app_static.py
likhonsheikh
Test with zero dependencies - pure Python HTTP server
dfd9494
#!/usr/bin/env python3
"""
Ultra-minimal static web server for OpenVPN config
No external dependencies except built-in Python modules
"""
import http.server
import socketserver
import json
from urllib.parse import parse_qs, urlparse
from datetime import datetime
class OpenVPNConfigHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
html_content = """<!DOCTYPE html>
<html>
<head>
<title>OpenVPN Configuration Manager</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; background: #f5f5f5; }
.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); }
h1 { color: #2563eb; text-align: center; }
.form-group { margin: 20px 0; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }
button { background: #2563eb; color: white; padding: 12px 24px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; }
button:hover { background: #1d4ed8; }
.output { margin-top: 20px; }
textarea { width: 100%; height: 300px; font-family: monospace; border: 1px solid #ddd; border-radius: 5px; padding: 10px; }
</style>
</head>
<body>
<div class="container">
<h1>πŸ”’ OpenVPN Configuration Generator</h1>
<form id="configForm">
<div class="form-group">
<label for="clientName">Client Name:</label>
<input type="text" id="clientName" name="clientName" value="client1" required>
</div>
<div class="form-group">
<label for="serverHost">Server Host:</label>
<input type="text" id="serverHost" name="serverHost" value="vpn.example.com" required>
</div>
<div class="form-group">
<label for="serverPort">Server Port:</label>
<input type="number" id="serverPort" name="serverPort" value="1194" required>
</div>
<div class="form-group">
<label for="protocol">Protocol:</label>
<select id="protocol" name="protocol">
<option value="udp">UDP</option>
<option value="tcp">TCP</option>
</select>
</div>
<button type="submit">Generate Configuration</button>
</form>
<div class="output">
<label for="configOutput">Generated Configuration:</label>
<textarea id="configOutput" readonly></textarea>
</div>
</div>
<script>
document.getElementById('configForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const config = generateConfig(
formData.get('clientName'),
formData.get('serverHost'),
formData.get('serverPort'),
formData.get('protocol')
);
document.getElementById('configOutput').value = config;
});
function generateConfig(clientName, serverHost, serverPort, protocol) {
const now = new Date().toLocaleString();
return `# OpenVPN Client Configuration
# Generated: ${now}
# Client: ${clientName}
client
dev tun
proto ${protocol}
remote ${serverHost} ${serverPort}
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-GCM
auth SHA256
verb 3
# Security Notes:
# - Use strong ciphers (AES-256-GCM)
# - Enable certificate verification
# - Keep certificates secure
# - Update regularly`;
}
</script>
</body>
</html>"""
self.wfile.write(html_content.encode())
else:
super().do_GET()
def log_message(self, format, *args):
# Suppress log messages to keep output clean
pass
if __name__ == "__main__":
PORT = 7860
with socketserver.TCPServer(("", PORT), OpenVPNConfigHandler) as httpd:
print(f"OpenVPN Configuration Manager running on port {PORT}")
print("Access at: http://localhost:7860")
httpd.serve_forever()