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

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

    
65
require_once("guiconfig.inc");
66
require_once("functions.inc");
67

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

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

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

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

    
108
if ($_POST) {
109

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

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

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

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

    
133

    
134
	}
135

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

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

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

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

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

    
162

    
163

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

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

    
188
		write_config();
189

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

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

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

    
206
	return($iplist);
207
}
208

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

    
212
include("head.inc");
213

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

    
218
if ($savemsg) {
219
	print_info_box($savemsg, 'success');
220
}
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
360
$section->addInput(new Form_Select(
361
	'bindip',
362
	'Bind Interface',
363
	$pconfig['bindip'],
364
	build_iplist()
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
	hostresChange();
382

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

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

    
396

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

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

    
408
<?php include("foot.inc");
(141-141/227)