Project

General

Profile

Download (18.2 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
$pconfig['enable'] = isset($config['snmpd']['enable']);
66
$pconfig['pollport'] = $config['snmpd']['pollport'];
67
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
68
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
69
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
70
/* disabled until some docs show up on what this does.
71
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
72
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
73
*/
74
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
75
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
76
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
77
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
78

    
79
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
80
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
81
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
82
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
83
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
84
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
85
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
86
$pconfig['bindip'] = $config['snmpd']['bindip'];
87

    
88
if ($_POST) {
89

    
90
	unset($input_errors);
91
	$pconfig = $_POST;
92

    
93
	/* input validation */
94
	if ($_POST['enable']) {
95
		if (strstr($_POST['syslocation'],"#")) $input_errors[] = gettext("Invalid character '#' in system location");
96
 		if (strstr($_POST['syscontact'],"#")) $input_errors[] = gettext("Invalid character '#' in system contact");
97
		if (strstr($_POST['rocommunity'],"#")) $input_errors[] = gettext("Invalid character '#' in read community string");
98

    
99
		$reqdfields = explode(" ", "rocommunity");
100
		$reqdfieldsn = array(gettext("Community"));
101
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
102

    
103
		$reqdfields = explode(" ", "pollport");
104
		$reqdfieldsn = array(gettext("Polling Port"));
105
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
106
		
107
	
108
	}
109

    
110
	if ($_POST['trapenable']) {
111
		if (strstr($_POST['trapstring'],"#")) $input_errors[] = gettext("Invalid character '#' in SNMP trap string");
112

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

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

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

    
126

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

    
135
	
136

    
137
	if (!$input_errors) {
138
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
139
		$config['snmpd']['pollport'] = $_POST['pollport'];
140
		$config['snmpd']['syslocation'] = $_POST['syslocation'];	
141
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
142
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
143
		/* disabled until some docs show up on what this does.
144
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
145
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
146
		*/
147
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
148
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
149
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
150
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
151
		
152
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
153
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
154
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
155
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
156
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
157
		$config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false;
158
		$config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false;
159
		$config['snmpd']['bindip'] = $_POST['bindip'];
160
			
161
		write_config();
162
		
163
		$retval = 0;
164
		$retval = services_snmpd_configure();
165
		$savemsg = get_std_save_message($retval);
166
	}
167
}
168

    
169
$closehead = false;
170
$pgtitle = array(gettext("Services"),gettext("SNMP"));
171
$shortcut_section = "snmp";
172
include("head.inc");
173

    
174
?>
175
<script type="text/javascript">
176
//<![CDATA[
177
function check_deps() {
178
	if (jQuery('#hostres').prop('checked') == true) {
179
		jQuery('#mibii').prop('checked',true);
180
	}
181
}
182

    
183
function enable_change(whichone) {
184

    
185
	if( whichone.name == "trapenable" )
186
        {
187
	    if( whichone.checked == true )
188
	    {
189
	        document.iform.trapserver.disabled = false;
190
	        document.iform.trapserverport.disabled = false;
191
	        document.iform.trapstring.disabled = false;
192
	    }
193
	    else
194
	    {
195
                document.iform.trapserver.disabled = true;
196
                document.iform.trapserverport.disabled = true;
197
                document.iform.trapstring.disabled = true;
198
	    }
199
	}
200

    
201
	/* disabled until some docs show up on what this does.
202
	if( whichone.name == "rwenable"  )
203
	{
204
	    if( whichone.checked == true )
205
	    {
206
		document.iform.rwcommunity.disabled = false;
207
	    }
208
	    else
209
	    {
210
		document.iform.rwcommunity.disabled = true;
211
	    }
212
	}
213
	*/
214

    
215
	if( document.iform.enable.checked == true )
216
	{
217
	    document.iform.pollport.disabled = false;
218
	    document.iform.syslocation.disabled = false;
219
	    document.iform.syscontact.disabled = false;
220
	    document.iform.rocommunity.disabled = false;
221
	    document.iform.trapenable.disabled = false;
222
	    /* disabled until some docs show up on what this does.
223
	    document.iform.rwenable.disabled = false;
224
	    if( document.iform.rwenable.checked == true )
225
	    {
226
	        document.iform.rwcommunity.disabled = false;
227
	    }
228
	    else
229
	    {
230
		document.iform.rwcommunity.disabled = true;
231
	    }
232
	    */
233
	    if( document.iform.trapenable.checked == true )
234
	    {
235
                document.iform.trapserver.disabled = false;
236
                document.iform.trapserverport.disabled = false;
237
                document.iform.trapstring.disabled = false;
238
	    }
239
	    else
240
	    {
241
                document.iform.trapserver.disabled = true;
242
                document.iform.trapserverport.disabled = true;
243
                document.iform.trapstring.disabled = true;
244
	    }
245
	    document.iform.mibii.disabled = false;
246
	    document.iform.netgraph.disabled = false;
247
	    document.iform.pf.disabled = false;
248
	    document.iform.hostres.disabled = false;
249
	    document.iform.ucd.disabled = false;
250
	    document.iform.regex.disabled = false;
251
	    //document.iform.bridge.disabled = false;
252
	}
253
	else
254
	{
255
            document.iform.pollport.disabled = true;
256
            document.iform.syslocation.disabled = true;
257
            document.iform.syscontact.disabled = true;
258
            document.iform.rocommunity.disabled = true;
259
	    /* 
260
            document.iform.rwenable.disabled = true;
261
	    document.iform.rwcommunity.disabled = true;
262
	    */
263
            document.iform.trapenable.disabled = true;
264
            document.iform.trapserver.disabled = true;
265
            document.iform.trapserverport.disabled = true;
266
            document.iform.trapstring.disabled = true;
267

    
268
            document.iform.mibii.disabled = true;
269
            document.iform.netgraph.disabled = true;
270
            document.iform.pf.disabled = true;
271
            document.iform.hostres.disabled = true;
272
            document.iform.ucd.disabled = true;
273
            document.iform.regex.disabled = true;
274
            //document.iform.bridge.disabled = true;
275
	}
276
}
277
//]]>
278
</script>
279
</head>
280
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
281
<?php include("fbegin.inc"); ?>
282
<?php if ($input_errors) print_input_errors($input_errors); ?>
283
<?php if ($savemsg) print_info_box($savemsg); ?>
284
            <form action="services_snmp.php" method="post" name="iform" id="iform">
285
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="snmp">
286

    
287
                <tr> 
288
  		  <td colspan="2" valign="top" class="optsect_t">
289
  			<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="enable">
290
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Daemon");?></strong></td>
291
					<td align="right" class="optsect_s"><input name="enable" id="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\""; ?> onclick="enable_change(this)" /> <strong><?=gettext("Enable");?></strong></td></tr>
292
  			</table></td>
293
                </tr>
294

    
295
                <tr>
296
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Polling Port ");?></td>
297
                  <td width="78%" class="vtable">
298
                    <input name="pollport" type="text" class="formfld unknown" id="pollport" size="40" value="<?=htmlspecialchars($pconfig['pollport']) ? htmlspecialchars($pconfig['pollport']) : htmlspecialchars(161);?>" />
299
                    <br /><?=gettext("Enter the port to accept polling events on (default 161)");?><br />
300
		  </td>
301
                </tr>
302

    
303
                <tr> 
304
                  <td width="22%" valign="top" class="vncell"><?=gettext("System location");?></td>
305
                  <td width="78%" class="vtable"> 
306
                    <input name="syslocation" type="text" class="formfld unknown" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>" />
307
                  </td>
308
                </tr>
309

    
310
                <tr> 
311
                  <td width="22%" valign="top" class="vncell"><?=gettext("System contact");?></td>
312
                  <td width="78%" class="vtable"> 
313
                    <input name="syscontact" type="text" class="formfld unknown" id="syscontact" size="40" value="<?=htmlspecialchars($pconfig['syscontact']);?>" />
314
                  </td>
315
                </tr>
316

    
317
                <tr> 
318
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Read Community String");?></td>
319
                  <td width="78%" class="vtable"> 
320
                    <input name="rocommunity" type="text" class="formfld unknown" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>" />
321
		    <br /><?=gettext("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.");?><br />
322
		  </td>
323
                </tr>
324

    
325
<?php 
326
			/* disabled until some docs show up on what this does.
327
                <tr>
328
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
329
                  <td width="78%" class="vtable">
330
	 	   <input name="rwenable" id="rwenable" type="checkbox" value="yes" <?php if ($pconfig['rwenable']) echo "checked=\"checked\""; ?> onclick="enable_change(this)" />
331
                    <strong>Enable Write Community String</strong>
332
		  </td>
333
                </tr>
334

    
335
		<tr>
336
		  <td width="22%" valign="top" class="vncellreq">Write community string</td>
337
          <td width="78%" class="vtable">
338
                    <input name="rwcommunity" type="text" class="formfld unknown" id="rwcommunity" size="40" value="<?=htmlspecialchars($pconfig['rwcommunity']);?>" />
339
		    <br />Please use something other then &quot;private&quot; here<br />
340
		  </td>
341
                </tr>
342
		    	*/ 
343
?>
344

    
345
		<tr><td>&nbsp;</td></tr>
346

    
347
                <tr> 
348
  		  <td colspan="2" valign="top" class="optsect_t">
349
  			<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="enable">
350
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Traps");?></strong></td>
351
			<td align="right" class="optsect_s"><input name="trapenable" id="trapenable" type="checkbox" value="yes" <?php if ($pconfig['trapenable']) echo "checked=\"checked\""; ?> onclick="enable_change(this)" /> <strong><?=gettext("Enable");?></strong></td></tr>
352
  			</table></td>
353
                </tr>
354

    
355

    
356
                <tr>
357
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Trap server");?></td>
358
                  <td width="78%" class="vtable">
359
                    <input name="trapserver" type="text" class="formfld unknown" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>" />
360
                    <br /><?=gettext("Enter trap server name");?><br />
361
		  </td>
362
                </tr>
363

    
364
                <tr>
365
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Trap server port ");?></td>
366
                  <td width="78%" class="vtable">
367
                    <input name="trapserverport" type="text" class="formfld unknown" id="trapserverport" size="40" value="<?=htmlspecialchars($pconfig['trapserverport']) ? htmlspecialchars($pconfig['trapserverport']) : htmlspecialchars(162);?>" />
368
                    <br /><?=gettext("Enter the port to send the traps to (default 162)");?><br />
369
		  </td>
370
                </tr>
371

    
372
                <tr>
373
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Enter the SNMP trap string");?></td>
374
                  <td width="78%" class="vtable">
375
                    <input name="trapstring" type="text" class="formfld unknown" id="trapstring" size="40" value="<?=htmlspecialchars($pconfig['trapstring']);?>" />
376
                    <br /><?=gettext("Trap string");?><br />
377
		  </td>
378
                </tr>
379

    
380
		<tr><td>&nbsp;</td></tr>
381

    
382
                <tr> 
383
  		  <td colspan="2" valign="top" class="optsect_t">
384
  			<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="modules">
385
  			<tr><td class="optsect_s"><strong><?=gettext("Modules");?></strong></td>
386
			<td align="right" class="optsect_s">&nbsp;</td></tr>
387
  			</table></td>
388
                </tr>
389

    
390
		<tr>
391
		  <td width="22%" valign="top" class="vncellreq"><?=gettext("SNMP Modules");?></td>
392
		  <td width="78%" class="vtable">
393
		    <input name="mibii" type="checkbox" id="mibii" value="yes" onclick="check_deps()" <?php if ($pconfig['mibii']) echo "checked=\"checked\""; ?> /><?=gettext("MibII"); ?>
394
		    <br />
395
		    <input name="netgraph" type="checkbox" id="netgraph" value="yes" <?php if ($pconfig['netgraph']) echo "checked=\"checked\""; ?> /><?=gettext("Netgraph"); ?>
396
		    <br />
397
		    <input name="pf" type="checkbox" id="pf" value="yes" <?php if ($pconfig['pf']) echo "checked=\"checked\""; ?> /><?=gettext("PF"); ?>
398
		    <br />
399
		    <input name="hostres" type="checkbox" id="hostres" value="yes" onclick="check_deps()" <?php if ($pconfig['hostres']) echo "checked=\"checked\""; ?> /><?=gettext("Host Resources (Requires MibII)");?>
400
		    <br />
401
		    <input name="ucd" type="checkbox" id="ucd" value="yes" <?php if ($pconfig['ucd']) echo "checked=\"checked\""; ?> /><?=gettext("UCD"); ?>
402
		    <br />
403
		    <input name="regex" type="checkbox" id="regex" value="yes" <?php if ($pconfig['regex']) echo "checked=\"checked\""; ?> /><?=gettext("Regex"); ?>
404
		    <br />
405
		  </td>
406
		</tr>
407

    
408
		<tr><td>&nbsp;</td></tr>
409

    
410
		<tr>
411
			<td colspan="2" valign="top" class="optsect_t">
412
			<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="interface">
413
				<tr><td class="optsect_s"><strong><?=gettext("Interface Binding");?></strong></td>
414
				<td align="right" class="optsect_s">&nbsp;</td></tr>
415
			</table></td>
416
		</tr>
417
		<tr>
418
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Bind Interface"); ?></td>
419
			<td width="78%" class="vtable">
420
				<select name="bindip" class="formselect">
421
					<option value="">All</option>
422
				<?php  $listenips = get_possible_listen_ips();
423
					foreach ($listenips as $lip):
424
						$selected = "";
425
						if ($lip['value'] == $pconfig['bindip'])
426
							$selected = "selected=\"selected\"";
427
				?>
428
					<option value="<?=$lip['value'];?>" <?=$selected;?>>
429
						<?=htmlspecialchars($lip['name']);?>
430
					</option>
431
				<?php endforeach; ?>
432
				</select>
433
			</td>
434
		</tr>
435
		 <tr> 
436
		   <td width="22%" valign="top">&nbsp;</td>
437
		   <td width="78%"> 
438
		     <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)" />
439
		   </td>
440
		 </tr>
441
		</table>
442
</form>
443
<script type="text/javascript">
444
//<![CDATA[
445
enable_change(this);
446
//]]>
447
</script>
448
<?php include("fend.inc"); ?>
449
</body>
450
</html>
(169-169/256)