2 ) { exec( 'wpa_passphrase '.$ssid. ' ' . $psk,$network ); foreach($network as $b) { $config .= "$b "; } } } error_log($config); } exec( "echo '$config' > /tmp/wifidata", $return ); system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval ); if( $returnval == 0 ) { $status->addMessage('Wifi settings updated successfully', 'success'); } else { $status->addMessage('Wifi settings failed to be updated', 'danger'); } } 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 foreach( $return as $network ) { $arrNetwork = preg_split("/[\t]+/",$network); $scanned_networks[] = array( 'bssid' => $arrNetwork[0], 'channel' => ConvertToChannel($arrNetwork[1]), 'signal' => $arrNetwork[2] . " dBm", 'security' => ConvertToSecurity($arrNetwork[3]), 'ssid' => $arrNetwork[4] ); } echo ''; } // // default action, output configured network(s) // exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $supplicant_return); // $ssid = array(); // $psk = array(); // // foreach($supplicant_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); // Find currently configured networks$ exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $known_return); $known_networks = array(); $network_id = null; foreach($known_return as $line) { error_log($line); if (preg_match('/network\s*=/', $line)) { $known_networks[] = array(); $network_id = count($known_networks) - 1; } elseif ($network_id !== null) { if (preg_match('/^\s*}\s*$/', $line)) { $network_id = null; } elseif ($lineArr = preg_split('/\s*=\s*/', trim($line))) { switch(strtolower($lineArr[0])) { case 'ssid': $known_networks[$network_id]['ssid'] = trim($lineArr[1], '"'); break; case 'psk': if (array_key_exists('passphrase', $known_networks[$network_id])) { break; } case '#psk': $known_networks[$network_id]['protocol'] = 'WPA'; case 'wep_key0': // Untested $known_networks[$network_id]['passphrase'] = trim($lineArr[1], '"'); break; case 'key_mgmt': if (! array_key_exists('passphrase', $known_networks[$network_id]) &&$lineArr[1] === 'NONE') { $known_networks[$network_id]['protocol'] = 'Open'; $known_networks[$network_id]['passphrase'] = '(Open)'; } break; } } } } ?>
showMessages(); ?>