Project

General

Profile

Download (11.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
}
39

    
40
$pconfig['enable'] = isset($config['snmpd']['enable']);
41
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
42
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
43
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
44
/* disabled until some docs show up on what this does.
45
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
46
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
47
*/
48
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
49
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
50
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
51
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
52

    
53
if ($_POST) {
54

    
55
	unset($input_errors);
56
	$pconfig = $_POST;
57

    
58
	/* input validation */
59
	if ($_POST['enable']) {
60
		$reqdfields = explode(" ", "rocommunity");
61
		$reqdfieldsn = explode(",", "Community");
62
		
63
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
64
	}
65

    
66
	if ($_POST['trapenable']) {
67
		$reqdfields = explode(" ", "trapserver");
68
		$reqdfieldsn = explode(",", "Trap server");
69
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
70
		$reqdfields = explode(" ", "trapserverport");
71
		$reqdfieldsn = explode(",", "Trap server port");
72
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
73
		$reqdfields = explode(" ", "trapstring");
74
		$reqdfieldsn = explode(",", "Trap string");
75
		do_input_validation($_POST, $reqdfields, $reqdfields, $reqdfieldsn, &$input_errors);
76
	}
77

    
78

    
79
/* disabled until some docs show up on what this does.
80
	if ($_POST['rwenable']) {
81
               $reqdfields = explode(" ", "rwcommunity");
82
               $reqdfieldsn = explode(",", "Write community string");
83
               do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
84
	}
85
*/
86

    
87
	
88

    
89
	if (!$input_errors) {
90
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
91
		$config['snmpd']['syslocation'] = $_POST['syslocation'];	
92
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
93
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
94
		/* disabled until some docs show up on what this does.
95
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
96
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
97
		*/
98
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
99
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
100
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
101
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
102
		
103
			
104
		write_config();
105
		
106
		$retval = 0;
107
		if (!file_exists($d_sysrebootreqd_path)) {
108
			config_lock();
109
			$retval = services_snmpd_configure();
110
			config_unlock();
111
		}
112
		$savemsg = get_std_save_message($retval);
113
	}
114
}
115
?>
116
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
117
<html>
118
<head>
119
<title><?=gentitle("Services: SNMP");?></title>
120
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
121
<link href="gui.css" rel="stylesheet" type="text/css">
122
<script language="JavaScript">
123
<!--
124
function enable_change(whichone) {
125

    
126
	if( whichone.name == "trapenable" )
127
        {
128
	    if( whichone.checked == true )
129
	    {
130
	        document.iform.trapserver.disabled = false;
131
	        document.iform.trapserverport.disabled = false;
132
	        document.iform.trapstring.disabled = false;
133
	    }
134
	    else
135
	    {
136
                document.iform.trapserver.disabled = true;
137
                document.iform.trapserverport.disabled = true;
138
                document.iform.trapstring.disabled = true;
139
	    }
140
	}
141

    
142
	/* disabled until some docs show up on what this does.
143
	if( whichone.name == "rwenable"  )
144
	{
145
	    if( whichone.checked == true )
146
	    {
147
		document.iform.rwcommunity.disabled = false;
148
	    }
149
	    else
150
	    {
151
		document.iform.rwcommunity.disabled = true;
152
	    }
153
	}
154
	*/
155

    
156
	if( document.iform.enable.checked == true )
157
	{
158
	    document.iform.syslocation.disabled = false;
159
	    document.iform.syscontact.disabled = false;
160
	    document.iform.rocommunity.disabled = false;
161
	    document.iform.trapenable.disabled = false;
162
	    /* disabled until some docs show up on what this does.
163
	    document.iform.rwenable.disabled = false;
164
	    if( document.iform.rwenable.checked == true )
165
	    {
166
	        document.iform.rwcommunity.disabled = false;
167
	    }
168
	    else
169
	    {
170
		document.iform.rwcommunity.disabled = true;
171
	    }
172
	    */
173
	    if( document.iform.trapenable.checked == true )
174
	    {
175
                document.iform.trapserver.disabled = false;
176
                document.iform.trapserverport.disabled = false;
177
                document.iform.trapstring.disabled = false;
178
	    }
179
	    else
180
	    {
181
                document.iform.trapserver.disabled = true;
182
                document.iform.trapserverport.disabled = true;
183
                document.iform.trapstring.disabled = true;
184
	    }
185
	}
186
	else
187
	{
188
            document.iform.syslocation.disabled = true;
189
            document.iform.syscontact.disabled = true;
190
            document.iform.rocommunity.disabled = true;
191
	    /* 
192
            document.iform.rwenable.disabled = true;
193
	    document.iform.rwcommunity.disabled = true;
194
	    */
195
            document.iform.trapenable.disabled = true;
196
            document.iform.trapserver.disabled = true;
197
            document.iform.trapserverport.disabled = true;
198
            document.iform.trapstring.disabled = true;
199
	}
200
}
201
//-->
202
</script>
203
</head>
204

    
205
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
206
<?php include("fbegin.inc"); ?>
207
<p class="pgtitle">Services: SNMP</p>
208
<?php if ($input_errors) print_input_errors($input_errors); ?>
209
<?php if ($savemsg) print_info_box($savemsg); ?>
210
            <form action="services_snmp.php" method="post" name="iform" id="iform">
211
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
212

    
213
                <tr> 
214
  		  <td colspan="2" valign="top" class="optsect_t">
215
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
216
  			<tr><td class="optsect_s"><strong>SNMP Daemon</strong></td>
217
			<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>
218
  			</table></td>
219
                </tr>
220
                <tr> 
221
                  <td width="22%" valign="top" class="vncell">System location</td>
222
                  <td width="78%" class="vtable"> 
223
                    <input name="syslocation" type="text" class="formfld" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>"> 
224
                  </td>
225
                </tr>
226
                <tr> 
227
                  <td width="22%" valign="top" class="vncell">System contact</td>
228
                  <td width="78%" class="vtable"> 
229
                    <input name="syscontact" type="text" class="formfld" id="syscontact" size="40" value="<?=htmlspecialchars($pconfig['syscontact']);?>"> 
230
                  </td>
231
                </tr>
232
                <tr> 
233
                  <td width="22%" valign="top" class="vncellreq">Read Community String</td>
234
                  <td width="78%" class="vtable"> 
235
                    <input name="rocommunity" type="text" class="formfld" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>"> 
236
                    <br>
237
                    In most cases, &quot;public&quot; is used here</td>
238
                </tr>
239

    
240

    
241

    
242
<?php 
243
			/* disabled until some docs show up on what this does.
244
                <tr>
245
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
246
                  <td width="78%" class="vtable">
247
	 	   <input name="rwenable" type="checkbox" value="yes" <?php if ($pconfig['rwenable']) echo "checked"; ?> onClick="enable_change(this)">
248
                    <strong>Enable Write Community String</strong></td>
249
                </tr>
250

    
251
		<tr>
252
		  <td width="22%" valign="top" class="vncellreq">Write community string</td>
253
          <td width="78%" class="vtable">
254
                    <input name="rwcommunity" type="text" class="formfld" id="rwcommunity" size="40" value="<?=htmlspecialchars($pconfig['rwcommunity']);?>">
255
		    <br>
256
                    Please use something other then &quot;private&quot; here</td>
257
                </tr>
258
		    	*/ 
259
?>
260

    
261

    
262

    
263
                <tr>
264
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
265
                  <td width="78%" class="vtable">
266
                   <input name="trapenable" type="checkbox" value="yes" <?php if ($pconfig['trapenable']) echo "checked"; ?> onClick="enable_change(this)">
267
                    <strong>Enable SNMP Traps</strong></td>
268
                </tr>
269

    
270
                <tr>
271
                  <td width="22%" valign="top" class="vncellreq">Trap server</td>
272
                  <td width="78%" class="vtable">
273
                    <input name="trapserver" type="text" class="formfld" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>">
274
                    <br>
275
                    Enter trap server name</td>
276
                </tr>
277

    
278
                <tr>
279
                  <td width="22%" valign="top" class="vncellreq">Trap server port </td>
280
                  <td width="78%" class="vtable">
281
                    <input name="trapserverport" type="text" class="formfld" id="trapserverport" size="40" value="<?=$pconfig['trapserverport'] ? htmlspecialchars($pconfig['trapserverport']) : htmlspecialchars(162);?>">
282
                    <br>
283
                    Enter the port to send the traps to (default 162)</td>
284
                </tr>
285
                <tr>
286
                  <td width="22%" valign="top" class="vncellreq">Trap server port </td>
287
                  <td width="78%" class="vtable">
288
                    <input name="trapstring" type="text" class="formfld" id="trapstring" size="40" value="<?=htmlspecialchars($pconfig['trapstring']);?>">
289
                    <br>
290
                    Trap string</td>
291
                </tr>
292

    
293

    
294
                <tr> 
295
                  <td width="22%" valign="top">&nbsp;</td>
296
                  <td width="78%"> 
297
                    <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)"> 
298
                  </td>
299
                </tr>
300
              </table>
301
</form>
302
<script language="JavaScript">
303
<!--
304
enable_change(this);
305
//-->
306
</script>
307
<?php include("fend.inc"); ?>
308
</body>
309
</html>
(84-84/117)