aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-06-23 22:30:34 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-06-28 11:26:51 +0200
commit16a551a0ee712b81dc267e50414ceee39d434edc (patch)
tree2061fce49039c6f0c0b71c4ab13289d38ebd35e2
parent0c8bc60648c2b5629273bf64bce81c664470506c (diff)
hotspot-to-wpa-cleanup: drop hard-coded server name, find by commentchange-103
-rw-r--r--doc/hotspot-to-wpa.md6
-rw-r--r--global-functions.rsc2
-rw-r--r--hotspot-to-wpa-cleanup.rsc28
-rw-r--r--news-and-changes.rsc1
4 files changed, 25 insertions, 12 deletions
diff --git a/doc/hotspot-to-wpa.md b/doc/hotspot-to-wpa.md
index 097cba4..5cbe22c 100644
--- a/doc/hotspot-to-wpa.md
+++ b/doc/hotspot-to-wpa.md
@@ -38,9 +38,11 @@ Create a scheduler:
/system/scheduler/add interval=1d name=hotspot-to-wpa-cleanup on-event="/system/script/run hotspot-to-wpa-cleanup;" start-time=startup;
-And add the lease script to your wpa interfaces' dhcp server:
+And add the lease script and matcher comment to your wpa interfaces' dhcp
+server. You can add more information to the comment, separated by comma. In
+this example the server is called `hotspot-to-wpa`.
- /ip/dhcp-server/set lease-script=lease-script [ find where name~"wpa" ];
+ /ip/dhcp-server/set lease-script=lease-script comment="hotspot-to-wpa=wpa" hotspot-to-wpa;
Configuration
-------------
diff --git a/global-functions.rsc b/global-functions.rsc
index 0378775..205f67a 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -12,7 +12,7 @@
:local 0 "global-functions";
# expected configuration version
-:global ExpectedConfigVersion 102;
+:global ExpectedConfigVersion 103;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
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;
diff --git a/news-and-changes.rsc b/news-and-changes.rsc
index b062c5e..fd7742e 100644
--- a/news-and-changes.rsc
+++ b/news-and-changes.rsc
@@ -16,6 +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.";
};
# Migration steps to be applied on script updates