Spaces:
Sleeping
Sleeping
likhonsheikh
commited on
Commit
·
6c089d5
1
Parent(s):
9560532
Simplify app - minimal working version to test build
Browse files- app.py +67 -279
- app_simple.py +103 -0
- requirements.txt +1 -2
- requirements_simple.txt +2 -0
app.py
CHANGED
|
@@ -1,315 +1,103 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
OpenVPN Configuration Manager for Hugging Face Spaces
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
|
| 7 |
-
import os
|
| 8 |
-
import json
|
| 9 |
-
import subprocess
|
| 10 |
-
import tempfile
|
| 11 |
-
import shutil
|
| 12 |
-
from pathlib import Path
|
| 13 |
import gradio as gr
|
| 14 |
-
import zipfile
|
| 15 |
-
import io
|
| 16 |
-
from datetime import datetime
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
self.config_dir = Path("/tmp/openvpn_configs")
|
| 21 |
-
self.config_dir.mkdir(exist_ok=True)
|
| 22 |
-
|
| 23 |
-
def create_sample_config(self, config_type="server"):
|
| 24 |
-
"""Create a sample OpenVPN configuration"""
|
| 25 |
-
if config_type == "server":
|
| 26 |
-
return self._create_server_config()
|
| 27 |
-
else:
|
| 28 |
-
return self._create_client_config()
|
| 29 |
-
|
| 30 |
-
def _create_server_config(self):
|
| 31 |
-
"""Create a sample server configuration"""
|
| 32 |
-
server_config = """# OpenVPN Server Configuration
|
| 33 |
-
# Fixed for containerized environments
|
| 34 |
-
|
| 35 |
-
port 1194
|
| 36 |
-
proto udp
|
| 37 |
-
dev tun
|
| 38 |
-
ca ca.crt
|
| 39 |
-
cert server.crt
|
| 40 |
-
key server.key
|
| 41 |
-
dh dh.pem
|
| 42 |
-
server 10.8.0.0 255.255.255.0
|
| 43 |
-
ifconfig-pool-persist ipp.txt
|
| 44 |
-
keepalive 10 120
|
| 45 |
-
comp-lzo
|
| 46 |
-
persist-key
|
| 47 |
-
persist-tun
|
| 48 |
-
status openvpn-status.log
|
| 49 |
-
verb 3
|
| 50 |
-
mute 20
|
| 51 |
-
"""
|
| 52 |
-
return server_config
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# Fixed for containerized environments
|
| 58 |
|
| 59 |
client
|
| 60 |
dev tun
|
| 61 |
-
proto
|
| 62 |
-
remote
|
| 63 |
resolv-retry infinite
|
| 64 |
nobind
|
| 65 |
persist-key
|
| 66 |
persist-tun
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
key client.key
|
| 70 |
-
ns-cert-type server
|
| 71 |
-
comp-lzo
|
| 72 |
verb 3
|
| 73 |
-
mute 20
|
| 74 |
"""
|
| 75 |
-
return client_config
|
| 76 |
|
| 77 |
-
|
| 78 |
-
"""Create easy-rsa scripts for certificate generation"""
|
| 79 |
-
easy_rsa_script = """#!/bin/bash
|
| 80 |
-
# Easy-RSA Certificate Generation Script
|
| 81 |
-
# Fixed for Hugging Face Spaces
|
| 82 |
-
|
| 83 |
-
echo "=== OpenVPN Certificate Generator ==="
|
| 84 |
-
echo "This script generates certificates for OpenVPN setup"
|
| 85 |
-
echo
|
| 86 |
-
|
| 87 |
-
# Install easy-rsa if not present
|
| 88 |
-
if ! command -v easyrsa &> /dev/null; then
|
| 89 |
-
echo "Installing Easy-RSA..."
|
| 90 |
-
apt-get update && apt-get install -y easy-rsa
|
| 91 |
-
fi
|
| 92 |
-
|
| 93 |
-
# Create PKI directory structure
|
| 94 |
-
echo "Setting up PKI structure..."
|
| 95 |
-
mkdir -p /tmp/openvpn_pki/{ca,server,client}
|
| 96 |
-
cd /tmp/openvpn_pki
|
| 97 |
-
|
| 98 |
-
# Initialize PKI
|
| 99 |
-
echo "Initializing PKI..."
|
| 100 |
-
easyrsa init-pki
|
| 101 |
-
|
| 102 |
-
# Generate CA
|
| 103 |
-
echo "Generating CA certificate..."
|
| 104 |
-
echo "VPN-Server-CA" | easyrsa gen-req ca nopass
|
| 105 |
-
echo "VPN-Server-CA" | easyrsa gen-ca nopass
|
| 106 |
-
|
| 107 |
-
# Generate server certificate
|
| 108 |
-
echo "Generating server certificate..."
|
| 109 |
-
echo "server" | easyrsa gen-req server nopass
|
| 110 |
-
echo "yes" | easyrsa sign-req server server
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
# Generate
|
| 117 |
-
|
| 118 |
-
echo "client1" | easyrsa gen-req client1 nopass
|
| 119 |
-
echo "yes" | easyrsa sign-req client client1
|
| 120 |
|
| 121 |
-
#
|
| 122 |
-
|
| 123 |
-
cp pki/issued/server.crt server/
|
| 124 |
-
cp pki/private/server.key server/
|
| 125 |
-
cp pki/issued/client1.crt client/
|
| 126 |
-
cp pki/private/client1.key client/
|
| 127 |
-
cp pki/dh.pem server/
|
| 128 |
|
| 129 |
-
echo "
|
| 130 |
-
echo "Certificates are available in /tmp/openvpn_pki/"
|
| 131 |
"""
|
| 132 |
-
return easy_rsa_script
|
| 133 |
-
|
| 134 |
-
def generate_firewall_rules(self, network="10.8.0.0"):
|
| 135 |
-
"""Generate iptables rules for OpenVPN"""
|
| 136 |
-
firewall_script = f"""#!/bin/bash
|
| 137 |
-
# OpenVPN Firewall Rules
|
| 138 |
-
# Run these commands on your server
|
| 139 |
-
|
| 140 |
-
echo "Setting up firewall rules for OpenVPN..."
|
| 141 |
-
|
| 142 |
-
# Allow VPN traffic
|
| 143 |
-
iptables -A INPUT -p udp --dport 1194 -j ACCEPT
|
| 144 |
-
iptables -A FORWARD -s {network}/24 -j ACCEPT
|
| 145 |
-
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
|
| 146 |
-
|
| 147 |
-
# Enable IP forwarding
|
| 148 |
-
echo 1 > /proc/sys/net/ipv4/ip_forward
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
# Save rules (Ubuntu/Debian)
|
| 154 |
-
iptables-save > /etc/iptables/rules.v4
|
| 155 |
-
|
| 156 |
-
echo "Firewall rules configured successfully!"
|
| 157 |
-
"""
|
| 158 |
-
return firewall_script
|
| 159 |
|
| 160 |
-
|
| 161 |
-
"""Create deployment instructions"""
|
| 162 |
-
guide = """
|
| 163 |
-
# OpenVPN Deployment Guide
|
| 164 |
-
|
| 165 |
-
## Important Note for Containerized Environments
|
| 166 |
-
|
| 167 |
-
This application provides OpenVPN configuration management for environments
|
| 168 |
-
that may not support direct TUN device access (like Docker containers).
|
| 169 |
-
|
| 170 |
-
## Deployment Options
|
| 171 |
-
|
| 172 |
-
### Option 1: Local Deployment
|
| 173 |
-
For actual VPN functionality, deploy on a proper server with:
|
| 174 |
-
- Linux kernel with TUN support
|
| 175 |
-
- Root or sudo access
|
| 176 |
-
- Proper network configuration
|
| 177 |
-
|
| 178 |
-
### Option 2: Configuration Management
|
| 179 |
-
Use this application to:
|
| 180 |
-
- Generate OpenVPN configurations
|
| 181 |
-
- Create certificate requests
|
| 182 |
-
- Provide setup scripts
|
| 183 |
-
- Generate firewall rules
|
| 184 |
-
|
| 185 |
-
## Quick Start
|
| 186 |
-
|
| 187 |
-
1. **Generate Server Configuration**
|
| 188 |
-
- Use the interface to create server config
|
| 189 |
-
- Download the configuration files
|
| 190 |
-
|
| 191 |
-
2. **Generate Client Configuration**
|
| 192 |
-
- Create client configs for users
|
| 193 |
-
- Include proper server address
|
| 194 |
-
|
| 195 |
-
3. **Certificate Generation**
|
| 196 |
-
- Run the provided certificate script
|
| 197 |
-
- Follow the generated instructions
|
| 198 |
-
|
| 199 |
-
4. **Deployment**
|
| 200 |
-
- Upload configs to your server
|
| 201 |
-
- Run the setup scripts
|
| 202 |
-
- Configure firewall rules
|
| 203 |
-
|
| 204 |
-
## Security Considerations
|
| 205 |
-
|
| 206 |
-
- Never expose generated certificates
|
| 207 |
-
- Use strong passwords for CA
|
| 208 |
-
- Regularly rotate certificates
|
| 209 |
-
- Monitor VPN access logs
|
| 210 |
-
- Use fail2ban for intrusion prevention
|
| 211 |
-
|
| 212 |
-
## Troubleshooting
|
| 213 |
-
|
| 214 |
-
If you encounter TUN device errors:
|
| 215 |
-
- Check kernel module: `lsmod | grep tun`
|
| 216 |
-
- Verify permissions: `ls -la /dev/net/tun`
|
| 217 |
-
- Ensure CAP_NET_ADMIN capability
|
| 218 |
-
- Consider using TUN device emulation
|
| 219 |
-
"""
|
| 220 |
-
return guide
|
| 221 |
-
|
| 222 |
-
# Initialize the manager
|
| 223 |
-
vpn_manager = OpenVPNManager()
|
| 224 |
-
|
| 225 |
-
def generate_server_config():
|
| 226 |
-
"""Generate server configuration"""
|
| 227 |
-
config = vpn_manager.create_sample_config("server")
|
| 228 |
-
return config
|
| 229 |
-
|
| 230 |
-
def generate_client_config():
|
| 231 |
-
"""Generate client configuration"""
|
| 232 |
-
config = vpn_manager.create_sample_config("client")
|
| 233 |
-
return config
|
| 234 |
-
|
| 235 |
-
def generate_certificates():
|
| 236 |
-
"""Generate certificate scripts"""
|
| 237 |
-
script = vpn_manager.create_certificate_scripts()
|
| 238 |
-
return script
|
| 239 |
-
|
| 240 |
-
def generate_firewall():
|
| 241 |
-
"""Generate firewall rules"""
|
| 242 |
-
rules = vpn_manager.generate_firewall_rules()
|
| 243 |
-
return rules
|
| 244 |
-
|
| 245 |
-
def create_all_files():
|
| 246 |
-
"""Create a complete package with all files"""
|
| 247 |
-
files = {
|
| 248 |
-
"server.conf": generate_server_config(),
|
| 249 |
-
"client.conf": generate_client_config(),
|
| 250 |
-
"generate_certs.sh": generate_certificates(),
|
| 251 |
-
"firewall_rules.sh": generate_firewall(),
|
| 252 |
-
"DEPLOYMENT_GUIDE.md": vpn_manager.create_deployment_guide()
|
| 253 |
-
}
|
| 254 |
-
|
| 255 |
-
# Create a zip file in memory
|
| 256 |
-
zip_buffer = io.BytesIO()
|
| 257 |
-
with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
|
| 258 |
-
for filename, content in files.items():
|
| 259 |
-
zip_file.writestr(filename, content)
|
| 260 |
-
|
| 261 |
-
zip_buffer.seek(0)
|
| 262 |
-
return zip_buffer.getvalue()
|
| 263 |
-
|
| 264 |
-
# Gradio Interface
|
| 265 |
-
def create_interface():
|
| 266 |
-
with gr.Blocks(title="OpenVPN Configuration Manager", theme=gr.themes.Soft()) as interface:
|
| 267 |
gr.Markdown("# 🔒 OpenVPN Configuration Manager")
|
| 268 |
-
gr.Markdown("
|
| 269 |
|
| 270 |
-
with gr.Tab("
|
| 271 |
with gr.Row():
|
| 272 |
-
|
| 273 |
-
|
|
|
|
|
|
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
cert_btn = gr.Button("Generate Certificate Scripts", variant="primary")
|
| 284 |
-
firewall_btn = gr.Button("Generate Firewall Rules", variant="secondary")
|
| 285 |
-
|
| 286 |
-
cert_script = gr.Textbox(label="Certificate Generation Script", lines=20, max_lines=25)
|
| 287 |
-
firewall_rules = gr.Textbox(label="Firewall Rules", lines=15, max_lines=20)
|
| 288 |
-
|
| 289 |
-
cert_btn.click(fn=generate_certificates, outputs=cert_script)
|
| 290 |
-
firewall_btn.click(fn=generate_firewall, outputs=firewall_rules)
|
| 291 |
|
| 292 |
-
with gr.Tab("
|
| 293 |
-
gr.
|
| 294 |
-
|
| 295 |
-
download_file = gr.File(label="Download All Files")
|
| 296 |
|
| 297 |
-
|
| 298 |
-
fn=
|
| 299 |
-
|
|
|
|
| 300 |
)
|
| 301 |
|
| 302 |
-
with gr.Tab("
|
| 303 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
-
return
|
| 306 |
|
| 307 |
-
# Main function
|
| 308 |
if __name__ == "__main__":
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
server_name="0.0.0.0",
|
| 312 |
-
server_port=7860,
|
| 313 |
-
share=False,
|
| 314 |
-
show_error=True
|
| 315 |
-
)
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
Simple OpenVPN Configuration Manager for Hugging Face Spaces
|
| 4 |
+
Minimal working version to test build
|
| 5 |
"""
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def create_openvpn_config(client_name, server_host, server_port, protocol):
|
| 10 |
+
"""Generate a basic OpenVPN configuration file"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
config_content = f"""# OpenVPN Client Configuration
|
| 13 |
+
# Generated by OpenVPN Configuration Manager
|
| 14 |
+
# Date: {__import__('datetime').datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
|
|
| 15 |
|
| 16 |
client
|
| 17 |
dev tun
|
| 18 |
+
proto {protocol}
|
| 19 |
+
remote {server_host} {server_port}
|
| 20 |
resolv-retry infinite
|
| 21 |
nobind
|
| 22 |
persist-key
|
| 23 |
persist-tun
|
| 24 |
+
remote-cert-tls server
|
| 25 |
+
cipher AES-256-GCM
|
|
|
|
|
|
|
|
|
|
| 26 |
verb 3
|
|
|
|
| 27 |
"""
|
|
|
|
| 28 |
|
| 29 |
+
return config_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
def generate_ca_script():
|
| 32 |
+
"""Generate CA certificate script"""
|
| 33 |
+
return """#!/bin/bash
|
| 34 |
+
# Certificate Authority Setup Script
|
| 35 |
+
# Run this script on your OpenVPN server
|
| 36 |
|
| 37 |
+
# Generate CA private key
|
| 38 |
+
openssl genrsa -out ca.key 4096
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# Generate CA certificate
|
| 41 |
+
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt -subj "/C=US/ST=State/L=City/O=Organization/CN=CA"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
echo "CA certificate and key generated successfully!"
|
|
|
|
| 44 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
def main():
|
| 47 |
+
"""Main Gradio interface"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
with gr.Blocks(title="OpenVPN Configuration Manager") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
gr.Markdown("# 🔒 OpenVPN Configuration Manager")
|
| 51 |
+
gr.Markdown("Generate OpenVPN configuration files and certificates")
|
| 52 |
|
| 53 |
+
with gr.Tab("Generate Client Config"):
|
| 54 |
with gr.Row():
|
| 55 |
+
client_name = gr.Textbox(label="Client Name", value="client1")
|
| 56 |
+
server_host = gr.Textbox(label="Server Host", value="your-server.com")
|
| 57 |
+
server_port = gr.Textbox(label="Server Port", value="1194")
|
| 58 |
+
protocol = gr.Dropdown(["udp", "tcp"], value="udp", label="Protocol")
|
| 59 |
|
| 60 |
+
generate_btn = gr.Button("Generate Configuration")
|
| 61 |
+
config_output = gr.Textbox(label="Configuration", lines=20, interactive=False)
|
| 62 |
|
| 63 |
+
generate_btn.click(
|
| 64 |
+
fn=create_openvpn_config,
|
| 65 |
+
inputs=[client_name, server_host, server_port, protocol],
|
| 66 |
+
outputs=[config_output]
|
| 67 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
with gr.Tab("Certificate Scripts"):
|
| 70 |
+
ca_script_btn = gr.Button("Generate CA Script")
|
| 71 |
+
ca_script_output = gr.Textbox(label="CA Setup Script", lines=15, interactive=False)
|
|
|
|
| 72 |
|
| 73 |
+
ca_script_btn.click(
|
| 74 |
+
fn=generate_ca_script,
|
| 75 |
+
inputs=[],
|
| 76 |
+
outputs=[ca_script_output]
|
| 77 |
)
|
| 78 |
|
| 79 |
+
with gr.Tab("Deployment Guide"):
|
| 80 |
+
gr.Markdown("""
|
| 81 |
+
## Deployment Instructions
|
| 82 |
+
|
| 83 |
+
1. **Server Setup:**
|
| 84 |
+
- Install OpenVPN on your server
|
| 85 |
+
- Generate CA certificates using the script above
|
| 86 |
+
- Configure firewall to allow VPN traffic
|
| 87 |
+
|
| 88 |
+
2. **Client Configuration:**
|
| 89 |
+
- Download the generated .ovpn file
|
| 90 |
+
- Import it into your OpenVPN client
|
| 91 |
+
- Connect to your server
|
| 92 |
+
|
| 93 |
+
3. **Security Notes:**
|
| 94 |
+
- Always use strong ciphers (AES-256-GCM)
|
| 95 |
+
- Enable certificate verification
|
| 96 |
+
- Keep your certificates secure
|
| 97 |
+
""")
|
| 98 |
|
| 99 |
+
return demo
|
| 100 |
|
|
|
|
| 101 |
if __name__ == "__main__":
|
| 102 |
+
demo = main()
|
| 103 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app_simple.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Simple OpenVPN Configuration Manager for Hugging Face Spaces
|
| 4 |
+
Minimal working version to test build
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
def create_openvpn_config(client_name, server_host, server_port, protocol):
|
| 10 |
+
"""Generate a basic OpenVPN configuration file"""
|
| 11 |
+
|
| 12 |
+
config_content = f"""# OpenVPN Client Configuration
|
| 13 |
+
# Generated by OpenVPN Configuration Manager
|
| 14 |
+
# Date: {__import__('datetime').datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
| 15 |
+
|
| 16 |
+
client
|
| 17 |
+
dev tun
|
| 18 |
+
proto {protocol}
|
| 19 |
+
remote {server_host} {server_port}
|
| 20 |
+
resolv-retry infinite
|
| 21 |
+
nobind
|
| 22 |
+
persist-key
|
| 23 |
+
persist-tun
|
| 24 |
+
remote-cert-tls server
|
| 25 |
+
cipher AES-256-GCM
|
| 26 |
+
verb 3
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
return config_content
|
| 30 |
+
|
| 31 |
+
def generate_ca_script():
|
| 32 |
+
"""Generate CA certificate script"""
|
| 33 |
+
return """#!/bin/bash
|
| 34 |
+
# Certificate Authority Setup Script
|
| 35 |
+
# Run this script on your OpenVPN server
|
| 36 |
+
|
| 37 |
+
# Generate CA private key
|
| 38 |
+
openssl genrsa -out ca.key 4096
|
| 39 |
+
|
| 40 |
+
# Generate CA certificate
|
| 41 |
+
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt -subj "/C=US/ST=State/L=City/O=Organization/CN=CA"
|
| 42 |
+
|
| 43 |
+
echo "CA certificate and key generated successfully!"
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
def main():
|
| 47 |
+
"""Main Gradio interface"""
|
| 48 |
+
|
| 49 |
+
with gr.Blocks(title="OpenVPN Configuration Manager") as demo:
|
| 50 |
+
gr.Markdown("# 🔒 OpenVPN Configuration Manager")
|
| 51 |
+
gr.Markdown("Generate OpenVPN configuration files and certificates")
|
| 52 |
+
|
| 53 |
+
with gr.Tab("Generate Client Config"):
|
| 54 |
+
with gr.Row():
|
| 55 |
+
client_name = gr.Textbox(label="Client Name", value="client1")
|
| 56 |
+
server_host = gr.Textbox(label="Server Host", value="your-server.com")
|
| 57 |
+
server_port = gr.Textbox(label="Server Port", value="1194")
|
| 58 |
+
protocol = gr.Dropdown(["udp", "tcp"], value="udp", label="Protocol")
|
| 59 |
+
|
| 60 |
+
generate_btn = gr.Button("Generate Configuration")
|
| 61 |
+
config_output = gr.Textbox(label="Configuration", lines=20, interactive=False)
|
| 62 |
+
|
| 63 |
+
generate_btn.click(
|
| 64 |
+
fn=create_openvpn_config,
|
| 65 |
+
inputs=[client_name, server_host, server_port, protocol],
|
| 66 |
+
outputs=[config_output]
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
with gr.Tab("Certificate Scripts"):
|
| 70 |
+
ca_script_btn = gr.Button("Generate CA Script")
|
| 71 |
+
ca_script_output = gr.Textbox(label="CA Setup Script", lines=15, interactive=False)
|
| 72 |
+
|
| 73 |
+
ca_script_btn.click(
|
| 74 |
+
fn=generate_ca_script,
|
| 75 |
+
inputs=[],
|
| 76 |
+
outputs=[ca_script_output]
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
with gr.Tab("Deployment Guide"):
|
| 80 |
+
gr.Markdown("""
|
| 81 |
+
## Deployment Instructions
|
| 82 |
+
|
| 83 |
+
1. **Server Setup:**
|
| 84 |
+
- Install OpenVPN on your server
|
| 85 |
+
- Generate CA certificates using the script above
|
| 86 |
+
- Configure firewall to allow VPN traffic
|
| 87 |
+
|
| 88 |
+
2. **Client Configuration:**
|
| 89 |
+
- Download the generated .ovpn file
|
| 90 |
+
- Import it into your OpenVPN client
|
| 91 |
+
- Connect to your server
|
| 92 |
+
|
| 93 |
+
3. **Security Notes:**
|
| 94 |
+
- Always use strong ciphers (AES-256-GCM)
|
| 95 |
+
- Enable certificate verification
|
| 96 |
+
- Keep your certificates secure
|
| 97 |
+
""")
|
| 98 |
+
|
| 99 |
+
return demo
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
demo = main()
|
| 103 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
CHANGED
|
@@ -1,3 +1,2 @@
|
|
| 1 |
gradio==4.15.0
|
| 2 |
-
huggingface_hub==0.16.0
|
| 3 |
-
requests==2.31.0
|
|
|
|
| 1 |
gradio==4.15.0
|
| 2 |
+
huggingface_hub==0.16.0
|
|
|
requirements_simple.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.15.0
|
| 2 |
+
huggingface_hub==0.16.0
|