#!/usr/bin/env python3 """Rename zone, split ether10 off hotspot, dual-band SSIDs. Keep users/plans on the box.""" from __future__ import annotations import time import paramiko JUMP = ("100.80.255.113", "otantik", "DeararbsFr2@") MK = ("172.30.0.1", "admin", "demopass") RSC = r""" :put "NKOABANG START" /system backup save name=wo-before-nkoabang /system identity set name=Otantik_Hub_Nkoabang /interface wireless set [find name=wlan2] ssid="Otantik Hub Nkoabang" disabled=no mode=ap-bridge :do { /interface wireless set [find name=wlan1] ssid="Otantik Hub Nkoabang 5G" disabled=no mode=ap-bridge band=5ghz-a/n/ac frequency=5180 channel-width=20/40/80mhz-Ceee wireless-protocol=802.11 } on-error={ :do { /interface wireless set [find name=wlan1] ssid="Otantik Hub Nkoabang 5G" disabled=no mode=ap-bridge } on-error={} } :do { /interface wireless enable wlan1 } on-error={} :if ([:len [/interface bridge find name="lan-office"]] = 0) do={ /interface bridge add name=lan-office protocol-mode=none comment="ether10 no portal" } :do { /interface bridge port set [find interface=ether10] bridge=lan-office } on-error={} :delay 1s :do { /ip address set [find where address="172.30.0.1/16"] interface=lan-office } on-error={} :if ([:len [/interface list member find where list=LAN and interface=lan-office]] = 0) do={ :do { /interface list member add list=LAN interface=lan-office } on-error={} } :if ([:len [/ip pool find name="office-pool"]] = 0) do={ /ip pool add name=office-pool ranges=172.30.10.20-172.30.10.250 } :do { /ip dhcp-server lease remove [find where mac-address=00:0C:29:28:33:75 and server=dhcp-hs] } on-error={} :if ([:len [/ip dhcp-server find name="dhcp-office"]] = 0) do={ /ip dhcp-server add name=dhcp-office interface=lan-office address-pool=office-pool lease-time=12h disabled=no } else={ /ip dhcp-server set [find name=dhcp-office] interface=lan-office disabled=no } :if ([:len [/ip dhcp-server lease find where mac-address=00:0C:29:28:33:75]] = 0) do={ :do { /ip dhcp-server lease add address=172.30.10.26 mac-address=00:0C:29:28:33:75 server=dhcp-office comment=otantik-jump } on-error={} } :if ([:len [/ip firewall nat find comment="wifi-otantik-office-masq"]] = 0) do={ /ip firewall nat add chain=srcnat src-address=172.30.0.0/16 action=masquerade comment=wifi-otantik-office-masq } /ip hotspot profile set [find name=hsprof1] hotspot-address=10.5.53.1 :do { /ip hotspot enable [find name=hotspot1] } on-error={} :do { /ip hotspot ip-binding remove [find comment="wifi-otantik-lan-bypass"] } on-error={} :do { /ip hotspot ip-binding remove [find where address="172.30.0.0/16"] } on-error={} :if ([:len [/ip hotspot ip-binding find address="100.80.255.113"]] = 0) do={ /ip hotspot ip-binding add address=100.80.255.113 type=bypassed comment=Otantik_Hub_Server } :if ([:len [/ip hotspot ip-binding find address="172.30.10.26"]] = 0) do={ /ip hotspot ip-binding add address=172.30.10.26 type=bypassed comment=localOtantikHub } :put "NKOABANG DONE" /system identity print /interface wireless print /interface bridge port print where interface=ether10 /ip address print where address~"172.30" /ip hotspot ip-binding print /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-nkoabang.rsc", "w") as f: f.write(RSC) sftp.close() stdin, stdout, stderr = mk.exec_command("/import file-name=wo-nkoabang.rsc", timeout=120) out = stdout.read().decode("utf-8", "replace") err = stderr.read().decode("utf-8", "replace") print(out) if err.strip(): print("STDERR", err) mk.close() jump.close() if __name__ == "__main__": main()