Project

General

Profile

Download (10 KB) Statistics
| Branch: | Tag: | Revision:
1 a7f5d4b9 sbeaver
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_snmp.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 a7f5d4b9 sbeaver
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 29aef6c4 Jim Thompson
10
	part of pfSense
11 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
12 29aef6c4 Jim Thompson
	All rights reserved.
13 a7f5d4b9 sbeaver
14 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16 a7f5d4b9 sbeaver
17 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19 a7f5d4b9 sbeaver
20 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23 a7f5d4b9 sbeaver
24 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35 1d333258 Scott Ullrich
/*
36 a7f5d4b9 sbeaver
	pfSense_MODULE: snmp
37 1d333258 Scott Ullrich
*/
38 5b237745 Scott Ullrich
39 6b07c15a Matthew Grooms
##|+PRIV
40
##|*IDENT=page-services-snmp
41
##|*NAME=Services: SNMP page
42
##|*DESCR=Allow access to the 'Services: SNMP' page.
43
##|*MATCH=services_snmp.php*
44
##|-PRIV
45
46 5b237745 Scott Ullrich
require("guiconfig.inc");
47 4e865673 Carlos Eduardo Ramos
require_once("functions.inc");
48 5b237745 Scott Ullrich
49
if (!is_array($config['snmpd'])) {
50
	$config['snmpd'] = array();
51
	$config['snmpd']['rocommunity'] = "public";
52 3805bfdd John Fleming
	$config['snmpd']['pollport'] = "161";
53 5b237745 Scott Ullrich
}
54
55 3805bfdd John Fleming
if (!is_array($config['snmpd']['modules'])) {
56
	$config['snmpd']['modules'] = array();
57
	$config['snmpd']['modules']['mibii'] = true;
58
	$config['snmpd']['modules']['netgraph'] = true;
59
	$config['snmpd']['modules']['pf'] = true;
60 95fb49e8 Seth Mos
	$config['snmpd']['modules']['hostres'] = true;
61
	$config['snmpd']['modules']['bridge'] = true;
62 671914b2 jim-p
	$config['snmpd']['modules']['ucd'] = true;
63
	$config['snmpd']['modules']['regex'] = true;
64 3805bfdd John Fleming
}
65 a7f5d4b9 sbeaver
66 4f4d63d8 John Fleming
$pconfig['enable'] = isset($config['snmpd']['enable']);
67 3805bfdd John Fleming
$pconfig['pollport'] = $config['snmpd']['pollport'];
68 5b237745 Scott Ullrich
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
69
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
70
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
71 4f4d63d8 John Fleming
/* disabled until some docs show up on what this does.
72
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
73
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
74
*/
75
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
76
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
77
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
78 8c3c9dc2 John Fleming
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
79 5b237745 Scott Ullrich
80 3805bfdd John Fleming
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
81
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
82
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
83 95fb49e8 Seth Mos
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
84
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
85 671914b2 jim-p
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
86
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
87 3d594a3f jim-p
$pconfig['bindip'] = $config['snmpd']['bindip'];
88 3805bfdd John Fleming
89 5b237745 Scott Ullrich
if ($_POST) {
90
91
	unset($input_errors);
92
	$pconfig = $_POST;
93
94
	/* input validation */
95
	if ($_POST['enable']) {
96 56463a6c Phil Davis
		if (strstr($_POST['syslocation'], "#")) {
97
			$input_errors[] = gettext("Invalid character '#' in system location");
98
		}
99
		if (strstr($_POST['syscontact'], "#")) {
100
			$input_errors[] = gettext("Invalid character '#' in system contact");
101
		}
102
		if (strstr($_POST['rocommunity'], "#")) {
103
			$input_errors[] = gettext("Invalid character '#' in read community string");
104
		}
105 00686fee pierrepomes
106 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "rocommunity");
107 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Community"));
108 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
109 3805bfdd John Fleming
110
		$reqdfields = explode(" ", "pollport");
111 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Polling Port"));
112 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
113 56463a6c Phil Davis
114
115 5b237745 Scott Ullrich
	}
116
117 4f4d63d8 John Fleming
	if ($_POST['trapenable']) {
118 56463a6c Phil Davis
		if (strstr($_POST['trapstring'], "#")) {
119
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
120
		}
121 00686fee pierrepomes
122 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserver");
123 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server"));
124 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
125 3805bfdd John Fleming
126 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserverport");
127 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server port"));
128 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
129 3805bfdd John Fleming
130 8c3c9dc2 John Fleming
		$reqdfields = explode(" ", "trapstring");
131 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap string"));
132 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
133 4f4d63d8 John Fleming
	}
134
135
/* disabled until some docs show up on what this does.
136
	if ($_POST['rwenable']) {
137 56463a6c Phil Davis
		$reqdfields = explode(" ", "rwcommunity");
138
		$reqdfieldsn = explode(",", "Write community string");
139
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
140 4f4d63d8 John Fleming
	}
141
*/
142
143 56463a6c Phil Davis
144 4f4d63d8 John Fleming
145 5b237745 Scott Ullrich
	if (!$input_errors) {
146 4f4d63d8 John Fleming
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
147 3805bfdd John Fleming
		$config['snmpd']['pollport'] = $_POST['pollport'];
148 a7f5d4b9 sbeaver
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
149 5b237745 Scott Ullrich
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
150
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
151 4f4d63d8 John Fleming
		/* disabled until some docs show up on what this does.
152
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
153
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
154
		*/
155
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
156
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
157
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
158 8c3c9dc2 John Fleming
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
159 a7f5d4b9 sbeaver
160 3805bfdd John Fleming
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
161
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
162
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
163 95fb49e8 Seth Mos
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
164
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
165 671914b2 jim-p
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
166
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
167 c82b2c3f jim-p
		$config['snmpd']['bindip'] = $_POST['bindip'];
168 a7f5d4b9 sbeaver
169 5b237745 Scott Ullrich
		write_config();
170 a7f5d4b9 sbeaver
171 5b237745 Scott Ullrich
		$retval = 0;
172 920b3bb0 Scott Ullrich
		$retval = services_snmpd_configure();
173 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
174
	}
175
}
176 4df96eff Scott Ullrich
177 a03c4756 sbeaver
function build_iplist() {
178
	$listenips = get_possible_listen_ips();
179
	$iplist = array();
180
	$iplist[''] = 'All';
181
182
	foreach ($listenips as $lip => $ldescr) {
183
		$iplist[$lip] = $ldescr;
184
	}
185
	unset($listenips);
186
187
	return($iplist);
188
}
189
190 a50337c3 Colin Fleming
$closehead = false;
191 56463a6c Phil Davis
$pgtitle = array(gettext("Services"), gettext("SNMP"));
192 d71fc5d3 jim-p
$shortcut_section = "snmp";
193 4df96eff Scott Ullrich
194 a03c4756 sbeaver
include("head.inc");
195
196 a7f5d4b9 sbeaver
if ($input_errors)
197
	print_input_errors($input_errors);
198 7bc5c543 jim-p
199 a7f5d4b9 sbeaver
if ($savemsg)
200
	print_info_box($savemsg);
201 4f4d63d8 John Fleming
202 ad2879b8 PiBa-NL
require_once('classes/Form.class.php');
203 a7f5d4b9 sbeaver
204
$form = new Form();
205
206
$section = new Form_Section('SNMP Daemon');
207
208
$section->addInput(new Form_Checkbox(
209
	'enable',
210
	'Enable',
211
	'Enable the SNMP Daemon and its controls',
212
	$pconfig['enable']
213 3150f4a4 Sjon Hortensius
));
214 a7f5d4b9 sbeaver
215
$form->add($section);
216
217
$section = new Form_Section('SNMP Daemon settings');
218 a03c4756 sbeaver
219 a7f5d4b9 sbeaver
$section->addInput(new Form_Input(
220
	'pollport',
221
	'Polling Port',
222
	'text',
223
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
224
))->setHelp('Enter the port to accept polling events on (default 161)');
225
226
$section->addInput(new Form_Input(
227
	'syslocation',
228
	'System Location',
229
	'text',
230
	$pconfig['syslocation']
231
));
232
233
$section->addInput(new Form_Input(
234
	'syscontact',
235
	'System Contact',
236
	'text',
237
	$pconfig['syscontact']
238
));
239
240
$section->addInput(new Form_Input(
241
	'rocommunity',
242
	'Read Community String',
243
	'text',
244
	$pconfig['rocommunity']
245
))->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.');
246
247 a03c4756 sbeaver
$form->add($section);
248 a7f5d4b9 sbeaver
249
$section = new Form_Section('SNMP Traps Enable');
250 a03c4756 sbeaver
251 a7f5d4b9 sbeaver
$section->addInput(new Form_Checkbox(
252
	'trapenable',
253
	'Enable',
254
	'Enable the SNMP Trap and its controls',
255
	$pconfig['trapenable']
256
))->toggles('.toggle-traps');
257
258
$form->add($section);
259
260
$section = new Form_Section('SNMP Trap settings');
261 a03c4756 sbeaver
262
if($pconfig['trapenable'])
263
	$section->addClass('toggle-traps', 'in');
264
else
265
	$section->addClass('toggle-traps', 'collapse');
266 a7f5d4b9 sbeaver
267
$section->addInput(new Form_Input(
268
	'trapserver',
269
	'Trap server',
270
	'text',
271
	$pconfig['trapserver']
272 a03c4756 sbeaver
))->setHelp('Enter the trap server name');
273 a7f5d4b9 sbeaver
274
$section->addInput(new Form_Input(
275
	'trapserverport',
276
	'Trap Server Port',
277
	'text',
278
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
279
))->setHelp('Enter the port to send the traps to (default 162)');
280
281
$section->addInput(new Form_Input(
282
	'trapstring',
283
	'SNMP Trap String',
284
	'text',
285
	$pconfig['trapstring']
286
));
287
288
$form->add($section);
289
290
$section = new Form_Section('SNMP Modules');
291 a03c4756 sbeaver
292 3150f4a4 Sjon Hortensius
$group = new Form_MultiCheckboxGroup('SNMP modules');
293 a7f5d4b9 sbeaver
294 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
295 a7f5d4b9 sbeaver
	'mibii',
296 a03c4756 sbeaver
	null,
297
	'MibII',
298 a7f5d4b9 sbeaver
	$pconfig['mibii']
299
));
300
301 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
302 a7f5d4b9 sbeaver
	'netgraph',
303 a03c4756 sbeaver
	null,
304 a7f5d4b9 sbeaver
	'Netgraph',
305
	$pconfig['netgraph']
306
));
307
308 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
309 a7f5d4b9 sbeaver
	'pf',
310 a03c4756 sbeaver
	null,
311 a7f5d4b9 sbeaver
	'PF',
312
	$pconfig['pf']
313
));
314
315 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
316 a7f5d4b9 sbeaver
	'hostres',
317 a03c4756 sbeaver
	null,
318 a7f5d4b9 sbeaver
	'Host Resources',
319
	$pconfig['hostres']
320
));
321
322 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
323 a7f5d4b9 sbeaver
	'ucd',
324 a03c4756 sbeaver
	null,
325 a7f5d4b9 sbeaver
	'UCD',
326
	$pconfig['ucd']
327
));
328
329 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
330 a7f5d4b9 sbeaver
	'regex',
331 a03c4756 sbeaver
	null,
332 a7f5d4b9 sbeaver
	'Regex',
333
	$pconfig['regex']
334
));
335
336
$section->add($group);
337
$form->add($section);
338
339
$section = new Form_Section('Interface Binding');
340
341
$section->addInput(new Form_Select(
342
	'bindip',
343
	'Bind Interface',
344
	$pconfig['bindip'],
345 a03c4756 sbeaver
	build_iplist()
346 a7f5d4b9 sbeaver
));
347
348
$form->add($section);
349
350
print($form);
351 a03c4756 sbeaver
?>
352
353
<script type="text/javascript">
354
//<![CDATA[
355
356
// hostres requires mibii so we force that here
357
events.push(function(){
358
	$('#hostres').change(function(){
359
		if($('#hostres').is(':checked'))
360
			$('#mibii').attr('checked', 'checked');
361
	});
362
});
363
//]]>
364
</script>
365
366 3150f4a4 Sjon Hortensius
<?php include("foot.inc");