Project

General

Profile

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