Project

General

Profile

Download (16.2 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
if($config['notifications']['growl']['ipaddress']) 
49
	$pconfig['ipaddress'] = $config['notifications']['growl']['ipaddress'];
50

    
51
if($config['notifications']['growl']['notification_name']) 
52
	$pconfig['notification_name'] = $config['notifications']['growl']['notification_name'];
53
else
54
  $pconfig['notification_name'] = "{$g['product_name']} growl alert";
55
  
56
if($config['notifications']['growl']['name']) 
57
	$pconfig['name'] = $config['notifications']['growl']['name'];
58
else
59
  $pconfig['name'] = 'PHP-Growl';
60

    
61

    
62
// SMTP
63
$pconfig['disable_smtp'] = isset($config['notifications']['smtp']['disable']);
64
if ($config['notifications']['smtp']['ipaddress'])
65
	$pconfig['smtpipaddress'] = $config['notifications']['smtp']['ipaddress'];
66
if ($config['notifications']['smtp']['port'])
67
	$pconfig['smtpport'] = $config['notifications']['smtp']['port'];
68
if (isset($config['notifications']['smtp']['ssl']))
69
	$pconfig['smtpssl'] = true;
70
if (isset($config['notifications']['smtp']['tls']))
71
	$pconfig['smtptls'] = true;
72
if ($config['notifications']['smtp']['notifyemailaddress'])
73
	$pconfig['smtpnotifyemailaddress'] = $config['notifications']['smtp']['notifyemailaddress'];
74
if ($config['notifications']['smtp']['username'])
75
	$pconfig['smtpusername'] = $config['notifications']['smtp']['username'];
76
if ($config['notifications']['smtp']['password'])
77
	$pconfig['smtppassword'] = $config['notifications']['smtp']['password'];
78
if ($config['notifications']['smtp']['authentication_mechanism'])
79
	$pconfig['smtpauthmech'] = $config['notifications']['smtp']['authentication_mechanism'];
80
if ($config['notifications']['smtp']['fromaddress'])
81
	$pconfig['smtpfromaddress'] = $config['notifications']['smtp']['fromaddress'];
82

    
83
// System Sounds
84
$pconfig['disablebeep'] = isset($config['system']['disablebeep']);
85

    
86
if ($_POST) {
87

    
88
	unset($input_errors);
89
	$pconfig = $_POST;
90

    
91
	/* if this is an AJAX caller then handle via JSON */
92
	if (isAjax() && is_array($input_errors)) {
93
		input_errors2Ajax($input_errors);
94
		exit;
95
	}
96

    
97
	if ($_POST['apply']) {
98
		$retval = 0;
99
		system_setup_sysctl();		
100
		$savemsg = get_std_save_message($retval);
101
	}
102

    
103
	if ($_POST['Submit'] == gettext("Save")) {
104
		$tunableent = array();
105

    
106
		// Growl
107
		$config['notifications']['growl']['ipaddress'] = $_POST['ipaddress'];
108
		$config['notifications']['growl']['password'] = $_POST['password'];
109
		$config['notifications']['growl']['name'] = $_POST['name'];
110
		$config['notifications']['growl']['notification_name'] = $_POST['notification_name'];
111

    
112
		if($_POST['disable_growl'] == "yes")
113
			$config['notifications']['growl']['disable'] = true;
114
		else
115
			unset($config['notifications']['growl']['disable']);
116

    
117
		// SMTP
118
		$config['notifications']['smtp']['ipaddress'] = $_POST['smtpipaddress'];
119
		$config['notifications']['smtp']['port'] = $_POST['smtpport'];
120
		if (isset($_POST['smtpssl']))
121
			$config['notifications']['smtp']['ssl'] = true;
122
		else
123
			unset($config['notifications']['smtp']['ssl']);
124
		if (isset($_POST['smtptls']))
125
			$config['notifications']['smtp']['tls'] = true;
126
		else
127
			unset($config['notifications']['smtp']['tls']);
128
		$config['notifications']['smtp']['notifyemailaddress'] = $_POST['smtpnotifyemailaddress'];
129
		$config['notifications']['smtp']['username'] = $_POST['smtpusername'];
130
		$config['notifications']['smtp']['password'] = $_POST['smtppassword'];
131
		$config['notifications']['smtp']['authentication_mechanism'] = $_POST['smtpauthmech'];
132
		$config['notifications']['smtp']['fromaddress'] = $_POST['smtpfromaddress'];
133

    
134
		if($_POST['disable_smtp'] == "yes")
135
			$config['notifications']['smtp']['disable'] = true;
136
		else
137
			unset($config['notifications']['smtp']['disable']);
138

    
139
		// System Sounds
140
		if($_POST['disablebeep'] == "yes")
141
			$config['system']['disablebeep'] = true;
142
		else
143
			unset($config['system']['disablebeep']);
144

    
145
		write_config();
146
		pfSenseHeader("system_advanced_notifications.php");
147
		return;
148

    
149
	}
150
	if ($_POST['test_growl'] == gettext("Test Growl")) {
151
		// Send test message via growl
152
		if($config['notifications']['growl']['ipaddress'] && 
153
			$config['notifications']['growl']['password'] = $_POST['password']) {
154
			unlink_if_exists($g['vardb_path'] . "/growlnotices_lastmsg.txt");
155
			register_via_growl();
156
			notify_via_growl(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
157
		}
158
	}
159
	if ($_POST['test_smtp'] == gettext("Test SMTP")) {
160
		// Send test message via smtp
161
		if(file_exists("/var/db/notices_lastmsg.txt"))
162
			unlink("/var/db/notices_lastmsg.txt");
163
		$savemsg = notify_via_smtp(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
164
	}
165
}
166

    
167
$pgtitle = array(gettext("System"),gettext("Advanced: Notifications"));
168
include("head.inc");
169

    
170
?>
171

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