|
|
@ -2,7 +2,7 @@
|
|
|
|
#### OFUNCTIONS MINI SUBSET ####
|
|
|
|
#### OFUNCTIONS MINI SUBSET ####
|
|
|
|
|
|
|
|
|
|
|
|
_OFUNCTIONS_VERSION=2.1
|
|
|
|
_OFUNCTIONS_VERSION=2.1
|
|
|
|
_OFUNCTIONS_BUILD=2016120902
|
|
|
|
_OFUNCTIONS_BUILD=2016121002
|
|
|
|
_OFUNCTIONS_BOOTSTRAP=true
|
|
|
|
_OFUNCTIONS_BOOTSTRAP=true
|
|
|
|
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
|
|
|
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
|
|
|
|
|
|
|
|
|
|
@ -202,6 +202,7 @@ function RemoteLogger {
|
|
|
|
function Logger {
|
|
|
|
function Logger {
|
|
|
|
local value="${1}" # Sentence to log (in double quotes)
|
|
|
|
local value="${1}" # Sentence to log (in double quotes)
|
|
|
|
local level="${2}" # Log level
|
|
|
|
local level="${2}" # Log level
|
|
|
|
|
|
|
|
local retval="${3:-undef}" # optional return value of command
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
|
|
|
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
|
|
|
prefix="TIME: $SECONDS - "
|
|
|
|
prefix="TIME: $SECONDS - "
|
|
|
@ -215,17 +216,17 @@ function Logger {
|
|
|
|
_Logger "$prefix($level):$value" "$prefix\e[41m$value\e[0m" true
|
|
|
|
_Logger "$prefix($level):$value" "$prefix\e[41m$value\e[0m" true
|
|
|
|
ERROR_ALERT=true
|
|
|
|
ERROR_ALERT=true
|
|
|
|
# ERROR_ALERT / WARN_ALERT isn't set in main when Logger is called from a subprocess. Need to keep this flag.
|
|
|
|
# ERROR_ALERT / WARN_ALERT isn't set in main when Logger is called from a subprocess. Need to keep this flag.
|
|
|
|
echo "1" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID"
|
|
|
|
echo "[$retval] in [${FUNCNAME[@]}] SP=$SCRIPT_PID P=$$" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID"
|
|
|
|
return
|
|
|
|
return
|
|
|
|
elif [ "$level" == "ERROR" ]; then
|
|
|
|
elif [ "$level" == "ERROR" ]; then
|
|
|
|
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
|
|
|
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
|
|
|
ERROR_ALERT=true
|
|
|
|
ERROR_ALERT=true
|
|
|
|
echo "1" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID"
|
|
|
|
echo "[$retval] in [${FUNCNAME[@]}] SP=$SCRIPT_PID P=$$" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID"
|
|
|
|
return
|
|
|
|
return
|
|
|
|
elif [ "$level" == "WARN" ]; then
|
|
|
|
elif [ "$level" == "WARN" ]; then
|
|
|
|
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
|
|
|
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
|
|
|
WARN_ALERT=true
|
|
|
|
WARN_ALERT=true
|
|
|
|
echo "1" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.warn.$SCRIPT_PID"
|
|
|
|
echo "[$retval] in [${FUNCNAME[@]}] SP=$SCRIPT_PID P=$$" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.warn.$SCRIPT_PID"
|
|
|
|
return
|
|
|
|
return
|
|
|
|
elif [ "$level" == "NOTICE" ]; then
|
|
|
|
elif [ "$level" == "NOTICE" ]; then
|
|
|
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
|
|
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
|
|
@ -394,7 +395,7 @@ function SendAlert {
|
|
|
|
attachmentFile="$ALERT_LOG_FILE"
|
|
|
|
attachmentFile="$ALERT_LOG_FILE"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
SendEmail "$subject" "$body" "$DESTINATION_MAILS" "$attachmentFile" "$SENDER_MAIL" "$SMTP_SERVER" "$SMTP_PORT" "$ENCRYPTION" "SMTP_USER" "$SMTP_PASSWORD"
|
|
|
|
SendEmail "$subject" "$body" "$DESTINATION_MAILS" "$attachmentFile" "$SENDER_MAIL" "$SMTP_SERVER" "$SMTP_PORT" "$SMTP_ENCRYPTION" "SMTP_USER" "$SMTP_PASSWORD"
|
|
|
|
|
|
|
|
|
|
|
|
# Delete tmp log file
|
|
|
|
# Delete tmp log file
|
|
|
|
if [ "$attachment" == true ]; then
|
|
|
|
if [ "$attachment" == true ]; then
|
|
|
@ -441,13 +442,17 @@ function SendEmail {
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$LOCAL_OS" == "Busybox" ] || [ "$LOCAL_OS" == "Android" ]; then
|
|
|
|
if [ "$LOCAL_OS" == "Busybox" ] || [ "$LOCAL_OS" == "Android" ]; then
|
|
|
|
|
|
|
|
if [ "$smtpPort" == "" ]; then
|
|
|
|
|
|
|
|
Logger "Missing smtp port, assuming 25." "WARN"
|
|
|
|
|
|
|
|
smtpPort=25
|
|
|
|
|
|
|
|
fi
|
|
|
|
if type sendmail > /dev/null 2>&1; then
|
|
|
|
if type sendmail > /dev/null 2>&1; then
|
|
|
|
if [ "$ENCRYPTION" == "tls" ]; then
|
|
|
|
if [ "$ENCRYPTION" == "tls" ]; then
|
|
|
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$SenderMail" -H "exec openssl s_client -quiet -tls1_2 -starttls smtp -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
|
|
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$SenderMail" -H "exec openssl s_client -quiet -tls1_2 -starttls smtp -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
|
|
|
elif [ "$ENCRYPTION" == "ssl" ]; then
|
|
|
|
elif [ "$ENCRYPTION" == "ssl" ]; then
|
|
|
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$SenderMail" -H "exec openssl s_client -quiet -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
|
|
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$SenderMail" -H "exec openssl s_client -quiet -connect $smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
|
|
|
else
|
|
|
|
else
|
|
|
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$SenderMail" -S "$smtpServer:$SmtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
|
|
|
echo -e "Subject:$subject\r\n$message" | $(type -p sendmail) -f "$SenderMail" -S "$smtpServer:$smtpPort" -au"$smtpUser" -ap"$smtpPassword" "$destinationMails"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|