diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index 7aac976a1..2017657bc 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -595,4 +595,28 @@ function convertUnicodeToIDNA($IDNA) { return $IDNA; } + +// Return PID of FTL (used in settings.php) +function pidofFTL() { + return shell_exec("pidof pihole-FTL"); +} + +// Get FTL process information (used in settings.php) +function get_FTL_data($FTLpid, $arg) { + return trim(exec("ps -p " . $FTLpid . " -o " . $arg)); +} + +// Convert seconds into readable time (used in settings.php) +function convertseconds($argument) { + $seconds = round($argument); + if ($seconds < 60) { + return sprintf('%ds', $seconds); + } elseif ($seconds < 3600) { + return sprintf('%dm %ds', ($seconds / 60), ($seconds % 60)); + } elseif ($seconds < 86400) { + return sprintf('%dh %dm %ds', ($seconds / 3600 % 24), ($seconds / 60 % 60), ($seconds % 60)); + } else { + return sprintf('%dd %dh %dm %ds', ($seconds / 86400), ($seconds / 3600 % 24), ($seconds / 60 % 60), ($seconds % 60)); + } +} ?> diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index 7a8354554..3b06edaec 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -6,156 +6,138 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ - require "scripts/pi-hole/php/auth.php"; - require "scripts/pi-hole/php/password.php"; - require_once "scripts/pi-hole/php/FTL.php"; - require_once "scripts/pi-hole/php/func.php"; - require "scripts/pi-hole/php/theme.php"; - $scriptname = basename($_SERVER['SCRIPT_FILENAME']); - $hostname = gethostname() ? gethostname() : ""; +require "scripts/pi-hole/php/auth.php"; +require "scripts/pi-hole/php/password.php"; +require_once "scripts/pi-hole/php/FTL.php"; +require_once "scripts/pi-hole/php/func.php"; +require "scripts/pi-hole/php/theme.php"; +$scriptname = basename($_SERVER['SCRIPT_FILENAME']); +$hostname = gethostname() ? gethostname() : ""; - check_cors(); +// Return memory usage to show on status block +function getMemUsage() { + $data = explode("\n", file_get_contents("/proc/meminfo")); + $meminfo = array(); + if (count($data) > 0) { + foreach ($data as $line) { + $expl = explode(":", $line); + if (count($expl) == 2) { + // remove " kB" from the end of the string and make it an integer + $meminfo[$expl[0]] = intval(trim(substr($expl[1],0, -3))); + } + } + $memused = $meminfo["MemTotal"] - $meminfo["MemFree"] - $meminfo["Buffers"] - $meminfo["Cached"]; + $memusage = $memused / $meminfo["MemTotal"]; + } else { + $memusage = -1; + } - // Create cache busting version - $cacheVer = filemtime(__FILE__); + return $memusage; +} - // Generate CSRF token - if(empty($_SESSION['token'])) { - $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); - } - $token = $_SESSION['token']; +// Try to get temperature value from different places (OS dependent) +// - return an array, containing the temperature and limit. +function getTemperature() { + global $setupVars; - // Try to get temperature value from different places (OS dependent) - if(file_exists("/sys/class/thermal/thermal_zone0/temp")) - { + if (file_exists("/sys/class/thermal/thermal_zone0/temp")) { $output = rtrim(file_get_contents("/sys/class/thermal/thermal_zone0/temp")); - } - elseif (file_exists("/sys/class/hwmon/hwmon0/temp1_input")) - { + } elseif (file_exists("/sys/class/hwmon/hwmon0/temp1_input")) { $output = rtrim(file_get_contents("/sys/class/hwmon/hwmon0/temp1_input")); - } - else - { + } else { $output = ""; } // Test if we succeeded in getting the temperature - if(is_numeric($output)) - { + if (is_numeric($output)) { // $output could be either 4-5 digits or 2-3, and we only divide by 1000 if it's 4-5 // ex. 39007 vs 39 $celsius = intval($output); // If celsius is greater than 1 degree and is in the 4-5 digit format - if($celsius > 1000) { + if ($celsius > 1000) { // Use multiplication to get around the division-by-zero error $celsius *= 1e-3; } // Get user-defined temperature limit if set - if(isset($setupVars['TEMPERATURE_LIMIT'])) - { - $temperaturelimit = intval($setupVars['TEMPERATURE_LIMIT']); - } - else - { - $temperaturelimit = 60; + if (isset($setupVars['TEMPERATURE_LIMIT'])) { + $limit = intval($setupVars['TEMPERATURE_LIMIT']); + } else { + $limit = 60; } - } - else - { + + } else { // Nothing can be colder than -273.15 degree Celsius (= 0 Kelvin) // This is the minimum temperature possible (AKA absolute zero) $celsius = -273.16; // Set templimit to null if no tempsensor was found - $temperaturelimit = null; + $limit = null; } - // Get load - $loaddata = sys_getloadavg(); - foreach ($loaddata as $key => $value) { - $loaddata[$key] = round($value, 2); - } - // Get number of processing units available to PHP - // (may be less than the number of online processors) - $nproc = shell_exec('nproc'); - if(!is_numeric($nproc)) - { - $cpuinfo = file_get_contents('/proc/cpuinfo'); - preg_match_all('/^processor/m', $cpuinfo, $matches); - $nproc = count($matches[0]); - } + return [$celsius, $limit]; +} - // Get memory usage - $data = explode("\n", file_get_contents("/proc/meminfo")); - $meminfo = array(); - if(count($data) > 0) - { - foreach ($data as $line) { - $expl = explode(":", trim($line)); - if(count($expl) == 2) - { - // remove " kB" from the end of the string and make it an integer - $meminfo[$expl[0]] = intval(substr($expl[1],0, -3)); - } - } - $memory_used = $meminfo["MemTotal"]-$meminfo["MemFree"]-$meminfo["Buffers"]-$meminfo["Cached"]; - $memory_total = $meminfo["MemTotal"]; - $memory_usage = $memory_used/$memory_total; - } - else - { - $memory_usage = -1; - } +check_cors(); - if($auth) { - // For session timer - $maxlifetime = ini_get("session.gc_maxlifetime"); +// Create cache busting version +$cacheVer = filemtime(__FILE__); - // Generate CSRF token - if(empty($_SESSION['token'])) { - $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); - } - $token = $_SESSION['token']; - } +// Generate CSRF token +if (empty($_SESSION['token'])) { + $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); +} +$token = $_SESSION['token']; - if(isset($setupVars['WEBUIBOXEDLAYOUT'])) - { - if($setupVars['WEBUIBOXEDLAYOUT'] === "boxed") - { - $boxedlayout = true; - } - else - { - $boxedlayout = false; - } - } - else - { - $boxedlayout = true; - } +if ($auth) { + // For session timer + $maxlifetime = ini_get("session.gc_maxlifetime"); - // Override layout setting if layout is changed via Settings page - if(isset($_POST["field"])) - { - if($_POST["field"] === "webUI" && isset($_POST["boxedlayout"])) - { - $boxedlayout = true; - } - elseif($_POST["field"] === "webUI" && !isset($_POST["boxedlayout"])) - { - $boxedlayout = false; - } + // Generate CSRF token + if (empty($_SESSION['token'])) { + $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); } + $token = $_SESSION['token']; +} + +// Get temperature +list($celsius, $temperaturelimit) = getTemperature(); + +// Get CPU load +$loaddata = sys_getloadavg(); +foreach ($loaddata as $key => $value) { + $loaddata[$key] = round($value, 2); +} + +// Get number of processing units available to PHP +// (may be less than the number of online processors) +$nproc = shell_exec('nproc'); +if (!is_numeric($nproc)) { + $cpuinfo = file_get_contents('/proc/cpuinfo'); + preg_match_all('/^processor/m', $cpuinfo, $matches); + $nproc = count($matches[0]); +} - function pidofFTL() - { - return shell_exec("pidof pihole-FTL"); +// Get memory usage +$memory_usage = getMemUsage(); + +// Retrieve layout setting from setupVars +if (isset($setupVars['WEBUIBOXEDLAYOUT']) && !($setupVars['WEBUIBOXEDLAYOUT'] === "boxed")) { + $boxedlayout = false; +} else { + $boxedlayout = true; +} + +// Override layout setting if layout is changed via Settings page +if (isset($_POST["field"])) { + if ($_POST["field"] === "webUI" && isset($_POST["boxedlayout"])) { + $boxedlayout = true; + } elseif ($_POST["field"] === "webUI" && !isset($_POST["boxedlayout"])) { + $boxedlayout = false; } - $FTLpid = intval(pidofFTL()); - $FTL = ($FTLpid !== 0 ? true : false); +} - $piholeFTLConf = piholeFTLConfig(); +$piholeFTLConf = piholeFTLConfig(); ?> - +
diff --git a/scripts/pi-hole/php/loginpage.php b/scripts/pi-hole/php/loginpage.php index 6a2339c0d..06843e4db 100644 --- a/scripts/pi-hole/php/loginpage.php +++ b/scripts/pi-hole/php/loginpage.php @@ -4,7 +4,8 @@ * Network-wide ad blocking via your own hardware. * * This file is copyright under the latest version of the EUPL. -* Please see LICENSE file for your rights under this license. */ ?> +* Please see LICENSE file for your rights under this license. */ +?>
@@ -69,3 +70,6 @@
+ diff --git a/scripts/pi-hole/php/sidebar.php b/scripts/pi-hole/php/sidebar.php new file mode 100644 index 000000000..28ca3a52b --- /dev/null +++ b/scripts/pi-hole/php/sidebar.php @@ -0,0 +1,339 @@ + + diff --git a/settings.php b/settings.php index 4c55087eb..431016ae8 100644 --- a/settings.php +++ b/settings.php @@ -233,13 +233,8 @@
@@ -254,25 +249,25 @@ function get_FTL_data($arg) - + - + - + - + - +
Time FTL started:
User / Group: / /
Total CPU utilization:%%
Memory utilization:%%
Used memory:
@@ -559,20 +554,6 @@ function get_FTL_data($arg) if (!is_resource($dhcpleases)) $leasesfile = false; - function convertseconds($argument) - { - $seconds = round($argument); - if ($seconds < 60) { - return sprintf('%ds', $seconds); - } elseif ($seconds < 3600) { - return sprintf('%dm %ds', ($seconds / 60), ($seconds % 60)); - } elseif ($seconds < 86400) { - return sprintf('%dh %dm %ds', ($seconds / 3600 % 24), ($seconds / 60 % 60), ($seconds % 60)); - } else { - return sprintf('%dd %dh %dm %ds', ($seconds / 86400), ($seconds / 3600 % 24), ($seconds / 60 % 60), ($seconds % 60)); - } - } - while (!feof($dhcpleases) && $leasesfile) { $line = explode(" ", trim(fgets($dhcpleases))); if (count($line) == 5) { diff --git a/style/themes/lcars.css b/style/themes/lcars.css index 2515c6cd8..b44691fd2 100644 --- a/style/themes/lcars.css +++ b/style/themes/lcars.css @@ -749,36 +749,39 @@ p.login-box-msg, } .sidebar-menu > li.header { + margin: 4px 0 0; + padding: 0.5em 1em; + text-align: left; + color: #000; + background: #cce6ff; + font-size: 11px; +} + +/* Hide menu headers if not logged in */ +body:not(.logged-in) .sidebar-menu > li.header { display: none; } .sidebar-menu > li > a { margin: 4px 0 0; - padding: 38px 15px 5px; + padding: 30px 15px 5px; background: #8bf; border-left: none; } .sidebar-menu > li.active > a { - background-color: #48f; -} - -.sidebar-menu > li:last-child > a { - background-color: #cce6ff; -} - -.sidebar-menu > li:nth-last-child(2) > a { - background-color: #cb7; + background-color: #eda; + box-shadow: inset 0 0 18px #ba7; } -.sidebar-menu > li:nth-last-child(3) > a { - background-color: #04f; +.sidebar-menu > li > a.menu-support { + background-color: #26f; } .sidebar-menu > li:hover > a, .sidebar-menu > li > a:focus { - background-color: #eda; - box-shadow: inset 0 0 18px #ba7; + background-color: #48f; + box-shadow: none; } .sidebar-menu > li > .treeview-menu {