Project

General

Profile

Download (9.66 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 5b237745 Scott Ullrich
36
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 3d594a3f jim-p
$pconfig['bindip'] = $config['snmpd']['bindip'];
75 3805bfdd John Fleming
76 5b237745 Scott Ullrich
if ($_POST) {
77
78
	unset($input_errors);
79
	$pconfig = $_POST;
80
81
	/* input validation */
82
	if ($_POST['enable']) {
83 56463a6c Phil Davis
		if (strstr($_POST['syslocation'], "#")) {
84
			$input_errors[] = gettext("Invalid character '#' in system location");
85
		}
86
		if (strstr($_POST['syscontact'], "#")) {
87
			$input_errors[] = gettext("Invalid character '#' in system contact");
88
		}
89
		if (strstr($_POST['rocommunity'], "#")) {
90
			$input_errors[] = gettext("Invalid character '#' in read community string");
91
		}
92 00686fee pierrepomes
93 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "rocommunity");
94 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Community"));
95 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
96 3805bfdd John Fleming
97
		$reqdfields = explode(" ", "pollport");
98 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Polling Port"));
99 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
100 56463a6c Phil Davis
101
102 5b237745 Scott Ullrich
	}
103
104 4f4d63d8 John Fleming
	if ($_POST['trapenable']) {
105 56463a6c Phil Davis
		if (strstr($_POST['trapstring'], "#")) {
106
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
107
		}
108 00686fee pierrepomes
109 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserver");
110 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server"));
111 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
112 3805bfdd John Fleming
113 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserverport");
114 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server port"));
115 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
116 3805bfdd John Fleming
117 8c3c9dc2 John Fleming
		$reqdfields = explode(" ", "trapstring");
118 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap string"));
119 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
120 4f4d63d8 John Fleming
	}
121
122
/* disabled until some docs show up on what this does.
123
	if ($_POST['rwenable']) {
124 56463a6c Phil Davis
		$reqdfields = explode(" ", "rwcommunity");
125
		$reqdfieldsn = explode(",", "Write community string");
126
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
127 4f4d63d8 John Fleming
	}
128
*/
129
130 56463a6c Phil Davis
131 4f4d63d8 John Fleming
132 5b237745 Scott Ullrich
	if (!$input_errors) {
133 4f4d63d8 John Fleming
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
134 3805bfdd John Fleming
		$config['snmpd']['pollport'] = $_POST['pollport'];
135 a7f5d4b9 sbeaver
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
136 5b237745 Scott Ullrich
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
137
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
138 4f4d63d8 John Fleming
		/* disabled until some docs show up on what this does.
139
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
140
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
141
		*/
142
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
143
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
144
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
145 8c3c9dc2 John Fleming
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
146 a7f5d4b9 sbeaver
147 3805bfdd John Fleming
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
148
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
149
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
150 95fb49e8 Seth Mos
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
151
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
152 671914b2 jim-p
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
153
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
154 c82b2c3f jim-p
		$config['snmpd']['bindip'] = $_POST['bindip'];
155 a7f5d4b9 sbeaver
156 5b237745 Scott Ullrich
		write_config();
157 a7f5d4b9 sbeaver
158 5b237745 Scott Ullrich
		$retval = 0;
159 920b3bb0 Scott Ullrich
		$retval = services_snmpd_configure();
160 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
161
	}
162
}
163 4df96eff Scott Ullrich
164 a03c4756 sbeaver
function build_iplist() {
165
	$listenips = get_possible_listen_ips();
166
	$iplist = array();
167
	$iplist[''] = 'All';
168
169
	foreach ($listenips as $lip => $ldescr) {
170
		$iplist[$lip] = $ldescr;
171
	}
172
	unset($listenips);
173
174
	return($iplist);
175
}
176
177 56463a6c Phil Davis
$pgtitle = array(gettext("Services"), gettext("SNMP"));
178 d71fc5d3 jim-p
$shortcut_section = "snmp";
179 4df96eff Scott Ullrich
180 a03c4756 sbeaver
include("head.inc");
181
182 20db3e1a Phil Davis
if ($input_errors) {
183 a7f5d4b9 sbeaver
	print_input_errors($input_errors);
184 20db3e1a Phil Davis
}
185 7bc5c543 jim-p
186 20db3e1a Phil Davis
if ($savemsg) {
187 f78bbe16 Phil Davis
	print_info_box($savemsg, 'success');
188 20db3e1a Phil Davis
}
189 4f4d63d8 John Fleming
190 a7f5d4b9 sbeaver
$form = new Form();
191
192
$section = new Form_Section('SNMP Daemon');
193
194
$section->addInput(new Form_Checkbox(
195
	'enable',
196
	'Enable',
197
	'Enable the SNMP Daemon and its controls',
198
	$pconfig['enable']
199 3150f4a4 Sjon Hortensius
));
200 a7f5d4b9 sbeaver
201
$form->add($section);
202
203 5f88f964 k-paulius
$section = new Form_Section('SNMP Daemon Settings');
204 a03c4756 sbeaver
205 a7f5d4b9 sbeaver
$section->addInput(new Form_Input(
206
	'pollport',
207
	'Polling Port',
208
	'text',
209
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
210 e78ecb96 NOYB
))->setHelp('Enter the port to accept polling events on (default 161).');
211 a7f5d4b9 sbeaver
212
$section->addInput(new Form_Input(
213
	'syslocation',
214
	'System Location',
215
	'text',
216
	$pconfig['syslocation']
217
));
218
219
$section->addInput(new Form_Input(
220
	'syscontact',
221
	'System Contact',
222
	'text',
223
	$pconfig['syscontact']
224
));
225
226
$section->addInput(new Form_Input(
227
	'rocommunity',
228
	'Read Community String',
229
	'text',
230
	$pconfig['rocommunity']
231
))->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.');
232
233 a03c4756 sbeaver
$form->add($section);
234 a7f5d4b9 sbeaver
235
$section = new Form_Section('SNMP Traps Enable');
236 a03c4756 sbeaver
237 a7f5d4b9 sbeaver
$section->addInput(new Form_Checkbox(
238
	'trapenable',
239
	'Enable',
240
	'Enable the SNMP Trap and its controls',
241
	$pconfig['trapenable']
242
))->toggles('.toggle-traps');
243
244
$form->add($section);
245
246 5f88f964 k-paulius
$section = new Form_Section('SNMP Trap Settings');
247 a03c4756 sbeaver
248 20db3e1a Phil Davis
if ($pconfig['trapenable']) {
249 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'in');
250 20db3e1a Phil Davis
} else {
251 a03c4756 sbeaver
	$section->addClass('toggle-traps', 'collapse');
252 20db3e1a Phil Davis
}
253 a7f5d4b9 sbeaver
254
$section->addInput(new Form_Input(
255
	'trapserver',
256
	'Trap server',
257
	'text',
258
	$pconfig['trapserver']
259 a03c4756 sbeaver
))->setHelp('Enter the trap server name');
260 a7f5d4b9 sbeaver
261
$section->addInput(new Form_Input(
262
	'trapserverport',
263
	'Trap Server Port',
264
	'text',
265
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
266
))->setHelp('Enter the port to send the traps to (default 162)');
267
268
$section->addInput(new Form_Input(
269
	'trapstring',
270
	'SNMP Trap String',
271
	'text',
272
	$pconfig['trapstring']
273
));
274
275
$form->add($section);
276
277
$section = new Form_Section('SNMP Modules');
278 a03c4756 sbeaver
279 3150f4a4 Sjon Hortensius
$group = new Form_MultiCheckboxGroup('SNMP modules');
280 a7f5d4b9 sbeaver
281 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
282 a7f5d4b9 sbeaver
	'mibii',
283 a03c4756 sbeaver
	null,
284
	'MibII',
285 a7f5d4b9 sbeaver
	$pconfig['mibii']
286
));
287
288 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
289 a7f5d4b9 sbeaver
	'netgraph',
290 a03c4756 sbeaver
	null,
291 a7f5d4b9 sbeaver
	'Netgraph',
292
	$pconfig['netgraph']
293
));
294
295 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
296 a7f5d4b9 sbeaver
	'pf',
297 a03c4756 sbeaver
	null,
298 a7f5d4b9 sbeaver
	'PF',
299
	$pconfig['pf']
300
));
301
302 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
303 a7f5d4b9 sbeaver
	'hostres',
304 a03c4756 sbeaver
	null,
305 a7f5d4b9 sbeaver
	'Host Resources',
306
	$pconfig['hostres']
307
));
308
309 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
310 a7f5d4b9 sbeaver
	'ucd',
311 a03c4756 sbeaver
	null,
312 a7f5d4b9 sbeaver
	'UCD',
313
	$pconfig['ucd']
314
));
315
316 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
317 a7f5d4b9 sbeaver
	'regex',
318 a03c4756 sbeaver
	null,
319 a7f5d4b9 sbeaver
	'Regex',
320
	$pconfig['regex']
321
));
322
323
$section->add($group);
324
$form->add($section);
325
326
$section = new Form_Section('Interface Binding');
327
328
$section->addInput(new Form_Select(
329
	'bindip',
330
	'Bind Interface',
331
	$pconfig['bindip'],
332 a03c4756 sbeaver
	build_iplist()
333 a7f5d4b9 sbeaver
));
334
335
$form->add($section);
336
337
print($form);
338 a03c4756 sbeaver
?>
339
340
<script type="text/javascript">
341
//<![CDATA[
342
343
// hostres requires mibii so we force that here
344 20db3e1a Phil Davis
events.push(function() {
345 e49bf8fd Stephen Beaver
346
	noMibii = false;
347
348
	$('#junk').hide();
349
	hostresChange();
350
351
	function hostresChange() {
352 20db3e1a Phil Davis
		if ($('#hostres').prop('checked')) {
353 e49bf8fd Stephen Beaver
			$('#mibii').prop('checked', true);
354
			noMibii = true;
355
		} else {
356
			noMibii = false;
357
		}
358
	}
359
360 20db3e1a Phil Davis
	$('#hostres').change(function() {
361 e49bf8fd Stephen Beaver
		hostresChange();
362
	});
363
364
365 20db3e1a Phil Davis
	$('#mibii').change(function() {
366
		if (noMibii) {
367 e49bf8fd Stephen Beaver
			$('#mibii').prop('checked', 'true');
368
		}
369 a03c4756 sbeaver
	});
370 e49bf8fd Stephen Beaver
371 6e127720 Stephen Beaver
	$('[name=btntoggleall]').hide();
372 a03c4756 sbeaver
});
373
//]]>
374
</script>
375
376 c10cb196 Stephen Beaver
<?php include("foot.inc");