Merge branch 'telegram-clickable'

This commit is contained in:
Christian Hesse 2020-11-27 10:03:08 +01:00
commit 107f9e4bdf
9 changed files with 54 additions and 42 deletions

View file

@ -91,7 +91,7 @@ $WaitFullyConnected;
"Fingerprint: " . ($CertNewVal->"fingerprint") . "\n" . \ "Fingerprint: " . ($CertNewVal->"fingerprint") . "\n" . \
"Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \ "Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \
"Validity: " . ($CertNewVal->"invalid-before") . " to " . ($CertNewVal->"invalid-after") . "\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; $LogPrintExit info ("The certificate " . ($CertVal->"name") . " has been renewed.") false;
} on-error={ } on-error={
$LogPrintExit debug ("Could not renew certificate " . ($CertVal->"name") . ".") false; $LogPrintExit debug ("Could not renew certificate " . ($CertVal->"name") . ".") false;

View file

@ -30,7 +30,7 @@
"LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \ "LTE interface " . $IntName . " on " . $Identity . ".\n\n" . \
"Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \ "Interface: " . [ $CharacterReplace ($Info->"manufacturer" . " " . $Info->"model") ("\"") "" ] . "\n" . \
"Installed: " . ($Firmware->"installed") . "\n" . \ "Installed: " . ($Firmware->"installed") . "\n" . \
"Available: " . ($Firmware->"latest")) "" "true"; "Available: " . ($Firmware->"latest")) "" "" "true";
:set SentLteFirmwareUpgradeNotification ($Firmware->"latest"); :set SentLteFirmwareUpgradeNotification ($Firmware->"latest");
} }
} }

View file

@ -48,13 +48,14 @@
:local NumInstalled [ $VersionToNum ($Update->"installed-version") ]; :local NumInstalled [ $VersionToNum ($Update->"installed-version") ];
:local NumLatest [ $VersionToNum ($Update->"latest-version") ]; :local NumLatest [ $VersionToNum ($Update->"latest-version") ];
:local Link ("https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree");
:if ($NumInstalled < $NumLatest) do={ :if ($NumInstalled < $NumLatest) do={
:if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={ :if ($SafeUpdatePatch = true && ($NumInstalled & 0xffff0000) = ($NumLatest & 0xffff0000)) do={
$LogPrintExit info ("Version " . $Update->"latest-version" . " is a patch release, updating...") false; $LogPrintExit info ("Version " . $Update->"latest-version" . " is a patch release, updating...") false;
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \ ("Version " . $Update->"latest-version" . " is a patch update for " . $Update->"channel" . \
", updating on " . $Identity . "...") "" "true"; ", updating on " . $Identity . "...") $Link "" "true";
$DoUpdate; $DoUpdate;
} }
@ -63,7 +64,7 @@
$LogPrintExit info ("Seen a neighbor running version " . $Update->"latest-version" . ", updating...") false; $LogPrintExit info ("Seen a neighbor running version " . $Update->"latest-version" . ", updating...") false;
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \ ("Seen a neighbor running version " . $Update->"latest-version" . " from " . $Update->"channel" . \
", updating on " . $Identity . "...") "" "true"; ", updating on " . $Identity . "...") $Link "" "true";
$DoUpdate; $DoUpdate;
} }
@ -80,7 +81,7 @@
$LogPrintExit info ("Version " . $Update->"latest-version" . " is considered safe, updating...") false; $LogPrintExit info ("Version " . $Update->"latest-version" . " is considered safe, updating...") false;
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \ ("Version " . $Update->"latest-version" . " is considered safe for " . $Update->"channel" . \
", updating on " . $Identity . "...") "" "true"; ", updating on " . $Identity . "...") $Link "" "true";
$DoUpdate; $DoUpdate;
} }
} }
@ -102,9 +103,7 @@
$SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \ $SendNotification ([ $SymbolForNotification "sparkles" ] . "RouterOS update") \
("A new RouterOS version " . ($Update->"latest-version") . \ ("A new RouterOS version " . ($Update->"latest-version") . \
" is available for " . $Identity . ".\n\n" . \ " is available for " . $Identity . ".\n\n" . \
[ $DeviceInfo ] . "\n\n" . \ [ $DeviceInfo ]) $Link "" "true";
"https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree") \
"" "true";
:set SentRouterosUpdateNotification ($Update->"latest-version"); :set SentRouterosUpdateNotification ($Update->"latest-version");
} }
@ -117,9 +116,7 @@
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "RouterOS version") \ $SendNotification ([ $SymbolForNotification "warning-sign" ] . "RouterOS version") \
("A different RouterOS version " . ($Update->"latest-version") . \ ("A different RouterOS version " . ($Update->"latest-version") . \
" is available for " . $Identity . ", but it is a downgrade.\n\n" . \ " is available for " . $Identity . ", but it is a downgrade.\n\n" . \
[ $DeviceInfo ] . "\n\n" . \ [ $DeviceInfo ]) $Link "" "true";
"https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree") \
"" "true";
$LogPrintExit info ("A different RouterOS version " . ($Update->"latest-version") . \ $LogPrintExit info ("A different RouterOS version " . ($Update->"latest-version") . \
" is available for downgrade.") false; " is available for downgrade.") false;
:set SentRouterosUpdateNotification ($Update->"latest-version"); :set SentRouterosUpdateNotification ($Update->"latest-version");

View file

@ -32,7 +32,7 @@
[ $DeviceInfo ] . "\n\n" . \ [ $DeviceInfo ] . "\n\n" . \
"Name: " . $Cloud->"name" . "\n" . \ "Name: " . $Cloud->"name" . "\n" . \
"Size: " . $Cloud->"size" . " B (" . ($Cloud->"size" / 1024) . " KiB)\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={ } on-error={
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed") \ $SendNotification ([ $SymbolForNotification "warning-sign" ] . "Cloud backup failed") \
("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]); ("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]);

View file

@ -93,8 +93,8 @@ $WaitFullyConnected;
"SSID: " . $Ssid . "\n" . \ "SSID: " . $Ssid . "\n" . \
"PSK: " . $NewPsk . "\n" . \ "PSK: " . $NewPsk . "\n" . \
"Date: " . $Date . "\n\n" . \ "Date: " . $Date . "\n\n" . \
"A client device specific rule must not exist!\n\n" . \ "A client device specific rule must not exist!") \
$Url) $Attach; $Url $Attach;
} }
} }
} }

View file

@ -93,8 +93,8 @@ $WaitFullyConnected;
"SSID: " . $Ssid . "\n" . \ "SSID: " . $Ssid . "\n" . \
"PSK: " . $NewPsk . "\n" . \ "PSK: " . $NewPsk . "\n" . \
"Date: " . $Date . "\n\n" . \ "Date: " . $Date . "\n\n" . \
"A client device specific rule must not exist!\n\n" . \ "A client device specific rule must not exist!") \
$Url) $Attach; $Url $Attach;
} }
} }
} }

View file

@ -99,8 +99,8 @@ $WaitFullyConnected;
"SSID: " . $Ssid . "\n" . \ "SSID: " . $Ssid . "\n" . \
"PSK: " . $NewPsk . "\n" . \ "PSK: " . $NewPsk . "\n" . \
"Date: " . $Date . "\n\n" . \ "Date: " . $Date . "\n\n" . \
"A client device specific rule must not exist!\n\n" . \ "A client device specific rule must not exist!") \
$Url) $Attach; $Url $Attach;
} }
} }
} }

View file

@ -682,17 +682,18 @@
"\n\nChanges are not available."); "\n\nChanges are not available.");
} }
:local Link;
:if ($IDonate != true) do={ :if ($IDonate != true) do={
:set NotificationMessage ($NotificationMessage . \ :set NotificationMessage ($NotificationMessage . \
"\n\n==== donation hint ====\n" . \ "\n\n==== donation hint ====\n" . \
"This project is developed in private spare time and usage is " . \ "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 " . \ "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" . \ "of value for you or your business please consider a donation.");
"https://git.eworm.de/cgit/routeros-scripts/about/#donate"); :set Link "https://git.eworm.de/cgit/routeros-scripts/about/#donate";
} }
$SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \ $SendNotification ([ $SymbolForNotification "pushpin" ] . "News and configuration changes") \
$NotificationMessage; $NotificationMessage $Link;
:set SentConfigChangesNotification $ExpectedConfigVersion; :set SentConfigChangesNotification $ExpectedConfigVersion;
} }
} }
@ -712,13 +713,15 @@
:set SendEMail do={ :set SendEMail do={
:local Subject [ :tostr $1 ]; :local Subject [ :tostr $1 ];
:local Message [ :tostr $2 ]; :local Message [ :tostr $2 ];
:local Attach [ :tostr $3 ]; :local Link [ :tostr $3 ];
:local Attach [ :tostr $4 ];
:global Identity; :global Identity;
:global EmailGeneralTo; :global EmailGeneralTo;
:global EmailGeneralCc; :global EmailGeneralCc;
:global LogPrintExit; :global LogPrintExit;
:global IfThenElse;
:if ([ :len $EmailGeneralTo ] = 0) do={ :if ([ :len $EmailGeneralTo ] = 0) do={
:return false; :return false;
@ -726,12 +729,12 @@
:do { :do {
:local Signature [ / system note get note ]; :local Signature [ / system note get note ];
:if ([ :len $Signature ] > 0) do={
:set Signature ("\n-- \n" . $Signature);
}
/ tool e-mail send to=$EmailGeneralTo cc=$EmailGeneralCc \ / tool e-mail send to=$EmailGeneralTo cc=$EmailGeneralCc \
subject=("[" . $Identity . "] " . $Subject) \ subject=("[" . $Identity . "] " . $Subject) \
body=($Message . $Signature) file=$Attach; body=($Message . \
[ $IfThenElse ([ :len $Link ] > 0) ("\n\n" . $Link) "" ] . \
[ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) \
file=$Attach;
} on-error={ } on-error={
$LogPrintExit warning ("Failed sending notification mail!") false; $LogPrintExit warning ("Failed sending notification mail!") false;
} }
@ -742,21 +745,23 @@
:set SendNotification do={ :set SendNotification do={
:local Subject [ :tostr $1 ]; :local Subject [ :tostr $1 ];
:local Message [ :tostr $2 ]; :local Message [ :tostr $2 ];
:local Attach [ :tostr $3 ]; :local Link [ :tostr $3 ];
:local Silent [ :tostr $4 ]; :local Attach [ :tostr $4 ];
:local Silent [ :tostr $5 ];
:global SendEMail; :global SendEMail;
:global SendTelegram; :global SendTelegram;
$SendEMail $Subject $Message $Attach; $SendEMail $Subject $Message $Link $Attach;
$SendTelegram $Subject $Message $Silent; $SendTelegram $Subject $Message $Link $Silent;
} }
# send notification via telegram # send notification via telegram
:set SendTelegram do={ :set SendTelegram do={
:local Subject [ :tostr $1 ]; :local Subject [ :tostr $1 ];
:local Message [ :tostr $2 ]; :local Message [ :tostr $2 ];
:local Silent [ :tostr $3 ]; :local Link [ :tostr $3 ];
:local Silent [ :tostr $4 ];
:global Identity; :global Identity;
:global TelegramChatId; :global TelegramChatId;
@ -776,14 +781,15 @@
:global TelegramFixedWidthFont; :global TelegramFixedWidthFont;
:global CharacterReplace; :global CharacterReplace;
:global IfThenElse;
:if ($TelegramFixedWidthFont != true) do={ :if ($TelegramFixedWidthFont != true) do={
:return $1; :return ($1 . [ $IfThenElse ($2 = "body") "\n" "" ]);
} }
:local Return $1; :local Return $1;
:local Chars { :local Chars {
"fixed"={ "\\"; "`" }; "body"={ "\\"; "`" };
"hint"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">"; "hint"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
"#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" }; "#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" };
} }
@ -791,7 +797,7 @@
:set Return [ $CharacterReplace $Return $Char ("\\" . $Char) ]; :set Return [ $CharacterReplace $Return $Char ("\\" . $Char) ];
} }
:if ($2 = "fixed") do={ :if ($2 = "body") do={
:return ("```\n" . $Return . "\n```"); :return ("```\n" . $Return . "\n```");
} }
@ -807,13 +813,21 @@
:return false; :return false;
} }
:local Truncated false;
:local LenLink [ :len $Link ];
:local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message); :local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message);
:if ([ :len $Text ] > 3968) do={ :if ([ :len $Text ] > (3968 - $LenLink)) do={
:set Text ([ $EscapeMD ([ :pick $Text 0 3840 ] . "...") "fixed" ] . \ :set Text [ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ];
"\n\n" . [ $SymbolForNotification "scissors" ] . \ :set Truncated true;
[ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]);
} else={ } else={
:set Text [ $EscapeMD $Text "fixed" ]; :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 ]; :set Text [ $UrlEncode $Text ];
:local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ]; :local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ];
@ -825,14 +839,14 @@
/ tool fetch check-certificate=yes-without-crl output=none http-method=post \ / tool fetch check-certificate=yes-without-crl output=none http-method=post \
("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \ ("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \
http-data=("chat_id=" . $ChatId . "&disable_notification=" . $Silent . \ 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={ } on-error={
$LogPrintExit info ("Failed sending telegram notification! Queuing...") false; $LogPrintExit info ("Failed sending telegram notification! Queuing...") false;
:if ([ :typeof $TelegramQueue ] = "nothing") do={ :if ([ :typeof $TelegramQueue ] = "nothing") do={
:set TelegramQueue [ :toarray "" ]; :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 ] . \ [ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \
" " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]); " " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]);
:set ($TelegramQueue->[ :len $TelegramQueue ]) { :set ($TelegramQueue->[ :len $TelegramQueue ]) {
@ -854,6 +868,7 @@
"floppy-disk"="\F0\9F\92\BE"; "floppy-disk"="\F0\9F\92\BE";
"high-voltage-sign"="\E2\9A\A1"; "high-voltage-sign"="\E2\9A\A1";
"incoming-envelope"="\F0\9F\93\A8"; "incoming-envelope"="\F0\9F\93\A8";
"link"="\F0\9F\94\97";
"lock-with-ink-pen"="\F0\9F\94\8F"; "lock-with-ink-pen"="\F0\9F\94\8F";
"mobile-phone"="\F0\9F\93\B1"; "mobile-phone"="\F0\9F\93\B1";
"pushpin"="\F0\9F\93\8C"; "pushpin"="\F0\9F\93\8C";

View file

@ -72,7 +72,7 @@ $SendNotification [ $IfThenElse ($Failed > 0) \
("Backup and config export upload for " . $Identity . ".\n\n" . \ ("Backup and config export upload for " . $Identity . ".\n\n" . \
[ $DeviceInfo ] . "\n\n" . \ [ $DeviceInfo ] . "\n\n" . \
"Backup file: " . $BackupFile . "\n" . \ "Backup file: " . $BackupFile . "\n" . \
"Config file: " . $ConfigFile) "" "true"; "Config file: " . $ConfigFile) "" "" "true";
:if ($Failed = 1) do={ :if ($Failed = 1) do={
:error "An error occured!"; :error "An error occured!";