Projet

Général

Profil

Télécharger (15 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_advanced_notifications.php @ cce09d94

1
<?php
2
/* $Id$ */
3
/*
4
	system_advanced_notifications.php
5
	part of pfSense
6
	Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
7

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

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

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

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

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

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

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

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

    
60

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

    
80
// System Sounds
81
$pconfig['disablebeep'] = isset($config['system']['disablebeep']);
82

    
83
if ($_POST) {
84

    
85
	unset($input_errors);
86
	$pconfig = $_POST;
87
	$pconfig['smtpssl'] = isset($_POST['smtpssl']) ? 'checked' : 'unchecked';
88
	$pconfig['smtptls'] = isset($_POST['smtptls']) ? (isset($_POST['smtpssl']) ? 'unchecked' : 'checked') : 'unchecked';
89

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

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

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

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

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

    
116
		// SMTP
117
		$config['notifications']['smtp']['ipaddress'] = $_POST['smtpipaddress'];
118
		$config['notifications']['smtp']['port'] = $_POST['smtpport'];
119
		$config['notifications']['smtp']['ssl'] = $pconfig['smtpssl'];
120
		$config['notifications']['smtp']['tls'] = $pconfig['smtptls'];
121
		$config['notifications']['smtp']['notifyemailaddress'] = $_POST['smtpnotifyemailaddress'];
122
		$config['notifications']['smtp']['username'] = $_POST['smtpusername'];
123
		$config['notifications']['smtp']['password'] = $_POST['smtppassword'];
124
		$config['notifications']['smtp']['fromaddress'] = $_POST['smtpfromaddress'];
125

    
126
		if($_POST['disable_smtp'] == "yes")
127
			$config['notifications']['smtp']['disable'] = true;
128
		else
129
			unset($config['notifications']['smtp']['disable']);
130

    
131
		// System Sounds
132
		if($_POST['disablebeep'] == "yes")
133
			$config['system']['disablebeep'] = true;
134
		else
135
			unset($config['system']['disablebeep']);
136

    
137
		write_config();
138
		pfSenseHeader("system_advanced_notifications.php");
139
		return;
140

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

    
159
$pgtitle = array(gettext("System"),gettext("Advanced: Notifications"));
160
include("head.inc");
161

    
162
?>
163

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