aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.d/03-check-certs.avifbin9339 -> 12089 bytes
-rw-r--r--README.md2
-rw-r--r--backup-cloud.rsc33
-rw-r--r--backup-upload.rsc2
-rw-r--r--global-functions.rsc30
-rw-r--r--mod/notification-matrix.rsc11
-rw-r--r--mod/notification-telegram.rsc29
-rw-r--r--mod/ssh-keys-import.rsc12
-rw-r--r--netwatch-notify.rsc5
-rw-r--r--telegram-chat.rsc2
10 files changed, 73 insertions, 53 deletions
diff --git a/README.d/03-check-certs.avif b/README.d/03-check-certs.avif
index 33bdc40..0477c39 100644
--- a/README.d/03-check-certs.avif
+++ b/README.d/03-check-certs.avif
Binary files differ
diff --git a/README.md b/README.md
index a92f71d..b6e529d 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ fingerprint. Make sure exactly these two certificates ("*E1*" and
/certificate/set name="E1" [ find where common-name="E1" ];
/certificate/set name="ISRG-Root-X2" [ find where common-name="ISRG Root X2" ];
- /certificate/print proplist=name where fingerprint="46494e30379059df18be52124305e606fc59070e5b21076ce113954b60517cda" or fingerprint="69729b8e15a86efc177a57afb7171dfc64add28c2fca8cf1507e34453ccb1470";
+ /certificate/print proplist=name,fingerprint where fingerprint="46494e30379059df18be52124305e606fc59070e5b21076ce113954b60517cda" or fingerprint="69729b8e15a86efc177a57afb7171dfc64add28c2fca8cf1507e34453ccb1470";
/file/remove [ find where name="letsencrypt-E1.pem" ];
![screenshot: check certs](README.d/03-check-certs.avif)
diff --git a/backup-cloud.rsc b/backup-cloud.rsc
index 8e29c67..88dd345 100644
--- a/backup-cloud.rsc
+++ b/backup-cloud.rsc
@@ -47,21 +47,23 @@
:error false;
}
- :execute {
- :global BackupPassword;
- # we are not interested in output, but print is
- # required to fetch information from cloud
- /system/backup/cloud/print as-value;
- :delay 20ms;
- :if ([ :len [ /system/backup/cloud/find ] ] > 0) do={
- /system/backup/cloud/upload-file action=create-and-upload \
- password=$BackupPassword replace=[ get ([ find ]->0) name ];
- } else={
- /system/backup/cloud/upload-file action=create-and-upload \
- password=$BackupPassword;
- }
- /file/add name="tmpfs/backup-cloud/done";
- } as-string;
+ :local I 5;
+ :do {
+ :execute {
+ :global BackupPassword;
+
+ :local Backup ([ /system/backup/cloud/find ]->0);
+ :if ([ :typeof $Backup ] = "id") do={
+ /system/backup/cloud/upload-file action=create-and-upload \
+ password=$BackupPassword replace=$Backup;
+ } else={
+ /system/backup/cloud/upload-file action=create-and-upload \
+ password=$BackupPassword;
+ }
+ /file/add name="tmpfs/backup-cloud/done";
+ } as-string;
+ :set I ($I - 1);
+ } while=([ $WaitForFile "tmpfs/backup-cloud/done" 200ms ] = false && $I > 0);
:if ([ $WaitForFile "tmpfs/backup-cloud/done" ] = true) do={
:local Cloud [ /system/backup/cloud/get ([ find ]->0) ];
@@ -79,7 +81,6 @@
message=("Failed uploading backup for " . $Identity . " to cloud!\n\n" . [ $DeviceInfo ]) });
$LogPrint error $ScriptName ("Failed uploading backup for " . $Identity . " to cloud!");
:set PackagesUpdateBackupFailure true;
- :error false;
}
/file/remove "tmpfs/backup-cloud";
} on-error={ }
diff --git a/backup-upload.rsc b/backup-upload.rsc
index 63e5b7f..1dc98d5 100644
--- a/backup-upload.rsc
+++ b/backup-upload.rsc
@@ -156,6 +156,6 @@
:if ($Failed = 1) do={
:set PackagesUpdateBackupFailure true;
- :error false;
}
+ /file/remove $DirName;
} on-error={ }
diff --git a/global-functions.rsc b/global-functions.rsc
index 66765bf..e8163ed 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -230,11 +230,19 @@
:for I from=0 to=([ :len $Input ] - 1) do={
:local Char [ :pick $Input $I ];
:if ([ :typeof [ find "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-" $Char ] ] = "nil") do={
- :set Char "-";
- }
- :if ($Char != "-" || [ :pick $Return ([ :len $Return ] - 1) ] != "-") do={
- :set Return ($Return . $Char);
+ :do {
+ :if ([ :len $Return ] = 0) do={
+ :error true;
+ }
+ :if ([ :pick $Return ([ :len $Return ] - 1) ] = "-") do={
+ :error true;
+ }
+ :set Char "-";
+ } on-error={
+ :set Char "";
+ }
}
+ :set Return ($Return . $Char);
}
:return $Return;
}
@@ -406,13 +414,13 @@
:set CheckCert [ $IfThenElse ($CheckCert = false) "no" "yes-without-crl" ];
- :local FileName ("tmpfs/" . [ $CleanName $ScriptName ]);
- :if ([ $MkDir $FileName ] = false) do={
+ :local DirName ("tmpfs/" . [ $CleanName $ScriptName ]);
+ :if ([ $MkDir $DirName ] = false) do={
$LogPrint error $0 ("Failed creating directory!");
:return false;
}
- :set FileName ($FileName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]);
+ :local FileName ($DirName . "/" . [ $CleanName $0 ] . "-" . [ $GetRandom20CharAlNum ]);
:do {
/tool/fetch check-certificate=$CheckCert $Url dst-path=$FileName \
http-header-field=({ [ $FetchUserAgentStr $ScriptName ] }) as-value;
@@ -421,6 +429,7 @@
/file/remove $FileName;
}
$LogPrint debug $0 ("Failed downloading from: " . $Url);
+ /file/remove $DirName;
:return false;
}
$WaitForFile $FileName;
@@ -432,7 +441,7 @@
:set Return ($Return . ([ /file/read offset=$VarSize chunk-size=32768 file=$FileName as-value ]->"data"));
:set VarSize [ :len $Return ];
}
- /file/remove $FileName;
+ /file/remove $DirName;
:return $Return;
}
@@ -1508,13 +1517,14 @@
:global CleanFilePath;
:global EitherOr;
+ :global MAX;
:set FileName [ $CleanFilePath $FileName ];
:local I 1;
- :local Delay ([ :totime [ $EitherOr $WaitTime 2s ] ] / 20);
+ :local Delay ([ $MAX [ $EitherOr $WaitTime 2s ] 100ms ] / 10);
:while ([ :len [ /file/find where name=$FileName ] ] = 0) do={
- :if ($I >= 20) do={
+ :if ($I >= 10) do={
:return false;
}
:delay $Delay;
diff --git a/mod/notification-matrix.rsc b/mod/notification-matrix.rsc
index 9442f54..196633a 100644
--- a/mod/notification-matrix.rsc
+++ b/mod/notification-matrix.rsc
@@ -139,11 +139,12 @@
:if ([ :typeof $MatrixQueue ] = "nothing") do={
:set MatrixQueue ({});
}
- :local Text ([ $SymbolForNotification "alarm-clock" ] . \
- "This message was queued since " . [ /system/clock/get date ] . \
- " " . [ /system/clock/get time ] . " and may be obsolete.");
- :set Plain ($Plain . "\n" . $Text);
- :set Formatted ($Formatted . "<br/>" . $Text);
+ :local Symbol [ $SymbolForNotification "alarm-clock" ];
+ :local DateTime ([ /system/clock/get date ] . " " . [ /system/clock/get time ]);
+ :set Plain ($Plain . "\n" . $Symbol . "This message was queued since *" . \
+ $DateTime . "* and may be obsolete.");
+ :set Formatted ($Formatted . "<br/>" . $Symbol . "This message was queued since <em>" . \
+ $DateTime . "</em> and may be obsolete.");
:set ($MatrixQueue->[ :len $MatrixQueue ]) { headers=$Headers; \
accesstoken=$AccessToken; homeserver=$HomeServer; room=$Room; \
plain=$Plain; formatted=$Formatted };
diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc
index 745367a..9a628ce 100644
--- a/mod/notification-telegram.rsc
+++ b/mod/notification-telegram.rsc
@@ -81,24 +81,29 @@
:global UrlEncode;
:local EscapeMD do={
+ :local Text [ :tostr $1 ];
+ :local Mode [ :tostr $2 ];
+ :local Excl [ :tostr $3 ];
+
:global CharacterReplace;
:global IfThenElse;
- :local Return $1;
:local Chars {
- "body"={ "\\"; "`" };
+ "body"={ "\\"; "`" };
"plain"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
"#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" };
}
- :foreach Char in=($Chars->$2) do={
- :set Return [ $CharacterReplace $Return $Char ("\\" . $Char) ];
+ :foreach Char in=($Chars->$Mode) do={
+ :if ([ :typeof [ :find $Excl $Char ] ] = "nil") do={
+ :set Text [ $CharacterReplace $Text $Char ("\\" . $Char) ];
+ }
}
- :if ($2 = "body") do={
- :return ("```\n" . $Return . "\n```");
+ :if ($Mode = "body") do={
+ :return ("```\n" . $Text . "\n```");
}
- :return $Return;
+ :return $Text;
}
:local ChatId [ $EitherOr ($Notification->"chatid") \
@@ -133,8 +138,8 @@
}
:if ($Truncated = true) do={
:set Text ($Text . "\n" . [ $SymbolForNotification "scissors" ] . \
- [ $EscapeMD ("The message was too long and has been truncated, cut off " . \
- (($LenSum - [ :len $Text ]) * 100 / $LenSum) . "%!") "plain" ]);
+ [ $EscapeMD ("The message was too long and has been truncated, cut off _" . \
+ (($LenSum - [ :len $Text ]) * 100 / $LenSum) . "%_!") "plain" "_" ]);
}
:do {
@@ -149,14 +154,14 @@
"&parse_mode=MarkdownV2&text=" . [ $UrlEncode $Text ]) as-value ]->"data");
:set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1;
} on-error={
- $LogPrint info $0 ("Failed sending telegram notification! Queuing...");
+ $LogPrint info $0 ("Failed sending Telegram notification! Queuing...");
:if ([ :typeof $TelegramQueue ] = "nothing") do={
:set TelegramQueue ({});
}
:set Text ($Text . "\n" . [ $SymbolForNotification "alarm-clock" ] . \
- [ $EscapeMD ("This message was queued since " . [ /system/clock/get date ] . \
- " " . [ /system/clock/get time ] . " and may be obsolete.") "plain" ]);
+ [ $EscapeMD ("This message was queued since _" . [ /system/clock/get date ] . \
+ " " . [ /system/clock/get time ] . "_ and may be obsolete.") "plain" "_" ]);
:set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TokenId;
text=$Text; silent=($Notification->"silent"); replyto=($Notification->"replyto") };
:if ([ :len [ /system/scheduler/find where name="_FlushTelegramQueue" ] ] = 0) do={
diff --git a/mod/ssh-keys-import.rsc b/mod/ssh-keys-import.rsc
index f37c28b..6272a93 100644
--- a/mod/ssh-keys-import.rsc
+++ b/mod/ssh-keys-import.rsc
@@ -38,11 +38,6 @@
:return false;
}
- :if ([ $MkDir "tmpfs/ssh-keys-import" ] = false) do={
- $LogPrint warning $0 ("Creating directory 'tmpfs/ssh-keys-import' failed!");
- :return false;
- }
-
:local FingerPrintMD5 [ :convert from=base64 transform=md5 to=hex ($KeyVal->1) ];
:if ([ :len [ /user/ssh-keys/find where user=$User key-owner~("\\bmd5=" . $FingerPrintMD5 . "\\b") ] ] > 0) do={
@@ -51,6 +46,11 @@
:return false;
}
+ :if ([ $MkDir "tmpfs/ssh-keys-import" ] = false) do={
+ $LogPrint warning $0 ("Creating directory 'tmpfs/ssh-keys-import' failed!");
+ :return false;
+ }
+
:local FileName ("tmpfs/ssh-keys-import/key-" . [ $GetRandom20CharAlNum 6 ] . ".pub");
/file/add name=$FileName contents=($Key . ", md5=" . $FingerPrintMD5);
$WaitForFile $FileName;
@@ -59,8 +59,10 @@
/user/ssh-keys/import public-key-file=$FileName user=$User;
$LogPrint info $0 ("Imported ssh public key (" . $KeyVal->2 . ", " . $KeyVal->0 . ", " . \
"MD5:" . $FingerPrintMD5 . ") for user '" . $User . "'.");
+ /file/remove "tmpfs/ssh-keys-import";
} on-error={
$LogPrint warning $0 ("Failed importing key.");
+ /file/remove "tmpfs/ssh-keys-import";
:return false;
}
}
diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc
index 9b0beb9..17682f0 100644
--- a/netwatch-notify.rsc
+++ b/netwatch-notify.rsc
@@ -116,8 +116,9 @@
}
} on-error={
:set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1);
- :if ($Metric->"resolve-failcnt" = 3 && $HostInfo->"no-resolve-fail" != true) do={
- $LogPrint warning $ScriptName ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse \
+ :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.");
}
diff --git a/telegram-chat.rsc b/telegram-chat.rsc
index c1a1cbc..f8dcd42 100644
--- a/telegram-chat.rsc
+++ b/telegram-chat.rsc
@@ -81,7 +81,7 @@
}
:if ($Data = false) do={
- $LogPrint warning $ScriptName ("Failed getting updates from Telegram.");
+ $LogPrint warning $ScriptName ("Failed getting updates.");
:error false;
}