aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2022-09-23 15:07:30 +0200
committerGravatar Christian Hesse <mail@eworm.de>2022-09-25 22:10:05 +0200
commiteccc187014da0ee71bdfc94bfc105e6d4b4524ed (patch)
treea2836d3b3cd4a002e92e1bf5e748be805de8c35e /global-functions
parent562c565fcf10fff454e82bd3eb718f6b4cbc5a1d (diff)
introduce 'mod/notification-email', split off from global-functionschange-84
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions129
1 files changed, 1 insertions, 128 deletions
diff --git a/global-functions b/global-functions
index a93b883..8fc3386 100644
--- a/global-functions
+++ b/global-functions
@@ -10,7 +10,7 @@
:local 0 "global-functions";
# expected configuration version
-:global ExpectedConfigVersion 83;
+:global ExpectedConfigVersion 84;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
@@ -26,7 +26,6 @@
:global DownloadPackage;
:global EitherOr;
:global EscapeForRegEx;
-:global FlushEmailQueue;
:global GetMacVendor;
:global GetRandom20CharAlNum;
:global GetRandom20CharHex;
@@ -49,8 +48,6 @@
:global ScriptFromTerminal;
:global ScriptInstallUpdate;
:global ScriptLock;
-:global SendEMail;
-:global SendEMail2;
:global SendNotification;
:global SendNotification2;
:global SymbolByUnicodeName;
@@ -318,74 +315,6 @@
:return $Return;
}
-# flush e-mail queue
-:set FlushEmailQueue do={
- :global EmailQueue;
-
- :global EitherOr;
- :global IsDNSResolving;
- :global IsTimeSync;
- :global LogPrintExit2;
-
- :local AllDone true;
- :local QueueLen [ :len $EmailQueue ];
-
- :if ([ /tool/e-mail/get last-status ] = "in-progress") do={
- $LogPrintExit2 debug $0 ("Sending mail in currently in progress, not flushing.") false;
- :return false;
- }
-
- :if ([ $IsTimeSync ] = false) do={
- $LogPrintExit2 debug $0 ("Time is not synced, not flushing.") false;
- :return false;
- }
-
- :if ([ :typeof [ :toip [ /tool/e-mail/get address ] ] ] != "ip" && [ $IsDNSResolving ] = false) do={
- $LogPrintExit2 debug $0 ("Server address is a DNS name and resolving fails, not flushing.") false;
- :return false;
- }
-
- :if ([ :len [ /system/scheduler/find where name=$0 ] ] > 0 && $QueueLen = 0) do={
- $LogPrintExit2 warning $0 ("Flushing E-Mail messages from scheduler, but queue is empty.") false;
- }
-
- /system/scheduler/set interval=($QueueLen . "m") [ find where name=$0 ];
-
- :foreach Id,Message in=$EmailQueue do={
- :if ([ :typeof $Message ] = "array" ) do={
- :local Attach [ $EitherOr ($Message->"attach") "" ];
- :while ([ /tool/e-mail/get last-status ] = "in-progress") do={ :delay 1s; }
- /tool/e-mail/send 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=[ :toarray $Attach ] do={
- /file/remove $File;
- }
- }
- }
- :if ($Status = "failed") do={
- :set AllDone false;
- :set Wait false;
- }
- } while=($Wait = true);
- }
- }
-
- :if ($AllDone = true && $QueueLen = [ :len $EmailQueue ]) do={
- /system/scheduler/remove [ find where name=$0 ];
- :set EmailQueue;
- } else={
- /system/scheduler/set interval=1m [ find where name=$0 ];
- }
-}
-
# get MAC vendor
:set GetMacVendor do={
:local Mac [ :tostr $1 ];
@@ -609,46 +538,6 @@
:set NotificationFunctions ({});
}
-# send notification via e-mail - expects one array argument
-:set ($NotificationFunctions->"email") do={
- :local Notification $1;
-
- :global Identity;
- :global EmailGeneralTo;
- :global EmailGeneralToOverride;
- :global EmailGeneralCc;
- :global EmailGeneralCcOverride;
- :global EmailQueue;
-
- :global EitherOr;
- :global IfThenElse;
- :global QuotedPrintable;
-
- :local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ];
- :local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ];
-
- :local EMailSettings [ /tool/e-mail/get ];
- :if ([ :len $To ] = 0 || ($EMailSettings->"address") = "0.0.0.0" || ($EMailSettings->"from") = "<>") do={
- :return false;
- }
-
- :if ([ :typeof $EmailQueue ] = "nothing") do={
- :set EmailQueue ({});
- }
- :local Signature [ /system/note/get note ];
- :set ($EmailQueue->[ :len $EmailQueue ]) {
- to=$To; cc=$Cc;
- subject=[ $QuotedPrintable ("[" . $Identity . "] " . ($Notification->"subject")) ];
- body=(($Notification->"message") . \
- [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \
- [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \
- 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 \
- on-event=(":global FlushEmailQueue; \$FlushEmailQueue;");
- }
-}
-
# parse key value store
:set ParseKeyValueStore do={
:local Source $1;
@@ -1115,22 +1004,6 @@
:return true;
}
-# send notification via e-mail - expects at least two string arguments
-:set SendEMail do={
- :global SendEMail2;
-
- $SendEMail2 ({ subject=$1; message=$2; link=$3 });
-}
-
-# send notification via e-mail - expects one array argument
-:set SendEMail2 do={
- :local Notification $1;
-
- :global NotificationFunctions;
-
- ($NotificationFunctions->"email") ("\$NotificationFunctions->\"email\"") $Notification;
-}
-
# send notification via NotificationFunctions - expects at least two string arguments
:set SendNotification do={
:global SendNotification2;