#!/usr/bin/env python3 """Dump hotspot config from Hub RB2011 (local or WG) for comparison.""" from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) DUMP = r""" :put "===IDENTITY===" /system identity print :put "===BOARD===" /system resource print :put "===HS===" /ip hotspot print detail :put "===HSPROF===" /ip hotspot profile print detail :put "===HS-SERVER-PROF===" /ip hotspot user profile print :put "===WGARDEN===" /ip hotspot walled-garden print :put "===WGARDEN-IP===" /ip hotspot walled-garden ip print :put "===BIND===" /ip hotspot ip-binding print :put "===DNS===" /ip dns print :put "===DNS-STATIC===" /ip dns static print :put "===SERVICE-WWW===" /ip service print where name=www or name=www-ssl :put "===FILES===" /file print where name~"hotspot" :put "===COOKIE-LOGINBY===" /ip hotspot profile print where name=hs-otantik """ def dump_hub_local(): from mk_hub_exec import run return run(DUMP, timeout=90) def dump_hub_wg(): import paramiko from mk_nko_wg_exec import JUMP jump = paramiko.SSHClient() jump.set_missing_host_key_policy(paramiko.AutoAddPolicy()) jump.connect(JUMP[0], username=JUMP[1], password=JUMP[2], timeout=25, allow_agent=False, look_for_keys=False) chan = jump.get_transport().open_channel("direct-tcpip", ("10.88.0.6", 22), ("127.0.0.1", 0)) mk = paramiko.SSHClient() mk.set_missing_host_key_policy(paramiko.AutoAddPolicy()) mk.connect("10.88.0.6", username="admin", password="", sock=chan, timeout=25, allow_agent=False, look_for_keys=False) stdin, stdout, stderr = mk.exec_command(DUMP, timeout=90) out = stdout.read().decode("utf-8", "replace") + stderr.read().decode("utf-8", "replace") mk.close() jump.close() return out.strip() def sftp_login(via: str) -> str: import paramiko if via == "local": from mk_hub_exec import connect mk = connect() sftp = mk.open_sftp() with sftp.file("hotspot/login.html", "r") as f: body = f.read() sftp.close() mk.close() else: from mk_nko_wg_exec import JUMP jump = paramiko.SSHClient() jump.set_missing_host_key_policy(paramiko.AutoAddPolicy()) jump.connect(JUMP[0], username=JUMP[1], password=JUMP[2], timeout=25, allow_agent=False, look_for_keys=False) chan = jump.get_transport().open_channel("direct-tcpip", ("10.88.0.6", 22), ("127.0.0.1", 0)) mk = paramiko.SSHClient() mk.set_missing_host_key_policy(paramiko.AutoAddPolicy()) mk.connect("10.88.0.6", username="admin", password="", sock=chan, timeout=25, allow_agent=False, look_for_keys=False) sftp = mk.open_sftp() with sftp.file("hotspot/login.html", "r") as f: body = f.read() sftp.close() mk.close() jump.close() if isinstance(body, bytes): body = body.decode("utf-8", "replace") return body if __name__ == "__main__": text = "" via = "none" try: text = dump_hub_local() via = "local" except Exception as e: print("local fail", e) text = dump_hub_wg() via = "wg" Path("_tmp_hub_hs_dump.txt").write_text(text, encoding="utf-8") print("DUMP via", via, "len", len(text)) body = sftp_login(via) Path("_tmp_hub_login.html").write_text(body, encoding="utf-8") print("login.html", len(body)) for needle in [ "wo.css", "woHotspotLite", "ui/ui_custom", "portal.otantik", "83.147", "wifi.otantik", "styles/bootstrap", "slide-1.jpg", "http://", "https://", ]: print(" ", needle, needle in body) print(text[-2500:])