Project

General

Profile

« Previous | Next » 

Revision b19369b7

Added by Scott Ullrich almost 16 years ago

Adding SMTP support. Ticket #59

View differences:

etc/inc/notices.inc
72 72
	led_normalize();
73 73
	led_morse(1, 'sos');
74 74
	notify_via_growl($notice);
75
	notify_via_smtp($notice);
75 76
	return $queuekey;
76 77
}
77 78

  
......
190 191
	return false;
191 192
}
192 193

  
194
/****f* pfsense-utils/notify_via_smtp
195
 * NAME
196
 *   notify_via_smtp
197
 * INPUTS
198
 *	 notification string to send as an email
199
 * RESULT
200
 *   returns true if message was sent
201
 ******/
202
function notify_via_growl($message) {
203
	require_once("smtp.inc");
204
	global $config;
205

  
206
	if(!$config['notifications']['smtp']['ipaddress'])
207
		return;
208

  
209
	$smtp = new smtp_class;
210

  
211
	$from = "pfsense@{$config['system']['hostname']}.{$config['system']['domain']}";
212
	$to = $config['notifications']['smtp']['notifyemailaddress'];
213

  
214
	$smtp->host_name = $config['notifications']['smtp']['ipaddress'];
215
	$smtp->host_port = 25;
216

  
217
	$smtp->direct_delivery = 1;
218
	$smtp->ssl = 0;
219
	$smtp->debug = 1;
220
	$smtp->html_debug = 0;
221

  
222
	$headers = array(
223
		"From: {$from}",
224
		"To: {$to}",
225
		"Subject: {$config['system']['hostname']}.{$config['system']['domain']} - Notification",
226
		"Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
227
	);
228

  
229
	if($smtp->SendMessage($from, array($to), $headers, $message))
230
		echo "Message sent to {$to} OK.\n";
231
	else
232
		echo "Cound not send the message to {$to}.\nError: {$smtp->error}\n";
233

  
234
}
235

  
236

  
193 237
/****f* pfsense-utils/notify_via_growl
194 238
 * NAME
195 239
 *   notify_via_growl
usr/local/www/system_advanced_notifications.php
36 36

  
37 37
require("guiconfig.inc");
38 38

  
39
// Growl
39 40
if($config['notifications']['growl']['password']) 
40 41
	$pconfig['password'] = $config['notifications']['growl']['password'];
41 42
if($config['notifications']['growl']['ipaddress']) 
42 43
	$pconfig['ipaddress'] = $config['notifications']['growl']['ipaddress'];
43 44

  
45
// SMTP
46
if($config['notifications']['smtp']['username']) 
47
	$pconfig['smtpusername'] = $config['notifications']['smtp']['username'];
48
if($config['notifications']['smtp']['password']) 
49
	$pconfig['smtppassword'] = $config['notifications']['smtp']['password'];
50
if($config['notifications']['smtp']['notifyemailaddress']) 
51
	$pconfig['smtpnotifyemailaddress'] = $config['notifications']['smtp']['notifyemailaddress'];
52

  
44 53
if ($_POST) {
45 54

  
46 55
	unset($input_errors);
......
61 70
	if ($_POST['Submit'] == "Save") {
62 71
		$tunableent = array();
63 72

  
73
		// Growl
64 74
		$config['notifications']['growl']['ipaddress'] = $_POST['ipaddress'];
65 75
		$config['notifications']['growl']['password'] = $_POST['password'];
66 76

  
77
		// SMTP
78
		$config['notifications']['smtp']['ipaddress'] = $_POST['smtpipaddress'];
79
		$config['notifications']['smtp']['notifyemailaddress'] = $_POST['smtpnotifyemailaddress'];
80

  
67 81
		write_config();
68 82

  
83
		// Send test message via growl
69 84
		register_via_growl();
70 85
		notify_via_growl("This is a test message form pfSense.  It is safe to ignore this message.");
71
		
86

  
87
		// Send test message via smtp
88
		notify_via_smtp("This is a test message form pfSense.  It is safe to ignore this message.");
89

  
72 90
		pfSenseHeader("system_advanced_notifications.php");
73 91
		exit;
74 92
    }
......
111 129
				<div class="tabcont">
112 130
					<form action="system_advanced_notifications.php" method="post" name="iform">
113 131
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
132
						<!-- GROWL -->
114 133
						<tr>
115 134
							<td colspan="2" valign="top" class="listtopic">Growl</td>
116 135
						</tr>
......
128 147
								Enter the password of the remote growl notification device.
129 148
							</td>
130 149
						</tr>
150
						<!-- SMTP -->
151
						<tr>
152
							<td colspan="2" valign="top" class="listtopic">SMTP E-Mail</td>
153
						</tr>
154
						<tr>
155
							<td width="22%" valign="top" class="vncell">IP Address of E-Mail server</td>
156
							<td width="78%" class="vtable">
157
								<input name='smtpipaddress' value='<?php echo $pconfig['smtpipaddress']; ?>'><br/>
158
								This is the IP address that you would like to send growl notifications to.
159
							</td>
160
						</tr>
161
						<tr>
162
							<td width="22%" valign="top" class="vncell">Notification E-Mail address</td>
163
							<td width="78%" class="vtable">
164
								<input name='smtpnotifyemailaddress' type='input' value='<?php echo $pconfig['smtpnotifyemailaddress']; ?>'><br/>
165
								Enter the e-mail address that you would like email notifications sent to.
166
							</td>
167
						</tr>
131 168
						<tr>
132 169
							<td valign="top" class="">
133 170
								&nbsp;

Also available in: Unified diff