Project

General

Profile

Download (10.8 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 (isset($_POST['save'])) {
105

    
106
		// Growl
107
		$config['notifications']['growl']['ipaddress'] = $_POST['ip-address'];
108
		$config['notifications']['growl']['password'] = $_POST['password'];
109
		$config['notifications']['growl']['name'] = $_POST['registration-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

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

    
139
		if ($_POST['disable_smtp'] == "yes") {
140
			$config['notifications']['smtp']['disable'] = true;
141
		} else {
142
			unset($config['notifications']['smtp']['disable']);
143
		}
144

    
145
		// System Sounds
146
		if ($_POST['disablebeep'] == "yes") {
147
			$config['system']['disablebeep'] = true;
148
		} else {
149
			unset($config['system']['disablebeep']);
150
		}
151

    
152
		write_config();
153
		pfSenseHeader("system_advanced_notifications.php");
154
		return;
155

    
156
	}
157

    
158
	if (isset($_POST['test-growl'])) {
159
		// Send test message via growl
160
		if ($config['notifications']['growl']['ipaddress'] &&
161
		    $config['notifications']['growl']['password'] = $_POST['password']) {
162
			unlink_if_exists($g['vardb_path'] . "/growlnotices_lastmsg.txt");
163
			register_via_growl();
164
			notify_via_growl(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
165
		}
166
	}
167

    
168
	if (isset($_POST['test-smtp'])) {
169
		// Send test message via smtp
170
		if (file_exists("/var/db/notices_lastmsg.txt")) {
171
			unlink("/var/db/notices_lastmsg.txt");
172
		}
173
		$savemsg = notify_via_smtp(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
174
	}
175
}
176

    
177
$pgtitle = array(gettext("System"), gettext("Advanced: Notifications"));
178
include("head.inc");
179

    
180
if ($input_errors)
181
	print_input_errors($input_errors);
182
if ($savemsg)
183
	print_info_box($savemsg);
184

    
185
$tab_array = array();
186
$tab_array[] = array(gettext("Admin Access"), false, "system_advanced_admin.php");
187
$tab_array[] = array(gettext("Firewall / NAT"), false, "system_advanced_firewall.php");
188
$tab_array[] = array(gettext("Networking"), false, "system_advanced_network.php");
189
$tab_array[] = array(gettext("Miscellaneous"), false, "system_advanced_misc.php");
190
$tab_array[] = array(gettext("System Tunables"), false, "system_advanced_sysctl.php");
191
$tab_array[] = array(gettext("Notifications"), true, "system_advanced_notifications.php");
192
display_top_tabs($tab_array);
193

    
194
?><div id="container"><?php
195

    
196
require('classes/Form.class.php');
197
$form = new Form;
198
$section = new Form_Section('Growl');
199

    
200
$section->addInput(new Form_Checkbox(
201
	'disable-growl',
202
	'Disable Growl',
203
	'Disable Growl Notifications',
204
	$pconfig['disable_growl']
205
))->setHelp('Check this option to disable growl notifications but preserve the '.
206
	'settings below.');
207

    
208
$section->addInput(new Form_Input(
209
	'registration-name',
210
	'Registration Name',
211
	'text',
212
	$pconfig['name'],
213
	['placeholder' => 'PHP-Growl']
214
))->setHelp('Enter the name to register with the Growl server.');
215

    
216
$section->addInput(new Form_Input(
217
	'notification-name',
218
	'Notification Name',
219
	'text',
220
	$pconfig['notification_name'],
221
	['placeholder' => $g["product_name"].' growl alert']
222

    
223
))->setHelp('Enter a name for the Growl notifications');
224

    
225
$section->addInput(new Form_Input(
226
	'ip-address',
227
	'IP Address',
228
	'text',
229
	$pconfig['ipaddress']
230
))->setHelp('This is the IP address that you would like to send growl '.
231
	'notifications to.');
232

    
233
$section->addInput(new Form_Input(
234
	'password',
235
	'Password',
236
	'text',
237
	$pconfig['password']
238
))->setHelp('Enter the password of the remote growl notification device.');
239

    
240
$section->addInput(new Form_Input(
241
	'test-growl',
242
	'Test Growl',
243
	'submit',
244
	'Test Growl settings'
245
))->setHelp('A test notification will be sent even if the service is '.
246
	'marked as disabled.');
247

    
248
$form->add($section);
249
$section = new Form_Section('E-Mail');
250

    
251
$section->addInput(new Form_Checkbox(
252
	'disable-smtp',
253
	'Disable SMTP',
254
	'Disable SMTP Notifications',
255
	$pconfig['disable_smtp']
256
))->setHelp('Check this option to disable SMTP notifications but preserve the '.
257
	'settings below. Some other mechanisms, such as packages, may need these settings '.
258
	'in place to function.');
259

    
260
$section->addInput(new Form_Input(
261
	'e-mail-server',
262
	'E-Mail server',
263
	'text',
264
	$pconfig['smtpipaddress']
265
))->setHelp('This is the FQDN or IP address of the SMTP E-Mail server to '.
266
	'which notifications will be sent.');
267

    
268
$section->addInput(new Form_Input(
269
	'smtp-port-of-e-mail-server',
270
	'SMTP Port of E-Mail server',
271
	'number',
272
	$pconfig['smtpport']
273
))->setHelp('This is the port of the SMTP E-Mail server, typically 25, 587 '.
274
	'(submission) or 465 (smtps)');
275

    
276
$group = new Form_Group('Secure SMTP Connection');
277
$group->add(new Form_Checkbox(
278
	'enable-ssl-tls',
279
	'Enable SSL/TLS',
280
	'Enable SMTP over SSL/TLS',
281
	isset($pconfig['smtpssl'])
282
));
283

    
284
$group->add(new Form_Checkbox(
285
	'secure-starttls',
286
	'Secure STARTTLS',
287
	'Enable STARTTLS',
288
	isset($pconfig['smtptls'])
289
));
290

    
291
$section->add($group);
292

    
293
$section->addInput(new Form_Input(
294
	'from-e-mail-address',
295
	'From e-mail address',
296
	'text',
297
	$pconfig['smtpfromaddress']
298
))->setHelp('This is the e-mail address that will appear in the from field.');
299

    
300
$section->addInput(new Form_Input(
301
	'notification-e-mail-address',
302
	'Notification E-Mail address',
303
	'text',
304
	$pconfig['smtpnotifyemailaddress']
305
))->setHelp('Enter the e-mail address that you would like email '.
306
	'notifications sent to.');
307

    
308
$section->addInput(new Form_Input(
309
	'notification-e-mail-auth-username-optional-',
310
	'Notification E-Mail auth username (optional)',
311
	'text',
312
	$pconfig['smtpusername']
313
))->setHelp('Enter the e-mail address username for SMTP authentication.');
314

    
315
$section->addInput(new Form_Input(
316
	'notification-e-mail-auth-password',
317
	'Notification E-Mail auth password',
318
	'password',
319
	$pconfig['smtppassword']
320
))->setHelp('Enter the e-mail address password for SMTP authentication.');
321

    
322
$section->addInput(new Form_Input(
323
	'test-smtp',
324
	'Test SMTP',
325
	'submit',
326
	'Test SMTP settings'
327
))->setHelp('A test notification will be sent even if the service is '.
328
	'marked as disabled.');
329

    
330
$section->addInput(new Form_Checkbox(
331
	'startup-shutdown-sound',
332
	'Startup/Shutdown Sound',
333
	'Disable the startup/shutdown beep',
334
	$pconfig['disablebeep']
335
))->setHelp('When this is checked, startup and shutdown sounds will no longer '.
336
	'play.');
337

    
338
$form->add($section);
339
print $form;
340

    
341
include("foot.inc");
(192-192/238)