PHP_SMART_HOME_V3/app/views/Server.php

57 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2020-07-23 15:58:46 +00:00
<?php
class Server extends Template
{
//TODO: to server manager
private function getSystemMemInfo()
{
$data = explode("\n", file_get_contents("/proc/meminfo"));
$meminfo = array();
foreach ($data as $line) {
$data = explode(":", $line);
if (count($data)!=2) continue;
$meminfo[$data[0]] = trim($data[1]);
}
return $meminfo;
}
2020-10-31 13:53:12 +00:00
private function getProcessorUsage(){
$loads=sys_getloadavg();
$core_nums=trim(shell_exec("grep -P '^physical id' /proc/cpuinfo|wc -l"));
$load = round($loads[0]/($core_nums + 1)*100, 2);
return $load;
}
2020-12-09 11:19:19 +00:00
2020-10-31 20:37:29 +00:00
function __construct()
{
2020-10-31 13:53:12 +00:00
$userManager = new UserManager();
2020-07-23 15:58:46 +00:00
$langMng = new LanguageManager('en');
if (!$userManager->isLogin()){
header('Location: ' . BASEURL . 'login');
}
$template = new Template('server');
$template->prepare('title', 'Server');
$template->prepare('baseDir', BASEDIR);
2020-12-09 11:19:19 +00:00
$template->prepare('baseUrl', BASEURL);
2020-07-23 15:58:46 +00:00
$template->prepare('debugMod', DEBUGMOD);
$template->prepare('langMng', $langMng);
$template->prepare('UPTIME', shell_exec('uptime -p'));
$template->prepare('serverTime', date('m. d. Y H:i:s - e'));
$template->prepare('ip', $_SERVER['SERVER_ADDR']);
$template->prepare('name', $_SERVER['SERVER_NAME']);
2020-10-31 13:53:12 +00:00
$template->prepare('CPU', $this->getProcessorUsage());
2020-07-23 15:58:46 +00:00
$template->prepare('ramFree', $this->getSystemMemInfo()["MemFree"]);
$template->prepare('ramTotal', $this->getSystemMemInfo()["MemTotal"]);
$template->prepare('diskFree', disk_free_space("/"));
$template->prepare('diskTotal', disk_total_space("/"));
$template->render();
}
}