import base64, time from pathlib import Path import vps_ssh def put_b64(local, remote): data = Path(local).read_bytes() b64 = base64.b64encode(data).decode("ascii") vps_ssh.run("rm -f /tmp/wo_up.b64 /tmp/wo_up.bin", timeout=30) step=1200 for i in range(0, len(b64), step): chunk=b64[i:i+step] for attempt in range(5): try: code,_=vps_ssh.run(f"printf %s '{chunk}' >> /tmp/wo_up.b64", timeout=30) if code==0: break except Exception: time.sleep(1) else: raise SystemExit("chunk fail "+local) time.sleep(0.1) code, out = vps_ssh.run(f"base64 -d /tmp/wo_up.b64 > /tmp/wo_up.bin && wc -c /tmp/wo_up.bin && sudo cp /tmp/wo_up.bin {remote} && sudo chown www-data:www-data {remote}", timeout=60) print(Path(local).name, out) if code!=0: raise SystemExit(code) # Patch PHP blocks via marker replace for smaller transfer src = Path(r"c:\laragon\www\light-otantik-nux\deploy\saas\nux-custom\system\plugin\wifi_otantik.php").read_text(encoding="utf-8") # 1) rsc_captive ending a = src.find('function wifi_otantik_rsc_captive($r)') b = src.find('function wifi_otantik_ros_choice($router)') assert a>0 and b>a block1 = src[a:b] # 2) push_captive c = src.find('function wifi_otantik_push_captive($router)') d = src.find('function wifi_otantik_captive()') assert c>0 and d>c block2 = src[c:d] cap = Path(r"c:\laragon\www\light-otantik-nux\deploy\saas\nux-custom\system\autoload\OtantikCaptive.php").read_text(encoding="utf-8") remote_py = f''' p="/var/www/wifi-otantik/system/plugin/wifi_otantik.php" t=open(p,encoding="utf-8",errors="replace").read() a=t.find("function wifi_otantik_rsc_captive($r)") b=t.find("function wifi_otantik_ros_choice($router)") assert a>0 and b>a, (a,b) t=t[:a]+{block1!r}+t[b:] c=t.find("function wifi_otantik_push_captive($router)") d=t.find("function wifi_otantik_captive()") assert c>0 and d>c, (c,d) t=t[:c]+{block2!r}+t[d:] open(p,"w",encoding="utf-8").write(t) print("PHP_OK") p2="/var/www/wifi-otantik/system/autoload/OtantikCaptive.php" open(p2,"w",encoding="utf-8").write({cap!r}) print("CAPTIVE_OK") ''' b64=base64.b64encode(remote_py.encode()).decode() print("patcher", len(b64)) vps_ssh.run("rm -f /tmp/wo_php_patch.b64", timeout=30) for i in range(0,len(b64),1200): chunk=b64[i:i+1200] for attempt in range(5): try: code,_=vps_ssh.run(f"printf %s '{chunk}' >> /tmp/wo_php_patch.b64", timeout=30) if code==0: break except Exception: time.sleep(1) else: raise SystemExit("patch chunk fail") time.sleep(0.1) code,out=vps_ssh.run("base64 -d /tmp/wo_php_patch.b64 > /tmp/wo_php_patch.py && sudo python3 /tmp/wo_php_patch.py && sudo php -l /var/www/wifi-otantik/system/plugin/wifi_otantik.php && sudo php -l /var/www/wifi-otantik/system/autoload/OtantikCaptive.php && sudo find /var/www/wifi-otantik/ui/compiled -type f -delete", timeout=120) print(out) raise SystemExit(code)