Project

General

Profile

Download (9.96 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 00686fee pierrepomes
		if (strstr($_POST['syslocation'],"#")) $input_errors[] = gettext("Invalid character '#' in system location");
97 a7f5d4b9 sbeaver
		if (strstr($_POST['syscontact'],"#")) $input_errors[] = gettext("Invalid character '#' in system contact");
98 00686fee pierrepomes
		if (strstr($_POST['rocommunity'],"#")) $input_errors[] = gettext("Invalid character '#' in read community string");
99
100 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "rocommunity");
101 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Community"));
102 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
103 3805bfdd John Fleming
104
		$reqdfields = explode(" ", "pollport");
105 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Polling Port"));
106 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
107 5b237745 Scott Ullrich
	}
108
109 4f4d63d8 John Fleming
	if ($_POST['trapenable']) {
110 00686fee pierrepomes
		if (strstr($_POST['trapstring'],"#")) $input_errors[] = gettext("Invalid character '#' in SNMP trap string");
111
112 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserver");
113 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server"));
114 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
115 3805bfdd John Fleming
116 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserverport");
117 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap server port"));
118 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
119 3805bfdd John Fleming
120 8c3c9dc2 John Fleming
		$reqdfields = explode(" ", "trapstring");
121 3d9bee96 Rafael Lucas
		$reqdfieldsn = array(gettext("Trap string"));
122 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
123 4f4d63d8 John Fleming
	}
124
125
/* disabled until some docs show up on what this does.
126
	if ($_POST['rwenable']) {
127 a7f5d4b9 sbeaver
			   $reqdfields = explode(" ", "rwcommunity");
128
			   $reqdfieldsn = explode(",", "Write community string");
129
			   do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
130 4f4d63d8 John Fleming
	}
131
*/
132
133 5b237745 Scott Ullrich
	if (!$input_errors) {
134 4f4d63d8 John Fleming
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
135 3805bfdd John Fleming
		$config['snmpd']['pollport'] = $_POST['pollport'];
136 a7f5d4b9 sbeaver
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
137 5b237745 Scott Ullrich
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
138
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
139 4f4d63d8 John Fleming
		/* disabled until some docs show up on what this does.
140
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
141
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
142
		*/
143
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
144
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
145
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
146 8c3c9dc2 John Fleming
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
147 a7f5d4b9 sbeaver
148 3805bfdd John Fleming
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
149
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
150
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
151 95fb49e8 Seth Mos
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
152
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
153 671914b2 jim-p
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
154
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
155 c82b2c3f jim-p
		$config['snmpd']['bindip'] = $_POST['bindip'];
156 a7f5d4b9 sbeaver
157 5b237745 Scott Ullrich
		write_config();
158 a7f5d4b9 sbeaver
159 5b237745 Scott Ullrich
		$retval = 0;
160 920b3bb0 Scott Ullrich
		$retval = services_snmpd_configure();
161 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
162
	}
163
}
164 4df96eff Scott Ullrich
165 a03c4756 sbeaver
function build_iplist() {
166
	$listenips = get_possible_listen_ips();
167
	$iplist = array();
168
	$iplist[''] = 'All';
169
170
	foreach ($listenips as $lip => $ldescr) {
171
		$iplist[$lip] = $ldescr;
172
	}
173
	unset($listenips);
174
175
	return($iplist);
176
}
177
178 a50337c3 Colin Fleming
$closehead = false;
179 3d9bee96 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("SNMP"));
180 d71fc5d3 jim-p
$shortcut_section = "snmp";
181 4df96eff Scott Ullrich
182 a03c4756 sbeaver
include("head.inc");
183
184 a7f5d4b9 sbeaver
if ($input_errors)
185
	print_input_errors($input_errors);
186 7bc5c543 jim-p
187 a7f5d4b9 sbeaver
if ($savemsg)
188
	print_info_box($savemsg);
189 4f4d63d8 John Fleming
190 a7f5d4b9 sbeaver
require('classes/Form.class.php');
191
192
$form = new Form();
193
194
$section = new Form_Section('SNMP Daemon');
195
196
$section->addInput(new Form_Checkbox(
197
	'enable',
198
	'Enable',
199
	'Enable the SNMP Daemon and its controls',
200
	$pconfig['enable']
201 3150f4a4 Sjon Hortensius
));
202 a7f5d4b9 sbeaver
203
$form->add($section);
204
205
$section = new Form_Section('SNMP Daemon settings');
206 a03c4756 sbeaver
207 a7f5d4b9 sbeaver
$section->addInput(new Form_Input(
208
	'pollport',
209
	'Polling Port',
210
	'text',
211
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
212
))->setHelp('Enter the port to accept polling events on (default 161)');
213
214
$section->addInput(new Form_Input(
215
	'syslocation',
216
	'System Location',
217
	'text',
218
	$pconfig['syslocation']
219
));
220
221
$section->addInput(new Form_Input(
222
	'syscontact',
223
	'System Contact',
224
	'text',
225
	$pconfig['syscontact']
226
));
227
228
$section->addInput(new Form_Input(
229
	'rocommunity',
230
	'Read Community String',
231
	'text',
232
	$pconfig['rocommunity']
233
))->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.');
234
235 a03c4756 sbeaver
$form->add($section);
236 a7f5d4b9 sbeaver
237
$section = new Form_Section('SNMP Traps Enable');
238 a03c4756 sbeaver
239 a7f5d4b9 sbeaver
$section->addInput(new Form_Checkbox(
240
	'trapenable',
241
	'Enable',
242
	'Enable the SNMP Trap and its controls',
243
	$pconfig['trapenable']
244
))->toggles('.toggle-traps');
245
246
$form->add($section);
247
248
$section = new Form_Section('SNMP Trap settings');
249 a03c4756 sbeaver
250
if($pconfig['trapenable'])
251
	$section->addClass('toggle-traps', 'in');
252
else
253
	$section->addClass('toggle-traps', 'collapse');
254 a7f5d4b9 sbeaver
255
$section->addInput(new Form_Input(
256
	'trapserver',
257
	'Trap server',
258
	'text',
259
	$pconfig['trapserver']
260 a03c4756 sbeaver
))->setHelp('Enter the trap server name');
261 a7f5d4b9 sbeaver
262
$section->addInput(new Form_Input(
263
	'trapserverport',
264
	'Trap Server Port',
265
	'text',
266
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
267
))->setHelp('Enter the port to send the traps to (default 162)');
268
269
$section->addInput(new Form_Input(
270
	'trapstring',
271
	'SNMP Trap String',
272
	'text',
273
	$pconfig['trapstring']
274
));
275
276
$form->add($section);
277
278
$section = new Form_Section('SNMP Modules');
279 a03c4756 sbeaver
280 3150f4a4 Sjon Hortensius
$group = new Form_MultiCheckboxGroup('SNMP modules');
281 a7f5d4b9 sbeaver
282 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
283 a7f5d4b9 sbeaver
	'mibii',
284 a03c4756 sbeaver
	null,
285
	'MibII',
286 a7f5d4b9 sbeaver
	$pconfig['mibii']
287
));
288
289 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
290 a7f5d4b9 sbeaver
	'netgraph',
291 a03c4756 sbeaver
	null,
292 a7f5d4b9 sbeaver
	'Netgraph',
293
	$pconfig['netgraph']
294
));
295
296 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
297 a7f5d4b9 sbeaver
	'pf',
298 a03c4756 sbeaver
	null,
299 a7f5d4b9 sbeaver
	'PF',
300
	$pconfig['pf']
301
));
302
303 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
304 a7f5d4b9 sbeaver
	'hostres',
305 a03c4756 sbeaver
	null,
306 a7f5d4b9 sbeaver
	'Host Resources',
307
	$pconfig['hostres']
308
));
309
310 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
311 a7f5d4b9 sbeaver
	'ucd',
312 a03c4756 sbeaver
	null,
313 a7f5d4b9 sbeaver
	'UCD',
314
	$pconfig['ucd']
315
));
316
317 3150f4a4 Sjon Hortensius
$group->add(new Form_MultiCheckbox(
318 a7f5d4b9 sbeaver
	'regex',
319 a03c4756 sbeaver
	null,
320 a7f5d4b9 sbeaver
	'Regex',
321
	$pconfig['regex']
322
));
323
324
$section->add($group);
325
$form->add($section);
326
327
$section = new Form_Section('Interface Binding');
328
329
$section->addInput(new Form_Select(
330
	'bindip',
331
	'Bind Interface',
332
	$pconfig['bindip'],
333 a03c4756 sbeaver
	build_iplist()
334 a7f5d4b9 sbeaver
));
335
336
$form->add($section);
337
338
print($form);
339 a03c4756 sbeaver
?>
340
341
<script type="text/javascript">
342
//<![CDATA[
343
344
// hostres requires mibii so we force that here
345
events.push(function(){
346
	$('#hostres').change(function(){
347
		if($('#hostres').is(':checked'))
348
			$('#mibii').attr('checked', 'checked');
349
	});
350
});
351
//]]>
352
</script>
353
354 3150f4a4 Sjon Hortensius
<?php include("foot.inc");