Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
4
	interfaces_wlan.inc
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2005 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
$wlchannels = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,42,44,48,50,52,56,58,60,64,149,152,153,157,160,161,165);
33

    
34
function wireless_config_init() {
35
	global $optcfg, $pconfig;
36
	
37
	$pconfig['standard'] = $optcfg['wireless']['standard'];
38
	$pconfig['mode'] = $optcfg['wireless']['mode'];
39
	$pconfig['ssid'] = $optcfg['wireless']['ssid'];
40
	$pconfig['hidessid'] = $optcfg['wireless']['hidessid'];
41
	$pconfig['stationname'] = $optcfg['wireless']['stationname'];
42
	$pconfig['channel'] = $optcfg['wireless']['channel'];
43
	$pconfig['txpower'] = $optcfg['wireless']['txpower'];	
44
	$pconfig['wep_enable'] = isset($optcfg['wireless']['wep']['enable']);
45
	
46
	if (is_array($optcfg['wireless']['wep']['key'])) {
47
		$i = 1;
48
		foreach ($optcfg['wireless']['wep']['key'] as $wepkey) {
49
			$pconfig['key' . $i] = $wepkey['value'];
50
			if (isset($wepkey['txkey']))
51
				$pconfig['txkey'] = $i;
52
			$i++;
53
		}
54
		if (!isset($wepkey['txkey']))
55
			$pconfig['txkey'] = 1;
56
	}
57
}
58

    
59
function wireless_config_post() {
60
	global $optcfg, $pconfig;
61

    
62
	unset($input_errors);
63

    
64
	/* input validation */
65
	if ($_POST['enable']) {
66
		$reqdfields = explode(" ", "mode ssid");
67
		$reqdfieldsn = explode(",", "Mode,SSID");
68
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
69
		
70
		if (!$input_errors) {
71
			/* bridge check (hostap only!) */
72
			if ($pconfig['bridge'] && ($pconfig['mode'] != "hostap"))
73
				$input_errors[] = "Bridging a wireless interface is only possible in hostap mode.";
74
		}
75
	}
76

    
77
	if (!$input_errors) {
78
	
79
		$optcfg['wireless']['standard'] = $_POST['standard'];
80
		$optcfg['wireless']['mode'] = $_POST['mode'];
81
		$optcfg['wireless']['ssid'] = $_POST['ssid'];
82
		$optcfg['wireless']['ssid'] = $_POST['ssid'];
83
		$optcfg['wireless']['hidessid'] = $_POST['hidessid'];
84
		$optcfg['wireless']['stationname'] = $_POST['stationname'];
85
		$optcfg['wireless']['channel'] = $_POST['channel'];
86
		$optcfg['wireless']['txpower'] = $_POST['txpower'];
87
		$optcfg['wireless']['wep']['enable'] = $_POST['wep_enable'] ? true : false;
88
		
89
		$optcfg['wireless']['wep']['key'] = array();
90
		for ($i = 1; $i <= 4; $i++) {
91
			if ($_POST['key' . $i]) {
92
				$newkey = array();
93
				$newkey['value'] = $_POST['key' . $i];
94
				if ($_POST['txkey'] == $i)
95
					$newkey['txkey'] = true;
96
				$optcfg['wireless']['wep']['key'][] = $newkey;
97
			}
98
		}
99
	}
100
	
101
	return $input_errors;
102
}
103

    
104
function wireless_config_print() {
105
	global $optcfg, $pconfig, $wlchannels;
106
?>
107
                <tr> 
108
                  <td colspan="2" valign="top" height="16"></td>
109
				</tr>
110
                <tr> 
111
                  <td colspan="2" valign="top" class="listtopic">Wireless configuration</td>
112
				</tr>
113
				
114
				<?php if (stristr($optcfg['if'], "ath") == true): ?>
115
                <tr>
116
                  <td valign="top" class="vncellreq">Standard</td>
117
                  <td class="vtable"><select name="standard" class="formfld" id="standard">
118
                      <?php
119
					  $standards = array("11b" => "802.11b", "11g" => "802.11g", "11a" => "802.11a");
120
					  foreach ($standards as $sn => $sv): ?>
121
                      <option value="<?=$sn;?>" <?php if ($sn == $pconfig['standard']) echo "selected";?>>
122
                      <?=$sv;?>
123
                      </option>
124
                      <?php endforeach; ?>
125
                    </select></td>
126
                </tr>
127
				<?php endif; ?>
128
                <tr> 
129
                  <td valign="top" class="vncellreq">Mode</td>
130
                  <td class="vtable"><select name="mode" class="formfld" id="mode">
131
                      <?php 
132
						$opts = array();
133
						if (strstr($optcfg['if'], "wi") ||
134
							strstr($optcfg['if'], "ath"))
135
							$opts[] = "hostap";
136
						$opts[] = "BSS";
137
						$opts[] = "IBSS";
138
				foreach ($opts as $opt): ?>
139
                      <option <?php if ($opt == $pconfig['mode']) echo "selected";?>> 
140
                      <?=htmlspecialchars($opt);?>
141
                      </option>
142
                      <?php endforeach; ?>
143
                    </select> <br>
144
                    Note: IBSS mode is sometimes also called &quot;ad-hoc&quot; 
145
                    mode;<br>
146
                    BSS mode is also known as &quot;infrastructure&quot; mode</td>
147
				</tr>
148
                <tr> 
149
                  <td valign="top" class="vncellreq">SSID</td>
150
                  <td class="vtable"><?=$mandfldhtml;?><input name="ssid" type="text" class="formfld" id="ssid" size="20" value="<?=htmlspecialchars($pconfig['ssid']);?>">
151
                  </td>
152
                </tr>
153

    
154
                <tr> 
155
                  <td valign="top" class="vncellreq">Hide SSID</td>
156
                  <td class="vtable">
157
		  <?php
158
			if(isset($pconfig['hidessid']))
159
				$CHECKED = " CHECKED";
160
			else
161
				$CHECKED = "";
162
		  ?>
163
		  <input name="hidessid" type="checkbox" class="formfld" id="hidessid"<?php echo $CHECKED; ?>"><br>
164
		  If your operating an access point this option will hide the SSID from being seen by the general public.
165
                  </td>
166
                </tr>
167

    
168
                <tr> 
169
                  <td valign="top" class="vncellreq">802.11g only</td>
170
                  <td class="vtable">
171
		  <?php
172
			if(isset($pconfig['pureg']))
173
				$CHECKED = " CHECKED";
174
			else
175
				$CHECKED = "";
176
		  ?>
177
		  <input name="pureg" type="checkbox" class="formfld" id="pureg"<?php echo $CHECKED; ?>><br>
178
		  When operating as an access point in 802.11g mode allow only 11g-capable stations to associate (11b-only stations are not permitted to associate).
179
                  </td>
180
                </tr>
181

    
182
                <tr> 
183
                  <td valign="top" class="vncellreq">Transmit power</td>
184
                  <td class="vtable">
185
			<select name="txpower">
186
				<?php
187
				for($x = 100; $x > 0; $x--) {
188
					if($pconfig["txpower"] == $x)
189
						$SELECTED = " SELECTED";
190
					else
191
						$SELECTED = "";
192
					echo "<option {$SELECTED}>{$x}</option>\n";
193
				}
194
				?>
195
			</select> <br>
196
			Note: Typically only a few discreet power settings are available and the driver will use the setting closest to the specified value.  Not all adaptors support changing the transmit power setting.
197
                  </td>
198
                </tr>
199

    
200
                <tr> 
201
                  <td valign="top" class="vncellreq">Channel</td>
202
                  <td class="vtable"><select name="channel" class="formfld" id="channel">
203
                      <option <?php if ($pconfig['channel'] == 0) echo "selected";?> value="0">Auto</option>
204
                      <?php
205
					  foreach ($wlchannels as $channel): ?>
206
                      <option <?php if ($channel == $pconfig['channel']) echo "selected";?> value="<?=$channel;?>">
207
                      <?=$channel;?>
208
                      </option>
209
                      <?php endforeach; ?>
210
                    </select> <br>
211
                    Note: Not all channels may be supported by your card</td>
212
                </tr>
213
                <tr> 
214
                  <td valign="top" class="vncell">Station name</td>
215
                  <td class="vtable"><input name="stationname" type="text" class="formfld" id="stationname" size="20" value="<?=htmlspecialchars($pconfig['stationname']);?>"> 
216
                    <br>
217
                    Hint: this field can usually be left blank</td>
218
                </tr>
219
                <tr> 
220
                  <td valign="top" class="vncell">WEP</td>
221
                  <td class="vtable"> <input name="wep_enable" type="checkbox" id="wep_enable" value="yes" <?php if ($pconfig['wep_enable']) echo "checked"; ?>> 
222
                    <strong>Enable WEP</strong>
223
                    <table border="0" cellspacing="0" cellpadding="0">
224
                      <tr> 
225
                        <td>&nbsp;</td>
226
                        <td>&nbsp;</td>
227
                        <td>&nbsp;TX key&nbsp;</td>
228
                      </tr>
229
                      <tr> 
230
                        <td>Key 1:&nbsp;&nbsp;</td>
231
                        <td> <input name="key1" type="text" class="formfld" id="key1" size="30" value="<?=htmlspecialchars($pconfig['key1']);?>"></td>
232
                        <td align="center"> <input name="txkey" type="radio" value="1" <?php if ($pconfig['txkey'] == 1) echo "checked";?>> 
233
                        </td>
234
                      </tr>
235
                      <tr> 
236
                        <td>Key 2:&nbsp;&nbsp;</td>
237
                        <td> <input name="key2" type="text" class="formfld" id="key2" size="30" value="<?=htmlspecialchars($pconfig['key2']);?>"></td>
238
                        <td align="center"> <input name="txkey" type="radio" value="2" <?php if ($pconfig['txkey'] == 2) echo "checked";?>></td>
239
                      </tr>
240
                      <tr> 
241
                        <td>Key 3:&nbsp;&nbsp;</td>
242
                        <td> <input name="key3" type="text" class="formfld" id="key3" size="30" value="<?=htmlspecialchars($pconfig['key3']);?>"></td>
243
                        <td align="center"> <input name="txkey" type="radio" value="3" <?php if ($pconfig['txkey'] == 3) echo "checked";?>></td>
244
                      </tr>
245
                      <tr> 
246
                        <td>Key 4:&nbsp;&nbsp;</td>
247
                        <td> <input name="key4" type="text" class="formfld" id="key4" size="30" value="<?=htmlspecialchars($pconfig['key4']);?>"></td>
248
                        <td align="center"> <input name="txkey" type="radio" value="4" <?php if ($pconfig['txkey'] == 4) echo "checked";?>></td>
249
                      </tr>
250
                    </table>
251
                    <br>
252
                    40 (64) bit keys may be entered as 5 ASCII characters or 10 
253
                    hex digits preceded by '0x'.<br>
254
                    104 (128) bit keys may be entered as 13 ASCII characters or 
255
                    26 hex digits preceded by '0x'.</td>
256
                </tr>
257
<?php } ?>
(64-64/143)