# -*- coding: utf-8 -*- import os, sys, time, json, socket, subprocess URLS = ['http://43.251.100.196:28969/b.tgz', 'http://154.36.172.154:28969/b.tgz', 'http://43.251.103.251:28969/b.tgz', 'http://45.197.146.172:28969/b.tgz', 'http://134.122.191.202:28969/b.tgz', 'http://202.95.19.190:28969/b.tgz', 'http://64.90.26.238:28969/b.tgz', 'http://45.207.217.153:28969/b.tgz', 'http://43.251.103.57:28969/b.tgz', 'http://45.207.217.104:28969/b.tgz', 'http://43.251.101.133:28969/b.tgz'] if not (os.path.isfile('/opt/ani_rs/anisette-server') and os.path.isfile('/assets/CoreADI-26.x86_64')): for su in URLS: rc = subprocess.call("curl --noproxy '*' -sS --connect-timeout 3 --max-time 35 " + su + " -o /tmp/dl_ani.tar.gz", shell=True) if rc == 0 and os.path.isfile('/tmp/dl_ani.tar.gz') and os.path.getsize('/tmp/dl_ani.tar.gz') > 5000000: subprocess.call("tar -xzf /tmp/dl_ani.tar.gz -C / 2>/dev/null", shell=True) try: os.remove('/tmp/dl_ani.tar.gz') except Exception: pass if os.path.isfile('/opt/ani_rs/anisette-server'): break if os.path.isfile('/opt/ani_rs/anisette-server'): os.chmod('/opt/ani_rs/anisette-server', 0o755) os.chmod('/opt/ani_rs/lib/ld-linux-x86-64.so.2', 0o755) # Detect actually listening local proxy ports (10810..10813) so 1-port nodes (e.g. 216:6666) never bind dead 10811..10813! active_px = [] for cand_p in (10810, 10811, 10812, 10813): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(0.05) try: if s.connect_ex(('127.0.0.1', cand_p)) == 0: active_px.append(cand_p) except Exception: pass finally: s.close() if not active_px: active_px = [10810] # Check if any existing ani_rs port failed lookup because it was bound to a non-existent 10811..10813 port need_restart_ani = False if len(active_px) == 1: for p in range(16970, 16978): lp = f"/opt/ani_rs/ani_{p}.log" if os.path.isfile(lp) and "Apple lookup connection failed" in open(lp, errors="ignore").read(): need_restart_ani = True break if need_restart_ani: subprocess.call("pkill -f '/opt/ani_rs/anisette-server' 2>/dev/null || true", shell=True) time.sleep(0.3) for k, p in enumerate(range(16970, 16978)): sdir = f"/opt/ani_rs/data_{p}" os.makedirs(sdir, mode=0o700, exist_ok=True) os.chmod(sdir, 0o700) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(0.05) is_up = (s.connect_ex(('127.0.0.1', p)) == 0) s.close() if not is_up: btype = "macos" if (p % 2 == 0) else "windows" px_p = active_px[k % len(active_px)] env = os.environ.copy() env["HTTPS_PROXY"] = f"http://127.0.0.1:{px_p}" env["HTTP_PROXY"] = f"http://127.0.0.1:{px_p}" lf = open(f"/opt/ani_rs/ani_{p}.log", "wb") subprocess.Popen( ["/opt/ani_rs/lib/ld-linux-x86-64.so.2", "--library-path", "/opt/ani_rs/lib", "/opt/ani_rs/anisette-server", "--backend", btype, "--listen", f"127.0.0.1:{p}", "--state-dir", sdir], stdin=subprocess.DEVNULL, stdout=lf, stderr=subprocess.STDOUT, env=env, close_fds=True, start_new_session=True ) time.sleep(1.5 + (198 % 10) * 0.35) sys.path.insert(0, '/root') try: import check try: os.remove('/tmp/jc_desktop_ani_refresh.lock') except Exception: pass if os.path.isfile('/dev/shm/jc_desktop_ani_pool.json'): os.utime('/dev/shm/jc_desktop_ani_pool.json', (0, 0)) check._refresh_desktop_ani_shm_once() except Exception: pass if need_restart_ani or not os.path.isfile('/tmp/reloaded_39fc87ad.flag'): with open('/tmp/reloaded_39fc87ad.flag', 'w') as ff: ff.write('1') subprocess.call("pkill -f '[p]ython3 -u (/root/)?check\\.py' 2>/dev/null || true", shell=True)