mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-12-22 01:39:30 +00: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
|
|
@ -13,26 +13,36 @@
|
|||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||
|
||||
:global LogPrintExit2;
|
||||
:global ParseKeyValueStore;
|
||||
:global ScriptLock;
|
||||
|
||||
$ScriptLock $0 false 10;
|
||||
|
||||
: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;
|
||||
: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/access-list/find where comment~"^hotspot-to-wpa:" and \
|
||||
:foreach Client in=[ /caps-man/registration-table/find where comment~"^hotspot-to-wpa:" ] do={
|
||||
: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={
|
||||
$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:" \
|
||||
!(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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue