diff options
author | Christian Hesse <mail@eworm.de> | 2023-06-23 22:30:34 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2023-06-28 11:26:51 +0200 |
commit | 16a551a0ee712b81dc267e50414ceee39d434edc (patch) | |
tree | 2061fce49039c6f0c0b71c4ab13289d38ebd35e2 /hotspot-to-wpa-cleanup.rsc | |
parent | 0c8bc60648c2b5629273bf64bce81c664470506c (diff) |
hotspot-to-wpa-cleanup: drop hard-coded server name, find by commentchange-103
Diffstat (limited to 'hotspot-to-wpa-cleanup.rsc')
-rw-r--r-- | hotspot-to-wpa-cleanup.rsc | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/hotspot-to-wpa-cleanup.rsc b/hotspot-to-wpa-cleanup.rsc index 15f63f9..b3aba11 100644 --- a/hotspot-to-wpa-cleanup.rsc +++ b/hotspot-to-wpa-cleanup.rsc @@ -13,26 +13,36 @@ :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } :global LogPrintExit2; +:global ParseKeyValueStore; :global ScriptLock; $ScriptLock $0 false 10; +:local DHCPServers ({}); +:foreach Server in=[ /ip/dhcp-server/find where comment~"hotspot-to-wpa" ] do={ + :local ServerVal [ /ip/dhcp-server/get $Server ] + :if (([ $ParseKeyValueStore ($ServerVal->"comment") ]->"hotspot-to-wpa") = "wpa") do={ + :set ($DHCPServers->($ServerVal->"name")) 1; + } +} + :foreach Client in=[ /caps-man/registration-table/find where comment~"^hotspot-to-wpa:" ] do={ :local ClientVal [ /caps-man/registration-table/get $Client ]; - :local Lease [ /ip/dhcp-server/lease/find where server~"wpa" dynamic \ - mac-address=($ClientVal->"mac-address") ]; - :if ([ :len $Lease ] > 0) do={ - $LogPrintExit2 info $0 ("Client with mac address " . ($ClientVal->"mac-address") . \ - " connected to WPA, making lease static.") false; - /ip/dhcp-server/lease/make-static $Lease; - /ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease; + :foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \ + mac-address=($ClientVal->"mac-address") ] do={ + :if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) = 1) do={ + $LogPrintExit2 info $0 ("Client with mac address " . ($ClientVal->"mac-address") . \ + " connected to WPA, making lease static.") false; + /ip/dhcp-server/lease/make-static $Lease; + /ip/dhcp-server/lease/set comment=($ClientVal->"comment") $Lease; + } } } -:foreach Client in=[ /caps-man/access-list/find where comment~"^hotspot-to-wpa:" and \ +:foreach Client in=[ /caps-man/access-list/find where comment~"^hotspot-to-wpa:" \ !(comment~[ /system/clock/get date ]) ] do={ :local ClientVal [ /caps-man/access-list/get $Client ]; - :if ([ :len [ /ip/dhcp-server/lease/find where server~"wpa" !dynamic \ + :if ([ :len [ /ip/dhcp-server/lease/find where !dynamic comment~"^hotspot-to-wpa:" \ mac-address=($ClientVal->"mac-address") ] ] = 0) do={ $LogPrintExit2 info $0 ("Client with mac address " . ($ClientVal->"mac-address") . \ " did not connect to WPA, removing from access list.") false; |