From 7406a5050c2a7fc9f74d39cdb4761fbc6d08354f Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Mon, 8 Aug 2016 12:31:19 +0000 Subject: [PATCH 1/2] 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/2] 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
+
+
% +
+
+
+
+
+
-
- - - -
+
+ + + +
-
-
-
-
- +
+
+ +