Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
1 a7f5d4b9 sbeaver
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * services_snmp.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8 191cb31d Stephen Beaver
 *
9 c5d81585 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 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16 191cb31d Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 191cb31d Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24 191cb31d Stephen Beaver
 */
25 5b237745 Scott Ullrich
26 6b07c15a Matthew Grooms
##|+PRIV
27
##|*IDENT=page-services-snmp
28 5230f468 jim-p
##|*NAME=Services: SNMP
29 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Services: SNMP' page.
30
##|*MATCH=services_snmp.php*
31
##|-PRIV
32
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 4e865673 Carlos Eduardo Ramos
require_once("functions.inc");
35 43de8397 jim-p
36 5b237745 Scott Ullrich
if (!is_array($config['snmpd'])) {
37
	$config['snmpd'] = array();
38
	$config['snmpd']['rocommunity'] = "public";
39 3805bfdd John Fleming
	$config['snmpd']['pollport'] = "161";
40 5b237745 Scott Ullrich
}
41
42 3805bfdd John Fleming
if (!is_array($config['snmpd']['modules'])) {
43
	$config['snmpd']['modules'] = array();
44
	$config['snmpd']['modules']['mibii'] = true;
45
	$config['snmpd']['modules']['netgraph'] = true;
46
	$config['snmpd']['modules']['pf'] = true;
47 95fb49e8 Seth Mos
	$config['snmpd']['modules']['hostres'] = true;
48
	$config['snmpd']['modules']['bridge'] = true;
49 671914b2 jim-p
	$config['snmpd']['modules']['ucd'] = true;
50
	$config['snmpd']['modules']['regex'] = true;
51 3805bfdd John Fleming
}
52 a7f5d4b9 sbeaver
53 4f4d63d8 John Fleming
$pconfig['enable'] = isset($config['snmpd']['enable']);
54 3805bfdd John Fleming
$pconfig['pollport'] = $config['snmpd']['pollport'];
55 5b237745 Scott Ullrich
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
56
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
57
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
58 4f4d63d8 John Fleming
/* disabled until some docs show up on what this does.
59
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
60
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
61
*/
62
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
63
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
64
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
65 8c3c9dc2 John Fleming
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
66 5b237745 Scott Ullrich
67 3805bfdd John Fleming
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
68
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
69
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
70 95fb49e8 Seth Mos
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
71
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
72 671914b2 jim-p
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
73
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
74 df8ebedc skrude61
if (empty($config['snmpd']['bindip'])) {
75
	$pconfig['bindip'] = array();
76
} else {
77
	$pconfig['bindip'] = explode(",", $config['snmpd']['bindip']);
78
}
79 3805bfdd John Fleming
80 5b237745 Scott Ullrich
if ($_POST) {
81
82
	unset($input_errors);
83
	$pconfig = $_POST;
84
85
	/* input validation */
86
	if ($_POST['enable']) {
87 56463a6c Phil Davis
		if (strstr($_POST['syslocation'], "#")) {
88
			$input_errors[] = gettext("Invalid character '#' in system location");
89
		}
90
		if (strstr($_POST['syscontact'], "#")) {
91
			$input_errors[] = gettext("Invalid character '#' in system contact");
92
		}
93
		if (strstr($_POST['rocommunity'], "#")) {
94
			$input_errors[] = gettext("Invalid character '#' in read community string");
95
		}
96 00686fee pierrepomes
97 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "rocommunity");
98 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Community"));
99 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
100 3805bfdd John Fleming
101
		$reqdfields = explode(" ", "pollport");
102 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Polling Port"));
103 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
104 56463a6c Phil Davis
105
106 5b237745 Scott Ullrich
	}
107
108 4f4d63d8 John Fleming
	if ($_POST['trapenable']) {
109 56463a6c Phil Davis
		if (strstr($_POST['trapstring'], "#")) {
110
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
111
		}
112 00686fee pierrepomes
113 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserver");
114 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server"));
115 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
116 3805bfdd John Fleming
117 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserverport");
118 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server port"));
119 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
120 3805bfdd John Fleming
121 8c3c9dc2 John Fleming
		$reqdfields = explode(" ", "trapstring");
122 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap string"));
123 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
124 4f4d63d8 John Fleming
	}
125
126
/* disabled until some docs show up on what this does.
127
	if ($_POST['rwenable']) {
128 56463a6c Phil Davis
		$reqdfields = explode(" ", "rwcommunity");
129
		$reqdfieldsn = explode(",", "Write community string");
130
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
131 4f4d63d8 John Fleming
	}
132
*/
133
134 56463a6c Phil Davis
135 4f4d63d8 John Fleming
136 5b237745 Scott Ullrich
	if (!$input_errors) {
137 4f4d63d8 John Fleming
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
138 3805bfdd John Fleming
		$config['snmpd']['pollport'] = $_POST['pollport'];
139 a7f5d4b9 sbeaver
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
140 5b237745 Scott Ullrich
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
141
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
142 4f4d63d8 John Fleming
		/* disabled until some docs show up on what this does.
143
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
144
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
145
		*/
146
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
147
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
148
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
149 8c3c9dc2 John Fleming
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
150 a7f5d4b9 sbeaver
151 3805bfdd John Fleming
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
152
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
153
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
154 95fb49e8 Seth Mos
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
155
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
156 671914b2 jim-p
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
157
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
158 df8ebedc skrude61
		if (is_array($_POST['bindip']) && !empty($_POST['bindip'])) {
159
			$config['snmpd']['bindip'] = implode(",", $_POST['bindip']);
160
		}
161 a7f5d4b9 sbeaver
162 5b237745 Scott Ullrich
		write_config();
163 a7f5d4b9 sbeaver
164 44c42356 Phil Davis
		$changes_applied = true;
165 5b237745 Scott Ullrich
		$retval = 0;
166 44c42356 Phil Davis
		$retval |= services_snmpd_configure();
167 5b237745 Scott Ullrich
	}
168
}
169 4df96eff Scott Ullrich
170 df8ebedc skrude61
function build_if_list($selectedifs) {
171
	$interface_addresses = get_possible_listen_ips(true);
172
	$iflist = array('options' => array(), 'selected' => array());
173
174
	$iflist['options']['all']	= gettext("All");
175
	if (empty($selectedifs) || empty($selectedifs[0]) || in_array("all", $selectedifs)) {
176
		array_push($iflist['selected'], "all");
177
	}
178
179
	foreach ($interface_addresses as $laddr => $ldescr) {
180
		if (is_ipaddr(get_interface_ip($laddr))) {
181
			$iflist['options'][$laddr] = htmlspecialchars($ldescr);
182
		}
183 a03c4756 sbeaver
184 df8ebedc skrude61
		if ($selectedifs && in_array($laddr, $selectedifs)) {
185
			array_push($iflist['selected'], $laddr);
186
		}
187 a03c4756 sbeaver
	}
188
189 df8ebedc skrude61
	unset($interface_addresses);
190
191
	return($iflist);
192 a03c4756 sbeaver
}
193
194 56463a6c Phil Davis
$pgtitle = array(gettext("Services"), gettext("SNMP"));
195 d71fc5d3 jim-p
$shortcut_section = "snmp";
196 4df96eff Scott Ullrich
197 a03c4756 sbeaver
include("head.inc");
198
199 20db3e1a Phil Davis
if ($input_errors) {
200 a7f5d4b9 sbeaver
	print_input_errors($input_errors);
201 20db3e1a Phil Davis
}
202 7bc5c543 jim-p
203 44c42356 Phil Davis
if ($changes_applied) {
204
	print_apply_result_box($retval);
205 20db3e1a Phil Davis
}
206 4f4d63d8 John Fleming
207 a7f5d4b9 sbeaver
$form = new Form();
208
209
$section = new Form_Section('SNMP Daemon');
210
211
$section->addInput(new Form_Checkbox(
212
	'enable',
213
	'Enable',
214
	'Enable the SNMP Daemon and its controls',
215
	$pconfig['enable']
216 3150f4a4 Sjon Hortensius
));
217 a7f5d4b9 sbeaver
218
$form->add($section);
219
220 5f88f964 k-paulius
$section = new Form_Section('SNMP Daemon Settings');
221 a03c4756 sbeaver
222 a7f5d4b9 sbeaver
$section->addInput(new Form_Input(
223
	'pollport',
224
	'Polling Port',
225
	'text',
226
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
227 e78ecb96 NOYB
))->setHelp('Enter the port to accept polling events on (default 161).');
228 a7f5d4b9 sbeaver
229
$section->addInput(new Form_Input(
230
	'syslocation',
231
	'System Location',
232
	'text',
233
	$pconfig['syslocation']
234
));
235
236
$section->addInput(new Form_Input(
237
	'syscontact',
238
	'System Contact',
239
	'text',
240
	$pconfig['syscontact']
241
));
242
243
$section->addInput(new Form_Input(
244
	'rocommunity',
245
	'Read Community String',
246
	'text',
247
	$pconfig['rocommunity']
248
))->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.');
249
250 a03c4756 sbeaver
$form->add($section);
251 a7f5d4b9 sbeaver
252
$section = new Form_Section('SNMP Traps Enable');
253 a03c4756 sbeaver
254 a7f5d4b9 sbeaver
$section->addInput(new Form_Checkbox(
255
	'trapenable',
256
	'Enable',
257
	'Enable the SNMP Trap and its controls',
258
	$pconfig['trapenable']
259
))->toggles('.toggle-traps');
260
261
$form->add($section);
262
263 5f88f964 k-paulius
$section = new Form_Section('SNMP Trap Settings');
264 a03c4756 sbeaver
265 20db3e1a Phil Davis
if ($pconfig['trapenable']) {
266 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'in');
267 20db3e1a Phil Davis
} else {
268 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'collapse');
269 20db3e1a Phil Davis
}
270 a7f5d4b9 sbeaver
271
$section->addInput(new Form_Input(
272
	'trapserver',
273
	'Trap server',
274
	'text',
275
	$pconfig['trapserver']
276 a03c4756 sbeaver
))->setHelp('Enter the trap server name');
277 a7f5d4b9 sbeaver
278
$section->addInput(new Form_Input(
279
	'trapserverport',
280
	'Trap Server Port',
281
	'text',
282
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
283
))->setHelp('Enter the port to send the traps to (default 162)');
284
285
$section->addInput(new Form_Input(
286
	'trapstring',
287
	'SNMP Trap String',
288
	'text',
289
	$pconfig['trapstring']
290
));
291
292
$form->add($section);
293
294
$section = new Form_Section('SNMP Modules');
295 a03c4756 sbeaver
296 3150f4a4 Sjon Hortensius
$group = new Form_MultiCheckboxGroup('SNMP modules');
297 a7f5d4b9 sbeaver
298 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
299 a7f5d4b9 sbeaver
	'mibii',
300 a03c4756 sbeaver
	null,
301
	'MibII',
302 a7f5d4b9 sbeaver
	$pconfig['mibii']
303
));
304
305 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
306 a7f5d4b9 sbeaver
	'netgraph',
307 a03c4756 sbeaver
	null,
308 a7f5d4b9 sbeaver
	'Netgraph',
309
	$pconfig['netgraph']
310
));
311
312 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
313 a7f5d4b9 sbeaver
	'pf',
314 a03c4756 sbeaver
	null,
315 a7f5d4b9 sbeaver
	'PF',
316
	$pconfig['pf']
317
));
318
319 e8972c2f Renato Botelho
$group->add(new Form_MultiCheckbox(
320
	'hostres',
321
	null,
322
	'Host Resources',
323
	$pconfig['hostres']
324
));
325 a7f5d4b9 sbeaver
326 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
327 a7f5d4b9 sbeaver
	'ucd',
328 a03c4756 sbeaver
	null,
329 a7f5d4b9 sbeaver
	'UCD',
330
	$pconfig['ucd']
331
));
332
333 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
334 a7f5d4b9 sbeaver
	'regex',
335 a03c4756 sbeaver
	null,
336 a7f5d4b9 sbeaver
	'Regex',
337
	$pconfig['regex']
338
));
339
340
$section->add($group);
341
$form->add($section);
342
343
$section = new Form_Section('Interface Binding');
344
345 df8ebedc skrude61
$iflist = build_if_list($pconfig['bindip']);
346
347 a7f5d4b9 sbeaver
$section->addInput(new Form_Select(
348
	'bindip',
349 df8ebedc skrude61
	'Bind Interfaces',
350
	$iflist['selected'],
351
	$iflist['options'],
352
	true
353 a7f5d4b9 sbeaver
));
354
355
$form->add($section);
356
357
print($form);
358 a03c4756 sbeaver
?>
359
360
<script type="text/javascript">
361
//<![CDATA[
362
363
// hostres requires mibii so we force that here
364 20db3e1a Phil Davis
events.push(function() {
365 e49bf8fd Stephen Beaver
366
	noMibii = false;
367
368
	$('#junk').hide();
369 24b82516 Phil Davis
	enableChange();
370
	trapenableChange();
371 e49bf8fd Stephen Beaver
	hostresChange();
372
373 24b82516 Phil Davis
	function enableChange() {
374
		setRequired('pollport', $('#enable').prop('checked'));
375
		setRequired('rocommunity', $('#enable').prop('checked'));
376
	}
377
378
	function trapenableChange() {
379
		setRequired('trapserver', $('#trapenable').prop('checked'));
380
		setRequired('trapserverport', $('#trapenable').prop('checked'));
381
		setRequired('trapstring', $('#trapenable').prop('checked'));
382
	}
383
384 e49bf8fd Stephen Beaver
	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 24b82516 Phil Davis
	$('#enable').change(function() {
394
		enableChange();
395
	});
396
397
	$('#trapenable').change(function() {
398
		trapenableChange();
399
	});
400
401 20db3e1a Phil Davis
	$('#hostres').change(function() {
402 e49bf8fd Stephen Beaver
		hostresChange();
403
	});
404
405 20db3e1a Phil Davis
	$('#mibii').change(function() {
406
		if (noMibii) {
407 e49bf8fd Stephen Beaver
			$('#mibii').prop('checked', 'true');
408
		}
409 a03c4756 sbeaver
	});
410 e49bf8fd Stephen Beaver
411 6e127720 Stephen Beaver
	$('[name=btntoggleall]').hide();
412 a03c4756 sbeaver
});
413
//]]>
414
</script>
415
416 c10cb196 Stephen Beaver
<?php include("foot.inc");