aboutsummaryrefslogtreecommitdiffstats
path: root/hotspot-to-wpa-cleanup.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-06-26 21:18:51 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-06-28 11:26:51 +0200
commita030e2f9468474bb883b36cae0828da575edcdb6 (patch)
treebff8e2ef7d13e6d3d1b12b0769d2bce817bc630f /hotspot-to-wpa-cleanup.rsc
parent5ba34c819a93e27b0eb4c56e25435fe522e16ee3 (diff)
parent64ab9eec6756a95df14471b0ebf0f3014c478e9a (diff)
Merge branch 'hotspot-to-wpa' into next
Diffstat (limited to 'hotspot-to-wpa-cleanup.rsc')
-rw-r--r--hotspot-to-wpa-cleanup.rsc49
1 files changed, 32 insertions, 17 deletions
diff --git a/hotspot-to-wpa-cleanup.rsc b/hotspot-to-wpa-cleanup.rsc
index 15f63f9..adb0abb 100644
--- a/hotspot-to-wpa-cleanup.rsc
+++ b/hotspot-to-wpa-cleanup.rsc
@@ -12,27 +12,40 @@
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
+:global EitherOr;
: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 ]
+ :local ServerInfo [ $ParseKeyValueStore ($ServerVal->"comment") ];
+ :if (($ServerInfo->"hotspot-to-wpa") = "wpa") do={
+ :set ($DHCPServers->($ServerVal->"name")) \
+ [ :totime [ $EitherOr ($ServerInfo->"timeout") 4w ] ];
+ }
+}
+
: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 ]) > 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;
+ /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;
@@ -40,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;
+ }
}