Spaces:
Sleeping
Sleeping
| import os | |
| import subprocess | |
| import time | |
| import json | |
| import base64 | |
| import requests | |
| import socket | |
| import socks | |
| import gradio as gr | |
| # --- KONFIGURÁCIA --- | |
| # Vlož sem svoj celý link z obrázka (Vmess Only WS) | |
| VMESS_LINK = "vmess://eyJ0eXBlIjogIm5vbmUiLCAicGF0aCI6ICIvdnBuamFudGl0IiwgImhvc3QiOiAiIiwgIm5ldCI6ICJ3cyIsICJwb3J0IjogIjEwMDAwIiwgImFkZCI6ICJzazEudnBuamFudGl0LmNvbSIsICJwcyI6ICJhYmMxMjMtdnBuamFudGl0LmNvbSIsICJ0bHMiOiAiIiwgImFpZCI6ICIwIiwgInYiOiAiMiIsICJpZCI6ICI5ZGY1NmQ4MC0zNjY5LTExZjEtOTBiMS04ZmI2ODcwNGQ1MGMifQ==" | |
| def setup_xray(): | |
| if os.path.exists("./xray"): | |
| return | |
| print("📥 Sťahujem Xray core...") | |
| # Stiahnutie Linux 64-bit verzie | |
| url = "https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-64.zip" | |
| subprocess.run(f"curl -L {url} -o xray.zip", shell=True) | |
| subprocess.run("unzip -q xray.zip && chmod +x xray", shell=True) | |
| print("✅ Xray pripravený.") | |
| def start_proxy(): | |
| # Dekódovanie VMess linku pre získanie údajov | |
| # VMess link je base64 zakódovaný JSON (po odstránení 'vmess://') | |
| try: | |
| data_b64 = VMESS_LINK.replace("vmess://", "") | |
| # Pridanie paddingu ak chýba | |
| data_json = base64.b64decode(data_b64 + '==' * (4 - len(data_b64) % 4)).decode('utf-8') | |
| config_data = json.loads(data_json) | |
| # Vytvorenie Xray konfigurácie | |
| xray_config = { | |
| "inbounds": [{"port": 10808, "protocol": "socks", "settings": {"auth": "noauth"}}], | |
| "outbounds": [{ | |
| "protocol": "vmess", | |
| "settings": { | |
| "vnext": [{ | |
| "address": config_data['add'], | |
| "port": int(config_data['port']), | |
| "users": [{"id": config_data['id'], "alterId": 0}] | |
| }] | |
| }, | |
| "streamSettings": { | |
| "network": config_data['net'], | |
| "security": config_data['tls'] if config_data.get('tls') else "none", | |
| "wsSettings": {"path": config_data['path']} if config_data.get('path') else {} | |
| } | |
| }] | |
| } | |
| with open("config.json", "w") as f: | |
| json.dump(xray_config, f) | |
| print("🚀 Štartujem proxy na porte 10808...") | |
| subprocess.Popen("./xray -c config.json", shell=True) | |
| time.sleep(5) # Čas na inicializáciu | |
| return True | |
| except Exception as e: | |
| print(f"❌ Chyba konfigurácie: {e}") | |
| return False | |
| def check_ip(): | |
| proxies = { | |
| 'http': 'socks5h://127.0.0.1:10808', | |
| 'https': 'socks5h://127.0.0.1:10808' | |
| } | |
| try: | |
| r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=10) | |
| return r.json()['ip'] | |
| except Exception as e: | |
| return f"Chyba: {e}" | |
| # --- SPUSTENIE --- | |
| setup_xray() | |
| proxy_ok = start_proxy() | |
| # Gradio rozhranie, aby Space nezhasol | |
| def greet(name): | |
| ip = check_ip() if proxy_ok else "Proxy nebeží" | |
| return f"Ahoj {name}! Tvoja aktuálna IP v tomto Space je: {ip}" | |
| demo = gr.Interface( | |
| fn=greet, | |
| inputs="text", | |
| outputs="text", | |
| title="Slovak IP Tunnel", | |
| description="Ak všetko prebehlo v poriadku, IP by mala byť zo Slovenska (Bratislava)." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |