aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-11-27 10:03:08 +0100
committerGravatar Christian Hesse <mail@eworm.de>2020-11-27 10:03:08 +0100
commit107f9e4bdf5e0964a66faab82620d7f42c5c1fca (patch)
tree87892cbd20b3f1d8911676c9cf15752b3b30ec47
parent6b19cf2578fb840d286e6539fa82acbacbf6cca5 (diff)
parentca4e25283fa7a3c72d4b678cd0e5781f71cfed7e (diff)
Merge branch 'telegram-clickable'
-rw-r--r--check-certificates2
-rw-r--r--check-lte-firmware-upgrade2
-rw-r--r--check-routeros-update15
-rw-r--r--cloud-backup2
-rw-r--r--daily-psk.capsman4
-rw-r--r--daily-psk.local4
-rw-r--r--daily-psk.template4
-rw-r--r--global-functions61
-rw-r--r--upload-backup2
9 files changed, 54 insertions, 42 deletions
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 b0b27c2..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,13 +713,15 @@
:set SendEMail do={
:local Subject [ :tostr $1 ];
:local Message [ :tostr $2 ];
- :local Attach [ :tostr $3 ];
+ :local Link [ :tostr $3 ];
+ :local Attach [ :tostr $4 ];
:global Identity;
:global EmailGeneralTo;
:global EmailGeneralCc;
:global LogPrintExit;
+ :global IfThenElse;
:if ([ :len $EmailGeneralTo ] = 0) do={
:return false;
@@ -726,12 +729,12 @@
: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 $Link ] > 0) ("\n\n" . $Link) "" ] . \
+ [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]) \
+ file=$Attach;
} on-error={
$LogPrintExit warning ("Failed sending notification mail!") false;
}
@@ -742,21 +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 Silent [ :tostr $3 ];
+ :local Link [ :tostr $3 ];
+ :local Silent [ :tostr $4 ];
:global Identity;
:global TelegramChatId;
@@ -776,14 +781,15 @@
:global TelegramFixedWidthFont;
:global CharacterReplace;
+ :global IfThenElse;
:if ($TelegramFixedWidthFont != true) do={
- :return $1;
+ :return ($1 . [ $IfThenElse ($2 = "body") "\n" "" ]);
}
:local Return $1;
:local Chars {
- "fixed"={ "\\"; "`" };
+ "body"={ "\\"; "`" };
"hint"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
"#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" };
}
@@ -791,7 +797,7 @@
:set Return [ $CharacterReplace $Return $Char ("\\" . $Char) ];
}
- :if ($2 = "fixed") do={
+ :if ($2 = "body") do={
:return ("```\n" . $Return . "\n```");
}
@@ -807,13 +813,21 @@
:return false;
}
+ :local Truncated false;
+ :local LenLink [ :len $Link ];
:local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message);
- :if ([ :len $Text ] > 3968) do={
- :set Text ([ $EscapeMD ([ :pick $Text 0 3840 ] . "...") "fixed" ] . \
- "\n\n" . [ $SymbolForNotification "scissors" ] . \
- [ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]);
+ :if ([ :len $Text ] > (3968 - $LenLink)) do={
+ :set Text [ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ];
+ :set Truncated true;
} 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 ];
:local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ];
@@ -825,14 +839,14 @@
/ 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;
: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 ]) {
@@ -854,6 +868,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";
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!";