hotspot-to-wpa: early exit with :exit

This commit is contained in:
Christian Hesse 2026-07-31 12:35:56 +02:00
parent 627145ba07
commit 8d69d84576
4 changed files with 13 additions and 22 deletions

View file

@ -3,7 +3,7 @@
# Copyright (c) 2019-2026 Christian Hesse <mail@eworm.de>
# https://rsc.eworm.de/COPYING.md
#
# requires RouterOS, version=7.21
# requires RouterOS, version=7.22
# requires device-mode, hotspot
# requires policy, policy=read;write
#
@ -12,7 +12,6 @@
#
# !! Do not edit this file, it is generated from template!
:local ExitOK false;
:onerror Err {
:local ScriptName [ :jobname ];
@ -25,16 +24,14 @@
:if ([ /caps-man/access-list/find where \
comment=("hotspot-to-wpa template " . $Hotspot) disabled action="reject" ] ] > 0) do={
:log info ($ScriptName . ": Ignoring login for " . $MacAddress . " on hotspot '" . $Hotspot . "'.");
:set ExitOK true;
:error false;
:exit;
}
:local Lease [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=$Address ];
:if ([ :len $Lease ] != 1) do={
:log warning ($ScriptName . ": Did not find exactly one lease for " . $MacAddress . "!");
:set ExitOK true;
:error false;
:exit;
}
/ip/dhcp-server/lease/set \
@ -48,5 +45,5 @@
:delay 1s;
/ip/dhcp-server/lease/disable $Lease;
} do={
:if ($ExitOK = false) do={ :log error ([ :jobname ] . ": " . $Err); }
:log error ([ :jobname ] . ": " . $Err);
}