From 095e1afa8ce44fd934d48c1840a1bb4287b58fa9 Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Mon, 8 Aug 2016 12:48:16 +0000 Subject: [PATCH 1/4] Move Dashboard function to separate file --- includes/dashboard.php | 147 +++++++++++++++++++++++++++++++++++++++++ includes/functions.php | 144 ---------------------------------------- index.php | 1 + 3 files changed, 148 insertions(+), 144 deletions(-) create mode 100755 includes/dashboard.php diff --git a/includes/dashboard.php b/includes/dashboard.php new file mode 100755 index 00000000..7fffa208 --- /dev/null +++ b/includes/dashboard.php @@ -0,0 +1,147 @@ +Interface is up + '; + $wlan0up = true; + } else { + $status = '
Interface is down +
'; + } + + if( isset($_POST['ifdown_wlan0']) ) { + exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); + if($test[0] == 1) { + exec( 'sudo ifdown wlan0',$return ); + } else { + echo 'Interface already down'; + } + } elseif( isset($_POST['ifup_wlan0']) ) { + exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); + if($test[0] == 0) { + exec( 'sudo ifup wlan0',$return ); + } else { + echo 'Interface already up'; + } + } + ?> +
+
+
+
Dashboard
+
+

+
+
+
+
+

Interface Information

+
Interface Name
wlan0
+
IP Address

+
Subnet Mask

+
Mac Address


+ +

Interface Statistics

+
Received Packets

+
Received Bytes


+
Transferred Packets

+
Transferred Bytes

+
+
+
+ +
+
+
+

Wireless Information

+
Connected To

+
AP Mac Address

+
Bitrate

+
Transmit Power

+
Frequency


+
Link Quality
+
+
% +
+
+
Signal Level
+
+
% +
+
+
+
+
+
+ +
+
+
+ '; + } else { + echo ''; + } + ?> + +
+
+
+ +
+ +
+
+
+ diff --git a/includes/functions.php b/includes/functions.php index eb76ffca..bf1ab228 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -137,150 +137,6 @@ function ConvertToSecurity( $security ) { } } -/** -* -* -*/ -function DisplayDashboard(){ - - exec( 'ifconfig wlan0', $return ); - exec( 'iwconfig wlan0', $return ); - - $strWlan0 = implode( " ", $return ); - $strWlan0 = preg_replace( '/\s\s+/', ' ', $strWlan0 ); - - // Parse results from ifconfig/iwconfig - preg_match( '/HWaddr ([0-9a-f:]+)/i',$strWlan0,$result ); - $strHWAddress = $result[1]; - preg_match( '/inet addr:([0-9.]+)/i',$strWlan0,$result ); - $strIPAddress = $result[1]; - preg_match( '/Mask:([0-9.]+)/i',$strWlan0,$result ); - $strNetMask = $result[1]; - preg_match( '/RX packets:(\d+)/',$strWlan0,$result ); - $strRxPackets = $result[1]; - preg_match( '/TX packets:(\d+)/',$strWlan0,$result ); - $strTxPackets = $result[1]; - preg_match( '/RX bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result ); - $strRxBytes = $result[1]; - preg_match( '/TX Bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result ); - $strTxBytes = $result[1]; - preg_match( '/ESSID:\"([a-zA-Z0-9\s]+)\"/i',$strWlan0,$result ); - $strSSID = str_replace( '"','',$result[1] ); - preg_match( '/Access Point: ([0-9a-f:]+)/i',$strWlan0,$result ); - $strBSSID = $result[1]; - preg_match( '/Bit Rate=([0-9]+ Mb\/s)/i',$strWlan0,$result ); - $strBitrate = $result[1]; - preg_match( '/Tx-Power=([0-9]+ dBm)/i',$strWlan0,$result ); - $strTxPower = $result[1]; - preg_match( '/Link Quality=([0-9]+)/i',$strWlan0,$result ); - $strLinkQuality = $result[1]; - preg_match( '/Signal Level=([0-9]+)/i',$strWlan0,$result ); - $strSignalLevel = $result[1]; - preg_match('/Frequency:(\d+.\d+ GHz)/i',$strWlan0,$result); - $strFrequency = $result[1]; - - if(strpos( $strWlan0, "UP" ) !== false && strpos( $strWlan0, "RUNNING" ) !== false ) { - $status = '
Interface is up -
'; - $wlan0up = true; - } else { - $status = '
Interface is down -
'; - } - - if( isset($_POST['ifdown_wlan0']) ) { - exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); - if($test[0] == 1) { - exec( 'sudo ifdown wlan0',$return ); - } else { - echo 'Interface already down'; - } - } elseif( isset($_POST['ifup_wlan0']) ) { - exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); - if($test[0] == 0) { - exec( 'sudo ifup wlan0',$return ); - } else { - echo 'Interface already up'; - } - } - ?> -
-
-
-
Dashboard
-
-

-
-
-
-
-

Interface Information

-
Interface Name
wlan0
-
IP Address

-
Subnet Mask

-
Mac Address


- -

Interface Statistics

-
Received Packets

-
Received Bytes


-
Transferred Packets

-
Transferred Bytes

-
-
-
- -
-
-
-

Wireless Information

-
Connected To

-
AP Mac Address

-
Bitrate

-
Transmit Power

-
Frequency


-
Link Quality
-
-
% -
-
-
Signal Level
-
-
% -
-
-
-
-
-
- -
-
-
- '; - } else { - echo ''; - } - ?> - -
-
-
- -
- -
-
-
- Date: Mon, 8 Aug 2016 21:37:44 +0100 Subject: [PATCH 2/4] Change tabs to spaces --- includes/dashboard.php | 256 ++++++++++++++++++++--------------------- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 7fffa208..981833c7 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -6,142 +6,142 @@ */ function DisplayDashboard(){ - exec( 'ifconfig wlan0', $return ); - exec( 'iwconfig wlan0', $return ); + exec( 'ifconfig wlan0', $return ); + exec( 'iwconfig wlan0', $return ); - $strWlan0 = implode( " ", $return ); - $strWlan0 = preg_replace( '/\s\s+/', ' ', $strWlan0 ); + $strWlan0 = implode( " ", $return ); + $strWlan0 = preg_replace( '/\s\s+/', ' ', $strWlan0 ); - // Parse results from ifconfig/iwconfig - preg_match( '/HWaddr ([0-9a-f:]+)/i',$strWlan0,$result ); - $strHWAddress = $result[1]; - preg_match( '/inet addr:([0-9.]+)/i',$strWlan0,$result ); - $strIPAddress = $result[1]; - preg_match( '/Mask:([0-9.]+)/i',$strWlan0,$result ); - $strNetMask = $result[1]; - preg_match( '/RX packets:(\d+)/',$strWlan0,$result ); - $strRxPackets = $result[1]; - preg_match( '/TX packets:(\d+)/',$strWlan0,$result ); - $strTxPackets = $result[1]; - preg_match( '/RX bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result ); - $strRxBytes = $result[1]; - preg_match( '/TX Bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result ); - $strTxBytes = $result[1]; - preg_match( '/ESSID:\"([a-zA-Z0-9\s]+)\"/i',$strWlan0,$result ); - $strSSID = str_replace( '"','',$result[1] ); - preg_match( '/Access Point: ([0-9a-f:]+)/i',$strWlan0,$result ); - $strBSSID = $result[1]; - preg_match( '/Bit Rate=([0-9]+ Mb\/s)/i',$strWlan0,$result ); - $strBitrate = $result[1]; - preg_match( '/Tx-Power=([0-9]+ dBm)/i',$strWlan0,$result ); - $strTxPower = $result[1]; - preg_match( '/Link Quality=([0-9]+)/i',$strWlan0,$result ); - $strLinkQuality = $result[1]; - preg_match( '/Signal Level=([0-9]+)/i',$strWlan0,$result ); - $strSignalLevel = $result[1]; - preg_match('/Frequency:(\d+.\d+ GHz)/i',$strWlan0,$result); - $strFrequency = $result[1]; + // Parse results from ifconfig/iwconfig + preg_match( '/HWaddr ([0-9a-f:]+)/i',$strWlan0,$result ); + $strHWAddress = $result[1]; + preg_match( '/inet addr:([0-9.]+)/i',$strWlan0,$result ); + $strIPAddress = $result[1]; + preg_match( '/Mask:([0-9.]+)/i',$strWlan0,$result ); + $strNetMask = $result[1]; + preg_match( '/RX packets:(\d+)/',$strWlan0,$result ); + $strRxPackets = $result[1]; + preg_match( '/TX packets:(\d+)/',$strWlan0,$result ); + $strTxPackets = $result[1]; + preg_match( '/RX bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result ); + $strRxBytes = $result[1]; + preg_match( '/TX Bytes:(\d+ \(\d+.\d+ [K|M|G]iB\))/i',$strWlan0,$result ); + $strTxBytes = $result[1]; + preg_match( '/ESSID:\"([a-zA-Z0-9\s]+)\"/i',$strWlan0,$result ); + $strSSID = str_replace( '"','',$result[1] ); + preg_match( '/Access Point: ([0-9a-f:]+)/i',$strWlan0,$result ); + $strBSSID = $result[1]; + preg_match( '/Bit Rate=([0-9]+ Mb\/s)/i',$strWlan0,$result ); + $strBitrate = $result[1]; + preg_match( '/Tx-Power=([0-9]+ dBm)/i',$strWlan0,$result ); + $strTxPower = $result[1]; + preg_match( '/Link Quality=([0-9]+)/i',$strWlan0,$result ); + $strLinkQuality = $result[1]; + preg_match( '/Signal Level=([0-9]+)/i',$strWlan0,$result ); + $strSignalLevel = $result[1]; + preg_match('/Frequency:(\d+.\d+ GHz)/i',$strWlan0,$result); + $strFrequency = $result[1]; - if(strpos( $strWlan0, "UP" ) !== false && strpos( $strWlan0, "RUNNING" ) !== false ) { - $status = '
Interface is up -
'; - $wlan0up = true; - } else { - $status = '
Interface is down -
'; - } + if(strpos( $strWlan0, "UP" ) !== false && strpos( $strWlan0, "RUNNING" ) !== false ) { + $status = '
Interface is up +
'; + $wlan0up = true; + } else { + $status = '
Interface is down +
'; + } - if( isset($_POST['ifdown_wlan0']) ) { - exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); - if($test[0] == 1) { - exec( 'sudo ifdown wlan0',$return ); - } else { - echo 'Interface already down'; - } - } elseif( isset($_POST['ifup_wlan0']) ) { - exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); - if($test[0] == 0) { - exec( 'sudo ifup wlan0',$return ); - } else { - echo 'Interface already up'; - } - } - ?> -
-
-
-
Dashboard
-
-

-
-
-
-
-

Interface Information

-
Interface Name
wlan0
-
IP Address

-
Subnet Mask

-
Mac Address


+ if( isset($_POST['ifdown_wlan0']) ) { + exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); + if($test[0] == 1) { + exec( 'sudo ifdown wlan0',$return ); + } else { + echo 'Interface already down'; + } + } elseif( isset($_POST['ifup_wlan0']) ) { + exec( 'ifconfig wlan0 | grep -i running | wc -l',$test ); + if($test[0] == 0) { + exec( 'sudo ifup wlan0',$return ); + } else { + echo 'Interface already up'; + } + } + ?> +
+
+
+
Dashboard
+
+

+
+
+
+
+

Interface Information

+
Interface Name
wlan0
+
IP Address

+
Subnet Mask

+
Mac Address


-

Interface Statistics

-
Received Packets

-
Received Bytes


-
Transferred Packets

-
Transferred Bytes

-
-
-
+

Interface Statistics

+
Received Packets

+
Received Bytes


+
Transferred Packets

+
Transferred Bytes

+
+
+
-
-
-
-

Wireless Information

-
Connected To

-
AP Mac Address

-
Bitrate

-
Transmit Power

-
Frequency


-
Link Quality
-
-
% -
-
-
Signal Level
-
-
% -
-
-
-
-
-
+
+
+
+

Wireless Information

+
Connected To

+
AP Mac Address

+
Bitrate

+
Transmit Power

+
Frequency


+
Link Quality
+
+
% +
+
+
Signal Level
+
+
% +
+
+
+
+
+
-
-
-
- '; - } else { - echo ''; - } - ?> - -
-
-
+
+
+
+ '; + } else { + echo ''; + } + ?> + +
+
+
-
- -
-
-
- + +
+
+
+ From f730aa1ffbaa3585bfa4342ef3fc0ea5a0c13d4f Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Mon, 15 Aug 2016 12:25:20 +0000 Subject: [PATCH 3/4] Use status class --- includes/dashboard.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 981833c7..90b4fb14 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -6,6 +6,8 @@ */ function DisplayDashboard(){ + $status = new StatusMessages(); + exec( 'ifconfig wlan0', $return ); exec( 'iwconfig wlan0', $return ); @@ -43,12 +45,10 @@ function DisplayDashboard(){ $strFrequency = $result[1]; if(strpos( $strWlan0, "UP" ) !== false && strpos( $strWlan0, "RUNNING" ) !== false ) { - $status = '
Interface is up -
'; + $status->addMessage('Interface is up', 'success'); $wlan0up = true; } else { - $status = '
Interface is down -
'; + $status->addMessage('Interface is down', 'warning'); } if( isset($_POST['ifdown_wlan0']) ) { @@ -72,7 +72,7 @@ function DisplayDashboard(){
Dashboard
-

+

showMessages(); ?>

From 66d6f3766c58c33a1e2113f5964c932b264dc2e7 Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Mon, 15 Aug 2016 12:45:37 +0000 Subject: [PATCH 4/4] Find bitrate and signal level correctly Also, display signal level as just a number rather than a graph --- includes/dashboard.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 90b4fb14..69ed7912 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -33,13 +33,13 @@ function DisplayDashboard(){ $strSSID = str_replace( '"','',$result[1] ); preg_match( '/Access Point: ([0-9a-f:]+)/i',$strWlan0,$result ); $strBSSID = $result[1]; - preg_match( '/Bit Rate=([0-9]+ Mb\/s)/i',$strWlan0,$result ); + preg_match( '/Bit Rate=([0-9\.]+ Mb\/s)/i',$strWlan0,$result ); $strBitrate = $result[1]; preg_match( '/Tx-Power=([0-9]+ dBm)/i',$strWlan0,$result ); $strTxPower = $result[1]; preg_match( '/Link Quality=([0-9]+)/i',$strWlan0,$result ); $strLinkQuality = $result[1]; - preg_match( '/Signal Level=([0-9]+)/i',$strWlan0,$result ); + preg_match( '/Signal level=(-?[0-9]+ dBm)/i',$strWlan0,$result ); $strSignalLevel = $result[1]; preg_match('/Frequency:(\d+.\d+ GHz)/i',$strWlan0,$result); $strFrequency = $result[1]; @@ -99,6 +99,7 @@ function DisplayDashboard(){
Connected To

AP Mac Address

Bitrate

+
Signal Level

Transmit Power

Frequency


Link Quality
@@ -108,15 +109,7 @@ function DisplayDashboard(){ aria-valuenow="" aria-valuemin="0" aria-valuemax="100" style="width: %;">%
-
-
Signal Level
-
-
% -
-
+