Project

General

Profile

Download (15.4 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
##|+PRIV
33
##|*IDENT=page-services-snmp
34
##|*NAME=Services: SNMP page
35
##|*DESCR=Allow access to the 'Services: SNMP' page.
36
##|*MATCH=services_snmp.php*
37
##|-PRIV
38

    
39

    
40
require("guiconfig.inc");
41

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

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

    
70
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
71
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
72
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
73
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
74
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
75
$pconfig['bindlan'] = isset($config['snmpd']['bindlan']);
76

    
77
if ($_POST) {
78

    
79
	unset($input_errors);
80
	$pconfig = $_POST;
81

    
82
	/* input validation */
83
	if ($_POST['enable']) {
84
		$reqdfields = explode(" ", "rocommunity");
85
		$reqdfieldsn = explode(",", "Community");
86
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
87

    
88
		$reqdfields = explode(" ", "pollport");
89
		$reqdfieldsn = explode(",", "Polling Port");
90
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
91
		
92
	
93
	}
94

    
95
	if ($_POST['trapenable']) {
96
		$reqdfields = explode(" ", "trapserver");
97
		$reqdfieldsn = explode(",", "Trap server");
98
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
99

    
100
		$reqdfields = explode(" ", "trapserverport");
101
		$reqdfieldsn = explode(",", "Trap server port");
102
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
103

    
104
		$reqdfields = explode(" ", "trapstring");
105
		$reqdfieldsn = explode(",", "Trap string");
106
		do_input_validation($_POST, $reqdfields, $reqdfields, $reqdfieldsn, &$input_errors);
107
	}
108

    
109

    
110
/* disabled until some docs show up on what this does.
111
	if ($_POST['rwenable']) {
112
               $reqdfields = explode(" ", "rwcommunity");
113
               $reqdfieldsn = explode(",", "Write community string");
114
               do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
115
	}
116
*/
117

    
118
	
119

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

    
150
$pgtitle = array("Services","SNMP");
151
include("head.inc");
152

    
153
?>
154
<script language="JavaScript">
155
<!--
156
function enable_change(whichone) {
157

    
158
	if( whichone.name == "trapenable" )
159
        {
160
	    if( whichone.checked == true )
161
	    {
162
	        document.iform.trapserver.disabled = false;
163
	        document.iform.trapserverport.disabled = false;
164
	        document.iform.trapstring.disabled = false;
165
	    }
166
	    else
167
	    {
168
                document.iform.trapserver.disabled = true;
169
                document.iform.trapserverport.disabled = true;
170
                document.iform.trapstring.disabled = true;
171
	    }
172
	}
173

    
174
	/* disabled until some docs show up on what this does.
175
	if( whichone.name == "rwenable"  )
176
	{
177
	    if( whichone.checked == true )
178
	    {
179
		document.iform.rwcommunity.disabled = false;
180
	    }
181
	    else
182
	    {
183
		document.iform.rwcommunity.disabled = true;
184
	    }
185
	}
186
	*/
187

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

    
240
            document.iform.mibii.disabled = true;
241
            document.iform.netgraph.disabled = true;
242
            document.iform.pf.disabled = true;
243
            document.iform.hostres.disabled = true;
244
            document.iform.bridge.disabled = true;
245
	    
246
	    document.iform.bindlan.disabled = true;
247
	}
248
}
249
//-->
250
</script>
251
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
252
<?php include("fbegin.inc"); ?>
253
<?php if ($input_errors) print_input_errors($input_errors); ?>
254
<?php if ($savemsg) print_info_box($savemsg); ?>
255
            <form action="services_snmp.php" method="post" name="iform" id="iform">
256
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
257

    
258
                <tr> 
259
  		  <td colspan="2" valign="top" class="optsect_t">
260
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
261
  			<tr><td class="optsect_s"><strong>SNMP Daemon</strong></td>
262
			<td align="right" class="optsect_s"><input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(this)"> <strong>Enable</strong></td></tr>
263
  			</table></td>
264
                </tr>
265

    
266
                <tr>
267
                  <td width="22%" valign="top" class="vncellreq">Polling Port </td>
268
                  <td width="78%" class="vtable">
269
                    <input name="pollport" type="text" class="formfld unknown" id="pollport" size="40" value="<?=$pconfig['pollport'] ? htmlspecialchars($pconfig['pollport']) : htmlspecialchars(161);?>">
270
                    <br>Enter the port to accept polling events on (default 161)</br>
271
		  </td>
272
                </tr>
273

    
274
                <tr> 
275
                  <td width="22%" valign="top" class="vncell">System location</td>
276
                  <td width="78%" class="vtable"> 
277
                    <input name="syslocation" type="text" class="formfld unknown" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>"> 
278
                  </td>
279
                </tr>
280

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

    
288
                <tr> 
289
                  <td width="22%" valign="top" class="vncellreq">Read Community String</td>
290
                  <td width="78%" class="vtable"> 
291
                    <input name="rocommunity" type="text" class="formfld unknown" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>"> 
292
                    <br>In most cases, &quot;public&quot; is used here</br>
293
		  </td>
294
                </tr>
295

    
296
<?php 
297
			/* disabled until some docs show up on what this does.
298
                <tr>
299
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
300
                  <td width="78%" class="vtable">
301
	 	   <input name="rwenable" type="checkbox" value="yes" <?php if ($pconfig['rwenable']) echo "checked"; ?> onClick="enable_change(this)">
302
                    <strong>Enable Write Community String</strong>
303
		  </td>
304
                </tr>
305

    
306
		<tr>
307
		  <td width="22%" valign="top" class="vncellreq">Write community string</td>
308
          <td width="78%" class="vtable">
309
                    <input name="rwcommunity" type="text" class="formfld unknown" id="rwcommunity" size="40" value="<?=htmlspecialchars($pconfig['rwcommunity']);?>">
310
		    <br>Please use something other then &quot;private&quot; here</br>
311
		  </td>
312
                </tr>
313
		    	*/ 
314
?>
315

    
316
		<tr><td>&nbsp;</td></tr>
317

    
318
                <tr> 
319
  		  <td colspan="2" valign="top" class="optsect_t">
320
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
321
  			<tr><td class="optsect_s"><strong>SNMP Traps</strong></td>
322
			<td align="right" class="optsect_s"><input name="trapenable" type="checkbox" value="yes" <?php if ($pconfig['trapenable']) echo "checked"; ?> onClick="enable_change(this)"> <strong>Enable</strong></td></tr>
323
  			</table></td>
324
                </tr>
325

    
326

    
327
                <tr>
328
                  <td width="22%" valign="top" class="vncellreq">Trap server</td>
329
                  <td width="78%" class="vtable">
330
                    <input name="trapserver" type="text" class="formfld unknown" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>">
331
                    <br>Enter trap server name</br>
332
		  </td>
333
                </tr>
334

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

    
343
                <tr>
344
                  <td width="22%" valign="top" class="vncellreq">Enter the SNMP trap string</td>
345
                  <td width="78%" class="vtable">
346
                    <input name="trapstring" type="text" class="formfld unknown" id="trapstring" size="40" value="<?=htmlspecialchars($pconfig['trapstring']);?>">
347
                    <br>Trap string</br>
348
		  </td>
349
                </tr>
350

    
351
		<tr><td>&nbsp;</td></tr>
352

    
353
                <tr> 
354
  		  <td colspan="2" valign="top" class="optsect_t">
355
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
356
  			<tr><td class="optsect_s"><strong>Modules</strong></td>
357
			<td align="right" class="optsect_s">&nbsp;</td></tr>
358
  			</table></td>
359
                </tr>
360

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