summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2013-06-13 12:51:48 -0400
committerjim-p <jimp@pfsense.org>2013-06-13 12:52:04 -0400
commit95dfe4f55c38be0bfc3401f2078fc30f2737adc9 (patch)
treef8ffda735216d6738770e031f9bea087cadf16a3
parentf09926869fb72c16c91f2d036acc80b3f3edd426 (diff)
downloadpfsense-95dfe4f55c38be0bfc3401f2078fc30f2737adc9.zip
pfsense-95dfe4f55c38be0bfc3401f2078fc30f2737adc9.tar.gz
Split actual SMTP send into its own function.
-rw-r--r--etc/inc/notices.inc32
1 files changed, 18 insertions, 14 deletions
diff --git a/etc/inc/notices.inc b/etc/inc/notices.inc
index 11d4176..ff45054 100644
--- a/etc/inc/notices.inc
+++ b/etc/inc/notices.inc
@@ -273,12 +273,6 @@ function notify_via_smtp($message, $force = false) {
if(isset($config['notifications']['smtp']['disable']) && !$force)
return;
- if(!$config['notifications']['smtp']['ipaddress'])
- return;
-
- if(!$config['notifications']['smtp']['notifyemailaddress'])
- return;
-
/* Do NOT send the same message twice */
if(file_exists("/var/db/notices_lastmsg.txt")) {
$lastmsg = trim(file_get_contents("/var/db/notices_lastmsg.txt"));
@@ -286,9 +280,26 @@ function notify_via_smtp($message, $force = false) {
return;
}
+ /* Store last message sent to avoid spamming */
+ $fd = fopen("/var/db/notices_lastmsg.txt", "w");
+ fwrite($fd, $message);
+ fclose($fd);
+
+ send_smtp_message($message, "{$config['system']['hostname']}.{$config['system']['domain']} - Notification");
+ return;
+}
+
+function send_smtp_message($message, $subject = "(no subject)") {
+ global $config, $g;
require_once("sasl.inc");
require_once("smtp.inc");
+ if(!$config['notifications']['smtp']['ipaddress'])
+ return;
+
+ if(!$config['notifications']['smtp']['notifyemailaddress'])
+ return;
+
$smtp = new smtp_class;
$from = "pfsense@{$config['system']['hostname']}.{$config['system']['domain']}";
@@ -317,15 +328,10 @@ function notify_via_smtp($message, $force = false) {
$headers = array(
"From: {$from}",
"To: {$to}",
- "Subject: {$config['system']['hostname']}.{$config['system']['domain']} - Notification",
+ "Subject: {$subject}",
"Date: ".date("r")
);
- /* Store last message sent to avoid spamming */
- $fd = fopen("/var/db/notices_lastmsg.txt", "w");
- fwrite($fd, $message);
- fclose($fd);
-
if($smtp->SendMessage($from, preg_split('/\s*,\s*/', trim($to)), $headers, $message)) {
log_error(sprintf(gettext("Message sent to %s OK"), $to));
return;
@@ -333,10 +339,8 @@ function notify_via_smtp($message, $force = false) {
log_error(sprintf(gettext('Could not send the message to %1$s -- Error: %2$s'), $to, $smtp->error));
return(sprintf(gettext('Could not send the message to %1$s -- Error: %2$s'), $to, $smtp->error));
}
-
}
-
/****f* notices/notify_via_growl
* NAME
* notify_via_growl
OpenPOWER on IntegriCloud