#!/usr/bin/env python3 from __future__ import annotations import ftplib import io import sys from pathlib import Path ROOT = Path(r"c:\laragon\www\light-otantik-nux") sys.path.insert(0, str(ROOT / "scripts")) from deploy_remote import connect, sudo # noqa: E402 FILES = [ (ROOT / "deploy/nux-custom/system/paymentgateway/mesomb.php", "/var/www/phpnuxbill/system/paymentgateway/mesomb.php"), (ROOT / "deploy/nux-custom/system/controllers/portal.php", "/var/www/phpnuxbill/system/controllers/portal.php"), (ROOT / "deploy/nux-custom/ui/ui/portal/index.tpl", "/var/www/phpnuxbill/ui/ui/portal/index.tpl"), (ROOT / "deploy/nux-custom/ui/ui/portal/pay.tpl", "/var/www/phpnuxbill/ui/ui/portal/pay.tpl"), (ROOT / "deploy/nux-custom/ui/ui/portal/voucher.tpl", "/var/www/phpnuxbill/ui/ui/portal/voucher.tpl"), (ROOT / "deploy/nux-custom/ui/ui/portal/wait.tpl", "/var/www/phpnuxbill/ui/ui/portal/wait.tpl"), (ROOT / "deploy/nux-custom/ui/ui/portal/recover.tpl", "/var/www/phpnuxbill/ui/ui/portal/recover.tpl"), ] REPAIR = r'''where("gateway","mesomb")->where("status",2)->where("user_id",0)->find_many(); foreach ($rows as $row) { $creds = mesomb_fulfill_portal($row); echo $row["id"]." ".$row["username"]." -> ".$creds["username"].":".$creds["password"]." mk=".(empty($creds["mikrotik_ok"])?"0":"1")."\n"; } echo "DONE\n"; ''' def main() -> int: html = (ROOT / "scripts" / "hotspot-login.html").read_bytes().replace(b"\r\n", b"\n") ftp = ftplib.FTP() ftp.encoding = "latin-1" ftp.connect("192.168.88.1", 21, timeout=10) ftp.login("admin", "") ftp.cwd("hotspot") ftp.storbinary("STOR login.html", io.BytesIO(html)) print("ftp login.html", len(html)) ftp.quit() client = connect() sftp = client.open_sftp() for i, (local, remote) in enumerate(FILES): data = local.read_bytes().replace(b"\r\n", b"\n") tmp = f"/tmp/pfix_{i}_{Path(remote).name}" with sftp.file(tmp, "wb") as f: f.write(data) print("uploaded", local.name, len(data), flush=True) with sftp.file("/tmp/repair_words.php", "w") as f: f.write(REPAIR.replace("\r\n", "\n")) sftp.close() copies = " && ".join( f"install -m 644 /tmp/pfix_{i}_{Path(remote).name} {remote}" for i, (_, remote) in enumerate(FILES) ) cmd = ( copies + " && chown -R www-data:www-data /var/www/phpnuxbill/ui/ui/portal /var/www/phpnuxbill/system/controllers/portal.php /var/www/phpnuxbill/system/paymentgateway/mesomb.php" + " && php -l /var/www/phpnuxbill/system/paymentgateway/mesomb.php" + " && php -l /var/www/phpnuxbill/system/controllers/portal.php" + " && find /var/www/phpnuxbill/ui/compiled -type f -delete" + " && php /tmp/repair_words.php" ) code, out = sudo(client, cmd, timeout=60) print(out) print("CODE", code) client.close() return code if __name__ == "__main__": raise SystemExit(main())