Project

General

Profile

Download (16.6 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
	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
}
59
$pconfig['enable'] = isset($config['snmpd']['enable']);
60
$pconfig['pollport'] = $config['snmpd']['pollport'];
61
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
62
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
63
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
64
/* disabled until some docs show up on what this does.
65
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
66
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
67
*/
68
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
69
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
70
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
71
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
72

    
73
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
74
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
75
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
76
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
77
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
78
$pconfig['bindlan'] = isset($config['snmpd']['bindlan']);
79

    
80
if ($_POST) {
81

    
82
	unset($input_errors);
83
	$pconfig = $_POST;
84

    
85
	/* input validation */
86
	if ($_POST['enable']) {
87
		if (strstr($_POST['syslocation'],"#")) $input_errors[] = gettext("Invalid character '#' in system location");
88
 		if (strstr($_POST['syscontact'],"#")) $input_errors[] = gettext("Invalid character '#' in system contact");
89
		if (strstr($_POST['rocommunity'],"#")) $input_errors[] = gettext("Invalid character '#' in read community string");
90

    
91
		$reqdfields = explode(" ", "rocommunity");
92
		$reqdfieldsn = array(gettext("Community"));
93
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
94

    
95
		$reqdfields = explode(" ", "pollport");
96
		$reqdfieldsn = array(gettext("Polling Port"));
97
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
98
		
99
	
100
	}
101

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

    
105
		$reqdfields = explode(" ", "trapserver");
106
		$reqdfieldsn = array(gettext("Trap server"));
107
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
108

    
109
		$reqdfields = explode(" ", "trapserverport");
110
		$reqdfieldsn = array(gettext("Trap server port"));
111
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
112

    
113
		$reqdfields = explode(" ", "trapstring");
114
		$reqdfieldsn = array(gettext("Trap string"));
115
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
116
	}
117

    
118

    
119
/* disabled until some docs show up on what this does.
120
	if ($_POST['rwenable']) {
121
               $reqdfields = explode(" ", "rwcommunity");
122
               $reqdfieldsn = explode(",", "Write community string");
123
               do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
124
	}
125
*/
126

    
127
	
128

    
129
	if (!$input_errors) {
130
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
131
		$config['snmpd']['pollport'] = $_POST['pollport'];
132
		$config['snmpd']['syslocation'] = $_POST['syslocation'];	
133
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
134
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
135
		/* disabled until some docs show up on what this does.
136
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
137
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
138
		*/
139
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
140
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
141
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
142
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
143
		
144
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
145
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
146
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
147
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
148
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
149
		$config['snmpd']['bindlan'] = $_POST['bindlan'] ? true : false;
150
			
151
		write_config();
152
		
153
		$retval = 0;
154
		$retval = services_snmpd_configure();
155
		$savemsg = get_std_save_message($retval);
156
	}
157
}
158

    
159
$pgtitle = array(gettext("Services"),gettext("SNMP"));
160
include("head.inc");
161

    
162
?>
163
<script language="JavaScript">
164
<!--
165
function enable_change(whichone) {
166

    
167
	if( whichone.name == "trapenable" )
168
        {
169
	    if( whichone.checked == true )
170
	    {
171
	        document.iform.trapserver.disabled = false;
172
	        document.iform.trapserverport.disabled = false;
173
	        document.iform.trapstring.disabled = false;
174
	    }
175
	    else
176
	    {
177
                document.iform.trapserver.disabled = true;
178
                document.iform.trapserverport.disabled = true;
179
                document.iform.trapstring.disabled = true;
180
	    }
181
	}
182

    
183
	/* disabled until some docs show up on what this does.
184
	if( whichone.name == "rwenable"  )
185
	{
186
	    if( whichone.checked == true )
187
	    {
188
		document.iform.rwcommunity.disabled = false;
189
	    }
190
	    else
191
	    {
192
		document.iform.rwcommunity.disabled = true;
193
	    }
194
	}
195
	*/
196

    
197
	if( document.iform.enable.checked == true )
198
	{
199
	    document.iform.pollport.disabled = false;
200
	    document.iform.syslocation.disabled = false;
201
	    document.iform.syscontact.disabled = false;
202
	    document.iform.rocommunity.disabled = false;
203
	    document.iform.trapenable.disabled = false;
204
	    //document.iform.bindlan.disabled = false;
205
	    /* disabled until some docs show up on what this does.
206
	    document.iform.rwenable.disabled = false;
207
	    if( document.iform.rwenable.checked == true )
208
	    {
209
	        document.iform.rwcommunity.disabled = false;
210
	    }
211
	    else
212
	    {
213
		document.iform.rwcommunity.disabled = true;
214
	    }
215
	    */
216
	    if( document.iform.trapenable.checked == true )
217
	    {
218
                document.iform.trapserver.disabled = false;
219
                document.iform.trapserverport.disabled = false;
220
                document.iform.trapstring.disabled = false;
221
	    }
222
	    else
223
	    {
224
                document.iform.trapserver.disabled = true;
225
                document.iform.trapserverport.disabled = true;
226
                document.iform.trapstring.disabled = true;
227
	    }
228
	    document.iform.mibii.disabled = false;
229
	    document.iform.netgraph.disabled = false;
230
	    document.iform.pf.disabled = false;
231
	    document.iform.hostres.disabled = false;
232
	    //document.iform.bridge.disabled = false;
233
	}
234
	else
235
	{
236
            document.iform.pollport.disabled = true;
237
            document.iform.syslocation.disabled = true;
238
            document.iform.syscontact.disabled = true;
239
            document.iform.rocommunity.disabled = true;
240
	    /* 
241
            document.iform.rwenable.disabled = true;
242
	    document.iform.rwcommunity.disabled = true;
243
	    */
244
            document.iform.trapenable.disabled = true;
245
            document.iform.trapserver.disabled = true;
246
            document.iform.trapserverport.disabled = true;
247
            document.iform.trapstring.disabled = true;
248

    
249
            document.iform.mibii.disabled = true;
250
            document.iform.netgraph.disabled = true;
251
            document.iform.pf.disabled = true;
252
            document.iform.hostres.disabled = true;
253
            //document.iform.bridge.disabled = true;
254
	    //document.iform.bindlan.disabled = true;
255
	}
256
}
257
//-->
258
</script>
259
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
260
<?php include("fbegin.inc"); ?>
261
<?php if ($input_errors) print_input_errors($input_errors); ?>
262
<?php if ($savemsg) print_info_box($savemsg); ?>
263
            <form action="services_snmp.php" method="post" name="iform" id="iform">
264
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
265

    
266
                <tr> 
267
  		  <td colspan="2" valign="top" class="optsect_t">
268
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
269
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Daemon");?></strong></td>
270
					<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>
271
  			</table></td>
272
                </tr>
273

    
274
                <tr>
275
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Polling Port ");?></td>
276
                  <td width="78%" class="vtable">
277
                    <input name="pollport" type="text" class="formfld unknown" id="pollport" size="40" value="<?=$pconfig['pollport'] ? htmlspecialchars($pconfig['pollport']) : htmlspecialchars(161);?>">
278
                    <br><?=gettext("Enter the port to accept polling events on (default 161)");?></br>
279
		  </td>
280
                </tr>
281

    
282
                <tr> 
283
                  <td width="22%" valign="top" class="vncell"><?=gettext("System location");?></td>
284
                  <td width="78%" class="vtable"> 
285
                    <input name="syslocation" type="text" class="formfld unknown" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>"> 
286
                  </td>
287
                </tr>
288

    
289
                <tr> 
290
                  <td width="22%" valign="top" class="vncell"><?=gettext("System contact");?></td>
291
                  <td width="78%" class="vtable"> 
292
                    <input name="syscontact" type="text" class="formfld unknown" id="syscontact" size="40" value="<?=htmlspecialchars($pconfig['syscontact']);?>"> 
293
                  </td>
294
                </tr>
295

    
296
                <tr> 
297
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Read Community String");?></td>
298
                  <td width="78%" class="vtable"> 
299
                    <input name="rocommunity" type="text" class="formfld unknown" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>"> 
300
		    <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>
301
		  </td>
302
                </tr>
303

    
304
<?php 
305
			/* disabled until some docs show up on what this does.
306
                <tr>
307
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
308
                  <td width="78%" class="vtable">
309
	 	   <input name="rwenable" id="rwenable" type="checkbox" value="yes" <?php if ($pconfig['rwenable']) echo "checked"; ?> onClick="enable_change(this)">
310
                    <strong>Enable Write Community String</strong>
311
		  </td>
312
                </tr>
313

    
314
		<tr>
315
		  <td width="22%" valign="top" class="vncellreq">Write community string</td>
316
          <td width="78%" class="vtable">
317
                    <input name="rwcommunity" type="text" class="formfld unknown" id="rwcommunity" size="40" value="<?=htmlspecialchars($pconfig['rwcommunity']);?>">
318
		    <br>Please use something other then &quot;private&quot; here</br>
319
		  </td>
320
                </tr>
321
		    	*/ 
322
?>
323

    
324
		<tr><td>&nbsp;</td></tr>
325

    
326
                <tr> 
327
  		  <td colspan="2" valign="top" class="optsect_t">
328
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
329
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Traps");?></strong></td>
330
			<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>
331
  			</table></td>
332
                </tr>
333

    
334

    
335
                <tr>
336
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Trap server");?></td>
337
                  <td width="78%" class="vtable">
338
                    <input name="trapserver" type="text" class="formfld unknown" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>">
339
                    <br><?=gettext("Enter trap server name");?></br>
340
		  </td>
341
                </tr>
342

    
343
                <tr>
344
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Trap server port ");?></td>
345
                  <td width="78%" class="vtable">
346
                    <input name="trapserverport" type="text" class="formfld unknown" id="trapserverport" size="40" value="<?=$pconfig['trapserverport'] ? htmlspecialchars($pconfig['trapserverport']) : htmlspecialchars(162);?>">
347
                    <br><?=gettext("Enter the port to send the traps to (default 162)");?></br>
348
		  </td>
349
                </tr>
350

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

    
359
		<tr><td>&nbsp;</td></tr>
360

    
361
                <tr> 
362
  		  <td colspan="2" valign="top" class="optsect_t">
363
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
364
  			<tr><td class="optsect_s"><strong><?=gettext("Modules");?></strong></td>
365
			<td align="right" class="optsect_s">&nbsp;</td></tr>
366
  			</table></td>
367
                </tr>
368

    
369
		<tr>
370
		  <td width="22%" valign="top" class="vncellreq"><?=gettext("SNMP Modules");?></td>
371
		  <td width="78%" class="vtable">
372
		    <input name="mibii" type="checkbox" id="mibii" value="yes" <?php if ($pconfig['mibii']) echo "checked"; ?> ><?=gettext("MibII"); ?>
373
		    <br />
374
		    <input name="netgraph" type="checkbox" id="netgraph" value="yes" <?php if ($pconfig['netgraph']) echo "checked"; ?> ><?=gettext("Netgraph"); ?>
375
		    <br />
376
		    <input name="pf" type="checkbox" id="pf" value="yes" <?php if ($pconfig['pf']) echo "checked"; ?> ><?=gettext("PF"); ?>
377
		    <br />
378
		    <input name="hostres" type="checkbox" id="hostres" value="yes" <?php if ($pconfig['hostres']) echo "checked"; ?> ><?=gettext("Host Resources");?>
379
		  </td>
380
		</tr>
381
<?php if(!$config['interfaces']['lan']): ?>
382
		 <tr> 
383
		   <td width="22%" valign="top" class="vtable"></td>
384
		   <td width="78%" class="vtable"> 
385
		     <input name="bindlan" type="checkbox" value="yes" <?php if ($pconfig['bindlan']) echo "checked"; ?>> <strong><?=gettext("Bind to LAN interface only");?></strong>
386
		     <br>
387
		     <?=gettext("This option can be useful when trying to access the SNMP agent".
388
            	    " by the LAN interface's IP address through a VPN tunnel terminated on the WAN interface.");?></td>
389
		 </tr>
390
<?php endif; ?>
391
		 <tr> 
392
		   <td width="22%" valign="top">&nbsp;</td>
393
		   <td width="78%"> 
394
		     <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)"> 
395
		   </td>
396
		 </tr>
397
		</table>
398
</form>
399
<script language="JavaScript">
400
<!--
401
enable_change(this);
402
//-->
403
</script>
404
<?php include("fend.inc"); ?>
405
</body>
406
</html>
(145-145/220)