Project

General

Profile

Download (9.75 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_snmp.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	part of pfSense
11
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	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

    
24
	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
/*
36
	pfSense_MODULE: snmp
37
*/
38

    
39
##|+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
require("guiconfig.inc");
47
require_once("functions.inc");
48

    
49
if (!is_array($config['snmpd'])) {
50
	$config['snmpd'] = array();
51
	$config['snmpd']['rocommunity'] = "public";
52
	$config['snmpd']['pollport'] = "161";
53
}
54

    
55
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
	$config['snmpd']['modules']['hostres'] = true;
61
	$config['snmpd']['modules']['bridge'] = true;
62
	$config['snmpd']['modules']['ucd'] = true;
63
	$config['snmpd']['modules']['regex'] = true;
64
}
65

    
66
$pconfig['enable'] = isset($config['snmpd']['enable']);
67
$pconfig['pollport'] = $config['snmpd']['pollport'];
68
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
69
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
70
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
71
/* 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
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
79

    
80
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
81
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
82
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
83
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
84
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
85
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
86
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
87
$pconfig['bindip'] = $config['snmpd']['bindip'];
88

    
89
if ($_POST) {
90

    
91
	unset($input_errors);
92
	$pconfig = $_POST;
93

    
94
	/* input validation */
95
	if ($_POST['enable']) {
96
		if (strstr($_POST['syslocation'],"#")) $input_errors[] = gettext("Invalid character '#' in system location");
97
		if (strstr($_POST['syscontact'],"#")) $input_errors[] = gettext("Invalid character '#' in system contact");
98
		if (strstr($_POST['rocommunity'],"#")) $input_errors[] = gettext("Invalid character '#' in read community string");
99

    
100
		$reqdfields = explode(" ", "rocommunity");
101
		$reqdfieldsn = array(gettext("Community"));
102
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
103

    
104
		$reqdfields = explode(" ", "pollport");
105
		$reqdfieldsn = array(gettext("Polling Port"));
106
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
107

    
108

    
109
	}
110

    
111
	if ($_POST['trapenable']) {
112
		if (strstr($_POST['trapstring'],"#")) $input_errors[] = gettext("Invalid character '#' in SNMP trap string");
113

    
114
		$reqdfields = explode(" ", "trapserver");
115
		$reqdfieldsn = array(gettext("Trap server"));
116
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
117

    
118
		$reqdfields = explode(" ", "trapserverport");
119
		$reqdfieldsn = array(gettext("Trap server port"));
120
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
121

    
122
		$reqdfields = explode(" ", "trapstring");
123
		$reqdfieldsn = array(gettext("Trap string"));
124
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
125
	}
126

    
127

    
128
/* disabled until some docs show up on what this does.
129
	if ($_POST['rwenable']) {
130
			   $reqdfields = explode(" ", "rwcommunity");
131
			   $reqdfieldsn = explode(",", "Write community string");
132
			   do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
133
	}
134
*/
135

    
136

    
137

    
138
	if (!$input_errors) {
139
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
140
		$config['snmpd']['pollport'] = $_POST['pollport'];
141
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
142
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
143
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
144
		/* 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
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
152

    
153
		$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
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
157
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
158
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
159
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
160
		$config['snmpd']['bindip'] = $_POST['bindip'];
161

    
162
		write_config();
163

    
164
		$retval = 0;
165
		$retval = services_snmpd_configure();
166
		$savemsg = get_std_save_message($retval);
167
	}
168
}
169

    
170
$closehead = false;
171
$pgtitle = array(gettext("Services"),gettext("SNMP"));
172
$shortcut_section = "snmp";
173

    
174
if ($input_errors)
175
	print_input_errors($input_errors);
176

    
177
if ($savemsg)
178
	print_info_box($savemsg);
179

    
180
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
}
326
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");
(155-155/241)