From b19369b76bb403662b0b61093f5352dfd01082ca Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Tue, 25 Aug 2009 14:37:08 -0400 Subject: [PATCH] Adding SMTP support. Ticket #59 --- etc/inc/notices.inc | 44 +++++++++++++++++++ .../www/system_advanced_notifications.php | 39 +++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/etc/inc/notices.inc b/etc/inc/notices.inc index 2f8e5fa4eb..c354b057bf 100644 --- a/etc/inc/notices.inc +++ b/etc/inc/notices.inc @@ -72,6 +72,7 @@ function file_notice($id, $notice, $category = "General", $url = "", $priority = led_normalize(); led_morse(1, 'sos'); notify_via_growl($notice); + notify_via_smtp($notice); return $queuekey; } @@ -190,6 +191,49 @@ function are_notices_pending($category = "all") { return false; } +/****f* pfsense-utils/notify_via_smtp + * NAME + * notify_via_smtp + * INPUTS + * notification string to send as an email + * RESULT + * returns true if message was sent + ******/ +function notify_via_growl($message) { + require_once("smtp.inc"); + global $config; + + if(!$config['notifications']['smtp']['ipaddress']) + return; + + $smtp = new smtp_class; + + $from = "pfsense@{$config['system']['hostname']}.{$config['system']['domain']}"; + $to = $config['notifications']['smtp']['notifyemailaddress']; + + $smtp->host_name = $config['notifications']['smtp']['ipaddress']; + $smtp->host_port = 25; + + $smtp->direct_delivery = 1; + $smtp->ssl = 0; + $smtp->debug = 1; + $smtp->html_debug = 0; + + $headers = array( + "From: {$from}", + "To: {$to}", + "Subject: {$config['system']['hostname']}.{$config['system']['domain']} - Notification", + "Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z") + ); + + if($smtp->SendMessage($from, array($to), $headers, $message)) + echo "Message sent to {$to} OK.\n"; + else + echo "Cound not send the message to {$to}.\nError: {$smtp->error}\n"; + +} + + /****f* pfsense-utils/notify_via_growl * NAME * notify_via_growl diff --git a/usr/local/www/system_advanced_notifications.php b/usr/local/www/system_advanced_notifications.php index d623d8a7a2..6e757c4156 100644 --- a/usr/local/www/system_advanced_notifications.php +++ b/usr/local/www/system_advanced_notifications.php @@ -36,11 +36,20 @@ require("guiconfig.inc"); +// Growl if($config['notifications']['growl']['password']) $pconfig['password'] = $config['notifications']['growl']['password']; if($config['notifications']['growl']['ipaddress']) $pconfig['ipaddress'] = $config['notifications']['growl']['ipaddress']; +// SMTP +if($config['notifications']['smtp']['username']) + $pconfig['smtpusername'] = $config['notifications']['smtp']['username']; +if($config['notifications']['smtp']['password']) + $pconfig['smtppassword'] = $config['notifications']['smtp']['password']; +if($config['notifications']['smtp']['notifyemailaddress']) + $pconfig['smtpnotifyemailaddress'] = $config['notifications']['smtp']['notifyemailaddress']; + if ($_POST) { unset($input_errors); @@ -61,14 +70,23 @@ if ($_POST) { if ($_POST['Submit'] == "Save") { $tunableent = array(); + // Growl $config['notifications']['growl']['ipaddress'] = $_POST['ipaddress']; $config['notifications']['growl']['password'] = $_POST['password']; + // SMTP + $config['notifications']['smtp']['ipaddress'] = $_POST['smtpipaddress']; + $config['notifications']['smtp']['notifyemailaddress'] = $_POST['smtpnotifyemailaddress']; + write_config(); + // Send test message via growl register_via_growl(); notify_via_growl("This is a test message form pfSense. It is safe to ignore this message."); - + + // Send test message via smtp + notify_via_smtp("This is a test message form pfSense. It is safe to ignore this message."); + pfSenseHeader("system_advanced_notifications.php"); exit; } @@ -111,6 +129,7 @@ include("head.inc");
+ @@ -128,6 +147,24 @@ include("head.inc"); Enter the password of the remote growl notification device. + + + + + + + + + + + +
Growl
SMTP E-Mail
IP Address of E-Mail server + '>
+ This is the IP address that you would like to send growl notifications to. +
Notification E-Mail address + '>
+ Enter the e-mail address that you would like email notifications sent to. +