. 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. */ $wlstandards = wireless_get_standards($optcfg['if']); $wlchannels = wireless_get_channellist($optcfg['if']); function wireless_get_standards($if) { $standards = array(); $fd = popen("/sbin/ifconfig -m $if", "r"); if ($fd) { while (!feof($fd)) { $line = trim(fgets($fd)); if (preg_match("/media \S+ mode (11\S+)/", $line, $matches)) { $standards[] = $matches[1]; } } } return array_unique($standards); } function wireless_get_channellist($if) { $chanlist = array(); $fd = popen("/sbin/ifconfig $if list chan", "r"); if ($fd) { while (!feof($fd)) { $line = trim(fgets($fd)); /* could have two channels on this line */ $chans = explode("Channel", $line); foreach ($chans as $chan) { if (preg_match("/(\d+)\s+:\s+(\d+)\s+Mhz\s+(.+)/", $chan, $matches)) { $chaninfo = array(); $chaninfo['chan'] = $matches[1]; $chaninfo['freq'] = $matches[2]; $chaninfo['mode'] = trim($matches[3]); $chanlist[$chaninfo['chan']] = $chaninfo; } } } pclose($fd); } ksort($chanlist, SORT_NUMERIC); return $chanlist; } function wireless_config_init() { global $optcfg, $pconfig; $pconfig['standard'] = $optcfg['wireless']['standard']; $pconfig['mode'] = $optcfg['wireless']['mode']; $pconfig['ssid'] = $optcfg['wireless']['ssid']; $pconfig['channel'] = $optcfg['wireless']['channel']; $pconfig['wep_enable'] = isset($optcfg['wireless']['wep']['enable']); $pconfig['hidessid'] = isset($optcfg['wireless']['hidessid']); $pconfig['wpamode'] = $optcfg['wireless']['wpa']['mode']; $pconfig['wpaversion'] = $optcfg['wireless']['wpa']['version']; $pconfig['wpacipher'] = $optcfg['wireless']['wpa']['cipher']; $pconfig['wpapsk'] = $optcfg['wireless']['wpa']['psk']; $pconfig['radiusip'] = $optcfg['wireless']['wpa']['radius']['server']; $pconfig['radiusauthport'] = $optcfg['wireless']['wpa']['radius']['authport']; $pconfig['radiusacctport'] = $optcfg['wireless']['wpa']['radius']['acctport']; $pconfig['radiussecret'] = $optcfg['wireless']['wpa']['radius']['secret']; if (is_array($optcfg['wireless']['wep']['key'])) { $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; } } function wireless_config_post() { global $optcfg, $pconfig, $wlchannels; unset($input_errors); /* input validation */ if ($_POST['enable']) { $reqdfields = "mode ssid channel"; $reqdfieldsn = "Mode,SSID,Channel"; if ($_POST['wpamode'] != "none") { $reqdfields .= " wpaversion wpacipher"; $reqdfieldsn .= ",WPA version,WPA cipher"; if ($_POST['wpamode'] == "psk") { $reqdfields .= " wpapsk"; $reqdfieldsn .= ",WPA PSK"; } else if ($_POST['wpamode'] == "enterprise") { $reqdfields .= " radiusip radiussecret"; $reqdfieldsn .= ",RADIUS IP,RADIUS Shared secret"; } } do_input_validation($_POST, explode(" ", $reqdfields), explode(",", $reqdfieldsn), &$input_errors); if ($_POST['radiusip'] && !is_ipaddr($_POST['radiusip'])) $input_errors[] = "A valid RADIUS IP address must be specified."; if ($_POST['radiusauthport'] && !is_port($_POST['radiusauthport'])) $input_errors[] = "A valid RADIUS authentication port number must be specified."; if ($_POST['radiusacctport'] && !is_port($_POST['radiusacctport'])) $input_errors[] = "A valid RADIUS accounting port number must be specified."; if ($_POST['wpapsk'] && !(strlen($_POST['wpapsk']) >= 8 && strlen($_POST['wpapsk']) <= 63)) $input_errors[] = "The WPA PSK must be between 8 and 63 characters long."; if (!$input_errors) { /* bridge check (hostap only!) */ if ($pconfig['bridge'] && ($pconfig['mode'] != "hostap")) $input_errors[] = "Bridging a wireless interface is only possible in hostap mode."; /* if an 11a channel is selected, the mode must be 11a too, and vice versa */ $is_chan_11a = (strpos($wlchannels[$_POST['channel']]['mode'], "11a") !== false); $is_std_11a = ($_POST['standard'] == "11a"); if ($is_chan_11a && !$is_std_11a) $input_errors[] = "802.11a channels can only be selected if the standard is set to 802.11a too."; else if (!$is_chan_11a && $is_std_11a) $input_errors[] = "802.11a can only be selected if an 802.11a channel is selected too."; /* currently, WPA is only supported in AP (hostap) mode */ if ($_POST['wpamode'] != "none" && $pconfig['mode'] != "hostap") $input_errors[] = "WPA is only supported in hostap mode."; } } if (!$input_errors) { $optcfg['wireless']['standard'] = $_POST['standard']; $optcfg['wireless']['mode'] = $_POST['mode']; $optcfg['wireless']['ssid'] = $_POST['ssid']; $optcfg['wireless']['channel'] = $_POST['channel']; $optcfg['wireless']['wep']['enable'] = $_POST['wep_enable'] ? true : false; $optcfg['wireless']['hidessid'] = $_POST['hidessid'] ? 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'] = array(); $optcfg['wireless']['wpa']['mode'] = $_POST['wpamode']; $optcfg['wireless']['wpa']['version'] = $_POST['wpaversion']; $optcfg['wireless']['wpa']['cipher'] = $_POST['wpacipher']; $optcfg['wireless']['wpa']['psk'] = $_POST['wpapsk']; $optcfg['wireless']['wpa']['radius'] = array(); $optcfg['wireless']['wpa']['radius']['server'] = $_POST['radiusip']; $optcfg['wireless']['wpa']['radius']['authport'] = $_POST['radiusauthport']; $optcfg['wireless']['wpa']['radius']['acctport'] = $_POST['radiusacctport']; $optcfg['wireless']['wpa']['radius']['secret'] = $_POST['radiussecret']; } return $input_errors; } function wireless_config_print() { global $g, $optcfg, $pconfig, $wlchannels, $wlstandards; ?> Wireless configuration Standard Mode
Note: To create an access-point, choose "hostap" mode. IBSS mode is sometimes also called "ad-hoc" mode; BSS mode is also known as "infrastructure" mode. SSID

>Hide SSID
If this option is selected, the SSID will not be broadcast in hostap mode, and only clients that know the exact SSID will be able to connect. Note that this option should never be used as a substitute for proper security/encryption settings. Channel WPA
WPA settings
Mode
Version
In most cases, you should select "WPA + WPA2" here.
Cipher
AES/CCMP provides better security than TKIP, but TKIP is more compatible with older hardware.
PSK
Enter the passphrase that will be used in WPA-PSK mode. This must be between 8 and 63 characters long.
RADIUS server
IP address
Enter the IP address of the RADIUS server that will be used in WPA-Enterprise mode.
Authentication port
Leave this field blank to use the default port (1812).
Accounting port
Leave this field blank to use the default port (1813).
Shared secret  
WEP > Enable WEP
     TX key 
Key 1:   >
Key 2:   >
Key 3:   >
Key 4:   >

40 (64) bit keys may be entered as 5 ASCII characters or 10 hex digits preceded by '0x'.
104 (128) bit keys may be entered as 13 ASCII characters or 26 hex digits preceded by '0x'.