From f8a71403a3da8e565ff36209fbfc46a9829395a4 Mon Sep 17 00:00:00 2001 From: Russ Marshall Date: Thu, 22 Feb 2018 20:07:52 -0500 Subject: [PATCH] preserve priority in wpa_supplicant.conf --- includes/configure_client.php | 43 +++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index 31a77e5e..206e6dc2 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -41,6 +41,9 @@ function DisplayWPAConfig(){ $network['protocol'] = 'Open'; } break; + case 'priority': + $network['priority'] = trim($lineArr[1], '"'); + break; } } } @@ -63,6 +66,9 @@ function DisplayWPAConfig(){ 'passphrase' => $_POST['passphrase' . $post_match[1]], 'configured' => true ); + if (array_key_exists('priority' . $post_match[1], $_POST)) { + $tmp_networks[$_POST['ssid' . $post_match[1]]]['priority'] = $_POST['priority' . $post_match[1]]; + } } } @@ -72,22 +78,30 @@ function DisplayWPAConfig(){ fwrite($wpa_file, "network={".PHP_EOL); fwrite($wpa_file, "\tssid=\"".$ssid."\"".PHP_EOL); fwrite($wpa_file, "\tkey_mgmt=NONE".PHP_EOL); + if (array_key_exists('priority', $network)) { + fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL); + } fwrite($wpa_file, "}".PHP_EOL); } else { if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) { - unset($wpa_passphrase); + unset($wpa_passphrase); unset($line); - exec( 'wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']),$wpa_passphrase ); + exec( 'wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']),$wpa_passphrase ); foreach($wpa_passphrase as $line) { - fwrite($wpa_file, $line.PHP_EOL); + if (preg_match('/^\s*}\s*$/', $line)) { + if (array_key_exists('priority', $network)) { + fwrite($wpa_file, "\tpriority=".$network['priority'].PHP_EOL); + } + fwrite($wpa_file, $line.PHP_EOL); + } else { + fwrite($wpa_file, $line.PHP_EOL); + } } } else { $status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger'); $ok = false; - } } - } if ($ok) { @@ -118,7 +132,7 @@ function DisplayWPAConfig(){ // display output foreach( $scan_return as $network ) { $arrNetwork = preg_split("/[\t]+/",$network); - if (array_key_exists($arrNetwork[4], $networks)) { + if (array_key_exists(4, $arrNetwork) && array_key_exists($arrNetwork[4], $networks)) { $networks[$arrNetwork[4]]['visible'] = true; $networks[$arrNetwork[4]]['channel'] = ConvertToChannel($arrNetwork[1]); // TODO What if the security has changed? @@ -150,9 +164,9 @@ function DisplayWPAConfig(){

showMessages(); ?>

Client settings for interface

-
- Rescan -
+
+ Rescan +
@@ -172,7 +186,7 @@ function DisplayWPAConfig(){ - + @@ -180,12 +194,17 @@ function DisplayWPAConfig(){ - + X - + + + + + + ---