network/mikrotik-tool/culleoka-opt82-hotspot.rsc
2026-07-19 14:42:02 -05:00

75 lines
4.4 KiB
Text

# On the DHCP server "culleoka" (ether2-netonix), update the lease script
# to add/remove hotspot bypass entries based on Option 82 presence.
# Devices WITH Option 82 → bypassed (internet access)
# Devices WITHOUT Option 82 → fall through to 0.0.0.0/0 type=blocked
/ip dhcp-server set lease-script="{\
\n:local url \"https://xtjlpnubrg.execute-api.us-east-1.amazonaws.com/production/on-start-workflow-execution/6f19a48f-04f7-40c1-a4e0-8cb66df99213/cdc24944-c947-4e01-9c54-07a1653d2e3e\"\
\n:local url2 \"https://iptrack.vntx.net/api/dhcp\"\
\n:local max 1\
\n\
\n:local attempts 0\
\n:local success1 0\
\n:local success2 0\
\n:do {\
\n :set attempts (\$attempts+1);\
\n :if (\$leaseBound = 0) do {\
\n # Deassign: remove hotspot bypass for this IP\
\n /ip hotspot ip-binding remove [find address=\$leaseActIP];\
\n\
\n :do {\
\n /tool fetch duration=30s mode=https url=\"\$url2\" http-method=post http-header-field=\"Content-Type: application/json\" http-data=\"{\\\"bound\\\":\\\"\$leaseBound\\\",\\\"mac\\\":\\\"\$leaseActMAC\\\",\\\"ip\\\":\\\"\$leaseActIP\\\",\\\"server\\\":\\\"\$leaseServerName\\\"}\"\
\n :set success1 1;\
\n :log info \"DHCP deassignment sent to iptrack for \$leaseActMAC / \$leaseActIP\";\
\n } on-error={\
\n :log error \"DHCP FAILED deassignment iptrack attempt \$attempts/\$max for \$leaseActMAC / \$leaseActIP\";\
\n }\
\n\
\n :do {\
\n /tool fetch duration=30s mode=https url=\"\$url\" http-method=post http-header-field=\"Content-Type: application/json\" http-data=\"{\\\"bound\\\":\\\"\$leaseBound\\\",\\\"mac\\\":\\\"\$leaseActMAC\\\",\\\"ip\\\":\\\"\$leaseActIP\\\",\\\"server\\\":\\\"\$leaseServerName\\\",\\\"remoteId\\\":\\\"\\\"}\"\
\n :set success2 1;\
\n :log info \"DHCP deassignment sent to gaiia for \$leaseActMAC / \$leaseActIP\";\
\n } on-error={\
\n :log error \"DHCP FAILED deassignment gaiia attempt \$attempts/\$max for \$leaseActMAC / \$leaseActIP\";\
\n }\
\n\
\n :if (\$success1 != 1 || \$success2 != 1) do={\
\n :delay 3s;\
\n }\
\n } else {\
\n :delay 1s;\
\n :local remoteID [/ip dhcp-server lease get [find where address=\$leaseActIP] agent-remote-id];\
\n\
\n # If Option 82 remote ID is present, bypass hotspot for this IP\
\n :if (\$remoteID != \"\") do={\
\n /ip hotspot ip-binding add address=\$leaseActIP mac-address=\$leaseActMAC server=hotspot1 to-address=\$leaseActIP type=bypassed;\
\n :log info \"DHCP Option 82 present for \$leaseActMAC / \$leaseActIP (remoteID=\$remoteID) - hotspot bypassed\";\
\n } else={\
\n :log warning \"DHCP NO Option 82 for \$leaseActMAC / \$leaseActIP - staying blocked by hotspot\";\
\n }\
\n\
\n :do {\
\n /tool fetch duration=30s mode=https url=\"\$url2\" http-method=post http-header-field=\"Content-Type: application/json\" http-data=\"{\\\"bound\\\":\\\"\$leaseBound\\\",\\\"mac\\\":\\\"\$leaseActMAC\\\",\\\"ip\\\":\\\"\$leaseActIP\\\",\\\"server\\\":\\\"\$leaseServerName\\\",\\\"remoteId\\\":\\\"\$remoteID\\\"}\"\
\n :set success1 1;\
\n :log info \"DHCP assignment sent to iptrack for \$leaseActMAC / \$leaseActIP / \$remoteID\";\
\n } on-error={\
\n :log error \"DHCP FAILED assignment iptrack attempt \$attempts/\$max for \$leaseActMAC / \$leaseActIP / \$remoteID\";\
\n }\
\n\
\n :do {\
\n /tool fetch duration=30s mode=https url=\"\$url\" http-method=post http-header-field=\"Content-Type: application/json\" http-data=\"{\\\"bound\\\":\\\"\$leaseBound\\\",\\\"mac\\\":\\\"\$leaseActMAC\\\",\\\"ip\\\":\\\"\$leaseActIP\\\",\\\"server\\\":\\\"\$leaseServerName\\\",\\\"remoteId\\\":\\\"\$remoteID\\\"}\"\
\n :set success2 1;\
\n :log info \"DHCP assignment sent to gaiia for \$leaseActMAC / \$leaseActIP / \$remoteID\";\
\n } on-error={\
\n :log error \"DHCP FAILED assignment gaiia attempt \$attempts/\$max for \$leaseActMAC / \$leaseActIP / \$remoteID\";\
\n }\
\n\
\n :if (\$success1 != 1 || \$success2 != 1) do={\
\n :delay 30s;\
\n }\
\n }\
\n :if (\$success1 = 1 && \$success2 = 1) do {\
\n :set attempts \$max;\
\n }\
\n} while ( \$attempts < \$max )\
\n}" [find name=culleoka]