Project

General

Profile

Download (18.1 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / services_snmp.php @ a1b66bec

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
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
	
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
	
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
	
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE:	snmp
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-services-snmp
37
##|*NAME=Services: SNMP page
38
##|*DESCR=Allow access to the 'Services: SNMP' page.
39
##|*MATCH=services_snmp.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("functions.inc");
44

    
45
if (!is_array($config['snmpd'])) {
46
	$config['snmpd'] = array();
47
	$config['snmpd']['rocommunity'] = "public";
48
	$config['snmpd']['pollport'] = "161";
49
}
50

    
51
if (!is_array($config['snmpd']['modules'])) {
52
	$config['snmpd']['modules'] = array();
53
	$config['snmpd']['modules']['mibii'] = true;
54
	$config['snmpd']['modules']['netgraph'] = true;
55
	$config['snmpd']['modules']['pf'] = true;
56
	$config['snmpd']['modules']['hostres'] = true;
57
	$config['snmpd']['modules']['bridge'] = true;
58
	$config['snmpd']['modules']['ucd'] = true;
59
	$config['snmpd']['modules']['regex'] = true;
60
}
61
$pconfig['enable'] = isset($config['snmpd']['enable']);
62
$pconfig['pollport'] = $config['snmpd']['pollport'];
63
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
64
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
65
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
66
/* disabled until some docs show up on what this does.
67
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
68
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
69
*/
70
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
71
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
72
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
73
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
74

    
75
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
76
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
77
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
78
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
79
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
80
$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']);
81
$pconfig['regex'] = isset($config['snmpd']['modules']['regex']);
82
$pconfig['bindip'] = $config['snmpd']['bindip'];
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'],"#")) $input_errors[] = gettext("Invalid character '#' in system location");
92
 		if (strstr($_POST['syscontact'],"#")) $input_errors[] = gettext("Invalid character '#' in system contact");
93
		if (strstr($_POST['rocommunity'],"#")) $input_errors[] = gettext("Invalid character '#' in read community string");
94

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

    
99
		$reqdfields = explode(" ", "pollport");
100
		$reqdfieldsn = array(gettext("Polling Port"));
101
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
102
		
103
	
104
	}
105

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

    
123
/* disabled until some docs show up on what this does.
124
	if ($_POST['rwenable']) {
125
               $reqdfields = explode(" ", "rwcommunity");
126
               $reqdfieldsn = explode(",", "Write community string");
127
               do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
128
	}
129
*/
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
$closehead = false;
166
$pgtitle = array(gettext("Services"),gettext("SNMP"));
167
$shortcut_section = "snmp";
168
include("head.inc");
169

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

    
179
function enable_change(whichone) {
180

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

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

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

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

    
283
                <tr> 
284
  		  <td colspan="2" valign="top" class="optsect_t">
285
  			<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="enable">
286
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Daemon");?></strong></td>
287
					<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>
288
  			</table></td>
289
                </tr>
290

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

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

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

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

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

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

    
341
		<tr><td>&nbsp;</td></tr>
342

    
343
                <tr> 
344
  		  <td colspan="2" valign="top" class="optsect_t">
345
  			<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="enable">
346
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Traps");?></strong></td>
347
			<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>
348
  			</table></td>
349
                </tr>
350

    
351

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

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

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

    
376
		<tr><td>&nbsp;</td></tr>
377

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

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

    
404
		<tr><td>&nbsp;</td></tr>
405

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