From 7406a5050c2a7fc9f74d39cdb4761fbc6d08354f Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Mon, 8 Aug 2016 12:31:19 +0000 Subject: [PATCH 1/9] Move system page into separate file --- includes/functions.php | 97 ----------------------------------------- includes/system.php | 98 ++++++++++++++++++++++++++++++++++++++++++ index.php | 1 + 3 files changed, 99 insertions(+), 97 deletions(-) create mode 100755 includes/system.php diff --git a/includes/functions.php b/includes/functions.php index eb76ffca..9d12869d 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -673,103 +673,6 @@ function DisplayTorProxyConfig(){ 1)? 's ':' '); } - if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); } - if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); } - - // mem used - exec("free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { print used/total*100}'", $memarray); - $memused = floor($memarray[0]); - if ($memused > 90) { $memused_status = "danger"; } - elseif ($memused > 75) { $memused_status = "warning"; } - elseif ($memused > 0) { $memused_status = "success"; } - - // cpu load - $cores = exec("grep -c ^processor /proc/cpuinfo"); - $loadavg = exec("awk '{print $1}' /proc/loadavg"); - $cpuload = floor(($loadavg * 100) / $cores); - if ($cpuload > 90) { $cpuload_status = "danger"; } - elseif ($cpuload > 75) { $cpuload_status = "warning"; } - elseif ($cpuload > 0) { $cpuload_status = "success"; } - - ?> -
-
-
-
System
-
- - System Rebooting Now!
'; - $result = shell_exec("sudo /sbin/reboot"); - } - if (isset($_POST['system_shutdown'])) { - echo '
System Shutting Down Now!
'; - $result = shell_exec("sudo /sbin/shutdown -h now"); - } - ?> - -
-
-
-
-

System Information

-
Hostname

-
Uptime


-
Memory Used
-
-
% -
-
-
CPU Load
-
-
% -
-
-
-
-
-
- -
- - - -
- -
-
-
- - 1)? 's ':' '); } + if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); } + if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); } + + // mem used + exec("free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { print used/total*100}'", $memarray); + $memused = floor($memarray[0]); + if ($memused > 90) { $memused_status = "danger"; } + elseif ($memused > 75) { $memused_status = "warning"; } + elseif ($memused > 0) { $memused_status = "success"; } + + // cpu load + $cores = exec("grep -c ^processor /proc/cpuinfo"); + $loadavg = exec("awk '{print $1}' /proc/loadavg"); + $cpuload = floor(($loadavg * 100) / $cores); + if ($cpuload > 90) { $cpuload_status = "danger"; } + elseif ($cpuload > 75) { $cpuload_status = "warning"; } + elseif ($cpuload > 0) { $cpuload_status = "success"; } + + ?> +
+
+
+
System
+
+ + System Rebooting Now!
'; + $result = shell_exec("sudo /sbin/reboot"); + } + if (isset($_POST['system_shutdown'])) { + echo '
System Shutting Down Now!
'; + $result = shell_exec("sudo /sbin/shutdown -h now"); + } + ?> + +
+
+
+
+

System Information

+
Hostname

+
Uptime


+
Memory Used
+
+
% +
+
+
CPU Load
+
+
% +
+
+
+
+
+
+ +
+ + + +
+ +
+
+
+ + diff --git a/index.php b/index.php index 2b066bef..f1fa7e6d 100755 --- a/index.php +++ b/index.php @@ -43,6 +43,7 @@ include_once( 'includes/authenticate.php' ); include_once( 'includes/admin.php' ); include_once( 'includes/dhcp.php' ); include_once( 'includes/hostapd.php' ); +include_once( 'includes/system.php' ); $output = $return = 0; $page = $_GET['page']; From bdfcf270a78da41b2ef0f5fd006b83cda81918c3 Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Mon, 8 Aug 2016 12:38:15 +0000 Subject: [PATCH 2/9] Show Raspberry Pi revision information --- includes/system.php | 201 ++++++++++++++++++++++++++------------------ 1 file changed, 121 insertions(+), 80 deletions(-) diff --git a/includes/system.php b/includes/system.php index a94d7c8a..005110be 100755 --- a/includes/system.php +++ b/includes/system.php @@ -1,98 +1,139 @@ 'Model B Revision 1.0', + '0003' => 'Model B Revision 1.0 + ECN0001', + '0004' => 'Model B Revision 2.0 (256 MB)', + '0005' => 'Model B Revision 2.0 (256 MB)', + '0006' => 'Model B Revision 2.0 (256 MB)', + '0007' => 'Model A', + '0008' => 'Model A', + '0009' => 'Model A', + '000d' => 'Model B Revision 2.0 (512 MB)', + '000e' => 'Model B Revision 2.0 (512 MB)', + '000f' => 'Model B Revision 2.0 (512 MB)', + '0010' => 'Model B+', + '0013' => 'Model B+', + '0011' => 'Compute Module', + '0012' => 'Model A+', + 'a01041' => 'a01041', + 'a21041' => 'a21041', + '900092' => 'PiZero', + 'a02082' => 'Pi 3 Model B', + 'a22082' => 'Pi 3 Model B' + ); + exec('cat /proc/cpuinfo', $cpuinfo_array); + $rev = trim(array_pop(explode(':',array_pop(preg_grep("/^Revision/", $cpuinfo_array))))); + if (array_key_exists($rev, $revisions)) { + return $revisions[$rev]; + } else { + return 'Unknown Pi'; + } +} + /** * * */ function DisplaySystem(){ - // hostname - exec("hostname -f", $hostarray); - $hostname = $hostarray[0]; + // hostname + exec("hostname -f", $hostarray); + $hostname = $hostarray[0]; - // uptime - $uparray = explode(" ", exec("cat /proc/uptime")); - $seconds = round($uparray[0], 0); - $minutes = $seconds / 60; - $hours = $minutes / 60; - $days = floor($hours / 24); - $hours = floor($hours - ($days * 24)); - $minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60)); - $uptime= ''; - if ($days != 0) { $uptime .= $days . ' day' . (($days > 1)? 's ':' '); } - if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); } - if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); } + // uptime + $uparray = explode(" ", exec("cat /proc/uptime")); + $seconds = round($uparray[0], 0); + $minutes = $seconds / 60; + $hours = $minutes / 60; + $days = floor($hours / 24); + $hours = floor($hours - ($days * 24)); + $minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60)); + $uptime= ''; + if ($days != 0) { $uptime .= $days . ' day' . (($days > 1)? 's ':' '); } + if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); } + if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); } - // mem used - exec("free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { print used/total*100}'", $memarray); - $memused = floor($memarray[0]); - if ($memused > 90) { $memused_status = "danger"; } - elseif ($memused > 75) { $memused_status = "warning"; } - elseif ($memused > 0) { $memused_status = "success"; } + // mem used + exec("free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { print used/total*100}'", $memarray); + $memused = floor($memarray[0]); + if ($memused > 90) { $memused_status = "danger"; } + elseif ($memused > 75) { $memused_status = "warning"; } + elseif ($memused > 0) { $memused_status = "success"; } - // cpu load - $cores = exec("grep -c ^processor /proc/cpuinfo"); + // cpu load + $cores = exec("grep -c ^processor /proc/cpuinfo"); $loadavg = exec("awk '{print $1}' /proc/loadavg"); - $cpuload = floor(($loadavg * 100) / $cores); - if ($cpuload > 90) { $cpuload_status = "danger"; } - elseif ($cpuload > 75) { $cpuload_status = "warning"; } - elseif ($cpuload > 0) { $cpuload_status = "success"; } + $cpuload = floor(($loadavg * 100) / $cores); + if ($cpuload > 90) { $cpuload_status = "danger"; } + elseif ($cpuload > 75) { $cpuload_status = "warning"; } + elseif ($cpuload > 0) { $cpuload_status = "success"; } - ?> -
-
-
-
System
-
+ ?> +
+
+
+
System
+
- System Rebooting Now!
'; - $result = shell_exec("sudo /sbin/reboot"); - } - if (isset($_POST['system_shutdown'])) { - echo '
System Shutting Down Now!
'; - $result = shell_exec("sudo /sbin/shutdown -h now"); - } - ?> + System Rebooting Now!
'; + $result = shell_exec("sudo /sbin/reboot"); + } + if (isset($_POST['system_shutdown'])) { + echo '
System Shutting Down Now!
'; + $result = shell_exec("sudo /sbin/shutdown -h now"); + } + ?> -
-
-
-
-

System Information

-
Hostname

-
Uptime


-
Memory Used
-
-
% -
-
-
CPU Load
-
-
% -
-
-
-
-
-
+
+
+
+
+

System Information

+
Hostname

+
Pi Revision

+
Uptime


+
Memory Used
+
+
% +
+
+
CPU Load
+
+
% +
+
+
+
+
+
-
- - - -
+
+ + + +
-
-
-
-
- +
+
+ + From fe3b0e9513f16db464b2ced887de1a8a42272ba3 Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Fri, 12 Aug 2016 17:00:43 +0000 Subject: [PATCH 3/9] Move client wifi configuration into separate file --- includes/configure_client.php | 126 ++++++++++++++++++++++++++++++++++ includes/functions.php | 123 --------------------------------- index.php | 1 + 3 files changed, 127 insertions(+), 123 deletions(-) create mode 100755 includes/configure_client.php diff --git a/includes/configure_client.php b/includes/configure_client.php new file mode 100755 index 00000000..4044dd74 --- /dev/null +++ b/includes/configure_client.php @@ -0,0 +1,126 @@ + +
+
+
+
Configure client +
+ +
+ +

Client settings

+
+
+ + 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 +
'; + } + + // 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 { + + // 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]); + } + } + + $numSSIDs = count($ssid); + $output = '
'; + + if ( $numSSIDs > 0 ) { + for( $ssids = 0; $ssids < $numSSIDs; $ssids++ ) { + $output .= '
+
+
+
+
'; + } + $output .= '
'; + } else { + $status = '
Not connected +
'; + } + $output .= '
'; + $output .= ''; + echo $output; + } + ?> + + +
+
+
+
+ diff --git a/includes/functions.php b/includes/functions.php index 9d12869d..21c88eac 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -281,129 +281,6 @@ function DisplayDashboard(){ -
-
-
-
Configure client -
- -
- -

Client settings

-
-
- - 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 -
'; - } - - // 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 { - - // 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]); - } - } - - $numSSIDs = count($ssid); - $output = '
'; - - if ( $numSSIDs > 0 ) { - for( $ssids = 0; $ssids < $numSSIDs; $ssids++ ) { - $output .= '
-
-
-
-
'; - } - $output .= '
'; - } else { - $status = '
Not connected -
'; - } - $output .= '
'; - $output .= ''; - echo $output; - } - ?> - - -
-
-
-
- Date: Fri, 12 Aug 2016 17:29:56 +0000 Subject: [PATCH 4/9] Change method of calculating channel and security --- includes/configure_client.php | 208 +++++++++++++++++----------------- includes/functions.php | 70 +++++------- 2 files changed, 132 insertions(+), 146 deletions(-) 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); + } } /** From ad76f7651a05ee3a91de8ab4ab242b986a3b14b5 Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Fri, 12 Aug 2016 20:53:44 +0000 Subject: [PATCH 5/9] Split out php from html --- includes/configure_client.php | 262 ++++++++++++++++++++-------------- 1 file changed, 157 insertions(+), 105 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index a5e2aa15..2b1d1188 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -5,119 +5,171 @@ * */ function DisplayWPAConfig(){ - $status = ''; + $status = new StatusMessages(); + $scanned_networks = array(); + + if( isset($_POST['SaveWPAPSKSettings']) ) { + + $config = 'ctrl_interface=DIR='. RASPI_WPA_CTRL_INTERFACE .' GROUP=netdev +update_config=1 +'; + $networks = $_POST['Networks']; + for( $x = 0; $x < $networks; $x++ ) { + $network = ''; + $ssid = escapeshellarg( $_POST['ssid'.$x] ); + $protocol = escapeshellarg( $_POST['protocol'.$x] ); + $psk = escapeshellarg( $_POST['psk'.$x] ); + + 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 ) { + $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); ?> + +
-
-
Configure client -
- -
- -

Client settings

+
+
Configure client
+ +
+

showMessages(); ?>

+

Client settings

- + +
+
+
+ + + +
+
+

Networks found

+
+ + + + + + + + + + + + + + + + + + + + + +
SSIDChannelSignalSecurity
+
+ +
+
- $config = 'ctrl_interface=DIR='. RASPI_WPA_CTRL_INTERFACE .' GROUP=netdev -update_config=1 -'; - $networks = $_POST['Networks']; - for( $x = 0; $x < $networks; $x++ ) { - $network = ''; - $ssid = escapeshellarg( $_POST['ssid'.$x] ); - $psk = escapeshellarg( $_POST['psk'.$x] ); - - 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 -
'; - } - - // 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 { - - // 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]); - } - } - - $numSSIDs = count($ssid); - $output = '
'; - - if ( $numSSIDs > 0 ) { - for( $ssids = 0; $ssids < $numSSIDs; $ssids++ ) { - $output .= '
-
-
-
-
'; - } - $output .= '
'; - } else { - $status = '
Not connected -
'; - } - $output .= '
'; - $output .= ''; - echo $output; - } - ?> - - +
+
+
+ +
+ +
+
+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ +
+
+ +
+
+
+ + + + +
+
+ +
-
+
Date: Fri, 12 Aug 2016 21:22:21 +0000 Subject: [PATCH 6/9] 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
- +
- - + +
+ +
+
+ + +
+
+
From e953e685569a0cc35a96047bc74689b49e255ace Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Sun, 14 Aug 2016 16:40:59 +0000 Subject: [PATCH 7/9] Redo 'Configure client' page --- README.md | 1 + includes/configure_client.php | 331 +++++++++++++++------------------- includes/functions.php | 7 +- installers/common.sh | 4 +- 4 files changed, 158 insertions(+), 185 deletions(-) diff --git a/README.md b/README.md index f3b83e2f..9d7cbe2f 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Add the following to the end of `/etc/sudoers`: ```sh www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results, /sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf, /etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start, /etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf, /sbin/shutdown -h now, /sbin/reboot +www-data ALL=(ALL) NOPASSWD:/sbin/wpa_cli reconfigure ``` Once those modifications are done, git clone the files to `/var/www`. diff --git a/includes/configure_client.php b/includes/configure_client.php index 7e8d3478..62331951 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -8,122 +8,128 @@ function DisplayWPAConfig(){ $status = new StatusMessages(); $scanned_networks = array(); - if( isset($_POST['SaveWPAPSKSettings']) ) { - - $config = 'ctrl_interface=DIR='. RASPI_WPA_CTRL_INTERFACE .' GROUP=netdev -update_config=1 -'; - $networks = $_POST['Networks']; - for( $x = 0; $x < $networks; $x++ ) { - $network = ''; - $ssid = escapeshellarg( $_POST['ssid'.$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 -"; - } - } - } - 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$ + // Find currently configured networks exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $known_return); - $known_networks = array(); - $network_id = null; + $network = null; + $ssid = 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) { + $network = array('visible' => false, 'configured' => true); + } elseif ($network !== null) { if (preg_match('/^\s*}\s*$/', $line)) { - $network_id = null; + $networks[$ssid] = $network; + $network = null; + $ssid = null; } elseif ($lineArr = preg_split('/\s*=\s*/', trim($line))) { switch(strtolower($lineArr[0])) { case 'ssid': - $known_networks[$network_id]['ssid'] = trim($lineArr[1], '"'); + $ssid = trim($lineArr[1], '"'); break; case 'psk': - if (array_key_exists('passphrase', $known_networks[$network_id])) { + if (array_key_exists('passphrase', $network)) { break; } case '#psk': - $known_networks[$network_id]['protocol'] = 'WPA'; + $network['protocol'] = 'WPA'; case 'wep_key0': // Untested - $known_networks[$network_id]['passphrase'] = trim($lineArr[1], '"'); + $network['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)'; + if (! array_key_exists('passphrase', $network) && $lineArr[1] === 'NONE') { + $network['protocol'] = 'Open'; } break; } } } } + + if ( isset($_POST['client_settings']) && CSRFValidate() ) { + $tmp_networks = $networks; + if ($wpa_file = fopen('/tmp/wifidata', 'w')) { + fwrite($wpa_file, 'ctrl_interface=DIR=' . RASPI_WPA_CTRL_INTERFACE . ' GROUP=netdev' . PHP_EOL); + fwrite($wpa_file, 'update_config=1' . PHP_EOL); + + foreach(array_keys($_POST) as $post) { + if (preg_match('/delete(\d+)/', $post, $post_match)) { + unset($tmp_networks[$_POST['ssid' . $post_match[1]]]); + } elseif (preg_match('/update(\d+)/', $post, $post_match)) { + // NB, at the moment, the value of protocol from the form may + // contain HTML line breaks + $tmp_networks[$_POST['ssid' . $post_match[1]]] = array( + 'protocol' => ( $_POST['protocol' . $post_match[1]] === 'Open' ? 'Open' : 'WPA' ), + 'passphrase' => $_POST['passphrase' . $post_match[1]], + 'configured' => true + ); + } + } + + $ok = true; + foreach($tmp_networks as $ssid => $network) { + if ($network['protocol'] === 'Open') { + fwrite($wpa_file, "network={".PHP_EOL); + fwrite($wpa_file, "\tssid=\"".$ssid."\"".PHP_EOL); + fwrite($wpa_file, "\tkey_mgmt=NONE".PHP_EOL); + fwrite($wpa_file, "}".PHP_EOL); + } else { + if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) { + exec( 'wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']),$wpa_passphrase ); + foreach($wpa_passphrase as $line) { + fwrite($wpa_file, $line.PHP_EOL); + } + } else { + $status->addMessage('WPA passphrase must be between 8 and 63 characters', 'danger'); + $ok = false; + + } + } + + } + + if ($ok) { + system( 'sudo cp /tmp/wifidata ' . RASPI_WPA_SUPPLICANT_CONFIG, $returnval ); + if( $returnval == 0 ) { + exec('sudo wpa_cli reconfigure', $reconfigure_out, $reconfigure_return ); + if ($reconfigure_return == 0) { + $status->addMessage('Wifi settings updated successfully', 'success'); + $networks = $tmp_networks; + } else { + $status->addMessage('Wifi settings updated but cannot restart (cannon execute "wpa_cli reconfigure")', 'danger'); + } + } else { + $status->addMessage('Wifi settings failed to be updated', 'danger'); + } + } + } else { + $status->addMessage('Failed to updated wifi settings', 'danger'); + } + } + + exec( 'sudo wpa_cli scan' ); + sleep(3); + exec( 'sudo wpa_cli scan_results',$scan_return ); + for( $shift = 0; $shift < 2; $shift++ ) { + array_shift($scan_return); + } + // display output + foreach( $scan_return as $network ) { + $arrNetwork = preg_split("/[\t]+/",$network); + if (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? + } else { + $networks[$arrNetwork[4]] = array( + 'configured' => false, + 'protocol' => ConvertToSecurity($arrNetwork[3]), + 'channel' => ConvertToChannel($arrNetwork[1]), + 'passphrase' => '', + 'visible' => true + ); + } + } ?>
@@ -134,98 +140,59 @@ update_config=1

showMessages(); ?>

Client settings

-
-
- - -
-
-
- - - + + + + + + + + + + + + + + $network) { ?> + + + + + + + + + + + + + + + + + + + + +
SSIDChannelSecurityPassphrase
+ + + X--- + + +
+ + /> + + + + />
- -

Networks found

-
- - - - - - - - - - - - - - - - - - - - - -
SSIDChannelSignalSecurity
-
- - - - -
-
-
- -
- -
-
-
- -
-
-
-
- - -
-
-
-
- - -
-
- -
-
- - -
-
- -
-
- -
-
- -
-
-
- - - - -
-
- -
+
+
+
diff --git a/includes/functions.php b/includes/functions.php index 6538f579..739ebe18 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -17,7 +17,12 @@ function CSRFToken() { * */ function CSRFValidate() { - return hash_equals($_POST['csrf_token'], $_SESSION['csrf_token']); + if ( hash_equals($_POST['csrf_token'], $_SESSION['csrf_token']) ) { + return true; + } else { + error_log('CSRF violation'); + return false; + } } /** diff --git a/installers/common.sh b/installers/common.sh index dbf1695e..917f3e43 100644 --- a/installers/common.sh +++ b/installers/common.sh @@ -97,7 +97,7 @@ function move_config_file() { function patch_system_files() { install_log "Patching system sudoers file" # patch /etc/sudoers file - sudo bash -c 'echo "www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results, /sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf, /etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start, /etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf, /sbin/shutdown -h now, /sbin/reboot" | (EDITOR="tee -a" visudo)' \ + sudo bash -c 'echo "www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results, /sbin/wpa_cli scan,/sbin/wpa_cli reconfigure:/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf, /etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start, /etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf, /sbin/shutdown -h now, /sbin/reboot" | (EDITOR="tee -a" visudo)' \ || install_error "Unable to patch /etc/sudoers" } @@ -124,4 +124,4 @@ function install_raspap() { move_config_file patch_system_files install_complete -} \ No newline at end of file +} From b353dd77a895f26af4cd5057e661f332f4f0013e Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Sun, 14 Aug 2016 16:56:13 +0000 Subject: [PATCH 8/9] Add password length check Also remove most of the rest of the javascript as it is unused. --- dist/js/functions.js | 87 +++-------------------------------- includes/configure_client.php | 8 ++-- 2 files changed, 11 insertions(+), 84 deletions(-) diff --git a/dist/js/functions.js b/dist/js/functions.js index 3588a3b5..e9164308 100644 --- a/dist/js/functions.js +++ b/dist/js/functions.js @@ -1,82 +1,9 @@ -function WiFiDown() { - var down = confirm("Take down wlan0 ?"); - if(down) { - } else { - alert("Action cancelled"); - } -} - -function UpdateNetworks() { - var existing = document.getElementById("networkbox").getElementsByTagName('div').length; - document.getElementById("Networks").value = existing; -} - -function AddNetwork() { -// existing = document.getElementById("networkbox").getElementsByTagName('div').length; -// existing++; - Networks++ - var Networks = document.getElementById('Networks').value; - document.getElementById('networkbox').innerHTML += '

Network '+Networks+'

\ -
\ -
\ -
'; - Networks++; - document.getElementById('Networks').value=Networks; - -} - -function AddScanned(network, open = false) { - - existing = document.getElementById("networkbox").getElementsByTagName('div').length; - var Networks = document.getElementById('Networks').value; - //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 CheckPSK(psk, id) { + if(psk.value.length < 8 || psk.value.length > 63) { + psk.style.background='#FFD0D0'; + document.getElementById(id).disabled = true; + } else { + psk.style.background='#D0FFD0'; + document.getElementById(id).disabled = false; } } - -function CheckSSID(ssid) { - if(ssid.value.length>31) { - ssid.style.background='#FFD0D0'; - document.getElementById('Save').disabled = true; - } else { - ssid.style.background='#D0FFD0' - document.getElementById('Save').disabled = false; - } -} - -function CheckPSK(psk) { - if(psk.value.length < 8) { - psk.style.background='#FFD0D0'; - document.getElementById('Save').disabled = true; - } else { - psk.style.background='#D0FFD0'; - document.getElementById('Save').disabled = false; - } -} - -function DeleteNetwork(network) { - element = document.getElementById('Networkbox'+network); - element.parentNode.removeChild(element); - var Networks = document.getElementById('Networks').value; - Networks-- - document.getElementById('Networks').value = Networks; -} diff --git a/includes/configure_client.php b/includes/configure_client.php index 62331951..cc9a1b5b 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -174,14 +174,14 @@ function DisplayWPAConfig(){ --- - +
- /> + /> - + /> />
@@ -192,7 +192,7 @@ function DisplayWPAConfig(){
- +
From 9492330196f7c48c8952272e34ac6f8c9a62f64f Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Sun, 14 Aug 2016 17:25:53 +0000 Subject: [PATCH 9/9] Indicated connected network --- includes/configure_client.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index cc9a1b5b..ba2e9e6f 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -16,7 +16,7 @@ function DisplayWPAConfig(){ foreach($known_return as $line) { if (preg_match('/network\s*=/', $line)) { - $network = array('visible' => false, 'configured' => true); + $network = array('visible' => false, 'configured' => true, 'connected' => false); } elseif ($network !== null) { if (preg_match('/^\s*}\s*$/', $line)) { $networks[$ssid] = $network; @@ -126,10 +126,18 @@ function DisplayWPAConfig(){ 'protocol' => ConvertToSecurity($arrNetwork[3]), 'channel' => ConvertToChannel($arrNetwork[1]), 'passphrase' => '', - 'visible' => true + 'visible' => true, + 'connected' => false ); } } + + exec( 'iwconfig wlan0', $iwconfig_return ); + foreach ($iwconfig_return as $line) { + if (preg_match( '/ESSID:\"(.+)\"/i',$line,$iwconfig_ssid )) { + $networks[$iwconfig_ssid[1]]['connected'] = true; + } + } ?>
@@ -156,11 +164,14 @@ function DisplayWPAConfig(){ $network) { ?> - - - - - + + + + + + + +