Project

General

Profile

Download (11.2 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 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 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 cd974f08 Viktor G
77
$pconfig['ipprotocol'] = $config['snmpd']['ipprotocol'];
78 df8ebedc skrude61
if (empty($config['snmpd']['bindip'])) {
79
	$pconfig['bindip'] = array();
80
} else {
81
	$pconfig['bindip'] = explode(",", $config['snmpd']['bindip']);
82
}
83 3805bfdd John Fleming
84 5b237745 Scott Ullrich
if ($_POST) {
85
86
	unset($input_errors);
87
	$pconfig = $_POST;
88
89
	/* input validation */
90
	if ($_POST['enable']) {
91 56463a6c Phil Davis
		if (strstr($_POST['syslocation'], "#")) {
92
			$input_errors[] = gettext("Invalid character '#' in system location");
93
		}
94
		if (strstr($_POST['syscontact'], "#")) {
95
			$input_errors[] = gettext("Invalid character '#' in system contact");
96
		}
97
		if (strstr($_POST['rocommunity'], "#")) {
98
			$input_errors[] = gettext("Invalid character '#' in read community string");
99
		}
100 00686fee pierrepomes
101 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "rocommunity");
102 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Community"));
103 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
104 3805bfdd John Fleming
105
		$reqdfields = explode(" ", "pollport");
106 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Polling Port"));
107 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
108 56463a6c Phil Davis
109
110 5b237745 Scott Ullrich
	}
111
112 4f4d63d8 John Fleming
	if ($_POST['trapenable']) {
113 56463a6c Phil Davis
		if (strstr($_POST['trapstring'], "#")) {
114
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
115
		}
116 00686fee pierrepomes
117 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserver");
118 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server"));
119 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
120 3805bfdd John Fleming
121 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserverport");
122 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server port"));
123 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
124 3805bfdd John Fleming
125 8c3c9dc2 John Fleming
		$reqdfields = explode(" ", "trapstring");
126 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap string"));
127 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
128 4f4d63d8 John Fleming
	}
129
130
/* disabled until some docs show up on what this does.
131
	if ($_POST['rwenable']) {
132 56463a6c Phil Davis
		$reqdfields = explode(" ", "rwcommunity");
133
		$reqdfieldsn = explode(",", "Write community string");
134
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
135 4f4d63d8 John Fleming
	}
136
*/
137
138 56463a6c Phil Davis
139 4f4d63d8 John Fleming
140 5b237745 Scott Ullrich
	if (!$input_errors) {
141 4f4d63d8 John Fleming
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
142 3805bfdd John Fleming
		$config['snmpd']['pollport'] = $_POST['pollport'];
143 a7f5d4b9 sbeaver
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
144 5b237745 Scott Ullrich
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
145
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
146 4f4d63d8 John Fleming
		/* disabled until some docs show up on what this does.
147
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
148
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
149
		*/
150
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
151
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
152
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
153 8c3c9dc2 John Fleming
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
154 a7f5d4b9 sbeaver
155 3805bfdd John Fleming
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
156
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
157
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
158 95fb49e8 Seth Mos
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
159
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
160 671914b2 jim-p
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
161
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
162 cd974f08 Viktor G
163
		$config['snmpd']['ipprotocol'] = $_POST['ipprotocol'];
164 df8ebedc skrude61
		if (is_array($_POST['bindip']) && !empty($_POST['bindip'])) {
165
			$config['snmpd']['bindip'] = implode(",", $_POST['bindip']);
166
		}
167 a7f5d4b9 sbeaver
168 e85ae672 Renato Botelho do Couto
		write_config("SNMP settings saved");
169 a7f5d4b9 sbeaver
170 44c42356 Phil Davis
		$changes_applied = true;
171 5b237745 Scott Ullrich
		$retval = 0;
172 44c42356 Phil Davis
		$retval |= services_snmpd_configure();
173 5b237745 Scott Ullrich
	}
174
}
175 4df96eff Scott Ullrich
176 df8ebedc skrude61
function build_if_list($selectedifs) {
177
	$interface_addresses = get_possible_listen_ips(true);
178
	$iflist = array('options' => array(), 'selected' => array());
179
180
	$iflist['options']['all']	= gettext("All");
181
	if (empty($selectedifs) || empty($selectedifs[0]) || in_array("all", $selectedifs)) {
182
		array_push($iflist['selected'], "all");
183
	}
184
185
	foreach ($interface_addresses as $laddr => $ldescr) {
186
		if (is_ipaddr(get_interface_ip($laddr))) {
187
			$iflist['options'][$laddr] = htmlspecialchars($ldescr);
188
		}
189 a03c4756 sbeaver
190 df8ebedc skrude61
		if ($selectedifs && in_array($laddr, $selectedifs)) {
191
			array_push($iflist['selected'], $laddr);
192
		}
193 a03c4756 sbeaver
	}
194
195 df8ebedc skrude61
	unset($interface_addresses);
196
197
	return($iflist);
198 a03c4756 sbeaver
}
199
200 56463a6c Phil Davis
$pgtitle = array(gettext("Services"), gettext("SNMP"));
201 d71fc5d3 jim-p
$shortcut_section = "snmp";
202 4df96eff Scott Ullrich
203 a03c4756 sbeaver
include("head.inc");
204
205 20db3e1a Phil Davis
if ($input_errors) {
206 a7f5d4b9 sbeaver
	print_input_errors($input_errors);
207 20db3e1a Phil Davis
}
208 7bc5c543 jim-p
209 44c42356 Phil Davis
if ($changes_applied) {
210
	print_apply_result_box($retval);
211 20db3e1a Phil Davis
}
212 4f4d63d8 John Fleming
213 a7f5d4b9 sbeaver
$form = new Form();
214
215
$section = new Form_Section('SNMP Daemon');
216
217
$section->addInput(new Form_Checkbox(
218
	'enable',
219
	'Enable',
220
	'Enable the SNMP Daemon and its controls',
221
	$pconfig['enable']
222 3150f4a4 Sjon Hortensius
));
223 a7f5d4b9 sbeaver
224
$form->add($section);
225
226 5f88f964 k-paulius
$section = new Form_Section('SNMP Daemon Settings');
227 a03c4756 sbeaver
228 a7f5d4b9 sbeaver
$section->addInput(new Form_Input(
229
	'pollport',
230
	'Polling Port',
231
	'text',
232
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
233 e78ecb96 NOYB
))->setHelp('Enter the port to accept polling events on (default 161).');
234 a7f5d4b9 sbeaver
235
$section->addInput(new Form_Input(
236
	'syslocation',
237
	'System Location',
238
	'text',
239
	$pconfig['syslocation']
240
));
241
242
$section->addInput(new Form_Input(
243
	'syscontact',
244
	'System Contact',
245
	'text',
246
	$pconfig['syscontact']
247
));
248
249
$section->addInput(new Form_Input(
250
	'rocommunity',
251
	'Read Community String',
252
	'text',
253
	$pconfig['rocommunity']
254
))->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.');
255
256 a03c4756 sbeaver
$form->add($section);
257 a7f5d4b9 sbeaver
258
$section = new Form_Section('SNMP Traps Enable');
259 a03c4756 sbeaver
260 a7f5d4b9 sbeaver
$section->addInput(new Form_Checkbox(
261
	'trapenable',
262
	'Enable',
263
	'Enable the SNMP Trap and its controls',
264
	$pconfig['trapenable']
265
))->toggles('.toggle-traps');
266
267
$form->add($section);
268
269 5f88f964 k-paulius
$section = new Form_Section('SNMP Trap Settings');
270 a03c4756 sbeaver
271 20db3e1a Phil Davis
if ($pconfig['trapenable']) {
272 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'in');
273 20db3e1a Phil Davis
} else {
274 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'collapse');
275 20db3e1a Phil Davis
}
276 a7f5d4b9 sbeaver
277
$section->addInput(new Form_Input(
278
	'trapserver',
279
	'Trap server',
280
	'text',
281
	$pconfig['trapserver']
282 a03c4756 sbeaver
))->setHelp('Enter the trap server name');
283 a7f5d4b9 sbeaver
284
$section->addInput(new Form_Input(
285
	'trapserverport',
286
	'Trap Server Port',
287
	'text',
288
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
289
))->setHelp('Enter the port to send the traps to (default 162)');
290
291
$section->addInput(new Form_Input(
292
	'trapstring',
293
	'SNMP Trap String',
294
	'text',
295
	$pconfig['trapstring']
296
));
297
298
$form->add($section);
299
300
$section = new Form_Section('SNMP Modules');
301 a03c4756 sbeaver
302 3150f4a4 Sjon Hortensius
$group = new Form_MultiCheckboxGroup('SNMP modules');
303 a7f5d4b9 sbeaver
304 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
305 a7f5d4b9 sbeaver
	'mibii',
306 a03c4756 sbeaver
	null,
307
	'MibII',
308 a7f5d4b9 sbeaver
	$pconfig['mibii']
309
));
310
311 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
312 a7f5d4b9 sbeaver
	'netgraph',
313 a03c4756 sbeaver
	null,
314 a7f5d4b9 sbeaver
	'Netgraph',
315
	$pconfig['netgraph']
316
));
317
318 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
319 a7f5d4b9 sbeaver
	'pf',
320 a03c4756 sbeaver
	null,
321 a7f5d4b9 sbeaver
	'PF',
322
	$pconfig['pf']
323
));
324
325 e8972c2f Renato Botelho
$group->add(new Form_MultiCheckbox(
326
	'hostres',
327
	null,
328
	'Host Resources',
329
	$pconfig['hostres']
330
));
331 a7f5d4b9 sbeaver
332 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
333 a7f5d4b9 sbeaver
	'ucd',
334 a03c4756 sbeaver
	null,
335 a7f5d4b9 sbeaver
	'UCD',
336
	$pconfig['ucd']
337
));
338
339 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
340 a7f5d4b9 sbeaver
	'regex',
341 a03c4756 sbeaver
	null,
342 a7f5d4b9 sbeaver
	'Regex',
343
	$pconfig['regex']
344
));
345
346
$section->add($group);
347
$form->add($section);
348
349
$section = new Form_Section('Interface Binding');
350
351 cd974f08 Viktor G
$section->addInput(new Form_Select(
352
	'ipprotocol',
353
	'Internet Protocol',
354
	$pconfig['ipprotocol'],
355
	array("inet4" => "IPv4", "inet6" => "IPv6", "inet46" => "IPv4+IPv6")
356
));
357
358 df8ebedc skrude61
$iflist = build_if_list($pconfig['bindip']);
359
360 a7f5d4b9 sbeaver
$section->addInput(new Form_Select(
361
	'bindip',
362 df8ebedc skrude61
	'Bind Interfaces',
363
	$iflist['selected'],
364
	$iflist['options'],
365
	true
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 24b82516 Phil Davis
	enableChange();
383
	trapenableChange();
384 e49bf8fd Stephen Beaver
	hostresChange();
385
386 24b82516 Phil Davis
	function enableChange() {
387
		setRequired('pollport', $('#enable').prop('checked'));
388
		setRequired('rocommunity', $('#enable').prop('checked'));
389
	}
390
391
	function trapenableChange() {
392
		setRequired('trapserver', $('#trapenable').prop('checked'));
393
		setRequired('trapserverport', $('#trapenable').prop('checked'));
394
		setRequired('trapstring', $('#trapenable').prop('checked'));
395
	}
396
397 e49bf8fd Stephen Beaver
	function hostresChange() {
398 20db3e1a Phil Davis
		if ($('#hostres').prop('checked')) {
399 e49bf8fd Stephen Beaver
			$('#mibii').prop('checked', true);
400
			noMibii = true;
401
		} else {
402
			noMibii = false;
403
		}
404
	}
405
406 24b82516 Phil Davis
	$('#enable').change(function() {
407
		enableChange();
408
	});
409
410
	$('#trapenable').change(function() {
411
		trapenableChange();
412
	});
413
414 20db3e1a Phil Davis
	$('#hostres').change(function() {
415 e49bf8fd Stephen Beaver
		hostresChange();
416
	});
417
418 20db3e1a Phil Davis
	$('#mibii').change(function() {
419
		if (noMibii) {
420 e49bf8fd Stephen Beaver
			$('#mibii').prop('checked', 'true');
421
		}
422 a03c4756 sbeaver
	});
423 e49bf8fd Stephen Beaver
424 6e127720 Stephen Beaver
	$('[name=btntoggleall]').hide();
425 a03c4756 sbeaver
});
426
//]]>
427
</script>
428
429 c10cb196 Stephen Beaver
<?php include("foot.inc");