Project

General

Profile

Download (9.96 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
	if ($_POST['trapenable']) {
110
		if (strstr($_POST['trapstring'],"#")) $input_errors[] = gettext("Invalid character '#' in SNMP trap string");
111

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

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

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

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

    
133
	if (!$input_errors) {
134
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
135
		$config['snmpd']['pollport'] = $_POST['pollport'];
136
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
137
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
138
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
139
		/* 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
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
147

    
148
		$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
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
152
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
153
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
154
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
155
		$config['snmpd']['bindip'] = $_POST['bindip'];
156

    
157
		write_config();
158

    
159
		$retval = 0;
160
		$retval = services_snmpd_configure();
161
		$savemsg = get_std_save_message($retval);
162
	}
163
}
164

    
165
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
$closehead = false;
179
$pgtitle = array(gettext("Services"),gettext("SNMP"));
180
$shortcut_section = "snmp";
181

    
182
include("head.inc");
183

    
184
if ($input_errors)
185
	print_input_errors($input_errors);
186

    
187
if ($savemsg)
188
	print_info_box($savemsg);
189

    
190
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
));
202

    
203
$form->add($section);
204

    
205
$section = new Form_Section('SNMP Daemon settings');
206

    
207
$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
$form->add($section);
236

    
237
$section = new Form_Section('SNMP Traps Enable');
238

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

    
250
if($pconfig['trapenable'])
251
	$section->addClass('toggle-traps', 'in');
252
else
253
	$section->addClass('toggle-traps', 'collapse');
254

    
255
$section->addInput(new Form_Input(
256
	'trapserver',
257
	'Trap server',
258
	'text',
259
	$pconfig['trapserver']
260
))->setHelp('Enter the trap server name');
261

    
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

    
280
$group = new Form_MultiCheckboxGroup('SNMP modules');
281

    
282
$group->add(new Form_MultiCheckbox(
283
	'mibii',
284
	null,
285
	'MibII',
286
	$pconfig['mibii']
287
));
288

    
289
$group->add(new Form_MultiCheckbox(
290
	'netgraph',
291
	null,
292
	'Netgraph',
293
	$pconfig['netgraph']
294
));
295

    
296
$group->add(new Form_MultiCheckbox(
297
	'pf',
298
	null,
299
	'PF',
300
	$pconfig['pf']
301
));
302

    
303
$group->add(new Form_MultiCheckbox(
304
	'hostres',
305
	null,
306
	'Host Resources',
307
	$pconfig['hostres']
308
));
309

    
310
$group->add(new Form_MultiCheckbox(
311
	'ucd',
312
	null,
313
	'UCD',
314
	$pconfig['ucd']
315
));
316

    
317
$group->add(new Form_MultiCheckbox(
318
	'regex',
319
	null,
320
	'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
	build_iplist()
334
));
335

    
336
$form->add($section);
337

    
338
print($form);
339
?>
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
<?php include("foot.inc");
(155-155/241)