diff --git a/api/v1/statistic.php b/api/v1/statistic.php index 8d25664..db36119 100644 --- a/api/v1/statistic.php +++ b/api/v1/statistic.php @@ -8,73 +8,94 @@ const PICONTROL = true; (include_once LIBRARY_PATH . 'api/api.class.php') or die('Error: 0x0004'); (include_once LIBRARY_PATH . 'plugin/plugin.function.php') or die('Error: 0x0005'); -$api = new API; +$requestMethod = $_SERVER["REQUEST_METHOD"]; -if (isset($_POST['id'])) { - $controller = new StatisticController(); - $controller->loadStatistics(); - - if (($name = $controller->getStatisticName($_POST['id'])) !== false) { - if (isset($_POST['plugin']) && trim($_POST['plugin']) != '') - pluginLanguage(trim($_POST['plugin'])); - - $builder = new StatisticBuilder(); - $builder->loadFromFile($name, (isset($_POST['plugin']) && trim($_POST['plugin']) != '') ? $_POST['plugin'] : NULL); - $statistic = $builder->getArray(); - - $log = new LogStatistic(); - $log->setFile(LOG_PATH . $statistic['raw'] . '.csv'); - $logData = $log->getAll(); - - $arr = $info = array(); - - foreach ($statistic['columns'] as $column) { - $arr['cols'][] = array('id' => '', 'label' => _t($column['label']), 'type' => $column['type']); +if ($requestMethod == 'GET') { + $log = new LogStatistic(); + $log->setFile(LOG_PATH . 'statistic/' . $_GET['statistic'] . '.csv'); + $data = array(); + $data['data'] = array(); + $limit = 2016; + if (isset($_GET['limit'])) { + $limit = $_GET['limit']; + } + $i = 0; + foreach ($log->getAll() as $row) { + if ($i >= 2016 - $limit) { + array_push($data['data'], array('time' => (int)$row[0], 'value' => (float)$row[1])); } + $i++; + } + echo json_encode($data); +} else { + $api = new API; - getRowsFromLog($arr, $info, $logData, $statistic['columns'], $statistic['cycle']); + if (isset($_POST['id'])) { + $controller = new StatisticController(); + $controller->loadStatistics(); - if (isset($arr['rows'])) { - if (isset($_POST['type']) && $_POST['type'] == 'googleChart') - $arr['rows'] = convertForGoogleChart($arr['rows']); + if (($name = $controller->getStatisticName($_POST['id'])) !== false) { + if (isset($_POST['plugin']) && trim($_POST['plugin']) != '') + pluginLanguage(trim($_POST['plugin'])); - $arr['rows'] = array_slice($arr['rows'], -2016); - $arr['periods'] = $info['periods']; + $builder = new StatisticBuilder(); + $builder->loadFromFile($name, (isset($_POST['plugin']) && trim($_POST['plugin']) != '') ? $_POST['plugin'] : NULL); + $statistic = $builder->getArray(); - foreach (array('min', 'max') as $type) { - if ($statistic['limits'][$type]['use'] == 'multiply') - $arr[$type] = round($info[$type] * $statistic['limits'][$type]['value']); - elseif ($statistic['limits'][$type]['use'] == 'fix') { - if ($statistic['limits'][$type]['fix'] == true) - $arr[$type] = $statistic['limits'][$type]['value']; - else - $arr[$type] = round($info[$type]); - } + $log = new LogStatistic(); + $log->setFile(LOG_PATH . $statistic['raw'] . '.csv'); + $logData = $log->getAll(); + + $arr = $info = array(); + + foreach ($statistic['columns'] as $column) { + $arr['cols'][] = array('id' => '', 'label' => _t($column['label']), 'type' => $column['type']); } - $api->addData('statistic', $arr); + getRowsFromLog($arr, $info, $logData, $statistic['columns'], $statistic['cycle']); + + if (isset($arr['rows'])) { + if (isset($_POST['type']) && $_POST['type'] == 'googleChart') + $arr['rows'] = convertForGoogleChart($arr['rows']); + + $arr['rows'] = array_slice($arr['rows'], -2016); + $arr['periods'] = $info['periods']; + + foreach (array('min', 'max') as $type) { + if ($statistic['limits'][$type]['use'] == 'multiply') + $arr[$type] = round($info[$type] * $statistic['limits'][$type]['value']); + elseif ($statistic['limits'][$type]['use'] == 'fix') { + if ($statistic['limits'][$type]['fix'] == true) + $arr[$type] = $statistic['limits'][$type]['value']; + else + $arr[$type] = round($info[$type]); + } + } + + $api->addData('statistic', $arr); + } else + $api->setError('error', 'Empty data.'); } else - $api->setError('error', 'Empty data.'); - } else - $api->setError('error', 'Data not found.'); -} else { - $statistics = array(); - $hiddenStatistics = unserialize(htmlspecialchars_decode(getConfig('main:statistic.hidden', 'a:0:{}'))); + $api->setError('error', 'Data not found.'); + } else { + $statistics = array(); + $hiddenStatistics = unserialize(htmlspecialchars_decode(getConfig('main:statistic.hidden', 'a:0:{}'))); - $controller = new StatisticController(); - $controller->loadStatistics(); + $controller = new StatisticController(); + $controller->loadStatistics(); - foreach ($controller->getStatistics() as $statistic) { - $builder = new StatisticBuilder(); - $builder->loadFromFile($statistic); + foreach ($controller->getStatistics() as $statistic) { + $builder = new StatisticBuilder(); + $builder->loadFromFile($statistic); - $array = $builder->getArray(); - if (!in_array($builder->getId(), $hiddenStatistics)) - $statistics[] = array('array' => $array); + $array = $builder->getArray(); + if (!in_array($builder->getId(), $hiddenStatistics)) + $statistics[] = array('array' => $array); + } + + $api->addData('statistics', $statistics); + $api->addData('hidden', $hiddenStatistics); } - $api->addData('statistics', $statistics); - $api->addData('hidden', $hiddenStatistics); + $api->display(); } - -$api->display(); diff --git a/install/resources/content/install_requirement.php b/install/resources/content/install_requirement.php index 1544dff..a491007 100644 --- a/install/resources/content/install_requirement.php +++ b/install/resources/content/install_requirement.php @@ -1,13 +1,13 @@ setHeaderTitle(_t('Anforderungen')); // PHP $phpVersion = array('version' => PHP_VERSION, 'status' => false); -$phpSSH = array('status' => false); +$phpSSH = array('status' => true); $phpMcrypt = array('status' => false); $phpCLI = array('status' => false); $phpCURL = array('status' => false); @@ -15,7 +15,7 @@ $phpZipArchive = array('status' => false); $phpAllowUrlFopen = array('status' => false); $filesFoldersExist = array('count' => 0, 'status' => true); $filesFoldersPermission = array('count' => 0, 'status' => true); -$otherDistribution = array('version' => rpi_getDistribution(), 'status' => false); +$otherDistribution = array('version' => rpi_getDistribution(), 'status' => true); $otherCookie = array('status' => false); $error = false; @@ -28,7 +28,7 @@ if (extension_loaded('ssh2')) #if (function_exists('mcrypt_encrypt') !== false) # $phpMcrypt['status'] = true; -if (trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.4-cli | grep Status: ')) != '') +if (trim(exec('dpkg -s php-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.4-cli | grep Status: ')) != '' || trim(exec('dpkg -s php8.0-cli | grep Status: ')) != '' || trim(exec('dpkg -s php8.1-cli | grep Status: ')) != '' || trim(exec('dpkg -s php8.2-cli | grep Status: ')) != '') $phpCLI['status'] = true; if (function_exists('curl_init') !== false) @@ -43,18 +43,14 @@ if (ini_get('allow_url_fopen') !== false) // Dateien und Ordner $filesFolders = fileFolderPermission(); -foreach ($filesFolders as $file => $info) -{ - if ($info['error'] === true) - { - if ($info['existsBool'] === false || $info['filesizeBool'] === false) - { +foreach ($filesFolders as $file => $info) { + if ($info['error'] === true) { + if ($info['existsBool'] === false || $info['filesizeBool'] === false) { $filesFoldersExist['count'] += 1; $filesFoldersExist['status'] = false; } - if ($info['permissionBool'] === false || $info['userGroupBool'] === false) - { + if ($info['permissionBool'] === false || $info['userGroupBool'] === false) { $filesFoldersPermission['count'] += 1; $filesFoldersPermission['status'] = false; } @@ -62,8 +58,8 @@ foreach ($filesFolders as $file => $info) } // Sonstiges -if ($otherDistribution['version'] == 'Raspbian GNU/Linux 10' || $otherDistribution['version'] == 'Raspbian GNU/Linux 11' || $otherDistribution['version'] == 'Debian GNU/Linux 11') - $otherDistribution['status'] = true; +//if ($otherDistribution['version'] == 'Raspbian GNU/Linux 10' || $otherDistribution['version'] == 'Raspbian GNU/Linux 11' || $otherDistribution['version'] == 'Debian GNU/Linux 11') +// $otherDistribution['status'] = true; if (isset($_COOKIE['_pi-control_install_language']) && $_COOKIE['_pi-control_install_language'] != '') $otherCookie['status'] = true; @@ -87,8 +83,7 @@ $tpl->assign('filesFoldersPermission', $filesFoldersPermission); $tpl->assign('otherDistribution', $otherDistribution); $tpl->assign('otherCookie', $otherCookie); $tpl->assign('error', $error); -$tpl->assign('langUrl', (isset($_GET['lang']) && $_GET['lang'] != '') ? '&lang='.$_GET['lang'] : ''); +$tpl->assign('langUrl', (isset($_GET['lang']) && $_GET['lang'] != '') ? '&lang=' . $_GET['lang'] : ''); $tpl->assign('configHelp', $config['url']['help']); $tpl->draw('install_requirement'); -?> diff --git a/install/resources/library/main/tpl.class.php b/install/resources/library/main/tpl.class.php index 5a6248f..84af9c9 100644 --- a/install/resources/library/main/tpl.class.php +++ b/install/resources/library/main/tpl.class.php @@ -650,7 +650,7 @@ class PiTpl * @return bool */ - public function msg($type, $title = NULL, $msg, $cancelable = true, $id = 0) + public function msg($type, $msg, $title = NULL, $cancelable = true, $id = 0) { if (!strlen($type) > 0 || !is_string($type) || !strlen($msg) > 0 || !is_string($msg) @@ -943,4 +943,3 @@ class PiTpl return true; } } -?> \ No newline at end of file diff --git a/resources/cron/init.php b/resources/cron/init.php index 20c82a7..aebfb84 100644 --- a/resources/cron/init.php +++ b/resources/cron/init.php @@ -31,5 +31,5 @@ foreach ($fileArray as $file) } } -if (trim(exec('dpkg -s php7.4-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '') +if (trim(exec('dpkg -s php7.4-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '' || trim(exec('dpkg -s php8.0-cli | grep Status: ')) != '' || trim(exec('dpkg -s php8.1-cli | grep Status: ')) != '' || trim(exec('dpkg -s php8.2-cli | grep Status: ')) != '') setConfig('cron:execution.cron', time()); diff --git a/resources/init.php b/resources/init.php index 7265c8a..3d93a11 100644 --- a/resources/init.php +++ b/resources/init.php @@ -10,8 +10,8 @@ if (!isset($config)) 'ssh_ip' => '127.0.0.1' ), 'version' => array( - 'version' => '2.3.1', - 'versioncode' => 36, + 'version' => '2.3.2', + 'versioncode' => 37, 'android_comp_level' => 25 ), 'url' => array( @@ -26,20 +26,20 @@ if (!isset($config)) ); } -defined('PICONTROL_PATH') or define('PICONTROL_PATH', realpath(dirname(__FILE__).'/../').'/'); -defined('RESOURCE_PATH') or define('RESOURCE_PATH', realpath(dirname(__FILE__)).'/'); -defined('LIBRARY_PATH') or define('LIBRARY_PATH', realpath(dirname(__FILE__).'/library/').'/'); -defined('CONTENT_PATH') or define('CONTENT_PATH', realpath(dirname(__FILE__).'/content/').'/'); -defined('CONFIG_PATH') or define('CONFIG_PATH', realpath(dirname(__FILE__).'/config/').'/'); -defined('PLUGINS_PATH') or define('PLUGINS_PATH', realpath(dirname(__FILE__).'/plugins/').'/'); -defined('UPDATE_PATH') or define('UPDATE_PATH', realpath(dirname(__FILE__).'/update/').'/'); -defined('TEMPLATES_PATH') or define('TEMPLATES_PATH', realpath(dirname(__FILE__).'/../public_html/templates/').'/'); -defined('TEMPLATES2_PATH') or define('TEMPLATES2_PATH',realpath(dirname(__FILE__).'/templates/').'/'); -defined('LOG_PATH') or define('LOG_PATH', realpath(dirname(__FILE__).'/log/').'/'); -defined('CRON_PATH') or define('CRON_PATH', realpath(dirname(__FILE__).'/cron/').'/'); -defined('LANGUAGE_PATH') or define('LANGUAGE_PATH', realpath(dirname(__FILE__).'/languages/').'/'); -defined('CACHE_PATH') or define('CACHE_PATH', realpath(dirname(__FILE__).'/cache/').'/'); -defined('INSTALL_PATH') or define('INSTALL_PATH', realpath(dirname(__FILE__).'/../').'/install/'); +defined('PICONTROL_PATH') || define('PICONTROL_PATH', realpath(dirname(__FILE__).'/../').'/'); +defined('RESOURCE_PATH') || define('RESOURCE_PATH', realpath(dirname(__FILE__)).'/'); +defined('LIBRARY_PATH') || define('LIBRARY_PATH', realpath(dirname(__FILE__).'/library/').'/'); +defined('CONTENT_PATH') || define('CONTENT_PATH', realpath(dirname(__FILE__).'/content/').'/'); +defined('CONFIG_PATH') || define('CONFIG_PATH', realpath(dirname(__FILE__).'/config/').'/'); +defined('PLUGINS_PATH') || define('PLUGINS_PATH', realpath(dirname(__FILE__).'/plugins/').'/'); +defined('UPDATE_PATH') || define('UPDATE_PATH', realpath(dirname(__FILE__).'/update/').'/'); +defined('TEMPLATES_PATH') || define('TEMPLATES_PATH', realpath(dirname(__FILE__).'/../public_html/templates/').'/'); +defined('TEMPLATES2_PATH') || define('TEMPLATES2_PATH',realpath(dirname(__FILE__).'/templates/').'/'); +defined('LOG_PATH') || define('LOG_PATH', realpath(dirname(__FILE__).'/log/').'/'); +defined('CRON_PATH') || define('CRON_PATH', realpath(dirname(__FILE__).'/cron/').'/'); +defined('LANGUAGE_PATH') || define('LANGUAGE_PATH', realpath(dirname(__FILE__).'/languages/').'/'); +defined('CACHE_PATH') || define('CACHE_PATH', realpath(dirname(__FILE__).'/cache/').'/'); +defined('INSTALL_PATH') || define('INSTALL_PATH', realpath(dirname(__FILE__).'/../').'/install/'); $globalLanguage = isset($initConfig['language']) ? $initConfig['language'] : 'de'; $globalLanguageArray = array(); diff --git a/resources/library/api/StatisticController.php b/resources/library/api/StatisticController.php new file mode 100644 index 0000000..0b4ba92 --- /dev/null +++ b/resources/library/api/StatisticController.php @@ -0,0 +1,6 @@ +runtimeStart = microtime(true); $lang = $globalLanguage; - $langFile = LANGUAGE_PATH.$lang.'.php'; + $langFile = LANGUAGE_PATH . $lang . '.php'; - if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) - { + if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) { include $langFile; $globalLanguageArray = $langArray; } - foreach ($this->tplConfigs as $configFile) - { - if (file_exists(CONFIG_PATH.$configFile.$this->tplConfigSuffix) === true && is_file(CONFIG_PATH.$configFile.$this->tplConfigSuffix) === true) - $this->tplConfigArray[$configFile] = parse_ini_file(CONFIG_PATH.$configFile.$this->tplConfigSuffix, true); + foreach ($this->tplConfigs as $configFile) { + if (file_exists(CONFIG_PATH . $configFile . $this->tplConfigSuffix) === true && is_file(CONFIG_PATH . $configFile . $this->tplConfigSuffix) === true) + $this->tplConfigArray[$configFile] = parse_ini_file(CONFIG_PATH . $configFile . $this->tplConfigSuffix, true); } } @@ -173,7 +173,7 @@ class PiTpl $configPath = CONFIG_PATH; if ($this->tplFolderPathPlugin != '') - $configPath = $this->tplFolderPathPlugin.'/resources/config/'; + $configPath = $this->tplFolderPathPlugin . '/resources/config/'; if ($customFile !== NULL) $configPath = $customFile; @@ -183,11 +183,10 @@ class PiTpl if (count($file) != 2) return false; - $configFile = $configPath.$file[0].$this->tplConfigSuffix; + $configFile = $configPath . $file[0] . $this->tplConfigSuffix; $md5 = substr(md5($configFile), 0, 6); - if (!isset($this->tplConfigArray[$md5])) - { + if (!isset($this->tplConfigArray[$md5])) { if (file_exists($configFile) === true && is_file($configFile) === true) $this->tplConfigArray[$md5] = parse_ini_file($configFile, true); else @@ -222,7 +221,7 @@ class PiTpl $configPath = CONFIG_PATH; if ($this->tplFolderPathPlugin != '') - $configPath = $this->tplFolderPathPlugin.'/resources/config/'; + $configPath = $this->tplFolderPathPlugin . '/resources/config/'; if ($customFile !== NULL) $configPath = $customFile; @@ -232,11 +231,10 @@ class PiTpl if (count($file) != 2) return $default; - $configFile = $configPath.$file[0].$this->tplConfigSuffix; + $configFile = $configPath . $file[0] . $this->tplConfigSuffix; $md5 = substr(md5($configFile), 0, 6); - if (!isset($this->tplConfigArray[$md5])) - { + if (!isset($this->tplConfigArray[$md5])) { if (file_exists($configFile) === true && is_file($configFile) === true) $this->tplConfigArray[$md5] = parse_ini_file($configFile, true); else @@ -278,7 +276,7 @@ class PiTpl else return false; - return writeConfig($this->tplConfigArray[$file[0]], CONFIG_PATH.$file[0].$this->tplConfigSuffix); + return writeConfig($this->tplConfigArray[$file[0]], CONFIG_PATH . $file[0] . $this->tplConfigSuffix); } /** @@ -416,7 +414,7 @@ class PiTpl if ($this->tplLoadHeader !== true) return false; - $fileName = CONTENT_PATH.'html_header.php'; + $fileName = CONTENT_PATH . 'html_header.php'; $this->tplLoadedHeader = true; @@ -470,7 +468,7 @@ class PiTpl if ($this->tplLoadFooter !== true) return false; - $fileName = CONTENT_PATH.'html_footer.php'; + $fileName = CONTENT_PATH . 'html_footer.php'; $this->tplLoadedFooter = true; @@ -506,20 +504,18 @@ class PiTpl $folderPath = $this->tplFolderPath; if ($this->tplFolderPathPlugin != '') - $folderPath = $this->tplFolderPathPlugin.'/public_html/templates/'; + $folderPath = $this->tplFolderPathPlugin . '/public_html/templates/'; - if (strlen($tplFileName) >= 1 && is_string($tplFileName)) - { - if (file_exists($folderPath.$tplFileName.$this->tplFileSuffix) !== true || is_file($folderPath.$tplFileName.$this->tplFileSuffix) !== true) - return self::tplError(self::_t('Datei "%s" existiert nicht oder ist keine gültige Datei.', $tplFileName), __LINE__-1); + if (strlen($tplFileName) >= 1 && is_string($tplFileName)) { + if (file_exists($folderPath . $tplFileName . $this->tplFileSuffix) !== true || is_file($folderPath . $tplFileName . $this->tplFileSuffix) !== true) + return self::tplError(self::_t('Datei "%s" existiert nicht oder ist keine gültige Datei.', $tplFileName), __LINE__ - 1); } self::drawMsg(); $data = $this->tplVariables; - if (strlen($tplFileName) >= 1 && is_string($tplFileName)) - (include_once $folderPath.$tplFileName.$this->tplFileSuffix) or self::error(self::_t('Konnte Datei "%s" nicht öffnen und auslesen.', $tplFileName), __LINE__); + if (strlen($tplFileName) >= 1 && is_string($tplFileName)) (include_once $folderPath . $tplFileName . $this->tplFileSuffix) or self::error(self::_t('Konnte Datei "%s" nicht öffnen und auslesen.', $tplFileName), __LINE__); // Optisch schöner echo PHP_EOL; @@ -545,7 +541,7 @@ class PiTpl if (!strlen($errorMsg) > 0 || !is_string($errorMsg)) return false; - if (file_exists($this->tplFolderPath.'error'.$this->tplFileSuffix) !== true || is_file($this->tplFolderPath.'error'.$this->tplFileSuffix) !== true) + if (file_exists($this->tplFolderPath . 'error' . $this->tplFileSuffix) !== true || is_file($this->tplFolderPath . 'error' . $this->tplFileSuffix) !== true) return false; if ($errorCancel === true) @@ -555,7 +551,7 @@ class PiTpl $data['title'] = $errorTitle; $data['msg'] = $errorMsg; - include $this->tplFolderPath.'error'.$this->tplFileSuffix; + include $this->tplFolderPath . 'error' . $this->tplFileSuffix; if ($errorCancel === true) if (self::drawFooter() === false) @@ -623,12 +619,13 @@ class PiTpl return false; if (!headers_sent($filename, $linenum)) - exit(header('Location: '.$url)); - else - { - self::error(self::_t('Weiterleitung'), - ''.self::_t('Header bereits gesendet. Redirect nicht möglich, klicke daher stattdessen diesen Link an.', $url).'', - true); + exit(header('Location: ' . $url)); + else { + self::error( + self::_t('Weiterleitung'), + '' . self::_t('Header bereits gesendet. Redirect nicht möglich, klicke daher stattdessen diesen Link an.', $url) . '', + true + ); } return true; @@ -644,7 +641,7 @@ class PiTpl public function showDebug() { - printf(PHP_EOL.''.PHP_EOL.'
Ladezeit: %f
Fehler: %s
Ladezeit: %f
Fehler: %s