1
|
<?php
|
2
|
/*
|
3
|
services_snmp.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
*
|
8
|
* Some or all of this file is based on the m0n0wall project which is
|
9
|
* Copyright (c) 2004 Manuel Kasper (BSD 2 clause)
|
10
|
*
|
11
|
* Redistribution and use in source and binary forms, with or without modification,
|
12
|
* are permitted provided that the following conditions are met:
|
13
|
*
|
14
|
* 1. Redistributions of source code must retain the above copyright notice,
|
15
|
* this list of conditions and the following disclaimer.
|
16
|
*
|
17
|
* 2. Redistributions in binary form must reproduce the above copyright
|
18
|
* notice, this list of conditions and the following disclaimer in
|
19
|
* the documentation and/or other materials provided with the
|
20
|
* distribution.
|
21
|
*
|
22
|
* 3. All advertising materials mentioning features or use of this software
|
23
|
* must display the following acknowledgment:
|
24
|
* "This product includes software developed by the pfSense Project
|
25
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
26
|
*
|
27
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28
|
* endorse or promote products derived from this software without
|
29
|
* prior written permission. For written permission, please contact
|
30
|
* coreteam@pfsense.org.
|
31
|
*
|
32
|
* 5. Products derived from this software may not be called "pfSense"
|
33
|
* nor may "pfSense" appear in their names without prior written
|
34
|
* permission of the Electric Sheep Fencing, LLC.
|
35
|
*
|
36
|
* 6. Redistributions of any form whatsoever must retain the following
|
37
|
* acknowledgment:
|
38
|
*
|
39
|
* "This product includes software developed by the pfSense Project
|
40
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41
|
*
|
42
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54
|
*
|
55
|
* ====================================================================
|
56
|
*
|
57
|
*/
|
58
|
/*
|
59
|
pfSense_MODULE: snmp
|
60
|
*/
|
61
|
|
62
|
##|+PRIV
|
63
|
##|*IDENT=page-services-snmp
|
64
|
##|*NAME=Services: SNMP page
|
65
|
##|*DESCR=Allow access to the 'Services: SNMP' page.
|
66
|
##|*MATCH=services_snmp.php*
|
67
|
##|-PRIV
|
68
|
|
69
|
require("guiconfig.inc");
|
70
|
require_once("functions.inc");
|
71
|
|
72
|
if (!is_array($config['snmpd'])) {
|
73
|
$config['snmpd'] = array();
|
74
|
$config['snmpd']['rocommunity'] = "public";
|
75
|
$config['snmpd']['pollport'] = "161";
|
76
|
}
|
77
|
|
78
|
if (!is_array($config['snmpd']['modules'])) {
|
79
|
$config['snmpd']['modules'] = array();
|
80
|
$config['snmpd']['modules']['mibii'] = true;
|
81
|
$config['snmpd']['modules']['netgraph'] = true;
|
82
|
$config['snmpd']['modules']['pf'] = true;
|
83
|
$config['snmpd']['modules']['hostres'] = true;
|
84
|
$config['snmpd']['modules']['bridge'] = true;
|
85
|
$config['snmpd']['modules']['ucd'] = true;
|
86
|
$config['snmpd']['modules']['regex'] = true;
|
87
|
}
|
88
|
|
89
|
$pconfig['enable'] = isset($config['snmpd']['enable']);
|
90
|
$pconfig['pollport'] = $config['snmpd']['pollport'];
|
91
|
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
|
92
|
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
|
93
|
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
|
94
|
/* disabled until some docs show up on what this does.
|
95
|
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
|
96
|
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
|
97
|
*/
|
98
|
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
|
99
|
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
|
100
|
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
|
101
|
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
|
102
|
|
103
|
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
|
104
|
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
|
105
|
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
|
106
|
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
|
107
|
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
|
108
|
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
|
109
|
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
|
110
|
$pconfig['bindip'] = $config['snmpd']['bindip'];
|
111
|
|
112
|
if ($_POST) {
|
113
|
|
114
|
unset($input_errors);
|
115
|
$pconfig = $_POST;
|
116
|
|
117
|
/* input validation */
|
118
|
if ($_POST['enable']) {
|
119
|
if (strstr($_POST['syslocation'], "#")) {
|
120
|
$input_errors[] = gettext("Invalid character '#' in system location");
|
121
|
}
|
122
|
if (strstr($_POST['syscontact'], "#")) {
|
123
|
$input_errors[] = gettext("Invalid character '#' in system contact");
|
124
|
}
|
125
|
if (strstr($_POST['rocommunity'], "#")) {
|
126
|
$input_errors[] = gettext("Invalid character '#' in read community string");
|
127
|
}
|
128
|
|
129
|
$reqdfields = explode(" ", "rocommunity");
|
130
|
$reqdfieldsn = array(gettext("Community"));
|
131
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
132
|
|
133
|
$reqdfields = explode(" ", "pollport");
|
134
|
$reqdfieldsn = array(gettext("Polling Port"));
|
135
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
136
|
|
137
|
|
138
|
}
|
139
|
|
140
|
if ($_POST['trapenable']) {
|
141
|
if (strstr($_POST['trapstring'], "#")) {
|
142
|
$input_errors[] = gettext("Invalid character '#' in SNMP trap string");
|
143
|
}
|
144
|
|
145
|
$reqdfields = explode(" ", "trapserver");
|
146
|
$reqdfieldsn = array(gettext("Trap server"));
|
147
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
148
|
|
149
|
$reqdfields = explode(" ", "trapserverport");
|
150
|
$reqdfieldsn = array(gettext("Trap server port"));
|
151
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
152
|
|
153
|
$reqdfields = explode(" ", "trapstring");
|
154
|
$reqdfieldsn = array(gettext("Trap string"));
|
155
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
156
|
}
|
157
|
|
158
|
/* disabled until some docs show up on what this does.
|
159
|
if ($_POST['rwenable']) {
|
160
|
$reqdfields = explode(" ", "rwcommunity");
|
161
|
$reqdfieldsn = explode(",", "Write community string");
|
162
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
163
|
}
|
164
|
*/
|
165
|
|
166
|
|
167
|
|
168
|
if (!$input_errors) {
|
169
|
$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
|
170
|
$config['snmpd']['pollport'] = $_POST['pollport'];
|
171
|
$config['snmpd']['syslocation'] = $_POST['syslocation'];
|
172
|
$config['snmpd']['syscontact'] = $_POST['syscontact'];
|
173
|
$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
|
174
|
/* disabled until some docs show up on what this does.
|
175
|
$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
|
176
|
$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
|
177
|
*/
|
178
|
$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
|
179
|
$config['snmpd']['trapserver'] = $_POST['trapserver'];
|
180
|
$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
|
181
|
$config['snmpd']['trapstring'] = $_POST['trapstring'];
|
182
|
|
183
|
$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
|
184
|
$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
|
185
|
$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
|
186
|
$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
|
187
|
$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
|
188
|
$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
|
189
|
$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
|
190
|
$config['snmpd']['bindip'] = $_POST['bindip'];
|
191
|
|
192
|
write_config();
|
193
|
|
194
|
$retval = 0;
|
195
|
$retval = services_snmpd_configure();
|
196
|
$savemsg = get_std_save_message($retval);
|
197
|
}
|
198
|
}
|
199
|
|
200
|
function build_iplist() {
|
201
|
$listenips = get_possible_listen_ips();
|
202
|
$iplist = array();
|
203
|
$iplist[''] = 'All';
|
204
|
|
205
|
foreach ($listenips as $lip => $ldescr) {
|
206
|
$iplist[$lip] = $ldescr;
|
207
|
}
|
208
|
unset($listenips);
|
209
|
|
210
|
return($iplist);
|
211
|
}
|
212
|
|
213
|
$closehead = false;
|
214
|
$pgtitle = array(gettext("Services"), gettext("SNMP"));
|
215
|
$shortcut_section = "snmp";
|
216
|
|
217
|
include("head.inc");
|
218
|
|
219
|
if ($input_errors)
|
220
|
print_input_errors($input_errors);
|
221
|
|
222
|
if ($savemsg)
|
223
|
print_info_box($savemsg);
|
224
|
|
225
|
require_once('classes/Form.class.php');
|
226
|
|
227
|
$form = new Form();
|
228
|
|
229
|
$section = new Form_Section('SNMP Daemon');
|
230
|
|
231
|
$section->addInput(new Form_Checkbox(
|
232
|
'enable',
|
233
|
'Enable',
|
234
|
'Enable the SNMP Daemon and its controls',
|
235
|
$pconfig['enable']
|
236
|
));
|
237
|
|
238
|
$form->add($section);
|
239
|
|
240
|
$section = new Form_Section('SNMP Daemon settings');
|
241
|
|
242
|
$section->addInput(new Form_Input(
|
243
|
'pollport',
|
244
|
'Polling Port',
|
245
|
'text',
|
246
|
($pconfig['pollport'] ? $pconfig['pollport']:'161')
|
247
|
))->setHelp('Enter the port to accept polling events on (default 161)');
|
248
|
|
249
|
$section->addInput(new Form_Input(
|
250
|
'syslocation',
|
251
|
'System Location',
|
252
|
'text',
|
253
|
$pconfig['syslocation']
|
254
|
));
|
255
|
|
256
|
$section->addInput(new Form_Input(
|
257
|
'syscontact',
|
258
|
'System Contact',
|
259
|
'text',
|
260
|
$pconfig['syscontact']
|
261
|
));
|
262
|
|
263
|
$section->addInput(new Form_Input(
|
264
|
'rocommunity',
|
265
|
'Read Community String',
|
266
|
'text',
|
267
|
$pconfig['rocommunity']
|
268
|
))->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.');
|
269
|
|
270
|
$form->add($section);
|
271
|
|
272
|
$section = new Form_Section('SNMP Traps Enable');
|
273
|
|
274
|
$section->addInput(new Form_Checkbox(
|
275
|
'trapenable',
|
276
|
'Enable',
|
277
|
'Enable the SNMP Trap and its controls',
|
278
|
$pconfig['trapenable']
|
279
|
))->toggles('.toggle-traps');
|
280
|
|
281
|
$form->add($section);
|
282
|
|
283
|
$section = new Form_Section('SNMP Trap settings');
|
284
|
|
285
|
if($pconfig['trapenable'])
|
286
|
$section->addClass('toggle-traps', 'in');
|
287
|
else
|
288
|
$section->addClass('toggle-traps', 'collapse');
|
289
|
|
290
|
$section->addInput(new Form_Input(
|
291
|
'trapserver',
|
292
|
'Trap server',
|
293
|
'text',
|
294
|
$pconfig['trapserver']
|
295
|
))->setHelp('Enter the trap server name');
|
296
|
|
297
|
$section->addInput(new Form_Input(
|
298
|
'trapserverport',
|
299
|
'Trap Server Port',
|
300
|
'text',
|
301
|
($pconfig['trapserverport'] ? $pconfig['trapserverport']:'162')
|
302
|
))->setHelp('Enter the port to send the traps to (default 162)');
|
303
|
|
304
|
$section->addInput(new Form_Input(
|
305
|
'trapstring',
|
306
|
'SNMP Trap String',
|
307
|
'text',
|
308
|
$pconfig['trapstring']
|
309
|
));
|
310
|
|
311
|
$form->add($section);
|
312
|
|
313
|
$section = new Form_Section('SNMP Modules');
|
314
|
|
315
|
$group = new Form_MultiCheckboxGroup('SNMP modules');
|
316
|
|
317
|
$group->add(new Form_MultiCheckbox(
|
318
|
'mibii',
|
319
|
null,
|
320
|
'MibII',
|
321
|
$pconfig['mibii']
|
322
|
));
|
323
|
|
324
|
$group->add(new Form_MultiCheckbox(
|
325
|
'netgraph',
|
326
|
null,
|
327
|
'Netgraph',
|
328
|
$pconfig['netgraph']
|
329
|
));
|
330
|
|
331
|
$group->add(new Form_MultiCheckbox(
|
332
|
'pf',
|
333
|
null,
|
334
|
'PF',
|
335
|
$pconfig['pf']
|
336
|
));
|
337
|
|
338
|
$group->add(new Form_MultiCheckbox(
|
339
|
'hostres',
|
340
|
null,
|
341
|
'Host Resources',
|
342
|
$pconfig['hostres']
|
343
|
));
|
344
|
|
345
|
$group->add(new Form_MultiCheckbox(
|
346
|
'ucd',
|
347
|
null,
|
348
|
'UCD',
|
349
|
$pconfig['ucd']
|
350
|
));
|
351
|
|
352
|
$group->add(new Form_MultiCheckbox(
|
353
|
'regex',
|
354
|
null,
|
355
|
'Regex',
|
356
|
$pconfig['regex']
|
357
|
));
|
358
|
|
359
|
$section->add($group);
|
360
|
$form->add($section);
|
361
|
|
362
|
$section = new Form_Section('Interface Binding');
|
363
|
|
364
|
$section->addInput(new Form_Select(
|
365
|
'bindip',
|
366
|
'Bind Interface',
|
367
|
$pconfig['bindip'],
|
368
|
build_iplist()
|
369
|
));
|
370
|
|
371
|
$form->add($section);
|
372
|
|
373
|
print($form);
|
374
|
?>
|
375
|
|
376
|
<script type="text/javascript">
|
377
|
//<![CDATA[
|
378
|
|
379
|
// hostres requires mibii so we force that here
|
380
|
events.push(function(){
|
381
|
$('#hostres').change(function(){
|
382
|
if($('#hostres').is(':checked'))
|
383
|
$('#mibii').attr('checked', 'checked');
|
384
|
});
|
385
|
});
|
386
|
//]]>
|
387
|
</script>
|
388
|
|
389
|
<?php include("foot.inc");
|