mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
hotspot-to-wpa-cleanup: drop hard-coded timeout, get from comment
This keeps the default of four weeks, though.
This commit is contained in:
parent
16a551a0ee
commit
64ab9eec67
|
@ -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
|
||||
-------------
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue