Project

General

Profile

Download (15.5 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

    
146
		config_lock();
147
		$retval = services_snmpd_configure();
148
		config_unlock();
149

    
150
		$savemsg = get_std_save_message($retval);
151
	}
152
}
153

    
154
$pgtitle = array("Services","SNMP");
155
include("head.inc");
156

    
157
?>
158
<script language="JavaScript">
159
<!--
160
function enable_change(whichone) {
161

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

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

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

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

    
262
                <tr> 
263
  		  <td colspan="2" valign="top" class="optsect_t">
264
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
265
  			<tr><td class="optsect_s"><strong>SNMP Daemon</strong></td>
266
			<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>
267
  			</table></td>
268
                </tr>
269

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

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

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

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

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

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

    
320
		<tr><td>&nbsp;</td></tr>
321

    
322
                <tr> 
323
  		  <td colspan="2" valign="top" class="optsect_t">
324
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
325
  			<tr><td class="optsect_s"><strong>SNMP Traps</strong></td>
326
			<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>
327
  			</table></td>
328
                </tr>
329

    
330

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

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

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

    
355
		<tr><td>&nbsp;</td></tr>
356

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

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