From c93d1c4944fff937598ec2825869a02030362a9a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 17:32:12 +0100 Subject: global-functions: $SendTelegram: disable web page preview --- global-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'global-functions') diff --git a/global-functions b/global-functions index b0b27c2..a058d69 100644 --- a/global-functions +++ b/global-functions @@ -825,7 +825,7 @@ / tool fetch check-certificate=yes-without-crl output=none http-method=post \ ("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \ http-data=("chat_id=" . $ChatId . "&disable_notification=" . $Silent . \ - "&parse_mode=" . $ParseMode . "&text=" . $Text); + "&disable_web_page_preview=true&parse_mode=" . $ParseMode . "&text=" . $Text); } on-error={ $LogPrintExit info ("Failed sending telegram notification! Queuing...") false; -- cgit v1.2.3-70-g09d2 From 54e164e542bcd5b220ed3cbb3ad866d53f052efe Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 22:02:39 +0100 Subject: global-functions: $SendTelegram: try to get the line breaks right --- global-functions | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'global-functions') diff --git a/global-functions b/global-functions index a058d69..ee13de8 100644 --- a/global-functions +++ b/global-functions @@ -776,9 +776,10 @@ :global TelegramFixedWidthFont; :global CharacterReplace; + :global IfThenElse; :if ($TelegramFixedWidthFont != true) do={ - :return $1; + :return ($1 . [ $IfThenElse ($2 = "fixed") "\n" "" ]); } :local Return $1; @@ -810,7 +811,7 @@ :local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message); :if ([ :len $Text ] > 3968) do={ :set Text ([ $EscapeMD ([ :pick $Text 0 3840 ] . "...") "fixed" ] . \ - "\n\n" . [ $SymbolForNotification "scissors" ] . \ + "\n" . [ $SymbolForNotification "scissors" ] . \ [ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]); } else={ :set Text [ $EscapeMD $Text "fixed" ]; @@ -832,7 +833,7 @@ :if ([ :typeof $TelegramQueue ] = "nothing") do={ :set TelegramQueue [ :toarray "" ]; } - :set Text ($Text . [ $UrlEncode ("\n\n" . [ $SymbolForNotification "alarm-clock" ] . \ + :set Text ($Text . [ $UrlEncode ("\n" . [ $SymbolForNotification "alarm-clock" ] . \ [ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \ " " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]); :set ($TelegramQueue->[ :len $TelegramQueue ]) { -- cgit v1.2.3-70-g09d2 From d7725540f884bf7486274f0e002cf2ba1b41306e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 22:06:03 +0100 Subject: global-functions: $SendTelegram: change internal wording --- global-functions | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'global-functions') diff --git a/global-functions b/global-functions index ee13de8..9c5e76e 100644 --- a/global-functions +++ b/global-functions @@ -779,12 +779,12 @@ :global IfThenElse; :if ($TelegramFixedWidthFont != true) do={ - :return ($1 . [ $IfThenElse ($2 = "fixed") "\n" "" ]); + :return ($1 . [ $IfThenElse ($2 = "body") "\n" "" ]); } :local Return $1; :local Chars { - "fixed"={ "\\"; "`" }; + "body"={ "\\"; "`" }; "hint"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">"; "#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" }; } @@ -792,7 +792,7 @@ :set Return [ $CharacterReplace $Return $Char ("\\" . $Char) ]; } - :if ($2 = "fixed") do={ + :if ($2 = "body") do={ :return ("```\n" . $Return . "\n```"); } @@ -810,11 +810,11 @@ :local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message); :if ([ :len $Text ] > 3968) do={ - :set Text ([ $EscapeMD ([ :pick $Text 0 3840 ] . "...") "fixed" ] . \ + :set Text ([ $EscapeMD ([ :pick $Text 0 3840 ] . "...") "body" ] . \ "\n" . [ $SymbolForNotification "scissors" ] . \ [ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]); } else={ - :set Text [ $EscapeMD $Text "fixed" ]; + :set Text [ $EscapeMD $Text "body" ]; } :set Text [ $UrlEncode $Text ]; :local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ]; -- cgit v1.2.3-70-g09d2 From 7e0558e85dcf06161d0b9c554688d4fc4d1b3101 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 22:21:28 +0100 Subject: global-functions: $SendTelegram: prepare to add clickable link Formatting with fixed width font stopped links from being clickable. --- global-functions | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'global-functions') diff --git a/global-functions b/global-functions index 9c5e76e..384f438 100644 --- a/global-functions +++ b/global-functions @@ -756,6 +756,7 @@ :set SendTelegram do={ :local Subject [ :tostr $1 ]; :local Message [ :tostr $2 ]; + :local Link; :local Silent [ :tostr $3 ]; :global Identity; @@ -808,14 +809,18 @@ :return false; } + :local LenLink [ :len $Link ]; :local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message); - :if ([ :len $Text ] > 3968) do={ - :set Text ([ $EscapeMD ([ :pick $Text 0 3840 ] . "...") "body" ] . \ + :if ([ :len $Text ] > (3968 - $LenLink)) do={ + :set Text ([ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ] . \ "\n" . [ $SymbolForNotification "scissors" ] . \ [ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]); } else={ :set Text [ $EscapeMD $Text "body" ]; } + :if ($LenLink > 0) do={ + :set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . [ $EscapeMD $Link "hint" ]); + } :set Text [ $UrlEncode $Text ]; :local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ]; @@ -855,6 +860,7 @@ "floppy-disk"="\F0\9F\92\BE"; "high-voltage-sign"="\E2\9A\A1"; "incoming-envelope"="\F0\9F\93\A8"; + "link"="\F0\9F\94\97"; "lock-with-ink-pen"="\F0\9F\94\8F"; "mobile-phone"="\F0\9F\93\B1"; "pushpin"="\F0\9F\93\8C"; -- cgit v1.2.3-70-g09d2 From b078ce2f0f8544936274506e55ee4ecc5c5425cb Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 22:24:56 +0100 Subject: global-functions: $SendTelegram: split off & move down truncation message --- global-functions | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'global-functions') diff --git a/global-functions b/global-functions index 384f438..ac7cec1 100644 --- a/global-functions +++ b/global-functions @@ -809,18 +809,22 @@ :return false; } + :local Truncated false; :local LenLink [ :len $Link ]; :local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message); :if ([ :len $Text ] > (3968 - $LenLink)) do={ - :set Text ([ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ] . \ - "\n" . [ $SymbolForNotification "scissors" ] . \ - [ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]); + :set Text [ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ]; + :set Truncated true; } else={ :set Text [ $EscapeMD $Text "body" ]; } :if ($LenLink > 0) do={ :set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . [ $EscapeMD $Link "hint" ]); } + :if ($Truncated = true) do={ + :set Text ($Text . "\n" . [ $SymbolForNotification "scissors" ] . \ + [ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]); + } :set Text [ $UrlEncode $Text ]; :local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ]; -- cgit v1.2.3-70-g09d2 From 46866e2ff232c86b62419810667a3a394a2b4b65 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 22:34:08 +0100 Subject: global-functions: $SendEMail: handle signature with $IfThenElse --- global-functions | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'global-functions') diff --git a/global-functions b/global-functions index ac7cec1..be04150 100644 --- a/global-functions +++ b/global-functions @@ -719,6 +719,7 @@ :global EmailGeneralCc; :global LogPrintExit; + :global IfThenElse; :if ([ :len $EmailGeneralTo ] = 0) do={ :return false; @@ -726,12 +727,11 @@ :do { :local Signature [ / system note get note ]; - :if ([ :len $Signature ] > 0) do={ - :set Signature ("\n-- \n" . $Signature); - } / tool e-mail send to=$EmailGeneralTo cc=$EmailGeneralCc \ subject=("[" . $Identity . "] " . $Subject) \ - body=($Message . $Signature) file=$Attach; + body=($Message . \ + [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) \ + file=$Attach; } on-error={ $LogPrintExit warning ("Failed sending notification mail!") false; } -- cgit v1.2.3-70-g09d2 From d09baddac30b8221ed34db41b9f0536daf83a084 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 22:36:14 +0100 Subject: global-functions: $SendEMail: prepare to add link For e-mail just in plain text... --- global-functions | 2 ++ 1 file changed, 2 insertions(+) (limited to 'global-functions') diff --git a/global-functions b/global-functions index be04150..de62a59 100644 --- a/global-functions +++ b/global-functions @@ -712,6 +712,7 @@ :set SendEMail do={ :local Subject [ :tostr $1 ]; :local Message [ :tostr $2 ]; + :local Link; :local Attach [ :tostr $3 ]; :global Identity; @@ -730,6 +731,7 @@ / tool e-mail send to=$EmailGeneralTo cc=$EmailGeneralCc \ subject=("[" . $Identity . "] " . $Subject) \ body=($Message . \ + [ $IfThenElse ([ :len $Link ] > 0) ("\n\n" . $Link) "" ] . \ [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) \ file=$Attach; } on-error={ -- cgit v1.2.3-70-g09d2 From ca4e25283fa7a3c72d4b678cd0e5781f71cfed7e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 26 Nov 2020 23:02:15 +0100 Subject: global-functions: clickable links in telegram notifications --- check-certificates | 2 +- check-lte-firmware-upgrade | 2 +- check-routeros-update | 15 ++++++--------- cloud-backup | 2 +- daily-psk.capsman | 4 ++-- daily-psk.local | 4 ++-- daily-psk.template | 4 ++-- global-functions | 24 +++++++++++++----------- upload-backup | 2 +- 9 files changed, 29 insertions(+), 30 deletions(-) (limited to 'global-functions') diff --git a/check-certificates b/check-certificates index d5c08b9..f3a8e99 100644 --- a/check-certificates +++ b/check-certificates @@ -91,7 +91,7 @@ $WaitFullyConnected; "Fingerprint: " . ($CertNewVal->"fingerprint") . "\n" . \ "Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \ "Validity: " . ($CertNewVal->"invalid-before") . " to " . ($CertNewVal->"invalid-after") . "\n" . \ - "Expires in: " . [ $FormatExpire ($CertNewVal->"expires-after") ]) "" "true"; + "Expires in: " . [ $FormatExpire ($CertNewVal->"expires-after") ]) "" "" "true"; $LogPrintExit info ("The certificate " . ($CertVal->"name") . " has been renewed.") false; } on-error={ $LogPrintExit debug ("Could not renew certificate " . ($CertVal->"name") . ".") false; diff --git a/check-lte-firmware-upgrade b/check-lte-firmware-upgrade index 0e4cb3d..08b27ce 100644 --- a/check-lte-firmware-upgrade +++ b/check-lte-firmware-upgrade @@ -30,7 +30,7 @@ "LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \ "Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \ "Installed: " . ($Firmware->"installed") . "\n" . \ - "Available: " . ($Firmware->"latest")) "" "true"; + "Available: " . ($Firmware->"latest")) "" "" "true"; :set SentLteFirmwareUpgradeNotification ($Firmware->"latest"); } } diff --git a/check-routeros-update b/check-routeros-update index b8e87d9..a4dfe9d 100644 --- a/check-routeros-update +++ b/check-routeros-update @@ -48,13 +48,14 @@ :local NumInstalled [ $VersionToNum ($Update->"installed-version") ]; :local NumLatest [ $VersionToNum ($Update->"latest-version") ]; +:local Link ("https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree"); :if ($NumInstalled < $NumLatest) do={ :if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={ $LogPrintExit info ("Version " . $Update->"latest-version" . " is a patch release, updating...") false; $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ ("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \ - ", updating on " . $Identity . "...") "" "true"; + ", updating on " . $Identity . "...") $Link "" "true"; $DoUpdate; } @@ -63,7 +64,7 @@ $LogPrintExit info ("Seen a neighbor running version " . $Update->"latest-version" . ", updating...") false; $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ ("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \ - ", updating on " . $Identity . "...") "" "true"; + ", updating on " . $Identity . "...") $Link "" "true"; $DoUpdate; } @@ -80,7 +81,7 @@ $LogPrintExit info ("Version " . $Update->"latest-version" . " is considered safe, updating...") false; $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ ("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \ - ", updating on " . $Identity . "...") "" "true"; + ", updating on " . $Identity . "...") $Link "" "true"; $DoUpdate; } } @@ -102,9 +103,7 @@ $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ ("A new RouterOS version " . ($Update->"latest-version") . \ " is available for " . $Identity . ".\n\n" . \ - [ $DeviceInfo ] . "\n\n" . \ - "https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree") \ - "" "true"; + [ $DeviceInfo ]) $Link "" "true"; :set SentRouterosUpdateNotification ($Update->"latest-version"); } @@ -117,9 +116,7 @@ $SendNotification ([ $SymbolForNotification "warning-sign" ] . "RouterOS version") \ ("A different RouterOS version " . ($Update->"latest-version") . \ " is available for " . $Identity . ", but it is a downgrade.\n\n" . \ - [ $DeviceInfo ] . "\n\n" . \ - "https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree") \ - "" "true"; + [ $DeviceInfo ]) $Link "" "true"; $LogPrintExit info ("A different RouterOS version " . ($Update->"latest-version") . \ " is available for downgrade.") false; :set SentRouterosUpdateNotification ($Update->"latest-version"); diff --git a/cloud-backup b/cloud-backup index e1386f0..46777b9 100644 --- a/cloud-backup +++ b/cloud-backup @@ -32,7 +32,7 @@ [ $DeviceInfo ] . "\n\n" . \ "Name: " . $Cloud->"name" . "\n" . \ "Size: " . $Cloud->"size" . " B (" . ($Cloud->"size" / 1024) . " KiB)\n" . \ - "Download key: " . $Cloud->"secret-download-key") "" "true"; + "Download key: " . $Cloud->"secret-download-key") "" "" "true"; } on-error={ $SendNotification ([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed") \ ("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]); diff --git a/daily-psk.capsman b/daily-psk.capsman index 33208f5..2f7e8f2 100644 --- a/daily-psk.capsman +++ b/daily-psk.capsman @@ -93,8 +93,8 @@ $WaitFullyConnected; "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ "Date: " . $Date . "\n\n" . \ - "A client device specific rule must not exist!\n\n" . \ - $Url) $Attach; + "A client device specific rule must not exist!") \ + $Url $Attach; } } } diff --git a/daily-psk.local b/daily-psk.local index 13a878e..d51d5f6 100644 --- a/daily-psk.local +++ b/daily-psk.local @@ -93,8 +93,8 @@ $WaitFullyConnected; "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ "Date: " . $Date . "\n\n" . \ - "A client device specific rule must not exist!\n\n" . \ - $Url) $Attach; + "A client device specific rule must not exist!") \ + $Url $Attach; } } } diff --git a/daily-psk.template b/daily-psk.template index fd5bd2b..acc8edd 100644 --- a/daily-psk.template +++ b/daily-psk.template @@ -99,8 +99,8 @@ $WaitFullyConnected; "SSID: " . $Ssid . "\n" . \ "PSK: " . $NewPsk . "\n" . \ "Date: " . $Date . "\n\n" . \ - "A client device specific rule must not exist!\n\n" . \ - $Url) $Attach; + "A client device specific rule must not exist!") \ + $Url $Attach; } } } diff --git a/global-functions b/global-functions index de62a59..f42d8f9 100644 --- a/global-functions +++ b/global-functions @@ -682,17 +682,18 @@ "\n\nChanges are not available."); } + :local Link; :if ($IDonate != true) do={ :set NotificationMessage ($NotificationMessage . \ "\n\n==== donation hint ====\n" . \ "This project is developed in private spare time and usage is " . \ "free of charge for you. If you like the scripts and think this is " . \ - "of value for you or your business please consider a donation:\n" . \ - "https://git.eworm.de/cgit/routeros-scripts/about/#donate"); + "of value for you or your business please consider a donation."); + :set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate"; } $SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \ - $NotificationMessage; + $NotificationMessage $Link; :set SentConfigChangesNotification $ExpectedConfigVersion; } } @@ -712,8 +713,8 @@ :set SendEMail do={ :local Subject [ :tostr $1 ]; :local Message [ :tostr $2 ]; - :local Link; - :local Attach [ :tostr $3 ]; + :local Link [ :tostr $3 ]; + :local Attach [ :tostr $4 ]; :global Identity; :global EmailGeneralTo; @@ -744,22 +745,23 @@ :set SendNotification do={ :local Subject [ :tostr $1 ]; :local Message [ :tostr $2 ]; - :local Attach [ :tostr $3 ]; - :local Silent [ :tostr $4 ]; + :local Link [ :tostr $3 ]; + :local Attach [ :tostr $4 ]; + :local Silent [ :tostr $5 ]; :global SendEMail; :global SendTelegram; - $SendEMail $Subject $Message $Attach; - $SendTelegram $Subject $Message $Silent; + $SendEMail $Subject $Message $Link $Attach; + $SendTelegram $Subject $Message $Link $Silent; } # send notification via telegram :set SendTelegram do={ :local Subject [ :tostr $1 ]; :local Message [ :tostr $2 ]; - :local Link; - :local Silent [ :tostr $3 ]; + :local Link [ :tostr $3 ]; + :local Silent [ :tostr $4 ]; :global Identity; :global TelegramChatId; diff --git a/upload-backup b/upload-backup index 27eab0c..5d4dd8e 100644 --- a/upload-backup +++ b/upload-backup @@ -72,7 +72,7 @@ $SendNotification [ $IfThenElse ($Failed > 0) \ ("Backup and config export upload for " . $Identity . ".\n\n" . \ [ $DeviceInfo ] . "\n\n" . \ "Backup file: " . $BackupFile . "\n" . \ - "Config file: " . $ConfigFile) "" "true"; + "Config file: " . $ConfigFile) "" "" "true"; :if ($Failed = 1) do={ :error "An error occured!"; -- cgit v1.2.3-70-g09d2