Umbau der Statistik Ausgabe (each enfernt)

Optimierungen
This commit is contained in:
Gregor Schulte
2021-11-29 15:23:19 +01:00
parent b303dd00d6
commit c464f9e3a3
18 changed files with 580 additions and 545 deletions

View File

@@ -38,7 +38,7 @@ $tpl->assign('configHelpFilesFolders', $config['url']['help'].'?s=view&i=1'.
$tpl->assign('configHelpCron', $config['url']['help'].'?s=view&i=10'.getURLLangParam());
$tpl->assign('cronEntry', $cronEntry);
$tpl->assign('cronMatch', $cronMatch);
$tpl->assign('cronPHPCLI', ($cronPHPCLI = (trim(exec('dpkg -s php5-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.0-cli | grep Status: ')) != '') ? true : false));
$tpl->assign('cronPHPCLI', ($cronPHPCLI = (trim(exec('dpkg -s php7.0-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '') ? true : false));
$tpl->assign('cronLastExecution', formatTime(getConfig('cron:execution.cron', 0)));
$tpl->assign('cronLastExecutionBool', ($cronLastExecutionBool = (getConfig('cron:execution.cron', 0) > time()-150) ? true : false));
$tpl->assign('cronLastExecutionLog', formatTime($lastExecutionLog[0]));
@@ -52,4 +52,4 @@ $tpl->assign('cronCharacterEncodingBool', ($cronCharacterEncodingBool = trim(exe
$tpl->assign('cronError', ($cronMatch !== 1) ? 1 : (($cronPHPCLI !== true || $cronLastExecutionBool !== true || $cronLastExecutionLogBool !== true || $cronPermissionBool !== true || $cronUserGroupBool !== true || $cronCharacterEncodingBool !== true ) ? 2 : 0));
$tpl->draw('settings/troubleshooting');
?>
?>

View File

@@ -1,6 +1,6 @@
<?php
if (PHP_SAPI != 'cli') exit();
define('PICONTROL', true);
const PICONTROL = true;
$doNotCheckForAuthentification = true;
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
@@ -13,4 +13,3 @@ $log->setFile(LOG_PATH.'statistic/coretemp.csv');
$log->setLimit(2016);
$log->add(array(time(), rpi_getCoreTemprature()));
$log->close();
?>

View File

@@ -1,6 +1,6 @@
<?php
if (PHP_SAPI != 'cli') exit();
define('PICONTROL', true);
const PICONTROL = true;
$doNotCheckForAuthentification = true;
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
@@ -22,7 +22,7 @@ foreach ($fileArray as $file)
{
$timeOfFile = str_replace('-', '', substr($file, 0, 2));
$rest = date('i', time()) % $timeOfFile;
if (is_numeric($rest) && $rest == 0)
{
exec('/usr/bin/php -f "'.CRON_PATH.$file.'"');
@@ -31,6 +31,5 @@ foreach ($fileArray as $file)
}
}
if (trim(exec('dpkg -s php5-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.0-cli | grep Status: ')) || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '')
if (trim(exec('dpkg -s php7.0-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '')
setConfig('cron:execution.cron', time());
?>

View File

@@ -10,7 +10,7 @@ if (!isset($config))
'ssh_ip' => '127.0.0.1'
),
'version' => array(
'version' => '2.1.2',
'version' => '2.2.0beta',
'versioncode' => 29,
'android_comp_level' => 25
),
@@ -63,7 +63,7 @@ function myErrorHandler($code, $msg, $file, $line)
{
global $errorHandler;
$errorHandler[] = 'Fehler ['.$code.']: '.$msg.' in der Datei '.$file.', Zeile '.$line;
if (isset($_COOKIE['debug']) && $_COOKIE['debug'] == 'debug_mode')
return false;
else
@@ -81,4 +81,4 @@ if (isset($_COOKIE['debug'], $_GET['s']) && $_COOKIE['debug'] == 'debug_mode')
if (!isset($doNotCheckForAuthentification))
(include LIBRARY_PATH.'main/authentification.php') or die('Nicht gefunden!');
?>
?>

View File

@@ -5,27 +5,27 @@ class API
{
// Startzeit
private $startTime = 0;
// Statuscode
private $status = 200;
// Daten
private $dataArray = array();
// Fehler
private $error = array();
/**
* Konstrukter, welcher die Startzeit für die Lauftzeit festlegt.
*
* <code>$api = new API;</code>
*/
function __construct()
{
$this->startTime = microtime(true);
}
/**
* Fügt ein Element hinzu.
*
@@ -35,20 +35,20 @@ class API
* @param string|array|bool $value Wert
* @return bool
*/
public function addData($key, $value)
{
if (!empty($this->error))
return false;
$dummyStatus = $this->status;
$this->status = 500;
if (($key = trim($key)) == '')
return false;
$splits = explode('.', $key);
switch (count($splits))
{
case 1:
@@ -69,12 +69,12 @@ class API
default:
return false;
}
$this->status = $dummyStatus;
return true;
}
/**
* Setzt den Statuscode.
*
@@ -83,17 +83,17 @@ class API
* @param int $status Statuscode
* @return bool
*/
public function setStatus($status)
{
if (!is_int($status))
return false;
$this->status = $status;
return true;
}
/**
* Setzt eine Fehlermeldung.
*
@@ -104,26 +104,26 @@ class API
* @param int $status Statuscode
* @return bool
*/
public function setError($type, $message, $status = 500)
{
if (($type = trim($type)) == '')
return false;
if (($message = trim($message)) == '')
return false;
if (!is_int($status))
return false;
header('HTTP/1.0 '.$status);
$this->error = array('type' => $type, 'message' => $message);
$this->status = $status;
return true;
}
/**
* Erzeugt das fertige JSON und gibt dieses anschließend aus.
*
@@ -132,19 +132,18 @@ class API
* @param bool $prettyPrint Eingerückte Ausgabe des JSON
* @return bool Ausgabe erfolgt mit "echo".
*/
public function display($prettyPrint = false)
{
header('Content-Type: application/json');
$executionTime = microtime(true) - $this->startTime;
if (empty($this->error))
echo json_encode(array('data' => $this->dataArray, 'executionTime' => $executionTime, 'status' => $this->status), ($prettyPrint != false) ? JSON_PRETTY_PRINT : 0);
else
echo json_encode(array('error' => $this->error, 'executionTime' => $executionTime, 'status' => $this->status), ($prettyPrint != false) ? JSON_PRETTY_PRINT : 0);
return true;
}
}
?>

View File

@@ -5,19 +5,19 @@ function getCacheList()
{
$fileSuffix = '.cache.php';
$cacheArray = array('usb_devices' => array(), 'users' => array(), 'weather' => array());
foreach ($cacheArray as $name => $info)
{
$cacheArray[$name]['active'] = (getConfig('cache:activation.'.$name, 'false') == 'true') ? true : false;
$cacheArray[$name]['lifetime'] = getConfig('cache:lifetime.'.$name, 0);
if (file_exists(CACHE_PATH.$name.$fileSuffix) && is_file(CACHE_PATH.$name.$fileSuffix))
{
$cacheArray[$name]['filesize'] = filesize(CACHE_PATH.$name.$fileSuffix);
$cacheArray[$name]['modification'] = filemtime(CACHE_PATH.$name.$fileSuffix);
}
}
return $cacheArray;
}
@@ -35,4 +35,3 @@ function getCacheName($file)
return $file;
}
}
?>

View File

@@ -17,53 +17,53 @@ function rpi_getHostAddr()
{
if (!isset($_SERVER['SERVER_ADDR']))
return 'unknown';
if (!$ip = $_SERVER['SERVER_ADDR'])
return gethostbyname($this->getHostname());
return $ip;
}
function rpi_getCoreTemprature()
{
$file = 85000;
while ($file == 85000)
$file = @shell_exec('cat /sys/class/thermal/thermal_zone0/temp');
if ($file != false)
return round((trim($file)/1000), 2);
return 0;
}
function rpi_getCpuClock()
{
$file = shell_exec('cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq');
if ($file !== false)
return (int) round(trim($file)/1000);
return 0;
}
function rpi_getCpuMinClock()
{
$file = shell_exec('cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq');
if ($file !== false)
return (int) round(trim($file)/1000);
return 0;
}
function rpi_getCpuMaxClock()
{
$file = shell_exec('cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq');
if ($file !== false)
return (int) round(trim($file)/1000);
return 0;
}
@@ -71,10 +71,10 @@ function rpi_getCPUType()
{
$file = shell_exec('cat /proc/cpuinfo');
preg_match('#Hardware\s*:\s*([^\s]+)#i', $file, $match);
if (isset($match[1]))
return $match[1];
return NULL;
}
@@ -87,69 +87,69 @@ function rpi_getCpuModel()
function rpi_getCPULoad($accurate = false, $mulitcore = false)
{
$return = NULL;
if ($accurate === true)
$file = shell_exec('cat /proc/stat; sleep 2; echo "##--##"; cat /proc/stat');
else
$file = shell_exec('cat /proc/stat; sleep 0.5; echo "##--##"; cat /proc/stat');
$file = explode('##--##', $file);
if (!isset($file[0], $file[1]))
return NULL;
preg_match_all('/^cpu[0-9]?(.*)$/im', $file[0], $prevCPUStrings);
preg_match_all('/^cpu[0-9]?(.*)$/im', $file[1], $curCPUStrings);
for ($i = 0; $i < count($prevCPUStrings[0]); $i++)
{
$prevCPU = preg_split('/\s+/', $prevCPUStrings[0][$i]);
$curCPU = preg_split('/\s+/', $curCPUStrings[0][$i]);
if ($prevCPU[0] != 'cpu' && $mulitcore == false)
break;
if (!isset($prevCPU[0], $curCPU[1]) || count($prevCPU) != 11 || count($curCPU) != 11)
return NULL;
$prevIdle = $prevCPU[4] + $prevCPU[5];
$curIdle = $curCPU[4] + $curCPU[5];
$prevNonIdle = $prevCPU[1] + $prevCPU[2] + $prevCPU[3] + $prevCPU[6] + $prevCPU[7] + $prevCPU[8];
$curNonIdle = $curCPU[1] + $curCPU[2] + $curCPU[3] + $curCPU[6] + $curCPU[7] + $curCPU[8];
$prevTotal = $prevIdle + $prevNonIdle;
$curTotal = $curIdle + $curNonIdle;
$total = $curTotal - $prevTotal;
$idle = $curIdle - $prevIdle;
if ($mulitcore == true)
$return[$prevCPU[0]] = (int) round(($total - $idle) / $total * 100);
else
$return = (int) round(($total - $idle) / $total * 100);
}
return $return;
}
function rpi_getDistribution()
{
$distribution = trim(@shell_exec('cat /etc/issue | cut -d " " -f 1-3'));
if ($distribution == '')
{
$distributionString = @shell_exec('cat /etc/*-release | grep PRETTY_NAME');
preg_match('/.*="([\w\s\d\/]*).*"/i', $distributionString, $match);
if (count($match) == 2)
$distribution = trim($match[1]);
else
$distribution = _t('Unbekannt');
}
return $distribution;
}
@@ -174,7 +174,7 @@ function rpi_getCountInstalledPackages()
function rpi_getInstalledPackages()
{
@exec('dpkg -l | grep ^ii', $packages);
$packages = array_map(function($package) { return preg_split('/[\s]+/', $package, 5); }, $packages);
return $packages;
}
@@ -199,14 +199,14 @@ function rpi_getRpiRevision()
$revision[19] = array('revision' => '0013', 'model' => 'B+', 'pcb' => '1.2', 'memory' => 512, 'manufacturer' => 'Embest');
$revision[20] = array('revision' => '0014', 'model' => 'Compute Module', 'pcb' => '1.0', 'memory' => 512, 'manufacturer' => 'Embest');
$revision[21] = array('revision' => '0015', 'model' => 'A+', 'pcb' => '1.1', 'memory' => 256, 'manufacturer' => 'Embest');
$revision_model = array(0 => 'A', 1 => 'B', 2 => 'A+', 3 => 'B+', 4 => 'Pi 2 B', 5 => 'Alpha', 6 => 'Compute Module', 7 => 'Zero', 8 => 'Pi 3 B', 9 => 'Zero', 10 => 'Compute Module 3', 12 => 'Zero W');
$revision_memory = array(0 => 256, 1 => 512, 2 => 1024);
$revision_manufacturer = array(0 => 'Sony', 1 => 'Egoman', 2 => 'Embest', 3 => 'Sony Japan', 4 => 'Embest');
$file = shell_exec('cat /proc/cpuinfo');
preg_match('#\nRevision\s*:\s*([\da-f]+)#i', $file, $match);
/*
* ######
* |||||+- PCB
@@ -216,12 +216,12 @@ function rpi_getRpiRevision()
* |+- Manufacturer
* +- Memory
*/
if (isset($match[1]))
{
if ($match[1][0] == '1' || $match[1][0] == '2')
$match[1] = substr($match[1], 1);
if (strlen($match[1]) == 4)
return $revision[hexdec($match[1])];
elseif (strlen($match[1]) == 6 && $match[1][0] != 'a' && $match[1][0] != '9')
@@ -235,7 +235,7 @@ function rpi_getRpiRevision()
'manufacturer' => $revision_manufacturer[hexdec(substr($match[1], 1, 1))]);
}
}
return NULL;
}
@@ -243,7 +243,7 @@ function rpi_getRpiSerial()
{
$file = shell_exec('cat /proc/cpuinfo');
preg_match('#\nSerial\s*:\s*([\da-f]+)#i', $file, $match);
return $match[1];
}
@@ -256,7 +256,7 @@ function rpi_getMemorySplit()
$config = @shell_exec('cat /boot/config.txt');
preg_match('#gpu_mem=([0-9]+)#i', $config, $match);
$total = intval($match[1]);
if ($total == 16)
return array('system' => '496 MiB', 'video' => '16 MiB');
elseif ($total == 32)
@@ -265,38 +265,38 @@ function rpi_getMemorySplit()
return array('system' => '448 MiB', 'video' => '64 MiB');
elseif ($total == 128)
return array('system' => '384 MiB', 'video' => '128 MiB');
return array('system' => '256 MiB', 'video' => '256 MiB');
}
// 256 MB
$mem = $this->getMemoryUsage();
$total = round($mem['total'] / 1024 / 1024, 0);
if ($total <= 128)
return array('system' => '128 MiB', 'video' => '128 MiB');
elseif ($total > 128 && $total <= 192)
return array('system' => '192 MiB', 'video' => '64 MiB');
elseif ($total > 192 && $total <= 224)
return array('system' => '224 MiB', 'video' => '32 MiB');
return array('system' => '240 MiB', 'video' => '16 MiB');
}
function rpi_getMemoryUsage()
{
exec('free -bo 2>/dev/null || free -b', $data);
if (strpos($data[0], 'available') !== false) {
list($type, $total, $used, $free, $shared, $buffers, $available) = preg_split('#\s+#', $data[1]);
$usage = (int) round(($total - $available) / $total * 100);
return array('percent' => $usage, 'total' => $total, 'free' => $available, 'used' => ($total - $available));
}
list($type, $total, $used, $free, $shared, $buffers, $cached) = preg_split('#\s+#', $data[1]);
$usage = (int) round(($used - $buffers - $cached) / $total * 100);
return array('percent' => $usage, 'total' => $total, 'free' => ($free + $buffers + $cached), 'used' => ($used - $buffers - $cached));
}
@@ -305,7 +305,7 @@ function rpi_getSwapUsage()
exec('free -bo 2>/dev/null || free -b', $data);
list($type, $total, $used, $free) = preg_split('#\s+#', $data[2]);
$usage = (int) round($used / $total * 100);
return array('percent' => $usage, 'total' => $total, 'free' => $free, 'used' => $used);
}
@@ -314,28 +314,28 @@ function multiArraySearch($array, $key, $value)
foreach ($array as $item)
if (isset($item[$key]) && $item[$key] == $value)
return true;
return false;
}
function rpi_getMemoryInfo()
{
exec('df -lT | grep -vE "tmpfs|rootfs|Filesystem|Dateisystem"', $data);
$devices = array();
$totalSize = 0;
$usedSize = 0;
foreach ($data as $row)
{
list($device, $type, $blocks, $use, $available, $used, $mountpoint) = preg_split('#[\s%]+#i', $row);
if (multiArraySearch($devices, 'device', $device) === false)
{
$totalSize += $blocks * 1024;
$usedSize += $use * 1024;
}
$devices[] = array(
'device' => $device,
'type' => $type,
@@ -346,14 +346,14 @@ function rpi_getMemoryInfo()
'mountpoint' => $mountpoint
);
}
usort($devices, function($a, $b)
{
return strcasecmp($a['device'], $b['device']);
});
$devices[] = array('total' => $totalSize, 'used' => $usedSize, 'free' => $totalSize - $usedSize, 'percent' => (int) round(($usedSize * 100 / $totalSize)));
return $devices;
}
@@ -361,17 +361,17 @@ function rpi_getUsbDevices()
{
exec('lsusb', $data);
$devices = array();
foreach ($data as $row)
{
preg_match('#[0-9a-f]{4}:[0-9a-f]{4}\s+(.+)#i', $row, $match);
if (count($match) == 2)
$devices[] = trim($match[1]);
else
$devices[] = '<'._t('Unbekannt').'>';
}
return $devices;
}
@@ -393,33 +393,33 @@ function rpi_getAllUsers()
call_user_func_array('array_multisort', $args);
return array_pop($args);
}
exec('/usr/bin/who --ips', $dataLoggedIn);
exec('/usr/bin/lastlog | grep -vE "Benutzername|Username" | cut -f 1 -d " "', $dataAllUsers);
$usersLoggedIn = array();
$usersAll = array();
foreach ($dataLoggedIn as $row)
{
$split = preg_split('/\s+/i', $row);
if (count($split) == 6)
$usersLoggedIn[$split[0]][] = array('port' => $split[1], 'lastLogin' => strtotime($split[2].' '.$split[3].' '.$split[4]), 'lastLoginAddress' => $split[5]);
}
foreach ($dataAllUsers as $row)
{
$userLastLoginInformation = '';
$userLastLoginInformation = shell_exec('/usr/bin/last -i -f /var/log/wtmp | grep -m 1 "^'.$row.' "');
if ($userLastLoginInformation == '')
$userLastLoginInformation = shell_exec('/usr/bin/last -i -f /var/log/wtmp.1 | grep -m 1 "^'.$row.' "');
if ($userLastLoginInformation != '')
{
$split = preg_split('/\s+/i', $userLastLoginInformation);
$usersAll[] = array('username' => $row,
'userId' => exec('id -u '.escapeshellarg($row)),
'groupId' => exec('id -g '.escapeshellarg($row)),
@@ -440,9 +440,9 @@ function rpi_getAllUsers()
'isLoggedIn' => isset($usersLoggedIn[$row]) ? true : false);
}
}
$usersAll = array_orderby($usersAll, 'isLoggedIn', SORT_DESC, 'username', SORT_ASC);
return $usersAll;
}
?>
?>

File diff suppressed because it is too large Load Diff

View File

@@ -4,133 +4,129 @@ if (!defined('PICONTROL')) exit();
class LogStatistic
{
private $file, $stream, $limit = -1, $length = 100;
function __destruct()
{
if (is_resource($this->stream))
fclose($this->stream);
}
public function setFile($pFile = '')
{
$this->file = $pFile;
}
public function setLimit($pLimit = -1)
{
$this->limit = $pLimit;
}
public function setLength($pLength = 100)
{
$this->length = $pLength;
}
public function add($entry, $moreThanOne = false)
{
if (!is_array($entry) || empty($entry))
return false;
if (!is_resource($this->stream))
$this->open();
if ($this->limit > -1)
$this->shortLog();
fseek($this->stream, 0, SEEK_END);
if ($moreThanOne === false)
fputcsv($this->stream, $entry);
else
{
else {
foreach ($entry as $item)
fputcsv($this->stream, $item);
}
return true;
}
public function getAll()
{
if (!is_resource($this->stream))
$this->open();
$entries = array();
fseek($this->stream, 0);
while (($entry = fgetcsv($this->stream, $this->length)) !== false)
$entries[] = $entry;
return $entries;
}
public function getLast()
{
if (!is_resource($this->stream))
$this->open();
$entries = $this->getAll();
if (is_array($entries))
return end($entries);
}
private function shortLog()
{
if ($this->limit == -1)
return false;
if (!is_array(($entries = $this->getAll())))
return false;
if (count($entries) >= $this->limit)
{
if (count($entries) >= $this->limit) {
$unsetLineCount = count($entries) - $this->limit;
for ($i = 0; $i <= $unsetLineCount; $i++)
unset($entries[$i]);
fseek($this->stream, 0);
ftruncate($this->stream, 0);
foreach ($entries as $entry)
fputcsv($this->stream, $entry);
}
return true;
}
public function deleteLog()
{
if (is_file($this->file))
{
if (is_file($this->file)) {
if (unlink($this->file) or exit(_t('Konnte Log-Datei nicht l&ouml;schen: %s', $this->file)))
return true;
}
else
} else
return false;
}
public function clearLog()
{
if (!is_resource($this->stream))
$this->open();
fseek($this->stream, 0);
ftruncate($this->stream, 0);
}
public function close()
{
fclose($this->stream);
}
private function open()
{
if (!file_exists($this->file) || !is_file($this->file))
touch($this->file);
$this->stream = fopen($this->file, 'r+') or exit(_t('Konnte Log-Datei nicht &ouml;ffnen: %s', $this->file));
}
}
@@ -138,107 +134,104 @@ class LogStatistic
class StatisticController
{
private $statistics = array();
public function __construct($tpl = NULL)
{
if (!isset($tpl))
return;
$jsTranslations = array();
$jsTranslations[] = 'Es sind noch keine Werte verf&uuml;gbar. Werte werden alle %%s Minuten eingetragen.';
$jsTranslations[] = 'Es ist ein Fehler aufgetreten! Fehler: %%s';
$jsTranslations[] = 'Zeit';
$jsTranslations[] = 'Es ist ein Fehler aufgetreten! Fehlercode: %%s';
$tpl->assign('jsTranslations', $jsTranslations, true);
}
public function loadStatistics($folder = NULL)
{
$files = array();
if ($folder == NULL)
$possibleFolders = array(LOG_PATH);
else
$possibleFolders = array(LOG_PATH.$folder);
while (list($key, $folder) = each($possibleFolders))
{
foreach (@scandir($folder) as $file)
{
if ($file[0] != '.')
{
if (is_file($folder.'/'.$file) && substr($file, -4) == '.csv')
{
$fileName = str_replace(LOG_PATH, '', $folder).substr($file, 0, -4);
$this->statistics[substr(md5($fileName), 0, 8)] = $fileName;
}
elseif (is_dir($folder.$file))
$possibleFolders[] = $folder.$file.'/';
}
}
$possibleFolders = array(LOG_PATH . $folder);
foreach ($possibleFolders as $folder) {
$this->statistics = array_merge($this->statistics, $this->loadStatisticsIterator($folder));
}
}
private function loadStatisticsIterator($folder)
{
$fileNames = array();
$files = array_diff(@scandir($folder), array('..', '.'));
foreach ($files as $file) {
$absolutePath = $folder . '/' . $file;
if (is_file($absolutePath) && substr($file, -4) == '.csv') {
$fileName = str_replace(LOG_PATH, '', $folder) . substr($file, 0, -4);
$fileNames[substr(md5($fileName), 0, 8)] = $fileName;
} elseif (is_dir($absolutePath))
$fileNames = array_merge($fileNames, $this->loadStatisticsIterator($folder . $file . '/'));
}
return $fileNames;
}
public function getStatisticID($name)
{
if (empty($this->statistics))
$this->loadStatistics();
if (!is_string($name))
return false;
if (($id = array_search($name, $this->statistics)) !== false)
return $id;
return false;
}
public function getStatisticName($id)
{
if (empty($this->statistics))
$this->loadStatistics();
if (!is_string($id))
return false;
if (isset($this->statistics[$id]))
return $this->statistics[$id];
return false;
}
public function checkStatistic($value, $isID = false)
{
if (!is_string($value))
return false;
if (!is_bool($isID))
return false;
if ($isID === true)
{
if ($isID === true) {
if ($this->getStatisticName($value) !== false)
return true;
else
return false;
}
elseif ($isID === false)
{
} elseif ($isID === false) {
if ($this->getStatisticID($value) !== false)
return true;
else
return false;
}
return false;
}
public function getStatistics()
{
if (empty($this->statistics))
$this->loadStatistics();
return $this->statistics;
}
}
@@ -246,46 +239,43 @@ class StatisticController
class StatisticBuilder
{
private $name, $columns, $title, $prefix, $suffix, $raw, $label, $unit, $cycle, $limits;
public function loadFromFile($name, $plugin = NULL)
{
$source = LIBRARY_PATH.'statistic/statistic.config.php';
$source = LIBRARY_PATH . 'statistic/statistic.config.php';
if ($plugin != NULL && is_string($plugin))
$source = PLUGINS_PATH.$plugin.'/plugin.statistic.config.php';
$source = PLUGINS_PATH . $plugin . '/plugin.statistic.config.php';
if (!file_exists($source) || !is_file($source))
return false;
include $source;
if (!isset($statisticConfig) || !is_array($statisticConfig))
return false;
$this->raw = $name;
if (strpos($name, '/') !== false)
{
if (strpos($name, '/') !== false) {
$explodes = explode('/', strrev($name), 2);
$name = strrev($explodes[0]);
$prefix = strrev($explodes[1]).'/';
$prefix = strrev($explodes[1]) . '/';
}
if (!isset($statisticConfig[$name]) && isset($statisticConfig[substr($name, 0, strpos($name, '_'))]))
{
if (strpos($name, '_') !== false)
{
if (!isset($statisticConfig[$name]) && isset($statisticConfig[substr($name, 0, strpos($name, '_'))])) {
if (strpos($name, '_') !== false) {
$explodes = explode('_', strrev($name), 2);
$suffix = strrev($explodes[0]);
$name = strrev($explodes[1]);
}
}
if (!isset($statisticConfig[$name]))
return false;
$statistic = $statisticConfig[$name];
$this->name = $name;
$this->title = _t($statistic['title']);
$this->prefix = isset($prefix) ? $prefix : '';
@@ -294,70 +284,68 @@ class StatisticBuilder
$this->unit = $statistic['unit'];
$this->cycle = $statistic['cycle'];
$this->limits = $statistic['limits'];
foreach ($statistic['columns'] as $column)
{
foreach ($column as &$values)
{
foreach ($statistic['columns'] as $column) {
foreach ($column as &$values) {
if (is_string($values))
$values = _t($values);
}
$this->columns[] = $column;
}
if (substr_count($this->title, '%s') == 1) {
$this->title = sprintf($this->title, $this->suffix);
}
if ($this->title == '')
$this->title = $this->suffix;
return true;
}
public function setTitle($title)
{
if (!is_string($title))
return false;
$this->title = $title;
}
public function getId()
{
return substr(md5($this->raw), 0, 8);
}
public function getArray()
{
return array(
'id' => $this->getId(),
'name' => $this->name,
'title' => $this->title,
'prefix' => $this->prefix,
'suffix' => $this->suffix,
'raw' => $this->raw,
'label' => $this->label,
'unit' => $this->unit,
'cycle' => $this->cycle,
'columns' => $this->columns,
'limits' => $this->limits
);
'id' => $this->getId(),
'name' => $this->name,
'title' => $this->title,
'prefix' => $this->prefix,
'suffix' => $this->suffix,
'raw' => $this->raw,
'label' => $this->label,
'unit' => $this->unit,
'cycle' => $this->cycle,
'columns' => $this->columns,
'limits' => $this->limits
);
}
public function getJSON()
{
$json = json_encode(array(
'id' => $this->getId(),
'label' => $this->label,
'unit' => $this->unit,
'cycle' => $this->cycle,
'columns' => $this->columns
)
);
$json = json_encode(
array(
'id' => $this->getId(),
'label' => $this->label,
'unit' => $this->unit,
'cycle' => $this->cycle,
'columns' => $this->columns
)
);
return $json;
}
}
?>

View File

@@ -1,5 +1,5 @@
<?php
define('PICONTROL', true);
const PICONTROL = true;
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
(include_once LIBRARY_PATH.'main/tpl.class.php') or die('Error: 0x0001');
@@ -18,10 +18,10 @@ $updateStatus = $updateController->fetchData();
if ($updateStatus === true) {
$nextUpdate = $updateController->getNextUpdate();
if ($nextUpdate instanceof Update) {
$downloadStatus = $updateController->download($nextUpdate);
if ($downloadStatus === true) {
$tpl->redirect('?s=settings&do=update&complete');
} elseif ($downloadStatus === 10) {
@@ -41,4 +41,4 @@ if ($updateStatus === true) {
if (isset($errorMsg)) {
$tpl->assign('content', '<div class="inner-header"><span>'._t('Aktualisierung').'</span></div><div class="inner red">'.$errorMsg.'</div><div class="inner-end"><a href="?s=settings&amp;do=update" class="button">'._t('Zur&uuml;ck zur Aktualisierung').'</a></div>');
$tpl->draw('single_box');
}
}