From 8d69d845766b461a6e04edf7b60ce8d69f745b90 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 31 Jul 2026 12:35:56 +0200 Subject: [PATCH] hotspot-to-wpa: early exit with :exit --- doc/hotspot-to-wpa.md | 2 +- hotspot-to-wpa.capsman.rsc | 11 ++++------- hotspot-to-wpa.template.rsc | 11 ++++------- hotspot-to-wpa.wifi.rsc | 11 ++++------- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/doc/hotspot-to-wpa.md b/doc/hotspot-to-wpa.md index 5a00f44e..1a04d2a2 100644 --- a/doc/hotspot-to-wpa.md +++ b/doc/hotspot-to-wpa.md @@ -4,7 +4,7 @@ Use WPA network with hotspot credentials [![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers) [![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network) [![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers) -[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.21-yellow?style=flat)](https://mikrotik.com/download/changelogs/) +[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.22-yellow?style=flat)](https://mikrotik.com/download/changelogs/) [![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts) [![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J) diff --git a/hotspot-to-wpa.capsman.rsc b/hotspot-to-wpa.capsman.rsc index c5fd7848..82eb908a 100644 --- a/hotspot-to-wpa.capsman.rsc +++ b/hotspot-to-wpa.capsman.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2019-2026 Christian Hesse # 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); } diff --git a/hotspot-to-wpa.template.rsc b/hotspot-to-wpa.template.rsc index e9a823a7..fb9fee62 100644 --- a/hotspot-to-wpa.template.rsc +++ b/hotspot-to-wpa.template.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2019-2026 Christian Hesse # 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 # @@ -13,7 +13,6 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. -:local ExitOK false; :onerror Err { :local ScriptName [ :jobname ]; @@ -27,16 +26,14 @@ :if ([ :len [ /interface/wifi/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 \ @@ -50,5 +47,5 @@ :delay 1s; /ip/dhcp-server/lease/disable $Lease; } do={ - :if ($ExitOK = false) do={ :log error ([ :jobname ] . ": " . $Err); } + :log error ([ :jobname ] . ": " . $Err); } diff --git a/hotspot-to-wpa.wifi.rsc b/hotspot-to-wpa.wifi.rsc index cbd6798a..5f7222ea 100644 --- a/hotspot-to-wpa.wifi.rsc +++ b/hotspot-to-wpa.wifi.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2019-2026 Christian Hesse # 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 ([ :len [ /interface/wifi/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); }