Project

General

Profile

Download (13.6 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php 
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
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 3805bfdd John Fleming
	$config['snmpd']['pollport'] = "161";
39 5b237745 Scott Ullrich
}
40
41 3805bfdd John Fleming
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 4f4d63d8 John Fleming
$pconfig['enable'] = isset($config['snmpd']['enable']);
48 3805bfdd John Fleming
$pconfig['pollport'] = $config['snmpd']['pollport'];
49 5b237745 Scott Ullrich
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
50
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
51
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
52 4f4d63d8 John Fleming
/* 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 8c3c9dc2 John Fleming
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
60 5b237745 Scott Ullrich
61 3805bfdd John Fleming
$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 5b237745 Scott Ullrich
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 3805bfdd John Fleming
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
75
76
		$reqdfields = explode(" ", "pollport");
77
		$reqdfieldsn = explode(",", "Polling Port");
78 5b237745 Scott Ullrich
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
79
	}
80
81 4f4d63d8 John Fleming
	if ($_POST['trapenable']) {
82
		$reqdfields = explode(" ", "trapserver");
83
		$reqdfieldsn = explode(",", "Trap server");
84
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
85 3805bfdd John Fleming
86 4f4d63d8 John Fleming
		$reqdfields = explode(" ", "trapserverport");
87
		$reqdfieldsn = explode(",", "Trap server port");
88
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
89 3805bfdd John Fleming
90 8c3c9dc2 John Fleming
		$reqdfields = explode(" ", "trapstring");
91
		$reqdfieldsn = explode(",", "Trap string");
92
		do_input_validation($_POST, $reqdfields, $reqdfields, $reqdfieldsn, &$input_errors);
93 4f4d63d8 John Fleming
	}
94
95 8c3c9dc2 John Fleming
96 4f4d63d8 John Fleming
/* 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 5b237745 Scott Ullrich
	if (!$input_errors) {
107 4f4d63d8 John Fleming
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
108 3805bfdd John Fleming
		$config['snmpd']['pollport'] = $_POST['pollport'];
109 5b237745 Scott Ullrich
		$config['snmpd']['syslocation'] = $_POST['syslocation'];	
110
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
111
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
112 4f4d63d8 John Fleming
		/* 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 8c3c9dc2 John Fleming
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
120 4f4d63d8 John Fleming
		
121 3805bfdd John Fleming
		$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 5b237745 Scott Ullrich
			
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 4df96eff Scott Ullrich
137
$pgtitle = "Services: SNMP";
138
include("head.inc");
139
140 5b237745 Scott Ullrich
?>
141
<script language="JavaScript">
142
<!--
143 4f4d63d8 John Fleming
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 8c3c9dc2 John Fleming
	        document.iform.trapstring.disabled = false;
152 4f4d63d8 John Fleming
	    }
153
	    else
154
	    {
155
                document.iform.trapserver.disabled = true;
156
                document.iform.trapserverport.disabled = true;
157 8c3c9dc2 John Fleming
                document.iform.trapstring.disabled = true;
158 4f4d63d8 John Fleming
	    }
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 3805bfdd John Fleming
	    document.iform.pollport.disabled = false;
178 4f4d63d8 John Fleming
	    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 8c3c9dc2 John Fleming
                document.iform.trapstring.disabled = false;
198 4f4d63d8 John Fleming
	    }
199
	    else
200
	    {
201
                document.iform.trapserver.disabled = true;
202 a21b1cad John Fleming
                document.iform.trapserverport.disabled = true;
203 8c3c9dc2 John Fleming
                document.iform.trapstring.disabled = true;
204 4f4d63d8 John Fleming
	    }
205 3805bfdd John Fleming
	    document.iform.mibii.disabled = false;
206
	    document.iform.netgraph.disabled = false;
207
	    document.iform.pf.disabled = false;
208 4f4d63d8 John Fleming
	}
209
	else
210
	{
211 3805bfdd John Fleming
            document.iform.pollport.disabled = true;
212 4f4d63d8 John Fleming
            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 8c3c9dc2 John Fleming
            document.iform.trapstring.disabled = true;
223 3805bfdd John Fleming
224
            document.iform.mibii.disabled = true;
225
            document.iform.netgraph.disabled = true;
226
            document.iform.pf.disabled = true;
227 4f4d63d8 John Fleming
	}
228 5b237745 Scott Ullrich
}
229
//-->
230
</script>
231
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
232
<?php include("fbegin.inc"); ?>
233 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
234 5b237745 Scott Ullrich
<?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 4f4d63d8 John Fleming
239 5b237745 Scott Ullrich
                <tr> 
240 4f4d63d8 John Fleming
  		  <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 5b237745 Scott Ullrich
                </tr>
246 3805bfdd John Fleming
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 5b237745 Scott Ullrich
                <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 3805bfdd John Fleming
262 5b237745 Scott Ullrich
                <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 3805bfdd John Fleming
269 5b237745 Scott Ullrich
                <tr> 
270 4f4d63d8 John Fleming
                  <td width="22%" valign="top" class="vncellreq">Read Community String</td>
271 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
272
                    <input name="rocommunity" type="text" class="formfld" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>"> 
273 3805bfdd John Fleming
                    <br>In most cases, &quot;public&quot; is used here</br>
274
		  </td>
275 5b237745 Scott Ullrich
                </tr>
276 4f4d63d8 John Fleming
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 3805bfdd John Fleming
                    <strong>Enable Write Community String</strong>
284
		  </td>
285 4f4d63d8 John Fleming
                </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 3805bfdd John Fleming
		    <br>Please use something other then &quot;private&quot; here</br>
292
		  </td>
293 4f4d63d8 John Fleming
                </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 3805bfdd John Fleming
                    <strong>Enable SNMP Traps</strong>
302
                  </td>
303 4f4d63d8 John Fleming
                </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 3805bfdd John Fleming
                    <br>Enter trap server name</br>
310
		  </td>
311 4f4d63d8 John Fleming
                </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 3805bfdd John Fleming
                    <br>Enter the port to send the traps to (default 162)</br>
318
		  </td>
319 4f4d63d8 John Fleming
                </tr>
320 3805bfdd John Fleming
321 8c3c9dc2 John Fleming
                <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 3805bfdd John Fleming
                    <br>Trap string</br>
326
		  </td>
327 8c3c9dc2 John Fleming
                </tr>
328
329 3805bfdd John Fleming
		<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 4f4d63d8 John Fleming
338 5b237745 Scott Ullrich
                <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 4f4d63d8 John Fleming
enable_change(this);
349 5b237745 Scott Ullrich
//-->
350
</script>
351
<?php include("fend.inc"); ?>
352
</body>
353
</html>