Project

General

Profile

Download (15.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
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
		$reqdfields = explode(" ", "syscontact");
81
		$reqdfieldsn = explode(",", "System contact");
82
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);		
83

    
84
		$reqdfields = explode(" ", "syslocation");
85
		$reqdfieldsn = explode(",", "System location");
86
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);			
87
	}
88

    
89
	if ($_POST['trapenable']) {
90
		$reqdfields = explode(" ", "trapserver");
91
		$reqdfieldsn = explode(",", "Trap server");
92
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
93

    
94
		$reqdfields = explode(" ", "trapserverport");
95
		$reqdfieldsn = explode(",", "Trap server port");
96
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
97

    
98
		$reqdfields = explode(" ", "trapstring");
99
		$reqdfieldsn = explode(",", "Trap string");
100
		do_input_validation($_POST, $reqdfields, $reqdfields, $reqdfieldsn, &$input_errors);
101
	}
102

    
103

    
104
/* disabled until some docs show up on what this does.
105
	if ($_POST['rwenable']) {
106
               $reqdfields = explode(" ", "rwcommunity");
107
               $reqdfieldsn = explode(",", "Write community string");
108
               do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
109
	}
110
*/
111

    
112
	
113

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

    
138
		config_lock();
139
		$retval = services_snmpd_configure();
140
		config_unlock();
141

    
142
		$savemsg = get_std_save_message($retval);
143
	}
144
}
145

    
146
$pgtitle = "Services: SNMP";
147
include("head.inc");
148

    
149
?>
150
<script language="JavaScript">
151
<!--
152
function enable_change(whichone) {
153

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

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

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

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

    
251
                <tr> 
252
  		  <td colspan="2" valign="top" class="optsect_t">
253
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
254
  			<tr><td class="optsect_s"><strong>SNMP Daemon</strong></td>
255
			<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>
256
  			</table></td>
257
                </tr>
258

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

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

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

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

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

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

    
309
                <tr> 
310
                  <td width="22%" valign="top">&nbsp;</td>
311
                  <td width="78%"> 
312
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)"> 
313
                  </td>
314
                </tr>
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" 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" 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" id="trapstring" size="40" value="<?=htmlspecialchars($pconfig['trapstring']);?>">
347
                    <br>Trap string</br>
348
		  </td>
349
                </tr>
350

    
351
                <tr> 
352
                  <td width="22%" valign="top">&nbsp;</td>
353
                  <td width="78%"> 
354
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)"> 
355
                  </td>
356
                </tr>
357

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

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

    
368
		<tr>
369
		  <td width="22%" valign="top" class="vncellreq">SNMP Modules</td>
370
		  <td width="78%" class="vtable">
371
		    <input name="mibii" type="checkbox" id="mibii" value="yes" <?php if ($pconfig['mibii']) echo "checked"; ?> >MibII
372
		    <br>
373
		    <input name="netgraph" type="checkbox" id="netgraph" value="yes" <?php if ($pconfig['netgraph']) echo "checked"; ?> >Netgraph
374
		    <br>
375
		    <input name="pf" type="checkbox" id="pf" value="yes" <?php if ($pconfig['pf']) echo "checked"; ?> >PF
376
		  </td>
377
		</tr>
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
                <tr> 
387
                  <td width="22%" valign="top">&nbsp;</td>
388
                  <td width="78%"> 
389
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)"> 
390
                  </td>
391
                </tr>
392
              </table>
393
</form>
394
<script language="JavaScript">
395
<!--
396
enable_change(this);
397
//-->
398
</script>
399
<?php include("fend.inc"); ?>
400
</body>
401
</html>
(112-112/160)