Project

General

Profile

Download (10.8 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-2018 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
if (!is_array($config['snmpd'])) {
37
	$config['snmpd'] = array();
38
	$config['snmpd']['rocommunity'] = "public";
39
	$config['snmpd']['pollport'] = "161";
40
}
41

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

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

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

    
80
if ($_POST) {
81

    
82
	unset($input_errors);
83
	$pconfig = $_POST;
84

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

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

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

    
105

    
106
	}
107

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

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

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

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

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

    
134

    
135

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

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

    
162
		write_config();
163

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

    
170
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

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

    
189
	unset($interface_addresses);
190

    
191
	return($iflist);
192
}
193

    
194
$pgtitle = array(gettext("Services"), gettext("SNMP"));
195
$shortcut_section = "snmp";
196

    
197
include("head.inc");
198

    
199
if ($input_errors) {
200
	print_input_errors($input_errors);
201
}
202

    
203
if ($changes_applied) {
204
	print_apply_result_box($retval);
205
}
206

    
207
$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
));
217

    
218
$form->add($section);
219

    
220
$section = new Form_Section('SNMP Daemon Settings');
221

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

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

    
252
$section = new Form_Section('SNMP Traps Enable');
253

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

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

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

    
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

    
296
$group = new Form_MultiCheckboxGroup('SNMP modules');
297

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

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

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

    
319
$group->add(new Form_MultiCheckbox(
320
	'hostres',
321
	null,
322
	'Host Resources',
323
	$pconfig['hostres']
324
));
325

    
326
$group->add(new Form_MultiCheckbox(
327
	'ucd',
328
	null,
329
	'UCD',
330
	$pconfig['ucd']
331
));
332

    
333
$group->add(new Form_MultiCheckbox(
334
	'regex',
335
	null,
336
	'Regex',
337
	$pconfig['regex']
338
));
339

    
340
$section->add($group);
341
$form->add($section);
342

    
343
$section = new Form_Section('Interface Binding');
344

    
345
$iflist = build_if_list($pconfig['bindip']);
346

    
347
$section->addInput(new Form_Select(
348
	'bindip',
349
	'Bind Interfaces',
350
	$iflist['selected'],
351
	$iflist['options'],
352
	true
353
));
354

    
355
$form->add($section);
356

    
357
print($form);
358
?>
359

    
360
<script type="text/javascript">
361
//<![CDATA[
362

    
363
// hostres requires mibii so we force that here
364
events.push(function() {
365

    
366
	noMibii = false;
367

    
368
	$('#junk').hide();
369
	enableChange();
370
	trapenableChange();
371
	hostresChange();
372

    
373
	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
	function hostresChange() {
385
		if ($('#hostres').prop('checked')) {
386
			$('#mibii').prop('checked', true);
387
			noMibii = true;
388
		} else {
389
			noMibii = false;
390
		}
391
	}
392

    
393
	$('#enable').change(function() {
394
		enableChange();
395
	});
396

    
397
	$('#trapenable').change(function() {
398
		trapenableChange();
399
	});
400

    
401
	$('#hostres').change(function() {
402
		hostresChange();
403
	});
404

    
405
	$('#mibii').change(function() {
406
		if (noMibii) {
407
			$('#mibii').prop('checked', 'true');
408
		}
409
	});
410

    
411
	$('[name=btntoggleall]').hide();
412
});
413
//]]>
414
</script>
415

    
416
<?php include("foot.inc");
(145-145/232)