diff options
author | Christian Hesse <mail@eworm.de> | 2023-06-27 21:59:18 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2023-06-28 11:26:51 +0200 |
commit | 64ab9eec6756a95df14471b0ebf0f3014c478e9a (patch) | |
tree | bff8e2ef7d13e6d3d1b12b0769d2bce817bc630f | |
parent | 16a551a0ee712b81dc267e50414ceee39d434edc (diff) |
hotspot-to-wpa-cleanup: drop hard-coded timeout, get from comment
This keeps the default of four weeks, though.
-rw-r--r-- | doc/hotspot-to-wpa.md | 5 | ||||
-rw-r--r-- | hotspot-to-wpa-cleanup.rsc | 27 | ||||
-rw-r--r-- | news-and-changes.rsc | 2 |
3 files changed, 22 insertions, 12 deletions
diff --git a/doc/hotspot-to-wpa.md b/doc/hotspot-to-wpa.md index 5cbe22c..2630694 100644 --- a/doc/hotspot-to-wpa.md +++ b/doc/hotspot-to-wpa.md @@ -44,6 +44,11 @@ this example the server is called `hotspot-to-wpa`. /ip/dhcp-server/set lease-script=lease-script comment="hotspot-to-wpa=wpa" hotspot-to-wpa; +You can specify the timeout after which a device is removed from leases and +access-list. The default is four weeks. + + /ip/dhcp-server/set lease-script=lease-script comment="hotspot-to-wpa=wpa, timeout=2w" hotspot-to-wpa; + Configuration ------------- diff --git a/hotspot-to-wpa-cleanup.rsc b/hotspot-to-wpa-cleanup.rsc index b3aba11..adb0abb 100644 --- a/hotspot-to-wpa-cleanup.rsc +++ b/hotspot-to-wpa-cleanup.rsc @@ -12,6 +12,7 @@ :global GlobalFunctionsReady; :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } +:global EitherOr; :global LogPrintExit2; :global ParseKeyValueStore; :global ScriptLock; @@ -21,8 +22,10 @@ $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; + :local ServerInfo [ $ParseKeyValueStore ($ServerVal->"comment") ]; + :if (($ServerInfo->"hotspot-to-wpa") = "wpa") do={ + :set ($DHCPServers->($ServerVal->"name")) \ + [ :totime [ $EitherOr ($ServerInfo->"timeout") 4w ] ]; } } @@ -30,7 +33,7 @@ $ScriptLock $0 false 10; :local ClientVal [ /caps-man/registration-table/get $Client ]; :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={ + :if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) > 0s) 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; @@ -50,12 +53,14 @@ $ScriptLock $0 false 10; } } -:foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status=waiting \ - last-seen>4w comment~"^hotspot-to-wpa:" ] do={ - :local LeaseVal [ /ip/dhcp-server/lease/get $Lease ]; - $LogPrintExit2 info $0 ("Client with mac address " . ($LeaseVal->"mac-address") . \ - " was not seen for long time, removing.") false; - /caps-man/access-list/remove [ find where comment~"^hotspot-to-wpa:" \ - mac-address=($LeaseVal->"mac-address") ]; - /ip/dhcp-server/lease/remove $Lease; +:foreach Server,Timeout in=$DHCPServers do={ + :foreach Lease in=[ /ip/dhcp-server/lease/find where !dynamic status="waiting" \ + server=$Server last-seen>$Timeout comment~"^hotspot-to-wpa:" ] do={ + :local LeaseVal [ /ip/dhcp-server/lease/get $Lease ]; + $LogPrintExit2 info $0 ("Client with mac address " . ($LeaseVal->"mac-address") . \ + " was not seen for " . $Timeout . ", removing.") false; + /caps-man/access-list/remove [ find where comment~"^hotspot-to-wpa:" \ + mac-address=($LeaseVal->"mac-address") ]; + /ip/dhcp-server/lease/remove $Lease; + } } diff --git a/news-and-changes.rsc b/news-and-changes.rsc index fd7742e..572f431 100644 --- a/news-and-changes.rsc +++ b/news-and-changes.rsc @@ -16,7 +16,7 @@ 100="The script 'ssh-keys-import' became a module 'mod/ssh-keys-import' with enhanced functionality."; 101="Introduced new script 'fw-addr-lists' to download, import and update firewall address-lists."; 102="Modified 'hotspot-to-wpa' to support non-local (radius) users."; - 103="Dropped hard-coded name from 'hotspot-to-wpa-cleanup', instead a comment is required for dhcp server now."; + 103="Dropped hard-coded name and timeout from 'hotspot-to-wpa-cleanup', instead a comment is required for dhcp server now."; }; # Migration steps to be applied on script updates |