From de7c0f7d79ef37400671c5013d974ab04060daf7 Mon Sep 17 00:00:00 2001 From: zlolz Date: Sun, 12 Jun 2016 00:17:44 +0000 Subject: [PATCH 1/2] Add System Info and System Control (foundation) --- README.md | 7 +- dist/css/custom.css | 7 +- includes/functions.php | 170 +++++++++++++++++++++++++++++++---------- index.php | 6 ++ 4 files changed, 142 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 4f27261b..68c55dfb 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,7 @@ So what I have done is added the `www-data` user to the sudoers file, but with r 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 +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 ``` Once those modifications are done, git clone the files to `/var/www`. diff --git a/dist/css/custom.css b/dist/css/custom.css index ea237b1d..72498bce 100644 --- a/dist/css/custom.css +++ b/dist/css/custom.css @@ -27,4 +27,9 @@ .btn-primary:hover { background-color: #c61931; border-color: #c61931; -} \ No newline at end of file +} + +.info-item { + width: 160px; + float: left; +} diff --git a/includes/functions.php b/includes/functions.php index 9354c554..325dbb14 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -161,50 +161,53 @@ function DisplayDashboard(){

-
-
-
-

Interface Information

- Interface Name : wlan0
- IP Address :
- Subnet Mask :
- Mac Address :
+
+
+
+

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 : -
-
- % -
-
-
-
- -
-
+
Connected To

+
AP Mac Address

+
Bitrate

+
Transmit Power

+
Frequency


+
Link Quality
+
+
% +
+
+
Signal Level
+
+
% +
+
+
+
+
+
@@ -982,6 +985,91 @@ 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]); + + ?> +
+
+
+
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
+
+
% +
+
+ +
+
+
+
+ +
+ + + +
+ +
+
+
+
+ Configure RaspAP +
  • + System +
  • @@ -176,6 +179,9 @@ $page = $_GET['page']; case "save_hostapd_conf": SaveHostAPDConfig(); break; + case "system_info": + DisplaySystem(); + break; default: DisplayDashboard(); } From 638f2e6d3d986a341685aceefa7141bb17d28862 Mon Sep 17 00:00:00 2001 From: zlolz Date: Sun, 12 Jun 2016 04:16:59 +0000 Subject: [PATCH 2/2] add cpu load bar, colour mem and cpu bars baased values (ok, warning, danger) --- includes/functions.php | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 325dbb14..d2773023 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1001,22 +1001,27 @@ function DisplaySystem(){ $minutes = $seconds / 60; $hours = $minutes / 60; $days = floor($hours / 24); - $hours = sprintf('%d', floor($hours - ($days * 24))); - $minutes = sprintf('%d', floor($minutes - ($days * 24 * 60) - ($hours * 60))); + $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':'' ) . ' '; - } + 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"; } + + // 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"; } ?>
    @@ -1042,16 +1047,23 @@ function DisplaySystem(){

    System Information

    Hostname

    -
    Uptime

    +
    Uptime


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