From 48336ac82ccc898057ffb549fae2f498be2ec4db Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 May 2025 17:59:20 +0200 Subject: [PATCH 01/49] backup-partition: :do ... on-error=... -> :onerror ... do=... --- backup-partition.rsc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/backup-partition.rsc b/backup-partition.rsc index c2221d2c..88ab3b60 100644 --- a/backup-partition.rsc +++ b/backup-partition.rsc @@ -32,12 +32,13 @@ :global LogPrint; - :do { + :onerror Err { /partitions/copy-to $FallbackTo; $LogPrint info $ScriptName ("Copied RouterOS to partition '" . $FallbackToName . "'."); :return true; - } on-error={ - $LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . $FallbackToName . "'!"); + } do={ + $LogPrint error $ScriptName ("Failed copying RouterOS to partition '" . \ + $FallbackToName . "': " . $Err); :return false; } } @@ -107,16 +108,17 @@ } } - :do { + :onerror Err { /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 . "'."); - } on-error={ + } do={ /system/scheduler/remove [ find where name="running-from-backup-partition" ]; - $LogPrint error $ScriptName ("Failed saving configuration to partition '" . $FallbackToName . "'!"); + $LogPrint error $ScriptName ("Failed saving configuration to partition '" . \ + $FallbackToName . "': " . $Err); :set PackagesUpdateBackupFailure true; :set ExitOK true; :error false; From 34227831913c9373f6922deb819c69e7279c4a3f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 May 2025 18:03:30 +0200 Subject: [PATCH 02/49] backup-upload: :do ... on-error=... -> :onerror ... do=... --- backup-upload.rsc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backup-upload.rsc b/backup-upload.rsc index 11ced4ca..e6b9f92f 100644 --- a/backup-upload.rsc +++ b/backup-upload.rsc @@ -90,13 +90,13 @@ /system/backup/save encryption=aes-sha256 name=$FilePath password=$BackupPassword; $WaitForFile ($FilePath . ".backup"); - :do { + :onerror Err { /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"); - } on-error={ - $LogPrint error $ScriptName ("Uploading backup file failed!"); + } do={ + $LogPrint error $ScriptName ("Uploading backup file failed: " . $Err); :set BackupFile "failed"; :set Failed 1; } @@ -109,13 +109,13 @@ /export terse show-sensitive file=$FilePath; $WaitForFile ($FilePath . ".rsc"); - :do { + :onerror Err { /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"); - } on-error={ - $LogPrint error $ScriptName ("Uploading configuration export failed!"); + } do={ + $LogPrint error $ScriptName ("Uploading configuration export failed: " . $Err); :set ExportFile "failed"; :set Failed 1; } @@ -130,13 +130,13 @@ file=($FilePath . ".conf\00"); $WaitForFile ($FilePath . ".conf"); - :do { + :onerror Err { /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"); - } on-error={ - $LogPrint error $ScriptName ("Uploading global-config-overlay failed!"); + } do={ + $LogPrint error $ScriptName ("Uploading global-config-overlay failed: " . $Err); :set ConfigFile "failed"; :set Failed 1; } From 89f569c7c0705705a9e6ecdf829dd185d511bc02 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:04:15 +0200 Subject: [PATCH 03/49] check-health: :do ... on-error=... -> :onerror ... do=... --- check-health.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check-health.rsc b/check-health.rsc index 1b92d1e4..4cb99408 100644 --- a/check-health.rsc +++ b/check-health.rsc @@ -89,10 +89,10 @@ :foreach Plugin in=$Plugins do={ :local PluginVal [ /system/script/get $Plugin ]; :if ([ $ValidateSyntax ($PluginVal->"source") ] = true) do={ - :do { + :onerror Err { /system/script/run $Plugin; - } on-error={ - $LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed to run."); + } do={ + $LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed to run: " . $Err); } } else={ $LogPrint error $ScriptName ("Plugin '" . $ScriptVal->"name" . "' failed syntax validation, skipping."); From 5cc8b7281a7812966cc15d2c115bca4da404b790 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:05:41 +0200 Subject: [PATCH 04/49] check-lte-firmware-upgrade: :do ... on-error=... -> :onerror ... do=... --- check-lte-firmware-upgrade.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check-lte-firmware-upgrade.rsc b/check-lte-firmware-upgrade.rsc index 1a5e08ce..9f4b6562 100644 --- a/check-lte-firmware-upgrade.rsc +++ b/check-lte-firmware-upgrade.rsc @@ -45,12 +45,12 @@ :local IntName [ /interface/lte/get $Interface name ]; :local Firmware; :local Info; - :do { + :onerror Err { :set Firmware [ /interface/lte/firmware-upgrade $Interface as-value ]; :set Info [ /interface/lte/monitor $Interface once as-value ]; - } on-error={ + } do={ $LogPrint debug $ScriptName ("Could not get latest LTE firmware version for interface " . \ - $IntName . "."); + $IntName . ": " . $Err); :return false; } From 72a7f20a64e2a63d70971a5447751a7754e19330 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:06:25 +0200 Subject: [PATCH 05/49] check-routeros-update: :do ... on-error=... -> :onerror ... do=... --- check-routeros-update.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check-routeros-update.rsc b/check-routeros-update.rsc index 34d06475..e28a0190 100644 --- a/check-routeros-update.rsc +++ b/check-routeros-update.rsc @@ -141,13 +141,13 @@ :if ([ :len $SafeUpdateUrl ] > 0) do={ :local Result; - :do { + :onerror Err { :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 ]; - } on-error={ - $LogPrint warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . "."); + } do={ + $LogPrint warning $ScriptName ("Failed receiving safe version for " . $Update->"channel" . ": " . $Err); } :if ($Result->"status" = "finished" && $Result->"data" = $Update->"latest-version") do={ $LogPrint info $ScriptName ("Version " . $Update->"latest-version" . " is considered safe, updating..."); From cefc9d7e4bb769347ec166b4d14f3107c9068587 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:17:46 +0200 Subject: [PATCH 06/49] fw-addr-lists: :do ... on-error=... -> :onerror ... do=... --- fw-addr-lists.rsc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fw-addr-lists.rsc b/fw-addr-lists.rsc index 4ee3c344..659fb2f9 100644 --- a/fw-addr-lists.rsc +++ b/fw-addr-lists.rsc @@ -176,13 +176,13 @@ :foreach Address,Timeout in=$Branch do={ $LogPrintVerbose debug $ScriptName ("Adding IPv4 address to list '" . $FwListName . \ "' with " . $Timeout . ": " . $Address); - :do { + :onerror Err { /ip/firewall/address-list/add list=$FwListName comment=$ListComment \ address=$Address timeout=$Timeout; :set CntAdd ($CntAdd + 1); - } on-error={ - $LogPrint warning $ScriptName ("Failed to add IPv4 address to list '" . $FwListName . \ - "': " . $Address); + } do={ + $LogPrint warning $ScriptName ("Failed to add IPv4 address " . $Address . \ + " to list '" . $FwListName . "': " . $Err); } } } @@ -192,13 +192,13 @@ :foreach Address,Timeout in=$Branch do={ $LogPrintVerbose debug $ScriptName ("Adding IPv6 address to list '" . $FwListName . \ "' with " . $Timeout . ": " . $Address); - :do { + :onerror Err { /ipv6/firewall/address-list/add list=$FwListName comment=$ListComment \ address=$Address timeout=$Timeout; :set CntAdd ($CntAdd + 1); - } on-error={ - $LogPrint warning $ScriptName ("Failed to add IPv6 address to list '" . $FwListName . \ - "': " . $Address); + } do={ + $LogPrint warning $ScriptName ("Failed to add IPv6 address " . $Address . \ + " to list '" . $FwListName . "': " . $Err); } } } From fc742edc587dd8d85662dee434599d3e33625f34 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:21:03 +0200 Subject: [PATCH 07/49] fw-addr-lists: adopt changes in wording --- fw-addr-lists.rsc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fw-addr-lists.rsc b/fw-addr-lists.rsc index 659fb2f9..5a03875d 100644 --- a/fw-addr-lists.rsc +++ b/fw-addr-lists.rsc @@ -135,15 +135,15 @@ :local Branch [ $GetBranch $Address ]; :local TimeOut ($IPv4Addresses->$Branch->$Address); :if ([ :typeof $TimeOut ] = "time") do={ - $LogPrintVerbose debug $ScriptName ("Renewing IPv4 address in list '" . $FwListName . \ - "' with " . $TimeOut . ": " . $Address); + $LogPrintVerbose debug $ScriptName ("Renewing IPv4 address " . $Address . \ + " in list '" . $FwListName . "' with " . $TimeOut . "."); /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 from list '" . $FwListName . \ - "': " . $Address); + $LogPrintVerbose debug $ScriptName ("Removing IPv4 address " . $Address . \ + " from list '" . $FwListName . "."); /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 in list '" . $FwListName . \ - "' with " . $TimeOut . ": " . $Address); + $LogPrintVerbose debug $ScriptName ("Renewing IPv6 address " . $Address . \ + " in list '" . $FwListName . "' with " . $TimeOut . "."); /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 from list '" . $FwListName . \ - "': " . $Address); + $LogPrintVerbose debug $ScriptName ("Removing IPv6 address " . $Address . \ + " from list '" . $FwListName ."."); /ipv6/firewall/address-list/remove $Entry; :set CntRemove ($CntRemove + 1); } @@ -174,8 +174,8 @@ :foreach BranchName,Branch in=$IPv4Addresses do={ $LogPrintVerbose debug $ScriptName ("Handling branch: " . $BranchName); :foreach Address,Timeout in=$Branch do={ - $LogPrintVerbose debug $ScriptName ("Adding IPv4 address to list '" . $FwListName . \ - "' with " . $Timeout . ": " . $Address); + $LogPrintVerbose debug $ScriptName ("Adding IPv4 address " . $Address . \ + " to list '" . $FwListName . "' with " . $Timeout . "."); :onerror Err { /ip/firewall/address-list/add list=$FwListName comment=$ListComment \ address=$Address timeout=$Timeout; @@ -190,8 +190,8 @@ :foreach BranchName,Branch in=$IPv6Addresses do={ $LogPrintVerbose debug $ScriptName ("Handling branch: " . $BranchName); :foreach Address,Timeout in=$Branch do={ - $LogPrintVerbose debug $ScriptName ("Adding IPv6 address to list '" . $FwListName . \ - "' with " . $Timeout . ": " . $Address); + $LogPrintVerbose debug $ScriptName ("Adding IPv6 address " . $Address . \ + " to list '" . $FwListName . "' with " . $Timeout . "."); :onerror Err { /ipv6/firewall/address-list/add list=$FwListName comment=$ListComment \ address=$Address timeout=$Timeout; From c36e303e01804552cef44d59884c0ca5673051df Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:22:02 +0200 Subject: [PATCH 08/49] global-config: :do ... on-error=... -> :onerror ... do=... --- global-config.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-config.rsc b/global-config.rsc index 589a58a4..86d528aa 100644 --- a/global-config.rsc +++ b/global-config.rsc @@ -277,11 +277,11 @@ # load custom settings from overlay and snippets :foreach Script in=([ /system/script/find where name="global-config-overlay" ], \ [ /system/script/find where name~"^global-config-overlay.d/" ]) do={ - :do { + :onerror Err { /system/script/run $Script; - } on-error={ + } do={ :log error ("Loading configuration from overlay or snippet " . \ - [ /system/script/get $Script name ] . " failed!"); + [ /system/script/get $Script name ] . " failed: " . $Err); } } From 0e891b09636a8fdb262b9db09220b8b50e7d1604 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:23:16 +0200 Subject: [PATCH 09/49] global-functions: $DownloadPackage: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index 6e3d7120..0b4c3897 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -393,15 +393,15 @@ $LogPrint debug $0 ("... from url: " . $Url); :local Retry 3; :while ($Retry > 0) do={ - :do { + :onerror Err { /tool/fetch check-certificate=yes-without-crl $Url dst-path=$PkgDest; $WaitForFile $PkgDest; :if ([ /file/get [ find where name=$PkgDest ] type ] = "package") do={ :return true; } - } on-error={ - $LogPrint debug $0 ("Downloading package file failed."); + } do={ + $LogPrint debug $0 ("Downloading package file failed: " . $Err); } $RmFile $PkgDest; From d419e58abd168edaab89ae433434e53fdf7a54ea Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:24:56 +0200 Subject: [PATCH 10/49] global-functions: $FetchHuge: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index 0b4c3897..fd43ecc6 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -489,14 +489,14 @@ } :local FileName ($DirName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]); - :do { + :onerror Err { /tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \ http-header-field=({ [ $FetchUserAgentStr $ScriptName ] }) as-value; - } on-error={ + } do={ :if ([ $WaitForFile $FileName 500ms ] = true) do={ $RmFile $FileName; } - $LogPrint debug $0 ("Failed downloading from: " . $Url); + $LogPrint debug $0 ("Failed downloading from " . $Url . " - " . $Err); $RmDir $DirName; :return false; } From efd259f8680ec1254bba0c4ef61c13f9fe78fc53 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:26:53 +0200 Subject: [PATCH 11/49] global-functions: $GetMacVendor: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index fd43ecc6..a4d4e1c5 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -589,12 +589,12 @@ ("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data"); :return $Vendor; } on-error={ - :do { + :onerror Err { /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."); - } on-error={ - $LogPrint warning $0 ("Failed getting mac vendor."); + } do={ + $LogPrint warning $0 ("Failed getting mac vendor: " . $Err); } :return "unknown vendor"; } From 9b46c3664104e04f711c0a544cf35807912b0468 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:27:50 +0200 Subject: [PATCH 12/49] global-functions: $MkDir: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index a4d4e1c5..ecdbec85 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -897,11 +897,11 @@ $LogPrint info $0 ("Creating disk of type tmpfs."); $RmDir "tmpfs"; - :do { + :onerror Err { /disk/add slot=tmpfs type=tmpfs tmpfs-max-size=([ /system/resource/get total-memory ] / 3); $WaitForFile "tmpfs"; - } on-error={ - $LogPrint warning $0 ("Creating disk of type tmpfs failed!"); + } do={ + $LogPrint warning $0 ("Creating disk of type tmpfs failed: " . $Err); :return false; } :return true; @@ -926,11 +926,11 @@ } } - :do { + :onerror Err { /file/add type="directory" name=$Path; $WaitForFile $Path; - } on-error={ - $LogPrint warning $0 ("Making directory '" . $Path . "' failed!"); + } do={ + $LogPrint warning $0 ("Making directory '" . $Path . "' failed: " . $Err); :return false; } From 4cdcd081e57356d9dc47ed86097827fafb79ccb6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:29:22 +0200 Subject: [PATCH 13/49] global-functions: $RmDir: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index ecdbec85..b600be24 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1055,10 +1055,10 @@ :return true; } - :do { + :onerror Err { /file/remove $Dir; - } on-error={ - $LogPrint error $0 ("Removing directory '" . $DirName . "' (" . $Dir . ") failed."); + } do={ + $LogPrint error $0 ("Removing directory '" . $DirName . "' (" . $Dir . ") failed: " . $Err); :return false; } :return true; From c0ea72ec7ab5af9e24385ab181b189a586ef9b24 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:30:08 +0200 Subject: [PATCH 14/49] global-functions: $RmFile: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index b600be24..52bcd140 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1083,10 +1083,10 @@ :return true; } - :do { + :onerror Err { /file/remove $File; - } on-error={ - $LogPrint error $0 ("Removing file '" . $FileName . "' (" . $File . ") failed."); + } do={ + $LogPrint error $0 ("Removing file '" . $FileName . "' (" . $File . ") failed: " . $Err); :return false; } :return true; From 172ca2c709cc86e5d2dca087dd2e0150aee6e8be Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:33:39 +0200 Subject: [PATCH 15/49] global-functions: $ScriptInstallUpdate: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index 52bcd140..db6eb383 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1204,7 +1204,7 @@ } } - :do { + :onerror Err { :local BaseUrl [ $EitherOr ($ScriptInfo->"base-url") $ScriptUpdatesBaseUrl ]; :local UrlSuffix [ $EitherOr ($ScriptInfo->"url-suffix") $ScriptUpdatesUrlSuffix ]; :local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix); @@ -1214,13 +1214,11 @@ :if ($Result->"status" = "finished") do={ :set SourceNew [ :tolf ($Result->"data") ]; } - } on-error={ + } do={ + $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . . "': " . $Err); :if ($ScriptVal->"source" = "#!rsc by RouterOS\n") do={ - $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . \ - "', removing dummy. Typo on installation?"); + $LogPrint warning $0 ("Removing dummy. Typo on installation?"); /system/script/remove $Script; - } else={ - $LogPrint warning $0 ("Failed fetching script '" . $ScriptVal->"name" . "'!"); } :error false; } @@ -1307,7 +1305,7 @@ :global GlobalConfigMigration; :local ChangeLogCode; - :do { + :onerror Err { :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 \ @@ -1315,16 +1313,16 @@ :if ($Result->"status" = "finished") do={ :set ChangeLogCode ($Result->"data"); } - } on-error={ - $LogPrint warning $0 ("Failed fetching news, changes and migration!"); + } do={ + $LogPrint warning $0 ("Failed fetching news, changes and migration: " . $Err); } :if ([ :len $ChangeLogCode ] > 0) do={ :if ([ $ValidateSyntax $ChangeLogCode ] = true) do={ - :do { + :onerror Err { [ :parse $ChangeLogCode ]; - } on-error={ - $LogPrint warning $0 ("The changelog failed to run!"); + } do={ + $LogPrint warning $0 ("The changelog failed to run: " . $Err); } } else={ $LogPrint warning $0 ("The changelog failed syntax validation!"); @@ -1346,10 +1344,10 @@ } $LogPrint info $0 ("Applying migration for change " . $I . ": " . $Migration); - :do { + :onerror Err { [ :parse $Migration ]; - } on-error={ - $LogPrint warning $0 ("Migration code for change " . $I . " failed to run!"); + } do={ + $LogPrint warning $0 ("Migration code for change " . $I . " failed to run: " . $Err); } } on-error={ } } From 912061b62476f278f78401e71b3455bb5af9120d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:37:18 +0200 Subject: [PATCH 16/49] global-functions: $ValidateSyntax: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index db6eb383..839dbf26 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1655,9 +1655,9 @@ :set ValidateSyntax do={ :local Code [ :tostr $1 ]; - :do { + :onerror Err { [ :parse (":local Validate do={\n" . $Code . "\n}") ]; - } on-error={ + } do={ :return false; } :return true; From 55e568414c32a8a0c8f7ec90b1700964b730efa0 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:39:17 +0200 Subject: [PATCH 17/49] global-functions: $ValidateSyntax: add debug output --- global-functions.rsc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/global-functions.rsc b/global-functions.rsc index 839dbf26..e03a076e 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1655,9 +1655,12 @@ :set ValidateSyntax do={ :local Code [ :tostr $1 ]; + :global LogPrint; + :onerror Err { [ :parse (":local Validate do={\n" . $Code . "\n}") ]; } do={ + $LogPrint debug $0 ("Valdation failed: " . $Err); :return false; } :return true; From 48eca31f3cf97b32cb6ed47d2918c0375e3c869e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:40:41 +0200 Subject: [PATCH 18/49] global-functions: :do ... on-error=... -> :onerror ... do=... --- global-functions.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index e03a076e..34bc60f5 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1774,10 +1774,10 @@ :foreach Script in=[ /system/script/find where name ~ "^mod/." ] do={ :local ScriptVal [ /system/script/get $Script ]; :if ([ $ValidateSyntax ($ScriptVal->"source") ] = true) do={ - :do { + :onerror Err { /system/script/run $Script; - } on-error={ - $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run."); + } do={ + $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed to run: " . $Err); } } else={ $LogPrint error $0 ("Module '" . $ScriptVal->"name" . "' failed syntax validation, skipping."); From ee9d61e28a62d19b8cffff8f1de31a9210b16b3e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:41:57 +0200 Subject: [PATCH 19/49] gps-track: :do ... on-error=... -> :onerror ... do=... --- gps-track.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gps-track.rsc b/gps-track.rsc index 4cc50663..6a090bfe 100644 --- a/gps-track.rsc +++ b/gps-track.rsc @@ -34,7 +34,7 @@ :local Gps [ /system/gps/monitor once as-value ]; :if ($Gps->"valid" = true) do={ - :do { + :onerror Err { /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,8 +42,8 @@ $LogPrint debug $ScriptName ("Sending GPS data in " . $CoordinateFormat . " format: " . \ "lat: " . ($Gps->"latitude") . " " . \ "lon: " . ($Gps->"longitude")); - } on-error={ - $LogPrint warning $ScriptName ("Failed sending GPS data!"); + } do={ + $LogPrint warning $ScriptName ("Failed sending GPS data: " . $Err); } } else={ $LogPrint debug $ScriptName ("GPS data not valid."); From 8c7cd61892533f66c7499161766b98d8439b69b2 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:42:48 +0200 Subject: [PATCH 20/49] lease-script: :do ... on-error=... -> :onerror ... do=... --- lease-script.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lease-script.rsc b/lease-script.rsc index b166ee3b..ab449568 100644 --- a/lease-script.rsc +++ b/lease-script.rsc @@ -53,11 +53,11 @@ } :foreach Order,Script in=$RunOrder do={ - :do { + :onerror Err { $LogPrint debug $ScriptName ("Running script with order " . $Order . ": " . $Script); /system/script/run $Script; - } on-error={ - $LogPrint warning $ScriptName ("Running script '" . $Script . "' failed!"); + } do={ + $LogPrint warning $ScriptName ("Running script '" . $Script . "' failed: " . $Err); } } } do={ From 9b9233a013cbde51d17c30887d7fba3a38522fa2 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:54:51 +0200 Subject: [PATCH 21/49] mod/notification-telegram: :do ... on-error=... -> :onerror ... do=... --- mod/notification-telegram.rsc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc index 51c8dbf7..0832b07e 100644 --- a/mod/notification-telegram.rsc +++ b/mod/notification-telegram.rsc @@ -38,14 +38,14 @@ :foreach Id,Message in=$TelegramQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :do { + :onerror Err { :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; - } on-error={ - $LogPrint debug $0 ("Sending queued Telegram message failed."); + } do={ + $LogPrint debug $0 ("Sending queued Telegram message failed: " . $Err); :set AllDone false; } } @@ -72,12 +72,12 @@ } :local Data; - :do { + :onerror Err { :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"); - } on-error={ - $LogPrint warning $0 ("Fetching data failed!"); + } do={ + $LogPrint warning $0 ("Fetching data failed: " . $Err); :return false; } @@ -190,7 +190,7 @@ :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"); - :do { + :onerror Err { :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; - } on-error={ - $LogPrint info $0 ("Failed sending Telegram notification! Queuing..."); + } do={ + $LogPrint info $0 ("Failed sending Telegram notification: " . $Err . " - Queuing..."); :if ([ :typeof $TelegramQueue ] = "nothing") do={ :set TelegramQueue ({}); From 0acb501ff5e031e4ee032fcd351f22a26ea7e457 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:55:55 +0200 Subject: [PATCH 22/49] mod/notification-ntfy: :do ... on-error=... -> :onerror ... do=... --- mod/notification-ntfy.rsc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mod/notification-ntfy.rsc b/mod/notification-ntfy.rsc index 8e5688e8..71140209 100644 --- a/mod/notification-ntfy.rsc +++ b/mod/notification-ntfy.rsc @@ -36,13 +36,13 @@ :foreach Id,Message in=$NtfyQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :do { + :onerror Err { /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); - } on-error={ - $LogPrint debug $0 ("Sending queued Ntfy message failed."); + } do={ + $LogPrint debug $0 ("Sending queued Ntfy message failed: " . $Err); :set AllDone false; } } @@ -107,7 +107,7 @@ :set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")); } - :do { + :onerror Err { :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; - } on-error={ - $LogPrint info $0 ("Failed sending ntfy notification! Queuing..."); + } do={ + $LogPrint info $0 ("Failed sending ntfy notification: " . $Err . " - Queuing..."); :if ([ :typeof $NtfyQueue ] = "nothing") do={ :set NtfyQueue ({}); From 29c6151d1edbea575433d05d43b868cd6d8d94c7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:57:31 +0200 Subject: [PATCH 23/49] mod/notification-matrix: :do ... on-error=... -> :onerror ... do=... --- mod/notification-matrix.rsc | 42 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/mod/notification-matrix.rsc b/mod/notification-matrix.rsc index c8cf887c..e9b42a0d 100644 --- a/mod/notification-matrix.rsc +++ b/mod/notification-matrix.rsc @@ -39,7 +39,7 @@ :foreach Id,Message in=$MatrixQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :do { + :onerror Err { /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); - } on-error={ - $LogPrint debug $0 ("Sending queued Matrix message failed."); + } do={ + $LogPrint debug $0 ("Sending queued Matrix message failed: " . $Err); :set AllDone false; } } @@ -129,15 +129,15 @@ [ $PrepareText $Label ] . ""); } - :do { + :onerror Err { /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; - } on-error={ - $LogPrint info $0 ("Failed sending Matrix notification! Queuing..."); + } do={ + $LogPrint info $0 ("Failed sending Matrix notification: " . $Err . " - Queuing..."); :if ([ :typeof $MatrixQueue ] = "nothing") do={ :set MatrixQueue ({}); @@ -196,14 +196,14 @@ :global MatrixHomeServer; :local Domain [ :pick $User ([ :find $User ":" ] + 1) [ :len $User] ]; - :do { + :onerror Err { :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); - } on-error={ - $LogPrint error $0 ("Failed getting home server!"); + } do={ + $LogPrint error $0 ("Failed getting home server: " . $Err); :return false; } @@ -211,27 +211,27 @@ :set MatrixHomeServer [ :pick $MatrixHomeServer 8 [ :len $MatrixHomeServer ] ]; } - :do { + :onerror Err { :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); - } on-error={ - $LogPrint error $0 ("Failed logging in (and getting access token)!"); + } do={ + $LogPrint error $0 ("Failed logging in (and getting access token): " . $Err); :return false; } - :do { + :onerror Err { /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!"); - } on-error={ - $LogPrint error $0 ("Failed adding configuration snippet!"); + } do={ + $LogPrint error $0 ("Failed adding configuration snippet: " . $Err); :return false; } } @@ -248,24 +248,24 @@ :global MatrixHomeServer; :global MatrixRoom; - :do { + :onerror Err { /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."); - } on-error={ - $LogPrint error $0 ("Failed joining the room!"); + } do={ + $LogPrint error $0 ("Failed joining the room: " . $Err); :return false; } - :do { + :onerror Err { :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!"); - } on-error={ - $LogPrint error $0 ("Failed appending configuration to snippet!"); + } do={ + $LogPrint error $0 ("Failed appending configuration to snippet: " . $Err); :return false; } } From 5caf54b26ec577d857dc8cd181a462fcd6dad716 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:58:53 +0200 Subject: [PATCH 24/49] mod/notification-gotify: :do ... on-error=... -> :onerror ... do=... --- mod/notification-gotify.rsc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mod/notification-gotify.rsc b/mod/notification-gotify.rsc index 3ae4cdd3..d8eafbe0 100644 --- a/mod/notification-gotify.rsc +++ b/mod/notification-gotify.rsc @@ -37,13 +37,13 @@ :foreach Id,Message in=$GotifyQueue do={ :if ([ :typeof $Message ] = "array" ) do={ - :do { + :onerror Err { /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); - } on-error={ - $LogPrint debug $0 ("Sending queued Gotify message failed."); + } do={ + $LogPrint debug $0 ("Sending queued Gotify message failed: " . $Err); :set AllDone false; } } @@ -91,11 +91,11 @@ ("\n" . [ $SymbolForNotification "link" ] . ($Notification->"link")) ]); \ "priority"=[ :tonum [ $IfThenElse ($Notification->"silent") 2 5 ] ] }); - :do { + :onerror Err { /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; - } on-error={ - $LogPrint info $0 ("Failed sending Gotify notification! Queuing..."); + } do={ + $LogPrint info $0 ("Failed sending Gotify notification: " . $Err . " - Queuing..."); :if ([ :typeof $GotifyQueue ] = "nothing") do={ :set GotifyQueue ({}); From 954bee9949f81dfcb032fc70935bc241ddf1cbbb Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 09:45:59 +0200 Subject: [PATCH 25/49] mode-button: :do ... on-error=... -> :onerror ... do=... --- mode-button.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mode-button.rsc b/mode-button.rsc index c6422f0b..d82f8995 100644 --- a/mode-button.rsc +++ b/mode-button.rsc @@ -69,11 +69,11 @@ :delay 200ms; } - :do { + :onerror Err { [ :parse $Code ]; - } on-error={ + } do={ $LogPrint warning $FuncName \ - ("The code for " . $Count . " mode-button presses failed with runtime error!"); + ("The code for " . $Count . " mode-button presses failed with runtime error: " . $Err); } } else={ $LogPrint warning $FuncName \ From fdcd5f8b01663871a1e1364eab76b85ceff277a6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:02:15 +0200 Subject: [PATCH 26/49] mod/scriptrunonce: :do ... on-error=... -> :onerror ... do=... --- mod/scriptrunonce.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mod/scriptrunonce.rsc b/mod/scriptrunonce.rsc index 3797c155..1d6aaf1f 100644 --- a/mod/scriptrunonce.rsc +++ b/mod/scriptrunonce.rsc @@ -41,11 +41,11 @@ :return false; } - :do { + :onerror Err { $LogPrint info $0 ("Running script '" . $Script . "' now."); [ :parse $Source ]; - } on-error={ - $LogPrint warning $0 ("The script '" . $Script . "' failed to run!"); + } do={ + $LogPrint warning $0 ("The script '" . $Script . "' failed to run: " . $Err); :return false; } From 937ac0aaba4ebfec5acc95724356af1bd2571fb2 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:05:12 +0200 Subject: [PATCH 27/49] mod/ssh-keys-import: :do ... on-error=... -> :onerror ... do=... --- mod/ssh-keys-import.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mod/ssh-keys-import.rsc b/mod/ssh-keys-import.rsc index 9a6cd398..176c1b46 100644 --- a/mod/ssh-keys-import.rsc +++ b/mod/ssh-keys-import.rsc @@ -55,13 +55,13 @@ /file/add name=$FileName contents=($Key . ", md5=" . $FingerPrintMD5); $WaitForFile $FileName; - :do { + :onerror Err { /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"; - } on-error={ - $LogPrint warning $0 ("Failed importing key."); + } do={ + $LogPrint warning $0 ("Failed importing key: " . $Err); $RmDir "tmpfs/ssh-keys-import"; :return false; } From 4b4346d0b48af91c843fb5d8f391306fed844ced Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:05:39 +0200 Subject: [PATCH 28/49] mod/ssh-keys-import: fix error condition --- mod/ssh-keys-import.rsc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mod/ssh-keys-import.rsc b/mod/ssh-keys-import.rsc index 176c1b46..94675255 100644 --- a/mod/ssh-keys-import.rsc +++ b/mod/ssh-keys-import.rsc @@ -94,9 +94,7 @@ :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={ - :do { - $SSHKeysImport ($KeyVal->0 . " " . $KeyVal->1 . " " . $KeyVal->2) $User; - } on-error={ + :if ([ $SSHKeysImport ($KeyVal->0 . " " . $KeyVal->1 . " " . $KeyVal->2) $User ] = false) do={ $LogPrint warning $0 ("Failed importing key for user '" . $User . "'."); } :set Continue true; From 6ccc37334c6bb2308c477be85deb04d246dcfc88 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:07:30 +0200 Subject: [PATCH 29/49] netwatch-dns: :do ... on-error=... -> :onerror ... do=... --- netwatch-dns.rsc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netwatch-dns.rsc b/netwatch-dns.rsc index 3da14987..4fa076af 100644 --- a/netwatch-dns.rsc +++ b/netwatch-dns.rsc @@ -118,15 +118,15 @@ } :local Data false; - :do { + :onerror Err { :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"); - } on-error={ - $LogPrint warning $ScriptName ("Request to DoH server failed (network or certificate issue): " . \ - ($DohServer->"doh-url")); + } do={ + $LogPrint warning $ScriptName ("Request to DoH server " . ($DohServer->"doh-url") . \ + " failed: " . $Err); } :if ($Data != false) do={ From f18930688ed8d08f038693b4dd7ffcf2829dc3d2 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:09:59 +0200 Subject: [PATCH 30/49] netwatch-notify: :do ... on-error=... -> :onerror ... do=... --- netwatch-notify.rsc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc index fb8e8d5e..00f03cde 100644 --- a/netwatch-notify.rsc +++ b/netwatch-notify.rsc @@ -38,10 +38,10 @@ :global ValidateSyntax; :if ([ $ValidateSyntax $Hook ] = true) do={ - :do { + onerror Err { [ :parse $Hook ]; - } on-error={ - $LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run."); + } do={ + $LogPrint warning $ScriptName ("The " . $State . "-hook for " . $Type . " '" . $Name . "' failed to run: " . $Err); :return ("The hook failed to run."); } } else={ @@ -107,7 +107,7 @@ :if ([ :typeof ($HostInfo->"resolve") ] = "str") do={ :if ([ $IsDNSResolving ] = true) do={ - :do { + :onerror Err { :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"; } } - } on-error={ + } do={ :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."); + $HostInfo->"name") "" ] . "' failed: " . $Err); } } } From 4561b17dbff272b1b5671155ee1838dba2f24062 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 6 May 2025 13:57:05 +0200 Subject: [PATCH 31/49] global-config: add another comment with visual hint --- global-config.rsc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/global-config.rsc b/global-config.rsc index c0577ff6..2d7d43d2 100644 --- a/global-config.rsc +++ b/global-config.rsc @@ -8,6 +8,9 @@ # 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; From 414870f051f61f12fcb830462c9954e226c75dc5 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:12:08 +0200 Subject: [PATCH 32/49] sms-forward: :do ... on-error=... -> :onerror ... do=... --- sms-forward.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sms-forward.rsc b/sms-forward.rsc index df5373d4..4e10444f 100644 --- a/sms-forward.rsc +++ b/sms-forward.rsc @@ -74,12 +74,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"); - :do { + :onerror Err { :local Command [ :parse ($Hook->"command") ]; $Command Phone=$Phone Message=($SmsVal->"message"); :set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . $Hook->"command"); - } on-error={ - $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run!"); + } do={ + $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run: " . $Err); } } else={ $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed syntax validation!"); From 661aad522b09bf4aba5b0be4877669e0a826b4a6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 6 May 2025 14:05:47 +0200 Subject: [PATCH 33/49] global-config: add another visual hint --- global-config.rsc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/global-config.rsc b/global-config.rsc index 2d7d43d2..589a58a4 100644 --- a/global-config.rsc +++ b/global-config.rsc @@ -270,8 +270,11 @@ "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={ :do { From 3d10fd82c8b96d79b40efca9b28ff0c5b1dc77c6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:13:05 +0200 Subject: [PATCH 34/49] telegram-chat: :do ... on-error=... -> :onerror ... do=... --- telegram-chat.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram-chat.rsc b/telegram-chat.rsc index b1f7f99e..5bfa31c8 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -70,14 +70,14 @@ :local Data false; :for I from=1 to=4 do={ :if ($Data = false) do={ - :do { + :onerror Err { :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) ]; - } on-error={ + } do={ :if ($I < 4) do={ - $LogPrint debug $ScriptName ("Fetch failed, " . $I . ". try."); + $LogPrint debug $ScriptName ("Fetch failed, " . $I . ". try: " . $Err); :set TelegramRandomDelay [ $MIN 15 ($TelegramRandomDelay + 5) ]; :delay (($I * $I) . "s"); } From f095b581e74b5c5a8110c801243b2ec039499120 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 6 May 2025 19:42:12 +0200 Subject: [PATCH 35/49] global-functions: $ScriptInstallUpdate: set config and functions not ready... ... before reload. This should fix some corner cases where scripts ran with broken configuration or functions. Also do reload both - configuration and functions - to simplify the function. --- global-functions.rsc | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/global-functions.rsc b/global-functions.rsc index 29e6d06b..6e3d7120 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -1126,6 +1126,8 @@ :global CommitId; :global CommitInfo; :global ExpectedConfigVersion; + :global GlobalConfigReady; + :global GlobalFunctionsReady; :global Identity; :global IDonate; :global NoNewsAndChangesNotification; @@ -1159,8 +1161,7 @@ :local CommitIdBefore $CommitId; :local ExpectedConfigVersionBefore $ExpectedConfigVersion; - :local ReloadGlobalFunctions false; - :local ReloadGlobalConfig false; + :local ReloadGlobal false; :local DeviceMode [ /system/device-mode/get ]; :local CheckSums ({}); @@ -1269,31 +1270,25 @@ $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") do={ - :set ReloadGlobalConfig true; - } - :if ($ScriptVal->"name" = "global-functions" || $ScriptVal->"name" ~ ("^mod/.")) do={ - :set ReloadGlobalFunctions true; + :if ($ScriptVal->"name" = "global-config" || \ + $ScriptVal->"name" = "global-functions" || \ + $ScriptVal->"name" ~ ("^mod/.")) do={ + :set ReloadGlobal true; } } on-error={ } } - :if ($ReloadGlobalFunctions = true) do={ - $LogPrint info $0 ("Reloading global functions."); - :do { - /system/script/run global-functions; - } on-error={ - $LogPrint error $0 ("Reloading global functions failed!"); - } - } + :if ($ReloadGlobal = true) do={ + $LogPrint info $0 ("Reloading global configuration and functions."); + :set GlobalConfigReady false; + :set GlobalFunctionsReady false; + :delay 1s; - :if ($ReloadGlobalConfig = true) do={ - $LogPrint info $0 ("Reloading global configuration."); - :do { + :onerror Err { /system/script/run global-config; - } on-error={ - $LogPrint error $0 ("Reloading global configuration failed!" . \ - " Syntax error or missing overlay?"); + /system/script/run global-functions; + } do={ + $LogPrint error $0 ("Reloading global configuration and functions failed! " . $Err); } } From 4222d11f1127bd0f4df1420299fb8774eea73659 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:14:24 +0200 Subject: [PATCH 36/49] unattended-lte-firmware-upgrade: :do ... on-error=... -> :onerror ... do=... --- unattended-lte-firmware-upgrade.rsc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unattended-lte-firmware-upgrade.rsc b/unattended-lte-firmware-upgrade.rsc index 83925fd9..237c2d83 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 ]; - :do { + :onerror Err { :set Firmware [ /interface/lte/firmware-upgrade $Interface as-value ]; - } on-error={ - :log debug ("Could not get latest LTE firmware version for interface " . $IntName . "."); + } do={ + :log debug ("Could not get latest LTE firmware version for interface " . $IntName . ": " . $Err); } :if ([ :typeof $Firmware ] = "array") do={ @@ -27,7 +27,7 @@ :set LTEFirmwareUpgrade; /system/scheduler/remove ($1 . "-firmware-upgrade"); - :do { + :onerror Err { /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?"); } - } on-error={ - :log error ("LTE firmware upgrade on '" . $1 . "' failed."); + } do={ + :log error ("LTE firmware upgrade on '" . $1 . "' failed: " . $Err); } } From fee36452b9961138c8e58c7bbd1364121ea73b9a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 May 2025 11:45:55 +0200 Subject: [PATCH 37/49] sms-forward: delay after removal... ... to give the SIM card some time to succeed. Removing several messages one after another fails without this. --- sms-forward.rsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sms-forward.rsc b/sms-forward.rsc index 8ca5ae43..1bf312f6 100644 --- a/sms-forward.rsc +++ b/sms-forward.rsc @@ -62,6 +62,7 @@ ($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={ $LogPrint debug $ScriptName ("Removing SMS, which started a script."); /tool/sms/inbox/remove $Sms; + :delay 300ms; } else={ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ " type " . $SmsVal->"type" . ":\n" . $SmsVal->"message"); @@ -93,6 +94,7 @@ " by " . $Identity . " from " . $Phone . ":" . $Messages) }); :foreach Sms in=$Delete do={ /tool/sms/inbox/remove $Sms; + :delay 300ms; } } } From 07551cd5627524e2c09742f6b880a3149e7d871e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:15:35 +0200 Subject: [PATCH 38/49] update-tunnelbroker: :do ... on-error=... -> :onerror ... do=... --- update-tunnelbroker.rsc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update-tunnelbroker.rsc b/update-tunnelbroker.rsc index 8e5e1d0f..9057e1e4 100644 --- a/update-tunnelbroker.rsc +++ b/update-tunnelbroker.rsc @@ -41,12 +41,12 @@ :for I from=2 to=0 do={ :if ($Data = false) do={ - :do { + :onerror Err { :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"); - } on-error={ - $LogPrint debug $ScriptName ("Failed downloading, " . $I . " retries pending."); + } do={ + $LogPrint debug $ScriptName ("Failed downloading: " . $Err . " - " . $I . " retries pending."); :delay 2s; } } From 93aef0f6d55d0d45152ce8a26c1268b97d1bb2ef Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 May 2025 14:31:37 +0200 Subject: [PATCH 39/49] sms-forward: add error handling on message removal --- sms-forward.rsc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sms-forward.rsc b/sms-forward.rsc index 1bf312f6..df5373d4 100644 --- a/sms-forward.rsc +++ b/sms-forward.rsc @@ -61,8 +61,12 @@ :if ($Phone = $Settings->"allowed-number" && \ ($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={ $LogPrint debug $ScriptName ("Removing SMS, which started a script."); - /tool/sms/inbox/remove $Sms; - :delay 300ms; + :onerror Err { + /tool/sms/inbox/remove $Sms; + :delay 300ms; + } do={ + $LogPrint warning $ScriptName ("Failed to remove message: " . $Err); + } } else={ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ " type " . $SmsVal->"type" . ":\n" . $SmsVal->"message"); @@ -93,8 +97,12 @@ message=("Received " . [ $IfThenElse ($Count = 1) "this message" ("these " . $Count . " messages") ] . \ " by " . $Identity . " from " . $Phone . ":" . $Messages) }); :foreach Sms in=$Delete do={ - /tool/sms/inbox/remove $Sms; - :delay 300ms; + :onerror Err { + /tool/sms/inbox/remove $Sms; + :delay 300ms; + } do={ + $LogPrint warning $ScriptName ("Failed to remove message: " . $Err); + } } } } From 6e0f9c26ccacfb33c891f69cd395a0868fd24271 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:07:39 +0200 Subject: [PATCH 40/49] mod/inspectvar: use $CharacterMultiply --- mod/inspectvar.rsc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mod/inspectvar.rsc b/mod/inspectvar.rsc index 89c02860..b864d9a8 100644 --- a/mod/inspectvar.rsc +++ b/mod/inspectvar.rsc @@ -33,11 +33,9 @@ :local Value [ :tostr $2 ]; :local Level [ :tonum $3 ]; - :local Indent ""; - :for I from=1 to=$Level step=1 do={ - :set Indent ($Indent . " "); - } - :return ($Indent . "-" . $Prefix . "-> " . $Value); + :global CharacterMultiply; + + :return ([ $CharacterMultiply " " $Level ] . "-" . $Prefix . "-> " . $Value); } :local TypeOf [ :typeof $Input ]; From 8019d6b7886fa0be20ade56cd86e0e915a9c9358 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:12:02 +0200 Subject: [PATCH 41/49] mod/inspectvar: print the length for strings --- mod/inspectvar.rsc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mod/inspectvar.rsc b/mod/inspectvar.rsc index b864d9a8..84c40d8f 100644 --- a/mod/inspectvar.rsc +++ b/mod/inspectvar.rsc @@ -39,6 +39,7 @@ } :local TypeOf [ :typeof $Input ]; + :local Len [ :len $Input ]; :local Return [ $IndentReturn "type" $TypeOf $Level ]; :if ($TypeOf = "array") do={ @@ -48,6 +49,10 @@ [ $InspectVarReturn $Value ($Level + 2) ]); } } else={ + :if ($TypeOf = "str") do={ + :set $Return ($Return . "\n" . \ + [ $IndentReturn "len" $Len $Level ]); + } :if ($TypeOf != "nothing") do={ :set $Return ($Return . "\n" . \ [ $IndentReturn "value" [ $IfThenElse ([ :len $Input ] > 80) \ From e75d986fe7a563a0a70059feddbc61b51145df33 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:15:21 +0200 Subject: [PATCH 42/49] mod/inspectvar: remove CR, replace LF --- mod/inspectvar.rsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mod/inspectvar.rsc b/mod/inspectvar.rsc index 84c40d8f..b32480f3 100644 --- a/mod/inspectvar.rsc +++ b/mod/inspectvar.rsc @@ -25,6 +25,7 @@ :local Input $1; :local Level (0 + [ :tonum $2 ]); + :global CharacterReplace; :global IfThenElse; :global InspectVarReturn; @@ -52,6 +53,7 @@ :if ($TypeOf = "str") do={ :set $Return ($Return . "\n" . \ [ $IndentReturn "len" $Len $Level ]); + :set Input [ $CharacterReplace [ $CharacterReplace $Input ("\r") "" ] ("\n") " " ]; } :if ($TypeOf != "nothing") do={ :set $Return ($Return . "\n" . \ From 8da55ba82d8b309e1fb8ca859bedacdbf50a376d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 13:35:49 +0200 Subject: [PATCH 43/49] mod/inspectvar: replace only when matching --- mod/inspectvar.rsc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mod/inspectvar.rsc b/mod/inspectvar.rsc index b32480f3..fc1b366f 100644 --- a/mod/inspectvar.rsc +++ b/mod/inspectvar.rsc @@ -53,7 +53,12 @@ :if ($TypeOf = "str") do={ :set $Return ($Return . "\n" . \ [ $IndentReturn "len" $Len $Level ]); - :set Input [ $CharacterReplace [ $CharacterReplace $Input ("\r") "" ] ("\n") " " ]; + :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" . \ From 8b2ae87892f6fcc00411c09b3f72f73e78976714 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:21:59 +0200 Subject: [PATCH 44/49] mod/notification-email: add error handling when sending mail --- mod/notification-email.rsc | 57 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/mod/notification-email.rsc b/mod/notification-email.rsc index c0f9d860..e05a8131 100644 --- a/mod/notification-email.rsc +++ b/mod/notification-email.rsc @@ -89,35 +89,40 @@ :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; } - :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; - } + :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."); } } - :if ($Status = "failed") do={ - :set AllDone false; - :set Wait false; - } - } while=($Wait = true); + /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; + } } } From 8644a7f4a32b2540e0a61f4db737c0a2a6715fe7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 13:29:01 +0200 Subject: [PATCH 45/49] mod/notification-email: properly truncate the body Truned out that the size limit for e-mail message/body is anywhere just below 64kB... So truncate at about 62.000 bytes. --- mod/notification-email.rsc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mod/notification-email.rsc b/mod/notification-email.rsc index e05a8131..c799c874 100644 --- a/mod/notification-email.rsc +++ b/mod/notification-email.rsc @@ -181,6 +181,7 @@ :global IfThenElse; :global NotificationEMailSignature; :global NotificationEMailSubject; + :global SymbolForNotification; :local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ]; :local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ]; @@ -193,13 +194,22 @@ :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" . ($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=(($Notification->"message") . \ - [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \ - [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \ + body=$Body; \ 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 \ From 950a4b94ba89722fc5ab882940dc73c6f5c11f37 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 14:54:42 +0200 Subject: [PATCH 46/49] mod/notification-email: add the link symbol --- mod/notification-email.rsc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/notification-email.rsc b/mod/notification-email.rsc index c799c874..52937668 100644 --- a/mod/notification-email.rsc +++ b/mod/notification-email.rsc @@ -202,7 +202,8 @@ } :local Signature [ $EitherOr [ $NotificationEMailSignature ] [ /system/note/get note ] ]; :set Body ($Body . "\n" . \ - [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n" . ($Notification->"link")) ] . \ + [ $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) "" ]); From 9f24bb0a2675433965299ad4f8d433c935d8a9af Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 11 May 2025 22:02:18 +0200 Subject: [PATCH 47/49] fw-addr-lists: for IPv6 the CIDR is always expected --- fw-addr-lists.rsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fw-addr-lists.rsc b/fw-addr-lists.rsc index 5a03875d..efd37db7 100644 --- a/fw-addr-lists.rsc +++ b/fw-addr-lists.rsc @@ -114,8 +114,8 @@ :error true; } :if ($Address ~ "^[0-9a-zA-Z]*:[0-9a-zA-Z:\\.]+(/[0-9]{1,3})?\$") do={ - :if ($Address ~ "/128\$") do={ - :set Address [ :pick $Address 0 ([ :len $Address ] - 4) ]; + :if ([ :typeof [ :find $Address "/" ] ] = "nil") do={ + :set Address ($Address . "/128"); } :set ($IPv6Addresses->$Branch->$Address) $TimeOut; :error true; From d7628f03103cbd3811843e7bce0dcc3ebd554376 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 12 May 2025 16:50:06 +0200 Subject: [PATCH 48/49] mod/notification-telegram: fix indention --- mod/notification-telegram.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc index 0832b07e..2eb90e12 100644 --- a/mod/notification-telegram.rsc +++ b/mod/notification-telegram.rsc @@ -189,7 +189,7 @@ :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"); + "&disable_web_page_preview=true&parse_mode=MarkdownV2"); :onerror Err { :if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" ] = false) do={ $LogPrint warning $0 ("Downloading required certificate failed."); From b88c2a14cce830be0846315d1f8d0bc559cd8d12 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 12 May 2025 16:53:55 +0200 Subject: [PATCH 49/49] telegram-chat: Support trusted group chat ids But be warned: Adding a person to a trusted group will give her/him administrative control over the device(s) - without changes on the device itself! --- telegram-chat.rsc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telegram-chat.rsc b/telegram-chat.rsc index 5bfa31c8..50fc0cce 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -107,7 +107,9 @@ :local ThreadId [ $IfThenElse ($Message->"is_topic_message") ($Message->"message_thread_id") "" ]; :foreach IdsTrusted in=($TelegramChatId, $TelegramChatIdsTrusted) do={ - :if ($From->"id" = $IdsTrusted || $From->"username" = $IdsTrusted) do={ + :if ($From->"id" = $IdsTrusted || \ + $From->"username" = $IdsTrusted || \ + $Chat->"id" = $IdsTrusted) do={ :set Trusted true; } }