Projet

Général

Profil

Télécharger (17,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_snmp.php @ 2d1e985d

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
$pgtitle = array(gettext("Services"),gettext("SNMP"));
166
$shortcut_section = "snmp";
167
include("head.inc");
168

    
169
?>
170
<script language="JavaScript">
171
<!--
172
function check_deps() {
173
	if (jQuery('#hostres').prop('checked') == true) {
174
		jQuery('#mibii').prop('checked',true);
175
	}
176
}
177

    
178
function enable_change(whichone) {
179

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

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

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

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

    
281
                <tr> 
282
  		  <td colspan="2" valign="top" class="optsect_t">
283
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
284
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Daemon");?></strong></td>
285
					<td align="right" class="optsect_s"><input name="enable" id="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(this)"> <strong><?=gettext("Enable");?></strong></td></tr>
286
  			</table></td>
287
                </tr>
288

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

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

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

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

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

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

    
339
		<tr><td>&nbsp;</td></tr>
340

    
341
                <tr> 
342
  		  <td colspan="2" valign="top" class="optsect_t">
343
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
344
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Traps");?></strong></td>
345
			<td align="right" class="optsect_s"><input name="trapenable" id="trapenable" type="checkbox" value="yes" <?php if ($pconfig['trapenable']) echo "checked"; ?> onClick="enable_change(this)"> <strong><?=gettext("Enable");?></strong></td></tr>
346
  			</table></td>
347
                </tr>
348

    
349

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

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

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

    
374
		<tr><td>&nbsp;</td></tr>
375

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

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

    
402
		<tr><td>&nbsp;</td></tr>
403

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