Project

General

Profile

Download (10 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'], "#")) {
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

    
106
		$reqdfields = explode(" ", "rocommunity");
107
		$reqdfieldsn = array(gettext("Community"));
108
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
109

    
110
		$reqdfields = explode(" ", "pollport");
111
		$reqdfieldsn = array(gettext("Polling Port"));
112
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
113

    
114

    
115
	}
116

    
117
	if ($_POST['trapenable']) {
118
		if (strstr($_POST['trapstring'], "#")) {
119
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
120
		}
121

    
122
		$reqdfields = explode(" ", "trapserver");
123
		$reqdfieldsn = array(gettext("Trap server"));
124
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
125

    
126
		$reqdfields = explode(" ", "trapserverport");
127
		$reqdfieldsn = array(gettext("Trap server port"));
128
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
129

    
130
		$reqdfields = explode(" ", "trapstring");
131
		$reqdfieldsn = array(gettext("Trap string"));
132
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
133
	}
134

    
135
/* disabled until some docs show up on what this does.
136
	if ($_POST['rwenable']) {
137
		$reqdfields = explode(" ", "rwcommunity");
138
		$reqdfieldsn = explode(",", "Write community string");
139
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
140
	}
141
*/
142

    
143

    
144

    
145
	if (!$input_errors) {
146
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
147
		$config['snmpd']['pollport'] = $_POST['pollport'];
148
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
149
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
150
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
151
		/* 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
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
159

    
160
		$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
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
164
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
165
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
166
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
167
		$config['snmpd']['bindip'] = $_POST['bindip'];
168

    
169
		write_config();
170

    
171
		$retval = 0;
172
		$retval = services_snmpd_configure();
173
		$savemsg = get_std_save_message($retval);
174
	}
175
}
176

    
177
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
$closehead = false;
191
$pgtitle = array(gettext("Services"), gettext("SNMP"));
192
$shortcut_section = "snmp";
193

    
194
include("head.inc");
195

    
196
if ($input_errors)
197
	print_input_errors($input_errors);
198

    
199
if ($savemsg)
200
	print_info_box($savemsg);
201

    
202
require_once('classes/Form.class.php');
203

    
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
));
214

    
215
$form->add($section);
216

    
217
$section = new Form_Section('SNMP Daemon settings');
218

    
219
$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
$form->add($section);
248

    
249
$section = new Form_Section('SNMP Traps Enable');
250

    
251
$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

    
262
if($pconfig['trapenable'])
263
	$section->addClass('toggle-traps', 'in');
264
else
265
	$section->addClass('toggle-traps', 'collapse');
266

    
267
$section->addInput(new Form_Input(
268
	'trapserver',
269
	'Trap server',
270
	'text',
271
	$pconfig['trapserver']
272
))->setHelp('Enter the trap server name');
273

    
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

    
292
$group = new Form_MultiCheckboxGroup('SNMP modules');
293

    
294
$group->add(new Form_MultiCheckbox(
295
	'mibii',
296
	null,
297
	'MibII',
298
	$pconfig['mibii']
299
));
300

    
301
$group->add(new Form_MultiCheckbox(
302
	'netgraph',
303
	null,
304
	'Netgraph',
305
	$pconfig['netgraph']
306
));
307

    
308
$group->add(new Form_MultiCheckbox(
309
	'pf',
310
	null,
311
	'PF',
312
	$pconfig['pf']
313
));
314

    
315
$group->add(new Form_MultiCheckbox(
316
	'hostres',
317
	null,
318
	'Host Resources',
319
	$pconfig['hostres']
320
));
321

    
322
$group->add(new Form_MultiCheckbox(
323
	'ucd',
324
	null,
325
	'UCD',
326
	$pconfig['ucd']
327
));
328

    
329
$group->add(new Form_MultiCheckbox(
330
	'regex',
331
	null,
332
	'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
	build_iplist()
346
));
347

    
348
$form->add($section);
349

    
350
print($form);
351
?>
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
<?php include("foot.inc");
(152-152/235)