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 @@
+
+/*+-------------------------------------------------------------------------+
+ | Copyright (C) 2004 Panousis Thanos - Dimopoulos Thimios |
+ | |
+ | This program is free software; you can redistribute it and/or |
+ | modify it under the terms of the GNU General Public License |
+ | as published by the Free Software Foundation; either version 2 |
+ | of the License, or (at your option) any later version. |
+ | |
+ | This program is distributed in the hope that it will be useful, |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ | GNU General Public License for more details. |
+ +-------------------------------------------------------------------------+
+ | WifiAdmin: The Free WiFi Web Interface |
+ +-------------------------------------------------------------------------+
+ | Send comments to |
+ | - panousis@ceid.upatras.gr |
+ | - dimopule@ceid.upatras.gr |
+ +-------------------------------------------------------------------------+*/
+
+include_once("config.php");
+/************************************************
+* Functions file *
+*************************************************
+
+/************************************************
+* Bytes to MB, GB, TB function *
+*************************************************/
+function ByteSize($bytes) {
+ $size = $bytes / 1024;
+ if($size < 1024){
+ $size = number_format($size, 2);
+ $size .= 'KB';
+ } else {
+ if($size / 1024 < 1024) {
+ $size = number_format($size / 1024, 2);
+ $size .= 'MB';
+ } elseif($size / 1024 / 1024 < 1024) {
+ $size = number_format($size / 1024 / 1024, 2);
+ $size .= 'GB';
+ } else {
+ $size = number_format($size / 1024 / 1024 / 1024, 2);
+ $size .= 'TB';
+ }
+ }
+ return $size;
+}
+function kernel () {
+ if ($fd = fopen('/proc/version', 'r')) {
+ $buf = fgets($fd, 4096);
+ fclose($fd);
+ if (preg_match('/version (.*?) /', $buf, $ar_buf)) {
+ $result = $ar_buf[1];
+ if (preg_match('/SMP/', $buf)) {
+ $result .= ' (SMP)';
+ }
+ } else {
+ $result = 'N.A.';
+ }
+ } else {
+ $result = 'N.A.';
+ }
+ return $result;
+}
+
+
+function uptime () {
+ $fd = fopen('/proc/uptime', 'r');
+ $ar_buf = split(' ', fgets($fd, 4096));
+ fclose($fd);
+ $sys_ticks = trim($ar_buf[0]);
+ $min = $sys_ticks / 60;
+ $hours = $min / 60;
+ $days = floor($hours / 24);
+ $hours = floor($hours - ($days * 24));
+ $min = floor($min - ($days * 60 * 24) - ($hours * 60));
+ $result = "";
+ if ($days != 0) {
+ if ($days > 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
".$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); +} + +?>