Project

General

Profile

Download (16.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_advanced_notifications.php
5
	part of pfSense
6
	Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8

    
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11

    
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14

    
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18

    
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_MODULE:	system
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-system-advanced-notifications
36
##|*NAME=System: Advanced: Notifications page
37
##|*DESCR=Allow access to the 'System: Advanced: Notifications' page.
38
##|*MATCH=system_advanced_notifications.php*
39
##|-PRIV
40

    
41
require("guiconfig.inc");
42
require_once("notices.inc");
43

    
44
// Growl
45
$pconfig['disable_growl'] = isset($config['notifications']['growl']['disable']);
46
if ($config['notifications']['growl']['password']) {
47
	$pconfig['password'] = $config['notifications']['growl']['password'];
48
}
49
if ($config['notifications']['growl']['ipaddress']) {
50
	$pconfig['ipaddress'] = $config['notifications']['growl']['ipaddress'];
51
}
52

    
53
if ($config['notifications']['growl']['notification_name']) {
54
	$pconfig['notification_name'] = $config['notifications']['growl']['notification_name'];
55
} else {
56
  $pconfig['notification_name'] = "{$g['product_name']} growl alert";
57
}
58

    
59
if ($config['notifications']['growl']['name']) {
60
	$pconfig['name'] = $config['notifications']['growl']['name'];
61
} else {
62
  $pconfig['name'] = 'PHP-Growl';
63
}
64

    
65

    
66
// SMTP
67
$pconfig['disable_smtp'] = isset($config['notifications']['smtp']['disable']);
68
if ($config['notifications']['smtp']['ipaddress']) {
69
	$pconfig['smtpipaddress'] = $config['notifications']['smtp']['ipaddress'];
70
}
71
if ($config['notifications']['smtp']['port']) {
72
	$pconfig['smtpport'] = $config['notifications']['smtp']['port'];
73
}
74
if (isset($config['notifications']['smtp']['ssl'])) {
75
	$pconfig['smtpssl'] = true;
76
}
77
if (isset($config['notifications']['smtp']['tls'])) {
78
	$pconfig['smtptls'] = true;
79
}
80
if ($config['notifications']['smtp']['notifyemailaddress']) {
81
	$pconfig['smtpnotifyemailaddress'] = $config['notifications']['smtp']['notifyemailaddress'];
82
}
83
if ($config['notifications']['smtp']['username']) {
84
	$pconfig['smtpusername'] = $config['notifications']['smtp']['username'];
85
}
86
if ($config['notifications']['smtp']['password']) {
87
	$pconfig['smtppassword'] = $config['notifications']['smtp']['password'];
88
}
89
if ($config['notifications']['smtp']['authentication_mechanism']) {
90
	$pconfig['smtpauthmech'] = $config['notifications']['smtp']['authentication_mechanism'];
91
}
92
if ($config['notifications']['smtp']['fromaddress']) {
93
	$pconfig['smtpfromaddress'] = $config['notifications']['smtp']['fromaddress'];
94
}
95

    
96
// System Sounds
97
$pconfig['disablebeep'] = isset($config['system']['disablebeep']);
98

    
99
if ($_POST) {
100

    
101
	unset($input_errors);
102
	$pconfig = $_POST;
103

    
104
	/* if this is an AJAX caller then handle via JSON */
105
	if (isAjax() && is_array($input_errors)) {
106
		input_errors2Ajax($input_errors);
107
		exit;
108
	}
109

    
110
	if ($_POST['apply']) {
111
		$retval = 0;
112
		system_setup_sysctl();
113
		$savemsg = get_std_save_message($retval);
114
	}
115

    
116
	if ($_POST['Submit'] == gettext("Save")) {
117
		$tunableent = array();
118

    
119
		// Growl
120
		$config['notifications']['growl']['ipaddress'] = $_POST['ipaddress'];
121
		$config['notifications']['growl']['password'] = $_POST['password'];
122
		$config['notifications']['growl']['name'] = $_POST['name'];
123
		$config['notifications']['growl']['notification_name'] = $_POST['notification_name'];
124

    
125
		if ($_POST['disable_growl'] == "yes") {
126
			$config['notifications']['growl']['disable'] = true;
127
		} else {
128
			unset($config['notifications']['growl']['disable']);
129
		}
130

    
131
		// SMTP
132
		$config['notifications']['smtp']['ipaddress'] = $_POST['smtpipaddress'];
133
		$config['notifications']['smtp']['port'] = $_POST['smtpport'];
134
		if (isset($_POST['smtpssl'])) {
135
			$config['notifications']['smtp']['ssl'] = true;
136
		} else {
137
			unset($config['notifications']['smtp']['ssl']);
138
		}
139
		if (isset($_POST['smtptls'])) {
140
			$config['notifications']['smtp']['tls'] = true;
141
		} else {
142
			unset($config['notifications']['smtp']['tls']);
143
		}
144
		$config['notifications']['smtp']['notifyemailaddress'] = $_POST['smtpnotifyemailaddress'];
145
		$config['notifications']['smtp']['username'] = $_POST['smtpusername'];
146
		$config['notifications']['smtp']['password'] = $_POST['smtppassword'];
147
		$config['notifications']['smtp']['authentication_mechanism'] = $_POST['smtpauthmech'];
148
		$config['notifications']['smtp']['fromaddress'] = $_POST['smtpfromaddress'];
149

    
150
		if ($_POST['disable_smtp'] == "yes") {
151
			$config['notifications']['smtp']['disable'] = true;
152
		} else {
153
			unset($config['notifications']['smtp']['disable']);
154
		}
155

    
156
		// System Sounds
157
		if ($_POST['disablebeep'] == "yes") {
158
			$config['system']['disablebeep'] = true;
159
		} else {
160
			unset($config['system']['disablebeep']);
161
		}
162

    
163
		write_config();
164
		pfSenseHeader("system_advanced_notifications.php");
165
		return;
166

    
167
	}
168
	if ($_POST['test_growl'] == gettext("Test Growl")) {
169
		// Send test message via growl
170
		if ($config['notifications']['growl']['ipaddress'] &&
171
		    $config['notifications']['growl']['password'] = $_POST['password']) {
172
			unlink_if_exists($g['vardb_path'] . "/growlnotices_lastmsg.txt");
173
			register_via_growl();
174
			notify_via_growl(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
175
		}
176
	}
177
	if ($_POST['test_smtp'] == gettext("Test SMTP")) {
178
		// Send test message via smtp
179
		if (file_exists("/var/db/notices_lastmsg.txt")) {
180
			unlink("/var/db/notices_lastmsg.txt");
181
		}
182
		$savemsg = notify_via_smtp(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
183
	}
184
}
185

    
186
$pgtitle = array(gettext("System"), gettext("Advanced: Notifications"));
187
include("head.inc");
188

    
189
?>
190

    
191
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
192
<?php include("fbegin.inc"); ?>
193
	<form action="system_advanced_notifications.php" method="post">
194
		<?php
195
			if ($input_errors) {
196
				print_input_errors($input_errors);
197
			}
198
			if ($savemsg) {
199
				print_info_box($savemsg);
200
			}
201
		?>
202
	</form>
203
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system advanced notifications">
204
		<tr>
205
			<td>
206
				<?php
207
					$tab_array = array();
208
					$tab_array[] = array(gettext("Admin Access"), false, "system_advanced_admin.php");
209
					$tab_array[] = array(gettext("Firewall / NAT"), false, "system_advanced_firewall.php");
210
					$tab_array[] = array(gettext("Networking"), false, "system_advanced_network.php");
211
					$tab_array[] = array(gettext("Miscellaneous"), false, "system_advanced_misc.php");
212
					$tab_array[] = array(gettext("System Tunables"), false, "system_advanced_sysctl.php");
213
					$tab_array[] = array(gettext("Notifications"), true, "system_advanced_notifications.php");
214
					display_top_tabs($tab_array);
215
				?>
216
			</td>
217
		</tr>
218
		<tr>
219
			<td id="mainarea">
220
				<div class="tabcont">
221
					<form action="system_advanced_notifications.php" method="post" name="iform">
222
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
223
						<!-- GROWL -->
224
						<tr>
225
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Growl"); ?></td>
226
						</tr>
227
						<tr>
228
							<td width="22%" valign="top" class="vncell"><?=gettext("Disable Growl Notifications"); ?></td>
229
							<td width="78%" class="vtable">
230
								<input type='checkbox' name='disable_growl' value="yes" <?php if ($pconfig['disable_growl']) {?>checked="checked"<?php } ?> /><br />
231
								<?=gettext("Check this option to disable growl notifications but preserve the settings below."); ?>
232
							</td>
233
						</tr>
234
						<tr>
235
							<td width="22%" valign="top" class="vncell"><?=gettext("Registration Name"); ?></td>
236
							<td width="78%" class="vtable">
237
								<input name='name' value='<?php echo htmlspecialchars($pconfig['name'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
238
								<?=gettext("Enter the name to register with the Growl server (default: PHP-Growl)."); ?>
239
							</td>
240
						</tr>
241
					<tr>
242
							<td width="22%" valign="top" class="vncell"><?=gettext("Notification Name"); ?></td>
243
							<td width="78%" class="vtable">
244
								<input name='notification_name' value='<?php echo htmlspecialchars($pconfig['notification_name'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
245
								<?=sprintf(gettext("Enter a name for the Growl notifications (default: %s growl alert)."), $g['product_name']); ?>
246
							</td>
247
						</tr>
248
						<tr>
249
							<td width="22%" valign="top" class="vncell"><?=gettext("IP Address"); ?></td>
250
							<td width="78%" class="vtable">
251
								<input name='ipaddress' value='<?php echo htmlspecialchars($pconfig['ipaddress'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
252
								<?=gettext("This is the IP address that you would like to send growl notifications to."); ?>
253
							</td>
254
						</tr>
255
						<tr>
256
							<td width="22%" valign="top" class="vncell"><?=gettext("Password"); ?></td>
257
							<td width="78%" class="vtable">
258
								<input name='password' type='password' value='<?php echo htmlspecialchars($pconfig['password'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
259
								<?=gettext("Enter the password of the remote growl notification device."); ?>
260
							</td>
261
						</tr>
262
						<tr>
263
							<td valign="top" class="">
264
								&nbsp;
265
							</td>
266
							<td>
267
								<input type='submit' id='test_growl' name='test_growl' value='<?=gettext("Test Growl"); ?>' />
268
								<br /><?= gettext("NOTE: A test notification will be sent even if the service is marked as disabled.") ?>
269
							</td>
270
						</tr>
271
						<tr>
272
							<td colspan="2" class="list" height="12">&nbsp;</td>
273
						</tr>
274
						<!-- SMTP -->
275
						<tr>
276
							<td colspan="2" valign="top" class="listtopic"><?=gettext("SMTP E-Mail"); ?></td>
277
						</tr>
278
						<tr>
279
							<td width="22%" valign="top" class="vncell"><?=gettext("Disable SMTP Notifications"); ?></td>
280
							<td width="78%" class="vtable">
281
								<input type='checkbox' name='disable_smtp' value="yes" <?php if ($pconfig['disable_smtp']) {?>checked="checked"<?php } ?> /><br />
282
								<?=gettext("Check this option to disable SMTP notifications but preserve the settings below. Some other mechanisms, such as packages, may need these settings in place to function."); ?>
283
							</td>
284
						</tr>
285
						<tr>
286
							<td width="22%" valign="top" class="vncell"><?=gettext("E-Mail server"); ?></td>
287
							<td width="78%" class="vtable">
288
								<input name='smtpipaddress' value='<?php echo htmlspecialchars($pconfig['smtpipaddress'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
289
								<?=gettext("This is the FQDN or IP address of the SMTP E-Mail server to which notifications will be sent."); ?>
290
							</td>
291
						</tr>
292
						<tr>
293
							<td width="22%" valign="top" class="vncell"><?=gettext("SMTP Port of E-Mail server"); ?></td>
294
							<td width="78%" class="vtable">
295
								<input name='smtpport' value='<?php echo htmlspecialchars($pconfig['smtpport'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
296
								<?=gettext("This is the port of the SMTP E-Mail server, typically 25, 587 (submission) or 465 (smtps)"); ?>
297
							</td>
298
						</tr>
299
						<tr>
300
							<td width="22%" valign="top" class="vncell"><?=gettext("Secure SMTP Connection"); ?></td>
301
							<td width="78%" class="vtable">
302
								<input type='checkbox' id='smtpssl' name='smtpssl' <?php if (isset($pconfig['smtpssl'])) echo "checked=\"checked\""; ?> />Enable SMTP over SSL/TLS<br />
303
								<input type='checkbox' id='smtptls' name='smtptls' <?php if (isset($pconfig['smtptls'])) echo "checked=\"checked\""; ?> />Enable STARTTLS<br />
304
							</td>
305
						</tr>
306
						<tr>
307
							<td width="22%" valign="top" class="vncell"><?=gettext("From e-mail address"); ?></td>
308
							<td width="78%" class="vtable">
309
								<input name='smtpfromaddress' type='text' value='<?php echo htmlspecialchars($pconfig['smtpfromaddress'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
310
								<?=gettext("This is the e-mail address that will appear in the from field."); ?>
311
							</td>
312
						</tr>
313
						<tr>
314
							<td width="22%" valign="top" class="vncell"><?=gettext("Notification E-Mail address"); ?></td>
315
							<td width="78%" class="vtable">
316
								<input name='smtpnotifyemailaddress' type='text' value='<?php echo htmlspecialchars($pconfig['smtpnotifyemailaddress'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
317
								<?=gettext("Enter the e-mail address that you would like email notifications sent to."); ?>
318
							</td>
319
						</tr>
320
						<tr>
321
							<td width="22%" valign="top" class="vncell"><?=gettext("Notification E-Mail auth username (optional)"); ?></td>
322
							<td width="78%" class="vtable">
323
								<input name='smtpusername' type='text' value='<?php echo htmlspecialchars($pconfig['smtpusername'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
324
								<?=gettext("Enter the e-mail address username for SMTP authentication."); ?>
325
							</td>
326
						</tr>
327
						<tr>
328
							<td width="22%" valign="top" class="vncell"><?=gettext("Notification E-Mail auth password"); ?></td>
329
							<td width="78%" class="vtable">
330
								<input name='smtppassword' type='password' value='<?php echo htmlspecialchars($pconfig['smtppassword'], ENT_QUOTES | ENT_HTML401); ?>' /><br />
331
								<?=gettext("Enter the e-mail address password for SMTP authentication."); ?>
332
							</td>
333
						</tr>
334
						<tr>
335
							<td width="22%" valign="top" class="vncell"><?=gettext("Notification E-Mail auth mechanism"); ?></td>
336
							<td width="78%" class="vtable">
337
								<select name='smtpauthmech' id='smtpauthmech' class="formselect">
338
								<?php
339
									foreach ($smtp_authentication_mechanisms as $name => $desc):
340
										$selected = "";
341
										if ($pconfig['smtpauthmech'] == $name) {
342
											$selected = "selected=\"selected\"";
343
										}
344
								?>
345
									<option value="<?=$name;?>" <?=$selected;?>><?=$desc;?></option>
346
								<?php endforeach; ?>
347
								</select>
348
								<br />
349
								<?=gettext("Select the authentication mechanism used by the SMTP server. Most work with PLAIN, some servers like Exchange or Office365 might require LOGIN."); ?>
350
							</td>
351
						</tr>
352
						<tr>
353
							<td valign="top" class="">
354
								&nbsp;
355
							</td>
356
							<td>
357
								<input type='submit' id='test_smtp' name='test_smtp' value='<?=gettext("Test SMTP"); ?>' />
358
								<br /><?= gettext("NOTE: A test message will be sent even if the service is marked as disabled.") ?>
359
							</td>
360
						</tr>
361
						<tr>
362
							<td colspan="2" class="list" height="12">&nbsp;</td>
363
						</tr>
364
						<!-- System Sounds -->
365
						<tr>
366
							<td colspan="2" valign="top" class="listtopic"><?=gettext("System Sounds"); ?></td>
367
						</tr>
368
						<tr>
369
							<td width="22%" valign="top" class="vncell"><?=gettext("Startup/Shutdown Sound"); ?></td>
370
							<td width="78%" class="vtable">
371
								<input name="disablebeep" type="checkbox" id="disablebeep" value="yes" <?php if ($pconfig['disablebeep']) echo "checked=\"checked\""; ?> />
372
								<strong><?=gettext("Disable the startup/shutdown beep"); ?></strong>
373
								<br />
374
								<span class="vexpl"><?=gettext("When this is checked, startup and shutdown sounds will no longer play."); ?></span>
375
							</td>
376
						</tr>
377
						<tr>
378
							<td colspan="2" class="list" height="12">&nbsp;</td>
379
						</tr>
380
						<tr>
381
							<td valign="top" class="">
382
								&nbsp;
383
							</td>
384
							<td>
385
								<input type='submit' id='Submit' name='Submit' value='<?=gettext("Save"); ?>' />
386
							</td>
387
						</tr>
388
					</table>
389
					</form>
390
				</div>
391
			</td>
392
		</tr>
393
	</table>
394
<script type="text/javascript">
395
//<![CDATA[
396
	jQuery(document).ready(function() {
397
		if (jQuery('#smtpssl').is(':checked')) {
398
			jQuery('#smtptls').prop('disabled', true);
399
		} else if (jQuery('#smtptls').is(':checked')) {
400
			jQuery('#smtpssl').prop('disabled', true);
401
		}
402
	});
403
	jQuery('#smtpssl').change( function() {
404
		jQuery('#smtptls').prop('disabled', this.checked);
405
	});
406
	jQuery('#smtptls').change( function() {
407
		jQuery('#smtpssl').prop('disabled', this.checked);
408
	});
409
//]]>
410
</script>
411
<?php include("fend.inc"); ?>
412
</body>
413
</html>
(205-205/252)