File size: 4,413 Bytes
dfd9494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/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()