Menu

[r3485]: / trunk / www / interfaces_wlan.inc  Maximize  Restore  History

Download this file

201 lines (173 with data), 9.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/*
interfaces_wlan.inc
part of m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
function wireless_config_init() {
global $optcfg, $pconfig;
$pconfig['standard'] = $optcfg['wireless']['standard'];
$pconfig['ssid'] = $optcfg['wireless']['ssid'];
$pconfig['stationname'] = $optcfg['wireless']['stationname'];
$pconfig['channel'] = $optcfg['wireless']['channel'];
$pconfig['wep_enable'] = isset($optcfg['wireless']['wep']['enable']);
$pconfig['wpa_enable'] = isset($optcfg['wireless']['wpa']['enable']);
if (is_array($optcfg['wireless']['wep'])) {
$i = 1;
foreach ($optcfg['wireless']['wep']['key'] as $wepkey) {
$pconfig['key' . $i] = $wepkey['value'];
if (isset($wepkey['txkey']))
$pconfig['txkey'] = $i;
$i++;
}
if (!isset($wepkey['txkey']))
$pconfig['txkey'] = 1;
}
if (is_array($optcfg['wireless']['wpa'])) {
$pconfig['keymgmt'] = $optcfg['wireless']['wpa']['wpa_keymgmt'];
$pconfig['pairwise'] = $optcfg['wireless']['wpa']['wpa_pairwise'];
$pconfig['psk'] = $optcfg['wireless']['wpa']['psk'];
}
}
function wireless_config_post() {
global $optcfg, $pconfig;
unset($input_errors);
// Input validation
if ($_POST['enable']) {
$reqdfields = explode(" ", "standard ssid channel");
$reqdfieldsn = array(gettext("Standard"), gettext("SSID"), gettext("Channel"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
}
if (!$input_errors) {
$optcfg['wireless']['standard'] = $_POST['standard'];
$optcfg['wireless']['ssid'] = $_POST['ssid'];
$optcfg['wireless']['stationname'] = $_POST['stationname'];
$optcfg['wireless']['channel'] = $_POST['channel'];
$optcfg['wireless']['wep']['enable'] = $_POST['wep_enable'] ? true : false;
$optcfg['wireless']['wep']['key'] = array();
for ($i = 1; $i <= 4; $i++) {
if ($_POST['key' . $i]) {
$newkey = array();
$newkey['value'] = $_POST['key' . $i];
if ($_POST['txkey'] == $i)
$newkey['txkey'] = true;
$optcfg['wireless']['wep']['key'][] = $newkey;
}
}
$optcfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] ? true : false;
$optcfg['wireless']['wpa']['keymgmt'] = $_POST['wpa_keymgmt'];
$optcfg['wireless']['wpa']['pairwise'] = $_POST['wpa_pairwise'];
$optcfg['wireless']['wpa']['psk'] = $_POST['wpa_psk'];
}
return $input_errors;
}
function wireless_get_channellist($if) {
$a_chanlist = array();
exec("/sbin/ifconfig {$if} list chan", $rawdata);
foreach ($rawdata as $line) {
$line = trim($line);
foreach (explode("Channel", $line) as $channelv) {
if (preg_match("/(\d+)\s+:\s+(\d+)\s+Mhz\s+(.+)/", $channelv, $matches)) {
$info = array();
$info['channel'] = $matches[1];
$info['freq'] = $matches[2];
$info['mode'] = trim($matches[3]);
$a_chanlist[$info['channel']] = $info;
}
}
}
ksort($a_chanlist, SORT_NUMERIC);
return $a_chanlist;
}
function wireless_get_standards($if) {
$a_standards = array();
exec("/sbin/ifconfig -m {$if}", $rawdata);
foreach ($rawdata as $line) {
$line = trim($line);
if (preg_match("/media \S+ mode (11\S+)/", $line, $matches)) {
$a_standards[] = $matches[1];
}
}
return array_unique($a_standards);
}
function wireless_config_print() {
global $optcfg, $pconfig;
?>
<?php html_separator();?>
<?php html_titleline(gettext("Wireless configuration"));?>
<?php $a_standard = array(); foreach (wireless_get_standards($optcfg['if']) as $standardv) { $a_standard[$standardv] = "802.{$standardv}"; }?>
<?php html_combobox("standard", gettext("Standard"), $pconfig['standard'], $a_standard, gettext(""), true);?>
<?php html_inputbox("ssid", gettext("SSID"), $pconfig['ssid'], gettext("Set the desired Service Set Identifier (aka network name)."), true, 20);?>
<tr>
<td valign="top" class="vncellreq"><?=gettext("Channel");?></td>
<td class="vtable">
<select name="channel" class="formfld" id="channel">
<option <?php if ("any" === $pconfig['channel']) echo "selected";?> value="any"><?=gettext("Auto");?></option>
<?php foreach (wireless_get_channellist($optcfg['if']) as $channelk => $channelv):?>
<?php if ($channelv['mode'] === "11g") $mode = "11b/g"; else $mode = $channelv['mode'];?>
<option <?php if ($channelk == $pconfig['channel']) echo "selected";?> value="<?=$channelk;?>"><?="{$channelv['channel']} ({$channelv['freq']} MHz, {$mode})";?></option>
<?php endforeach;?>
</select>
</td>
</tr>
<?php html_inputbox("stationname", gettext("Station name"), $pconfig['stationname'], gettext("Set the name of this station (usually empty)."), false, 20);?>
<?php html_separator();?>
<?php html_titleline_checkbox("wep_enable", gettext("WEP"), $pconfig['wep_enable'] ? true : false, gettext("Enable"));?>
<tr>
<td valign="top" class="vncellreq"><?=gettext("Key");?></td>
<td class="vtable">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;TX key&nbsp;</td>
</tr>
<tr>
<td>Key 1:&nbsp;&nbsp;</td>
<td> <input name="key1" type="text" class="formfld" id="key1" size="30" value="<?=htmlspecialchars($pconfig['key1']);?>"></td>
<td align="center"> <input name="txkey" type="radio" value="1" <?php if ($pconfig['txkey'] == 1) echo "checked";?>>
</td>
</tr>
<tr>
<td>Key 2:&nbsp;&nbsp;</td>
<td> <input name="key2" type="text" class="formfld" id="key2" size="30" value="<?=htmlspecialchars($pconfig['key2']);?>"></td>
<td align="center"> <input name="txkey" type="radio" value="2" <?php if ($pconfig['txkey'] == 2) echo "checked";?>></td>
</tr>
<tr>
<td>Key 3:&nbsp;&nbsp;</td>
<td> <input name="key3" type="text" class="formfld" id="key3" size="30" value="<?=htmlspecialchars($pconfig['key3']);?>"></td>
<td align="center"> <input name="txkey" type="radio" value="3" <?php if ($pconfig['txkey'] == 3) echo "checked";?>></td>
</tr>
<tr>
<td>Key 4:&nbsp;&nbsp;</td>
<td> <input name="key4" type="text" class="formfld" id="key4" size="30" value="<?=htmlspecialchars($pconfig['key4']);?>"></td>
<td align="center"> <input name="txkey" type="radio" value="4" <?php if ($pconfig['txkey'] == 4) echo "checked";?>></td>
</tr>
</table><br/>
<?=gettext("A key will be either 5 or 13 characters (40 or 104 bits) depending of the local network and the capabilities of the adaptor. It may be specified either as a plain string or as a string of hexadecimal digits preceded by '0x'.")?>
</td>
</tr>
<?php html_separator();?>
<?php html_titleline_checkbox("wpa_enable", gettext("WPA"), $pconfig['wpa_enable'] ? true : false, gettext("Enable"));?>
<?php html_combobox("wpa_keymgmt", gettext("Key Management Protocol"), $pconfig['wpa_keymgmt'], array("WPA-PSK" => gettext("WPA-PSK (Pre Shared Key)"), "WPA-EAP" => gettext("WPA-EAP (Extensible Authentication Protocol)"), "WPA-PSK WPA-EAP" => gettext("WPA-PSK WPA-EAP")), gettext(""), true);?>
<?php html_combobox("wpa_pairwise", gettext("Pairwise"), $pconfig['wpa_pairwise'], array("CCMP TKIP" => gettext("CCMP TKIP"), "CCMP" => gettext("CCMP"), "TKIP" => gettext("TKIP")), gettext("List of acceptable pairwise (unicast) ciphers for WPA. One or more of: CCMP (AES in Counter mode with CBC-MAC, RFC 3610, IEEE 802.11i/D7.0), TKIP (Temporal Key Integrity Protocol, IEEE 802.11i/D7.0)."), true);?>
<?php html_inputbox("wpa_psk", gettext("PSK"), $pconfig['wpa_psk'], gettext("Enter the passphrase that will be used in WPA-PSK mode. This must be between 8 and 63 characters long."), false, 40);?>
<?php } ?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.