mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-06-21 09:25:42 +02:00
hotspot-to-wpa-cleanup: drop hard-coded server name, find by comment
This commit is contained in:
parent
0c8bc60648
commit
16a551a0ee
4 changed files with 27 additions and 14 deletions
|
@ -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;
|
/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
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
:local 0 "global-functions";
|
:local 0 "global-functions";
|
||||||
|
|
||||||
# expected configuration version
|
# expected configuration version
|
||||||
:global ExpectedConfigVersion 102;
|
:global ExpectedConfigVersion 103;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
|
|
@ -13,26 +13,36 @@
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
|
:global ParseKeyValueStore;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
|
|
||||||
$ScriptLock $0 false 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
:foreach Client in=[ /caps-man/registration-table/find where comment~"^hotspot-to-wpa:" ] do={
|
:foreach Client in=[ /caps-man/registration-table/find where comment~"^hotspot-to-wpa:" ] do={
|
||||||
:local ClientVal [ /caps-man/registration-table/get $Client ];
|
:local ClientVal [ /caps-man/registration-table/get $Client ];
|
||||||
:local Lease [ /ip/dhcp-server/lease/find where server~"wpa" dynamic \
|
:foreach Lease in=[ /ip/dhcp-server/lease/find where dynamic \
|
||||||
mac-address=($ClientVal->"mac-address") ];
|
mac-address=($ClientVal->"mac-address") ] do={
|
||||||
:if ([ :len $Lease ] > 0) do={
|
:if (($DHCPServers->[ /ip/dhcp-server/lease/get $Lease server ]) = 1) do={
|
||||||
$LogPrintExit2 info $0 ("Client with mac address " . ($ClientVal->"mac-address") . \
|
$LogPrintExit2 info $0 ("Client with mac address " . ($ClientVal->"mac-address") . \
|
||||||
" connected to WPA, making lease static.") false;
|
" connected to WPA, making lease static.") false;
|
||||||
/ip/dhcp-server/lease/make-static $Lease;
|
/ip/dhcp-server/lease/make-static $Lease;
|
||||||
/ip/dhcp-server/lease/set comment=($ClientVal->"comment") $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={
|
!(comment~[ /system/clock/get date ]) ] do={
|
||||||
:local ClientVal [ /caps-man/access-list/get $Client ];
|
: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={
|
mac-address=($ClientVal->"mac-address") ] ] = 0) do={
|
||||||
$LogPrintExit2 info $0 ("Client with mac address " . ($ClientVal->"mac-address") . \
|
$LogPrintExit2 info $0 ("Client with mac address " . ($ClientVal->"mac-address") . \
|
||||||
" did not connect to WPA, removing from access list.") false;
|
" did not connect to WPA, removing from access list.") false;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
100="The script 'ssh-keys-import' became a module 'mod/ssh-keys-import' with enhanced functionality.";
|
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.";
|
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.";
|
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
|
# Migration steps to be applied on script updates
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue