From fc1cde98f2fba257dac6d11265c00a338a6f3230 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:05:39 +0200 Subject: [PATCH 01/38] =?UTF-8?q?mod/ssh-keys-import:=20:do=20...=20on-err?= =?UTF-8?q?or=3D...=20->=20...=20well...=20-=20fix=20error=20condition=20?= =?UTF-8?q?=F0=9F=A5=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 e138cd0ab9730168db12e08e8398e22679d3dd46 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:07:30 +0200 Subject: [PATCH 02/38] 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 a6f9e6c6beb958e49b8b3de1ed19b8c088ec5e1b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:09:59 +0200 Subject: [PATCH 03/38] 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 70b10dd2a6a3fc3f306f284cca07a77e5c4076ff Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:12:08 +0200 Subject: [PATCH 04/38] 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 a564056a..feb640e5 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 37b417369ead67b082ba3ccc51e0dc1b58412c46 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:13:05 +0200 Subject: [PATCH 05/38] 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 7e58ee3fdbd8e2252f65ad8842b4e971fae5ea62 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:14:24 +0200 Subject: [PATCH 06/38] 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 fee409f0ba4a4834e3331d4149d94e1115f87ffb Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:15:35 +0200 Subject: [PATCH 07/38] 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 bd700b8e75b1309a605cf9102d069443061ef540 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:07:39 +0200 Subject: [PATCH 08/38] 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 02531d5fae29158665c44217b3af8b2758260c4e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:12:02 +0200 Subject: [PATCH 09/38] 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 616e9f244aeb763e5adbf81f7bb5c4cf6a684c96 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:15:21 +0200 Subject: [PATCH 10/38] 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 6209f5296247f54b14123d8967d98af0b9e215e0 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 13:35:49 +0200 Subject: [PATCH 11/38] 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 68c38df755be92c2ce6a4153c086e3020e44d5d7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:21:59 +0200 Subject: [PATCH 12/38] 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 de9e726661a6e6f817da9e3503104f322d8c1265 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 13:29:01 +0200 Subject: [PATCH 13/38] 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 3e404027f67215289a5cd42b74a6a71724049747 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 14:54:42 +0200 Subject: [PATCH 14/38] 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 9d94d69677242646dd35be603a2cfa351e3a2590 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 11 May 2025 22:02:18 +0200 Subject: [PATCH 15/38] 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 0576fbc5320fe0692492353ad6db34cc44551ebf Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 12 May 2025 16:50:06 +0200 Subject: [PATCH 16/38] 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 828c93bd666ce12eba3940412cdd3953397fadeb Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 12 May 2025 16:53:55 +0200 Subject: [PATCH 17/38] 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! On the other hand... Removing permissions is easily done by removing a person from a group. Closes: https://github.com/eworm-de/routeros-scripts/issues/101 --- 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; } } From 5b5e3d47b68544349e8b35b33ddb34c78c3788f1 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 13 May 2025 09:52:12 +0200 Subject: [PATCH 18/38] telegram-chat: support debug output for updates in JSON --- telegram-chat.rsc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/telegram-chat.rsc b/telegram-chat.rsc index 50fc0cce..277c40fc 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -33,6 +33,7 @@ :global GetRandom20CharAlNum; :global IfThenElse; :global LogPrint; + :global LogPrintVerbose; :global MAX; :global MIN; :global MkDir; @@ -96,6 +97,8 @@ :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") ]); From 4db0a0d4f0e64f8489cae5f224bc1f866f3f8361 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 13 May 2025 10:02:03 +0200 Subject: [PATCH 19/38] DEBUG: fix typo --- DEBUG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEBUG.md b/DEBUG.md index d5e9beb7..66bf728a 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 remote that setting to restore regular logging. +Disable or remove that setting to restore regular logging. ## Verbose output From c757064eb9537321b7cad69db6e05ddc9c576583 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:05:39 +0200 Subject: [PATCH 20/38] =?UTF-8?q?mod/ssh-keys-import:=20:do=20...=20on-err?= =?UTF-8?q?or=3D...=20->=20...=20well...=20-=20fix=20condition=20?= =?UTF-8?q?=F0=9F=A5=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 a523f9793861d8927388f18bb5f2319bbe04c0b8 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:07:30 +0200 Subject: [PATCH 21/38] 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 fefe59751f1487fbdd4feace39c32445bd97547c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:09:59 +0200 Subject: [PATCH 22/38] 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 d0adf9974e75668fc16e736ce2dc29a1477b10b8 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:12:08 +0200 Subject: [PATCH 23/38] 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 a564056a..feb640e5 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 f22d46da96dfe0c421172d30ee1baf9976205329 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:13:05 +0200 Subject: [PATCH 24/38] 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 10ac81634877858717a3d99fee418edc9887b377 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:14:24 +0200 Subject: [PATCH 25/38] 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 205bcce6f9d49518f1e1999154d96b0e0bb6d1ed Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 10:15:35 +0200 Subject: [PATCH 26/38] 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 3521995dbc1173e722819efca1908cd0df251b1d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:07:39 +0200 Subject: [PATCH 27/38] 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 187735f35f7b361b1cc6d45f703d5c121681254c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:12:02 +0200 Subject: [PATCH 28/38] 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 36f155ce621abe427d126a6ee3a3363bff15b2bb Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:15:21 +0200 Subject: [PATCH 29/38] 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 bd3cc3bbd49934f42fe9f6c6820501c7cc9d33ba Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 13:35:49 +0200 Subject: [PATCH 30/38] 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 ff218e4ce5032b2ead7f33f53382bda98f6e5e2e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 11:21:59 +0200 Subject: [PATCH 31/38] 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 74dc809b98759cb337fbaf6b1fa98bb0137dadc0 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 13:29:01 +0200 Subject: [PATCH 32/38] 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 2a956874777c83748f4a2afea4e9ee1382928230 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 8 May 2025 14:54:42 +0200 Subject: [PATCH 33/38] 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 ce129ee4418a09d4b1987e3d94818a561d9fd384 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 11 May 2025 22:02:18 +0200 Subject: [PATCH 34/38] 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 e78c71948dfa847fd21820dffacd3c6e7165d832 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 12 May 2025 16:50:06 +0200 Subject: [PATCH 35/38] 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 1b5dd1e1d3555f347bd6ff587659ac8b8ec5c73e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 12 May 2025 16:53:55 +0200 Subject: [PATCH 36/38] 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! On the other hand... Removing permissions is easily done by removing a person from a group. Closes: https://github.com/eworm-de/routeros-scripts/issues/101 --- 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; } } From f1396b83aa7f506fe653184016cd970728eb9407 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 13 May 2025 09:52:12 +0200 Subject: [PATCH 37/38] telegram-chat: support debug output for updates in JSON --- telegram-chat.rsc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/telegram-chat.rsc b/telegram-chat.rsc index 50fc0cce..277c40fc 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -33,6 +33,7 @@ :global GetRandom20CharAlNum; :global IfThenElse; :global LogPrint; + :global LogPrintVerbose; :global MAX; :global MIN; :global MkDir; @@ -96,6 +97,8 @@ :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") ]); From 64fe923c5aea4e6b8cd549a39f8e76c1e9814391 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 13 May 2025 10:02:03 +0200 Subject: [PATCH 38/38] DEBUG: fix typo --- DEBUG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEBUG.md b/DEBUG.md index d5e9beb7..66bf728a 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 remote that setting to restore regular logging. +Disable or remove that setting to restore regular logging. ## Verbose output