1
|
<?php
|
2
|
/*
|
3
|
* services_snmp.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
|
9
|
* All rights reserved.
|
10
|
*
|
11
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
12
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13
|
* All rights reserved.
|
14
|
*
|
15
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
16
|
* you may not use this file except in compliance with the License.
|
17
|
* You may obtain a copy of the License at
|
18
|
*
|
19
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20
|
*
|
21
|
* Unless required by applicable law or agreed to in writing, software
|
22
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
23
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24
|
* See the License for the specific language governing permissions and
|
25
|
* limitations under the License.
|
26
|
*/
|
27
|
|
28
|
##|+PRIV
|
29
|
##|*IDENT=page-services-snmp
|
30
|
##|*NAME=Services: SNMP
|
31
|
##|*DESCR=Allow access to the 'Services: SNMP' page.
|
32
|
##|*MATCH=services_snmp.php*
|
33
|
##|-PRIV
|
34
|
|
35
|
require_once("guiconfig.inc");
|
36
|
require_once("functions.inc");
|
37
|
|
38
|
if (!is_array($config['snmpd'])) {
|
39
|
$config['snmpd'] = array();
|
40
|
$config['snmpd']['rocommunity'] = "public";
|
41
|
$config['snmpd']['pollport'] = "161";
|
42
|
}
|
43
|
|
44
|
if (!is_array($config['snmpd']['modules'])) {
|
45
|
$config['snmpd']['modules'] = array();
|
46
|
$config['snmpd']['modules']['mibii'] = true;
|
47
|
$config['snmpd']['modules']['netgraph'] = true;
|
48
|
$config['snmpd']['modules']['pf'] = true;
|
49
|
$config['snmpd']['modules']['hostres'] = true;
|
50
|
$config['snmpd']['modules']['bridge'] = true;
|
51
|
$config['snmpd']['modules']['ucd'] = true;
|
52
|
$config['snmpd']['modules']['regex'] = true;
|
53
|
}
|
54
|
|
55
|
$pconfig['enable'] = isset($config['snmpd']['enable']);
|
56
|
$pconfig['pollport'] = $config['snmpd']['pollport'];
|
57
|
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
|
58
|
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
|
59
|
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
|
60
|
/* disabled until some docs show up on what this does.
|
61
|
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
|
62
|
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
|
63
|
*/
|
64
|
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
|
65
|
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
|
66
|
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
|
67
|
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
|
68
|
|
69
|
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
|
70
|
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
|
71
|
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
|
72
|
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
|
73
|
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
|
74
|
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
|
75
|
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
|
76
|
|
77
|
$pconfig['ipprotocol'] = $config['snmpd']['ipprotocol'];
|
78
|
if (empty($config['snmpd']['bindip'])) {
|
79
|
$pconfig['bindip'] = array();
|
80
|
} else {
|
81
|
$pconfig['bindip'] = explode(",", $config['snmpd']['bindip']);
|
82
|
}
|
83
|
|
84
|
if ($_POST) {
|
85
|
|
86
|
unset($input_errors);
|
87
|
$pconfig = $_POST;
|
88
|
|
89
|
/* input validation */
|
90
|
if ($_POST['enable']) {
|
91
|
if (strstr($_POST['syslocation'], "#")) {
|
92
|
$input_errors[] = gettext("Invalid character '#' in system location");
|
93
|
}
|
94
|
if (strstr($_POST['syscontact'], "#")) {
|
95
|
$input_errors[] = gettext("Invalid character '#' in system contact");
|
96
|
}
|
97
|
if (strstr($_POST['rocommunity'], "#")) {
|
98
|
$input_errors[] = gettext("Invalid character '#' in read community string");
|
99
|
}
|
100
|
|
101
|
$reqdfields = explode(" ", "rocommunity");
|
102
|
$reqdfieldsn = array(gettext("Community"));
|
103
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
104
|
|
105
|
$reqdfields = explode(" ", "pollport");
|
106
|
$reqdfieldsn = array(gettext("Polling Port"));
|
107
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
108
|
|
109
|
|
110
|
}
|
111
|
|
112
|
if ($_POST['trapenable']) {
|
113
|
if (strstr($_POST['trapstring'], "#")) {
|
114
|
$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
|
115
|
}
|
116
|
|
117
|
$reqdfields = explode(" ", "trapserver");
|
118
|
$reqdfieldsn = array(gettext("Trap server"));
|
119
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
120
|
|
121
|
$reqdfields = explode(" ", "trapserverport");
|
122
|
$reqdfieldsn = array(gettext("Trap server port"));
|
123
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
124
|
|
125
|
$reqdfields = explode(" ", "trapstring");
|
126
|
$reqdfieldsn = array(gettext("Trap string"));
|
127
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
128
|
}
|
129
|
|
130
|
/* disabled until some docs show up on what this does.
|
131
|
if ($_POST['rwenable']) {
|
132
|
$reqdfields = explode(" ", "rwcommunity");
|
133
|
$reqdfieldsn = explode(",", "Write community string");
|
134
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
135
|
}
|
136
|
*/
|
137
|
|
138
|
|
139
|
|
140
|
if (!$input_errors) {
|
141
|
$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
|
142
|
$config['snmpd']['pollport'] = $_POST['pollport'];
|
143
|
$config['snmpd']['syslocation'] = $_POST['syslocation'];
|
144
|
$config['snmpd']['syscontact'] = $_POST['syscontact'];
|
145
|
$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
|
146
|
/* disabled until some docs show up on what this does.
|
147
|
$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
|
148
|
$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
|
149
|
*/
|
150
|
$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
|
151
|
$config['snmpd']['trapserver'] = $_POST['trapserver'];
|
152
|
$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
|
153
|
$config['snmpd']['trapstring'] = $_POST['trapstring'];
|
154
|
|
155
|
$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
|
156
|
$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
|
157
|
$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
|
158
|
$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
|
159
|
$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
|
160
|
$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
|
161
|
$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
|
162
|
|
163
|
$config['snmpd']['ipprotocol'] = $_POST['ipprotocol'];
|
164
|
if (is_array($_POST['bindip']) && !empty($_POST['bindip'])) {
|
165
|
$config['snmpd']['bindip'] = implode(",", $_POST['bindip']);
|
166
|
}
|
167
|
|
168
|
write_config("SNMP settings saved");
|
169
|
|
170
|
$changes_applied = true;
|
171
|
$retval = 0;
|
172
|
$retval |= services_snmpd_configure();
|
173
|
}
|
174
|
}
|
175
|
|
176
|
function build_if_list($selectedifs) {
|
177
|
$interface_addresses = get_possible_listen_ips(true);
|
178
|
$iflist = array('options' => array(), 'selected' => array());
|
179
|
|
180
|
$iflist['options']['all'] = gettext("All");
|
181
|
if (empty($selectedifs) || empty($selectedifs[0]) || in_array("all", $selectedifs)) {
|
182
|
array_push($iflist['selected'], "all");
|
183
|
}
|
184
|
|
185
|
foreach ($interface_addresses as $laddr => $ldescr) {
|
186
|
if (is_ipaddr(get_interface_ip($laddr))) {
|
187
|
$iflist['options'][$laddr] = htmlspecialchars($ldescr);
|
188
|
}
|
189
|
|
190
|
if ($selectedifs && in_array($laddr, $selectedifs)) {
|
191
|
array_push($iflist['selected'], $laddr);
|
192
|
}
|
193
|
}
|
194
|
|
195
|
unset($interface_addresses);
|
196
|
|
197
|
return($iflist);
|
198
|
}
|
199
|
|
200
|
$pgtitle = array(gettext("Services"), gettext("SNMP"));
|
201
|
$shortcut_section = "snmp";
|
202
|
|
203
|
include("head.inc");
|
204
|
|
205
|
if ($input_errors) {
|
206
|
print_input_errors($input_errors);
|
207
|
}
|
208
|
|
209
|
if ($changes_applied) {
|
210
|
print_apply_result_box($retval);
|
211
|
}
|
212
|
|
213
|
$form = new Form();
|
214
|
|
215
|
$section = new Form_Section('SNMP Daemon');
|
216
|
|
217
|
$section->addInput(new Form_Checkbox(
|
218
|
'enable',
|
219
|
'Enable',
|
220
|
'Enable the SNMP Daemon and its controls',
|
221
|
$pconfig['enable']
|
222
|
));
|
223
|
|
224
|
$form->add($section);
|
225
|
|
226
|
$section = new Form_Section('SNMP Daemon Settings');
|
227
|
|
228
|
$section->addInput(new Form_Input(
|
229
|
'pollport',
|
230
|
'Polling Port',
|
231
|
'text',
|
232
|
($pconfig['pollport'] ? $pconfig['pollport']:'161')
|
233
|
))->setHelp('Enter the port to accept polling events on (default 161).');
|
234
|
|
235
|
$section->addInput(new Form_Input(
|
236
|
'syslocation',
|
237
|
'System Location',
|
238
|
'text',
|
239
|
$pconfig['syslocation']
|
240
|
));
|
241
|
|
242
|
$section->addInput(new Form_Input(
|
243
|
'syscontact',
|
244
|
'System Contact',
|
245
|
'text',
|
246
|
$pconfig['syscontact']
|
247
|
));
|
248
|
|
249
|
$section->addInput(new Form_Input(
|
250
|
'rocommunity',
|
251
|
'Read Community String',
|
252
|
'text',
|
253
|
$pconfig['rocommunity']
|
254
|
))->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.');
|
255
|
|
256
|
$form->add($section);
|
257
|
|
258
|
$section = new Form_Section('SNMP Traps Enable');
|
259
|
|
260
|
$section->addInput(new Form_Checkbox(
|
261
|
'trapenable',
|
262
|
'Enable',
|
263
|
'Enable the SNMP Trap and its controls',
|
264
|
$pconfig['trapenable']
|
265
|
))->toggles('.toggle-traps');
|
266
|
|
267
|
$form->add($section);
|
268
|
|
269
|
$section = new Form_Section('SNMP Trap Settings');
|
270
|
|
271
|
if ($pconfig['trapenable']) {
|
272
|
$section->addClass('toggle-traps', 'in');
|
273
|
} else {
|
274
|
$section->addClass('toggle-traps', 'collapse');
|
275
|
}
|
276
|
|
277
|
$section->addInput(new Form_Input(
|
278
|
'trapserver',
|
279
|
'Trap server',
|
280
|
'text',
|
281
|
$pconfig['trapserver']
|
282
|
))->setHelp('Enter the trap server name');
|
283
|
|
284
|
$section->addInput(new Form_Input(
|
285
|
'trapserverport',
|
286
|
'Trap Server Port',
|
287
|
'text',
|
288
|
($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
|
289
|
))->setHelp('Enter the port to send the traps to (default 162)');
|
290
|
|
291
|
$section->addInput(new Form_Input(
|
292
|
'trapstring',
|
293
|
'SNMP Trap String',
|
294
|
'text',
|
295
|
$pconfig['trapstring']
|
296
|
));
|
297
|
|
298
|
$form->add($section);
|
299
|
|
300
|
$section = new Form_Section('SNMP Modules');
|
301
|
|
302
|
$group = new Form_MultiCheckboxGroup('SNMP modules');
|
303
|
|
304
|
$group->add(new Form_MultiCheckbox(
|
305
|
'mibii',
|
306
|
null,
|
307
|
'MibII',
|
308
|
$pconfig['mibii']
|
309
|
));
|
310
|
|
311
|
$group->add(new Form_MultiCheckbox(
|
312
|
'netgraph',
|
313
|
null,
|
314
|
'Netgraph',
|
315
|
$pconfig['netgraph']
|
316
|
));
|
317
|
|
318
|
$group->add(new Form_MultiCheckbox(
|
319
|
'pf',
|
320
|
null,
|
321
|
'PF',
|
322
|
$pconfig['pf']
|
323
|
));
|
324
|
|
325
|
$group->add(new Form_MultiCheckbox(
|
326
|
'hostres',
|
327
|
null,
|
328
|
'Host Resources',
|
329
|
$pconfig['hostres']
|
330
|
));
|
331
|
|
332
|
$group->add(new Form_MultiCheckbox(
|
333
|
'ucd',
|
334
|
null,
|
335
|
'UCD',
|
336
|
$pconfig['ucd']
|
337
|
));
|
338
|
|
339
|
$group->add(new Form_MultiCheckbox(
|
340
|
'regex',
|
341
|
null,
|
342
|
'Regex',
|
343
|
$pconfig['regex']
|
344
|
));
|
345
|
|
346
|
$section->add($group);
|
347
|
$form->add($section);
|
348
|
|
349
|
$section = new Form_Section('Interface Binding');
|
350
|
|
351
|
$section->addInput(new Form_Select(
|
352
|
'ipprotocol',
|
353
|
'Internet Protocol',
|
354
|
$pconfig['ipprotocol'],
|
355
|
array("inet4" => "IPv4", "inet6" => "IPv6", "inet46" => "IPv4+IPv6")
|
356
|
));
|
357
|
|
358
|
$iflist = build_if_list($pconfig['bindip']);
|
359
|
|
360
|
$section->addInput(new Form_Select(
|
361
|
'bindip',
|
362
|
'Bind Interfaces',
|
363
|
$iflist['selected'],
|
364
|
$iflist['options'],
|
365
|
true
|
366
|
));
|
367
|
|
368
|
$form->add($section);
|
369
|
|
370
|
print($form);
|
371
|
?>
|
372
|
|
373
|
<script type="text/javascript">
|
374
|
//<![CDATA[
|
375
|
|
376
|
// hostres requires mibii so we force that here
|
377
|
events.push(function() {
|
378
|
|
379
|
noMibii = false;
|
380
|
|
381
|
$('#junk').hide();
|
382
|
enableChange();
|
383
|
trapenableChange();
|
384
|
hostresChange();
|
385
|
|
386
|
function enableChange() {
|
387
|
setRequired('pollport', $('#enable').prop('checked'));
|
388
|
setRequired('rocommunity', $('#enable').prop('checked'));
|
389
|
}
|
390
|
|
391
|
function trapenableChange() {
|
392
|
setRequired('trapserver', $('#trapenable').prop('checked'));
|
393
|
setRequired('trapserverport', $('#trapenable').prop('checked'));
|
394
|
setRequired('trapstring', $('#trapenable').prop('checked'));
|
395
|
}
|
396
|
|
397
|
function hostresChange() {
|
398
|
if ($('#hostres').prop('checked')) {
|
399
|
$('#mibii').prop('checked', true);
|
400
|
noMibii = true;
|
401
|
} else {
|
402
|
noMibii = false;
|
403
|
}
|
404
|
}
|
405
|
|
406
|
$('#enable').change(function() {
|
407
|
enableChange();
|
408
|
});
|
409
|
|
410
|
$('#trapenable').change(function() {
|
411
|
trapenableChange();
|
412
|
});
|
413
|
|
414
|
$('#hostres').change(function() {
|
415
|
hostresChange();
|
416
|
});
|
417
|
|
418
|
$('#mibii').change(function() {
|
419
|
if (noMibii) {
|
420
|
$('#mibii').prop('checked', 'true');
|
421
|
}
|
422
|
});
|
423
|
|
424
|
$('[name=btntoggleall]').hide();
|
425
|
});
|
426
|
//]]>
|
427
|
</script>
|
428
|
|
429
|
<?php include("foot.inc");
|