From a87d7ee86993087f6ee28ed3ab8fe0038932008b Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Fri, 12 Aug 2016 21:22:21 +0000 Subject: [PATCH] Allow open networks --- dist/js/functions.js | 36 ++++++----- includes/configure_client.php | 109 ++++++++++++++++++++++++++-------- 2 files changed, 105 insertions(+), 40 deletions(-) diff --git a/dist/js/functions.js b/dist/js/functions.js index 5adf581a..3588a3b5 100644 --- a/dist/js/functions.js +++ b/dist/js/functions.js @@ -25,24 +25,32 @@ function AddNetwork() { } -function AddScanned(network) { +function AddScanned(network, open = false) { - existing = document.getElementById("networkbox").getElementsByTagName('div').length; + existing = document.getElementById("networkbox").getElementsByTagName('div').length; var Networks = document.getElementById('Networks').value; - //if(existing != 0) { - Networks++; - //} + //if(existing != 0) { + Networks++; + //} document.getElementById('Networks').value=Networks; - document.getElementById('networkbox').innerHTML += '

Network '+Networks+'

\ -
\ -
\ -
'; - document.getElementById('ssid'+Networks).value = network; - if(existing == 0) { - Networks++ - document.getElementById('Networks').value = Networks; - } + document.getElementById('networkbox').innerHTML += '

Network '+Networks+'

'; + document.getElementById('networkbox').innerHTML += '
'; + + if ( open ) { + document.getElementById('networkbox').innerHTML += ''; + document.getElementById('Save').disabled = false; + } else { + document.getElementById('networkbox').innerHTML += ''; + document.getElementById('networkbox').innerHTML += '
'; + } + + document.getElementById('networkbox').innerHTML += '
'; + document.getElementById('ssid'+Networks).value = network; + if(existing == 0) { + Networks++ + document.getElementById('Networks').value = Networks; + } } function CheckSSID(ssid) { diff --git a/includes/configure_client.php b/includes/configure_client.php index 2b1d1188..7e8d3478 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -17,16 +17,24 @@ update_config=1 for( $x = 0; $x < $networks; $x++ ) { $network = ''; $ssid = escapeshellarg( $_POST['ssid'.$x] ); - $protocol = escapeshellarg( $_POST['protocol'.$x] ); - $psk = escapeshellarg( $_POST['psk'.$x] ); + $protocol = $_POST['protocol'.$x]; + if ($protocol === 'Open') { + $config .= "network={".PHP_EOL; + $config .= "\tssid=\"".$ssid."\"".PHP_EOL; + $config .= "\tkey_mgmt=NONE".PHP_EOL; + $config .= "}".PHP_EOL; + } else { + $psk = escapeshellarg( $_POST['psk'.$x] ); - if ( strlen($psk) >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 "; + } } } + error_log($config); } exec( "echo '$config' > /tmp/wifidata", $return ); system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval ); @@ -57,25 +65,66 @@ update_config=1 echo ''; } - // default action, output configured network(s) - exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $supplicant_return); - $ssid = array(); - $psk = array(); +// // 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); - 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]); + + + + // 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; + } + } } } - - $numSSIDs = count($ssid); - ?> - +?>
@@ -132,7 +181,7 @@ update_config=1
- +
@@ -142,15 +191,23 @@ update_config=1
- +
- - + +
+ +
+
+ + +
+
+