|
|
|
|
|
""" |
|
|
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) |