Project

General

Profile

Download (11.4 KB) Statistics
| Branch: | Tag: | Revision:
1 a7f5d4b9 sbeaver
<?php
2 5b237745 Scott Ullrich
/*
3
	services_snmp.php
4
*/
5 191cb31d Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10 191cb31d Stephen Beaver
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58 5b237745 Scott Ullrich
59 6b07c15a Matthew Grooms
##|+PRIV
60
##|*IDENT=page-services-snmp
61 5230f468 jim-p
##|*NAME=Services: SNMP
62 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Services: SNMP' page.
63
##|*MATCH=services_snmp.php*
64
##|-PRIV
65
66 5b237745 Scott Ullrich
require("guiconfig.inc");
67 4e865673 Carlos Eduardo Ramos
require_once("functions.inc");
68 5b237745 Scott Ullrich
69
if (!is_array($config['snmpd'])) {
70
	$config['snmpd'] = array();
71
	$config['snmpd']['rocommunity'] = "public";
72 3805bfdd John Fleming
	$config['snmpd']['pollport'] = "161";
73 5b237745 Scott Ullrich
}
74
75 3805bfdd John Fleming
if (!is_array($config['snmpd']['modules'])) {
76
	$config['snmpd']['modules'] = array();
77
	$config['snmpd']['modules']['mibii'] = true;
78
	$config['snmpd']['modules']['netgraph'] = true;
79
	$config['snmpd']['modules']['pf'] = true;
80 95fb49e8 Seth Mos
	$config['snmpd']['modules']['hostres'] = true;
81
	$config['snmpd']['modules']['bridge'] = true;
82 671914b2 jim-p
	$config['snmpd']['modules']['ucd'] = true;
83
	$config['snmpd']['modules']['regex'] = true;
84 3805bfdd John Fleming
}
85 a7f5d4b9 sbeaver
86 4f4d63d8 John Fleming
$pconfig['enable'] = isset($config['snmpd']['enable']);
87 3805bfdd John Fleming
$pconfig['pollport'] = $config['snmpd']['pollport'];
88 5b237745 Scott Ullrich
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
89
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
90
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
91 4f4d63d8 John Fleming
/* disabled until some docs show up on what this does.
92
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
93
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
94
*/
95
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
96
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
97
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
98 8c3c9dc2 John Fleming
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
99 5b237745 Scott Ullrich
100 3805bfdd John Fleming
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
101
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
102
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
103 95fb49e8 Seth Mos
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
104
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
105 671914b2 jim-p
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
106
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
107 3d594a3f jim-p
$pconfig['bindip'] = $config['snmpd']['bindip'];
108 3805bfdd John Fleming
109 5b237745 Scott Ullrich
if ($_POST) {
110
111
	unset($input_errors);
112
	$pconfig = $_POST;
113
114
	/* input validation */
115
	if ($_POST['enable']) {
116 56463a6c Phil Davis
		if (strstr($_POST['syslocation'], "#")) {
117
			$input_errors[] = gettext("Invalid character '#' in system location");
118
		}
119
		if (strstr($_POST['syscontact'], "#")) {
120
			$input_errors[] = gettext("Invalid character '#' in system contact");
121
		}
122
		if (strstr($_POST['rocommunity'], "#")) {
123
			$input_errors[] = gettext("Invalid character '#' in read community string");
124
		}
125 00686fee pierrepomes
126 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "rocommunity");
127 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Community"));
128 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
129 3805bfdd John Fleming
130
		$reqdfields = explode(" ", "pollport");
131 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Polling Port"));
132 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
133 56463a6c Phil Davis
134
135 5b237745 Scott Ullrich
	}
136
137 4f4d63d8 John Fleming
	if ($_POST['trapenable']) {
138 56463a6c Phil Davis
		if (strstr($_POST['trapstring'], "#")) {
139
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
140
		}
141 00686fee pierrepomes
142 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserver");
143 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server"));
144 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
145 3805bfdd John Fleming
146 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserverport");
147 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server port"));
148 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
149 3805bfdd John Fleming
150 8c3c9dc2 John Fleming
		$reqdfields = explode(" ", "trapstring");
151 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap string"));
152 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
153 4f4d63d8 John Fleming
	}
154
155
/* disabled until some docs show up on what this does.
156
	if ($_POST['rwenable']) {
157 56463a6c Phil Davis
		$reqdfields = explode(" ", "rwcommunity");
158
		$reqdfieldsn = explode(",", "Write community string");
159
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
160 4f4d63d8 John Fleming
	}
161
*/
162
163 56463a6c Phil Davis
164 4f4d63d8 John Fleming
165 5b237745 Scott Ullrich
	if (!$input_errors) {
166 4f4d63d8 John Fleming
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
167 3805bfdd John Fleming
		$config['snmpd']['pollport'] = $_POST['pollport'];
168 a7f5d4b9 sbeaver
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
169 5b237745 Scott Ullrich
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
170
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
171 4f4d63d8 John Fleming
		/* disabled until some docs show up on what this does.
172
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
173
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
174
		*/
175
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
176
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
177
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
178 8c3c9dc2 John Fleming
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
179 a7f5d4b9 sbeaver
180 3805bfdd John Fleming
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
181
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
182
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
183 95fb49e8 Seth Mos
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
184
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
185 671914b2 jim-p
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
186
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
187 c82b2c3f jim-p
		$config['snmpd']['bindip'] = $_POST['bindip'];
188 a7f5d4b9 sbeaver
189 5b237745 Scott Ullrich
		write_config();
190 a7f5d4b9 sbeaver
191 5b237745 Scott Ullrich
		$retval = 0;
192 920b3bb0 Scott Ullrich
		$retval = services_snmpd_configure();
193 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
194
	}
195
}
196 4df96eff Scott Ullrich
197 a03c4756 sbeaver
function build_iplist() {
198
	$listenips = get_possible_listen_ips();
199
	$iplist = array();
200
	$iplist[''] = 'All';
201
202
	foreach ($listenips as $lip => $ldescr) {
203
		$iplist[$lip] = $ldescr;
204
	}
205
	unset($listenips);
206
207
	return($iplist);
208
}
209
210 56463a6c Phil Davis
$pgtitle = array(gettext("Services"), gettext("SNMP"));
211 d71fc5d3 jim-p
$shortcut_section = "snmp";
212 4df96eff Scott Ullrich
213 a03c4756 sbeaver
include("head.inc");
214
215 20db3e1a Phil Davis
if ($input_errors) {
216 a7f5d4b9 sbeaver
	print_input_errors($input_errors);
217 20db3e1a Phil Davis
}
218 7bc5c543 jim-p
219 20db3e1a Phil Davis
if ($savemsg) {
220 a7f5d4b9 sbeaver
	print_info_box($savemsg);
221 20db3e1a Phil Davis
}
222 4f4d63d8 John Fleming
223 a7f5d4b9 sbeaver
$form = new Form();
224
225
$section = new Form_Section('SNMP Daemon');
226
227
$section->addInput(new Form_Checkbox(
228
	'enable',
229
	'Enable',
230
	'Enable the SNMP Daemon and its controls',
231
	$pconfig['enable']
232 3150f4a4 Sjon Hortensius
));
233 a7f5d4b9 sbeaver
234
$form->add($section);
235
236
$section = new Form_Section('SNMP Daemon settings');
237 a03c4756 sbeaver
238 a7f5d4b9 sbeaver
$section->addInput(new Form_Input(
239
	'pollport',
240
	'Polling Port',
241
	'text',
242
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
243
))->setHelp('Enter the port to accept polling events on (default 161)');
244
245
$section->addInput(new Form_Input(
246
	'syslocation',
247
	'System Location',
248
	'text',
249
	$pconfig['syslocation']
250
));
251
252
$section->addInput(new Form_Input(
253
	'syscontact',
254
	'System Contact',
255
	'text',
256
	$pconfig['syscontact']
257
));
258
259
$section->addInput(new Form_Input(
260
	'rocommunity',
261
	'Read Community String',
262
	'text',
263
	$pconfig['rocommunity']
264
))->setHelp('The community string is like a password, restricting access to querying SNMP to hosts knowing the community string. Use a strong value here to protect from unauthorized information disclosure.');
265
266 a03c4756 sbeaver
$form->add($section);
267 a7f5d4b9 sbeaver
268
$section = new Form_Section('SNMP Traps Enable');
269 a03c4756 sbeaver
270 a7f5d4b9 sbeaver
$section->addInput(new Form_Checkbox(
271
	'trapenable',
272
	'Enable',
273
	'Enable the SNMP Trap and its controls',
274
	$pconfig['trapenable']
275
))->toggles('.toggle-traps');
276
277
$form->add($section);
278
279
$section = new Form_Section('SNMP Trap settings');
280 a03c4756 sbeaver
281 20db3e1a Phil Davis
if ($pconfig['trapenable']) {
282 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'in');
283 20db3e1a Phil Davis
} else {
284 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'collapse');
285 20db3e1a Phil Davis
}
286 a7f5d4b9 sbeaver
287
$section->addInput(new Form_Input(
288
	'trapserver',
289
	'Trap server',
290
	'text',
291
	$pconfig['trapserver']
292 a03c4756 sbeaver
))->setHelp('Enter the trap server name');
293 a7f5d4b9 sbeaver
294
$section->addInput(new Form_Input(
295
	'trapserverport',
296
	'Trap Server Port',
297
	'text',
298
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
299
))->setHelp('Enter the port to send the traps to (default 162)');
300
301
$section->addInput(new Form_Input(
302
	'trapstring',
303
	'SNMP Trap String',
304
	'text',
305
	$pconfig['trapstring']
306
));
307
308
$form->add($section);
309
310
$section = new Form_Section('SNMP Modules');
311 a03c4756 sbeaver
312 3150f4a4 Sjon Hortensius
$group = new Form_MultiCheckboxGroup('SNMP modules');
313 a7f5d4b9 sbeaver
314 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
315 a7f5d4b9 sbeaver
	'mibii',
316 a03c4756 sbeaver
	null,
317
	'MibII',
318 a7f5d4b9 sbeaver
	$pconfig['mibii']
319
));
320
321 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
322 a7f5d4b9 sbeaver
	'netgraph',
323 a03c4756 sbeaver
	null,
324 a7f5d4b9 sbeaver
	'Netgraph',
325
	$pconfig['netgraph']
326
));
327
328 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
329 a7f5d4b9 sbeaver
	'pf',
330 a03c4756 sbeaver
	null,
331 a7f5d4b9 sbeaver
	'PF',
332
	$pconfig['pf']
333
));
334
335 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
336 a7f5d4b9 sbeaver
	'hostres',
337 a03c4756 sbeaver
	null,
338 a7f5d4b9 sbeaver
	'Host Resources',
339
	$pconfig['hostres']
340
));
341
342 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
343 a7f5d4b9 sbeaver
	'ucd',
344 a03c4756 sbeaver
	null,
345 a7f5d4b9 sbeaver
	'UCD',
346
	$pconfig['ucd']
347
));
348
349 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
350 a7f5d4b9 sbeaver
	'regex',
351 a03c4756 sbeaver
	null,
352 a7f5d4b9 sbeaver
	'Regex',
353
	$pconfig['regex']
354
));
355
356
$section->add($group);
357
$form->add($section);
358
359
$section = new Form_Section('Interface Binding');
360
361
$section->addInput(new Form_Select(
362
	'bindip',
363
	'Bind Interface',
364
	$pconfig['bindip'],
365 a03c4756 sbeaver
	build_iplist()
366 a7f5d4b9 sbeaver
));
367
368
$form->add($section);
369
370
print($form);
371 a03c4756 sbeaver
?>
372
373
<script type="text/javascript">
374
//<![CDATA[
375
376
// hostres requires mibii so we force that here
377 20db3e1a Phil Davis
events.push(function() {
378 e49bf8fd Stephen Beaver
379
	noMibii = false;
380
381
	$('#junk').hide();
382
	hostresChange();
383
384
	function hostresChange() {
385 20db3e1a Phil Davis
		if ($('#hostres').prop('checked')) {
386 e49bf8fd Stephen Beaver
			$('#mibii').prop('checked', true);
387
			noMibii = true;
388
		} else {
389
			noMibii = false;
390
		}
391
	}
392
393 20db3e1a Phil Davis
	$('#hostres').change(function() {
394 e49bf8fd Stephen Beaver
		hostresChange();
395
	});
396
397
398 20db3e1a Phil Davis
	$('#mibii').change(function() {
399
		if (noMibii) {
400 e49bf8fd Stephen Beaver
			$('#mibii').prop('checked', 'true');
401
		}
402 a03c4756 sbeaver
	});
403 e49bf8fd Stephen Beaver
404 6e127720 Stephen Beaver
	$('[name=btntoggleall]').hide();
405 a03c4756 sbeaver
});
406
//]]>
407
</script>
408
409 c10cb196 Stephen Beaver
<?php include("foot.inc");