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; } return $memusage; } // Try to get temperature value from different places (OS dependent) // - return an array, containing the temperature and limit. function getTemperature() { global $setupVars; 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')) { $output = rtrim(file_get_contents('/sys/class/hwmon/hwmon0/temp1_input')); } else { $output = ''; } // Test if we succeeded in getting the temperature 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) { // 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'])) { $limit = intval($setupVars['TEMPERATURE_LIMIT']); } else { $limit = 60; } } 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 $limit = null; } // Get user-defined temperature limit if set if (isset($setupVars['TEMPERATUREUNIT'])) { switch (strtoupper($setupVars['TEMPERATUREUNIT'])) { case 'F': case 'K': $unit = strtoupper($setupVars['TEMPERATUREUNIT']); break; default: $unit = 'C'; } } else { // no value is set in setupVars.conf $unit = ''; } return array($celsius, $limit, $unit); } check_cors(); // Generate CSRF token if (empty($_SESSION['token'])) { $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); } $token = $_SESSION['token']; // For session timer $maxlifetime = ini_get('session.gc_maxlifetime'); // Get temperature list($celsius, $temperaturelimit, $temperatureunit) = 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]); } // Get memory usage $memory_usage = getMemUsage(); $piholeFTLConf = piholeFTLConfig(); require 'header.php'; ?> {$token}"; } ?>