#!/usr/bin/env python3 """Force hotspot on LAN ports: disable switch chip offload on hs-bridge.""" from mk_rb4011_exec import run import paramiko from mk_rb4011_exec import JUMP, MK RSC = r""" :put "PORTAL-LAN START" /system backup save name=wo-before-portal-lan /interface bridge settings set use-ip-firewall=yes allow-fast-path=no /interface bridge set [find name=hs-bridge] fast-forward=no :foreach p in=[/interface bridge port find where bridge=hs-bridge and interface~"ether"] do={ :do { /interface bridge port set $p hw=no } on-error={} } /ip hotspot profile set [find name=hsprof1] login-by=cookie,http-chap,http-pap :do { /ip hotspot active remove [find where user~"^T-"] } on-error={} :put "PORTAL-LAN DONE" /interface bridge print where name=hs-bridge /interface bridge port print where bridge=hs-bridge /ip hotspot profile print where name=hsprof1 /ip hotspot print """ def main() -> None: 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", (MK[0], 22), ("127.0.0.1", 0)) mk = paramiko.SSHClient() mk.set_missing_host_key_policy(paramiko.AutoAddPolicy()) mk.connect(MK[0], username=MK[1], password=MK[2], sock=chan, timeout=25, allow_agent=False, look_for_keys=False) sftp = mk.open_sftp() with sftp.file("wo-portal-lan.rsc", "w") as f: f.write(RSC) sftp.close() stdin, stdout, stderr = mk.exec_command("/import file-name=wo-portal-lan.rsc", timeout=90) print(stdout.read().decode("utf-8", "replace")) err = stderr.read().decode("utf-8", "replace") if err.strip(): print("STDERR", err) mk.close() jump.close() if __name__ == "__main__": main()