Project

General

Profile

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