diff -urN wifiadmin-0.0.4/include/functions.php wifiadmin-0.0.4-modified/include/functions.php --- wifiadmin-0.0.4/include/functions.php 2004-12-22 00:45:00.000000000 +0200 +++ wifiadmin-0.0.4-modified/include/functions.php 2005-02-26 18:36:09.826564607 +0200 @@ -366,6 +366,9 @@ sscanf($device_status_string,"%s ",$device); if (strstr($device_status_string, "no wireless extensions") !== false) continue; + //ignore newest hostap fake devices, called wifix + if (strstr($device,"wifi") !==false) + continue; $devices_data[$device] = parse_iwconfig($device_status_string); $devices_data[$device]["name"] = $device; } @@ -384,6 +387,9 @@ //skip loopback interface if ($device == "lo") continue; + //ignore newest hostap fake devices, called wifix + if (strstr($device,"wifi") !==false) + continue; $device_status["Link encap"] = get_value($device_status_string,"Link encap:"); $device_status["hwaddr"] = get_value($device_status_string,"HWaddr"); $device_status["ipaddr"] = get_value($device_status_string,"inet addr:"); diff -urN wifiadmin-0.0.4/include/functions.php~ wifiadmin-0.0.4-modified/include/functions.php~ --- wifiadmin-0.0.4/include/functions.php~ 1970-01-01 02:00:00.000000000 +0200 +++ wifiadmin-0.0.4-modified/include/functions.php~ 2005-02-26 18:36:09.851560320 +0200 @@ -0,0 +1,465 @@ + 1) + $result = "$days " ." days "; + else + $result = "$days " ." day "; + } + if ($hours != 0) { + if ($hours > 1) + $result .= "$hours " ." hours "; + else + $result .= "$hours " ." hour "; + } + if ($min > 1 || $min == 0) + $result .= "$min " ." minutes "; + elseif ($min == 1) + $result .= "$min " ." minute "; + + return $result; +} + +function chostname () { + if ($fp = fopen('/proc/sys/kernel/hostname', 'r')) { + $result = trim(fgets($fp, 4096)); + fclose($fp); + $result = gethostbyaddr(gethostbyname($result)); + } else { + $result = 'N.A.'; + } + return $result; +} + +function parse_assoc($associations) +{ + $list = preg_split("/[\s]+/", $associations); + for($i=0;$i$macs,'rx_bytes'=>$rx_bytes,'tx_bytes'=>$tx_bytes,'rates'=>$rates,'signal'=>$signal,'noise'=>$noise); +} + + +/************************************************ +* freq2channel($freq) +* returns the channel # of a given frequency of 802.11 +************************************************/ +function freq2channel($freq) +{ + $out = array(".","GHz"); + $freq = str_replace($out,"",$freq); + return ($freq - 2412)/5 + 1; +} +/************************************************ +* channel2freq($channel) +* returns the frequency of a given channel of 802.11 +************************************************/ +function channel2freq($channel) +{ + if(is_int($channel)) + return ($channel+1 * 5) + 2.412; + else return -1; +} +/************************************************ +* get_wif() +* returns an array in the following format +* ans[i] = ith interface's name +* ans[i+1] = ith interface's mode +************************************************/ +function get_wifs() +{ + global $iwconfig_bin; + //wifs contains the names of the wifi devices + $wifs = explode("\n",trim(`ls /proc/net/hostap/`)); + //gets the modes of the wifi devs + $i = 0; + foreach($wifs as $var) //finds modes of every wifi + { + $cmd = "$iwconfig_bin ".$var; + $temp = trim(`$cmd`); + $pos = strpos($temp,"Master"); + if(!($pos === false)) + {$ans[$i] = $var; + $ans[$i+1] = "Master";} + else + { + $pos = strpos($temp,"Managed"); + if(!($pos === false)) + {$ans[$i] = $var; + $ans[$i+1] = "Managed";} + else + { + $pos = strpos($temp,"Ad-Hoc"); + if(!($pos === false)) + {$ans[$i] = $var; + $ans[$i+1] = "Ad-Hoc"; + } + else + {$ans[$i] = $var; + $ans[$i+1] = "unknown";} + } + } + $i=$i+2; + } + return $ans; +} +/************************************************************ +* Returns the security policy of the specified device +* Device must be in master mode or else garbage is returned +*************************************************************/ +function get_policy($wif) +{ + $ap_control_file = "/proc/net/hostap/".$wif."/ap_control"; + $data = file($ap_control_file); + sscanf($data[0],"MAC policy: %s", $security['policy']); + if(sizeof($data) > 3) + { + for($i=3;$iAn error has occured in the ban proccess

"; +} +/*an1 IEEE 802.11b ESSID:"PWN_aroi" + Mode:Managed Frequency:2.432GHz Access Point: 00:40:96:38:9:0 + Bit Rate:2Mb/s Tx-Power:128 dBm Sensitivity=1/3 + Retry limit:8 RTS thr:off Fragment thr:off + Encryption key:off + Power Management:off + Link Quality:24/92 Signal level:-68 dBm Noise level:-95 dBm + Rx invalid nwid:0 Rx invalid crypt:42 Rx invalid frag:0 + Tx excessive retries:416352 Invalid misc:70361034 Missed beacon:0 */ +//use for use within parse_iwconfig +function getnext($haystack,$needle) +{ + $pos = strpos($haystack,$needle); + if($pos == true) + { + $pos+= strlen($needle); + $str = substr($haystack, $pos+1); + $str= ltrim($str); + return trim(substr($str,0,strpos($str," "))); + } + else + return ""; +} + + +function getmicrotime() +{ + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); +} + +function error_echo($string) +{ + return "

".$string."

"; +} + +//this works for hostap only +function get_connected_users_num( $device ){ + global $hostap_device_path; + $dh = opendir($hostap_device_path); + while (false !== ($filename = readdir($dh))) { + $device_dirs[] = $filename; + } + if ( array_search( $device, $device_dirs) == false) + return false; + $dh = opendir($hostap_device_path.$device); + while (false !== ($filename = readdir($dh))) { + $files[] = $filename; + } + $users_num = 0; + foreach( $files as $file){ + if (strstr( $file , ':') != false) + $users_num++; + } + return $users_num; +} + +function get_value($input_string, $attribute){ + sscanf(strstr($input_string, $attribute) ,$attribute."%s",$out); + return trim($out); +} + +function get_all_values($input_string, $attribute){ + $values = array(); + $count = 0; + $next_pos = strpos($input_string, $attribute); + while(!($next_pos === false)){ + sscanf(strstr($input_string, $attribute), $attribute."%s",$value); + $values[$count] = trim($value); + $count++; + $input_string = substr($input_string, $next_pos + strlen($attribute)); + $next_pos = strpos($input_string, $attribute); + } + return $values; +} + +//returns the following attributes of a wifi device +//given its "iwconfig wlanX" output +function parse_iwconfig($output) +{ + //IWCONFIG OUTPUT PARSING!! + $data['type'] = getnext($output,"IEEE"); + $data['nick'] = getnext($output,"Nickname"); + $data['essid'] = getnext($output,"ESSID"); + $data['mode'] = getnext($output,"Mode"); + $data['channel'] = freq2channel(str_replace("GHz","",getnext($output,"Frequency"))); + $data['ap'] = getnext($output,"Access Point"); + $data['cell'] = getnext($output,"Cell"); + $data['quality'] = getnext($output,"Link Quality"); + $data['signal'] = getnext($output,"Signal level"); + $data['noise'] = getnext($output,"Noise level"); + $data['rate'] = getnext($output,"Rate"); + $data['sens'] = getnext($output,"Sensitivity"); + $data['retry'] = getnext($output,"limit");//fix "retry min limit" and "retry limit" that exist in different versions of hostap/witools + $data['rts'] = getnext($output,"RTS thr"); + $data['frag'] = getnext($output,"Fragment thr"); + $data['power'] = getnext($output,"Power Management"); + return $data; +} +/*iwconfig output in an array with device names as keys*/ +function get_wireless_status(){ + global $iwconfig_bin; + $iwconfig_output = trim(`$iwconfig_bin`); + $device_status_strings = explode("\n\n", $iwconfig_output); + foreach($device_status_strings as $device_status_string){ + sscanf($device_status_string,"%s ",$device); + if (strstr($device_status_string, "no wireless extensions") !== false) + continue; + $devices_data[$device] = parse_iwconfig($device_status_string); + $devices_data[$device]["name"] = $device; + } + return $devices_data; +} + +/* device, inet addr, Bcast, mask, in an associative array with device name as key*/ +function get_ethernet_status(){ + global $ifconfig_bin; + $ifconfig_cmd = $ifconfig_bin; + $ifconfig_output = rtrim(`$ifconfig_cmd`, " \n"); + $device_status_strings = explode("\n\n", $ifconfig_output); + + foreach($device_status_strings as $device_status_string){ + sscanf($device_status_string,"%s ",$device); + //skip loopback interface + if ($device == "lo") + continue; + //ignore newest hostap fake devices, called wifix + if (strstr($device,"wifi") !==false) + continue; + $device_status["Link encap"] = get_value($device_status_string,"Link encap:"); + $device_status["hwaddr"] = get_value($device_status_string,"HWaddr"); + $device_status["ipaddr"] = get_value($device_status_string,"inet addr:"); + $device_status["bcast"] = get_value($device_status_string,"Bcast:"); + $device_status["mask"] = get_value($device_status_string,"Mask:"); + $device_status["mtu"] = get_value($device_status_string,"MTU:"); + $device_status["Metric"] = get_value($device_status_string,"Metric:"); + $device_status["tx"] = get_value($device_status_string,"TX bytes:"); + $device_status["rx"] = get_value($device_status_string,"RX bytes:"); + $device_statuses[$device] = $device_status; + } + return $device_statuses; +} + +/*each element of routes is an associative array with key the attribute name*/ +function get_routing_table(){ + global $route_bin; + $route_cmd = $route_bin." -n"; + $route_output = rtrim(`$route_cmd`, " \n"); + $route_strings = explode("\n", $route_output); + $index=0; + foreach($route_strings as $route_string_index => $route_string){ + if($route_string_index == 0 || $route_string_index ==1) + continue; + list($routes[$index]["destination"], + $routes[$index]["gateway"], + $routes[$index]["netmask"], + $routes[$index]["flags"], + $routes[$index]["metric"], + $routes[$index]["ref"], + $routes[$index]["use"], + $routes[$index]["iface"]) = sscanf($route_string, "%s %s %s %s %s %s %s %s"); + $index++; + } + return $routes; +} + +/*returns false if device doesn't support scanning, empty array if there are no scan results +*/ +function get_scan_results($device){ + global $iwlist_bin; + $iwlist_cmd = $iwlist_bin." ".$device." scan"; + $iwlist_output = rtrim(`$iwlist_cmd`, " \n"); + if (!(stristr( $iwlist_output, "Operation not supported") === false)) + return false; + //remove first line + $iwlist_output = ltrim (substr($iwlist_output,strcspn($iwlist_output, "\n"))); + //shift the first empty element + $cell_strings = array_slice(explode("Cell", $iwlist_output),1); + + $cell_infos = array(); + foreach( $cell_strings as $cell_index => $cell_string){ + $cell_info["address"] = get_value($cell_string,"Address:"); + $cell_info["essid"] = get_value($cell_string,"ESSID:"); + $cell_info["mode"] = get_value($cell_string,"Mode:"); + $cell_info["frequency"] = get_value($cell_string,"Frequency:"); + $cell_info["channel"] = freq2channel($cell_info["frequency"]); + $cell_info["quality"] = get_value($cell_string,"Quality:"); + $cell_info["signal"] = get_value($cell_string,"Signal level:"); + $cell_info["noise"] = get_value($cell_string,"Noise level:"); + $cell_info["encryption"] = get_value($cell_string,"Encryption key:"); + $rates = get_all_values($cell_string,"Bit Rate:"); + $cell_info["rates"] = array_shift($rates); + foreach ($rates as $rate) + $cell_info["rates"] = $cell_info["rates"].", ".$rate; + + $extras = get_all_values($cell_string,"Extra:"); + $cell_info["extras"] = array_shift($extras); + foreach ($extras as $extra) + $cell_info["extras"] = $cell_info["extras"].", ".$extra; + $cell_infos[$cell_index] = $cell_info; + } + return($cell_infos); +} + +?>