From ac50d769c9c84aeddd03c7584e7de656582b291c Mon Sep 17 00:00:00 2001 From: deajan Date: Tue, 22 Mar 2016 12:38:09 +0100 Subject: [PATCH] Added pfSense mail.php support --- dev/debug_obackup.sh | 18 ++++++++++++++++-- dev/ofunctions.sh | 18 ++++++++++++++++-- obackup.sh | 18 ++++++++++++++++-- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/dev/debug_obackup.sh b/dev/debug_obackup.sh index d70bacb..22356e3 100755 --- a/dev/debug_obackup.sh +++ b/dev/debug_obackup.sh @@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre PROGRAM_BUILD=2016031801 IS_STABLE=no -## FUNC_BUILD=2016032002 +## FUNC_BUILD=2016032201 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -167,6 +167,7 @@ function SendAlert { local mail_no_attachment= local attachment_command= + local subject= if [ "$DESTINATION_MAILS" == "" ]; then return 0 @@ -270,8 +271,21 @@ function SendAlert { fi fi + # pfSense specific + if [ -f /usr/local/bin/mail.php ]; then + cmd="echo \"$MAIL_ALERT_MSG\" | /usr/local/bin/mail.php subject=\"$subject\"" + Logger "Mail cmd: $cmd" "DEBUG" + eval $cmd + if [ $? != 0 ]; then + Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN" + else + Logger "Sent alert mail using pfSense mail.php." "NOTICE" + return 0 + fi + fi + # If function has not returned 0 yet, assume it's critical that no alert can be sent - Logger "Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "ERROR" # Is not marked critical because execution must continue + Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php found)." "ERROR" # Is not marked critical because execution must continue # Delete tmp log file if [ -f "$ALERT_LOG_FILE" ]; then diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index 79ee896..e3d5d9f 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -1,4 +1,4 @@ -## FUNC_BUILD=2016032002 +## FUNC_BUILD=2016032201 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -157,6 +157,7 @@ function SendAlert { local mail_no_attachment= local attachment_command= + local subject= if [ "$DESTINATION_MAILS" == "" ]; then return 0 @@ -260,8 +261,21 @@ function SendAlert { fi fi + # pfSense specific + if [ -f /usr/local/bin/mail.php ]; then + cmd="echo \"$MAIL_ALERT_MSG\" | /usr/local/bin/mail.php subject=\"$subject\"" + Logger "Mail cmd: $cmd" "DEBUG" + eval $cmd + if [ $? != 0 ]; then + Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN" + else + Logger "Sent alert mail using pfSense mail.php." "NOTICE" + return 0 + fi + fi + # If function has not returned 0 yet, assume it's critical that no alert can be sent - Logger "Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "ERROR" # Is not marked critical because execution must continue + Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php found)." "ERROR" # Is not marked critical because execution must continue # Delete tmp log file if [ -f "$ALERT_LOG_FILE" ]; then diff --git a/obackup.sh b/obackup.sh index 199f9bb..5b9752e 100755 --- a/obackup.sh +++ b/obackup.sh @@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre PROGRAM_BUILD=2016031801 IS_STABLE=no -## FUNC_BUILD=2016032002 +## FUNC_BUILD=2016032201 ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -156,6 +156,7 @@ function SendAlert { local mail_no_attachment= local attachment_command= + local subject= if [ "$DESTINATION_MAILS" == "" ]; then return 0 @@ -259,8 +260,21 @@ function SendAlert { fi fi + # pfSense specific + if [ -f /usr/local/bin/mail.php ]; then + cmd="echo \"$MAIL_ALERT_MSG\" | /usr/local/bin/mail.php subject=\"$subject\"" + Logger "Mail cmd: $cmd" "DEBUG" + eval $cmd + if [ $? != 0 ]; then + Logger "Cannot send alert email via /usr/local/bin/mail.php (pfsense) !!!" "WARN" + else + Logger "Sent alert mail using pfSense mail.php." "NOTICE" + return 0 + fi + fi + # If function has not returned 0 yet, assume it's critical that no alert can be sent - Logger "Cannot send alert (neither mutt, mail, sendmail nor sendemail found)." "ERROR" # Is not marked critical because execution must continue + Logger "Cannot send alert (neither mutt, mail, sendmail, sendemail or pfSense mail.php found)." "ERROR" # Is not marked critical because execution must continue # Delete tmp log file if [ -f "$ALERT_LOG_FILE" ]; then