mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
Adding SMTP support. Ticket #59
This commit is contained in:
parent
98301932bb
commit
b19369b76b
@ -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
|
||||
|
||||
@ -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="">
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user