Project

General

Profile

Download (11.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	services_snmp.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58

    
59
##|+PRIV
60
##|*IDENT=page-services-snmp
61
##|*NAME=Services: SNMP
62
##|*DESCR=Allow access to the 'Services: SNMP' page.
63
##|*MATCH=services_snmp.php*
64
##|-PRIV
65

    
66
require("guiconfig.inc");
67
require_once("functions.inc");
68

    
69
if (!is_array($config['snmpd'])) {
70
	$config['snmpd'] = array();
71
	$config['snmpd']['rocommunity'] = "public";
72
	$config['snmpd']['pollport'] = "161";
73
}
74

    
75
if (!is_array($config['snmpd']['modules'])) {
76
	$config['snmpd']['modules'] = array();
77
	$config['snmpd']['modules']['mibii'] = true;
78
	$config['snmpd']['modules']['netgraph'] = true;
79
	$config['snmpd']['modules']['pf'] = true;
80
	$config['snmpd']['modules']['hostres'] = true;
81
	$config['snmpd']['modules']['bridge'] = true;
82
	$config['snmpd']['modules']['ucd'] = true;
83
	$config['snmpd']['modules']['regex'] = true;
84
}
85

    
86
$pconfig['enable'] = isset($config['snmpd']['enable']);
87
$pconfig['pollport'] = $config['snmpd']['pollport'];
88
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
89
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
90
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
91
/* disabled until some docs show up on what this does.
92
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
93
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
94
*/
95
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
96
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
97
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
98
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
99

    
100
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
101
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
102
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
103
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
104
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
105
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
106
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
107
$pconfig['bindip'] = $config['snmpd']['bindip'];
108

    
109
if ($_POST) {
110

    
111
	unset($input_errors);
112
	$pconfig = $_POST;
113

    
114
	/* input validation */
115
	if ($_POST['enable']) {
116
		if (strstr($_POST['syslocation'], "#")) {
117
			$input_errors[] = gettext("Invalid character '#' in system location");
118
		}
119
		if (strstr($_POST['syscontact'], "#")) {
120
			$input_errors[] = gettext("Invalid character '#' in system contact");
121
		}
122
		if (strstr($_POST['rocommunity'], "#")) {
123
			$input_errors[] = gettext("Invalid character '#' in read community string");
124
		}
125

    
126
		$reqdfields = explode(" ", "rocommunity");
127
		$reqdfieldsn = array(gettext("Community"));
128
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
129

    
130
		$reqdfields = explode(" ", "pollport");
131
		$reqdfieldsn = array(gettext("Polling Port"));
132
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
133

    
134

    
135
	}
136

    
137
	if ($_POST['trapenable']) {
138
		if (strstr($_POST['trapstring'], "#")) {
139
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
140
		}
141

    
142
		$reqdfields = explode(" ", "trapserver");
143
		$reqdfieldsn = array(gettext("Trap server"));
144
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
145

    
146
		$reqdfields = explode(" ", "trapserverport");
147
		$reqdfieldsn = array(gettext("Trap server port"));
148
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
149

    
150
		$reqdfields = explode(" ", "trapstring");
151
		$reqdfieldsn = array(gettext("Trap string"));
152
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
153
	}
154

    
155
/* disabled until some docs show up on what this does.
156
	if ($_POST['rwenable']) {
157
		$reqdfields = explode(" ", "rwcommunity");
158
		$reqdfieldsn = explode(",", "Write community string");
159
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
160
	}
161
*/
162

    
163

    
164

    
165
	if (!$input_errors) {
166
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
167
		$config['snmpd']['pollport'] = $_POST['pollport'];
168
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
169
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
170
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
171
		/* disabled until some docs show up on what this does.
172
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
173
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
174
		*/
175
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
176
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
177
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
178
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
179

    
180
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
181
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
182
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
183
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
184
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
185
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
186
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
187
		$config['snmpd']['bindip'] = $_POST['bindip'];
188

    
189
		write_config();
190

    
191
		$retval = 0;
192
		$retval = services_snmpd_configure();
193
		$savemsg = get_std_save_message($retval);
194
	}
195
}
196

    
197
function build_iplist() {
198
	$listenips = get_possible_listen_ips();
199
	$iplist = array();
200
	$iplist[''] = 'All';
201

    
202
	foreach ($listenips as $lip => $ldescr) {
203
		$iplist[$lip] = $ldescr;
204
	}
205
	unset($listenips);
206

    
207
	return($iplist);
208
}
209

    
210
$pgtitle = array(gettext("Services"), gettext("SNMP"));
211
$shortcut_section = "snmp";
212

    
213
include("head.inc");
214

    
215
if ($input_errors) {
216
	print_input_errors($input_errors);
217
}
218

    
219
if ($savemsg) {
220
	print_info_box($savemsg);
221
}
222

    
223
$form = new Form();
224

    
225
$section = new Form_Section('SNMP Daemon');
226

    
227
$section->addInput(new Form_Checkbox(
228
	'enable',
229
	'Enable',
230
	'Enable the SNMP Daemon and its controls',
231
	$pconfig['enable']
232
));
233

    
234
$form->add($section);
235

    
236
$section = new Form_Section('SNMP Daemon settings');
237

    
238
$section->addInput(new Form_Input(
239
	'pollport',
240
	'Polling Port',
241
	'text',
242
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
243
))->setHelp('Enter the port to accept polling events on (default 161)');
244

    
245
$section->addInput(new Form_Input(
246
	'syslocation',
247
	'System Location',
248
	'text',
249
	$pconfig['syslocation']
250
));
251

    
252
$section->addInput(new Form_Input(
253
	'syscontact',
254
	'System Contact',
255
	'text',
256
	$pconfig['syscontact']
257
));
258

    
259
$section->addInput(new Form_Input(
260
	'rocommunity',
261
	'Read Community String',
262
	'text',
263
	$pconfig['rocommunity']
264
))->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.');
265

    
266
$form->add($section);
267

    
268
$section = new Form_Section('SNMP Traps Enable');
269

    
270
$section->addInput(new Form_Checkbox(
271
	'trapenable',
272
	'Enable',
273
	'Enable the SNMP Trap and its controls',
274
	$pconfig['trapenable']
275
))->toggles('.toggle-traps');
276

    
277
$form->add($section);
278

    
279
$section = new Form_Section('SNMP Trap settings');
280

    
281
if ($pconfig['trapenable']) {
282
	$section->addClass('toggle-traps', 'in');
283
} else {
284
	$section->addClass('toggle-traps', 'collapse');
285
}
286

    
287
$section->addInput(new Form_Input(
288
	'trapserver',
289
	'Trap server',
290
	'text',
291
	$pconfig['trapserver']
292
))->setHelp('Enter the trap server name');
293

    
294
$section->addInput(new Form_Input(
295
	'trapserverport',
296
	'Trap Server Port',
297
	'text',
298
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
299
))->setHelp('Enter the port to send the traps to (default 162)');
300

    
301
$section->addInput(new Form_Input(
302
	'trapstring',
303
	'SNMP Trap String',
304
	'text',
305
	$pconfig['trapstring']
306
));
307

    
308
$form->add($section);
309

    
310
$section = new Form_Section('SNMP Modules');
311

    
312
$group = new Form_MultiCheckboxGroup('SNMP modules');
313

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

    
321
$group->add(new Form_MultiCheckbox(
322
	'netgraph',
323
	null,
324
	'Netgraph',
325
	$pconfig['netgraph']
326
));
327

    
328
$group->add(new Form_MultiCheckbox(
329
	'pf',
330
	null,
331
	'PF',
332
	$pconfig['pf']
333
));
334

    
335
$group->add(new Form_MultiCheckbox(
336
	'hostres',
337
	null,
338
	'Host Resources',
339
	$pconfig['hostres']
340
));
341

    
342
$group->add(new Form_MultiCheckbox(
343
	'ucd',
344
	null,
345
	'UCD',
346
	$pconfig['ucd']
347
));
348

    
349
$group->add(new Form_MultiCheckbox(
350
	'regex',
351
	null,
352
	'Regex',
353
	$pconfig['regex']
354
));
355

    
356
$section->add($group);
357
$form->add($section);
358

    
359
$section = new Form_Section('Interface Binding');
360

    
361
$section->addInput(new Form_Select(
362
	'bindip',
363
	'Bind Interface',
364
	$pconfig['bindip'],
365
	build_iplist()
366
));
367

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

    
370
print($form);
371
?>
372

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

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

    
379
	noMibii = false;
380

    
381
	$('#junk').hide();
382
	hostresChange();
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
	$('#hostres').change(function() {
394
		hostresChange();
395
	});
396

    
397

    
398
	$('#mibii').change(function() {
399
		if (noMibii) {
400
			$('#mibii').prop('checked', 'true');
401
		}
402
	});
403

    
404
	$('[name=btntoggleall]').hide();
405
});
406
//]]>
407
</script>
408

    
409
<?php include("foot.inc");
(139-139/229)