Project

General

Profile

Download (10.5 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']['fromaddress'])
79
	$pconfig['smtpfromaddress'] = $config['notifications']['smtp']['fromaddress'];
80

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

    
84
if ($_POST) {
85

    
86
	unset($input_errors);
87
	$pconfig = $_POST;
88

    
89
	if (isset($_POST['save'])) {
90

    
91
		// Growl
92
		$config['notifications']['growl']['ipaddress'] = $_POST['ip-address'];
93
		$config['notifications']['growl']['password'] = $_POST['password'];
94
		$config['notifications']['growl']['name'] = $_POST['registration-name'];
95
		$config['notifications']['growl']['notification_name'] = $_POST['notification-name'];
96

    
97
		if($_POST['disable-growl'] == "yes")
98
			$config['notifications']['growl']['disable'] = true;
99
		else
100
			unset($config['notif	ications']['growl']['disable']);
101

    
102
		// SMTP
103
		$config['notifications']['smtp']['ipaddress'] = $_POST['e-mail-server'];
104
		$config['notifications']['smtp']['port'] = $_POST['smtp-port-of-e-mail-server'];
105
		if (isset($_POST['enable-ssl-tls']))
106
			$config['notifications']['smtp']['ssl'] = true;
107
		else
108
			unset($config['notifications']['smtp']['ssl']);
109
		if (isset($_POST['secure-starttls']))
110
			$config['notifications']['smtp']['tls'] = true;
111
		else
112
			unset($config['notifications']['smtp']['tls']);
113
		$config['notifications']['smtp']['notifyemailaddress'] = $_POST['notification-e-mail-address'];
114
		$config['notifications']['smtp']['username'] = $_POST['notification-e-mail-auth-username-optional-'];
115
		$config['notifications']['smtp']['password'] = $_POST['notification-e-mail-auth-password'];
116
		$config['notifications']['smtp']['fromaddress'] = $_POST['from-e-mail-address'];
117

    
118
		if($_POST['disable-smtp'] == "yes")
119
			$config['notifications']['smtp']['disable'] = true;
120
		else
121
			unset($config['notifications']['smtp']['disable']);
122

    
123
		// System Sounds
124
		if($_POST['startup-shutdown-sound'] == "yes")
125
			$config['system']['disablebeep'] = true;
126
		else
127
			unset($config['system']['disablebeep']);
128

    
129
		write_config();
130
		pfSenseHeader("system_advanced_notifications.php");
131
		return;
132

    
133
	}
134

    
135
	if (isset($_POST['test-growl'])) {
136
		// Send test message via growl
137
		if($config['notifications']['growl']['ipaddress'] &&
138
			$config['notifications']['growl']['password'] = $_POST['password']) {
139
			unlink_if_exists($g['vardb_path'] . "/growlnotices_lastmsg.txt");
140
			register_via_growl();
141
			notify_via_growl(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
142
		}
143
	}
144

    
145
	if (isset($_POST['test-smtp'])) {
146
		// Send test message via smtp
147
		if(file_exists("/var/db/notices_lastmsg.txt"))
148
			unlink("/var/db/notices_lastmsg.txt");
149
		$savemsg = notify_via_smtp(sprintf(gettext("This is a test message from %s.  It is safe to ignore this message."), $g['product_name']), true);
150
	}
151
}
152

    
153
$pgtitle = array(gettext("System"),gettext("Advanced: Notifications"));
154
include("head.inc");
155

    
156
if ($input_errors)
157
	print_input_errors($input_errors);
158
if ($savemsg)
159
	print_info_box($savemsg);
160

    
161
$tab_array = array();
162
$tab_array[] = array(gettext("Admin Access"), false, "system_advanced_admin.php");
163
$tab_array[] = array(gettext("Firewall / NAT"), false, "system_advanced_firewall.php");
164
$tab_array[] = array(gettext("Networking"), false, "system_advanced_network.php");
165
$tab_array[] = array(gettext("Miscellaneous"), false, "system_advanced_misc.php");
166
$tab_array[] = array(gettext("System Tunables"), false, "system_advanced_sysctl.php");
167
$tab_array[] = array(gettext("Notifications"), true, "system_advanced_notifications.php");
168
display_top_tabs($tab_array);
169

    
170
?><div id="container"><?php
171

    
172
require('classes/Form.class.php');
173
$form = new Form;
174
$section = new Form_Section('Growl');
175

    
176
$section->addInput(new Form_Checkbox(
177
	'disable-growl',
178
	'Disable Growl',
179
	'Disable Growl Notifications',
180
	$pconfig['disable_growl']
181
))->setHelp('Check this option to disable growl notifications but preserve the '.
182
	'settings below.');
183

    
184
$section->addInput(new Form_Input(
185
	'registration-name',
186
	'Registration Name',
187
	'text',
188
	$pconfig['name'],
189
	['placeholder' => 'PHP-Growl']
190
))->setHelp('Enter the name to register with the Growl server.');
191

    
192
$section->addInput(new Form_Input(
193
	'notification-name',
194
	'Notification Name',
195
	'text',
196
	$pconfig['notification_name'],
197
	['placeholder' => $g["product_name"].' growl alert']
198

    
199
))->setHelp('Enter a name for the Growl notifications');
200

    
201
$section->addInput(new Form_Input(
202
	'ip-address',
203
	'IP Address',
204
	'text',
205
	$pconfig['ipaddress']
206
))->setHelp('This is the IP address that you would like to send growl '.
207
	'notifications to.');
208

    
209
$section->addInput(new Form_Input(
210
	'password',
211
	'Password',
212
	'text',
213
	$pconfig['password']
214
))->setHelp('Enter the password of the remote growl notification device.');
215

    
216
$section->addInput(new Form_Input(
217
	'test-growl',
218
	'Test Growl',
219
	'submit',
220
	'Test Growl settings'
221
))->setHelp('A test notification will be sent even if the service is '.
222
	'marked as disabled.');
223

    
224
$form->add($section);
225
$section = new Form_Section('E-Mail');
226

    
227
$section->addInput(new Form_Checkbox(
228
	'disable-smtp',
229
	'Disable SMTP',
230
	'Disable SMTP Notifications',
231
	$pconfig['disable_smtp']
232
))->setHelp('Check this option to disable SMTP notifications but preserve the '.
233
	'settings below. Some other mechanisms, such as packages, may need these settings '.
234
	'in place to function.');
235

    
236
$section->addInput(new Form_Input(
237
	'e-mail-server',
238
	'E-Mail server',
239
	'text',
240
	$pconfig['smtpipaddress']
241
))->setHelp('This is the FQDN or IP address of the SMTP E-Mail server to '.
242
	'which notifications will be sent.');
243

    
244
$section->addInput(new Form_Input(
245
	'smtp-port-of-e-mail-server',
246
	'SMTP Port of E-Mail server',
247
	'number',
248
	$pconfig['smtpport']
249
))->setHelp('This is the port of the SMTP E-Mail server, typically 25, 587 '.
250
	'(submission) or 465 (smtps)');
251

    
252
$group = new Form_Group('Secure SMTP Connection');
253
$group->add(new Form_Checkbox(
254
	'enable-ssl-tls',
255
	'Enable SSL/TLS',
256
	'Enable SMTP over SSL/TLS',
257
	isset($pconfig['smtpssl'])
258
));
259

    
260
$group->add(new Form_Checkbox(
261
	'secure-starttls',
262
	'Secure STARTTLS',
263
	'Enable STARTTLS',
264
	isset($pconfig['smtptls'])
265
));
266

    
267
$section->add($group);
268

    
269
$section->addInput(new Form_Input(
270
	'from-e-mail-address',
271
	'From e-mail address',
272
	'text',
273
	$pconfig['smtpfromaddress']
274
))->setHelp('This is the e-mail address that will appear in the from field.');
275

    
276
$section->addInput(new Form_Input(
277
	'notification-e-mail-address',
278
	'Notification E-Mail address',
279
	'text',
280
	$pconfig['smtpnotifyemailaddress']
281
))->setHelp('Enter the e-mail address that you would like email '.
282
	'notifications sent to.');
283

    
284
$section->addInput(new Form_Input(
285
	'notification-e-mail-auth-username-optional-',
286
	'Notification E-Mail auth username (optional)',
287
	'text',
288
	$pconfig['smtpusername']
289
))->setHelp('Enter the e-mail address username for SMTP authentication.');
290

    
291
$section->addInput(new Form_Input(
292
	'notification-e-mail-auth-password',
293
	'Notification E-Mail auth password',
294
	'password',
295
	$pconfig['smtppassword']
296
))->setHelp('Enter the e-mail address password for SMTP authentication.');
297

    
298
$section->addInput(new Form_Input(
299
	'test-smtp',
300
	'Test SMTP',
301
	'submit',
302
	'Test SMTP settings'
303
))->setHelp('A test notification will be sent even if the service is '.
304
	'marked as disabled.');
305

    
306
$section->addInput(new Form_Checkbox(
307
	'startup-shutdown-sound',
308
	'Startup/Shutdown Sound',
309
	'Disable the startup/shutdown beep',
310
	$pconfig['disablebeep']
311
))->setHelp('When this is checked, startup and shutdown sounds will no longer '.
312
	'play.');
313

    
314
$form->add($section);
315
print $form;
316

    
317
include("foot.inc");
(206-206/252)