#!/usr/bin/env python3 """Upload generated chat.html and allow Intergram in the walled garden.""" from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) import paramiko import vps_ssh from mk_fix_trial_dst import hub_connect from mk_nko_wg_exec import connect_mk as nko_connect HOSTS = ( "intergram.xyz", "www.intergram.xyz", "*.intergram.xyz", ) def vps_chat(slug: str) -> bytes: cmd = ( "curl -sS -A Mozilla -H Host:portal.otantik.cm " f"'http://127.0.0.1/wifi/{slug}/chat.html'" ) code, out = vps_ssh.run(cmd, timeout=45, sudo=False) if code != 0 or "intergram.xyz" not in out: raise SystemExit(f"chat.html missing Intergram for {slug}: {out[:400]}") return out.encode("utf-8") def garden(mk: paramiko.SSHClient) -> None: for h in HOSTS: cmd = ( f':do {{ /ip hotspot walled-garden add dst-host="{h}" ' f'action=allow comment="wifi-otantik" }} on-error={{}}' ) mk.exec_command(cmd, timeout=20) def upload(mk: paramiko.SSHClient, html: bytes) -> None: sftp = mk.open_sftp() with sftp.file("hotspot/chat.html", "wb") as f: f.write(html) sftp.close() def main() -> None: hub_html = vps_chat("otantik-hub") nko_html = vps_chat("otantik-hub-nkoabang") print("hub bytes", len(hub_html), "nko bytes", len(nko_html), flush=True) print("=== RB2011 ===", flush=True) jump, mk = hub_connect() try: upload(mk, hub_html) garden(mk) print("ok hub", flush=True) finally: mk.close() jump.close() print("=== RB4011 ===", flush=True) jump, mk = nko_connect() try: upload(mk, nko_html) garden(mk) print("ok nko", flush=True) finally: mk.close() jump.close() print("DONE", flush=True) if __name__ == "__main__": main()