21 Commits
2.3.0 ... main

Author SHA1 Message Date
db3d54a835 Umstellung auf GET Methoden
Zusammenfassen von Anfragen
2023-10-27 23:05:48 +02:00
37e155a9b1 Vorbereitungen SSH Login 2023-09-23 16:17:39 +02:00
69e2ee972c README.md aktualisiert 2023-08-18 21:26:56 +02:00
c6fb90e562 Netzwerkdaten anzeigen 2023-08-04 21:30:36 +02:00
9f2d29c8fe PHP CLI in Cron prüfen 2023-05-03 15:17:04 +02:00
ec8a954b0b Auslesen von Netzwerkinformationen 2023-05-02 22:03:09 +02:00
f2938cf701 Installer angepasst für aktuelle Systeme 2023-04-21 09:17:10 +02:00
f803effbbd Beta zu Final Version gesetzt 2022-06-09 20:24:03 +02:00
fcceec8545 Footer URL angepasst 2022-06-09 20:22:48 +02:00
130dee67ea Versionsnummer angepasst 2022-06-08 21:02:14 +02:00
79c7fbc841 Update URL korrigiert
Git Link angepasst
2022-06-08 21:01:00 +02:00
Gregor Schulte
57608f3b2f Korrekturen
URLs angepasst
Statistik Einheit automatisch ändern (MB -> GB)
2022-04-16 20:56:12 +02:00
Gregor Schulte
1e60371abe 64bit Anpassungen
Name der Distro angepasst
Max Value in Statistiken angepasst
Hash Verfahren auf SHA256 umgestellt
2022-02-09 09:40:58 +01:00
Gregor Schulte
79fc07e010 ReadMe angepasst 2021-12-14 12:27:22 +01:00
Gregor Schulte
db683a5b19 Merge durchgeführt in bullseye (Pull-Request #1)
Bullseye
2021-12-14 11:22:25 +00:00
Gregor Schulte
3ebc78f14d PiControl-2.2.0.zip edited online with Bitbucket 2021-12-14 11:22:01 +00:00
Gregor Schulte
588c82f4e8 PiControl-2.2.0-full.zip edited online with Bitbucket 2021-12-14 11:21:54 +00:00
Gregor Schulte
22fa53e3a3 Pi Control.iml edited online with Bitbucket 2021-12-14 10:54:44 +00:00
Gregor Schulte
1257825709 PiControl-2.2.0.zip edited online with Bitbucket 2021-12-14 10:54:32 +00:00
Gregor Schulte
6f819ed9f5 PiControl-2.2.0-full.zip edited online with Bitbucket 2021-12-14 10:54:18 +00:00
Gregor Schulte
6adb4fe93e Korrektur bei der Download URL 2021-12-14 11:50:53 +01:00
31 changed files with 1218 additions and 1386 deletions

3
.gitignore vendored
View File

@@ -10,6 +10,7 @@
.idea/**/shelf
.idea
.vscode
pack.sh
# Generated files
.idea/**/contentModel.xml
@@ -99,3 +100,5 @@ data/DoctrineORMModule/cache/
demos/
extras/documentation
*.zip

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

Binary file not shown.

View File

@@ -4,4 +4,4 @@
[Pi Control Installation](https://pi-control.de/install/)
## Bei Fragen oder Problemen
Schreibe mir eine E-Mail an [support@pi-control.de](mailto:support@pi-control.de) oder nutze das Feedback in Pi Control.
Über das [Ticketsystem](https://git.schultes.dev/gregor/pi-control/issues) können Fehler gemeldet werden und im [Forum](https://bugs.die-schultes.eu/projects/pi-control/boards) gibt es Hilfe zu Fragen rund um Pi Control

View File

@@ -8,14 +8,21 @@ define('PICONTROL', true);
$api = new API;
if (isset($_POST['data']))
{
if (isset($_POST['data'])) {
$datas = explode(';', $_POST['data']);
setData($datas, $api);
} elseif (isset($_GET['data'])) {
$datas = explode(';', $_GET['data']);
setData($datas, $api);
} else
$api->setError('error', 'No data set.');
foreach ($datas as $data)
{
switch ($data)
$api->display();
function setData($datas, $api)
{
foreach ($datas as $data) {
switch ($data) {
case 'startTime':
$api->addData('startTime', formatTime(time() - rpi_getRuntime()));
break;
@@ -26,7 +33,7 @@ if (isset($_POST['data']))
$api->addData('cpuClock', rpi_getCpuClock());
break;
case 'cpuLoad':
$api->addData('cpuLoad', rpi_getCpuLoad(true));
$api->addData('cpuLoad', rpi_getCpuLoad(false));
break;
case 'cpuTemp':
$api->addData('cpuTemp', numberFormat(rpi_getCoreTemprature()));
@@ -60,8 +67,3 @@ if (isset($_POST['data']))
}
}
}
else
$api->setError('error', 'No data set.');
$api->display();
?>

View File

@@ -111,4 +111,3 @@ if (isset($_POST['logout']))
}
$api->display();
?>

View File

@@ -8,15 +8,33 @@ 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');
$requestMethod = $_SERVER["REQUEST_METHOD"];
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;
if (isset($_POST['id']))
{
if (isset($_POST['id'])) {
$controller = new StatisticController();
$controller->loadStatistics();
if (($name = $controller->getStatisticName($_POST['id'])) !== false)
{
if (($name = $controller->getStatisticName($_POST['id'])) !== false) {
if (isset($_POST['plugin']) && trim($_POST['plugin']) != '')
pluginLanguage(trim($_POST['plugin']));
@@ -26,28 +44,27 @@ if (isset($_POST['id']))
$log = new LogStatistic();
$log->setFile(LOG_PATH . $statistic['raw'] . '.csv');
$logData = $log->getAll();
$arr = $info = array();
foreach ($statistic['columns'] as $column)
foreach ($statistic['columns'] as $column) {
$arr['cols'][] = array('id' => '', 'label' => _t($column['label']), 'type' => $column['type']);
}
getRowsFromLog($arr, $info, $log->getAll(), $statistic['columns'], $statistic['cycle']);
getRowsFromLog($arr, $info, $logData, $statistic['columns'], $statistic['cycle']);
if (isset($arr['rows']))
{
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)
{
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')
{
elseif ($statistic['limits'][$type]['use'] == 'fix') {
if ($statistic['limits'][$type]['fix'] == true)
$arr[$type] = $statistic['limits'][$type]['value'];
else
@@ -56,23 +73,18 @@ if (isset($_POST['id']))
}
$api->addData('statistic', $arr);
}
else
} else
$api->setError('error', 'Empty data.');
}
else
} else
$api->setError('error', 'Data not found.');
}
else
{
} else {
$statistics = array();
$hiddenStatistics = unserialize(htmlspecialchars_decode(getConfig('main:statistic.hidden', 'a:0:{}')));
$controller = new StatisticController();
$controller->loadStatistics();
foreach ($controller->getStatistics() as $statistic)
{
foreach ($controller->getStatistics() as $statistic) {
$builder = new StatisticBuilder();
$builder->loadFromFile($statistic);
@@ -86,3 +98,4 @@ else
}
$api->display();
}

View File

@@ -7,4 +7,3 @@ $apiVersions[0] = array('versioncode' => 1,
'date' => 1443909600);
echo json_encode(array('versions' => $apiVersions, 'latest' => $apiLatest));
?>

View File

@@ -7,7 +7,7 @@ $tpl->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['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;
@@ -91,4 +87,3 @@ $tpl->assign('langUrl', (isset($_GET['lang']) && $_GET['lang'] != '') ? '&amp;la
$tpl->assign('configHelp', $config['url']['help']);
$tpl->draw('install_requirement');
?>

View File

@@ -368,8 +368,15 @@ function urlIsPublic($url)
$ip = gethostbyname($url);
$long = ip2long($ip);
if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1)
if (PHP_INT_SIZE == 4) {
if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1) {
return false;
}
} else {
if (($long >= 3232235520 && $long <= 3232301055) || ($long >= 2886729728 && $long <= 2887778303) || ($long >= 167772160 && $long <= 184549375) || $long == -1) {
return false;
}
}
return true;
}
@@ -614,4 +621,3 @@ function getURLLangParam($echo = false, $html = true, $first = false)
return $param;
}
?>

View File

@@ -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;
}
}
?>

View File

@@ -1,15 +1,13 @@
var is_loding = false;
function overviewStatusRefreshEffect(element)
{
function overviewStatusRefreshEffect(element) {
element.css({ 'transition': 'background-color 0.5s', 'background-color': 'rgba(243, 255, 164, 1)' });
setTimeout(function () {
element.css({ 'background-color': 'transparent' });
}, 800);
}
function showError()
{
function showError() {
jQuery('.error-msg-refresh-bar').remove();
jQuery('.flex-box-refresh div:eq(0)').after('<div class="red error-msg-refresh-bar" style="vertical-align: bottom; font-weight: bold;">' + _t('Fehler!') + '</div>');
jQuery('.refresh-bar').stop(false, true).css('width', 0);
@@ -18,91 +16,66 @@ function showError()
setTimeout('overviewStatusRefresh()', 3000);
}
function overviewStatusRefresh()
{
function overviewStatusRefresh() {
jQuery('.error-msg-refresh-bar').remove();
jQuery('.refresh-bar').animate({width: '100%'}, reload_timeout, 'linear', function(e)
{
var this_ = jQuery(this);
var runtime = jQuery('.flex-container > div:eq(2)');
var cpuClock = jQuery('.flex-container > div:eq(3)');
var cpuLoad = jQuery('.flex-container > div:eq(4)');
var cpuTemp = jQuery('.flex-container > div:eq(5)');
var ramPercentage = jQuery('.flex-container > div:eq(6)');
var memoryUsed = jQuery('.flex-container > div:eq(7)');
var memoryFree = jQuery('.flex-container > div:eq(8)');
var memoryTotal = jQuery('.flex-container > div:eq(9)');
jQuery('.refresh-bar').animate({ width: '100%' }, reload_timeout, 'linear', function (e) {
let this_ = jQuery(this);
let runtime = jQuery('.flex-container > div:eq(2)');
let cpuClock = jQuery('.flex-container > div:eq(3)');
let cpuLoad = jQuery('.flex-container > div:eq(4)');
let cpuTemp = jQuery('.flex-container > div:eq(5)');
let ramPercentage = jQuery('.flex-container > div:eq(6)');
let memoryUsed = jQuery('.flex-container > div:eq(7)');
let memoryFree = jQuery('.flex-container > div:eq(8)');
let memoryTotal = jQuery('.flex-container > div:eq(9)');
jQuery('a[href=#refresh] img').addClass('rotate-icon');
this_.animate({ width: '88.8%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'runtime' }, function(data)
{
if (runtime.find('span').html() != data.data.runtime)
{
jQuery.get('api/v1/overview.php', { data: 'runtime;cpuClock;cpuLoad;cpuTemp;ramPercentage;memoryUsed;memoryFree;memoryTotal' }, function (data) {
if (runtime.find('span').html() != data.data.runtime) {
overviewStatusRefreshEffect(runtime);
runtime.find('span').html(data.data.runtime);
}
this_.animate({ width: '77.7%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'cpuClock' }, function(data)
{
if (cpuClock.find('span').html() != data.data.cpuClock+' MHz')
{
if (cpuClock.find('span').html() != data.data.cpuClock + ' MHz') {
overviewStatusRefreshEffect(cpuClock);
cpuClock.find('span').html(data.data.cpuClock + ' MHz');
}
this_.animate({ width: '66.6%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'cpuLoad' }, function(data)
{
if (cpuLoad.find('.progressbar div').html() != data.data.cpuLoad+'%')
{
if (cpuLoad.find('.progressbar div').html() != data.data.cpuLoad + '%') {
overviewStatusRefreshEffect(cpuLoad);
cpuLoad.find('.progressbar').attr('data-text', data.data.cpuLoad + '%').find('div').css('width', data.data.cpuLoad + '%');
}
this_.animate({ width: '55.5%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'cpuTemp' }, function(data)
{
if (cpuTemp.find('span').html() != data.data.cpuTemp+' °C')
{
if (cpuTemp.find('span').html() != data.data.cpuTemp + ' °C') {
overviewStatusRefreshEffect(cpuTemp);
cpuTemp.find('span').html(data.data.cpuTemp + ' &deg;C');
}
this_.animate({ width: '44.4%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'ramPercentage' }, function(data)
{
if (ramPercentage.find('.progressbar div').html() != data.data.ramPercentage+'%')
{
if (ramPercentage.find('.progressbar div').html() != data.data.ramPercentage + '%') {
overviewStatusRefreshEffect(ramPercentage);
ramPercentage.find('.progressbar').attr('data-text', data.data.ramPercentage + '%').find('div').css('width', data.data.ramPercentage + '%');
}
this_.animate({ width: '33.3%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'memoryUsed' }, function(data)
{
if (memoryUsed.find('span').html() != data.data.memoryUsed)
{
if (memoryUsed.find('span').html() != data.data.memoryUsed) {
overviewStatusRefreshEffect(memoryUsed);
memoryUsed.find('span').html(data.data.memoryUsed);
}
this_.animate({ width: '22.2%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'memoryFree' }, function(data)
{
if (memoryFree.find('span').html() != data.data.memoryFree)
{
if (memoryFree.find('span').html() != data.data.memoryFree) {
overviewStatusRefreshEffect(memoryFree);
memoryFree.find('span').html(data.data.memoryFree);
}
this_.animate({ width: '11.1%' }, 300, 'linear');
jQuery.post('api/v1/overview.php', { data: 'memoryTotal' }, function(data)
{
if (memoryTotal.find('span').html() != data.data.memoryTotal)
{
if (memoryTotal.find('span').html() != data.data.memoryTotal) {
overviewStatusRefreshEffect(memoryTotal);
memoryTotal.find('span').html(data.data.memoryTotal);
}
@@ -114,25 +87,16 @@ function overviewStatusRefresh()
overviewStatusRefresh();
}).fail(function (e) { showError(); });
}).fail(function(e) { showError(); });
}).fail(function(e) { showError(); });
}).fail(function(e) { showError(); });
}).fail(function(e) { showError(); });
}).fail(function(e) { showError(); });
}).fail(function(e) { showError(); });
}).fail(function(e) { showError(); });
});
}
jQuery(document).on('click', 'a[href=#refresh]', function(e)
{
jQuery(document).on('click', 'a[href=#refresh]', function (e) {
if (is_loding == false)
jQuery('.refresh-bar').stop(false, true);
return false;
});
jQuery(document).ready(function(e)
{
jQuery(document).ready(function (e) {
overviewStatusRefresh();
});

View File

@@ -1,18 +1,15 @@
var dataSlider = [];
var dataPeriods = [];
function statisticBuilder(builder, plugin)
{
var jsonData = jQuery.ajax({
function statisticBuilder(builder, plugin) {
jQuery.ajax({
url: 'api/v1/statistic.php',
method: 'POST',
data: { id: builder.id, plugin: plugin, type: 'googleChart' },
dataType: 'json',
async: true
}).done(function(data)
{
if (data.error != null)
{
}).done(function (data) {
if (data.error != null) {
if (data.error.message == 'Empty data.')
jQuery('#chart_log_' + builder.id).html('<br /><br /><strong class="red">' + _t('Es sind noch keine Werte verf&uuml;gbar. Werte werden alle %%s Minuten eingetragen.', builder.cycle) + '</strong>');
else
@@ -41,8 +38,6 @@ function statisticBuilder(builder, plugin)
}
});
var t = null;
var myLine = new google.visualization.ChartWrapper({
'chartType': 'AreaChart',
'containerId': 'chart_log_' + builder.id,
@@ -91,26 +86,35 @@ function statisticBuilder(builder, plugin)
myDashboard.bind(dataSlider[builder.id], myLine);
myDashboard.draw(myData);
}).fail(function(xhr, textStatus)
{
setRange();
}).fail(function (xhr, textStatus) {
jQuery('#chart_log_' + builder.id).html('<br /><br /><strong class="red">' + _t('Es ist ein Fehler aufgetreten! Fehlercode: %%s', xhr.status) + '</strong>');
});
}
function changeRange(dropdown)
{
var days = Array('seven', 'six', 'five', 'four', 'three', 'two', 'one');
function changeRange(dropdown) {
var day = dropdown.value;
window.localStorage.setItem("days", day);
if (days.indexOf(day) > -1)
{
for (var data in dataSlider)
{
if (typeof dataSlider[data] != 'undefined')
{
setRange();
}
function setRange() {
var days = Array('seven', 'six', 'five', 'four', 'three', 'two', 'one');
var day = window.localStorage.getItem("days");
if (days.indexOf(day) > -1) {
for (var data in dataSlider) {
if (typeof dataSlider[data] != 'undefined') {
dataSlider[data].setState({ 'lowValue': new Date(dataPeriods[data][day]) });
dataSlider[data].draw();
}
}
}
}
window.addEventListener("DOMContentLoaded", function () {
if (window.localStorage.days)
document.getElementById("range").value = window.localStorage.days;
}, false);

View File

@@ -14,15 +14,15 @@
<a href="https://willy-tech.de/kontakt/" target="_blank" data-lang="<?php echo $data['language']; ?>"><?php _e('Feedback'); ?></a><br />
<a href="<?php echo $data['helpLink']; ?>" target="_blank"><?php _e('Hilfe'); ?></a><br />
<a href="https://play.google.com/store/apps/details?id=de.willytech.picontrol" target="_blank" title="<?php _e('&Ouml;ffne im Play Store'); ?>"><?php _e('App im Play Store'); ?></a><br />
<a href="https://bitbucket.org/GSchulte/pi-control/" target="_blank"><?php _e('Git Repo'); ?></a></td>
<td rowspan="2"><a href="https://www.die-schultes.eu/" target="_blank"><?php _e('Mein Blog'); ?></a><br />
<a href="https://bugs.schultes.dev/gregor/pi-control" target="_blank"><?php _e('Git Repo'); ?></a></td>
<td rowspan="2"><a href="https://www.schultes.dev/" target="_blank"><?php _e('Mein Blog'); ?></a><br />
<td><?php echo $data['version']; ?></td>
</tr>
<tr>
<td><strong><?php _e('LIZENZ'); ?></strong><span><?php _e('Raspberry Pi ist ein Markenzeichen<br />der %s.', '<a href="https://www.raspberrypi.org/" target="_blank">Raspberry Pi Foundation</a>'); ?></span></td>
</tr>
</table>
<div id="footer-copyright"><?php _e('Mit %s entwickelt von %s.', '<span style="color: #F44336;">&#10084;</span>', '<a href="https://willy-tech.de/" target="_blank">Willy Fritzsche</a>'); ?> 2013-2017 <br>Weiterentwickelt von <a href="https://www.die-schultes.eu">Gregor Schulte</a> 2021</div>
<div id="footer-copyright"><?php _e('Mit %s entwickelt von %s.', '<span style="color: #F44336;">&#10084;</span>', '<a href="https://willy-tech.de/" target="_blank">Willy Fritzsche</a>'); ?> 2013-2017 <br>Weiterentwickelt von <a href="https://www.schultes.dev">Gregor Schulte</a> 2021-2023</div>
</div>
</div>
<script type="text/javascript">var errorHandler = '<?php echo $data['errorHandler']; ?>';</script>

View File

@@ -38,7 +38,10 @@
</div>
</label>
<div class="inner">
<div class="divider"><div></div><div><?php _e('ODER'); ?></div></div>
<div class="divider">
<div></div>
<div><?php _e('ODER'); ?></div>
</div>
</div>
<input type="radio" id="ssh-login-pubkey" name="ssh-login" value="publickey" />
<label for="ssh-login-pubkey">

View File

@@ -17,7 +17,7 @@
<span><?php _e('Zeitraum'); ?></span>
</div>
<div class="inner">
<select onchange="changeRange(this)">
<select id="range" onchange="changeRange(this)">
<option name="" value="seven"><?php _e('Alles (7 Tage)'); ?></option>
<option name="" value="six"><?php _e('Letzten 6 Tage'); ?></option>
<option name="" value="five"><?php _e('Letzten 5 Tage'); ?></option>
@@ -62,14 +62,15 @@
</div>
<?php } ?>
</div>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="public_html/js/statistic_builder.js"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages:['controls']});
google.load('visualization', '51', {
packages: ['controls']
});
google.setOnLoadCallback(createTable);
function createTable()
{
function createTable() {
<?php foreach ($data['statistics'] as $statistic) { ?>
statisticBuilder(<?php echo $statistic['json']; ?>, null);
<?php } ?>

View File

@@ -1,9 +1,21 @@
<?php if (!defined('PICONTROL')) exit(); ?>
<style>
.system_msg{color: #01a7db; font-style: italic;}
.user_name{font-weight:bold;}
.user_message{color: #FFFFFF;}
pre { margin: 0; }
.system_msg {
color: #01a7db;
font-style: italic;
}
.user_name {
font-weight: bold;
}
.user_message {
color: #FFFFFF;
}
pre {
margin: 0;
}
</style>
<script language="javascript" type="text/javascript">
var ip = '<?php echo $_SERVER['SERVER_ADDR']; ?>';

View File

@@ -5,20 +5,15 @@ if (!defined('PICONTROL')) exit();
(include_once LIBRARY_PATH . 'network/network.function.php') or die('Error: 0x0011');
$tpl->setHeaderTitle(_t('Netzwerk'));
if (isset($_GET['hostname']))
{
if (isset($_POST['submit']) && $_POST['submit'] != '')
{
if (isset($_POST['hostname']) && trim($pHostname = trim($_POST['hostname'])) != '')
{
if (preg_match('/^([a-z][a-z0-9\-\.]*[^\-]){1,24}$/im', $pHostname))
{
if (isset($_GET['hostname'])) {
if (isset($_POST['submit']) && $_POST['submit'] != '') {
if (isset($_POST['hostname']) && trim($pHostname = trim($_POST['hostname'])) != '') {
if (preg_match('/^([a-z][a-z0-9\-\.]*[^\-]){1,24}$/im', $pHostname)) {
if (($status = editHostname($pHostname)) === true)
$tpl->msg('success', _t('Hostname gespeichert'), _t('Damit die &Auml;nderung wirksam wird, muss dein Raspberry Pi neu gestartet werden. <a href="%s">Jetzt neu starten.</a>', '?s=shutdown&restart'));
else
$tpl->msg('error', _t('Fehler'), _t('Fehler beim &Auml;ndern des Hostname! Fehlercode: %s', $status));
}
else
} else
$tpl->msg('error', _t('Fehler'), _t('Der Hostname ist ung&uuml;ltig! Er muss aus mindestens 1 bis 24 Zeichen bestehen und darf nur folgende Zeichen enthalten: A-Z a-z 0-9 -<br />Der Hostname darf nicht mit einem Bindestrich Anfangen oder Enden.'));
}
}
@@ -26,16 +21,13 @@ if (isset($_GET['hostname']))
$tpl->assign('hostname', rpi_getHostname());
$tpl->draw('network_hostname');
}
else
{
} else {
$networkConnections = getAllNetworkConnections();
$networkCounts = unserialize(htmlspecialchars_decode(getConfig('main:network.overflowCount', 'a:0:{}')));
$counter = 0;
foreach ($networkConnections as $network)
{
foreach ($networkConnections as $network) {
$countSent = 0;
$countReceive = 0;
@@ -57,4 +49,3 @@ else
$tpl->draw('network');
}
?>

View File

@@ -38,7 +38,7 @@ $tpl->assign('configHelpFilesFolders', $config['url']['help'].'?s=view&amp;i=1'.
$tpl->assign('configHelpCron', $config['url']['help'].'?s=view&amp;i=10'.getURLLangParam());
$tpl->assign('cronEntry', $cronEntry);
$tpl->assign('cronMatch', $cronMatch);
$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('cronPHPCLI', ($cronPHPCLI = (trim(exec('dpkg -s php-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]));

View File

@@ -9,27 +9,23 @@ $doNotCheckForAuthentification = true;
$folder = CRON_PATH;
$fileArray = array();
foreach (@scandir($folder) as $file)
{
if ($file[0] != '.')
{
foreach (@scandir($folder) as $file) {
if ($file[0] != '.') {
if (is_file($folder . '/' . $file) && $file != 'init.php')
$fileArray[] = $file;
}
}
foreach ($fileArray as $file)
{
foreach ($fileArray as $file) {
$timeOfFile = str_replace('-', '', substr($file, 0, 2));
$rest = date('i', time()) % $timeOfFile;
if (is_numeric($rest) && $rest == 0)
{
if (is_numeric($rest) && $rest == 0) {
exec('/usr/bin/php -f "' . CRON_PATH . $file . '"');
set_time_limit(30);
usleep(500000);
}
}
if (trim(exec('dpkg -s php7.4-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '')
if (trim(exec('dpkg -s php-cli | grep Status: ')) != '')
setConfig('cron:execution.cron', time());

View File

@@ -10,13 +10,13 @@ if (!isset($config))
'ssh_ip' => '127.0.0.1'
),
'version' => array(
'version' => '2.3.0',
'versioncode' => 31,
'version' => '2.3.3',
'versioncode' => 38,
'android_comp_level' => 25
),
'url' => array(
'update' => 'https://pic.die-schultes.eu/service/v1/update/',
'updateDownload' => 'https://www.die-schultes.eu/wp-content/uploads/',
'update' => 'https://pic.schultes.dev/api/service/v2/update/',
'updateDownload' => 'https://pic.schultes.dev/api/download/',
'updateNotification' => 'https://pi-control.de/?service=update_notification',
'plugin' => 'https://pi-control.de/service/v1/plugin/',
'pluginDownload' => 'https://pi-control.de/?service=plugin',
@@ -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();
@@ -81,4 +81,3 @@ 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

@@ -0,0 +1,6 @@
<?php
namespace resources\library\api;
class StatisticController {
}

View File

@@ -28,8 +28,7 @@ function setConfig($config, $value, $customFile = NULL)
$configFile = $configPath . $file[0] . $configFileSuffix;
if (file_exists($configFile) !== true || is_file($configFile) !== true)
{
if (file_exists($configFile) !== true || is_file($configFile) !== true) {
if (!touch($configFile))
return false;
}
@@ -85,17 +84,14 @@ function getConfig($config, $default = NULL, $customFile = NULL)
if (!count($configArray) > 0)
return $default;
if (isset($file[1]))
{
if (isset($file[1])) {
$var = explode('.', $file[1]);
if (count($var) == 1 && isset($configArray[$var[0]]))
return $configArray[$var[0]];
elseif (count($var) == 2 && isset($configArray[$var[0]][$var[1]]))
return $configArray[$var[0]][$var[1]];
}
else
{
} else {
if (isset($configArray))
return $configArray;
}
@@ -152,16 +148,13 @@ function writeConfig($configArray, $configFile)
ksort($configArray);
foreach ($configArray as $key => $val)
{
if (is_array($val))
{
foreach ($configArray as $key => $val) {
if (is_array($val)) {
$res[] = PHP_EOL . "[$key]";
foreach ($val as $skey => $sval)
$res[] = "$skey = " . (is_numeric($sval) ? $sval : '"' . $sval . '"');
}
else
} else
$res[] = PHP_EOL . "$key = " . (is_numeric($val) ? $val : '"' . $val . '"');
}
@@ -170,11 +163,9 @@ function writeConfig($configArray, $configFile)
if (file_exists($configFile) !== true || is_file($configFile) !== true || is_writeable($configFile) !== true)
return false;
if ($fp = fopen($configFile, 'w'))
{
if ($fp = fopen($configFile, 'w')) {
$startTime = microtime();
do
{
do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
@@ -183,8 +174,7 @@ function writeConfig($configArray, $configFile)
} while ((!$canWrite) && ((microtime() - $startTime) < 1000));
// file was locked so now we can store information
if ($canWrite)
{
if ($canWrite) {
fwrite($fp, implode(PHP_EOL, $res));
flock($fp, LOCK_UN);
}
@@ -212,8 +202,7 @@ function _t()
$lang = $globalLanguage;
$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;
}
@@ -247,8 +236,7 @@ function _e()
$lang = $globalLanguage;
$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;
}
@@ -288,8 +276,7 @@ function return_bytes($size)
$size = trim($size);
$last = strtolower($size[strlen($size) - 1]);
switch ($last)
{
switch ($last) {
case 'g':
$size *= 1024;
case 'm':
@@ -309,11 +296,9 @@ function getFolderSize($folder_path, $folder_size = 0)
{
if (!is_dir($folder_path))
$folder_size += filesize($folder_path);
else
{
else {
$folder_dir = opendir($folder_path);
while ($folder_file = readdir($folder_dir))
{
while ($folder_file = readdir($folder_dir)) {
if (is_file($folder_path . '/' . $folder_file))
$folder_size += filesize($folder_path . '/' . $folder_file);
if (is_dir($folder_path . '/' . $folder_file) && $folder_file != '.' && $folder_file != '..')
@@ -331,11 +316,12 @@ function formatTime($time, $type = 'd.m.Y H:i')
return date($type, $time);
}
if (!function_exists('array_column'))
{
if (!function_exists('array_column')) {
function array_column($array, $columnName)
{
return array_map(function($element) use($columnName) { return $element[$columnName]; }, $array);
return array_map(function ($element) use ($columnName) {
return $element[$columnName];
}, $array);
}
}
@@ -345,8 +331,7 @@ function checkUpdate()
$lang = $globalLanguage;
if (!class_exists('cURL'))
(include LIBRARY_PATH.'curl/curl.class.php');
if (!class_exists('cURL')) (include LIBRARY_PATH . 'curl/curl.class.php');
$curl = new cURL($config['url']['update']);
$curl->execute();
@@ -360,8 +345,7 @@ function checkUpdate()
if (!isset($data['versions'], $data['latest']))
return 1;
if ($data['latest']['versioncode'] > $config['version']['versioncode'])
{
if ($data['latest']['versioncode'] > $config['version']['versioncode']) {
$currentUpdateKey = array_search($config['version']['versioncode'] + 1, array_column($data['versions'], 'versioncode'));
if (isset($data['versions'][$currentUpdateKey]['changelog'][$lang]))
@@ -370,8 +354,7 @@ function checkUpdate()
$data['versions'][$currentUpdateKey]['changelog'] = current($data['versions'][$currentUpdateKey]['changelog']);
return $data['versions'][$currentUpdateKey];
}
else
} else
return 0;
}
@@ -410,37 +393,27 @@ function getImageFromSignal($signal)
function getAllNetworkConnections()
{
$shell_string = '';
$output = array();
$networkInterfaces = json_decode(shell_exec('ip -j addr'));
exec('/sbin/ifconfig | grep -E -o "^[[:alnum:][:punct:]]*" | grep -E -v "(lo)" | sed "s/:$//"', $networkInterfaces);
foreach ($networkInterfaces as $interface) {
if ($interface->ifname != 'lo') {
$wirelessOption = [];
$interfaceData = json_decode(shell_exec('ip -j -s link show ' . $interface->ifname));
foreach ($networkInterfaces as $interface)
$shell_string .= '/sbin/ifconfig '.$interface.(($networkInterfaces[count($networkInterfaces)-1] != $interface) ? ' && echo "-#-" && ' : '');
foreach ($interface->addr_info as $addr) {
if ($addr->family == "inet")
$ipAddress = $addr->local;
}
$macAddress = $interface->address;
$bytesReceived = $interfaceData[0]->stats64->rx->bytes;
$bytesSent = $interfaceData[0]->stats64->tx->bytes;
$packetsReceived = $interfaceData[0]->stats64->rx->packets;
$packetsSent = $interfaceData[0]->stats64->tx->packets;
$streamInterfaces = explode('-#-', shell_exec($shell_string));
if (substr($interface->ifname, 0, 4) == 'wlan') {
$streamWirelessInterface = shell_exec('/sbin/iwconfig ' . $interface->ifname);
foreach ($streamInterfaces as $index => $streamInterface)
{
$wirelessOption = '';
$interface = $networkInterfaces[$index];
preg_match('#inet(?:[ ]+(?:addr\:)?)([\w\.]+)#', $streamInterface, $ipAddress);
preg_match('#(?:HWaddr|ether) ([\w\:]+)#', $streamInterface, $macAddress);
preg_match('#RX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesReceived);
preg_match('#TX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesSent);
preg_match('#RX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsReceived);
preg_match('#TX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsSent);
$output0 = $interface;
if (substr($output0, 0, 4) == 'wlan')
{
$streamWirelessInterface = shell_exec('/sbin/iwconfig '.$output0);
if (0 == substr_count($streamWirelessInterface, 'Not-Associated'))
{
if (0 == substr_count($streamWirelessInterface, 'Not-Associated')) {
$posConfig_start = @strpos($streamWirelessInterface, 'ESSID:"', 0) + 7;
$posConfig_end = @strpos($streamWirelessInterface, '"', $posConfig_start);
$wirelessOption['ssid'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
@@ -451,8 +424,7 @@ function getAllNetworkConnections()
$posConfig_start = @strpos($streamWirelessInterface, 'Signal level=', 0) + 13;
if (($posConfig_end = @strpos($streamWirelessInterface, '/100', $posConfig_start)) === false)
{
if (($posConfig_end = @strpos($streamWirelessInterface, '/100', $posConfig_start)) === false) {
$posConfig_end = @strpos($streamWirelessInterface, ' dBm', $posConfig_start);
$signal = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
@@ -462,14 +434,13 @@ function getAllNetworkConnections()
$wirelessOption['signal'] = 100;
else
$wirelessOption['signal'] = 2 * ($signal + 100);
}
else
} else
$wirelessOption['signal'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
}
}
$output[] = array('interface' => $interface, 'mac' => strtoupper($macAddress[1]), 'ip' => (isset($ipAddress[1])) ? $ipAddress[1] : NULL, 'sent' => $bytesSent[1], 'receive' => $bytesReceived[1], 'option' => $wirelessOption, 'packets' => array('sent' => $packetsSent[1], 'received' => $packetsReceived[1]));
$output[] = array('interface' => $interface->ifname, 'mac' => strtoupper($macAddress), 'ip' => (isset($ipAddress)) ? $ipAddress : NULL, 'sent' => $bytesSent, 'receive' => $bytesReceived, 'option' => $wirelessOption, 'packets' => array('sent' => $packetsSent, 'received' => $packetsReceived));
}
}
return $output;
@@ -481,8 +452,7 @@ function scanAccessPoints($networkConnections, $ssh = false)
$wlan = array();
foreach ($networkConnections as $interface)
{
foreach ($networkConnections as $interface) {
if (substr($interface['interface'], 0, 4) != 'wlan')
continue;
@@ -493,8 +463,7 @@ function scanAccessPoints($networkConnections, $ssh = false)
else
$streamWlan = shell_exec('/sbin/iwlist ' . escapeshellarg($interface['interface']) . ' scan');
for ($i = 1; $i <= substr_count($streamWlan, 'ESSID:"'); $i += 1)
{
for ($i = 1; $i <= substr_count($streamWlan, 'ESSID:"'); $i += 1) {
$posCell_start = @strpos($streamWlan, 'Cell ' . (($i < 10) ? '0' : '') . $i . ' - Address:', 0) + 19;
$posCell_end = @strpos($streamWlan, 'Cell ' . ((($i + 1) < 10) ? '0' : '') . ($i + 1), $posCell_start);
if ($posCell_end === false)
@@ -520,8 +489,7 @@ function scanAccessPoints($networkConnections, $ssh = false)
$wirelessOption['signal'] = trim(substr($string, $posConfig_start, ($posConfig_end - $posConfig_start)));
if (strpos(substr($string, $posConfig_start, 20), 'dBm'))
{
if (strpos(substr($string, $posConfig_start, 20), 'dBm')) {
if ($wirelessOption['signal'] <= -100)
$wirelessOption['signal'] = 0;
elseif ($wirelessOption['signal'] >= -50)
@@ -558,9 +526,15 @@ function urlIsPublic($url)
$ip = gethostbyname($url);
$long = ip2long($ip);
if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1)
if (PHP_INT_SIZE == 4) {
if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1) {
return false;
}
} else {
if (($long >= 3232235520 && $long <= 3232301055) || ($long >= 2886729728 && $long <= 2887778303) || ($long >= 167772160 && $long <= 184549375) || $long == -1) {
return false;
}
}
return true;
}
@@ -581,12 +555,9 @@ function getDirectory($folder_)
$folder = array();
$file = array();
foreach (@scandir($folder_) as $file_)
{
if ($file_[0] != '.')
{
if (is_dir($folder_.'/'.$file_))
{
foreach (@scandir($folder_) as $file_) {
if ($file_[0] != '.') {
if (is_dir($folder_ . '/' . $file_)) {
$folderArray[] = $file_;
$fileArray[] = $file_;
}
@@ -619,10 +590,8 @@ function getAllFiles($folder_)
else
$fileArray[] = $file_;
if (isset($folderArray))
{
foreach ($folderArray as $row)
{
if (isset($folderArray)) {
foreach ($folderArray as $row) {
list($file_return, $error_log) = getAllFiles($folder_ . '/' . $row);
$file[$row] = $file_return;
@@ -633,10 +602,8 @@ function getAllFiles($folder_)
}
}
if (isset($fileArray))
{
foreach ($fileArray as $row)
{
if (isset($fileArray)) {
foreach ($fileArray as $row) {
$file[] = $row;
if (is_writeable($folder_ . '/' . $row) !== true)
@@ -651,8 +618,7 @@ function deleteFolder($folder)
{
chmod($folder, 0777);
if (is_dir($folder))
{
if (is_dir($folder)) {
$handle = opendir($folder);
while ($filename = readdir($handle))
if ($filename != '.' && $filename != '..')
@@ -660,21 +626,18 @@ function deleteFolder($folder)
closedir($handle);
rmdir($folder);
}
else
} else
unlink($folder);
}
function checkInternetConnection()
{
if (function_exists('fsockopen') && ini_get('allow_url_fopen') !== false)
{
if (function_exists('fsockopen') && ini_get('allow_url_fopen') !== false) {
if (!$sock = @fsockopen('www.google.com', 80, $num, $error, 5))
return false; // Raspberry Pi is not connected to internet
else
return true;
}
else
} else
return false;
}
@@ -719,38 +682,28 @@ function addCronToCrontab($cronEntry, $ssh)
$hashtag = 0;
$hashtagLine = 0;
if (!in_array($cronEntry, $lines))
{
if (substr(trim($lines[$lastLine]), 0, 1) == '')
{
if (substr(trim($lines[$secondLastLine]), 0, 1) == '#')
{
if (!in_array($cronEntry, $lines)) {
if (substr(trim($lines[$lastLine]), 0, 1) == '') {
if (substr(trim($lines[$secondLastLine]), 0, 1) == '#') {
$hashtag = 1;
$hashtagLine = $secondLastLine;
}
else
{
} else {
$hashtag = 0;
$hashtagLine = $lastLine;
}
}
if (substr(trim($lines[$lastLine]), 0, 1) == '#')
{
if (substr(trim($lines[$lastLine]), 0, 1) == '#') {
$hashtag = 2;
$hashtagLine = $lastLine;
}
foreach ($lines as $line)
{
if ($lineCount == $hashtagLine)
{
if ($hashtag == 0)
{
foreach ($lines as $line) {
if ($lineCount == $hashtagLine) {
if ($hashtag == 0) {
$newFile .= $cronEntry . "\n";
$newFile .= '#';
}
elseif ($hashtag == 1)
} elseif ($hashtag == 1)
$newFile .= $cronEntry . "\n";
elseif ($hashtag == 2)
$newFile .= $cronEntry . "\n";
@@ -763,30 +716,24 @@ function addCronToCrontab($cronEntry, $ssh)
if (file_exists(TEMP_PATH . 'crontab.tmp.php') && is_file(TEMP_PATH . 'crontab.tmp.php'))
unlink(TEMP_PATH . 'crontab.tmp.php');
if (($file = fopen(TEMP_PATH.'crontab.tmp.php', 'w+')))
{
if (($file = fopen(TEMP_PATH . 'crontab.tmp.php', 'w+'))) {
if (!fwrite($file, $newFile))
return 4;
}
else
} else
return 3;
if (($stream = ssh2_scp_send($ssh, TEMP_PATH.'crontab.tmp.php', '/etc/crontab')))
{
if (($stream = ssh2_scp_send($ssh, TEMP_PATH . 'crontab.tmp.php', '/etc/crontab'))) {
unlink(TEMP_PATH . 'crontab.tmp.php');
return 0;
}
else
} else
return 1;
}
else
} else
return 2;
}
function getWeatherIconYahoo($icon)
{
switch ($icon)
{
switch ($icon) {
case 32:
case 36:
return '01d';
@@ -852,8 +799,7 @@ function getWeatherIconYahoo($icon)
function getWeatherIconOpenWeatherMap($icon)
{
switch ($icon)
{
switch ($icon) {
case '01d':
return '01d';
case '01n':
@@ -891,8 +837,7 @@ function getWeatherIconOpenWeatherMap($icon)
function getWeatherIconWunderground($icon)
{
switch ($icon)
{
switch ($icon) {
case 'clear':
case 'sunny':
return '01d';
@@ -942,8 +887,7 @@ function getWeatherIconWunderground($icon)
function getWeatherIconDarksky($icon)
{
switch ($icon)
{
switch ($icon) {
case 'clear-day':
return '01d';
case 'clear-night':
@@ -976,8 +920,7 @@ function getWeatherIconDarksky($icon)
function getWeatherIconYr($icon)
{
switch ($icon)
{
switch ($icon) {
case '1':
case '01':
case '01d':
@@ -1111,8 +1054,7 @@ function getWeather()
{
global $globalLanguage;
if (!class_exists('cURL'))
(include LIBRARY_PATH.'curl/curl.class.php');
if (!class_exists('cURL')) (include LIBRARY_PATH . 'curl/curl.class.php');
$service = getConfig('main:weather.service', 'openweathermap');
$serviceToken = getConfig('main:weather.serviceToken', '');
@@ -1139,8 +1081,7 @@ function getWeather()
$output = array();
if ($service == 'openweathermap')
{
if ($service == 'openweathermap') {
$curl = new cURL('http://api.openweathermap.org/data/2.5/weather?q=' . $location . ',' . $country . '&units=metric&lang=de&appid=' . $serviceToken);
$curl->execute();
@@ -1164,8 +1105,7 @@ function getWeather()
$output['icon'] = getWeatherIconOpenWeatherMap($data['weather'][0]['icon']);
$output['description'] = $data['weather'][0]['description'];
if (empty($data['name']))
{
if (empty($data['name'])) {
$curl = new cURL('http://api.openweathermap.org/data/2.5/weather?q=' . $location . ',' . $country . '&appid=' . $serviceToken);
$curl->execute();
@@ -1181,11 +1121,8 @@ function getWeather()
$output['city'] = $data['name'];
$output['country'] = $data['sys']['country'];
}
}
elseif ($service == 'yahoo')
{
for ($i = 0; $i < 2; $i++)
{
} elseif ($service == 'yahoo') {
for ($i = 0; $i < 2; $i++) {
$yahooApiUrl = 'https://query.yahooapis.com/v1/public/yql';
$yqlQuery = 'select location, wind, atmosphere, item.condition, item.forecast from weather.forecast where woeid in (select woeid from geo.places(1) where text="' . $location . ', ' . $country . '") AND u=\'c\' | truncate(count=1)';
$yqlQueryUrl = $yahooApiUrl . '?q=' . urlencode($yqlQuery) . '&format=json';
@@ -1193,8 +1130,7 @@ function getWeather()
$curl = new cURL($yqlQueryUrl);
$curl->execute();
if ($curl->getStatusCode() != '200')
{
if ($curl->getStatusCode() != '200') {
if ($curl->getStatusCode() == '0')
return 100;
@@ -1204,8 +1140,7 @@ function getWeather()
if ($curl->getResult($data) != JSON_ERROR_NONE)
return 1;
if (!isset($data['query']['results']['channel']))
{
if (!isset($data['query']['results']['channel'])) {
if ($i == 0)
continue;
@@ -1225,11 +1160,8 @@ function getWeather()
$output['icon'] = getWeatherIconYahoo($data['item']['condition']['code']);
$output['description'] = $data['item']['condition']['text'];
}
}
elseif ($service == 'wunderground')
{
switch ($globalLanguage)
{
} elseif ($service == 'wunderground') {
switch ($globalLanguage) {
case 'de':
$lang = 'DL';
break;
@@ -1240,8 +1172,7 @@ function getWeather()
$lang = 'DL';
}
switch ($country)
{
switch ($country) {
case 'germany':
$customCountry = 'germany';
break;
@@ -1263,8 +1194,7 @@ function getWeather()
$iMax = 2;
do
{
do {
if (($wundergroundCache = getConfig('main:weather.wundergroundCache', '')) != '')
$location = 'zmw:' . $wundergroundCache;
@@ -1277,15 +1207,13 @@ function getWeather()
if ($curl->getResult($data) != JSON_ERROR_NONE)
return 1;
if (isset($data['response']['results']) && count($data['response']['results']) > 0 && $iMax >= 0)
{
if (isset($data['response']['results']) && count($data['response']['results']) > 0 && $iMax >= 0) {
$iMax--;
setConfig('main:weather.wundergroundCache', $data['response']['results'][0]['zmw']);
continue;
}
}
while (false);
} while (false);
if (!isset($data['current_observation']))
return 1;
@@ -1305,9 +1233,7 @@ function getWeather()
$output['wind'] = str_replace('.', ',', round($data['wind_kph']));
$output['icon'] = getWeatherIconWunderground(isset($matches[1]) ? $matches[1] : $data['icon']);
$output['description'] = $data['weather'];
}
elseif ($service == 'darksky')
{
} elseif ($service == 'darksky') {
$lang = $globalLanguage;
$curl = new cURL('https://api.darksky.net/forecast/' . $serviceToken . '/' . $latitude . ',' . $longitude . '?lang=' . $lang . '&units=si');
@@ -1335,15 +1261,11 @@ function getWeather()
$output['wind'] = str_replace('.', ',', round($data['windSpeed']));
$output['icon'] = getWeatherIconDarksky($data['icon']);
$output['description'] = $data['summary'];
}
elseif ($service == 'yr')
{
} elseif ($service == 'yr') {
$yrCache = getConfig('main:weather.yrCache', '');
if ($yrCache == '')
{
switch ($country)
{
if ($yrCache == '') {
switch ($country) {
case 'germany':
$customCountry = 'de';
break;
@@ -1401,8 +1323,7 @@ function getWeather()
function getYrQueryFromLocation($location, $country)
{
if (!class_exists('cURL'))
(include LIBRARY_PATH.'curl/curl.class.php');
if (!class_exists('cURL')) (include LIBRARY_PATH . 'curl/curl.class.php');
$curl = new cURL('http://www.geonames.org/postalcode-search.html?q=' . urlencode($location) . '&country=' . $country);
$curl->execute();
@@ -1428,24 +1349,18 @@ function array_sort($array, $on, $order = SORT_ASC)
$new_array = array();
$sortable_array = array();
if (count($array) > 0)
{
foreach ($array as $k => $v)
{
if (is_array($v))
{
foreach ($v as $k2 => $v2)
{
if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on)
$sortable_array[$k] = $v2;
}
}
else
} else
$sortable_array[$k] = $v;
}
switch ($order)
{
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
@@ -1484,24 +1399,18 @@ function arraySort($array, $on, $order = SORT_ASC)
$new_array = array();
$sortable_array = array();
if (count($array) > 0)
{
foreach ($array as $k => $v)
{
if (is_array($v))
{
foreach ($v as $k2 => $v2)
{
if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on)
$sortable_array[$k] = $v2;
}
}
else
} else
$sortable_array[$k] = $v;
}
switch ($order)
{
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
@@ -1522,12 +1431,10 @@ function ipInRange($ip, $ranges)
if (!is_array($ranges))
$ranges[] = $ranges;
foreach ($ranges as $range)
{
foreach ($ranges as $range) {
$return = false;
if (strpos($range, '/') !== false)
{
if (strpos($range, '/') !== false) {
list($range, $netmask) = explode('/', $range, 2);
$blocks = explode('.', $range);
@@ -1541,18 +1448,14 @@ function ipInRange($ip, $ranges)
$netmaskLong = ~$wildcardLong;
$return = (($ipLong & $netmaskLong) == ($rangeLong & $netmaskLong));
}
else
{
if (strpos($range, '*') !== false)
{
} else {
if (strpos($range, '*') !== false) {
$lower = str_replace('*', '0', $range);
$upper = str_replace('*', '255', $range);
$range = $lower . '-' . $upper;
}
if (strpos($range, '-') !== false)
{
if (strpos($range, '-') !== false) {
list($lower, $upper) = explode('-', $range, 2);
$lowerLong = (float) sprintf('%u', ip2long($lower));
$upperLong = (float) sprintf('%u', ip2long($upper));
@@ -1560,8 +1463,7 @@ function ipInRange($ip, $ranges)
$return = (($ipLong >= $lowerLong) && ($ipLong <= $upperLong));
}
if (filter_var($range, FILTER_VALIDATE_IP))
{
if (filter_var($range, FILTER_VALIDATE_IP)) {
$rangeLong = ip2long($range);
$ipLong = ip2long($ip);
$return = ($ipLong == $rangeLong);
@@ -1580,10 +1482,11 @@ function getLanguageFromIso($isoCode)
if (empty($isoCode))
return false;
switch ($isoCode)
{
case 'de': return _t('Deutsch');
case 'en': return _t('Englisch');
switch ($isoCode) {
case 'de':
return _t('Deutsch');
case 'en':
return _t('Englisch');
}
return false;
@@ -1606,15 +1509,19 @@ function getInfoForHeaderBar()
{
$type = getConfig('main:headerInfo.type', 'disable');
switch ($type)
{
case 'label': return getConfig('main:main.label', 'Raspberry Pi');
case 'label-ip': return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), $_SERVER['SERVER_ADDR']);
case 'label-hostname': return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), trim(@shell_exec('cat /proc/sys/kernel/hostname')));
case 'ip': return $_SERVER['SERVER_ADDR'];
case 'hostname': return trim(@shell_exec('cat /proc/sys/kernel/hostname'));
switch ($type) {
case 'label':
return getConfig('main:main.label', 'Raspberry Pi');
case 'label-ip':
return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), $_SERVER['SERVER_ADDR']);
case 'label-hostname':
return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), trim(@shell_exec('cat /proc/sys/kernel/hostname')));
case 'ip':
return $_SERVER['SERVER_ADDR'];
case 'hostname':
return trim(@shell_exec('cat /proc/sys/kernel/hostname'));
case 'disable':
default: return false;
default:
return false;
}
}
?>

View File

@@ -3,14 +3,12 @@ if (!defined('PICONTROL')) exit();
function rpi_getRuntime()
{
$runtime = trim(@shell_exec('cat /proc/uptime | awk -F \'.\' \'{print $1}\''));
return $runtime;
return trim(@shell_exec('cat /proc/uptime | awk -F \'.\' \'{print $1}\''));
}
function rpi_getHostname()
{
$host = trim(@shell_exec('cat /proc/sys/kernel/hostname'));
return $host;
return trim(@shell_exec('cat /proc/sys/kernel/hostname'));
}
function rpi_getHostAddr()
@@ -75,34 +73,32 @@ function rpi_getCPUType()
if (isset($match[1]))
return $match[1];
return NULL;
return null;
}
function rpi_getCpuModel()
{
$model = trim(@shell_exec('cat /proc/cpuinfo | grep -m 1 "model name" | tr -d " " | cut -d ":" -f 2'));
return $model;
return trim(@shell_exec('cat /proc/cpuinfo | grep -m 1 "Model" | cut -d ":" -f 2'));
}
function rpi_getCPULoad($accurate = false, $mulitcore = false)
{
$return = NULL;
$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 = shell_exec('cat /proc/stat; echo "##--##"; cat /proc/stat');
$file = explode('##--##', $file);
if (!isset($file[0], $file[1]))
return NULL;
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++)
{
for ($i = 0; $i < count($prevCPUStrings[0]); $i++) {
$prevCPU = preg_split('/\s+/', $prevCPUStrings[0][$i]);
$curCPU = preg_split('/\s+/', $curCPUStrings[0][$i]);
@@ -111,7 +107,7 @@ function rpi_getCPULoad($accurate = false, $mulitcore = false)
if (!isset($prevCPU[0], $curCPU[1]) || count($prevCPU) != 11 || count($curCPU) != 11)
return NULL;
return null;
$prevIdle = $prevCPU[4] + $prevCPU[5];
$curIdle = $curCPU[4] + $curCPU[5];
@@ -125,7 +121,7 @@ function rpi_getCPULoad($accurate = false, $mulitcore = false)
$total = $curTotal - $prevTotal;
$idle = $curIdle - $prevIdle;
if ($mulitcore == true)
if ($mulitcore)
$return[$prevCPU[0]] = (int) round(($total - $idle) / $total * 100);
else
$return = (int) round(($total - $idle) / $total * 100);
@@ -138,8 +134,7 @@ function rpi_getDistribution()
{
$distribution = trim(@shell_exec('cat /etc/issue | cut -d " " -f 1-3'));
if ($distribution == '')
{
if ($distribution == '') {
$distributionString = @shell_exec('cat /etc/*-release | grep PRETTY_NAME');
preg_match('/.*="([\w\s\d\/]*).*"/i', $distributionString, $match);
@@ -155,27 +150,26 @@ function rpi_getDistribution()
function rpi_getKernelVersion()
{
$kernel = trim(@shell_exec('cat /proc/version | cut -d " " -f 1,3'));
return $kernel;
return trim(@shell_exec('cat /proc/version | cut -d " " -f 1,3'));
}
function rpi_getCountRunningTasks()
{
$tasks = trim(@shell_exec('ps -auxeaf| wc -l'));
return $tasks;
return trim(@shell_exec('ps -auxeaf| wc -l'));
}
function rpi_getCountInstalledPackages()
{
$packages = trim(@shell_exec('dpkg --get-selections | grep -v deinstall | wc -l'));
return $packages;
return trim(@shell_exec('dpkg --get-selections | grep -v deinstall | wc -l'));
}
function rpi_getInstalledPackages()
{
@exec('dpkg -l | grep ^ii', $packages);
$packages = array_map(function($package) { return preg_split('/[\s]+/', $package, 5); }, $packages);
$packages = array_map(function ($package) {
return preg_split('/[\s]+/', $package, 5);
}, $packages);
return $packages;
}
@@ -217,8 +211,7 @@ function rpi_getRpiRevision()
* +- Memory
*/
if (isset($match[1]))
{
if (isset($match[1])) {
if ($match[1][0] == '1' || $match[1][0] == '2')
$match[1] = substr($match[1], 1);
@@ -226,13 +219,14 @@ function rpi_getRpiRevision()
return $revision[hexdec($match[1])];
elseif (strlen($match[1]) == 6 && $match[1][0] != 'a' && $match[1][0] != '9')
return $revision[hexdec(substr($match[1], -4))];
elseif (strlen($match[1]) == 6)
{
return array('revision' => $match[1],
elseif (strlen($match[1]) == 6) {
return array(
'revision' => $match[1],
'model' => $revision_model[hexdec(substr($match[1], 3, 2))],
'pcb' => '1.' . hexdec(substr($match[1], -1)),
'memory' => $revision_memory[bindec(substr(decbin(hexdec(substr($match[1], 0, 1))), 1))],
'manufacturer' => $revision_manufacturer[hexdec(substr($match[1], 1, 1))]);
'manufacturer' => $revision_manufacturer[hexdec(substr($match[1], 1, 1))]
);
}
}
@@ -250,15 +244,14 @@ function rpi_getRpiSerial()
function rpi_getMemorySplit()
{
$rev = $this->getRpiRevision();
if ($rev >= 7)
{
if ($rev >= 7) {
// 512 MB
$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');
return array('system' => '1991 MiB', 'video' => '16 MiB');
elseif ($total == 32)
return array('system' => '480 MiB', 'video' => '32 MiB');
elseif ($total == 64)
@@ -280,29 +273,21 @@ function rpi_getMemorySplit()
elseif ($total > 192 && $total <= 224)
return array('system' => '224 MiB', 'video' => '32 MiB');
return array('system' => '240 MiB', 'video' => '16 MiB');
return array('system' => '1991 MiB', 'video' => '16 MiB');
}
function rpi_getMemoryUsage()
{
exec('free -bo 2>/dev/null || free -b', $data);
if (strpos($data[0], 'available') !== false) {
exec('free -b', $data);
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));
}
function rpi_getSwapUsage()
{
exec('free -bo 2>/dev/null || free -b', $data);
exec('free -b', $data);
list($type, $total, $used, $free) = preg_split('#\s+#', $data[2]);
$usage = (int) round($used / $total * 100);
@@ -326,12 +311,10 @@ function rpi_getMemoryInfo()
$totalSize = 0;
$usedSize = 0;
foreach ($data as $row)
{
foreach ($data as $row) {
list($device, $type, $blocks, $use, $available, $used, $mountpoint) = preg_split('#[\s%]+#i', $row);
if (multiArraySearch($devices, 'device', $device) === false)
{
if (multiArraySearch($devices, 'device', $device) === false) {
$totalSize += $blocks * 1024;
$usedSize += $use * 1024;
}
@@ -347,8 +330,7 @@ function rpi_getMemoryInfo()
);
}
usort($devices, function($a, $b)
{
usort($devices, function ($a, $b) {
return strcasecmp($a['device'], $b['device']);
});
@@ -362,8 +344,7 @@ function rpi_getUsbDevices()
exec('lsusb', $data);
$devices = array();
foreach ($data as $row)
{
foreach ($data as $row) {
preg_match('#[0-9a-f]{4}:[0-9a-f]{4}\s+(.+)#i', $row, $match);
if (count($match) == 2)
@@ -400,44 +381,43 @@ function rpi_getAllUsers()
$usersLoggedIn = array();
$usersAll = array();
foreach ($dataLoggedIn as $row)
{
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)
{
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 != '')
{
if ($userLastLoginInformation != '') {
$split = preg_split('/\s+/i', $userLastLoginInformation);
$usersAll[] = array('username' => $row,
$usersAll[] = array(
'username' => $row,
'userId' => exec('id -u ' . escapeshellarg($row)),
'groupId' => exec('id -g ' . escapeshellarg($row)),
'port' => $split[1],
'lastLoginAddress' => $split[2],
'lastLogin' => strtotime($split[4] . ' ' . $split[5] . ' ' . $split[6]),
'isLoggedIn' => isset($usersLoggedIn[$row]) ? true : false,
'loggedIn' => isset($usersLoggedIn[$row]) ? $usersLoggedIn[$row] : array());
}
else
{
$usersAll[] = array('username' => $row,
'loggedIn' => isset($usersLoggedIn[$row]) ? $usersLoggedIn[$row] : array()
);
} else {
$usersAll[] = array(
'username' => $row,
'userId' => exec('id -u ' . escapeshellarg($row)),
'groupId' => exec('id -g ' . escapeshellarg($row)),
'port' => '',
'lastLoginAddress' => '',
'lastLogin' => 0,
'isLoggedIn' => isset($usersLoggedIn[$row]) ? true : false);
'isLoggedIn' => isset($usersLoggedIn[$row]) ? true : false
);
}
}
@@ -445,4 +425,3 @@ function rpi_getAllUsers()
return $usersAll;
}
?>

View File

@@ -5,7 +5,9 @@ if (!defined('PICONTROL')) exit();
* Beschreibung. Mehr unter: http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.pkg.html
*/
class FileException extends Exception { }
class FileException extends Exception
{
}
class PiTpl
{
@@ -63,14 +65,12 @@ class PiTpl
$lang = $globalLanguage;
$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)
{
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);
}
@@ -186,8 +186,7 @@ class PiTpl
$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
@@ -235,8 +234,7 @@ class PiTpl
$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
@@ -508,8 +506,7 @@ class PiTpl
if ($this->tplFolderPathPlugin != '')
$folderPath = $this->tplFolderPathPlugin . '/public_html/templates/';
if (strlen($tplFileName) >= 1 && is_string($tplFileName))
{
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&uuml;ltige Datei.', $tplFileName), __LINE__ - 1);
}
@@ -518,8 +515,7 @@ class PiTpl
$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 &ouml;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 &ouml;ffnen und auslesen.', $tplFileName), __LINE__);
// Optisch schöner
echo PHP_EOL;
@@ -624,11 +620,12 @@ class PiTpl
if (!headers_sent($filename, $linenum))
exit(header('Location: ' . $url));
else
{
self::error(self::_t('Weiterleitung'),
else {
self::error(
self::_t('Weiterleitung'),
'<strong class="red">' . self::_t('Header bereits gesendet. Redirect nicht m&ouml;glich, klicke daher stattdessen <a href="%s">diesen Link</a> an.', $url) . '</strong>',
true);
true
);
}
return true;
@@ -661,18 +658,17 @@ 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) ||
if (
!strlen($type) > 0 || !is_string($type) ||
!strlen($msg) > 0 || !is_string($msg)
)
return false;
if ($id > 0)
{
if ($id > 0) {
$this->tplMsg[$id + 100] = array($type, $title, $msg, $cancelable);
}
else
} else
$this->tplMsg[] = array($type, $title, $msg, $cancelable);
return true;
@@ -702,8 +698,7 @@ class PiTpl
if (file_exists($this->tplFolderPath . 'msg' . $this->tplFileSuffix) !== true || is_file($this->tplFolderPath . 'msg' . $this->tplFileSuffix) !== true)
return false;
foreach ($this->tplMsg as $key => $msg)
{
foreach ($this->tplMsg as $key => $msg) {
$data['id'] = $key;
$data['type'] = $msg[0];
$data['title'] = $msg[1];
@@ -728,8 +723,7 @@ class PiTpl
{
set_include_path(LIBRARY_PATH . 'terminal');
if (!class_exists('Net_SSH2'))
{
if (!class_exists('Net_SSH2')) {
include(LIBRARY_PATH . 'terminal/Net/SSH2.php');
include(LIBRARY_PATH . 'terminal/File/ANSI.php');
include(LIBRARY_PATH . 'terminal/Crypt/RSA.php');
@@ -757,14 +751,12 @@ class PiTpl
$ssh = new Net_SSH2('127.0.0.1', $sshPort);
if ($sshType == 'password')
{
if ($sshType == 'password') {
if (!$ssh->login($sshUsername, $sshPassword))
return false;
}
if ($sshType == 'publickey')
{
if ($sshType == 'publickey') {
$sshKey = new Crypt_RSA();
if ($sshPassword != '')
@@ -833,11 +825,9 @@ class PiTpl
public function getSSHResource($cancelIfError = 0)
{
if ($this->tplSSH === NULL)
if (self::loadSSH() !== true)
{
if (self::loadSSH() !== true) {
if ($cancelIfError !== 0)
self::error(_t('SSH-Zugriffsfehler'), _t('Kein SSH-Zugriff, diese Funktion steht aktuell nicht zur Verfügung!'), ($cancelIfError === 1) ? true : false);
#self::error(_t('SSH-Zugriffsfehler'), _t('Kein SSH-Zugriff, bitte anmelden! <a href="%s">Jetzt anmelden.</a>', '?s=ssh_login'), ($cancelIfError === 1) ? true : false);
self::error(_t('SSH-Zugriffsfehler'), _t('Kein SSH-Zugriff, bitte anmelden! <a href="%s">Jetzt anmelden.</a>', '?s=ssh_login'), ($cancelIfError === 1) ? true : false);
return false;
}
@@ -859,8 +849,7 @@ class PiTpl
$sshPort = getConfig('ssh:latest.port', 22);
$sshUsername = getConfig('ssh:latest.username', '');
if (isset($_COOKIE['_pi-control_ssh']) && $_COOKIE['_pi-control_ssh'] != '')
{
if (isset($_COOKIE['_pi-control_ssh']) && $_COOKIE['_pi-control_ssh'] != '') {
$token = $_COOKIE['_pi-control_ssh'];
$sshType = getConfig('ssh:token_' . $token . '.type', $sshType);
@@ -900,8 +889,7 @@ class PiTpl
if ($privateKey != '' && is_string($privateKey))
$SSHInfo['privateKey'] = $privateKey;
if ($password != '')
{
if ($password != '') {
if (isset($_COOKIE['_pi-control_ssh']) && $_COOKIE['_pi-control_ssh'] != '')
$this->logoutSSH();
@@ -926,13 +914,10 @@ class PiTpl
setConfig('ssh:latest.port', $SSHInfo['port']);
setConfig('ssh:latest.username', $SSHInfo['username']);
if ($rememberMe == false)
{
if ($rememberMe == false) {
setcookie('_pi-control_ssh', $uniqid, time() + 60 * 60 * 12);
setcookie('_pi-control_ssh_' . $uniqid, $uniqid2, time() + 60 * 60 * 12);
}
else
{
} else {
setcookie('_pi-control_ssh', $uniqid, time() + 60 * 60 * 24 * 30);
setcookie('_pi-control_ssh_' . $uniqid, $uniqid2, time() + 60 * 60 * 24 * 30);
}
@@ -954,8 +939,7 @@ class PiTpl
public function logoutSSH()
{
if (isset($_COOKIE['_pi-control_ssh']) && $_COOKIE['_pi-control_ssh'] != '')
{
if (isset($_COOKIE['_pi-control_ssh']) && $_COOKIE['_pi-control_ssh'] != '') {
$token = $_COOKIE['_pi-control_ssh'];
removeConfig('ssh:token_' . $token);
@@ -968,4 +952,3 @@ class PiTpl
return true;
}
}
?>

View File

@@ -14,41 +14,32 @@ function checkTemperatureMonitoringEmailStatus()
curl_setopt($curl, CURLOPT_URL, $config['url']['temperatureMonitoring'] . '?' . http_build_query(array('id' => $id, 'code' => $code, 'email' => $email)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
do
{
if (($data = curl_exec($curl)) === false)
{
do {
if (($data = curl_exec($curl)) === false) {
$info = curl_getinfo($curl);
$tpl->msg('error', _t('Verbindungsfehler'), _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d (%s)', $info['http_code'], curl_error($curl)), true, 12);
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d (%s)', _t('Verbindungsfehler'), $info['http_code'], curl_error($curl)), true, 12);
break;
}
else
{
} else {
$info = curl_getinfo($curl);
if ($info['http_code'] == 404)
{
$tpl->msg('error', _t('Verbindungsfehler'), _t('Leider konnte keine Verbindung zum Server hergestellt werden, da dieser momentan vermutlich nicht erreichbar ist. Fehlercode: %d', $info['http_code']), true, 12);
if ($info['http_code'] == 404) {
$tpl->msg('error', _t('Leider konnte keine Verbindung zum Server hergestellt werden, da dieser momentan vermutlich nicht erreichbar ist. Fehlercode: %d', _t('Verbindungsfehler'), $info['http_code']), true, 12);
break;
}
elseif ($info['http_code'] != 200)
{
$tpl->msg('error', _t('Verbindungsfehler'), _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d', $info['http_code']), true, 12);
} elseif ($info['http_code'] != 200) {
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d', $info['http_code']), _t('Verbindungsfehler'), true, 12);
break;
}
if ($data == '')
{
$tpl->msg('error', _t('Serverfehler'), _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine leere Antwort.'), true, 12);
if ($data == '') {
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine leere Antwort.'), _t('Serverfehler'), true, 12);
break;
}
// Verarbeite Datenstring
$json = json_decode($data, true);
if (json_last_error() != JSON_ERROR_NONE || !isset($json['existing'], $json['email'], $json['code']))
{
$tpl->msg('error', _t('Verarbeitungsfehler'), _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine fehlerhafte Antwort.'), true, 12);
if (json_last_error() != JSON_ERROR_NONE || !isset($json['existing'], $json['email'], $json['code'])) {
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine fehlerhafte Antwort.'), _t('Verarbeitungsfehler'), true, 12);
break;
}
@@ -56,8 +47,7 @@ function checkTemperatureMonitoringEmailStatus()
if ($json['existing'] == false || $json['email'] == false || $json['code'] == false)
setConfig('main:monitoringCpuTemp.code', '');
}
}
while (false);
} while (false);
curl_close($curl);
}
@@ -74,56 +64,43 @@ function checkTemperatureMonitoringEmailCode()
curl_setopt($curl, CURLOPT_URL, $config['url']['temperatureMonitoring'] . '?' . http_build_query(array('id' => $id, 'code' => true, 'email' => $email)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
do
{
if (($data = curl_exec($curl)) === false)
{
do {
if (($data = curl_exec($curl)) === false) {
$info = curl_getinfo($curl);
$tpl->msg('error', _t('Verbindungsfehler'), _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d (%s)', $info['http_code'], curl_error($curl)), true, 12);
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d (%s)', _t('Verbindungsfehler'), $info['http_code'], curl_error($curl)), true, 12);
break;
}
else
{
} else {
$info = curl_getinfo($curl);
if ($info['http_code'] == 404)
{
$tpl->msg('error', _t('Verbindungsfehler'), _t('Leider konnte keine Verbindung zum Server hergestellt werden, da dieser momentan vermutlich nicht erreichbar ist. Fehlercode: %d', $info['http_code']), true, 12);
if ($info['http_code'] == 404) {
$tpl->msg('error', _t('Leider konnte keine Verbindung zum Server hergestellt werden, da dieser momentan vermutlich nicht erreichbar ist. Fehlercode: %d', _t('Verbindungsfehler'), $info['http_code']), true, 12);
break;
}
elseif ($info['http_code'] != 200)
{
$tpl->msg('error', _t('Verbindungsfehler'), _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d', $info['http_code']), true, 12);
} elseif ($info['http_code'] != 200) {
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein unerwarteter Fehler aufgetreten. Fehlercode: %d', $info['http_code']), _t('Verbindungsfehler'), true, 12);
break;
}
if ($data == '')
{
$tpl->msg('error', _t('Serverfehler'), _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine leere Antwort.'), true, 12);
if ($data == '') {
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine leere Antwort.'), _t('Serverfehler'), true, 12);
break;
}
// Verarbeite Datenstring
$json = json_decode($data, true);
if (json_last_error() != JSON_ERROR_NONE || !isset($json['existing'], $json['email'], $json['code']))
{
$tpl->msg('error', _t('Verarbeitungsfehler'), _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine fehlerhafte Antwort.'), true, 12);
if (json_last_error() != JSON_ERROR_NONE || !isset($json['existing'], $json['email'], $json['code'])) {
$tpl->msg('error', _t('Bei der Verbindung zum Server ist ein Fehler aufgetreten. Der Server sendet eine fehlerhafte Antwort.'), _t('Verarbeitungsfehler'), true, 12);
break;
}
// Antwort in Ordnung
if ($json['code'] != false && strlen($json['code']) == 16)
{
if ($json['code'] != false && strlen($json['code']) == 16) {
setConfig('main:monitoringCpuTemp.code', $json['code']);
$tpl->msg('success', _t('E-Mail best&auml;tigt'), _t('Deine E-Mail wurde erfolgreich best&auml;tigt.'));
$tpl->msg('success', _t('Deine E-Mail wurde erfolgreich best&auml;tigt.'), _t('E-Mail best&auml;tigt'));
} else
$tpl->msg('error', _t('Der Server konnte zugeh&ouml;rige Daten nicht finden. Versichere, dass du die E-Mail best&auml;tigt hast.'), _t('Verarbeitungsfehler'), true, 12);
}
else
$tpl->msg('error', _t('Verarbeitungsfehler'), _t('Der Server konnte zugeh&ouml;rige Daten nicht finden. Versichere, dass du die E-Mail best&auml;tigt hast.'), true, 12);
}
}
while (false);
} while (false);
curl_close($curl);
}
?>

View File

@@ -127,7 +127,7 @@ class LogStatistic
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));
$this->stream = fopen($this->file, 'r+');# || exit(_t('Konnte Log-Datei nicht &ouml;ffnen: %s', $this->file));
}
}
@@ -282,6 +282,17 @@ class StatisticBuilder
$this->suffix = isset($suffix) ? $suffix : NULL;
$this->label = _t($statistic['label']);
$this->unit = $statistic['unit'];
if ($statistic['unit'] == 'MB') {
$log = new LogStatistic();
$log->setFile(LOG_PATH . $this->raw . '.csv');
$lastValue = $log->getLast();
$log->close();
if ($lastValue && $lastValue[1] > 999999999) {
$this->unit = 'GB';
$this->label = 'GB';
}
}
$this->cycle = $statistic['cycle'];
$this->limits = $statistic['limits'];

View File

@@ -84,7 +84,7 @@ $statisticConfig = array(
'fix' => true
),
'max' => array(
'value' => 1200,
'value' => 2100,
'use' => 'fix',
'fix' => true
)

View File

@@ -25,10 +25,8 @@ function calculateEmptyRows(&$arr, $columns, $firstTime, $lastTime, $cycle)
{
$buffer = array();
if ($lastTime < (time() - ($cycle * 60)))
{
for ($i = 0; $i < ceil(((time() - ($cycle * 60)) - $lastTime) / ($cycle * 60)); $i++)
{
if ($lastTime < (time() - ($cycle * 60))) {
for ($i = 0; $i < ceil(((time() - ($cycle * 60)) - $lastTime) / ($cycle * 60)); $i++) {
$dummy = array($lastTime + (($i + 1) * ($cycle * 60)));
for ($j = 1; $j < count($columns); $j++)
@@ -41,10 +39,8 @@ function calculateEmptyRows(&$arr, $columns, $firstTime, $lastTime, $cycle)
$buffer = array();
if (isset($arr['rows']) && count($arr['rows']) < (604800 / ($cycle * 60)))
{
for ($i = 0; $i < ((604800 / ($cycle * 60)) - count($arr['rows'])); $i++)
{
if (isset($arr['rows']) && count($arr['rows']) < (604800 / ($cycle * 60))) {
for ($i = 0; $i < ((604800 / ($cycle * 60)) - count($arr['rows'])); $i++) {
$dummy = array($firstTime - (($i + 1) * ($cycle * 60)));
for ($j = 1; $j < count($columns); $j++)
@@ -63,19 +59,16 @@ function getRowsFromLog(&$arr, &$info, $log, $columns, $cycle)
$leapyear = -1;
$leapyearSkip = 0;
foreach ($log as $row)
{
foreach ($log as $row) {
foreach ($row as &$data)
$data = trim($data);
if ($leapyearSkip != 0)
{
if ($leapyearSkip != 0) {
$leapyearSkip--;
continue;
}
if ($leapyear != -1 && $leapyear > date('I', $row[0]))
{
if ($leapyear != -1 && $leapyear > date('I', $row[0])) {
$leapyear = 0;
$leapyearSkip = (60 / $cycle) - 1;
continue;
@@ -83,11 +76,9 @@ function getRowsFromLog(&$arr, &$info, $log, $columns, $cycle)
$leapyear = date('I', $row[0]);
if ($lastTime !== NULL && ($lastTime + ($cycle * 60) + 100) < $row[0])
{
if ($lastTime !== NULL && ($lastTime + ($cycle * 60) + 100) < $row[0]) {
$skipped = round(($row[0] - ($lastTime + ($cycle * 60))) / ($cycle * 60));
for ($i = 0; $i < $skipped; $i++)
{
for ($i = 0; $i < $skipped; $i++) {
$dummy = array($lastTime + (($i + 1) * ($cycle * 60)));
for ($j = 1; $j < count($columns); $j++)
@@ -99,13 +90,15 @@ function getRowsFromLog(&$arr, &$info, $log, $columns, $cycle)
$dummy = array((int) $row[0]);
for ($i = 1; $i < count($columns); $i++)
{
for ($i = 1; $i < count($columns); $i++) {
$rowFloat = 0;
if (isset($columns[$i]['division']))
if (isset($columns[$i]['division'])) {
if ((float)$log[count($log) - 1][1] > 999999999)
$rowFloat = (float) round(str_replace(array("\n", ','), array('', '.'), $row[$i]) / $columns[$i]['division'] / 1024, 2);
else
$rowFloat = (float) round(str_replace(array("\n", ','), array('', '.'), $row[$i]) / $columns[$i]['division'], 2);
elseif (isset($columns[$i]['multiplication']))
} elseif (isset($columns[$i]['multiplication']))
$rowFloat = (float) round(str_replace(array("\n", ','), array('', '.'), $row[$i]) * $columns[$i]['multiplication'], 2);
else
$rowFloat = (float) $row[$i];
@@ -133,8 +126,7 @@ function getRowsFromLog(&$arr, &$info, $log, $columns, $cycle)
function convertForGoogleChart($rows)
{
foreach ($rows as $index => $row)
{
foreach ($rows as $index => $row) {
$dummy = array('c' => array(array('v' => 'Date(' . date('Y,' . (date('m', $row[0]) - 1) . ',d,H,i', $row[0]) . ')')));
unset($row[0]);
@@ -147,4 +139,3 @@ function convertForGoogleChart($rows)
return $rows;
}
?>

View File

@@ -253,7 +253,8 @@ class UpdateController
if (!class_exists('cURL'))
(include LIBRARY_PATH.'curl/curl.class.php');
$curl = new cURL($this->updateDownloadURL.'&'.http_build_query(array('file' => $version->getFilename())));
$curl = new cURL($this->updateDownloadURL . $version->getFilename());
$curlStatus = $curl->downloadFile(UPDATE_PATH.'update.zip');
if (!is_bool($curlStatus))
@@ -268,7 +269,7 @@ class UpdateController
return $curl->getStatusCode();
}
if (md5_file(UPDATE_PATH.'update.zip') !== $version->getChecksum())
if (hash_file('sha256', UPDATE_PATH.'update.zip') !== $version->getChecksum())
{
unlink(UPDATE_PATH.'update.zip');
return 1;
@@ -439,4 +440,3 @@ class Update
}
}
?>