Project

General

Profile

Download (11.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_snmp.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * 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
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * 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
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-services-snmp
28
##|*NAME=Services: SNMP
29
##|*DESCR=Allow access to the 'Services: SNMP' page.
30
##|*MATCH=services_snmp.php*
31
##|-PRIV
32

    
33
require_once("guiconfig.inc");
34
require_once("functions.inc");
35

    
36
$specplatform = system_identify_specific_platform();
37

    
38
if (!is_array($config['snmpd'])) {
39
	$config['snmpd'] = array();
40
	$config['snmpd']['rocommunity'] = "public";
41
	$config['snmpd']['pollport'] = "161";
42
}
43

    
44
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
	$config['snmpd']['modules']['hostres'] = true;
50
	$config['snmpd']['modules']['bridge'] = true;
51
	$config['snmpd']['modules']['ucd'] = true;
52
	$config['snmpd']['modules']['regex'] = true;
53
}
54

    
55
$pconfig['enable'] = isset($config['snmpd']['enable']);
56
$pconfig['pollport'] = $config['snmpd']['pollport'];
57
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
58
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
59
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
60
/* 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
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
68

    
69
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
70
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
71
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
72
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
73
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
74
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
75
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
76
if (empty($config['snmpd']['bindip'])) {
77
	$pconfig['bindip'] = array();
78
} else {
79
	$pconfig['bindip'] = explode(",", $config['snmpd']['bindip']);
80
}
81

    
82
if ($_POST) {
83

    
84
	unset($input_errors);
85
	$pconfig = $_POST;
86

    
87
	/* input validation */
88
	if ($_POST['enable']) {
89
		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

    
99
		$reqdfields = explode(" ", "rocommunity");
100
		$reqdfieldsn = array(gettext("Community"));
101
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
102

    
103
		$reqdfields = explode(" ", "pollport");
104
		$reqdfieldsn = array(gettext("Polling Port"));
105
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
106

    
107

    
108
	}
109

    
110
	if ($_POST['trapenable']) {
111
		if (strstr($_POST['trapstring'], "#")) {
112
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
113
		}
114

    
115
		$reqdfields = explode(" ", "trapserver");
116
		$reqdfieldsn = array(gettext("Trap server"));
117
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
118

    
119
		$reqdfields = explode(" ", "trapserverport");
120
		$reqdfieldsn = array(gettext("Trap server port"));
121
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
122

    
123
		$reqdfields = explode(" ", "trapstring");
124
		$reqdfieldsn = array(gettext("Trap string"));
125
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
126
	}
127

    
128
/* disabled until some docs show up on what this does.
129
	if ($_POST['rwenable']) {
130
		$reqdfields = explode(" ", "rwcommunity");
131
		$reqdfieldsn = explode(",", "Write community string");
132
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
133
	}
134
*/
135

    
136

    
137

    
138
	if (!$input_errors) {
139
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
140
		$config['snmpd']['pollport'] = $_POST['pollport'];
141
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
142
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
143
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
144
		/* 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
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
152

    
153
		$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
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
157
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
158
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
159
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
160
		if (is_array($_POST['bindip']) && !empty($_POST['bindip'])) {
161
			$config['snmpd']['bindip'] = implode(",", $_POST['bindip']);
162
		}
163

    
164
		write_config();
165

    
166
		$changes_applied = true;
167
		$retval = 0;
168
		$retval |= services_snmpd_configure();
169
	}
170
}
171

    
172
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

    
186
		if ($selectedifs && in_array($laddr, $selectedifs)) {
187
			array_push($iflist['selected'], $laddr);
188
		}
189
	}
190

    
191
	unset($interface_addresses);
192

    
193
	return($iflist);
194
}
195

    
196
$pgtitle = array(gettext("Services"), gettext("SNMP"));
197
$shortcut_section = "snmp";
198

    
199
include("head.inc");
200

    
201
if ($input_errors) {
202
	print_input_errors($input_errors);
203
}
204

    
205
if ($changes_applied) {
206
	print_apply_result_box($retval);
207
}
208

    
209
$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
));
219

    
220
$form->add($section);
221

    
222
$section = new Form_Section('SNMP Daemon Settings');
223

    
224
$section->addInput(new Form_Input(
225
	'pollport',
226
	'Polling Port',
227
	'text',
228
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
229
))->setHelp('Enter the port to accept polling events on (default 161).');
230

    
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
$form->add($section);
253

    
254
$section = new Form_Section('SNMP Traps Enable');
255

    
256
$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
$section = new Form_Section('SNMP Trap Settings');
266

    
267
if ($pconfig['trapenable']) {
268
	$section->addClass('toggle-traps', 'in');
269
} else {
270
	$section->addClass('toggle-traps', 'collapse');
271
}
272

    
273
$section->addInput(new Form_Input(
274
	'trapserver',
275
	'Trap server',
276
	'text',
277
	$pconfig['trapserver']
278
))->setHelp('Enter the trap server name');
279

    
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

    
298
$group = new Form_MultiCheckboxGroup('SNMP modules');
299

    
300
$group->add(new Form_MultiCheckbox(
301
	'mibii',
302
	null,
303
	'MibII',
304
	$pconfig['mibii']
305
));
306

    
307
$group->add(new Form_MultiCheckbox(
308
	'netgraph',
309
	null,
310
	'Netgraph',
311
	$pconfig['netgraph']
312
));
313

    
314
$group->add(new Form_MultiCheckbox(
315
	'pf',
316
	null,
317
	'PF',
318
	$pconfig['pf']
319
));
320

    
321
if (!(($specplatform['name'] == 'VMware') && (file_exists('/dev/cd0')))) {
322
	$group->add(new Form_MultiCheckbox(
323
		'hostres',
324
		null,
325
		'Host Resources',
326
		$pconfig['hostres']
327
	));
328
}
329

    
330
$group->add(new Form_MultiCheckbox(
331
	'ucd',
332
	null,
333
	'UCD',
334
	$pconfig['ucd']
335
));
336

    
337
$group->add(new Form_MultiCheckbox(
338
	'regex',
339
	null,
340
	'Regex',
341
	$pconfig['regex']
342
));
343

    
344
$section->add($group);
345
if ((($specplatform['name'] == 'VMware') && (file_exists('/dev/cd0')))) {
346
	$section->addInput(new Form_StaticText(
347
		NULL,
348
		NULL
349
	))->setHelp(sprint_info_box('The hostres module is not compatible with VMware virtual ' .
350
		    'machines configured with a virtual CD/DVD Drive.', 'warning', false));
351
}
352

    
353
$form->add($section);
354

    
355
$section = new Form_Section('Interface Binding');
356

    
357
$iflist = build_if_list($pconfig['bindip']);
358

    
359
$section->addInput(new Form_Select(
360
	'bindip',
361
	'Bind Interfaces',
362
	$iflist['selected'],
363
	$iflist['options'],
364
	true
365
));
366

    
367
$form->add($section);
368

    
369
print($form);
370
?>
371

    
372
<script type="text/javascript">
373
//<![CDATA[
374

    
375
// hostres requires mibii so we force that here
376
events.push(function() {
377

    
378
	noMibii = false;
379

    
380
	$('#junk').hide();
381
	enableChange();
382
	trapenableChange();
383
	hostresChange();
384

    
385
	function enableChange() {
386
		setRequired('pollport', $('#enable').prop('checked'));
387
		setRequired('rocommunity', $('#enable').prop('checked'));
388
	}
389

    
390
	function trapenableChange() {
391
		setRequired('trapserver', $('#trapenable').prop('checked'));
392
		setRequired('trapserverport', $('#trapenable').prop('checked'));
393
		setRequired('trapstring', $('#trapenable').prop('checked'));
394
	}
395

    
396
	function hostresChange() {
397
		if ($('#hostres').prop('checked')) {
398
			$('#mibii').prop('checked', true);
399
			noMibii = true;
400
		} else {
401
			noMibii = false;
402
		}
403
	}
404

    
405
	$('#enable').change(function() {
406
		enableChange();
407
	});
408

    
409
	$('#trapenable').change(function() {
410
		trapenableChange();
411
	});
412

    
413
	$('#hostres').change(function() {
414
		hostresChange();
415
	});
416

    
417
	$('#mibii').change(function() {
418
		if (noMibii) {
419
			$('#mibii').prop('checked', 'true');
420
		}
421
	});
422

    
423
	$('[name=btntoggleall]').hide();
424
});
425
//]]>
426
</script>
427

    
428
<?php include("foot.inc");
(137-137/223)