Project

General

Profile

Download (9.65 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_snmp.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-services-snmp
28
##|*NAME=Services: SNMP
29
##|*DESCR=Allow access to the 'Services: SNMP' page.
30
##|*MATCH=services_snmp.php*
31
##|-PRIV
32

    
33
require_once("guiconfig.inc");
34
require_once("functions.inc");
35

    
36
if (!is_array($config['snmpd'])) {
37
	$config['snmpd'] = array();
38
	$config['snmpd']['rocommunity'] = "public";
39
	$config['snmpd']['pollport'] = "161";
40
}
41

    
42
if (!is_array($config['snmpd']['modules'])) {
43
	$config['snmpd']['modules'] = array();
44
	$config['snmpd']['modules']['mibii'] = true;
45
	$config['snmpd']['modules']['netgraph'] = true;
46
	$config['snmpd']['modules']['pf'] = true;
47
	$config['snmpd']['modules']['hostres'] = true;
48
	$config['snmpd']['modules']['bridge'] = true;
49
	$config['snmpd']['modules']['ucd'] = true;
50
	$config['snmpd']['modules']['regex'] = true;
51
}
52

    
53
$pconfig['enable'] = isset($config['snmpd']['enable']);
54
$pconfig['pollport'] = $config['snmpd']['pollport'];
55
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
56
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
57
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
58
/* disabled until some docs show up on what this does.
59
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
60
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
61
*/
62
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
63
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
64
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
65
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
66

    
67
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
68
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
69
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
70
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
71
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
72
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
73
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
74
$pconfig['bindip'] = $config['snmpd']['bindip'];
75

    
76
if ($_POST) {
77

    
78
	unset($input_errors);
79
	$pconfig = $_POST;
80

    
81
	/* input validation */
82
	if ($_POST['enable']) {
83
		if (strstr($_POST['syslocation'], "#")) {
84
			$input_errors[] = gettext("Invalid character '#' in system location");
85
		}
86
		if (strstr($_POST['syscontact'], "#")) {
87
			$input_errors[] = gettext("Invalid character '#' in system contact");
88
		}
89
		if (strstr($_POST['rocommunity'], "#")) {
90
			$input_errors[] = gettext("Invalid character '#' in read community string");
91
		}
92

    
93
		$reqdfields = explode(" ", "rocommunity");
94
		$reqdfieldsn = array(gettext("Community"));
95
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
96

    
97
		$reqdfields = explode(" ", "pollport");
98
		$reqdfieldsn = array(gettext("Polling Port"));
99
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
100

    
101

    
102
	}
103

    
104
	if ($_POST['trapenable']) {
105
		if (strstr($_POST['trapstring'], "#")) {
106
			$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
107
		}
108

    
109
		$reqdfields = explode(" ", "trapserver");
110
		$reqdfieldsn = array(gettext("Trap server"));
111
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
112

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

    
117
		$reqdfields = explode(" ", "trapstring");
118
		$reqdfieldsn = array(gettext("Trap string"));
119
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
120
	}
121

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

    
130

    
131

    
132
	if (!$input_errors) {
133
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
134
		$config['snmpd']['pollport'] = $_POST['pollport'];
135
		$config['snmpd']['syslocation'] = $_POST['syslocation'];
136
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
137
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
138
		/* disabled until some docs show up on what this does.
139
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
140
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
141
		*/
142
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
143
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
144
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
145
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
146

    
147
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
148
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
149
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
150
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
151
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
152
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
153
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
154
		$config['snmpd']['bindip'] = $_POST['bindip'];
155

    
156
		write_config();
157

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

    
164
function build_iplist() {
165
	$listenips = get_possible_listen_ips();
166
	$iplist = array();
167
	$iplist[''] = 'All';
168

    
169
	foreach ($listenips as $lip => $ldescr) {
170
		$iplist[$lip] = $ldescr;
171
	}
172
	unset($listenips);
173

    
174
	return($iplist);
175
}
176

    
177
$pgtitle = array(gettext("Services"), gettext("SNMP"));
178
$shortcut_section = "snmp";
179

    
180
include("head.inc");
181

    
182
if ($input_errors) {
183
	print_input_errors($input_errors);
184
}
185

    
186
if ($savemsg) {
187
	print_info_box($savemsg, 'success');
188
}
189

    
190
$form = new Form();
191

    
192
$section = new Form_Section('SNMP Daemon');
193

    
194
$section->addInput(new Form_Checkbox(
195
	'enable',
196
	'Enable',
197
	'Enable the SNMP Daemon and its controls',
198
	$pconfig['enable']
199
));
200

    
201
$form->add($section);
202

    
203
$section = new Form_Section('SNMP Daemon Settings');
204

    
205
$section->addInput(new Form_Input(
206
	'pollport',
207
	'Polling Port',
208
	'text',
209
	($pconfig['pollport'] ? $pconfig['pollport']:'161')
210
))->setHelp('Enter the port to accept polling events on (default 161).');
211

    
212
$section->addInput(new Form_Input(
213
	'syslocation',
214
	'System Location',
215
	'text',
216
	$pconfig['syslocation']
217
));
218

    
219
$section->addInput(new Form_Input(
220
	'syscontact',
221
	'System Contact',
222
	'text',
223
	$pconfig['syscontact']
224
));
225

    
226
$section->addInput(new Form_Input(
227
	'rocommunity',
228
	'Read Community String',
229
	'text',
230
	$pconfig['rocommunity']
231
))->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.');
232

    
233
$form->add($section);
234

    
235
$section = new Form_Section('SNMP Traps Enable');
236

    
237
$section->addInput(new Form_Checkbox(
238
	'trapenable',
239
	'Enable',
240
	'Enable the SNMP Trap and its controls',
241
	$pconfig['trapenable']
242
))->toggles('.toggle-traps');
243

    
244
$form->add($section);
245

    
246
$section = new Form_Section('SNMP Trap Settings');
247

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

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

    
261
$section->addInput(new Form_Input(
262
	'trapserverport',
263
	'Trap Server Port',
264
	'text',
265
	($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
266
))->setHelp('Enter the port to send the traps to (default 162)');
267

    
268
$section->addInput(new Form_Input(
269
	'trapstring',
270
	'SNMP Trap String',
271
	'text',
272
	$pconfig['trapstring']
273
));
274

    
275
$form->add($section);
276

    
277
$section = new Form_Section('SNMP Modules');
278

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

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

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

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

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

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

    
316
$group->add(new Form_MultiCheckbox(
317
	'regex',
318
	null,
319
	'Regex',
320
	$pconfig['regex']
321
));
322

    
323
$section->add($group);
324
$form->add($section);
325

    
326
$section = new Form_Section('Interface Binding');
327

    
328
$section->addInput(new Form_Select(
329
	'bindip',
330
	'Bind Interface',
331
	$pconfig['bindip'],
332
	build_iplist()
333
));
334

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

    
337
print($form);
338
?>
339

    
340
<script type="text/javascript">
341
//<![CDATA[
342

    
343
// hostres requires mibii so we force that here
344
events.push(function() {
345

    
346
	noMibii = false;
347

    
348
	$('#junk').hide();
349
	hostresChange();
350

    
351
	function hostresChange() {
352
		if ($('#hostres').prop('checked')) {
353
			$('#mibii').prop('checked', true);
354
			noMibii = true;
355
		} else {
356
			noMibii = false;
357
		}
358
	}
359

    
360
	$('#hostres').change(function() {
361
		hostresChange();
362
	});
363

    
364

    
365
	$('#mibii').change(function() {
366
		if (noMibii) {
367
			$('#mibii').prop('checked', 'true');
368
		}
369
	});
370

    
371
	$('[name=btntoggleall]').hide();
372
});
373
//]]>
374
</script>
375

    
376
<?php include("foot.inc");
(141-141/227)