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
|
$pgtitle = "Services: SNMP";
|
117
|
include("head.inc");
|
118
|
|
119
|
?>
|
120
|
<script language="JavaScript">
|
121
|
<!--
|
122
|
function enable_change(whichone) {
|
123
|
|
124
|
if( whichone.name == "trapenable" )
|
125
|
{
|
126
|
if( whichone.checked == true )
|
127
|
{
|
128
|
document.iform.trapserver.disabled = false;
|
129
|
document.iform.trapserverport.disabled = false;
|
130
|
document.iform.trapstring.disabled = false;
|
131
|
}
|
132
|
else
|
133
|
{
|
134
|
document.iform.trapserver.disabled = true;
|
135
|
document.iform.trapserverport.disabled = true;
|
136
|
document.iform.trapstring.disabled = true;
|
137
|
}
|
138
|
}
|
139
|
|
140
|
/* disabled until some docs show up on what this does.
|
141
|
if( whichone.name == "rwenable" )
|
142
|
{
|
143
|
if( whichone.checked == true )
|
144
|
{
|
145
|
document.iform.rwcommunity.disabled = false;
|
146
|
}
|
147
|
else
|
148
|
{
|
149
|
document.iform.rwcommunity.disabled = true;
|
150
|
}
|
151
|
}
|
152
|
*/
|
153
|
|
154
|
if( document.iform.enable.checked == true )
|
155
|
{
|
156
|
document.iform.syslocation.disabled = false;
|
157
|
document.iform.syscontact.disabled = false;
|
158
|
document.iform.rocommunity.disabled = false;
|
159
|
document.iform.trapenable.disabled = false;
|
160
|
/* disabled until some docs show up on what this does.
|
161
|
document.iform.rwenable.disabled = false;
|
162
|
if( document.iform.rwenable.checked == true )
|
163
|
{
|
164
|
document.iform.rwcommunity.disabled = false;
|
165
|
}
|
166
|
else
|
167
|
{
|
168
|
document.iform.rwcommunity.disabled = true;
|
169
|
}
|
170
|
*/
|
171
|
if( document.iform.trapenable.checked == true )
|
172
|
{
|
173
|
document.iform.trapserver.disabled = false;
|
174
|
document.iform.trapserverport.disabled = false;
|
175
|
document.iform.trapstring.disabled = false;
|
176
|
}
|
177
|
else
|
178
|
{
|
179
|
document.iform.trapserver.disabled = true;
|
180
|
document.iform.trapserverport.disabled = true;
|
181
|
document.iform.trapstring.disabled = true;
|
182
|
}
|
183
|
}
|
184
|
else
|
185
|
{
|
186
|
document.iform.syslocation.disabled = true;
|
187
|
document.iform.syscontact.disabled = true;
|
188
|
document.iform.rocommunity.disabled = true;
|
189
|
/*
|
190
|
document.iform.rwenable.disabled = true;
|
191
|
document.iform.rwcommunity.disabled = true;
|
192
|
*/
|
193
|
document.iform.trapenable.disabled = true;
|
194
|
document.iform.trapserver.disabled = true;
|
195
|
document.iform.trapserverport.disabled = true;
|
196
|
document.iform.trapstring.disabled = true;
|
197
|
}
|
198
|
}
|
199
|
//-->
|
200
|
</script>
|
201
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
202
|
<?php include("fbegin.inc"); ?>
|
203
|
<p class="pgtitle"><?=$pgtitle?></p>
|
204
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
205
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
206
|
<form action="services_snmp.php" method="post" name="iform" id="iform">
|
207
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
208
|
|
209
|
<tr>
|
210
|
<td colspan="2" valign="top" class="optsect_t">
|
211
|
<table border="0" cellspacing="0" cellpadding="0" width="100%">
|
212
|
<tr><td class="optsect_s"><strong>SNMP Daemon</strong></td>
|
213
|
<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>
|
214
|
</table></td>
|
215
|
</tr>
|
216
|
<tr>
|
217
|
<td width="22%" valign="top" class="vncell">System location</td>
|
218
|
<td width="78%" class="vtable">
|
219
|
<input name="syslocation" type="text" class="formfld" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>">
|
220
|
</td>
|
221
|
</tr>
|
222
|
<tr>
|
223
|
<td width="22%" valign="top" class="vncell">System contact</td>
|
224
|
<td width="78%" class="vtable">
|
225
|
<input name="syscontact" type="text" class="formfld" id="syscontact" size="40" value="<?=htmlspecialchars($pconfig['syscontact']);?>">
|
226
|
</td>
|
227
|
</tr>
|
228
|
<tr>
|
229
|
<td width="22%" valign="top" class="vncellreq">Read Community String</td>
|
230
|
<td width="78%" class="vtable">
|
231
|
<input name="rocommunity" type="text" class="formfld" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>">
|
232
|
<br>
|
233
|
In most cases, "public" is used here</td>
|
234
|
</tr>
|
235
|
|
236
|
|
237
|
|
238
|
<?php
|
239
|
/* disabled until some docs show up on what this does.
|
240
|
<tr>
|
241
|
<td width="22%" valign="top" class="vtable"> </td>
|
242
|
<td width="78%" class="vtable">
|
243
|
<input name="rwenable" type="checkbox" value="yes" <?php if ($pconfig['rwenable']) echo "checked"; ?> onClick="enable_change(this)">
|
244
|
<strong>Enable Write Community String</strong></td>
|
245
|
</tr>
|
246
|
|
247
|
<tr>
|
248
|
<td width="22%" valign="top" class="vncellreq">Write community string</td>
|
249
|
<td width="78%" class="vtable">
|
250
|
<input name="rwcommunity" type="text" class="formfld" id="rwcommunity" size="40" value="<?=htmlspecialchars($pconfig['rwcommunity']);?>">
|
251
|
<br>
|
252
|
Please use something other then "private" here</td>
|
253
|
</tr>
|
254
|
*/
|
255
|
?>
|
256
|
|
257
|
|
258
|
|
259
|
<tr>
|
260
|
<td width="22%" valign="top" class="vtable"> </td>
|
261
|
<td width="78%" class="vtable">
|
262
|
<input name="trapenable" type="checkbox" value="yes" <?php if ($pconfig['trapenable']) echo "checked"; ?> onClick="enable_change(this)">
|
263
|
<strong>Enable SNMP Traps</strong></td>
|
264
|
</tr>
|
265
|
|
266
|
<tr>
|
267
|
<td width="22%" valign="top" class="vncellreq">Trap server</td>
|
268
|
<td width="78%" class="vtable">
|
269
|
<input name="trapserver" type="text" class="formfld" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>">
|
270
|
<br>
|
271
|
Enter trap server name</td>
|
272
|
</tr>
|
273
|
|
274
|
<tr>
|
275
|
<td width="22%" valign="top" class="vncellreq">Trap server port </td>
|
276
|
<td width="78%" class="vtable">
|
277
|
<input name="trapserverport" type="text" class="formfld" id="trapserverport" size="40" value="<?=$pconfig['trapserverport'] ? htmlspecialchars($pconfig['trapserverport']) : htmlspecialchars(162);?>">
|
278
|
<br>
|
279
|
Enter the port to send the traps to (default 162)</td>
|
280
|
</tr>
|
281
|
<tr>
|
282
|
<td width="22%" valign="top" class="vncellreq">Trap server port </td>
|
283
|
<td width="78%" class="vtable">
|
284
|
<input name="trapstring" type="text" class="formfld" id="trapstring" size="40" value="<?=htmlspecialchars($pconfig['trapstring']);?>">
|
285
|
<br>
|
286
|
Trap string</td>
|
287
|
</tr>
|
288
|
|
289
|
|
290
|
<tr>
|
291
|
<td width="22%" valign="top"> </td>
|
292
|
<td width="78%">
|
293
|
<input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)">
|
294
|
</td>
|
295
|
</tr>
|
296
|
</table>
|
297
|
</form>
|
298
|
<script language="JavaScript">
|
299
|
<!--
|
300
|
enable_change(this);
|
301
|
//-->
|
302
|
</script>
|
303
|
<?php include("fend.inc"); ?>
|
304
|
</body>
|
305
|
</html>
|