make cronjobs also classes and began to refactor the whole cronjob stuff

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-19 08:55:23 +01:00
parent a25150babf
commit 903b775f79
52 changed files with 460 additions and 523 deletions

View File

@@ -63,9 +63,9 @@ function storeDefaultIndex($loginname = null, $destination = null, $logger = nul
} else {
$destination = makeCorrectDir($destination);
if ($logger !== null) {
$logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
$logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . \Froxlor\Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
}
safe_exec('cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
safe_exec('cp -a ' . \Froxlor\Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
}
}
return;

View File

@@ -1,140 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2014 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* 1st: check for task of generation
* 2nd: if task found, generate cron.d-file
* 3rd: maybe restart cron?
*/
function checkCrondConfigurationFile() {
// check for task
$result_tasks_stmt = Database::query("
SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'
");
$num_results = Database::num_rows();
// is there a task for re-generating the cron.d-file?
if ($num_results > 0) {
// get all crons and their intervals
if (isFreeBSD()) {
// FreeBSD does not need a header as we are writing directly to the crontab
$cronfile = "\n";
} else {
$cronfile = "# automatically generated cron-configuration by froxlor\n";
$cronfile.= "# do not manually edit this file as it will be re-generated periodically.\n";
$cronfile.= "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n#\n";
}
// get all the crons
$result_stmt = Database::query("
SELECT * FROM `" . TABLE_PANEL_CRONRUNS . "` WHERE `isactive` = '1'
");
$hour_delay = 0;
$day_delay = 5;
$month_delay = 7;
while ($row_cronentry = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
// create cron.d-entry
if (preg_match("/(\d+) (MINUTE|HOUR|DAY|WEEK|MONTH)/", $row_cronentry['interval'], $matches)) {
if ($matches[1] == 1) {
$minvalue = "*";
} else {
$minvalue = "*/".$matches[1];
}
switch($matches[2]) {
case "MINUTE":
$cronfile .= $minvalue . " * * * * ";
break;
case "HOUR":
$cronfile .= $hour_delay." " . $minvalue . " * * * ";
$hour_delay += 3;
break;
case "DAY":
if ($row_cronentry['cronfile'] == 'traffic') {
// traffic at exactly 0:00 o'clock
$cronfile .= "0 0 " . $minvalue . " * * ";
} else {
$cronfile .= $day_delay." 0 " . $minvalue . " * * ";
$day_delay += 5;
}
break;
case "MONTH":
$cronfile .= $month_delay." 0 1 " . $minvalue . " * ";
$month_delay += 7;
break;
case "WEEK":
$cronfile .= $day_delay." 0 " . ($matches[1] * 7) . " * * ";
$day_delay += 5;
break;
}
// create entry-line
$binpath = Settings::Get("system.croncmdline");
// fallback as it is important
if ($binpath === null) {
$binpath = "/usr/bin/nice -n 5 /usr/bin/php5 -q";
}
$cronfile .= "root " . $binpath." " . FROXLOR_INSTALL_DIR . "/scripts/froxlor_master_cronjob.php --" . $row_cronentry['cronfile'] . " 1> /dev/null\n";
}
}
if (isFreeBSD()) {
// FreeBSD handles the cron-stuff in another way. We need to directly
// write to the crontab file as there is not cron.d/froxlor file
// (settings for system.cronconfig should be set correctly of course)
$crontab = file_get_contents(Settings::Get("system.cronconfig"));
if ($crontab === false) {
die("Oh snap, we cannot read the crontab file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// now parse out / replace our entries
$crontablines = explode("\n", $crontab);
$newcrontab = "";
foreach ($crontablines as $ctl) {
$ctl = trim($ctl);
if (!empty($ctl) && !preg_match("/(.*)froxlor_master_cronjob\.php(.*)/", $ctl)) {
$newcrontab .= $ctl."\n";
}
}
// re-assemble old-content + new froxlor-content
$newcrontab .= $cronfile;
// now continue with writing the file
$cronfile = $newcrontab;
}
// write the file
if (file_put_contents(Settings::Get("system.cronconfig"), $cronfile) === false) {
// oh snap cannot create new crond-file
die("Oh snap, we cannot create the cron-file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// correct permissions
chmod(Settings::Get("system.cronconfig"), 0640);
// remove all re-generation tasks
Database::query("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'");
// run reload command
safe_exec(escapeshellcmd(Settings::Get('system.crondreload')));
}
return true;
}

View File

@@ -62,7 +62,7 @@ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot
// File names
$domain_file = makeCorrectFile(Settings::Get('system.awstats_conf').'/awstats.' . $siteDomain . '.conf');
$model_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstats/awstats.froxlor.model.conf';
$model_file = \Froxlor\Froxlor::getInstallDir().'/templates/misc/awstats/awstats.froxlor.model.conf';
$model_file = makeCorrectFile($model_file);
// Test if the file exists

View File

@@ -22,7 +22,7 @@
*/
function getThemes() {
$themespath = makeCorrectDir(FROXLOR_INSTALL_DIR.'/templates/');
$themespath = makeCorrectDir(\Froxlor\Froxlor::getInstallDir().'/templates/');
$themes_available = array();
if (is_dir($themespath)) {

View File

@@ -26,9 +26,9 @@ function phpErrHandler($errno, $errstr, $errfile, $errline, $errcontext) {
$theme = "Sparkle";
}
// prevent possible file-path-disclosure
$errfile = str_replace(FROXLOR_INSTALL_DIR, "", $errfile);
$errfile = str_replace(\Froxlor\Froxlor::getInstallDir(), "", $errfile);
// if we're not on the shell, output a nicer error-message
$err_hint = file_get_contents(FROXLOR_INSTALL_DIR.'/templates/'.$theme.'/misc/phperrornice.tpl');
$err_hint = file_get_contents(\Froxlor\Froxlor::getInstallDir().'/templates/'.$theme.'/misc/phperrornice.tpl');
// replace values
$err_hint = str_replace("<TEXT>", '#'.$errno.' '.$errstr, $err_hint);
$err_hint = str_replace("<DEBUG>", $errfile.':'.$errline, $err_hint);

View File

@@ -76,24 +76,7 @@ function isFroxlorVersion($to_check = null) {
return false;
}
/**
* Function hasUpdates
*
* checks if a given version is not equal the current one
*
* @param string $to_check version to check
*
* @return bool true if version to check does not match, else false
*/
function hasUpdates($to_check = null) {
if (Settings::Get('panel.version') == null
|| Settings::Get('panel.version') != $to_check
) {
return true;
}
return false;
}
/**
* Function showUpdateStep
@@ -208,25 +191,6 @@ function isDatabaseVersion($to_check = null) {
return false;
}
/**
* Function hasUpdates
*
* checks if a given database-version is not equal the current one
*
* @param int $to_check version to check
*
* @return bool true if version to check does not match, else false
*/
function hasDbUpdates($to_check = null) {
if (Settings::Get('panel.db_version') == null
|| Settings::Get('panel.db_version') != $to_check
) {
return true;
}
return false;
}
/**
* Function updateToDbVersion
*

View File

@@ -1,44 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Daniel Reichelt <hacking@nachtgeist.net> (2016-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function getLogLevelDesc($type) {
switch($type) {
case LOG_INFO:
$_type = 'information';
break;
case LOG_NOTICE:
$_type = 'notice';
break;
case LOG_WARNING:
$_type = 'warning';
break;
case LOG_ERR:
$_type = 'error';
break;
case LOG_CRIT:
$_type = 'critical';
break;
case LOG_DEBUG:
$_type = 'debug';
break;
default:
$_type = 'unknown';
break;
}
return $_type;
}