1 |
8600af6f
|
Scott Ullrich
|
<?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['stationname'] = $optcfg['wireless']['stationname'];
|
41 |
|
|
$pconfig['channel'] = $optcfg['wireless']['channel'];
|
42 |
|
|
$pconfig['txpower'] = $optcfg['wireless']['txpower'];
|
43 |
|
|
$pconfig['wep_enable'] = isset($optcfg['wireless']['wep']['enable']);
|
44 |
|
|
|
45 |
|
|
if (is_array($optcfg['wireless']['wep']['key'])) {
|
46 |
|
|
$i = 1;
|
47 |
|
|
foreach ($optcfg['wireless']['wep']['key'] as $wepkey) {
|
48 |
|
|
$pconfig['key' . $i] = $wepkey['value'];
|
49 |
|
|
if (isset($wepkey['txkey']))
|
50 |
|
|
$pconfig['txkey'] = $i;
|
51 |
|
|
$i++;
|
52 |
|
|
}
|
53 |
|
|
if (!isset($wepkey['txkey']))
|
54 |
|
|
$pconfig['txkey'] = 1;
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
function wireless_config_post() {
|
59 |
|
|
global $optcfg, $pconfig;
|
60 |
|
|
|
61 |
|
|
unset($input_errors);
|
62 |
|
|
|
63 |
|
|
/* input validation */
|
64 |
|
|
if ($_POST['enable']) {
|
65 |
|
|
$reqdfields = explode(" ", "mode ssid");
|
66 |
|
|
$reqdfieldsn = explode(",", "Mode,SSID");
|
67 |
|
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
68 |
|
|
|
69 |
|
|
if (!$input_errors) {
|
70 |
|
|
/* bridge check (hostap only!) */
|
71 |
|
|
if ($pconfig['bridge'] && ($pconfig['mode'] != "hostap"))
|
72 |
|
|
$input_errors[] = "Bridging a wireless interface is only possible in hostap mode.";
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/* loop through keys and enforce size */
|
77 |
|
|
for ($i = 1; $i <= 4; $i++) {
|
78 |
|
|
if ($_POST['key' . $i]) {
|
79 |
192fd3d1
|
Scott Ullrich
|
/* 64 bit */
|
80 |
ea206efb
|
Scott Ullrich
|
if(strlen($_POST['key' . $i]) == 5)
|
81 |
|
|
continue;
|
82 |
bcf53132
|
Scott Ullrich
|
if(strlen($_POST['key' . $i]) == 10) {
|
83 |
|
|
/* hex key */
|
84 |
|
|
if(stristr($_POST['key' . $i], "0x") == false) {
|
85 |
|
|
$_POST['key' . $i] = "0x" . $_POST['key' . $i];
|
86 |
|
|
}
|
87 |
ea206efb
|
Scott Ullrich
|
continue;
|
88 |
bcf53132
|
Scott Ullrich
|
}
|
89 |
18547c5d
|
Scott Ullrich
|
if(strlen($_POST['key' . $i]) == 12) {
|
90 |
|
|
/* hex key */
|
91 |
|
|
if(stristr($_POST['key' . $i], "0x") == false) {
|
92 |
|
|
$_POST['key' . $i] = "0x" . $_POST['key' . $i];
|
93 |
|
|
}
|
94 |
|
|
continue;
|
95 |
|
|
}
|
96 |
192fd3d1
|
Scott Ullrich
|
/* 128 bit */
|
97 |
ea206efb
|
Scott Ullrich
|
if(strlen($_POST['key' . $i]) == 13)
|
98 |
|
|
continue;
|
99 |
bcf53132
|
Scott Ullrich
|
if(strlen($_POST['key' . $i]) == 26) {
|
100 |
|
|
/* hex key */
|
101 |
|
|
if(stristr($_POST['key' . $i], "0x") == false) {
|
102 |
|
|
$_POST['key' . $i] = "0x" . $_POST['key' . $i];
|
103 |
|
|
}
|
104 |
ea206efb
|
Scott Ullrich
|
continue;
|
105 |
bcf53132
|
Scott Ullrich
|
}
|
106 |
c33565ad
|
Scott Ullrich
|
if(strlen($_POST['key' . $i]) == 28)
|
107 |
|
|
continue;
|
108 |
ea206efb
|
Scott Ullrich
|
$input_errors[] = "Invalid wep key size. Sizes should be 40 (64) bit keys or 104 (128) bit.";
|
109 |
b4197106
|
Scott Ullrich
|
break;
|
110 |
8600af6f
|
Scott Ullrich
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
if (!$input_errors) {
|
114 |
|
|
|
115 |
|
|
$optcfg['wireless']['standard'] = $_POST['standard'];
|
116 |
|
|
$optcfg['wireless']['mode'] = $_POST['mode'];
|
117 |
|
|
$optcfg['wireless']['ssid'] = $_POST['ssid'];
|
118 |
|
|
$optcfg['wireless']['stationname'] = $_POST['stationname'];
|
119 |
|
|
$optcfg['wireless']['channel'] = $_POST['channel'];
|
120 |
|
|
$optcfg['wireless']['txpower'] = $_POST['txpower'];
|
121 |
|
|
$optcfg['wireless']['wep']['enable'] = $_POST['wep_enable'] ? true : false;
|
122 |
|
|
|
123 |
|
|
$optcfg['wireless']['wep']['key'] = array();
|
124 |
|
|
for ($i = 1; $i <= 4; $i++) {
|
125 |
|
|
if ($_POST['key' . $i]) {
|
126 |
|
|
$newkey = array();
|
127 |
|
|
$newkey['value'] = $_POST['key' . $i];
|
128 |
|
|
if ($_POST['txkey'] == $i)
|
129 |
|
|
$newkey['txkey'] = true;
|
130 |
|
|
$optcfg['wireless']['wep']['key'][] = $newkey;
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
return $input_errors;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
function wireless_config_print() {
|
139 |
|
|
global $optcfg, $pconfig, $wlchannels, $g;
|
140 |
|
|
?>
|
141 |
f881baa3
|
Scott Ullrich
|
|
142 |
|
|
<script language="JavaScript">
|
143 |
|
|
function openwindow(url) {
|
144 |
|
|
var oWin = window.open(url,"pfSensePop","width=620,height=400,top=150,left=150");
|
145 |
|
|
if (oWin==null || typeof(oWin)=="undefined") {
|
146 |
|
|
return false;
|
147 |
|
|
} else {
|
148 |
|
|
return true;
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
</script>
|
152 |
8600af6f
|
Scott Ullrich
|
<tr>
|
153 |
|
|
<td colspan="2" valign="top" height="16"></td>
|
154 |
|
|
</tr>
|
155 |
|
|
<tr>
|
156 |
|
|
<td colspan="2" valign="top" class="listtopic">Wireless configuration</td>
|
157 |
|
|
</tr>
|
158 |
|
|
<?php if (preg_match($g['wireless_regex'], $optcfg['if'])): ?>
|
159 |
|
|
<tr>
|
160 |
|
|
<td valign="top" class="vncellreq">Standard</td>
|
161 |
|
|
<td class="vtable"><select name="standard" class="formfld" id="standard">
|
162 |
|
|
<?php
|
163 |
|
|
$standards = array("11b" => "802.11b", "11g" => "802.11g", "11a" => "802.11a");
|
164 |
|
|
foreach ($standards as $sn => $sv): ?>
|
165 |
|
|
<option value="<?=$sn;?>" <?php if ($sn == $pconfig['standard']) echo "selected";?>>
|
166 |
|
|
<?=$sv;?>
|
167 |
|
|
</option>
|
168 |
|
|
<?php endforeach; ?>
|
169 |
|
|
</select></td>
|
170 |
|
|
</tr>
|
171 |
|
|
<?php endif; ?>
|
172 |
|
|
<tr>
|
173 |
|
|
<td valign="top" class="vncellreq">Mode</td>
|
174 |
|
|
<td class="vtable"><select name="mode" class="formfld" id="mode">
|
175 |
|
|
<?php
|
176 |
|
|
$opts = array();
|
177 |
|
|
if (preg_match($g['wireless_regex'], $optcfg['if']))
|
178 |
|
|
$opts[] = "hostap";
|
179 |
|
|
$opts[] = "BSS";
|
180 |
|
|
$opts[] = "IBSS";
|
181 |
|
|
foreach ($opts as $opt): ?>
|
182 |
|
|
<option <?php if ($opt == $pconfig['mode']) echo "selected";?>>
|
183 |
|
|
<?=htmlspecialchars($opt);?>
|
184 |
|
|
</option>
|
185 |
|
|
<?php endforeach; ?>
|
186 |
|
|
</select> <br>
|
187 |
|
|
Note: IBSS mode is sometimes also called "ad-hoc"
|
188 |
|
|
mode;<br>
|
189 |
|
|
BSS mode is also known as "infrastructure" mode</td>
|
190 |
|
|
</tr>
|
191 |
|
|
<tr>
|
192 |
|
|
<td valign="top" class="vncellreq">SSID</td>
|
193 |
|
|
<td class="vtable"><?=$mandfldhtml;?><input name="ssid" type="text" class="formfld" id="ssid" size="20" value="<?=htmlspecialchars($pconfig['ssid']);?>">
|
194 |
|
|
</td>
|
195 |
|
|
</tr>
|
196 |
|
|
<tr>
|
197 |
|
|
<td valign="top" class="vncellreq">802.11g only</td>
|
198 |
|
|
<td class="vtable">
|
199 |
|
|
<?php
|
200 |
|
|
if(isset($pconfig['pureg']))
|
201 |
|
|
$CHECKED = " CHECKED";
|
202 |
|
|
else
|
203 |
|
|
$CHECKED = "";
|
204 |
|
|
?>
|
205 |
|
|
<input name="pureg" type="checkbox" class="formfld" id="pureg"<?php echo $CHECKED; ?>><br>
|
206 |
|
|
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).
|
207 |
|
|
</td>
|
208 |
|
|
</tr>
|
209 |
|
|
<tr>
|
210 |
|
|
<td valign="top" class="vncellreq">Transmit power</td>
|
211 |
|
|
<td class="vtable">
|
212 |
|
|
<select name="txpower">
|
213 |
|
|
<?php
|
214 |
60ae7b45
|
Scott Ullrich
|
for($x = 99; $x > 0; $x--) {
|
215 |
8600af6f
|
Scott Ullrich
|
if($pconfig["txpower"] == $x)
|
216 |
|
|
$SELECTED = " SELECTED";
|
217 |
|
|
else
|
218 |
|
|
$SELECTED = "";
|
219 |
|
|
echo "<option {$SELECTED}>{$x}</option>\n";
|
220 |
|
|
}
|
221 |
|
|
?>
|
222 |
|
|
</select> <br>
|
223 |
|
|
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.
|
224 |
|
|
</td>
|
225 |
|
|
</tr>
|
226 |
|
|
<tr>
|
227 |
|
|
<td valign="top" class="vncellreq">Channel</td>
|
228 |
|
|
<td class="vtable"><select name="channel" class="formfld" id="channel">
|
229 |
|
|
<option <?php if ($pconfig['channel'] == 0) echo "selected";?> value="0">Auto</option>
|
230 |
|
|
<?php
|
231 |
|
|
foreach ($wlchannels as $channel): ?>
|
232 |
|
|
<option <?php if ($channel == $pconfig['channel']) echo "selected";?> value="<?=$channel;?>">
|
233 |
|
|
<?=$channel;?>
|
234 |
|
|
</option>
|
235 |
|
|
<?php endforeach; ?>
|
236 |
|
|
</select> <br>
|
237 |
|
|
Note: Not all channels may be supported by your card</td>
|
238 |
|
|
</tr>
|
239 |
|
|
<tr>
|
240 |
|
|
<td valign="top" class="vncell">Station name</td>
|
241 |
|
|
<td class="vtable"><input name="stationname" type="text" class="formfld" id="stationname" size="20" value="<?=htmlspecialchars($pconfig['stationname']);?>">
|
242 |
|
|
<br>
|
243 |
|
|
Hint: this field can usually be left blank</td>
|
244 |
|
|
</tr>
|
245 |
|
|
<tr>
|
246 |
|
|
<td valign="top" class="vncell">WEP</td>
|
247 |
|
|
<td class="vtable"> <input name="wep_enable" type="checkbox" id="wep_enable" value="yes" <?php if ($pconfig['wep_enable']) echo "checked"; ?>>
|
248 |
|
|
<strong>Enable WEP</strong>
|
249 |
|
|
<table border="0" cellspacing="0" cellpadding="0">
|
250 |
|
|
<tr>
|
251 |
|
|
<td> </td>
|
252 |
|
|
<td> </td>
|
253 |
|
|
<td> TX key </td>
|
254 |
|
|
</tr>
|
255 |
|
|
<tr>
|
256 |
|
|
<td>Key 1: </td>
|
257 |
|
|
<td> <input name="key1" type="text" class="formfld" id="key1" size="30" value="<?=htmlspecialchars($pconfig['key1']);?>"></td>
|
258 |
|
|
<td align="center"> <input name="txkey" type="radio" value="1" <?php if ($pconfig['txkey'] == 1) echo "checked";?>>
|
259 |
|
|
</td>
|
260 |
|
|
</tr>
|
261 |
|
|
<tr>
|
262 |
|
|
<td>Key 2: </td>
|
263 |
|
|
<td> <input name="key2" type="text" class="formfld" id="key2" size="30" value="<?=htmlspecialchars($pconfig['key2']);?>"></td>
|
264 |
|
|
<td align="center"> <input name="txkey" type="radio" value="2" <?php if ($pconfig['txkey'] == 2) echo "checked";?>></td>
|
265 |
|
|
</tr>
|
266 |
|
|
<tr>
|
267 |
|
|
<td>Key 3: </td>
|
268 |
|
|
<td> <input name="key3" type="text" class="formfld" id="key3" size="30" value="<?=htmlspecialchars($pconfig['key3']);?>"></td>
|
269 |
|
|
<td align="center"> <input name="txkey" type="radio" value="3" <?php if ($pconfig['txkey'] == 3) echo "checked";?>></td>
|
270 |
|
|
</tr>
|
271 |
|
|
<tr>
|
272 |
|
|
<td>Key 4: </td>
|
273 |
|
|
<td> <input name="key4" type="text" class="formfld" id="key4" size="30" value="<?=htmlspecialchars($pconfig['key4']);?>"></td>
|
274 |
|
|
<td align="center"> <input name="txkey" type="radio" value="4" <?php if ($pconfig['txkey'] == 4) echo "checked";?>></td>
|
275 |
|
|
</tr>
|
276 |
|
|
</table>
|
277 |
|
|
<br>
|
278 |
|
|
40 (64) bit keys may be entered as 5 ASCII characters or 10
|
279 |
|
|
hex digits preceded by '0x'.<br>
|
280 |
|
|
104 (128) bit keys may be entered as 13 ASCII characters or
|
281 |
ecc738d3
|
Scott Ullrich
|
26 hex digits preceded by '0x'.
|
282 |
7293dad0
|
Scott Ullrich
|
<p>For assistance with creating keys, please see
|
283 |
ecc738d3
|
Scott Ullrich
|
<a href="javascript:if(openwindow('/wlan_strong_key_generator/generator.php') == false) alert('Popup blocker detected. Action aborted.');">WLAN Strong Key Generator</a>.
|
284 |
|
|
</td>
|
285 |
8600af6f
|
Scott Ullrich
|
</tr>
|
286 |
|
|
<?php } ?>
|