#!/usr/bin/env python3 """Office = ether2+ether3. Hotspot = other LAN ports + WiFi. Do not touch WAN ether1.""" from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from mk_hub_exec import import_rsc, run RSC = r""" :put "HUB-PORTAL-LAN START" /system backup save name=wo-before-hub-portal-lan :if ([:len [/interface bridge find name="bridge-hotspot"]] = 0) do={ /interface bridge add name=bridge-hotspot protocol-mode=none comment=wifi-otantik-hs } # Office LAN only: ether2 + ether3 :do { /interface bridge port set [find interface=ether2] bridge=bridge hw=yes comment=defconf } on-error={} :do { /interface bridge port set [find interface=ether3] bridge=bridge hw=yes comment=defconf } on-error={} # Remaining LAN (never ether1) onto hotspot, CPU path :do { /interface bridge port set [find interface=ether4] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :do { /interface bridge port set [find interface=ether5] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :do { /interface bridge port set [find interface=ether6] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :do { /interface bridge port set [find interface=ether7] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :do { /interface bridge port set [find interface=ether8] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :do { /interface bridge port set [find interface=ether9] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :do { /interface bridge port set [find interface=ether10] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :do { /interface bridge port set [find interface=sfp1] bridge=bridge-hotspot hw=no comment=wifi-otantik-hs } on-error={} :if ([:len [/interface bridge port find interface=wlan1]] = 0) do={ :do { /interface bridge port add bridge=bridge-hotspot interface=wlan1 comment=wifi-otantik-hs } on-error={} } else={ :do { /interface bridge port set [find interface=wlan1] bridge=bridge-hotspot comment=wifi-otantik-hs } on-error={} } /interface bridge settings set use-ip-firewall=yes allow-fast-path=no /interface bridge set [find name=bridge-hotspot] fast-forward=no :foreach p in=[/interface bridge port find where bridge=bridge-hotspot] do={ :local iname [/interface bridge port get $p interface] :if ($iname != "wlan1") do={ :do { /interface bridge port set $p hw=no } on-error={} } } :do { /ip hotspot set [find name=hotspot-otantik] interface=bridge-hotspot disabled=no } on-error={} :do { /ip hotspot profile set [find name=hs-otantik] hotspot-address=10.8.192.1 } on-error={} :if ([:len [/interface list member find where list=LAN and interface=bridge-hotspot]] = 0) do={ :do { /interface list member add list=LAN interface=bridge-hotspot comment=wifi-otantik-hs } on-error={} } :if ([:len [/ip firewall filter find comment="wifi-otantik-hs-no-fasttrack"]] = 0) do={ /ip firewall filter add chain=forward src-address=10.8.192.0/18 action=accept comment=wifi-otantik-hs-no-fasttrack place-before=0 /ip firewall filter add chain=forward dst-address=10.8.192.0/18 action=accept comment=wifi-otantik-hs-no-fasttrack place-before=0 } :if ([:len [/ip firewall nat find comment="wifi-otantik-hs-masq-18"]] = 0) do={ /ip firewall nat add chain=srcnat src-address=10.8.192.0/18 action=masquerade comment=wifi-otantik-hs-masq-18 } :put "HUB-PORTAL-LAN DONE" /interface bridge port print /ip hotspot print /interface bridge print where name=bridge-hotspot /interface bridge settings print """ def main() -> None: print("backup-only", run("/system backup save name=wo-before-hub-portal-lan", timeout=40)[:200]) print("==== IMPORT ====") print(import_rsc("wo-hub-portal-lan.rsc", RSC, timeout=180)) print("==== PING WG ====") print(run("/ping 10.88.0.1 count=3", timeout=25)) if __name__ == "__main__": main()