# INCTG - fresh installation, RouterOS 6.43+ with legacy wireless. # Export a backup and use Safe Mode. Do not import over an existing hotspot. :local guestSubnet "10.10.10.0/24" :local guestIP "10.10.10.1" :local backendIP "192.168.3.100" :local backendPort 3000 :local portalHost "hotspot.jf.eng.br" :local wanInterface "ether1" :local guestInterface "ether4" # Abort before changes when resources conflict. :if ([:len [/interface bridge find name="bridge-guest"]] > 0) do={ :error "Existing guest bridge: manual migration required" } :if ([:len [/interface bridge port find interface=$guestInterface]] > 0) do={ :error "Guest port is in another bridge: review topology in Safe Mode" } :if ([:len [/ip hotspot find name="guest-hotspot"]] > 0) do={ :error "Existing guest hotspot: manual migration required" } :if ([:len [/ip pool find name="guest-pool"]] > 0) do={ :error "Existing guest pool" } :if ([:len [/ip hotspot profile find name="hs-guest"]] > 0) do={ :error "Existing hotspot profile" } :if ([:len [/interface wireless find name="wlan1"]] = 0) do={ :error "Legacy wlan1 is required" } :if ([:len [/interface find name=$wanInterface]] = 0) do={ :error "WAN not found" } :if ([:len [/interface find name=$guestInterface]] = 0) do={ :error "Guest interface not found" } /interface bridge add name=bridge-guest comment="pix: guest network" /ip address add address=($guestIP . "/24") interface=bridge-guest comment="pix: guest gateway" /interface bridge port add bridge=bridge-guest interface=$guestInterface /interface wireless add master-interface=wlan1 name=wlan-guest ssid="Internet Gratis" mode=ap-bridge default-forwarding=no disabled=no /interface bridge port add bridge=bridge-guest interface=wlan-guest /ip pool add name=guest-pool ranges="10.10.10.10-10.10.10.50" /ip dhcp-server add name=guest-dhcp interface=bridge-guest address-pool=guest-pool lease-time=1h disabled=no /ip dhcp-server network add address=$guestSubnet gateway=$guestIP dns-server=1.1.1.1,8.8.8.8 comment="pix: DHCP" /ip hotspot profile add name=hs-guest hotspot-address=$guestIP html-directory=hotspot login-by=cookie,http-chap,http-pap dns-name="" /ip hotspot add name=guest-hotspot interface=bridge-guest address-pool=guest-pool profile=hs-guest disabled=no # RouterOS rate-limit is upload/download from the client perspective. # Preserve existing profiles and vouchers. :if ([:len [/ip hotspot user profile find name="pix-1h"]] = 0) do={ /ip hotspot user profile add name=pix-1h rate-limit=1M/5M shared-users=1 } :if ([:len [/ip hotspot user profile find name="pix-24h"]] = 0) do={ /ip hotspot user profile add name=pix-24h rate-limit=2M/8M shared-users=1 } :if ([:len [/ip hotspot user profile find name="pix-7d"]] = 0) do={ /ip hotspot user profile add name=pix-7d rate-limit=3M/10M shared-users=1 } /ip firewall nat add chain=srcnat out-interface=$wanInterface src-address=$guestSubnet action=masquerade comment="pix: NAT" # Private-network guard runs before existing accepts/fasttrack. # Internet returns to the ordinary chain so HotSpot filtering still applies. /ip firewall filter add chain=pix-guest-forward dst-address=$backendIP protocol=tcp dst-port=$backendPort action=accept comment="pix: portal LAN" /ip firewall filter add chain=pix-guest-forward dst-address=192.168.0.0/16 action=drop /ip firewall filter add chain=pix-guest-forward dst-address=10.0.0.0/8 action=drop /ip firewall filter add chain=pix-guest-forward dst-address=172.16.0.0/12 action=drop /ip firewall filter add chain=pix-guest-forward dst-address=169.254.0.0/16 action=drop /ip firewall filter add chain=pix-guest-forward action=return /ip firewall filter add chain=forward in-interface=bridge-guest action=jump jump-target=pix-guest-forward place-before=0 comment="pix: guest isolation" /ip firewall filter add chain=pix-guest-input protocol=udp dst-port=53,67,64872 action=accept /ip firewall filter add chain=pix-guest-input protocol=tcp dst-port=53,64872-64875 action=accept /ip firewall filter add chain=pix-guest-input action=drop /ip firewall filter add chain=input in-interface=bridge-guest action=jump jump-target=pix-guest-input place-before=0 comment="pix: router guard" # Restrict pre-login exception to the portal host, not all Cloudflare IPs. /ip hotspot walled-garden ip add dst-host=$portalHost dst-port=443 protocol=tcp action=accept comment="pix: public portal" /ip hotspot walled-garden ip add dst-address=$backendIP dst-port=$backendPort protocol=tcp action=accept comment="pix: local portal" # HotSpot is IPv4-only: prevent an IPv6 path around authentication. :do { /ipv6 firewall filter add chain=forward in-interface=bridge-guest action=drop place-before=0 comment="pix: block guest IPv6" /ipv6 firewall filter add chain=input in-interface=bridge-guest action=drop place-before=0 comment="pix: block guest IPv6 management" } on-error={ :log warning "pix: verify guest network has no IPv6 connectivity" } # Copy hotspot-login.html ONLY to hotspot/login.html; keep stock alogin.html # so the login dst parameter is honored. Restrict API service to backend LAN IP. :log info "pix-hotspot: setup complete; validate DHCP, DNS, login and isolation"