from flask import Flask, render_template_string, jsonify, Response, request from flask_cors import CORS import requests import base64 import csv app = Flask(__name__) CORS(app) # Yeh zaroori hai taake Mobile App API ko access kar sake # --- Data Fetching Logic --- def get_vpn_data(): VPNGATE_API_URL = "http://www.vpngate.net/api/iphone/" servers = [] try: headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"} response = requests.get(VPNGATE_API_URL, headers=headers, timeout=6) text_data = response.text lines = [line for line in text_data.split('\n') if not line.startswith('*')] reader = csv.DictReader(lines) for row in reader: if row and 'OpenVPN_ConfigData_Base64' in row: try: speed_mbps = round(int(row.get('Speed', 0)) / 1000000, 2) # Sirf wo servers jo 1mbps se tez hon if speed_mbps > 1: servers.append({ 'ip': row['IP'], 'country': row['CountryLong'], 'speed': speed_mbps, 'ping': row['Ping'], 'base64_config': row['OpenVPN_ConfigData_Base64'] }) except: pass return servers[:40] # Top 40 servers except Exception as e: print(f"Error: {e}") return [] # --- 1. API Route (Mobile App ke liye) --- @app.route('/api/servers', methods=['GET']) def api_servers(): servers = get_vpn_data() return jsonify({ "status": "success", "message": "Data fetched successfully", "total_servers": len(servers), "data": servers }) # --- 2. Web UI Route (Browser ke liye) --- HTML_TEMPLATE = """ VPN Master Hub

🔥 VPN Master Hub

Mobile App API Endpoint: /api/servers

{% for server in servers %}
🌍 {{ server.country }}
IP: {{ server.ip }} | Speed: {{ server.speed }} Mbps
Connect
{% endfor %} """ @app.route('/') def web_ui(): servers = get_vpn_data() return render_template_string(HTML_TEMPLATE, servers=servers) # --- File Download Route --- @app.route('/download//') def download_file(ip, config_base64): try: decoded = base64.b64decode(config_base64) return Response(decoded, mimetype="application/x-openvpn-profile", headers={"Content-disposition": f"attachment; filename=VPN_{ip}.ovpn"}) except: return "Error downloading file" if __name__ == '__main__': app.run(host='0.0.0.0', port=7860)