diff --git a/includes/configure_client.php b/includes/configure_client.php index 4044dd74..a5e2aa15 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -5,121 +5,121 @@ * */ function DisplayWPAConfig(){ - $status = ''; - ?> -
-
-
-
Configure client -
- -
- -

Client settings

-
-
+ $status = ''; + ?> +
+
+
+
Configure client +
+ +
+ +

Client settings

+
+
- 2 ) { - exec( 'wpa_passphrase '.$ssid. ' ' . $psk,$network ); - foreach($network as $b) { - $config .= "$b + if ( strlen($psk) >2 ) { + exec( 'wpa_passphrase '.$ssid. ' ' . $psk,$network ); + foreach($network as $b) { + $config .= "$b "; - } - } - } - exec( "echo '$config' > /tmp/wifidata", $return ); - system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval ); - if( $returnval == 0 ) { - echo '
Wifi settings updated successfully -
'; - } else { - echo '
Wifi settings failed to be updated -
'; - } + } + } + } + exec( "echo '$config' > /tmp/wifidata", $return ); + system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval ); + if( $returnval == 0 ) { + echo '
Wifi settings updated successfully +
'; + } else { + echo '
Wifi settings failed to be updated +
'; + } - // scan networks - } elseif( isset($_POST['Scan']) ) { - $return = ''; - exec( 'sudo wpa_cli scan',$return ); - sleep(3); - exec( 'sudo wpa_cli scan_results',$return ); - for( $shift = 0; $shift < 4; $shift++ ) { - array_shift($return); - } - // display output - echo '
'; - echo '
'; - echo '

Networks found

'; - echo ''; - foreach( $return as $network ) { - $arrNetwork = preg_split("/[\t]+/",$network); - $bssid = $arrNetwork[0]; - $channel = ConvertToChannel($arrNetwork[1]); - $signal = $arrNetwork[2] . " dBm"; - $security = $arrNetwork[3]; - $ssid = $arrNetwork[4]; - echo '"; - } - echo '
SSIDChannelSignalSecurity
' . $ssid . " " . $channel . "" . $signal . "". ConvertToSecurity($security) ."
'; + // scan networks + } elseif( isset($_POST['Scan']) ) { + $return = ''; + exec( 'sudo wpa_cli scan',$return ); + sleep(3); + exec( 'sudo wpa_cli scan_results',$return ); + for( $shift = 0; $shift < 4; $shift++ ) { + array_shift($return); + } + // display output + echo '
'; + echo '
'; + echo '

Networks found

'; + echo ''; + foreach( $return as $network ) { + $arrNetwork = preg_split("/[\t]+/",$network); + $bssid = $arrNetwork[0]; + $channel = ConvertToChannel($arrNetwork[1]); + $signal = $arrNetwork[2] . " dBm"; + $security = $arrNetwork[3]; + $ssid = $arrNetwork[4]; + echo '"; + } + echo '
SSIDChannelSignalSecurity
' . $ssid . " " . $channel . "" . $signal . "". ConvertToSecurity($security) ."
'; - } else { + } else { - // default action, output configured network(s) - exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $return); - $ssid = array(); - $psk = array(); + // default action, output configured network(s) + exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $return); + $ssid = array(); + $psk = array(); - foreach($return as $a) { - if(preg_match('/SSID/i',$a)) { - $arrssid = explode("=",$a); - $ssid[] = str_replace('"','',$arrssid[1]); - } - if(preg_match('/psk/i',$a)) { - $arrpsk = explode("=",$a); - $psk[] = str_replace('"','',$arrpsk[1]); - } - } + foreach($return as $a) { + if(preg_match('/SSID/i',$a)) { + $arrssid = explode("=",$a); + $ssid[] = str_replace('"','',$arrssid[1]); + } + if(preg_match('/psk/i',$a)) { + $arrpsk = explode("=",$a); + $psk[] = str_replace('"','',$arrpsk[1]); + } + } - $numSSIDs = count($ssid); - $output = '
'; - - if ( $numSSIDs > 0 ) { - for( $ssids = 0; $ssids < $numSSIDs; $ssids++ ) { - $output .= '
-
-
-
-
'; - } - $output .= '
'; - } else { - $status = '
Not connected -
'; - } - $output .= '
'; - $output .= ''; - echo $output; - } - ?> - - -
-
-
-
+ $numSSIDs = count($ssid); + $output = '
'; + + if ( $numSSIDs > 0 ) { + for( $ssids = 0; $ssids < $numSSIDs; $ssids++ ) { + $output .= '
+
+
+
+
'; + } + $output .= '
'; + } else { + $status = '
Not connected +
'; + } + $output .= '
'; + $output .= ''; + echo $output; + } + ?> + + +
+
+
+
0 && $channel < 14) { + return $channel; + } else { + return 'Invalid Channel'; + } } /** @@ -105,36 +99,28 @@ function ConvertToChannel( $freq ) { * @return string */ function ConvertToSecurity( $security ) { - - switch( $security ) { - case "[WPA2-PSK-CCMP][ESS]": - return "WPA2-PSK (AES)"; - break; - case "[WPA2-PSK-TKIP][ESS]": - return "WPA2-PSK (TKIP)"; - break; - case "[WPA2-PSK-CCMP][WPS][ESS]": - return "WPA/WPA2-PSK (TKIP/AES)"; - break; - case "[WPA2-PSK-TKIP+CCMP][WPS][ESS]": - return "WPA2-PSK (TKIP/AES) with WPS"; - break; - case "[WPA-PSK-TKIP+CCMP][WPS][ESS]": - return "WPA-PSK (TKIP/AES) with WPS"; - break; - case "[WPA-PSK-TKIP][WPA2-PSK-CCMP][WPS][ESS]": - return "WPA/WPA2-PSK (TKIP/AES)"; - break; - case "[WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][ESS]": - return "WPA/WPA2-PSK (TKIP/AES)"; - break; - case "[WPA-PSK-TKIP][ESS]": - return "WPA-PSK (TKIP)"; - break; - case "[WEP][ESS]": - return "WEP"; - break; - } + $options = array(); + preg_match_all('/\[([^\]]+)\]/s', $security, $matches); + foreach($matches[1] as $match) { + if (preg_match('/^(WPA\d?)/', $match, $protocol_match)) { + $protocol = $protocol_match[1]; + $matchArr = explode('-', $match); + if (count($matchArr) > 2) { + $options[] = $protocol . ' ('. $matchArr[2] .')'; + } else { + $options[] = $protocol; + } + } + } + + if (count($options) === 0) { + // This could also be WEP but wpa_supplicant doesn't have a way to determine + // this. + // And you shouldn't be using WEP these days anyway. + return 'Open'; + } else { + return implode('
', $options); + } } /**