Init
This commit is contained in:
20
backend/resources/cron/30-user.php
Normal file
20
backend/resources/cron/30-user.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
|
||||
$loggedInUsers = getConfig('login');
|
||||
unset($loggedInUsers['login']);
|
||||
|
||||
foreach ($loggedInUsers as $token => $user)
|
||||
{
|
||||
if ($user['created'] < time()-60*60*12 && !(isset($user['remember_me']) && $user['remember_me'] == 'true'))
|
||||
removeConfig('login:'.$token);
|
||||
|
||||
if ($user['created'] < time()-60*60*24*30 && (isset($user['remember_me']) && $user['remember_me'] == 'true'))
|
||||
removeConfig('login:'.$token);
|
||||
}
|
||||
?>
|
||||
15
backend/resources/cron/5-coretemp.php
Normal file
15
backend/resources/cron/5-coretemp.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
const PICONTROL = true;
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0003');
|
||||
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'statistic/coretemp.csv');
|
||||
$log->setLimit(2016);
|
||||
$log->add(array(time(), rpi_getCoreTemprature()));
|
||||
$log->close();
|
||||
17
backend/resources/cron/5-cpufrequency.php
Normal file
17
backend/resources/cron/5-cpufrequency.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0003');
|
||||
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'statistic/cpufrequency.csv');
|
||||
$log->setLimit(2016);
|
||||
sleep(7);
|
||||
$log->add(array(time(), rpi_getCpuClock()));
|
||||
$log->close();
|
||||
?>
|
||||
16
backend/resources/cron/5-cpuload.php
Normal file
16
backend/resources/cron/5-cpuload.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0003');
|
||||
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'statistic/cpuload.csv');
|
||||
$log->setLimit(2016);
|
||||
$log->add(array(time(), rpi_getCPULoad(true)));
|
||||
$log->close();
|
||||
?>
|
||||
19
backend/resources/cron/5-memory.php
Normal file
19
backend/resources/cron/5-memory.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0003');
|
||||
|
||||
$memories = rpi_getMemoryInfo();
|
||||
$memory = end($memories);
|
||||
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'statistic/memory.csv');
|
||||
$log->setLimit(2016);
|
||||
$log->add(array(time(), $memory['total'], $memory['used']));
|
||||
$log->close();
|
||||
?>
|
||||
59
backend/resources/cron/5-network.php
Normal file
59
backend/resources/cron/5-network.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0003');
|
||||
|
||||
$networkConnections = getAllNetworkConnections();
|
||||
$networkCounts = unserialize(htmlspecialchars_decode(getConfig('main:network.overflowCount', 'a:0:{}')));
|
||||
|
||||
foreach ($networkConnections as $network)
|
||||
{
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'statistic/network_'.$network['interface'].'.csv');
|
||||
$log->setLimit(2016);
|
||||
|
||||
$last = $log->getLast();
|
||||
|
||||
$countSent = 0;
|
||||
$countReceive = 0;
|
||||
|
||||
if (isset($networkCounts[$network['interface']]['sent']))
|
||||
$countSent = $networkCounts[$network['interface']]['sent'];
|
||||
|
||||
if (isset($networkCounts[$network['interface']]['receive']))
|
||||
$countReceive = $networkCounts[$network['interface']]['receive'];
|
||||
|
||||
$rpiRuntime = rpi_getRuntime();
|
||||
|
||||
if ((time() - $rpiRuntime) < (int) $last[0] && (float) $last[1] > (float) ($network['sent'] + 4294967295 * $countSent))
|
||||
$countSent++;
|
||||
|
||||
if ((time() - $rpiRuntime) < (int) $last[0] && (float) $last[2] > (float) ($network['receive'] + 4294967295 * $countReceive))
|
||||
$countReceive++;
|
||||
|
||||
if ((time() - $rpiRuntime) > (int) $last[0] && (int) $last[0] != 0)
|
||||
{
|
||||
$countSent = 0;
|
||||
$countReceive = 0;
|
||||
}
|
||||
|
||||
$networkCounts[$network['interface']]['sent'] = $countSent;
|
||||
$networkCounts[$network['interface']]['receive'] = $countReceive;
|
||||
|
||||
$log->add(array(time(), ($last[1] + (4294967295 * $countSent - $last[1]) + $network['sent']), ($last[2] + (4294967295 * $countReceive - $last[2]) + $network['receive'])));
|
||||
$log->close();
|
||||
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'statistic/network_packets_'.$network['interface'].'.csv');
|
||||
$log->setLimit(2016);
|
||||
$log->add(array(time(), $network['packets']['sent'], $network['packets']['received']));
|
||||
$log->close();
|
||||
}
|
||||
|
||||
setConfig('main:network.overflowCount', htmlspecialchars(serialize($networkCounts)));
|
||||
?>
|
||||
18
backend/resources/cron/5-ram.php
Normal file
18
backend/resources/cron/5-ram.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0003');
|
||||
|
||||
$ram = rpi_getMemoryUsage();
|
||||
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'statistic/ram.csv');
|
||||
$log->setLimit(2016);
|
||||
$log->add(array(time(), $ram['percent']));
|
||||
$log->close();
|
||||
?>
|
||||
35
backend/resources/cron/init.php
Normal file
35
backend/resources/cron/init.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
const PICONTROL = true;
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
|
||||
$folder = CRON_PATH;
|
||||
$fileArray = array();
|
||||
|
||||
foreach (@scandir($folder) as $file)
|
||||
{
|
||||
if ($file[0] != '.')
|
||||
{
|
||||
if (is_file($folder.'/'.$file) && $file != 'init.php')
|
||||
$fileArray[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fileArray as $file)
|
||||
{
|
||||
$timeOfFile = str_replace('-', '', substr($file, 0, 2));
|
||||
$rest = date('i', time()) % $timeOfFile;
|
||||
|
||||
if (is_numeric($rest) && $rest == 0)
|
||||
{
|
||||
exec('/usr/bin/php -f "'.CRON_PATH.$file.'"');
|
||||
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: ')) != '' || 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());
|
||||
Reference in New Issue
Block a user