Project

General

Profile

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