Project

General

Profile

Download (17 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
	pfSense_MODULE:	snmp
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-services-snmp
37
##|*NAME=Services: SNMP page
38
##|*DESCR=Allow access to the 'Services: SNMP' page.
39
##|*MATCH=services_snmp.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("functions.inc");
44

    
45
if (!is_array($config['snmpd'])) {
46
	$config['snmpd'] = array();
47
	$config['snmpd']['rocommunity'] = "public";
48
	$config['snmpd']['pollport'] = "161";
49
}
50

    
51
if (!is_array($config['snmpd']['modules'])) {
52
	$config['snmpd']['modules'] = array();
53
	$config['snmpd']['modules']['mibii'] = true;
54
	$config['snmpd']['modules']['netgraph'] = true;
55
	$config['snmpd']['modules']['pf'] = true;
56
	$config['snmpd']['modules']['hostres'] = true;
57
	$config['snmpd']['modules']['bridge'] = true;
58
}
59
$pconfig['enable'] = isset($config['snmpd']['enable']);
60
$pconfig['pollport'] = $config['snmpd']['pollport'];
61
$pconfig['syslocation'] = $config['snmpd']['syslocation'];
62
$pconfig['syscontact'] = $config['snmpd']['syscontact'];
63
$pconfig['rocommunity'] = $config['snmpd']['rocommunity'];
64
/* disabled until some docs show up on what this does.
65
$pconfig['rwenable'] = isset($config['snmpd']['rwenable']);
66
$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity'];
67
*/
68
$pconfig['trapenable'] = isset($config['snmpd']['trapenable']);
69
$pconfig['trapserver'] = $config['snmpd']['trapserver'];
70
$pconfig['trapserverport'] = $config['snmpd']['trapserverport'];
71
$pconfig['trapstring'] = $config['snmpd']['trapstring'];
72

    
73
$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']);
74
$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']);
75
$pconfig['pf'] = isset($config['snmpd']['modules']['pf']);
76
$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']);
77
$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']);
78
$pconfig['bindip'] = $config['snmpd']['bindip'];
79

    
80
if ($_POST) {
81

    
82
	unset($input_errors);
83
	$pconfig = $_POST;
84

    
85
	/* input validation */
86
	if ($_POST['enable']) {
87
		if (strstr($_POST['syslocation'],"#")) $input_errors[] = gettext("Invalid character '#' in system location");
88
 		if (strstr($_POST['syscontact'],"#")) $input_errors[] = gettext("Invalid character '#' in system contact");
89
		if (strstr($_POST['rocommunity'],"#")) $input_errors[] = gettext("Invalid character '#' in read community string");
90

    
91
		$reqdfields = explode(" ", "rocommunity");
92
		$reqdfieldsn = array(gettext("Community"));
93
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
94

    
95
		$reqdfields = explode(" ", "pollport");
96
		$reqdfieldsn = array(gettext("Polling Port"));
97
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
98
		
99
	
100
	}
101

    
102
	if ($_POST['trapenable']) {
103
		if (strstr($_POST['trapstring'],"#")) $input_errors[] = gettext("Invalid character '#' in SNMP trap string");
104

    
105
		$reqdfields = explode(" ", "trapserver");
106
		$reqdfieldsn = array(gettext("Trap server"));
107
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
108

    
109
		$reqdfields = explode(" ", "trapserverport");
110
		$reqdfieldsn = array(gettext("Trap server port"));
111
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
112

    
113
		$reqdfields = explode(" ", "trapstring");
114
		$reqdfieldsn = array(gettext("Trap string"));
115
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
116
	}
117

    
118

    
119
/* disabled until some docs show up on what this does.
120
	if ($_POST['rwenable']) {
121
               $reqdfields = explode(" ", "rwcommunity");
122
               $reqdfieldsn = explode(",", "Write community string");
123
               do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
124
	}
125
*/
126

    
127
	
128

    
129
	if (!$input_errors) {
130
		$config['snmpd']['enable'] = $_POST['enable'] ? true : false;
131
		$config['snmpd']['pollport'] = $_POST['pollport'];
132
		$config['snmpd']['syslocation'] = $_POST['syslocation'];	
133
		$config['snmpd']['syscontact'] = $_POST['syscontact'];
134
		$config['snmpd']['rocommunity'] = $_POST['rocommunity'];
135
		/* disabled until some docs show up on what this does.
136
		$config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false;
137
		$config['snmpd']['rwcommunity'] = $_POST['rwcommunity'];
138
		*/
139
		$config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false;
140
		$config['snmpd']['trapserver'] = $_POST['trapserver'];
141
		$config['snmpd']['trapserverport'] = $_POST['trapserverport'];
142
		$config['snmpd']['trapstring'] = $_POST['trapstring'];
143
		
144
		$config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false;
145
		$config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false;
146
		$config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false;
147
		$config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false;
148
		$config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false;
149
		$config['snmpd']['bindip'] = $_POST['bindip'];
150
			
151
		write_config();
152
		
153
		$retval = 0;
154
		$retval = services_snmpd_configure();
155
		$savemsg = get_std_save_message($retval);
156
	}
157
}
158

    
159
$pgtitle = array(gettext("Services"),gettext("SNMP"));
160
$shortcut_section = "snmp";
161
include("head.inc");
162

    
163
?>
164
<script language="JavaScript">
165
<!--
166
function check_deps() {
167
	if (jQuery('#hostres').prop('checked') == true) {
168
		jQuery('#mibii').prop('checked',true);
169
	}
170
}
171

    
172
function enable_change(whichone) {
173

    
174
	if( whichone.name == "trapenable" )
175
        {
176
	    if( whichone.checked == true )
177
	    {
178
	        document.iform.trapserver.disabled = false;
179
	        document.iform.trapserverport.disabled = false;
180
	        document.iform.trapstring.disabled = false;
181
	    }
182
	    else
183
	    {
184
                document.iform.trapserver.disabled = true;
185
                document.iform.trapserverport.disabled = true;
186
                document.iform.trapstring.disabled = true;
187
	    }
188
	}
189

    
190
	/* disabled until some docs show up on what this does.
191
	if( whichone.name == "rwenable"  )
192
	{
193
	    if( whichone.checked == true )
194
	    {
195
		document.iform.rwcommunity.disabled = false;
196
	    }
197
	    else
198
	    {
199
		document.iform.rwcommunity.disabled = true;
200
	    }
201
	}
202
	*/
203

    
204
	if( document.iform.enable.checked == true )
205
	{
206
	    document.iform.pollport.disabled = false;
207
	    document.iform.syslocation.disabled = false;
208
	    document.iform.syscontact.disabled = false;
209
	    document.iform.rocommunity.disabled = false;
210
	    document.iform.trapenable.disabled = false;
211
	    /* disabled until some docs show up on what this does.
212
	    document.iform.rwenable.disabled = false;
213
	    if( document.iform.rwenable.checked == true )
214
	    {
215
	        document.iform.rwcommunity.disabled = false;
216
	    }
217
	    else
218
	    {
219
		document.iform.rwcommunity.disabled = true;
220
	    }
221
	    */
222
	    if( document.iform.trapenable.checked == true )
223
	    {
224
                document.iform.trapserver.disabled = false;
225
                document.iform.trapserverport.disabled = false;
226
                document.iform.trapstring.disabled = false;
227
	    }
228
	    else
229
	    {
230
                document.iform.trapserver.disabled = true;
231
                document.iform.trapserverport.disabled = true;
232
                document.iform.trapstring.disabled = true;
233
	    }
234
	    document.iform.mibii.disabled = false;
235
	    document.iform.netgraph.disabled = false;
236
	    document.iform.pf.disabled = false;
237
	    document.iform.hostres.disabled = false;
238
	    //document.iform.bridge.disabled = false;
239
	}
240
	else
241
	{
242
            document.iform.pollport.disabled = true;
243
            document.iform.syslocation.disabled = true;
244
            document.iform.syscontact.disabled = true;
245
            document.iform.rocommunity.disabled = true;
246
	    /* 
247
            document.iform.rwenable.disabled = true;
248
	    document.iform.rwcommunity.disabled = true;
249
	    */
250
            document.iform.trapenable.disabled = true;
251
            document.iform.trapserver.disabled = true;
252
            document.iform.trapserverport.disabled = true;
253
            document.iform.trapstring.disabled = true;
254

    
255
            document.iform.mibii.disabled = true;
256
            document.iform.netgraph.disabled = true;
257
            document.iform.pf.disabled = true;
258
            document.iform.hostres.disabled = true;
259
            //document.iform.bridge.disabled = true;
260
	}
261
}
262
//-->
263
</script>
264
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
265
<?php include("fbegin.inc"); ?>
266
<?php if ($input_errors) print_input_errors($input_errors); ?>
267
<?php if ($savemsg) print_info_box($savemsg); ?>
268
            <form action="services_snmp.php" method="post" name="iform" id="iform">
269
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
270

    
271
                <tr> 
272
  		  <td colspan="2" valign="top" class="optsect_t">
273
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
274
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Daemon");?></strong></td>
275
					<td align="right" class="optsect_s"><input name="enable" id="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(this)"> <strong><?=gettext("Enable");?></strong></td></tr>
276
  			</table></td>
277
                </tr>
278

    
279
                <tr>
280
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Polling Port ");?></td>
281
                  <td width="78%" class="vtable">
282
                    <input name="pollport" type="text" class="formfld unknown" id="pollport" size="40" value="<?=htmlspecialchars($pconfig['pollport']) ? htmlspecialchars($pconfig['pollport']) : htmlspecialchars(161);?>">
283
                    <br><?=gettext("Enter the port to accept polling events on (default 161)");?></br>
284
		  </td>
285
                </tr>
286

    
287
                <tr> 
288
                  <td width="22%" valign="top" class="vncell"><?=gettext("System location");?></td>
289
                  <td width="78%" class="vtable"> 
290
                    <input name="syslocation" type="text" class="formfld unknown" id="syslocation" size="40" value="<?=htmlspecialchars($pconfig['syslocation']);?>"> 
291
                  </td>
292
                </tr>
293

    
294
                <tr> 
295
                  <td width="22%" valign="top" class="vncell"><?=gettext("System contact");?></td>
296
                  <td width="78%" class="vtable"> 
297
                    <input name="syscontact" type="text" class="formfld unknown" id="syscontact" size="40" value="<?=htmlspecialchars($pconfig['syscontact']);?>"> 
298
                  </td>
299
                </tr>
300

    
301
                <tr> 
302
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Read Community String");?></td>
303
                  <td width="78%" class="vtable"> 
304
                    <input name="rocommunity" type="text" class="formfld unknown" id="rocommunity" size="40" value="<?=htmlspecialchars($pconfig['rocommunity']);?>"> 
305
		    <br><?=gettext("The community string is like a password, restricting access to querying SNMP to hosts knowing the community string. Use a strong value here to protect from unauthorized information disclosure.");?></br>
306
		  </td>
307
                </tr>
308

    
309
<?php 
310
			/* disabled until some docs show up on what this does.
311
                <tr>
312
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
313
                  <td width="78%" class="vtable">
314
	 	   <input name="rwenable" id="rwenable" type="checkbox" value="yes" <?php if ($pconfig['rwenable']) echo "checked"; ?> onClick="enable_change(this)">
315
                    <strong>Enable Write Community String</strong>
316
		  </td>
317
                </tr>
318

    
319
		<tr>
320
		  <td width="22%" valign="top" class="vncellreq">Write community string</td>
321
          <td width="78%" class="vtable">
322
                    <input name="rwcommunity" type="text" class="formfld unknown" id="rwcommunity" size="40" value="<?=htmlspecialchars($pconfig['rwcommunity']);?>">
323
		    <br>Please use something other then &quot;private&quot; here</br>
324
		  </td>
325
                </tr>
326
		    	*/ 
327
?>
328

    
329
		<tr><td>&nbsp;</td></tr>
330

    
331
                <tr> 
332
  		  <td colspan="2" valign="top" class="optsect_t">
333
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
334
  			<tr><td class="optsect_s"><strong><?=gettext("SNMP Traps");?></strong></td>
335
			<td align="right" class="optsect_s"><input name="trapenable" id="trapenable" type="checkbox" value="yes" <?php if ($pconfig['trapenable']) echo "checked"; ?> onClick="enable_change(this)"> <strong><?=gettext("Enable");?></strong></td></tr>
336
  			</table></td>
337
                </tr>
338

    
339

    
340
                <tr>
341
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Trap server");?></td>
342
                  <td width="78%" class="vtable">
343
                    <input name="trapserver" type="text" class="formfld unknown" id="trapserver" size="40" value="<?=htmlspecialchars($pconfig['trapserver']);?>">
344
                    <br><?=gettext("Enter trap server name");?></br>
345
		  </td>
346
                </tr>
347

    
348
                <tr>
349
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Trap server port ");?></td>
350
                  <td width="78%" class="vtable">
351
                    <input name="trapserverport" type="text" class="formfld unknown" id="trapserverport" size="40" value="<?=htmlspecialchars($pconfig['trapserverport']) ? htmlspecialchars($pconfig['trapserverport']) : htmlspecialchars(162);?>">
352
                    <br><?=gettext("Enter the port to send the traps to (default 162)");?></br>
353
		  </td>
354
                </tr>
355

    
356
                <tr>
357
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Enter the SNMP trap string");?></td>
358
                  <td width="78%" class="vtable">
359
                    <input name="trapstring" type="text" class="formfld unknown" id="trapstring" size="40" value="<?=htmlspecialchars($pconfig['trapstring']);?>">
360
                    <br><?=gettext("Trap string");?></br>
361
		  </td>
362
                </tr>
363

    
364
		<tr><td>&nbsp;</td></tr>
365

    
366
                <tr> 
367
  		  <td colspan="2" valign="top" class="optsect_t">
368
  			<table border="0" cellspacing="0" cellpadding="0" width="100%">
369
  			<tr><td class="optsect_s"><strong><?=gettext("Modules");?></strong></td>
370
			<td align="right" class="optsect_s">&nbsp;</td></tr>
371
  			</table></td>
372
                </tr>
373

    
374
		<tr>
375
		  <td width="22%" valign="top" class="vncellreq"><?=gettext("SNMP Modules");?></td>
376
		  <td width="78%" class="vtable">
377
		    <input name="mibii" type="checkbox" id="mibii" value="yes" onClick="check_deps()" <?php if ($pconfig['mibii']) echo "checked"; ?> ><?=gettext("MibII"); ?>
378
		    <br />
379
		    <input name="netgraph" type="checkbox" id="netgraph" value="yes" <?php if ($pconfig['netgraph']) echo "checked"; ?> ><?=gettext("Netgraph"); ?>
380
		    <br />
381
		    <input name="pf" type="checkbox" id="pf" value="yes" <?php if ($pconfig['pf']) echo "checked"; ?> ><?=gettext("PF"); ?>
382
		    <br />
383
		    <input name="hostres" type="checkbox" id="hostres" value="yes" onClick="check_deps()" <?php if ($pconfig['hostres']) echo "checked"; ?> ><?=gettext("Host Resources (Requires MibII)");?>
384
		  </td>
385
		</tr>
386

    
387
		<tr><td>&nbsp;</td></tr>
388

    
389
		<tr>
390
			<td colspan="2" valign="top" class="optsect_t">
391
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
392
				<tr><td class="optsect_s"><strong><?=gettext("Interface Binding");?></strong></td>
393
				<td align="right" class="optsect_s">&nbsp;</td></tr>
394
			</table></td>
395
		</tr>
396
		<tr>
397
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Bind Interface"); ?></td>
398
			<td width="78%" class="vtable">
399
				<select name="bindip" class="formselect">
400
					<option value="">All</option>
401
				<?php  $listenips = get_possible_listen_ips();
402
					foreach ($listenips as $lip):
403
						$selected = "";
404
						if ($lip['value'] == $pconfig['bindip'])
405
							$selected = "selected";
406
				?>
407
					<option value="<?=$lip['value'];?>" <?=$selected;?>>
408
						<?=htmlspecialchars($lip['name']);?>
409
					</option>
410
				<?php endforeach; ?>
411
		</tr>
412
		 <tr> 
413
		   <td width="22%" valign="top">&nbsp;</td>
414
		   <td width="78%"> 
415
		     <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)"> 
416
		   </td>
417
		 </tr>
418
		</table>
419
</form>
420
<script language="JavaScript">
421
<!--
422
enable_change(this);
423
//-->
424
</script>
425
<?php include("fend.inc"); ?>
426
</body>
427
</html>
(167-167/251)