From 54638924e4a06f926d3bdd3bbd44489acc692a75 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 6 Mar 2024 15:28:55 +0100 Subject: hotspot-to-wpa: drop main function, use :do with on-error --- hotspot-to-wpa.capsman.rsc | 19 +++++++++---------- hotspot-to-wpa.template.rsc | 19 +++++++++---------- hotspot-to-wpa.wifi.rsc | 19 +++++++++---------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/hotspot-to-wpa.capsman.rsc b/hotspot-to-wpa.capsman.rsc index 7498ae2..a6ad2a1 100644 --- a/hotspot-to-wpa.capsman.rsc +++ b/hotspot-to-wpa.capsman.rsc @@ -13,21 +13,22 @@ :global GlobalFunctionsReady; :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } -:local Main do={ - :local ScriptName [ :tostr $1 ]; - :local MacAddress [ :tostr $2 ]; - :local UserName [ :tostr $3 ]; +:do { + :local ScriptName [ :jobname ]; :global EitherOr; :global LogPrintExit2; :global ParseKeyValueStore; :global ScriptLock; + :local MacAddress $"mac-address"; + :local UserName $username; + :if ([ $ScriptLock $ScriptName ] = false) do={ - :return false; + :error false; } - :if ([ :len $MacAddress ] = 0 || [ :len $UserName ] = 0) do={ + :if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={ $LogPrintExit2 error $ScriptName ("This script is supposed to run from hotspot on login.") true; } @@ -55,7 +56,7 @@ :if ($Template->"action" = "reject") do={ $LogPrintExit2 info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.") false; - :return true; + :error true; } # allow login page to load @@ -93,6 +94,4 @@ :delay 2s; /caps-man/access-list/set $Entry action=accept; -} - -$Main [ :jobname ] $"mac-address" $username; +} on-error={ } diff --git a/hotspot-to-wpa.template.rsc b/hotspot-to-wpa.template.rsc index c96096c..b7869c4 100644 --- a/hotspot-to-wpa.template.rsc +++ b/hotspot-to-wpa.template.rsc @@ -14,21 +14,22 @@ :global GlobalFunctionsReady; :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } -:local Main do={ - :local ScriptName [ :tostr $1 ]; - :local MacAddress [ :tostr $2 ]; - :local UserName [ :tostr $3 ]; +:do { + :local ScriptName [ :jobname ]; :global EitherOr; :global LogPrintExit2; :global ParseKeyValueStore; :global ScriptLock; + :local MacAddress $"mac-address"; + :local UserName $username; + :if ([ $ScriptLock $ScriptName ] = false) do={ - :return false; + :error false; } - :if ([ :len $MacAddress ] = 0 || [ :len $UserName ] = 0) do={ + :if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={ $LogPrintExit2 error $ScriptName ("This script is supposed to run from hotspot on login.") true; } @@ -62,7 +63,7 @@ :if ($Template->"action" = "reject") do={ $LogPrintExit2 info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.") false; - :return true; + :error true; } # allow login page to load @@ -113,6 +114,4 @@ :delay 2s; /caps-man/access-list/set $Entry action=accept; /interface/wifi/access-list/set $Entry action=accept; -} - -$Main [ :jobname ] $"mac-address" $username; +} on-error={ } diff --git a/hotspot-to-wpa.wifi.rsc b/hotspot-to-wpa.wifi.rsc index 83f490d..e728d7f 100644 --- a/hotspot-to-wpa.wifi.rsc +++ b/hotspot-to-wpa.wifi.rsc @@ -13,21 +13,22 @@ :global GlobalFunctionsReady; :while ($GlobalFunctionsReady != true) do={ :delay 500ms; } -:local Main do={ - :local ScriptName [ :tostr $1 ]; - :local MacAddress [ :tostr $2 ]; - :local UserName [ :tostr $3 ]; +:do { + :local ScriptName [ :jobname ]; :global EitherOr; :global LogPrintExit2; :global ParseKeyValueStore; :global ScriptLock; + :local MacAddress $"mac-address"; + :local UserName $username; + :if ([ $ScriptLock $ScriptName ] = false) do={ - :return false; + :error false; } - :if ([ :len $MacAddress ] = 0 || [ :len $UserName ] = 0) do={ + :if ([ :typeof $MacAddress ] = "nothing" || [ :typeof $UserName ] = "nothing") do={ $LogPrintExit2 error $ScriptName ("This script is supposed to run from hotspot on login.") true; } @@ -55,7 +56,7 @@ :if ($Template->"action" = "reject") do={ $LogPrintExit2 info $ScriptName ("Ignoring login for hotspot '" . $Hotspot . "'.") false; - :return true; + :error true; } # allow login page to load @@ -90,6 +91,4 @@ :delay 2s; /interface/wifi/access-list/set $Entry action=accept; -} - -$Main [ :jobname ] $"mac-address" $username; +} on-error={ } -- cgit v1.2.3-54-g00ecf