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
$closehead = false;
211
$pgtitle = array(gettext("Services"), gettext("SNMP"));
212
$shortcut_section = "snmp";
213

    
214
include("head.inc");
215

    
216
if ($input_errors)
217
	print_input_errors($input_errors);
218

    
219
if ($savemsg)
220
	print_info_box($savemsg);
221

    
222
$form = new Form();
223

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
306
$form->add($section);
307

    
308
$section = new Form_Section('SNMP Modules');
309

    
310
$group = new Form_MultiCheckboxGroup('SNMP modules');
311

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

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

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

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

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

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

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

    
357
$section = new Form_Section('Interface Binding');
358

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

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

    
368
print($form);
369
?>
370

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

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

    
377
	noMibii = false;
378

    
379
	$('#junk').hide();
380
	hostresChange();
381

    
382
	function hostresChange() {
383
		if($('#hostres').prop('checked')) {
384
			$('#mibii').prop('checked', true);
385
			noMibii = true;
386
		} else {
387
			noMibii = false;
388
		}
389
	}
390

    
391
	$('#hostres').change(function(){
392
		hostresChange();
393
	});
394

    
395

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

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

    
407
<?php include("foot.inc");
(139-139/228)