diff --git a/DEBUG.md b/DEBUG.md index 66bf728a..d5e9beb7 100644 --- a/DEBUG.md +++ b/DEBUG.md @@ -42,7 +42,7 @@ Other actions (`disk`, `email`, `remote` or `support`) can be used as well. I do not recommend using `echo` - use [debug output](#debug-output) instead. -Disable or remove that setting to restore regular logging. +Disable or remote that setting to restore regular logging. ## Verbose output diff --git a/accesslist-duplicates.capsman.rsc b/accesslist-duplicates.capsman.rsc index 5e6cf0a0..27546c8d 100644 --- a/accesslist-duplicates.capsman.rsc +++ b/accesslist-duplicates.capsman.rsc @@ -10,11 +10,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :local Seen ({}); @@ -32,6 +32,6 @@ } :set ($Seen->$Mac) 1; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/accesslist-duplicates.local.rsc b/accesslist-duplicates.local.rsc index a6b4f417..589815d6 100644 --- a/accesslist-duplicates.local.rsc +++ b/accesslist-duplicates.local.rsc @@ -10,11 +10,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :local Seen ({}); @@ -32,6 +32,6 @@ } :set ($Seen->$Mac) 1; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/accesslist-duplicates.template.rsc b/accesslist-duplicates.template.rsc index e51198d8..ccbca3df 100644 --- a/accesslist-duplicates.template.rsc +++ b/accesslist-duplicates.template.rsc @@ -11,11 +11,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :local Seen ({}); @@ -41,6 +41,6 @@ } :set ($Seen->$Mac) 1; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/accesslist-duplicates.wifi.rsc b/accesslist-duplicates.wifi.rsc index cadacb6b..527ebb4b 100644 --- a/accesslist-duplicates.wifi.rsc +++ b/accesslist-duplicates.wifi.rsc @@ -10,11 +10,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :local Seen ({}); @@ -32,6 +32,6 @@ } :set ($Seen->$Mac) 1; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/backup-cloud.rsc b/backup-cloud.rsc index e41db275..c4e23b2a 100644 --- a/backup-cloud.rsc +++ b/backup-cloud.rsc @@ -9,11 +9,11 @@ # upload backup to MikroTik cloud # https://rsc.eworm.de/doc/backup-cloud.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global BackupRandomDelay; @@ -99,6 +99,6 @@ :set PackagesUpdateBackupFailure true; } $RmDir "tmpfs/backup-cloud"; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/backup-email.rsc b/backup-email.rsc index 632d2e60..d0973011 100644 --- a/backup-email.rsc +++ b/backup-email.rsc @@ -9,11 +9,11 @@ # create and email backup and config file # https://rsc.eworm.de/doc/backup-email.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global BackupPassword; @@ -135,6 +135,6 @@ :delay 1s; :set I ($I + 1); } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/backup-partition.rsc b/backup-partition.rsc index ae7ad030..1f0cf2ee 100644 --- a/backup-partition.rsc +++ b/backup-partition.rsc @@ -10,11 +10,11 @@ # save configuration to fallback partition # https://rsc.eworm.de/doc/backup-partition.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global BackupPartitionCopyBeforeFeatureUpdate; @@ -32,15 +32,14 @@ :global LogPrint; - :onerror Err { + :do { /partitions/copy-to $FallbackTo; $LogPrint info $ScriptName ("Copied RouterOS to partition '" . $FallbackToName . "'."); - } do={ - $LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . \ - $FallbackToName . "': " . $Err); + :return true; + } on-error={ + $LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . $FallbackToName . "'!"); :return false; } - :return true; } :if ([ $ScriptLock $ScriptName ] = false) do={ @@ -108,21 +107,20 @@ } } - :onerror Err { + :do { /system/scheduler/add start-time=startup name="running-from-backup-partition" \ on-event=(":log warning (\"Running from partition '\" . " . \ "[ /partitions/get [ find where running ] name ] . \"'!\")"); /partitions/save-config-to $FallbackTo; /system/scheduler/remove "running-from-backup-partition"; $LogPrint info $ScriptName ("Saved configuration to partition '" . $FallbackToName . "'."); - } do={ + } on-error={ /system/scheduler/remove [ find where name="running-from-backup-partition" ]; - $LogPrint error $ScriptName ("Failed saving configuration to partition '" . \ - $FallbackToName . "': " . $Err); + $LogPrint error $ScriptName ("Failed saving configuration to partition '" . $FallbackToName . "'!"); :set PackagesUpdateBackupFailure true; :set ExitOK true; :error false; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/backup-upload.rsc b/backup-upload.rsc index e6b9f92f..14c39141 100644 --- a/backup-upload.rsc +++ b/backup-upload.rsc @@ -10,11 +10,11 @@ # create and upload backup and config file # https://rsc.eworm.de/doc/backup-upload.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global BackupPassword; @@ -90,13 +90,13 @@ /system/backup/save encryption=aes-sha256 name=$FilePath password=$BackupPassword; $WaitForFile ($FilePath . ".backup"); - :onerror Err { + :do { /tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".backup") \ user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".backup"); :set BackupFile [ /file/get ($FilePath . ".backup") ]; :set ($BackupFile->"name") ($FileName . ".backup"); - } do={ - $LogPrint error $ScriptName ("Uploading backup file failed: " . $Err); + } on-error={ + $LogPrint error $ScriptName ("Uploading backup file failed!"); :set BackupFile "failed"; :set Failed 1; } @@ -109,13 +109,13 @@ /export terse show-sensitive file=$FilePath; $WaitForFile ($FilePath . ".rsc"); - :onerror Err { + :do { /tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".rsc") \ user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".rsc"); :set ExportFile [ /file/get ($FilePath . ".rsc") ]; :set ($ExportFile->"name") ($FileName . ".rsc"); - } do={ - $LogPrint error $ScriptName ("Uploading configuration export failed: " . $Err); + } on-error={ + $LogPrint error $ScriptName ("Uploading configuration export failed!"); :set ExportFile "failed"; :set Failed 1; } @@ -130,13 +130,13 @@ file=($FilePath . ".conf\00"); $WaitForFile ($FilePath . ".conf"); - :onerror Err { + :do { /tool/fetch upload=yes url=($BackupUploadUrl . "/" . $FileName . ".conf") \ user=$BackupUploadUser password=$BackupUploadPass src-path=($FilePath . ".conf"); :set ConfigFile [ /file/get ($FilePath . ".conf") ]; :set ($ConfigFile->"name") ($FileName . ".conf"); - } do={ - $LogPrint error $ScriptName ("Uploading global-config-overlay failed: " . $Err); + } on-error={ + $LogPrint error $ScriptName ("Uploading global-config-overlay failed!"); :set ConfigFile "failed"; :set Failed 1; } @@ -173,6 +173,6 @@ :set PackagesUpdateBackupFailure true; } $RmDir $DirName; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/capsman-download-packages.capsman.rsc b/capsman-download-packages.capsman.rsc index cab1e4c3..25c43f58 100644 --- a/capsman-download-packages.capsman.rsc +++ b/capsman-download-packages.capsman.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CleanFilePath; @@ -87,6 +87,6 @@ /caps-man/remote-cap/upgrade [ find where version!=$InstalledVersion ]; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/capsman-download-packages.template.rsc b/capsman-download-packages.template.rsc index ea411201..b2698382 100644 --- a/capsman-download-packages.template.rsc +++ b/capsman-download-packages.template.rsc @@ -12,11 +12,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CleanFilePath; @@ -98,6 +98,6 @@ /interface/wifi/capsman/remote-cap/upgrade [ find where version!=$InstalledVersion ]; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/capsman-download-packages.wifi.rsc b/capsman-download-packages.wifi.rsc index a8103569..901bb0af 100644 --- a/capsman-download-packages.wifi.rsc +++ b/capsman-download-packages.wifi.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CleanFilePath; @@ -89,6 +89,6 @@ /interface/wifi/capsman/remote-cap/upgrade [ find where version!=$InstalledVersion ]; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/capsman-rolling-upgrade.capsman.rsc b/capsman-rolling-upgrade.capsman.rsc index 0d4114a3..791b3dbb 100644 --- a/capsman-rolling-upgrade.capsman.rsc +++ b/capsman-rolling-upgrade.capsman.rsc @@ -12,11 +12,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -45,6 +45,6 @@ :delay ($Delay . "s"); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/capsman-rolling-upgrade.template.rsc b/capsman-rolling-upgrade.template.rsc index 690d73d8..0b1cc2ba 100644 --- a/capsman-rolling-upgrade.template.rsc +++ b/capsman-rolling-upgrade.template.rsc @@ -13,11 +13,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -53,6 +53,6 @@ :delay ($Delay . "s"); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/capsman-rolling-upgrade.wifi.rsc b/capsman-rolling-upgrade.wifi.rsc index 8e32ab20..4afdee2e 100644 --- a/capsman-rolling-upgrade.wifi.rsc +++ b/capsman-rolling-upgrade.wifi.rsc @@ -12,11 +12,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -46,6 +46,6 @@ :delay ($Delay . "s"); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/certificate-renew-issued.rsc b/certificate-renew-issued.rsc index 14917e4c..91a48dea 100644 --- a/certificate-renew-issued.rsc +++ b/certificate-renew-issued.rsc @@ -8,11 +8,11 @@ # renew locally issued certificates # https://rsc.eworm.de/doc/certificate-renew-issued.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CertIssuedExportPass; @@ -47,6 +47,6 @@ $LogPrint info $ScriptName ("Issued a new certificate for '" . $CertVal->"common-name" . "'."); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/check-certificates.rsc b/check-certificates.rsc index c10e33ba..be8e4dff 100644 --- a/check-certificates.rsc +++ b/check-certificates.rsc @@ -9,11 +9,11 @@ # check for certificate validity # https://rsc.eworm.de/doc/check-certificates.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CertRenewTime; @@ -237,6 +237,6 @@ ", it is invalid after " . ($CertVal->"invalid-after") . "."); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/check-health.rsc b/check-health.rsc index 4cb99408..f02a2491 100644 --- a/check-health.rsc +++ b/check-health.rsc @@ -8,11 +8,11 @@ # check for RouterOS health state # https://rsc.eworm.de/doc/check-health.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CheckHealthCPUUtilization; @@ -89,10 +89,10 @@ :foreach Plugin in=$Plugins do={ :local PluginVal [ /system/script/get $Plugin ]; :if ([ $ValidateSyntax ($PluginVal->"source") ] = true) do={ - :onerror Err { + :do { /system/script/run $Plugin; - } do={ - $LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed to run: " . $Err); + } on-error={ + $LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed to run."); } } else={ $LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed syntax validation, skipping."); @@ -105,6 +105,6 @@ } :set CheckHealthPlugins; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/check-lte-firmware-upgrade.rsc b/check-lte-firmware-upgrade.rsc index 9f4b6562..c5b6cb56 100644 --- a/check-lte-firmware-upgrade.rsc +++ b/check-lte-firmware-upgrade.rsc @@ -8,11 +8,11 @@ # check for LTE firmware upgrade, send notification # https://rsc.eworm.de/doc/check-lte-firmware-upgrade.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global SentLteFirmwareUpgradeNotification; @@ -45,12 +45,12 @@ :local IntName [ /interface/lte/get $Interface name ]; :local Firmware; :local Info; - :onerror Err { + :do { :set Firmware [ /interface/lte/firmware-upgrade $Interface as-value ]; :set Info [ /interface/lte/monitor $Interface once as-value ]; - } do={ + } on-error={ $LogPrint debug $ScriptName ("Could not get latest LTE firmware version for interface " . \ - $IntName . ": " . $Err); + $IntName . "."); :return false; } @@ -102,6 +102,6 @@ :foreach Interface in=[ /interface/lte/find ] do={ $CheckInterface $ScriptName $Interface; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/check-perpetual-license.rsc b/check-perpetual-license.rsc index c2f0dff0..9a3a3c74 100644 --- a/check-perpetual-license.rsc +++ b/check-perpetual-license.rsc @@ -8,11 +8,11 @@ # check perpetual license on CHR # https://rsc.eworm.de/doc/check-perpetual-license.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -73,6 +73,6 @@ ". It is now valid until " . ($License->"deadline-at") . ".") }); :set SentCertificateNotification; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/check-routeros-update.rsc b/check-routeros-update.rsc index e28a0190..361be34e 100644 --- a/check-routeros-update.rsc +++ b/check-routeros-update.rsc @@ -9,11 +9,11 @@ # check for RouterOS update, send notification and/or install # https://rsc.eworm.de/doc/check-routeros-update.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -62,9 +62,8 @@ $WaitFullyConnected; :if ([ :len [ /system/scheduler/find where name="_RebootForUpdate" ] ] > 0) do={ - $LogPrint info $ScriptName ("A reboot for update is already scheduled."); :set ExitOK true; - :error false; + :error "A reboot for update is already scheduled."; } $LogPrint debug $ScriptName ("Checking for updates..."); @@ -141,13 +140,13 @@ :if ([ :len $SafeUpdateUrl ] > 0) do={ :local Result; - :onerror Err { + :do { :set Result [ /tool/fetch check-certificate=yes-without-crl \ ($SafeUpdateUrl . $Update->"channel" . "?installed=" . $Update->"installed-version" . \ "&latest=" . $Update->"latest-version") http-header-field=({ [ $FetchUserAgentStr $ScriptName ] }) \ output=user as-value ]; - } do={ - $LogPrint warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . ": " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . "."); } :if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={ $LogPrint info $ScriptName ("Version " . $Update->"latest-version" . " is considered safe, updating..."); @@ -214,6 +213,6 @@ " is available for downgrade."); :set SentRouterosUpdateNotification ($Update->"latest-version"); } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/collect-wireless-mac.capsman.rsc b/collect-wireless-mac.capsman.rsc index 06b8d844..17e09e3c 100644 --- a/collect-wireless-mac.capsman.rsc +++ b/collect-wireless-mac.capsman.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -95,6 +95,6 @@ $LogPrint debug $ScriptName ("No mac address available... Ignoring."); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/collect-wireless-mac.local.rsc b/collect-wireless-mac.local.rsc index 6716582d..4a38bfa4 100644 --- a/collect-wireless-mac.local.rsc +++ b/collect-wireless-mac.local.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -96,6 +96,6 @@ $LogPrint debug $ScriptName ("No mac address available... Ignoring."); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/collect-wireless-mac.template.rsc b/collect-wireless-mac.template.rsc index 53e6b0a8..da901be2 100644 --- a/collect-wireless-mac.template.rsc +++ b/collect-wireless-mac.template.rsc @@ -12,11 +12,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -113,6 +113,6 @@ $LogPrint debug $ScriptName ("No mac address available... Ignoring."); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/collect-wireless-mac.wifi.rsc b/collect-wireless-mac.wifi.rsc index 43ac8519..cb217ce1 100644 --- a/collect-wireless-mac.wifi.rsc +++ b/collect-wireless-mac.wifi.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -95,6 +95,6 @@ $LogPrint debug $ScriptName ("No mac address available... Ignoring."); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/daily-psk.capsman.rsc b/daily-psk.capsman.rsc index 3ecd6b66..56729315 100644 --- a/daily-psk.capsman.rsc +++ b/daily-psk.capsman.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global DailyPskMatchComment; @@ -91,6 +91,6 @@ } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/daily-psk.local.rsc b/daily-psk.local.rsc index d496350c..9dea4692 100644 --- a/daily-psk.local.rsc +++ b/daily-psk.local.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global DailyPskMatchComment; @@ -90,6 +90,6 @@ } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/daily-psk.template.rsc b/daily-psk.template.rsc index 5a1df2f1..8202eeba 100644 --- a/daily-psk.template.rsc +++ b/daily-psk.template.rsc @@ -12,11 +12,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global DailyPskMatchComment; @@ -106,6 +106,6 @@ } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/daily-psk.wifi.rsc b/daily-psk.wifi.rsc index c441e581..3de3c5b6 100644 --- a/daily-psk.wifi.rsc +++ b/daily-psk.wifi.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global DailyPskMatchComment; @@ -91,6 +91,6 @@ } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/dhcp-lease-comment.capsman.rsc b/dhcp-lease-comment.capsman.rsc index 3615bb9b..36b31c85 100644 --- a/dhcp-lease-comment.capsman.rsc +++ b/dhcp-lease-comment.capsman.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -38,6 +38,6 @@ /ip/dhcp-server/lease/set comment=$NewComment $Lease; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/dhcp-lease-comment.local.rsc b/dhcp-lease-comment.local.rsc index 9da53336..35dc6f68 100644 --- a/dhcp-lease-comment.local.rsc +++ b/dhcp-lease-comment.local.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -38,6 +38,6 @@ /ip/dhcp-server/lease/set comment=$NewComment $Lease; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/dhcp-lease-comment.template.rsc b/dhcp-lease-comment.template.rsc index 62cace12..47a85542 100644 --- a/dhcp-lease-comment.template.rsc +++ b/dhcp-lease-comment.template.rsc @@ -12,11 +12,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -43,6 +43,6 @@ /ip/dhcp-server/lease/set comment=$NewComment $Lease; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/dhcp-lease-comment.wifi.rsc b/dhcp-lease-comment.wifi.rsc index 667708cd..e0f97851 100644 --- a/dhcp-lease-comment.wifi.rsc +++ b/dhcp-lease-comment.wifi.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -38,6 +38,6 @@ /ip/dhcp-server/lease/set comment=$NewComment $Lease; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/dhcp-to-dns.rsc b/dhcp-to-dns.rsc index a9c91e1c..9b940984 100644 --- a/dhcp-to-dns.rsc +++ b/dhcp-to-dns.rsc @@ -9,11 +9,11 @@ # check DHCP leases and add/remove/update DNS entries # https://rsc.eworm.de/doc/dhcp-to-dns.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Domain; @@ -125,6 +125,6 @@ $LogPrint debug $ScriptName ("No address available... Ignoring."); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/firmware-upgrade-reboot.rsc b/firmware-upgrade-reboot.rsc index e3ca55b3..86a9a8c5 100644 --- a/firmware-upgrade-reboot.rsc +++ b/firmware-upgrade-reboot.rsc @@ -8,11 +8,11 @@ # install firmware upgrade, and reboot # https://rsc.eworm.de/doc/firmware-upgrade-reboot.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -55,6 +55,6 @@ $LogPrint info $ScriptName ("Firmware upgrade successful, rebooting."); /system/reboot; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/fw-addr-lists.rsc b/fw-addr-lists.rsc index efd37db7..f0940fef 100644 --- a/fw-addr-lists.rsc +++ b/fw-addr-lists.rsc @@ -8,11 +8,11 @@ # download, import and update firewall address-lists # https://rsc.eworm.de/doc/fw-addr-lists.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global FwAddrLists; @@ -114,8 +114,8 @@ :error true; } :if ($Address ~ "^[0-9a-zA-Z]*:[0-9a-zA-Z:\\.]+(/[0-9]{1,3})?\$") do={ - :if ([ :typeof [ :find $Address "/" ] ] = "nil") do={ - :set Address ($Address . "/128"); + :if ($Address ~ "/128\$") do={ + :set Address [ :pick $Address 0 ([ :len $Address ] - 4) ]; } :set ($IPv6Addresses->$Branch->$Address) $TimeOut; :error true; @@ -135,15 +135,15 @@ :local Branch [ $GetBranch $Address ]; :local TimeOut ($IPv4Addresses->$Branch->$Address); :if ([ :typeof $TimeOut ] = "time") do={ - $LogPrintVerbose debug $ScriptName ("Renewing IPv4 address " . $Address . \ - " in list '" . $FwListName . "' with " . $TimeOut . "."); + $LogPrintVerbose debug $ScriptName ("Renewing IPv4 address in list '" . $FwListName . \ + "' with " . $TimeOut . ": " . $Address); /ip/firewall/address-list/set $Entry timeout=$TimeOut; :set ($IPv4Addresses->$Branch->$Address); :set CntRenew ($CntRenew + 1); } else={ :if ($Failure = false) do={ - $LogPrintVerbose debug $ScriptName ("Removing IPv4 address " . $Address . \ - " from list '" . $FwListName . "."); + $LogPrintVerbose debug $ScriptName ("Removing IPv4 address from list '" . $FwListName . \ + "': " . $Address); /ip/firewall/address-list/remove $Entry; :set CntRemove ($CntRemove + 1); } @@ -156,15 +156,15 @@ :local Branch [ $GetBranch $Address ]; :local TimeOut ($IPv6Addresses->$Branch->$Address); :if ([ :typeof $TimeOut ] = "time") do={ - $LogPrintVerbose debug $ScriptName ("Renewing IPv6 address " . $Address . \ - " in list '" . $FwListName . "' with " . $TimeOut . "."); + $LogPrintVerbose debug $ScriptName ("Renewing IPv6 address in list '" . $FwListName . \ + "' with " . $TimeOut . ": " . $Address); /ipv6/firewall/address-list/set $Entry timeout=$TimeOut; :set ($IPv6Addresses->$Branch->$Address); :set CntRenew ($CntRenew + 1); } else={ :if ($Failure = false) do={ - $LogPrintVerbose debug $ScriptName ("Removing IPv6 address " . $Address . \ - " from list '" . $FwListName ."."); + $LogPrintVerbose debug $ScriptName ("Removing IPv6 address from list '" . $FwListName . \ + "': " . $Address); /ipv6/firewall/address-list/remove $Entry; :set CntRemove ($CntRemove + 1); } @@ -174,15 +174,15 @@ :foreach BranchName,Branch in=$IPv4Addresses do={ $LogPrintVerbose debug $ScriptName ("Handling branch: " . $BranchName); :foreach Address,Timeout in=$Branch do={ - $LogPrintVerbose debug $ScriptName ("Adding IPv4 address " . $Address . \ - " to list '" . $FwListName . "' with " . $Timeout . "."); - :onerror Err { + $LogPrintVerbose debug $ScriptName ("Adding IPv4 address to list '" . $FwListName . \ + "' with " . $Timeout . ": " . $Address); + :do { /ip/firewall/address-list/add list=$FwListName comment=$ListComment \ address=$Address timeout=$Timeout; :set CntAdd ($CntAdd + 1); - } do={ - $LogPrint warning $ScriptName ("Failed to add IPv4 address " . $Address . \ - " to list '" . $FwListName . "': " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("Failed to add IPv4 address to list '" . $FwListName . \ + "': " . $Address); } } } @@ -190,15 +190,15 @@ :foreach BranchName,Branch in=$IPv6Addresses do={ $LogPrintVerbose debug $ScriptName ("Handling branch: " . $BranchName); :foreach Address,Timeout in=$Branch do={ - $LogPrintVerbose debug $ScriptName ("Adding IPv6 address " . $Address . \ - " to list '" . $FwListName . "' with " . $Timeout . "."); - :onerror Err { + $LogPrintVerbose debug $ScriptName ("Adding IPv6 address to list '" . $FwListName . \ + "' with " . $Timeout . ": " . $Address); + :do { /ipv6/firewall/address-list/add list=$FwListName comment=$ListComment \ address=$Address timeout=$Timeout; :set CntAdd ($CntAdd + 1); - } do={ - $LogPrint warning $ScriptName ("Failed to add IPv6 address " . $Address . \ - " to list '" . $FwListName . "': " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("Failed to add IPv6 address to list '" . $FwListName . \ + "': " . $Address); } } } @@ -209,6 +209,6 @@ " - renewed: " . [ $HumanReadableNum $CntRenew 1000 ] . \ " - removed: " . [ $HumanReadableNum $CntRemove 1000 ]); } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/global-config.rsc b/global-config.rsc index 86d528aa..42a457a5 100644 --- a/global-config.rsc +++ b/global-config.rsc @@ -6,12 +6,6 @@ # global configuration # https://rsc.eworm.de/ -# Warning: Do *NOT* copy this line to overlay! -:global GlobalConfigReady false; -# || ... but -# \||/ start -# \/ here! - # Set this to 'true' to disable news and change notifications. :global NoNewsAndChangesNotification false; @@ -270,20 +264,14 @@ "cert2-cn"="4n0th3r-s3cr3t"; }; -# /\ Warning: Do *NOT* copy -# /\7\ the code below to overlay! -# /_()_\ Things *will* break! -# # load custom settings from overlay and snippets +# Warning: Do *NOT* copy this code to overlay! :foreach Script in=([ /system/script/find where name="global-config-overlay" ], \ [ /system/script/find where name~"^global-config-overlay.d/" ]) do={ - :onerror Err { + :do { /system/script/run $Script; - } do={ + } on-error={ :log error ("Loading configuration from overlay or snippet " . \ - [ /system/script/get $Script name ] . " failed: " . $Err); + [ /system/script/get $Script name ] . " failed!"); } } - -# signal we are ready -:set GlobalConfigReady true; diff --git a/global-functions.rsc b/global-functions.rsc index 8331e4a7..71aa7de3 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -391,22 +391,25 @@ :local Url ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile); $LogPrint info $0 ("Downloading package file '" . $PkgName . "'..."); $LogPrint debug $0 ("... from url: " . $Url); + :local Retry 3; + :while ($Retry > 0) do={ + :do { + /tool/fetch check-certificate=yes-without-crl $Url dst-path=$PkgDest; + $WaitForFile $PkgDest; - :onerror Err { - /tool/fetch check-certificate=yes-without-crl $Url dst-path=$PkgDest; - $WaitForFile $PkgDest; - } do={ - $LogPrint warning $0 ("Downloading package file '" . $PkgName . "' failed: " . $Err); - :return false; - } + :if ([ /file/get [ find where name=$PkgDest ] type ] = "package") do={ + :return true; + } + } on-error={ + $LogPrint debug $0 ("Downloading package file failed."); + } - :if ([ /file/get [ find where name=$PkgDest ] type ] != "package") do={ - $LogPrint warning $0 ("Downloaded file is not a package, removing."); $RmFile $PkgDest; - :return false; + :set Retry ($Retry - 1); } - :return true; + $LogPrint warning $0 ("Downloading package file '" . $PkgName . "' failed."); + :return false; } # return either first (if "true") or second @@ -449,15 +452,13 @@ :set ExitError do={ :local ExitOK [ :tostr $1 ]; :local Name [ :tostr $2 ]; - :local Error [ :tostr $3 ]; :global IfThenElse; :global LogPrint; :if ($ExitOK = "false") do={ $LogPrint error $Name ([ $IfThenElse ([ :pick $Name 0 1 ] = "\$") \ - "Function" "Script" ] . " '" . $Name . "' exited with error" . \ - [ $IfThenElse (!($Error ~ "^(|true|false)\$")) (": " . $Error) "." ]); + "Function" "Script" ] . " '" . $Name . "' exited with error."); } } @@ -486,14 +487,14 @@ } :local FileName ($DirName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]); - :onerror Err { + :do { /tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \ http-header-field=({ [ $FetchUserAgentStr $ScriptName ] }) as-value; - } do={ + } on-error={ :if ([ $WaitForFile $FileName 500ms ] = true) do={ $RmFile $FileName; } - $LogPrint debug $0 ("Failed downloading from " . $Url . " - " . $Err); + $LogPrint debug $0 ("Failed downloading from: " . $Url); $RmDir $DirName; :return false; } @@ -586,12 +587,12 @@ ("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data"); :return $Vendor; } on-error={ - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \ output=none as-value; $LogPrint debug $0 ("The mac vendor is not known in database."); - } do={ - $LogPrint warning $0 ("Failed getting mac vendor: " . $Err); + } on-error={ + $LogPrint warning $0 ("Failed getting mac vendor."); } :return "unknown vendor"; } @@ -894,11 +895,11 @@ $LogPrint info $0 ("Creating disk of type tmpfs."); $RmDir "tmpfs"; - :onerror Err { + :do { /disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3); $WaitForFile "tmpfs"; - } do={ - $LogPrint warning $0 ("Creating disk of type tmpfs failed: " . $Err); + } on-error={ + $LogPrint warning $0 ("Creating disk of type tmpfs failed!"); :return false; } :return true; @@ -923,11 +924,11 @@ } } - :onerror Err { + :do { /file/add type="directory" name=$Path; $WaitForFile $Path; - } do={ - $LogPrint warning $0 ("Making directory '" . $Path . "' failed: " . $Err); + } on-error={ + $LogPrint warning $0 ("Making directory '" . $Path . "' failed!"); :return false; } @@ -1052,10 +1053,10 @@ :return true; } - :onerror Err { + :do { /file/remove $Dir; - } do={ - $LogPrint error $0 ("Removing directory '" . $DirName . "' (" . $Dir . ") failed: " . $Err); + } on-error={ + $LogPrint error $0 ("Removing directory '" . $DirName . "' (" . $Dir . ") failed."); :return false; } :return true; @@ -1080,10 +1081,10 @@ :return true; } - :onerror Err { + :do { /file/remove $File; - } do={ - $LogPrint error $0 ("Removing file '" . $FileName . "' (" . $File . ") failed: " . $Err); + } on-error={ + $LogPrint error $0 ("Removing file '" . $FileName . "' (" . $File . ") failed."); :return false; } :return true; @@ -1116,15 +1117,13 @@ } # install new scripts, update existing scripts -:set ScriptInstallUpdate do={ :onerror Err { +:set ScriptInstallUpdate do={ :do { :local Scripts [ :toarray $1 ]; :local NewComment [ :tostr $2 ]; :global CommitId; :global CommitInfo; :global ExpectedConfigVersion; - :global GlobalConfigReady; - :global GlobalFunctionsReady; :global Identity; :global IDonate; :global NoNewsAndChangesNotification; @@ -1158,7 +1157,8 @@ :local CommitIdBefore $CommitId; :local ExpectedConfigVersionBefore $ExpectedConfigVersion; - :local ReloadGlobal false; + :local ReloadGlobalFunctions false; + :local ReloadGlobalConfig false; :local DeviceMode [ /system/device-mode/get ]; :local CheckSums ({}); @@ -1201,7 +1201,7 @@ } } - :onerror Err { + :do { :local BaseUrl [ $EitherOr ($ScriptInfo->"base-url") $ScriptUpdatesBaseUrl ]; :local UrlSuffix [ $EitherOr ($ScriptInfo->"url-suffix") $ScriptUpdatesUrlSuffix ]; :local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix); @@ -1211,11 +1211,13 @@ :if ($Result->"status" = "finished") do={ :set SourceNew [ :tolf ($Result->"data") ]; } - } do={ - $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . . "': " . $Err); + } on-error={ :if ($ScriptVal->"source" = "#!rsc by RouterOS\n") do={ - $LogPrint warning $0 ("Removing dummy. Typo on installation?"); + $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . \ + "', removing dummy. Typo on installation?"); /system/script/remove $Script; + } else={ + $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . "'!"); } :error false; } @@ -1265,25 +1267,31 @@ $LogPrint info $0 ("Updating script: " . $ScriptVal->"name"); /system/script/set owner=($ScriptVal->"name") \ source=[ $IfThenElse ($ScriptUpdatesCRLF = true) $SourceCRLF $SourceNew ] $Script; - :if ($ScriptVal->"name" = "global-config" || \ - $ScriptVal->"name" = "global-functions" || \ - $ScriptVal->"name" ~ ("^mod/.")) do={ - :set ReloadGlobal true; + :if ($ScriptVal->"name" = "global-config") do={ + :set ReloadGlobalConfig true; + } + :if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={ + :set ReloadGlobalFunctions true; } } on-error={ } } - :if ($ReloadGlobal = true) do={ - $LogPrint info $0 ("Reloading global configuration and functions."); - :set GlobalConfigReady false; - :set GlobalFunctionsReady false; - :delay 1s; - - :onerror Err { - /system/script/run global-config; + :if ($ReloadGlobalFunctions = true) do={ + $LogPrint info $0 ("Reloading global functions."); + :do { /system/script/run global-functions; - } do={ - $LogPrint error $0 ("Reloading global configuration and functions failed! " . $Err); + } on-error={ + $LogPrint error $0 ("Reloading global functions failed!"); + } + } + + :if ($ReloadGlobalConfig = true) do={ + $LogPrint info $0 ("Reloading global configuration."); + :do { + /system/script/run global-config; + } on-error={ + $LogPrint error $0 ("Reloading global configuration failed!" . \ + " Syntax error or missing overlay?"); } } @@ -1302,7 +1310,7 @@ :global GlobalConfigMigration; :local ChangeLogCode; - :onerror Err { + :do { :local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix); $LogPrint debug $0 ("Fetching news, changes and migration: " . $Url); :local Result [ /tool/fetch check-certificate=yes-without-crl \ @@ -1310,16 +1318,16 @@ :if ($Result->"status" = "finished") do={ :set ChangeLogCode ($Result->"data"); } - } do={ - $LogPrint warning $0 ("Failed fetching news, changes and migration: " . $Err); + } on-error={ + $LogPrint warning $0 ("Failed fetching news, changes and migration!"); } :if ([ :len $ChangeLogCode ] > 0) do={ :if ([ $ValidateSyntax $ChangeLogCode ] = true) do={ - :onerror Err { + :do { [ :parse $ChangeLogCode ]; - } do={ - $LogPrint warning $0 ("The changelog failed to run: " . $Err); + } on-error={ + $LogPrint warning $0 ("The changelog failed to run!"); } } else={ $LogPrint warning $0 ("The changelog failed syntax validation!"); @@ -1341,10 +1349,10 @@ } $LogPrint info $0 ("Applying migration for change " . $I . ": " . $Migration); - :onerror Err { + :do { [ :parse $Migration ]; - } do={ - $LogPrint warning $0 ("Migration code for change " . $I . " failed to run: " . $Err); + } on-error={ + $LogPrint warning $0 ("Migration code for change " . $I . " failed to run!"); } } on-error={ } } @@ -1386,8 +1394,8 @@ :set GlobalConfigChanges; :set GlobalConfigMigration; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # lock script against multiple invocation @@ -1528,12 +1536,12 @@ } # send notification via NotificationFunctions - expects at least two string arguments -:set SendNotification do={ :onerror Err { +:set SendNotification do={ :do { :global SendNotification2; $SendNotification2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 }); -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via NotificationFunctions - expects one array argument @@ -1652,12 +1660,9 @@ :set ValidateSyntax do={ :local Code [ :tostr $1 ]; - :global LogPrint; - - :onerror Err { + :do { [ :parse (":local Validate do={\n" . $Code . "\n}") ]; - } do={ - $LogPrint debug $0 ("Valdation failed: " . $Err); + } on-error={ :return false; } :return true; @@ -1771,10 +1776,10 @@ :foreach Script in=[ /system/script/find where name ~ "^mod/." ] do={ :local ScriptVal [ /system/script/get $Script ]; :if ([ $ValidateSyntax ($ScriptVal->"source") ] = true) do={ - :onerror Err { + :do { /system/script/run $Script; - } do={ - $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run: " . $Err); + } on-error={ + $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run."); } } else={ $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping."); diff --git a/global-wait.rsc b/global-wait.rsc index 23b56298..ca3fc0c4 100644 --- a/global-wait.rsc +++ b/global-wait.rsc @@ -8,6 +8,5 @@ # wait for global-functions to finish # https://rsc.eworm.de/doc/global-wait.md -:global GlobalConfigReady; :global GlobalFunctionsReady; -:while ($GlobalConfigReady != true || $GlobalFunctionsReady != true) do={ :delay 500ms; } +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } diff --git a/gps-track.rsc b/gps-track.rsc index 6a090bfe..dea56d2e 100644 --- a/gps-track.rsc +++ b/gps-track.rsc @@ -9,11 +9,11 @@ # track gps data by sending json data to http server # https://rsc.eworm.de/doc/gps-track.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global GpsTrackUrl; @@ -34,7 +34,7 @@ :local Gps [ /system/gps/monitor once as-value ]; :if ($Gps->"valid" = true) do={ - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl output=none http-method=post \ http-header-field=({ [ $FetchUserAgentStr $ScriptName ]; "Content-Type: application/json" }) \ http-data=[ :serialize to=json { "identity"=$Identity; \ @@ -42,12 +42,12 @@ $LogPrint debug $ScriptName ("Sending GPS data in " . $CoordinateFormat . " format: " . \ "lat: " . ($Gps->"latitude") . " " . \ "lon: " . ($Gps->"longitude")); - } do={ - $LogPrint warning $ScriptName ("Failed sending GPS data: " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("Failed sending GPS data!"); } } else={ $LogPrint debug $ScriptName ("GPS data not valid."); } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/hotspot-to-wpa-cleanup.capsman.rsc b/hotspot-to-wpa-cleanup.capsman.rsc index e4ac9678..033d0e73 100644 --- a/hotspot-to-wpa-cleanup.capsman.rsc +++ b/hotspot-to-wpa-cleanup.capsman.rsc @@ -12,11 +12,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global EitherOr; @@ -75,6 +75,6 @@ /ip/dhcp-server/lease/remove $Lease; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/hotspot-to-wpa-cleanup.template.rsc b/hotspot-to-wpa-cleanup.template.rsc index d51e1d03..0f8c490e 100644 --- a/hotspot-to-wpa-cleanup.template.rsc +++ b/hotspot-to-wpa-cleanup.template.rsc @@ -13,11 +13,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global EitherOr; @@ -82,6 +82,6 @@ /ip/dhcp-server/lease/remove $Lease; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/hotspot-to-wpa-cleanup.wifi.rsc b/hotspot-to-wpa-cleanup.wifi.rsc index 8bb2631b..dfec697d 100644 --- a/hotspot-to-wpa-cleanup.wifi.rsc +++ b/hotspot-to-wpa-cleanup.wifi.rsc @@ -12,11 +12,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global EitherOr; @@ -75,6 +75,6 @@ /ip/dhcp-server/lease/remove $Lease; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/hotspot-to-wpa.capsman.rsc b/hotspot-to-wpa.capsman.rsc index 8977cee1..3f514750 100644 --- a/hotspot-to-wpa.capsman.rsc +++ b/hotspot-to-wpa.capsman.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global EitherOr; @@ -100,6 +100,6 @@ :delay 2s; /caps-man/access-list/set $Entry action=accept; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/hotspot-to-wpa.template.rsc b/hotspot-to-wpa.template.rsc index c5d977d1..068241d1 100644 --- a/hotspot-to-wpa.template.rsc +++ b/hotspot-to-wpa.template.rsc @@ -12,11 +12,11 @@ # !! This is just a template to generate the real script! # !! Pattern '%TEMPL%' is replaced, paths are filtered. +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global EitherOr; @@ -120,6 +120,6 @@ :delay 2s; /caps-man/access-list/set $Entry action=accept; /interface/wifi/access-list/set $Entry action=accept; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/hotspot-to-wpa.wifi.rsc b/hotspot-to-wpa.wifi.rsc index 6a97e460..cc5e2fc6 100644 --- a/hotspot-to-wpa.wifi.rsc +++ b/hotspot-to-wpa.wifi.rsc @@ -11,11 +11,11 @@ # # !! Do not edit this file, it is generated from template! +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global EitherOr; @@ -97,6 +97,6 @@ :delay 2s; /interface/wifi/access-list/set $Entry action=accept; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/ipsec-to-dns.rsc b/ipsec-to-dns.rsc index 1b5ed133..26dab0a2 100644 --- a/ipsec-to-dns.rsc +++ b/ipsec-to-dns.rsc @@ -9,11 +9,11 @@ # and add/remove/update DNS entries from IPSec mode-config # https://rsc.eworm.de/doc/ipsec-to-dns.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Domain; @@ -79,6 +79,6 @@ /ip/dns/static/add name=$Fqdn address=($PeerVal->"dynamic-address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/ipv6-update.rsc b/ipv6-update.rsc index 580a426c..94bd1bc4 100644 --- a/ipv6-update.rsc +++ b/ipv6-update.rsc @@ -8,11 +8,11 @@ # update firewall and dns settings on IPv6 prefix change # https://rsc.eworm.de/doc/ipv6-update.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -102,6 +102,6 @@ } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/lease-script.rsc b/lease-script.rsc index ab449568..bf27fda8 100644 --- a/lease-script.rsc +++ b/lease-script.rsc @@ -8,11 +8,11 @@ # run scripts on DHCP lease # https://rsc.eworm.de/doc/lease-script.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Grep; @@ -53,13 +53,13 @@ } :foreach Order,Script in=$RunOrder do={ - :onerror Err { + :do { $LogPrint debug $ScriptName ("Running script with order " . $Order . ": " . $Script); /system/script/run $Script; - } do={ - $LogPrint warning $ScriptName ("Running script '" . $Script . "' failed: " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("Running script '" . $Script . "' failed!"); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/log-forward.rsc b/log-forward.rsc index be7eff7b..afeb3f29 100644 --- a/log-forward.rsc +++ b/log-forward.rsc @@ -8,11 +8,11 @@ # forward log messages via notification # https://rsc.eworm.de/doc/log-forward.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -108,6 +108,6 @@ :local LogAll [ /log/find ]; :set LogForwardLast ($LogAll->([ :len $LogAll ] - 1) ); -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/mod/bridge-port-to.rsc b/mod/bridge-port-to.rsc index 93eedcef..39a036e5 100644 --- a/mod/bridge-port-to.rsc +++ b/mod/bridge-port-to.rsc @@ -10,7 +10,7 @@ :global BridgePortTo; -:set BridgePortTo do={ :onerror Err { +:set BridgePortTo do={ :do { :local BridgePortTo [ :tostr $1 ]; :global IfThenElse; @@ -65,6 +65,6 @@ $LogPrint info $0 ("Re-enabling interfaces..."); /interface/ethernet/enable $InterfaceReEnable; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } diff --git a/mod/bridge-port-vlan.rsc b/mod/bridge-port-vlan.rsc index 6deee994..0eeb9b5f 100644 --- a/mod/bridge-port-vlan.rsc +++ b/mod/bridge-port-vlan.rsc @@ -10,7 +10,7 @@ :global BridgePortVlan; -:global BridgePortVlan do={ :onerror Err { +:global BridgePortVlan do={ :do { :local ConfigTo [ :tostr $1 ]; :global IfThenElse; @@ -74,6 +74,6 @@ $LogPrint info $0 ("Re-enabling interfaces..."); /interface/ethernet/enable $InterfaceReEnable; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } diff --git a/mod/inspectvar.rsc b/mod/inspectvar.rsc index fc1b366f..c8615573 100644 --- a/mod/inspectvar.rsc +++ b/mod/inspectvar.rsc @@ -12,12 +12,12 @@ :global InspectVarReturn; # inspect variable and print on terminal -:set InspectVar do={ :onerror Err { +:set InspectVar do={ :do { :global InspectVarReturn; :put [ :tocrlf [ $InspectVarReturn $1 ] ]; -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # inspect variable and return formatted string @@ -25,7 +25,6 @@ :local Input $1; :local Level (0 + [ :tonum $2 ]); - :global CharacterReplace; :global IfThenElse; :global InspectVarReturn; @@ -34,13 +33,14 @@ :local Value [ :tostr $2 ]; :local Level [ :tonum $3 ]; - :global CharacterMultiply; - - :return ([ $CharacterMultiply " " $Level ] . "-" . $Prefix . "-> " . $Value); + :local Indent ""; + :for I from=1 to=$Level step=1 do={ + :set Indent ($Indent . " "); + } + :return ($Indent . "-" . $Prefix . "-> " . $Value); } :local TypeOf [ :typeof $Input ]; - :local Len [ :len $Input ]; :local Return [ $IndentReturn "type" $TypeOf $Level ]; :if ($TypeOf = "array") do={ @@ -50,16 +50,6 @@ [ $InspectVarReturn $Value ($Level + 2) ]); } } else={ - :if ($TypeOf = "str") do={ - :set $Return ($Return . "\n" . \ - [ $IndentReturn "len" $Len $Level ]); - :if ([ :typeof [ :find $Input ("\r") ] ] = "num") do={ - :set Input [ $CharacterReplace $Input ("\r") "" ]; - } - :if ([ :typeof [ :find $Input ("\n") ] ] = "num") do={ - :set Input [ $CharacterReplace $Input ("\n") " " ]; - } - } :if ($TypeOf != "nothing") do={ :set $Return ($Return . "\n" . \ [ $IndentReturn "value" [ $IfThenElse ([ :len $Input ] > 80) \ diff --git a/mod/ipcalc.rsc b/mod/ipcalc.rsc index eacff6d9..477cf4a8 100644 --- a/mod/ipcalc.rsc +++ b/mod/ipcalc.rsc @@ -12,7 +12,7 @@ :global IPCalcReturn; # print netmask, network, min host, max host and broadcast -:set IPCalc do={ :onerror Err { +:set IPCalc do={ :do { :local Input [ :tostr $1 ]; :global FormatLine; @@ -27,8 +27,8 @@ [ $FormatLine "HostMin" ($Values->"hostmin") ] . "\n" . \ [ $FormatLine "HostMax" ($Values->"hostmax") ] . "\n" . \ [ $FormatLine "Broadcast" ($Values->"broadcast") ]) ]; -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # calculate and return netmask, network, min host, max host and broadcast diff --git a/mod/notification-email.rsc b/mod/notification-email.rsc index 52937668..7b89d985 100644 --- a/mod/notification-email.rsc +++ b/mod/notification-email.rsc @@ -35,7 +35,7 @@ } # flush e-mail queue -:set FlushEmailQueue do={ :onerror Err { +:set FlushEmailQueue do={ :do { :global EmailQueue; :global EitherOr; @@ -89,40 +89,35 @@ :foreach Id,Message in=$EmailQueue do={ :if ([ :typeof $Message ] = "array" ) do={ + :local Attach ({}); :while ([ /tool/e-mail/get last-status ] = "in-progress") do={ :delay 1s; } - :onerror Err { - :local Attach ({}); - :foreach File in=[ :toarray [ $EitherOr ($Message->"attach") "" ] ] do={ - :if ([ :len [ /file/find where name=$File ] ] = 1) do={ - :set Attach ($Attach, $File); - } else={ - $LogPrint warning $0 ("File '" . $File . "' does not exist, can not attach."); - } + :foreach File in=[ :toarray [ $EitherOr ($Message->"attach") "" ] ] do={ + :if ([ :len [ /file/find where name=$File ] ] = 1) do={ + :set Attach ($Attach, $File); + } else={ + $LogPrint warning $0 ("File '" . $File . "' does not exist, can not attach."); } - /tool/e-mail/send from=[ $EMailGenerateFrom ] to=($Message->"to") cc=($Message->"cc") \ - subject=($Message->"subject") body=($Message->"body") file=$Attach; - :local Wait true; - :do { - :delay 1s; - :local Status [ /tool/e-mail/get last-status ]; - :if ($Status = "succeeded") do={ - :set ($EmailQueue->$Id); - :set Wait false; - :if (($Message->"remove-attach") = true) do={ - :foreach File in=$Attach do={ - /file/remove $File; - } + } + /tool/e-mail/send from=[ $EMailGenerateFrom ] to=($Message->"to") cc=($Message->"cc") \ + subject=($Message->"subject") body=($Message->"body") file=$Attach; + :local Wait true; + :do { + :delay 1s; + :local Status [ /tool/e-mail/get last-status ]; + :if ($Status = "succeeded") do={ + :set ($EmailQueue->$Id); + :set Wait false; + :if (($Message->"remove-attach") = true) do={ + :foreach File in=$Attach do={ + /file/remove $File; } } - :if ($Status = "failed") do={ - :set AllDone false; - :set Wait false; - } - } while=($Wait = true); - } do={ - $LogPrint warning $0 ("Sending queued mail failed: " . $Err); - :set AllDone false; - } + } + :if ($Status = "failed") do={ + :set AllDone false; + :set Wait false; + } + } while=($Wait = true); } } @@ -140,8 +135,8 @@ /system/scheduler/set interval=(($SchedVal->"run-count") . "m") \ comment="Waiting for retry..." $Scheduler; -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # generate filter for log-forward @@ -181,7 +176,6 @@ :global IfThenElse; :global NotificationEMailSignature; :global NotificationEMailSubject; - :global SymbolForNotification; :local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ]; :local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ]; @@ -194,23 +188,13 @@ :if ([ :typeof $EmailQueue ] = "nothing") do={ :set EmailQueue ({}); } - :local Truncated false; - :local Body ($Notification->"message"); - :if ([ :len $Body ] > 62000) do={ - :set Body ([ :pick $Body 0 62000 ] . "..."); - :set Truncated true; - } :local Signature [ $EitherOr [ $NotificationEMailSignature ] [ /system/note/get note ] ]; - :set Body ($Body . "\n" . \ - [ $IfThenElse ([ :len ($Notification->"link") ] > 0) \ - ("\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")) ] . \ - [ $IfThenElse ($Truncated = true) ("\n" . [ $SymbolForNotification "scissors" ] . \ - "The message was too long and has been truncated!") ] . \ - [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); :set ($EmailQueue->[ :len $EmailQueue ]) { to=$To; cc=$Cc; subject=[ $NotificationEMailSubject ($Notification->"subject") ]; - body=$Body; \ + body=(($Notification->"message") . \ + [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \ + [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \ attach=($Notification->"attach"); remove-attach=($Notification->"remove-attach") }; :if ([ :len [ /system/scheduler/find where name="_FlushEmailQueue" ] ] = 0) do={ /system/scheduler/add name="_FlushEmailQueue" interval=1s start-time=startup \ @@ -264,12 +248,12 @@ } # send notification via e-mail - expects at least two string arguments -:set SendEMail do={ :onerror Err { +:set SendEMail do={ :do { :global SendEMail2; $SendEMail2 ({ origin=$0; subject=$1; message=$2; link=$3 }); -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via e-mail - expects one array argument diff --git a/mod/notification-gotify.rsc b/mod/notification-gotify.rsc index d8eafbe0..70709189 100644 --- a/mod/notification-gotify.rsc +++ b/mod/notification-gotify.rsc @@ -17,7 +17,7 @@ :global SendGotify2; # flush Gotify queue -:set FlushGotifyQueue do={ :onerror Err { +:set FlushGotifyQueue do={ :do { :global GotifyQueue; :global IsFullyConnected; @@ -37,13 +37,13 @@ :foreach Id,Message in=$GotifyQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl output=none http-method=post \ http-header-field=($Message->"headers") http-data=[ :serialize to=json ($Message->"message") ] \ ($Message->"url") as-value; :set ($GotifyQueue->$Id); - } do={ - $LogPrint debug $0 ("Sending queued Gotify message failed: " . $Err); + } on-error={ + $LogPrint debug $0 ("Sending queued Gotify message failed."); :set AllDone false; } } @@ -53,8 +53,8 @@ /system/scheduler/remove [ find where name="_FlushGotifyQueue" ]; :set GotifyQueue; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via Gotify - expects one array argument @@ -91,11 +91,11 @@ ("\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")) ]); \ "priority"=[ :tonum [ $IfThenElse ($Notification->"silent") 2 5 ] ] }); - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl output=none http-method=post \ http-header-field=$Headers http-data=[ :serialize to=json $Message ] $Url as-value; - } do={ - $LogPrint info $0 ("Failed sending Gotify notification: " . $Err . " - Queuing..."); + } on-error={ + $LogPrint info $0 ("Failed sending Gotify notification! Queuing..."); :if ([ :typeof $GotifyQueue ] = "nothing") do={ :set GotifyQueue ({}); @@ -121,12 +121,12 @@ } # send notification via Gotify - expects at least two string arguments -:set SendGotify do={ :onerror Err { +:set SendGotify do={ :do { :global SendGotify2; $SendGotify2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 }); -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via Gotify - expects one array argument diff --git a/mod/notification-matrix.rsc b/mod/notification-matrix.rsc index e9b42a0d..e989ee04 100644 --- a/mod/notification-matrix.rsc +++ b/mod/notification-matrix.rsc @@ -19,7 +19,7 @@ :global SetupMatrixJoinRoom; # flush Matrix queue -:set FlushMatrixQueue do={ :onerror Err { +:set FlushMatrixQueue do={ :do { :global MatrixQueue; :global IsFullyConnected; @@ -39,7 +39,7 @@ :foreach Id,Message in=$MatrixQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl output=none \ http-header-field=($Message->"headers") http-method=post \ http-data=[ :serialize to=json { "msgtype"="m.text"; "body"=($Message->"plain"); @@ -47,8 +47,8 @@ ("https://" . $Message->"homeserver" . "/_matrix/client/r0/rooms/" . $Message->"room" . \ "/send/m.room.message?access_token=" . $Message->"accesstoken") as-value; :set ($MatrixQueue->$Id); - } do={ - $LogPrint debug $0 ("Sending queued Matrix message failed: " . $Err); + } on-error={ + $LogPrint debug $0 ("Sending queued Matrix message failed."); :set AllDone false; } } @@ -58,8 +58,8 @@ /system/scheduler/remove [ find where name="_FlushMatrixQueue" ]; :set MatrixQueue; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via Matrix - expects one array argument @@ -129,15 +129,15 @@ [ $PrepareText $Label ] . ""); } - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl output=none \ http-header-field=$Headers http-method=post \ http-data=[ :serialize to=json { "msgtype"="m.text"; "body"=$Plain; "format"="org.matrix.custom.html"; "formatted_body"=$Formatted } ] \ ("https://" . $HomeServer . "/_matrix/client/r0/rooms/" . $Room . \ "/send/m.room.message?access_token=" . $AccessToken) as-value; - } do={ - $LogPrint info $0 ("Failed sending Matrix notification: " . $Err . " - Queuing..."); + } on-error={ + $LogPrint info $0 ("Failed sending Matrix notification! Queuing..."); :if ([ :typeof $MatrixQueue ] = "nothing") do={ :set MatrixQueue ({}); @@ -167,12 +167,12 @@ } # send notification via Matrix - expects at least two string arguments -:set SendMatrix do={ :onerror Err { +:set SendMatrix do={ :do { :global SendMatrix2; $SendMatrix2 ({ origin=$0; subject=$1; message=$2; link=$3 }); -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via Matrix - expects one array argument @@ -196,14 +196,14 @@ :global MatrixHomeServer; :local Domain [ :pick $User ([ :find $User ":" ] + 1) [ :len $User] ]; - :onerror Err { + :do { :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ http-header-field=({ [ $FetchUserAgentStr $0 ] }) \ ("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data"); :set MatrixHomeServer ([ :deserialize from=json value=$Data ]->"m.homeserver"->"base_url"); $LogPrint debug $0 ("Home server is: " . $MatrixHomeServer); - } do={ - $LogPrint error $0 ("Failed getting home server: " . $Err); + } on-error={ + $LogPrint error $0 ("Failed getting home server!"); :return false; } @@ -211,27 +211,27 @@ :set MatrixHomeServer [ :pick $MatrixHomeServer 8 [ :len $MatrixHomeServer ] ]; } - :onerror Err { + :do { :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ http-header-field=({ [ $FetchUserAgentStr $0 ] }) http-method=post \ http-data=[ :serialize to=json { "type"="m.login.password"; "user"=$User; "password"=$Pass } ] \ ("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data"); :set MatrixAccessToken ([ :deserialize from=json value=$Data ]->"access_token"); $LogPrint debug $0 ("Access token is: " . $MatrixAccessToken); - } do={ - $LogPrint error $0 ("Failed logging in (and getting access token): " . $Err); + } on-error={ + $LogPrint error $0 ("Failed logging in (and getting access token)!"); :return false; } - :onerror Err { + :do { /system/script/remove [ find where name="global-config-overlay.d/mod/notification-matrix" ]; /system/script/add name="global-config-overlay.d/mod/notification-matrix" source=( \ "# configuration snippet: mod/notification-matrix\n\n" . \ ":global MatrixHomeServer \"" . $MatrixHomeServer . "\";\n" . \ ":global MatrixAccessToken \"" . $MatrixAccessToken . "\";\n"); $LogPrint info $0 ("Added configuration snippet. Now create and join a room, please!"); - } do={ - $LogPrint error $0 ("Failed adding configuration snippet: " . $Err); + } on-error={ + $LogPrint error $0 ("Failed adding configuration snippet!"); :return false; } } @@ -248,24 +248,24 @@ :global MatrixHomeServer; :global MatrixRoom; - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl output=none \ http-header-field=({ [ $FetchUserAgentStr $0 ] }) http-method=post http-data="" \ ("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ $UrlEncode $MatrixRoom ] . \ "/join?access_token=" . [ $UrlEncode $MatrixAccessToken ]) as-value; $LogPrint debug $0 ("Joined the room."); - } do={ - $LogPrint error $0 ("Failed joining the room: " . $Err); + } on-error={ + $LogPrint error $0 ("Failed joining the room!"); :return false; } - :onerror Err { + :do { :local Snippet [ /system/script/find where name="global-config-overlay.d/mod/notification-matrix" ]; /system/script/set $Snippet source=([ get $Snippet source ] . \ ":global MatrixRoom \"" . $MatrixRoom . "\";\n"); $LogPrint info $0 ("Appended configuration to configuration snippet. Please review!"); - } do={ - $LogPrint error $0 ("Failed appending configuration to snippet: " . $Err); + } on-error={ + $LogPrint error $0 ("Failed appending configuration to snippet!"); :return false; } } diff --git a/mod/notification-ntfy.rsc b/mod/notification-ntfy.rsc index 71140209..2748c5b6 100644 --- a/mod/notification-ntfy.rsc +++ b/mod/notification-ntfy.rsc @@ -16,7 +16,7 @@ :global SendNtfy2; # flush ntfy queue -:set FlushNtfyQueue do={ :onerror Err { +:set FlushNtfyQueue do={ :do { :global NtfyQueue; :global IsFullyConnected; @@ -36,13 +36,13 @@ :foreach Id,Message in=$NtfyQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :onerror Err { + :do { /tool/fetch check-certificate=yes-without-crl output=none http-method=post \ http-header-field=($Message->"headers") http-data=($Message->"text") \ ($Message->"url") as-value; :set ($NtfyQueue->$Id); - } do={ - $LogPrint debug $0 ("Sending queued Ntfy message failed: " . $Err); + } on-error={ + $LogPrint debug $0 ("Sending queued Ntfy message failed."); :set AllDone false; } } @@ -52,8 +52,8 @@ /system/scheduler/remove [ find where name="_FlushNtfyQueue" ]; :set NtfyQueue; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via ntfy - expects one array argument @@ -107,7 +107,7 @@ :set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")); } - :onerror Err { + :do { :if ($Server = "ntfy.sh") do={ :if ([ $CertificateAvailable "ISRG Root X1" ] = false) do={ $LogPrint warning $0 ("Downloading required certificate failed."); @@ -116,8 +116,8 @@ } /tool/fetch check-certificate=yes-without-crl output=none http-method=post \ http-header-field=$Headers http-data=$Text $Url as-value; - } do={ - $LogPrint info $0 ("Failed sending ntfy notification: " . $Err . " - Queuing..."); + } on-error={ + $LogPrint info $0 ("Failed sending ntfy notification! Queuing..."); :if ([ :typeof $NtfyQueue ] = "nothing") do={ :set NtfyQueue ({}); @@ -143,12 +143,12 @@ } # send notification via ntfy - expects at least two string arguments -:set SendNtfy do={ :onerror Err { +:set SendNtfy do={ :do { :global SendNtfy2; $SendNtfy2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 }); -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via ntfy - expects one array argument diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc index 2eb90e12..5ef353b4 100644 --- a/mod/notification-telegram.rsc +++ b/mod/notification-telegram.rsc @@ -17,7 +17,7 @@ :global SendTelegram2; # flush telegram queue -:set FlushTelegramQueue do={ :onerror Err { +:set FlushTelegramQueue do={ :do { :global TelegramQueue; :global TelegramMessageIDs; @@ -38,14 +38,14 @@ :foreach Id,Message in=$TelegramQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :onerror Err { + :do { :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user http-method=post \ ("https://api.telegram.org/bot" . ($Message->"tokenid") . "/sendMessage") \ http-data=($Message->"http-data") as-value ]->"data"); :set ($TelegramQueue->$Id); :set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1; - } do={ - $LogPrint debug $0 ("Sending queued Telegram message failed: " . $Err); + } on-error={ + $LogPrint debug $0 ("Sending queued Telegram message failed."); :set AllDone false; } } @@ -55,12 +55,12 @@ /system/scheduler/remove [ find where name="_FlushTelegramQueue" ]; :set TelegramQueue; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # get the chat id -:set GetTelegramChatId do={ :onerror Err { +:set GetTelegramChatId do={ :do { :global TelegramTokenId; :global CertificateAvailable; @@ -72,12 +72,12 @@ } :local Data; - :onerror Err { + :do { :set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ ("https://api.telegram.org/bot" . $TelegramTokenId . "/getUpdates?offset=0" . \ "&allowed_updates=%5B%22message%22%5D") as-value ]->"data"); - } do={ - $LogPrint warning $0 ("Fetching data failed: " . $Err); + } on-error={ + $LogPrint warning $0 ("Fetching data failed!"); :return false; } @@ -94,8 +94,8 @@ :if (($Message->"is_topic_message") = true) do={ $LogPrint info $0 ("The thread id is: " . ($Message->"message_thread_id")); } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via telegram - expects one array argument @@ -189,8 +189,8 @@ :local HTTPData ("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \ "&reply_to_message_id=" . ($Notification->"replyto") . "&message_thread_id=" . $ThreadId . \ - "&disable_web_page_preview=true&parse_mode=MarkdownV2"); - :onerror Err { + "&disable_web_page_preview=true&parse_mode=MarkdownV2"); + :do { :if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" ] = false) do={ $LogPrint warning $0 ("Downloading required certificate failed."); :error false; @@ -199,8 +199,8 @@ ("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \ http-data=($HTTPData . "&text=" . [ $UrlEncode $Text ]) as-value ]->"data"); :set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1; - } do={ - $LogPrint info $0 ("Failed sending Telegram notification: " . $Err . " - Queuing..."); + } on-error={ + $LogPrint info $0 ("Failed sending Telegram notification! Queuing..."); :if ([ :typeof $TelegramQueue ] = "nothing") do={ :set TelegramQueue ({}); @@ -226,12 +226,12 @@ } # send notification via telegram - expects at least two string arguments -:set SendTelegram do={ :onerror Err { +:set SendTelegram do={ :do { :global SendTelegram2; $SendTelegram2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 }); -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # send notification via telegram - expects one array argument diff --git a/mod/scriptrunonce.rsc b/mod/scriptrunonce.rsc index 1d6aaf1f..7fcd5b5b 100644 --- a/mod/scriptrunonce.rsc +++ b/mod/scriptrunonce.rsc @@ -11,7 +11,7 @@ :global ScriptRunOnce; # fetch and run script(s) once -:set ScriptRunOnce do={ :onerror Err { +:set ScriptRunOnce do={ :do { :local Scripts [ :toarray $1 ]; :global ScriptRunOnceBaseUrl; @@ -41,16 +41,16 @@ :return false; } - :onerror Err { + :do { $LogPrint info $0 ("Running script '" . $Script . "' now."); [ :parse $Source ]; - } do={ - $LogPrint warning $0 ("The script '" . $Script . "' failed to run: " . $Err); + } on-error={ + $LogPrint warning $0 ("The script '" . $Script . "' failed to run!"); :return false; } :return true; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } diff --git a/mod/ssh-keys-import.rsc b/mod/ssh-keys-import.rsc index 94675255..2fae4b13 100644 --- a/mod/ssh-keys-import.rsc +++ b/mod/ssh-keys-import.rsc @@ -12,7 +12,7 @@ :global SSHKeysImportFile; # import single key passed as string -:set SSHKeysImport do={ :onerror Err { +:set SSHKeysImport do={ :do { :local Key [ :tostr $1 ]; :local User [ :tostr $2 ]; @@ -55,22 +55,22 @@ /file/add name=$FileName contents=($Key . ", md5=" . $FingerPrintMD5); $WaitForFile $FileName; - :onerror Err { + :do { /user/ssh-keys/import public-key-file=$FileName user=$User; $LogPrint info $0 ("Imported ssh public key (" . $KeyVal->2 . ", " . $KeyVal->0 . ", " . \ "MD5:" . $FingerPrintMD5 . ") for user '" . $User . "'."); $RmDir "tmpfs/ssh-keys-import"; - } do={ - $LogPrint warning $0 ("Failed importing key: " . $Err); + } on-error={ + $LogPrint warning $0 ("Failed importing key."); $RmDir "tmpfs/ssh-keys-import"; :return false; } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } # import keys from a file -:set SSHKeysImportFile do={ :onerror Err { +:set SSHKeysImportFile do={ :do { :local FileName [ :tostr $1 ]; :local User [ :tostr $2 ]; @@ -94,7 +94,9 @@ :foreach KeyVal in=[ :deserialize $Keys delimiter=" " from=dsv options=dsv.plain ] do={ :local Continue false; :if ($KeyVal->0 = "ssh-ed25519" || $KeyVal->0 = "ssh-rsa") do={ - :if ([ $SSHKeysImport ($KeyVal->0 . " " . $KeyVal->1 . " " . $KeyVal->2) $User ] = false) do={ + :do { + $SSHKeysImport ($KeyVal->0 . " " . $KeyVal->1 . " " . $KeyVal->2) $User; + } on-error={ $LogPrint warning $0 ("Failed importing key for user '" . $User . "'."); } :set Continue true; @@ -107,6 +109,6 @@ $LogPrint warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported."); } } -} do={ - :global ExitError; $ExitError false $0 $Err; +} on-error={ + :global ExitError; $ExitError false $0; } } diff --git a/mode-button.rsc b/mode-button.rsc index d82f8995..edc5f400 100644 --- a/mode-button.rsc +++ b/mode-button.rsc @@ -9,11 +9,11 @@ # act on multiple mode and reset button presses # https://rsc.eworm.de/doc/mode-button.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global ModeButton; @@ -26,7 +26,7 @@ :if ([ :len $Scheduler ] = 0) do={ $LogPrint info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses..."); - :global ModeButtonScheduler do={ :onerror Err { + :global ModeButtonScheduler do={ :do { :local FuncName $0; :global ModeButton; @@ -69,11 +69,11 @@ :delay 200ms; } - :onerror Err { + :do { [ :parse $Code ]; - } do={ + } on-error={ $LogPrint warning $FuncName \ - ("The code for " . $Count . " mode-button presses failed with runtime error: " . $Err); + ("The code for " . $Count . " mode-button presses failed with runtime error!"); } } else={ $LogPrint warning $FuncName \ @@ -82,8 +82,8 @@ } else={ $LogPrint info $FuncName ("No action defined for " . $Count . " mode-button presses."); } - } do={ - :global ExitError; $ExitError false $0 $Err; + } on-error={ + :global ExitError; $ExitError false $0; } } /system/scheduler/add name="_ModeButtonScheduler" \ on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s; @@ -91,6 +91,6 @@ $LogPrint debug $ScriptName ("Updating scheduler _ModeButtonScheduler..."); /system/scheduler/set $Scheduler start-time=[ /system/clock/get time ]; } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/netwatch-dns.rsc b/netwatch-dns.rsc index 4fa076af..467d6362 100644 --- a/netwatch-dns.rsc +++ b/netwatch-dns.rsc @@ -9,11 +9,11 @@ # monitor and manage dns/doh with netwatch # https://rsc.eworm.de/doc/netwatch-dns.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CertificateAvailable; @@ -118,15 +118,15 @@ } :local Data false; - :onerror Err { + :do { :set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ http-header-field=({ "accept: application/dns-message" }) \ url=(($DohServer->"doh-url") . "?dns=" . [ :convert to=base64 ([ :rndstr length=2 ] . \ "\01\00" . "\00\01" . "\00\00" . "\00\00" . "\00\00" . "\09doh-check\05eworm\02de\00" . \ "\00\10" . "\00\01") ]) as-value ]->"data"); - } do={ - $LogPrint warning $ScriptName ("Request to DoH server " . ($DohServer->"doh-url") . \ - " failed: " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("Request to DoH server failed (network or certificate issue): " . \ + ($DohServer->"doh-url")); } :if ($Data != false) do={ @@ -145,6 +145,6 @@ } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc index 00f03cde..0b8a8dc5 100644 --- a/netwatch-notify.rsc +++ b/netwatch-notify.rsc @@ -8,11 +8,11 @@ # monitor netwatch and send notifications # https://rsc.eworm.de/doc/netwatch-notify.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global NetwatchNotify; @@ -38,10 +38,10 @@ :global ValidateSyntax; :if ([ $ValidateSyntax $Hook ] = true) do={ - onerror Err { + :do { [ :parse $Hook ]; - } do={ - $LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run: " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run."); :return ("The hook failed to run."); } } else={ @@ -107,7 +107,7 @@ :if ([ :typeof ($HostInfo->"resolve") ] = "str") do={ :if ([ $IsDNSResolving ] = true) do={ - :onerror Err { + :do { :local Resolve [ :resolve type=[ $IfThenElse ([ :typeof ($HostVal->"host") ] = "ip") \ "ipv4" "ipv6" ] ($HostInfo->"resolve") ]; :if ($Resolve != $HostVal->"host") do={ @@ -121,13 +121,13 @@ :set ($HostVal->"status") "unknown"; } } - } do={ + } on-error={ :set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1); :if ($Metric->"resolve-failcnt" = 3) do={ $LogPrint [ $IfThenElse ($HostInfo->"no-resolve-fail" != true) warning debug ] \ $ScriptName ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse \ ($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \ - $HostInfo->"name") "" ] . "' failed: " . $Err); + $HostInfo->"name") "" ] . "' failed."); } } } @@ -224,6 +224,6 @@ "since"=($Metric->"since") }; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/ospf-to-leds.rsc b/ospf-to-leds.rsc index 26f8aa37..a8662b32 100644 --- a/ospf-to-leds.rsc +++ b/ospf-to-leds.rsc @@ -8,11 +8,11 @@ # visualize ospf instance state via leds # https://rsc.eworm.de/doc/ospf-to-leds.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -44,6 +44,6 @@ /system/leds/set type=off [ find where leds=$LED ]; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/packages-update.rsc b/packages-update.rsc index 4fde131b..b11596ea 100644 --- a/packages-update.rsc +++ b/packages-update.rsc @@ -9,11 +9,11 @@ # download packages and reboot for installation # https://rsc.eworm.de/doc/packages-update.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global BackupRandomDelay; @@ -163,6 +163,6 @@ $LogPrint info $ScriptName ("Rebooting for update."); :delay 1s; /system/reboot; -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/ppp-on-up.rsc b/ppp-on-up.rsc index f16d73f3..e09bd9d5 100644 --- a/ppp-on-up.rsc +++ b/ppp-on-up.rsc @@ -8,11 +8,11 @@ # run scripts on ppp up # https://rsc.eworm.de/doc/ppp-on-up.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global LogPrint; @@ -39,6 +39,6 @@ $LogPrint warning $ScriptName ("Running script '" . $ScriptName . "' failed!"); } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/sms-action.rsc b/sms-action.rsc index 47e19223..3c8307a8 100644 --- a/sms-action.rsc +++ b/sms-action.rsc @@ -8,11 +8,11 @@ # run action on received SMS # https://rsc.eworm.de/doc/sms-action.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global SmsAction; @@ -36,6 +36,6 @@ } else={ $LogPrint warning $ScriptName ("The code for action '" . $Action . "' failed syntax validation!"); } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/sms-forward.rsc b/sms-forward.rsc index feb640e5..8169022c 100644 --- a/sms-forward.rsc +++ b/sms-forward.rsc @@ -9,11 +9,11 @@ # forward SMS to e-mail # https://rsc.eworm.de/doc/sms-forward.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -61,12 +61,7 @@ :if ($Phone = $Settings->"allowed-number" && \ ($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={ $LogPrint debug $ScriptName ("Removing SMS, which started a script."); - :onerror Err { - /tool/sms/inbox/remove $Sms; - :delay 50ms; - } do={ - $LogPrint warning $ScriptName ("Failed to remove message: " . $Err); - } + /tool/sms/inbox/remove $Sms; } else={ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ " type " . $SmsVal->"type" . ":\n" . $SmsVal->"message"); @@ -74,12 +69,12 @@ :if ($Phone~($Hook->"allowed-number") && ($SmsVal->"message")~($Hook->"match")) do={ :if ([ $ValidateSyntax ($Hook->"command") ] = true) do={ $LogPrint info $ScriptName ("Running hook '" . $Hook->"match" . "': " . $Hook->"command"); - :onerror Err { + :do { :local Command [ :parse ($Hook->"command") ]; $Command Phone=$Phone Message=($SmsVal->"message"); :set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . $Hook->"command"); - } do={ - $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run: " . $Err); + } on-error={ + $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run!"); } } else={ $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed syntax validation!"); @@ -97,15 +92,10 @@ message=("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \ " by " . $Identity . " from " . $Phone . ":" . $Messages) }); :foreach Sms in=$Delete do={ - :onerror Err { - /tool/sms/inbox/remove $Sms; - :delay 50ms; - } do={ - $LogPrint warning $ScriptName ("Failed to remove message: " . $Err); - } + /tool/sms/inbox/remove $Sms; } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/telegram-chat.rsc b/telegram-chat.rsc index 277c40fc..5db4860f 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -9,11 +9,11 @@ # use Telegram to chat with your Router and send commands # https://rsc.eworm.de/doc/telegram-chat.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global Identity; @@ -33,7 +33,6 @@ :global GetRandom20CharAlNum; :global IfThenElse; :global LogPrint; - :global LogPrintVerbose; :global MAX; :global MIN; :global MkDir; @@ -71,14 +70,14 @@ :local Data false; :for I from=1 to=4 do={ :if ($Data = false) do={ - :onerror Err { + :do { :set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ ("https://api.telegram.org/bot" . $TelegramTokenId . "/getUpdates?offset=" . \ $TelegramChatOffset->0 . "&allowed_updates=%5B%22message%22%5D") as-value ]->"data"); :set TelegramRandomDelay [ $MAX 0 ($TelegramRandomDelay - 1) ]; - } do={ + } on-error={ :if ($I < 4) do={ - $LogPrint debug $ScriptName ("Fetch failed, " . $I . ". try: " . $Err); + $LogPrint debug $ScriptName ("Fetch failed, " . $I . ". try."); :set TelegramRandomDelay [ $MIN 15 ($TelegramRandomDelay + 5) ]; :delay (($I * $I) . "s"); } @@ -97,8 +96,6 @@ :local Uptime [ /system/resource/get uptime ]; :foreach Update in=($JSON->"result") do={ :set UpdateID ($Update->"update_id"); - $LogPrintVerbose debug $ScriptName ("Update " . $UpdateID . ": " . [ :serialize to=json $Update ]); - :local Message ($Update->"message"); :local IsReply ([ :typeof ($Message->"reply_to_message") ] = "string"); :local IsMyReply ($TelegramMessageIDs->[ :tostr ($Message->"reply_to_message"->"message_id") ]); @@ -110,9 +107,7 @@ :local ThreadId [ $IfThenElse ($Message->"is_topic_message") ($Message->"message_thread_id") "" ]; :foreach IdsTrusted in=($TelegramChatId, $TelegramChatIdsTrusted) do={ - :if ($From->"id" = $IdsTrusted || \ - $From->"username" = $IdsTrusted || \ - $Chat->"id" = $IdsTrusted) do={ + :if ($From->"id" = $IdsTrusted || $From->"username" = $IdsTrusted) do={ :set Trusted true; } } @@ -195,6 +190,6 @@ } :set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \ [ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]); -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/unattended-lte-firmware-upgrade.rsc b/unattended-lte-firmware-upgrade.rsc index 237c2d83..83925fd9 100644 --- a/unattended-lte-firmware-upgrade.rsc +++ b/unattended-lte-firmware-upgrade.rsc @@ -12,10 +12,10 @@ :foreach Interface in=[ /interface/lte/find where running ] do={ :local Firmware; :local IntName [ /interface/lte/get $Interface name ]; - :onerror Err { + :do { :set Firmware [ /interface/lte/firmware-upgrade $Interface as-value ]; - } do={ - :log debug ("Could not get latest LTE firmware version for interface " . $IntName . ": " . $Err); + } on-error={ + :log debug ("Could not get latest LTE firmware version for interface " . $IntName . "."); } :if ([ :typeof $Firmware ] = "array") do={ @@ -27,7 +27,7 @@ :set LTEFirmwareUpgrade; /system/scheduler/remove ($1 . "-firmware-upgrade"); - :onerror Err { + :do { /interface/lte/firmware-upgrade $1 upgrade=yes; :log info ("LTE firmware upgrade on '" . $1 . "' finished, waiting for reset."); :delay 240s; @@ -36,8 +36,8 @@ ($Firmware->"installed") != ($Firmware->"latest")) do={ :log warning ("LTE firmware versions still differ. Upgrade failed anyway?"); } - } do={ - :log error ("LTE firmware upgrade on '" . $1 . "' failed: " . $Err); + } on-error={ + :log error ("LTE firmware upgrade on '" . $1 . "' failed."); } } diff --git a/update-gre-address.rsc b/update-gre-address.rsc index dd7d63e4..cddfa92f 100644 --- a/update-gre-address.rsc +++ b/update-gre-address.rsc @@ -9,11 +9,11 @@ # ipsec remote peer # https://rsc.eworm.de/doc/update-gre-address.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CharacterReplace; @@ -41,6 +41,6 @@ } } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; } diff --git a/update-tunnelbroker.rsc b/update-tunnelbroker.rsc index 9057e1e4..45afa6f8 100644 --- a/update-tunnelbroker.rsc +++ b/update-tunnelbroker.rsc @@ -11,11 +11,11 @@ # update local address of tunnelbroker interface # https://rsc.eworm.de/doc/update-tunnelbroker.md +:global GlobalFunctionsReady; +:while ($GlobalFunctionsReady != true) do={ :delay 500ms; } + :local ExitOK false; -:onerror Err { - :global GlobalConfigReady; :global GlobalFunctionsReady; - :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ - do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50; +:do { :local ScriptName [ :jobname ]; :global CertificateAvailable; @@ -41,12 +41,12 @@ :for I from=2 to=0 do={ :if ($Data = false) do={ - :onerror Err { + :do { :set Data ([ /tool/fetch check-certificate=yes-without-crl \ ("https://ipv4.tunnelbroker.net/nic/update?hostname=" . $Comment->"id") \ user=($Comment->"user") password=($Comment->"pass") output=user as-value ]->"data"); - } do={ - $LogPrint debug $ScriptName ("Failed downloading: " . $Err . " - " . $I . " retries pending."); + } on-error={ + $LogPrint debug $ScriptName ("Failed downloading, " . $I . " retries pending."); :delay 2s; } } @@ -69,6 +69,6 @@ /interface/6to4/set $Interface local-address=$PublicAddress; } } -} do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; +} on-error={ + :global ExitError; $ExitError $ExitOK [ :jobname ]; }