From 8600af6f3053b09e80049d22634fd3eebffdbf0d Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Sun, 14 Aug 2005 18:09:11 +0000 Subject: Enforce wep key sizes Ticket #344 --- usr/local/www/interfaces_wlan.inc | 244 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100755 usr/local/www/interfaces_wlan.inc (limited to 'usr/local/www') diff --git a/usr/local/www/interfaces_wlan.inc b/usr/local/www/interfaces_wlan.inc new file mode 100755 index 0000000..08dee1a --- /dev/null +++ b/usr/local/www/interfaces_wlan.inc @@ -0,0 +1,244 @@ +. + 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. +*/ + +$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); + +function wireless_config_init() { + global $optcfg, $pconfig; + + $pconfig['standard'] = $optcfg['wireless']['standard']; + $pconfig['mode'] = $optcfg['wireless']['mode']; + $pconfig['ssid'] = $optcfg['wireless']['ssid']; + $pconfig['stationname'] = $optcfg['wireless']['stationname']; + $pconfig['channel'] = $optcfg['wireless']['channel']; + $pconfig['txpower'] = $optcfg['wireless']['txpower']; + $pconfig['wep_enable'] = isset($optcfg['wireless']['wep']['enable']); + + 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; + + unset($input_errors); + + /* input validation */ + if ($_POST['enable']) { + $reqdfields = explode(" ", "mode ssid"); + $reqdfieldsn = explode(",", "Mode,SSID"); + do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); + + 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."; + } + } + + /* loop through keys and enforce size */ + for ($i = 1; $i <= 4; $i++) { + if ($_POST['key' . $i]) { + if(strlen($_POST['key' . $i]) <> 40 and strlen($_POST['key' . $i]) <> 104) { + $input_errors[] = "Invalid wep key size. Sizes should be 40 (64) bit keys or 104 (128) bit."; + } + } + } + + if (!$input_errors) { + + $optcfg['wireless']['standard'] = $_POST['standard']; + $optcfg['wireless']['mode'] = $_POST['mode']; + $optcfg['wireless']['ssid'] = $_POST['ssid']; + $optcfg['wireless']['stationname'] = $_POST['stationname']; + $optcfg['wireless']['channel'] = $_POST['channel']; + $optcfg['wireless']['txpower'] = $_POST['txpower']; + $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; + } + } + } + + return $input_errors; +} + +function wireless_config_print() { + global $optcfg, $pconfig, $wlchannels, $g; +?> + + + + + Wireless configuration + + + + Standard + + + + + Mode +
+ Note: IBSS mode is sometimes also called "ad-hoc" + mode;
+ BSS mode is also known as "infrastructure" mode + + + SSID + + + + + 802.11g only + + + >
+ 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). + + + + Transmit power + +
+ 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. + + + + Channel +
+ Note: Not all channels may be supported by your card + + + Station name + +
+ Hint: this field can usually be left blank + + + 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'. + + -- cgit v1.1