Project

General

Profile

Download (13.6 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/* $Id$ */
4
/*
5
	services_snmp.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
require("guiconfig.inc");
34

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

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

    
61
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
62
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
63
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
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
	if ($_POST['trapenable']) {
82
		$reqdfields = explode(" ", "trapserver");
83
		$reqdfieldsn = explode(",", "Trap server");
84
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
85

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

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

    
95

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

    
104
	
105

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

    
137
$pgtitle = "Services: SNMP";
138
include("head.inc");
139

    
140
?>
141
<script language="JavaScript">
142
<!--
143
function enable_change(whichone) {
144

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

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

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

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

    
239
                <tr> 
240
  		  <td colspan="2" valign="top" class="optsect_t">
241
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
242
  			<tr><td class="optsect_s"><strong>SNMP Daemon</strong></td>
243
			<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>
244
  			</table></td>
245
                </tr>
246

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

    
255
                <tr> 
256
                  <td width="22%" valign="top" class="vncell">System location</td>
257
                  <td width="78%" class="vtable"> 
258
                    <input name="syslocation" type="text" class="formfld" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>"> 
259
                  </td>
260
                </tr>
261

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

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

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

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

    
297
                <tr>
298
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
299
                  <td width="78%" class="vtable">
300
                   <input name="trapenable" type="checkbox" value="yes" <?php if ($pconfig['trapenable']) echo "checked"; ?> onClick="enable_change(this)">
301
                    <strong>Enable SNMP Traps</strong>
302
                  </td>
303
                </tr>
304

    
305
                <tr>
306
                  <td width="22%" valign="top" class="vncellreq">Trap server</td>
307
                  <td width="78%" class="vtable">
308
                    <input name="trapserver" type="text" class="formfld" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>">
309
                    <br>Enter trap server name</br>
310
		  </td>
311
                </tr>
312

    
313
                <tr>
314
                  <td width="22%" valign="top" class="vncellreq">Trap server port </td>
315
                  <td width="78%" class="vtable">
316
                    <input name="trapserverport" type="text" class="formfld" id="trapserverport" size="40" value="<?=$pconfig['trapserverport'] ? htmlspecialchars($pconfig['trapserverport']) : htmlspecialchars(162);?>">
317
                    <br>Enter the port to send the traps to (default 162)</br>
318
		  </td>
319
                </tr>
320

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

    
329
		<tr>
330
		  <td width="22%" valign="top" class="vncellreq">SNMP Modules</td>
331
		  <td width="78%" class="vtable">
332
		    <input name="mibii" type="checkbox" id="mibii" value="yes" <?php if ($pconfig['mibii']) echo "checked"; ?> >MibII
333
		    <input name="netgraph" type="checkbox" id="netgraph" value="yes" <?php if ($pconfig['netgraph']) echo "checked"; ?> >Netgraph
334
		    <input name="pf" type="checkbox" id="pf" value="yes" <?php if ($pconfig['pf']) echo "checked"; ?> >PF
335
		  </td>
336
		</tr>
337

    
338
                <tr> 
339
                  <td width="22%" valign="top">&nbsp;</td>
340
                  <td width="78%"> 
341
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)"> 
342
                  </td>
343
                </tr>
344
              </table>
345
</form>
346
<script language="JavaScript">
347
<!--
348
enable_change(this);
349
//-->
350
</script>
351
<?php include("fend.inc"); ?>
352
</body>
353
</html>
(103-103/144)