diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2009-08-25 14:37:08 -0400 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2009-08-25 14:37:08 -0400 |
commit | b19369b76bb403662b0b61093f5352dfd01082ca (patch) | |
tree | 8f944f47f1fe79198ccbcb65bd3ae0fb01af1277 | |
parent | 98301932bb99c4577e938f9b7fd61b78d78ecbef (diff) | |
download | pfsense-b19369b76bb403662b0b61093f5352dfd01082ca.zip pfsense-b19369b76bb403662b0b61093f5352dfd01082ca.tar.gz |
Adding SMTP support. Ticket #59
-rw-r--r-- | etc/inc/notices.inc | 44 | ||||
-rw-r--r-- | usr/local/www/system_advanced_notifications.php | 39 |
2 files changed, 82 insertions, 1 deletions
diff --git a/etc/inc/notices.inc b/etc/inc/notices.inc index 2f8e5fa..c354b05 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 d623d8a..6e757c4 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"); <div class="tabcont"> <form action="system_advanced_notifications.php" method="post" name="iform"> <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <!-- GROWL --> <tr> <td colspan="2" valign="top" class="listtopic">Growl</td> </tr> @@ -128,6 +147,24 @@ include("head.inc"); Enter the password of the remote growl notification device. </td> </tr> + <!-- SMTP --> + <tr> + <td colspan="2" valign="top" class="listtopic">SMTP E-Mail</td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell">IP Address of E-Mail server</td> + <td width="78%" class="vtable"> + <input name='smtpipaddress' value='<?php echo $pconfig['smtpipaddress']; ?>'><br/> + This is the IP address that you would like to send growl notifications to. + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell">Notification E-Mail address</td> + <td width="78%" class="vtable"> + <input name='smtpnotifyemailaddress' type='input' value='<?php echo $pconfig['smtpnotifyemailaddress']; ?>'><br/> + Enter the e-mail address that you would like email notifications sent to. + </td> + </tr> <tr> <td valign="top" class=""> |