'."\n"; switch($page) { case "wlan0_info": //Declare a pile of variables $strIPAddress = NULL; $strNetMask = NULL; $strRxPackets = NULL; $strRxBytes = NULL; $strTxPackets = NULL; $strTxBytes = NULL; $strSSID = NULL; $strBSSID = NULL; $strBitrate = NULL; $strTxPower = NULL; $strLinkQuality = NULL; $strSignalLevel = NULL; $strWifiFreq = NULL; $strWifiChan = NULL; exec('ifconfig wlan0',$return); exec('iwconfig wlan0',$return); exec('iw dev wlan0 link',$return); $strWlan0 = implode(" ",$return); $strWlan0 = preg_replace('/\s\s+/', ' ', $strWlan0); if (strpos($strWlan0,'HWaddr') !== false) { preg_match('/HWaddr ([0-9a-f:]+)/i',$strWlan0,$result); $strHWAddress = $result[1]; } if (strpos($strWlan0,'ether') !== false) { preg_match('/ether ([0-9a-f:]+)/i',$strWlan0,$result); $strHWAddress = $result[1]; } if(strpos($strWlan0, "UP") !== false && strpos($strWlan0, "RUNNING") !== false) { $strStatus = '已启用'; //Cant get these unless we are connected :) if (strpos($strWlan0,'inet addr:') !== false) { preg_match('/inet addr:([0-9.]+)/i',$strWlan0,$result); $strIPAddress = $result[1]; } else { preg_match('/inet ([0-9.]+)/i',$strWlan0,$result); $strIPAddress = $result[1]; } if (strpos($strWlan0,'Mask:') !== false) { preg_match('/Mask:([0-9.]+)/i',$strWlan0,$result); $strNetMask = $result[1]; } else { preg_match('/netmask ([0-9.]+)/i',$strWlan0,$result); $strNetMask = $result[1]; } preg_match('/RX packets.(\d+)/',$strWlan0,$result); $strRxPackets = $result[1]; preg_match('/TX packets.(\d+)/',$strWlan0,$result); $strTxPackets = $result[1]; if (strpos($strWlan0,'RX bytes') !== false) { preg_match('/RX [B|b]ytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result); $strRxBytes = $result[1]; } else { preg_match('/RX packets \d+ bytes (\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result); $strRxBytes = $result[1]; } if (strpos($strWlan0,'TX bytes') !== false) { preg_match('/TX [B|b]ytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result); $strTxBytes = $result[1]; } else { preg_match('/TX packets \d+ bytes (\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result); $strTxBytes = $result[1]; } //preg_match('/TX Bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result); //$strTxBytes = $result[1]; if (preg_match('/Access Point: ([0-9a-f:]+)/i',$strWlan0,$result)) { $strBSSID = $result[1]; } if (preg_match('/Connected to\ ([0-9a-f:]+)/i',$strWlan0,$result)) { $strBSSID = $result[1]; } if (preg_match('/Bit Rate([=:0-9\.]+ Mb\/s)/i',$strWlan0,$result)) { $strBitrate = str_replace(':', '', str_replace('=', '', $result[1])); } if (preg_match('/tx bitrate:\ ([0-9\.]+ Mbit\/s)/i',$strWlan0,$result)) { $strBitrate = str_replace(':', '', str_replace('=', '', $result[1])); } if (preg_match('/Tx-Power=([0-9]+ dBm)/i',$strWlan0,$result)) { $strTxPower = $result[1]; } if (preg_match('/ESSID:\"([a-zA-Z0-9-_.\s]+)\"/i',$strWlan0,$result)) { $strSSID = str_replace('"','',$result[1]); } if (preg_match('/SSID:\ ([a-zA-Z0-9-_.\s]+)/i',$strWlan0,$result)) { $strSSID = str_replace(' freq','',$result[1]); } if (preg_match('/Link Quality=([0-9]+\/[0-9]+)/i',$strWlan0,$result)) { $strLinkQuality = $result[1]; if (strpos($strLinkQuality, "/")) { $arrLinkQuality = explode("/", $strLinkQuality); $strLinkQuality = number_format(($arrLinkQuality[0] / $arrLinkQuality[1]) * 100)." %"; } } if (preg_match('/Signal Level=(-[0-9]+ dBm)/i',$strWlan0,$result)) { $strSignalLevel = $result[1]; } if (preg_match('/Signal Level=([0-9]+\/[0-9]+)/i',$strWlan0,$result)) { $strSignalLevel = $result[1]; } if (preg_match('/signal:\ (-[0-9]+ dBm)/i',$strWlan0,$result)) { $strSignalLevel = $result[1]; } if (preg_match('/Frequency:([0-9.]+ GHz)/i',$strWlan0,$result)) { $strWifiFreq = $result[1]; $strWifiChan = str_replace(" GHz", "", $strWifiFreq); $strWifiChan = str_replace(".", "", $strWifiChan); $strWifiChan = ConvertToChannel(str_replace(".", "", $strWifiChan)); } } else { $strStatus = '未启用'; } if(isset($_POST['ifdown_wlan0'])) { exec('ifconfig wlan0 | grep -i running | wc -l',$test); if($test[0] == 1) { exec('sudo ifdown wlan0',$return); } else { echo '接口已经是关闭状态'; } } elseif(isset($_POST['ifup_wlan0'])) { exec('ifconfig wlan0 | grep -i running | wc -l',$test); if($test[0] == 0) { exec('sudo ifup wlan0',$return); } else { echo '接口已经是开启状态'; } } elseif(isset($_POST['reset_wlan0'])) { exec('sudo wpa_cli reconfigure wlan0 && sudo ifdown wlan0 && sleep 3 && sudo ifup wlan0 && sudo wpa_cli scan',$test); echo ''; } echo '
无线信息与统计
接口信息
      接口名称 : wlan0
    接口状态 : ' . $strStatus . '
          IP 地址 : ' . $strIPAddress . '
         子网掩码 : ' . $strNetMask . '
         MAC 地址 : ' . $strHWAddress . '

接口统计
    接收数据包 : ' . $strRxPackets . '
      接收字节数 : ' . $strRxBytes . '
 发送数据包 : ' . $strTxPackets . '
   发送字节数 : ' . $strTxBytes . '

无线信息
   已连接到 : ' . $strSSID . '
 接入点 MAC 地址 : ' . $strBSSID . '

        传输速率 : ' . $strBitrate . '
   信号强度 : ' . $strSignalLevel . '

'; if ($strTxPower) { echo ' 发射功率 : ' . $strTxPower .'
'."\n"; } else { echo "
\n"; } if ($strLinkQuality) { echo '   链路质量 : ' . $strLinkQuality . '
'."\n"; } else { echo "
\n"; } if (($strWifiFreq) && ($strWifiChan) && ($strWifiChan != "Invalid Channel")) { echo '   信道信息 : ' . $strWifiChan . ' (' . $strWifiFreq . ')
'."\n"; } else { echo "
\n"; } if (file_exists('/etc/wpa_supplicant/wpa_supplicant.conf')) { exec('sudo grep "country" /etc/wpa_supplicant/wpa_supplicant.conf', $wifiCountryArr); } if (isset($wifiCountryArr[0])) { $wifiCountry = explode("=", $wifiCountryArr[0]); if (isset($wifiCountry[1])) { echo '   WiFi 国家代码 : '.$wifiCountry[1]."
\n"; } } echo '


信息来源:ifconfig 和 iwconfig
'; break; case "wpa_conf": exec('sudo cat /etc/wpa_supplicant/wpa_supplicant.conf',$return); $ssid = array(); $psk = array(); foreach($return as $a) { if(preg_match('/country=/i',$a)) { $wifiCountryArr = explode("=",$a); $wifiCountry = $wifiCountryArr[1]; } // Make sure we only put ONE SSID and matching PSK into the arrays if ( ( isset($curssidplain) || isset($curssidalt) ) && ( isset($curpskplain) || isset($curpskalt) ) ) { if (isset($curssidplain)) { $ssid[] = $curssidplain; unset($curssidplain); unset($curssidalt); } if (isset($curssidalt)) { $ssid[] = $curssidalt; unset($curssidplain); unset($curssidalt); } if (isset($curpskplain)) { $psk[] = $curpskplain; unset($curpskplain); unset($curpskalt); } if (isset($curpskalt)) { $psk[] = $curpskalt; unset($curpskplain); unset($curpskalt); } } // Handle the case of the old file format, and the new... if(preg_match('/\#SSID=/i',$a) && !preg_match('/scan_ssid/i',$a)) { $arrssid = explode("=",$a); //$ssid[] = str_replace('"','',$arrssid[1]); $curssidplain = str_replace('"','',$arrssid[1]); } elseif(preg_match('/SSID="/i',$a) && !preg_match('/scan_ssid/i',$a)) { $arrssid = explode("=",$a); //$ssid[] = str_replace('"','',$arrssid[1]); if (!isset($curssidplain)) { $curssidalt = str_replace('"','',$arrssid[1]); } } if (isset($curssidplain) || isset($curssidalt)) { if(preg_match('/\#psk="/i',$a)) { $arrpsk = explode("=",$a); //$psk[] = str_replace('"','',$arrpsk[1]); $curpskplain = str_replace('"','',$arrpsk[1]); } elseif(preg_match('/psk=/i',$a)) { $arrpsk = explode("=",$a); //$psk[] = str_replace('"','',$arrpsk[1]); if (!isset($curpskplain)) { $curpskalt = str_replace('"','',$arrpsk[1]); } } } } $numSSIDs = count($ssid); $output = '

'."\n"; if (!isset($wifiCountry)) { $wifiCountry = "JP"; } $output .= 'WiFi 法规域(国家代码):
'."\n"; for($ssids = 0; $ssids < $numSSIDs; $ssids++) { $output .= '
网络 '.$ssids."\n"; $output .= '
'."\n"; $output .= 'SSID :
'."\n"; $output .= 'PSK :

'."\n"; } $output .= '
'."\n"; $output .= '
'."\n"; $output .= ''."\n"; $output .= ''."\n"; $output .= ''."\n"; $output .= '
'."\n"; $output .= '
'."\n"; echo $output; echo ''; if(isset($_POST['SaveWPAPSKSettings'])) { $config = "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\nap_scan=1\nfast_reauth=1\ncountry=".$_POST['wifiCountryCode']."\n\n"; $networks = $_POST['Networks']; //Reworked WiFi Starts Here for($x = 0; $x < $networks; $x++) { //$network = ''; $ssid = $_POST['ssid'.$x]; $psk = $_POST['psk'.$x]; $priority = 100 - $x; if ($ssid == "*" && !$psk) { $config .= "network={\n\t#ssid=\"$ssid\"\n\t#psk=\"\"\n\tkey_mgmt=NONE\n\tid_str=\"$x\"\n\tpriority=$priority\n\tscan_ssid=1\n}\n\n"; } elseif ($ssid && !$psk) { $config .= "network={\n\tssid=\"$ssid\"\n\t#psk=\"\"\n\tkey_mgmt=NONE\n\tid_str=\"$x\"\n\tpriority=$priority\n\tscan_ssid=1\n}\n\n"; } elseif ($ssid && $psk) { $pskSalted = hash_pbkdf2("sha1",$psk, $ssid, 4096, 64); $ssidHex = bin2hex("$ssid"); $config .= "network={\n\t#ssid=\"$ssid\"\n\tssid=$ssidHex\n\t#psk=\"$psk\"\n\tpsk=$pskSalted\n\tid_str=\"$x\"\n\tpriority=$priority\n\tscan_ssid=1\n}\n\n"; } } file_put_contents('/tmp/wifidata', $config); system('sudo mount -o remount,rw / && sudo cp -f /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf && sudo sync && sudo sync && sudo sync && sudo mount -o remount,ro /'); echo "WiFi 设置已成功更新\n"; // If Auto AP is on, dont restart the WiFi Card if (!file_exists('/sys/class/net/wlan0_ap')) { exec('sudo ip link set wlan0 down && sleep 3 && sudo ip link set wlan0 up'); } echo ""; } elseif(isset($_POST['Scan'])) { $return = ''; exec('ifconfig wlan0 | grep -i running | wc -l',$test); exec('sudo wpa_cli scan -i wlan0',$return); sleep(8); exec('sudo wpa_cli scan_results -i wlan0',$return); unset($return['0']); // This is a better way to clean up; unset($return['1']); // This is a better way to clean up; echo "
\n"; echo "
\n"; echo "发现的网络 :
\n"; echo "\n"; echo ""; foreach($return as $network) { $arrNetwork = preg_split("/[\t]+/",$network); $bssid = $arrNetwork[0]; $channel = ConvertToChannel($arrNetwork[1]); $signal = $arrNetwork[2] . " dBm"; $security = ConvertToSecurity($arrNetwork[3]); $ssid = $arrNetwork[4]; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''."\n"; } echo "
连接SSID信道信号加密方式
'.$ssid.''.$channel.''.$signal.''.$security.'
\n"; echo "
\n"; } break; } echo '
.
'; ?>