File size: 3,393 Bytes
6c089d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Simple OpenVPN Configuration Manager for Hugging Face Spaces
Minimal working version to test build
"""

import gradio as gr

def create_openvpn_config(client_name, server_host, server_port, protocol):
    """Generate a basic OpenVPN configuration file"""
    
    config_content = f"""# OpenVPN Client Configuration
# Generated by OpenVPN Configuration Manager
# Date: {__import__('datetime').datetime.now().strftime('%Y-%m-%d %H:%M:%S')}

client
dev tun
proto {protocol}
remote {server_host} {server_port}
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-GCM
verb 3
"""
    
    return config_content

def generate_ca_script():
    """Generate CA certificate script"""
    return """#!/bin/bash
# Certificate Authority Setup Script
# Run this script on your OpenVPN server

# Generate CA private key
openssl genrsa -out ca.key 4096

# Generate CA certificate
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt -subj "/C=US/ST=State/L=City/O=Organization/CN=CA"

echo "CA certificate and key generated successfully!"
"""

def main():
    """Main Gradio interface"""
    
    with gr.Blocks(title="OpenVPN Configuration Manager") as demo:
        gr.Markdown("# πŸ”’ OpenVPN Configuration Manager")
        gr.Markdown("Generate OpenVPN configuration files and certificates")
        
        with gr.Tab("Generate Client Config"):
            with gr.Row():
                client_name = gr.Textbox(label="Client Name", value="client1")
                server_host = gr.Textbox(label="Server Host", value="your-server.com")
                server_port = gr.Textbox(label="Server Port", value="1194")
                protocol = gr.Dropdown(["udp", "tcp"], value="udp", label="Protocol")
            
            generate_btn = gr.Button("Generate Configuration")
            config_output = gr.Textbox(label="Configuration", lines=20, interactive=False)
            
            generate_btn.click(
                fn=create_openvpn_config,
                inputs=[client_name, server_host, server_port, protocol],
                outputs=[config_output]
            )
        
        with gr.Tab("Certificate Scripts"):
            ca_script_btn = gr.Button("Generate CA Script")
            ca_script_output = gr.Textbox(label="CA Setup Script", lines=15, interactive=False)
            
            ca_script_btn.click(
                fn=generate_ca_script,
                inputs=[],
                outputs=[ca_script_output]
            )
        
        with gr.Tab("Deployment Guide"):
            gr.Markdown("""
            ## Deployment Instructions
            
            1. **Server Setup:**
               - Install OpenVPN on your server
               - Generate CA certificates using the script above
               - Configure firewall to allow VPN traffic
            
            2. **Client Configuration:**
               - Download the generated .ovpn file
               - Import it into your OpenVPN client
               - Connect to your server
            
            3. **Security Notes:**
               - Always use strong ciphers (AES-256-GCM)
               - Enable certificate verification
               - Keep your certificates secure
            """)
    
    return demo

if __name__ == "__main__":
    demo = main()
    demo.launch(server_name="0.0.0.0", server_port=7860)