Project

General

Profile

Download (15.3 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
require("guiconfig.inc");
33

    
34
if (!is_array($config['snmpd'])) {
35
	$config['snmpd'] = array();
36
	$config['snmpd']['rocommunity'] = "public";
37
	$config['snmpd']['pollport'] = "161";
38
}
39

    
40
if (!is_array($config['snmpd']['modules'])) {
41
	$config['snmpd']['modules'] = array();
42
	$config['snmpd']['modules']['mibii'] = true;
43
	$config['snmpd']['modules']['netgraph'] = true;
44
	$config['snmpd']['modules']['pf'] = true;
45
}
46
$pconfig['enable'] = isset($config['snmpd']['enable']);
47
$pconfig['pollport'] = $config['snmpd']['pollport'];
48
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
49
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
50
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
51
/* disabled until some docs show up on what this does.
52
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
53
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
54
*/
55
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
56
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
57
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
58
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
59

    
60
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
61
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
62
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
63
$pconfig['bindlan'] = isset($config['snmpd']['bindlan']);
64

    
65
if ($_POST) {
66

    
67
	unset($input_errors);
68
	$pconfig = $_POST;
69

    
70
	/* input validation */
71
	if ($_POST['enable']) {
72
		$reqdfields = explode(" ", "rocommunity");
73
		$reqdfieldsn = explode(",", "Community");
74
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
75

    
76
		$reqdfields = explode(" ", "pollport");
77
		$reqdfieldsn = explode(",", "Polling Port");
78
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
79
		
80
	
81
	}
82

    
83
	if ($_POST['trapenable']) {
84
		$reqdfields = explode(" ", "trapserver");
85
		$reqdfieldsn = explode(",", "Trap server");
86
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
87

    
88
		$reqdfields = explode(" ", "trapserverport");
89
		$reqdfieldsn = explode(",", "Trap server port");
90
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
91

    
92
		$reqdfields = explode(" ", "trapstring");
93
		$reqdfieldsn = explode(",", "Trap string");
94
		do_input_validation($_POST, $reqdfields, $reqdfields, $reqdfieldsn, &$input_errors);
95
	}
96

    
97

    
98
/* disabled until some docs show up on what this does.
99
	if ($_POST['rwenable']) {
100
               $reqdfields = explode(" ", "rwcommunity");
101
               $reqdfieldsn = explode(",", "Write community string");
102
               do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
103
	}
104
*/
105

    
106
	
107

    
108
	if (!$input_errors) {
109
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
110
		$config['snmpd']['pollport'] = $_POST['pollport'];
111
		$config['snmpd']['syslocation'] = $_POST['syslocation'];	
112
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
113
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
114
		/* disabled until some docs show up on what this does.
115
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
116
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
117
		*/
118
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
119
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
120
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
121
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
122
		
123
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
124
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
125
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
126
		$config['snmpd']['bindlan'] = $_POST['bindlan'] ? true : false;
127
			
128
		write_config();
129
		
130
		$retval = 0;
131

    
132
		config_lock();
133
		$retval = services_snmpd_configure();
134
		config_unlock();
135

    
136
		$savemsg = get_std_save_message($retval);
137
	}
138
}
139

    
140
$pgtitle = "Services: SNMP";
141
include("head.inc");
142

    
143
?>
144
<script language="JavaScript">
145
<!--
146
function enable_change(whichone) {
147

    
148
	if( whichone.name == "trapenable" )
149
        {
150
	    if( whichone.checked == true )
151
	    {
152
	        document.iform.trapserver.disabled = false;
153
	        document.iform.trapserverport.disabled = false;
154
	        document.iform.trapstring.disabled = false;
155
	    }
156
	    else
157
	    {
158
                document.iform.trapserver.disabled = true;
159
                document.iform.trapserverport.disabled = true;
160
                document.iform.trapstring.disabled = true;
161
	    }
162
	}
163

    
164
	/* disabled until some docs show up on what this does.
165
	if( whichone.name == "rwenable"  )
166
	{
167
	    if( whichone.checked == true )
168
	    {
169
		document.iform.rwcommunity.disabled = false;
170
	    }
171
	    else
172
	    {
173
		document.iform.rwcommunity.disabled = true;
174
	    }
175
	}
176
	*/
177

    
178
	if( document.iform.enable.checked == true )
179
	{
180
	    document.iform.pollport.disabled = false;
181
	    document.iform.syslocation.disabled = false;
182
	    document.iform.syscontact.disabled = false;
183
	    document.iform.rocommunity.disabled = false;
184
	    document.iform.trapenable.disabled = false;
185
	    document.iform.bindlan.disabled = false;
186
	    /* disabled until some docs show up on what this does.
187
	    document.iform.rwenable.disabled = false;
188
	    if( document.iform.rwenable.checked == true )
189
	    {
190
	        document.iform.rwcommunity.disabled = false;
191
	    }
192
	    else
193
	    {
194
		document.iform.rwcommunity.disabled = true;
195
	    }
196
	    */
197
	    if( document.iform.trapenable.checked == true )
198
	    {
199
                document.iform.trapserver.disabled = false;
200
                document.iform.trapserverport.disabled = false;
201
                document.iform.trapstring.disabled = false;
202
	    }
203
	    else
204
	    {
205
                document.iform.trapserver.disabled = true;
206
                document.iform.trapserverport.disabled = true;
207
                document.iform.trapstring.disabled = true;
208
	    }
209
	    document.iform.mibii.disabled = false;
210
	    document.iform.netgraph.disabled = false;
211
	    document.iform.pf.disabled = false;
212
	}
213
	else
214
	{
215
            document.iform.pollport.disabled = true;
216
            document.iform.syslocation.disabled = true;
217
            document.iform.syscontact.disabled = true;
218
            document.iform.rocommunity.disabled = true;
219
	    /* 
220
            document.iform.rwenable.disabled = true;
221
	    document.iform.rwcommunity.disabled = true;
222
	    */
223
            document.iform.trapenable.disabled = true;
224
            document.iform.trapserver.disabled = true;
225
            document.iform.trapserverport.disabled = true;
226
            document.iform.trapstring.disabled = true;
227

    
228
            document.iform.mibii.disabled = true;
229
            document.iform.netgraph.disabled = true;
230
            document.iform.pf.disabled = true;
231
	    
232
	    document.iform.bindlan.disabled = true;
233
	}
234
}
235
//-->
236
</script>
237
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
238
<?php include("fbegin.inc"); ?>
239
<p class="pgtitle"><?=$pgtitle?></p>
240
<?php if ($input_errors) print_input_errors($input_errors); ?>
241
<?php if ($savemsg) print_info_box($savemsg); ?>
242
            <form action="services_snmp.php" method="post" name="iform" id="iform">
243
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
244

    
245
                <tr> 
246
  		  <td colspan="2" valign="top" class="optsect_t">
247
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
248
  			<tr><td class="optsect_s"><strong>SNMP Daemon</strong></td>
249
			<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>
250
  			</table></td>
251
                </tr>
252

    
253
                <tr>
254
                  <td width="22%" valign="top" class="vncellreq">Polling Port </td>
255
                  <td width="78%" class="vtable">
256
                    <input name="pollport" type="text" class="formfld" id="pollport" size="40" value="<?=$pconfig['pollport'] ? htmlspecialchars($pconfig['pollport']) : htmlspecialchars(161);?>">
257
                    <br>Enter the port to accept polling events on (default 161)</br>
258
		  </td>
259
                </tr>
260

    
261
                <tr> 
262
                  <td width="22%" valign="top" class="vncell">System location</td>
263
                  <td width="78%" class="vtable"> 
264
                    <input name="syslocation" type="text" class="formfld" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>"> 
265
                  </td>
266
                </tr>
267

    
268
                <tr> 
269
                  <td width="22%" valign="top" class="vncell">System contact</td>
270
                  <td width="78%" class="vtable"> 
271
                    <input name="syscontact" type="text" class="formfld" id="syscontact" size="40" value="<?=htmlspecialchars($pconfig['syscontact']);?>"> 
272
                  </td>
273
                </tr>
274

    
275
                <tr> 
276
                  <td width="22%" valign="top" class="vncellreq">Read Community String</td>
277
                  <td width="78%" class="vtable"> 
278
                    <input name="rocommunity" type="text" class="formfld" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>"> 
279
                    <br>In most cases, &quot;public&quot; is used here</br>
280
		  </td>
281
                </tr>
282

    
283
<?php 
284
			/* disabled until some docs show up on what this does.
285
                <tr>
286
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
287
                  <td width="78%" class="vtable">
288
	 	   <input name="rwenable" type="checkbox" value="yes" <?php if ($pconfig['rwenable']) echo "checked"; ?> onClick="enable_change(this)">
289
                    <strong>Enable Write Community String</strong>
290
		  </td>
291
                </tr>
292

    
293
		<tr>
294
		  <td width="22%" valign="top" class="vncellreq">Write community string</td>
295
          <td width="78%" class="vtable">
296
                    <input name="rwcommunity" type="text" class="formfld" id="rwcommunity" size="40" value="<?=htmlspecialchars($pconfig['rwcommunity']);?>">
297
		    <br>Please use something other then &quot;private&quot; here</br>
298
		  </td>
299
                </tr>
300
		    	*/ 
301
?>
302

    
303
                <tr> 
304
                  <td width="22%" valign="top">&nbsp;</td>
305
                  <td width="78%"> 
306
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)"> 
307
                  </td>
308
                </tr>
309

    
310
		<tr><td>&nbsp;</td></tr>
311

    
312
                <tr> 
313
  		  <td colspan="2" valign="top" class="optsect_t">
314
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
315
  			<tr><td class="optsect_s"><strong>SNMP Traps</strong></td>
316
			<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>
317
  			</table></td>
318
                </tr>
319

    
320

    
321
                <tr>
322
                  <td width="22%" valign="top" class="vncellreq">Trap server</td>
323
                  <td width="78%" class="vtable">
324
                    <input name="trapserver" type="text" class="formfld" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>">
325
                    <br>Enter trap server name</br>
326
		  </td>
327
                </tr>
328

    
329
                <tr>
330
                  <td width="22%" valign="top" class="vncellreq">Trap server port </td>
331
                  <td width="78%" class="vtable">
332
                    <input name="trapserverport" type="text" class="formfld" id="trapserverport" size="40" value="<?=$pconfig['trapserverport'] ? htmlspecialchars($pconfig['trapserverport']) : htmlspecialchars(162);?>">
333
                    <br>Enter the port to send the traps to (default 162)</br>
334
		  </td>
335
                </tr>
336

    
337
                <tr>
338
                  <td width="22%" valign="top" class="vncellreq">Enter the SNMP trap string</td>
339
                  <td width="78%" class="vtable">
340
                    <input name="trapstring" type="text" class="formfld" id="trapstring" size="40" value="<?=htmlspecialchars($pconfig['trapstring']);?>">
341
                    <br>Trap string</br>
342
		  </td>
343
                </tr>
344

    
345
                <tr> 
346
                  <td width="22%" valign="top">&nbsp;</td>
347
                  <td width="78%"> 
348
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)"> 
349
                  </td>
350
                </tr>
351

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

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

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