|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/* * *************************************************************************
|
|
|
|
|
|
|
|
|
|
pseudo-cron v1.2.1.con // modified version for contenido
|
|
|
|
@ -118,20 +119,14 @@ if(!defined('CON_FRAMEWORK')) {
|
|
|
|
|
// || PLEASE NOTE:
|
|
|
|
|
// || all paths used here and in cron scripts
|
|
|
|
|
// || must be absolute or relative to the script which includes pseudo-cron.inc.php!
|
|
|
|
|
|
|
|
|
|
// the file that contains the job descriptions
|
|
|
|
|
// for a description of the format, see http://www.unixgeeks.org/security/newbie/unix/cron-1.html
|
|
|
|
|
// and http://www.bitfolge.de/pseudocron
|
|
|
|
|
$PC_cronTab = $cfg["path"]["contenido"].$cfg['path']['cronjobs']."crontab.txt";
|
|
|
|
|
$PC_localCronTab = $cfg["path"]["contenido"].$cfg['path']['cronjobs']."crontab.local.txt";
|
|
|
|
|
$PC_cronTab = $cfg['path']['conlite_cronlog'] . "crontab.txt";
|
|
|
|
|
$PC_localCronTab = $cfg['path']['conlite_cronlog'] . "crontab.local.txt";
|
|
|
|
|
|
|
|
|
|
// the directory where the script can store information on completed jobs and its log file
|
|
|
|
|
// include trailing slash
|
|
|
|
|
$PC_writeDir = $cfg["path"]["contenido"].$cfg['path']['cronjobs'];
|
|
|
|
|
|
|
|
|
|
// the directory where the script can store information on completed jobs and its log file
|
|
|
|
|
// include trailing slash
|
|
|
|
|
$PC_jobDir = $cfg["path"]["contenido"].$cfg['path']['cronjobs'];
|
|
|
|
|
$PC_writeDir = $cfg['path']['conlite_cronlog'];
|
|
|
|
|
$PC_jobDir = $cfg['path']['conlite'] . $cfg['path']['cronjobs'];
|
|
|
|
|
|
|
|
|
|
// store directory information
|
|
|
|
|
$PC_reqDir = getcwd();
|
|
|
|
@ -184,24 +179,17 @@ for ($i=0;$i<count($PC_jobs);$i++) {
|
|
|
|
|
}
|
|
|
|
|
chdir($PC_reqDir);
|
|
|
|
|
|
|
|
|
|
if ($PC_debug) echo "\n</pre>";
|
|
|
|
|
|
|
|
|
|
if ($PC_debug)
|
|
|
|
|
echo "\n</pre>";
|
|
|
|
|
|
|
|
|
|
function logMessage($msg, $PC_writeDir, $PC_useLog, $PC_debug) {
|
|
|
|
|
$oCronLog = new cCronJob();
|
|
|
|
|
$oCronLog->useCronLog($PC_useLog);
|
|
|
|
|
$oCronLog->logMessages($msg);
|
|
|
|
|
unset($oCronLog);
|
|
|
|
|
|
|
|
|
|
if ($PC_useLog==1) {
|
|
|
|
|
$logfile = $PC_writeDir."pseudo-cron.log";
|
|
|
|
|
|
|
|
|
|
if (is_writable($logfile))
|
|
|
|
|
{
|
|
|
|
|
$file = fopen($logfile,"ab");
|
|
|
|
|
if ($msg[strlen($msg)-1]!="\n") {
|
|
|
|
|
$msg.="\r\n";
|
|
|
|
|
}
|
|
|
|
|
if ($PC_debug) echo $msg;
|
|
|
|
|
fputs($file,date("r",time())." ".$msg);
|
|
|
|
|
fclose($file);
|
|
|
|
|
}
|
|
|
|
|
if ($PC_debug) {
|
|
|
|
|
echo $msg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -228,8 +216,7 @@ function parseElement($element, &$targetArray, $numberOfElements) {
|
|
|
|
|
} elseif (!array_key_exists(4, $matches) || $matches[4] == "") {
|
|
|
|
|
$matches[4] = $matches[2];
|
|
|
|
|
}
|
|
|
|
|
if (array_key_exists(5, $matches))
|
|
|
|
|
{
|
|
|
|
|
if (array_key_exists(5, $matches)) {
|
|
|
|
|
if ($matches[5][0] != "/") {
|
|
|
|
|
$matches[6] = 1; // step
|
|
|
|
|
}
|
|
|
|
@ -245,7 +232,8 @@ function parseElement($element, &$targetArray, $numberOfElements) {
|
|
|
|
|
|
|
|
|
|
function decDate(&$dateArr, $amount, $unit, $PC_debug) {
|
|
|
|
|
|
|
|
|
|
if ($PC_debug) echo sprintf("Decreasing from %02d.%02d. %02d:%02d by %d %6s ",$dateArr[mday],$dateArr[mon],$dateArr[hours],$dateArr[minutes],$amount,$unit);
|
|
|
|
|
if ($PC_debug)
|
|
|
|
|
echo sprintf("Decreasing from %02d.%02d. %02d:%02d by %d %6s ", $dateArr[mday], $dateArr[mon], $dateArr[hours], $dateArr[minutes], $amount, $unit);
|
|
|
|
|
if ($unit == "mday") {
|
|
|
|
|
$dateArr["hours"] = 23;
|
|
|
|
|
$dateArr["minutes"] = 59;
|
|
|
|
@ -298,7 +286,8 @@ function decDate(&$dateArr, $amount, $unit, $PC_debug) {
|
|
|
|
|
$dateArr["minutes"] --;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($PC_debug) echo sprintf("to %02d.%02d. %02d:%02d\n",$dateArr[mday],$dateArr[mon],$dateArr[hours],$dateArr[minutes]);
|
|
|
|
|
if ($PC_debug)
|
|
|
|
|
echo sprintf("to %02d.%02d. %02d:%02d\n", $dateArr[mday], $dateArr[mon], $dateArr[hours], $dateArr[minutes]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getLastScheduledRunTime($job, $PC_debug) {
|
|
|
|
@ -306,11 +295,7 @@ function getLastScheduledRunTime($job, $PC_debug) {
|
|
|
|
|
$dateArr = getdate();
|
|
|
|
|
$minutesBack = 0;
|
|
|
|
|
while (
|
|
|
|
|
$minutesBack<525600 AND
|
|
|
|
|
(!$job[PC_MINUTE][$dateArr["minutes"]] OR
|
|
|
|
|
!$job[PC_HOUR][$dateArr["hours"]] OR
|
|
|
|
|
(!$job[PC_DOM][$dateArr["mday"]] OR !$job[PC_DOW][$dateArr["wday"]]) OR
|
|
|
|
|
!$job[PC_MONTH][$dateArr["mon"]])
|
|
|
|
|
$minutesBack < 525600 AND ( !$job[PC_MINUTE][$dateArr["minutes"]] OR ! $job[PC_HOUR][$dateArr["hours"]] OR ( !$job[PC_DOM][$dateArr["mday"]] OR ! $job[PC_DOW][$dateArr["wday"]]) OR ! $job[PC_MONTH][$dateArr["mon"]])
|
|
|
|
|
) {
|
|
|
|
|
if (!$job[PC_DOM][$dateArr["mday"]] OR ! $job[PC_DOW][$dateArr["wday"]]) {
|
|
|
|
|
decDate($dateArr, 1, "mday", $PC_debug);
|
|
|
|
@ -329,7 +314,8 @@ function getLastScheduledRunTime($job, $PC_debug) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($PC_debug) print_r($dateArr);
|
|
|
|
|
if ($PC_debug)
|
|
|
|
|
print_r($dateArr);
|
|
|
|
|
|
|
|
|
|
return mktime($dateArr["hours"], $dateArr["minutes"], 0, $dateArr["mon"], $dateArr["mday"], $dateArr["year"]);
|
|
|
|
|
}
|
|
|
|
@ -354,13 +340,11 @@ function getLastActialRunTime($jobname, $PC_writeDir) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function markLastRun($jobname, $lastRun, $PC_writeDir)
|
|
|
|
|
{
|
|
|
|
|
function markLastRun($jobname, $lastRun, $PC_writeDir) {
|
|
|
|
|
|
|
|
|
|
$jobfile = getJobFileName($jobname, $PC_writeDir);
|
|
|
|
|
|
|
|
|
|
if ($file = @fopen($jobfile,"w"))
|
|
|
|
|
{
|
|
|
|
|
if ($file = @fopen($jobfile, "w")) {
|
|
|
|
|
fputs($file, $lastRun);
|
|
|
|
|
fclose($file);
|
|
|
|
|
} else {
|
|
|
|
@ -369,7 +353,7 @@ function markLastRun($jobname, $lastRun, $PC_writeDir)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function runJob($job, $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug = false) {
|
|
|
|
|
global $cfg, $sess;
|
|
|
|
|
global $cfg, $sess, $PC_logDir;
|
|
|
|
|
if (!is_writable($PC_writeDir)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -384,6 +368,8 @@ function runJob($job, $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug=false) {
|
|
|
|
|
$lastActual = getLastActialRunTime($job[PC_CMD], $PC_writeDir);
|
|
|
|
|
$lastScheduled = getLastScheduledRunTime($extjob, $PC_debug);
|
|
|
|
|
|
|
|
|
|
//echo "LastSch: " . $lastScheduled . " ::: LastAct: " . $lastActual . "\n";
|
|
|
|
|
|
|
|
|
|
if ($lastScheduled > $lastActual) {
|
|
|
|
|
logMessage("Running " . $job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug);
|
|
|
|
|
logMessage(" Last run: " . date("r", $lastActual), $PC_writeDir, $PC_useLog, $PC_debug);
|
|
|
|
@ -394,13 +380,11 @@ function runJob($job, $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug=false) {
|
|
|
|
|
echo getcwd();
|
|
|
|
|
include($PC_jobDir . $job[PC_CMD]); // display errors only when debugging
|
|
|
|
|
} else {
|
|
|
|
|
if (is_object($sess))
|
|
|
|
|
{
|
|
|
|
|
if (is_object($sess)) {
|
|
|
|
|
$sess->freeze();
|
|
|
|
|
}
|
|
|
|
|
@include($PC_jobDir . $job[PC_CMD]); // any error messages are supressed
|
|
|
|
|
if (is_object($sess))
|
|
|
|
|
{
|
|
|
|
|
if (is_object($sess)) {
|
|
|
|
|
$sess->thaw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -431,17 +415,60 @@ function parseCronFile($PC_cronTabFile, $PC_debug) {
|
|
|
|
|
$jobs[$jobNumber] = $job;
|
|
|
|
|
if ($jobs[$jobNumber][PC_DOW][0] != '*' AND ! is_numeric($jobs[$jobNumber][PC_DOW])) {
|
|
|
|
|
$jobs[$jobNumber][PC_DOW] = str_replace(
|
|
|
|
|
Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"),
|
|
|
|
|
Array(0,1,2,3,4,5,6),
|
|
|
|
|
$jobs[$jobNumber][PC_DOW]);
|
|
|
|
|
Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), Array(0, 1, 2, 3, 4, 5, 6), $jobs[$jobNumber][PC_DOW]);
|
|
|
|
|
}
|
|
|
|
|
$jobs[$jobNumber][PC_CMD] = trim($job[PC_CMD]);
|
|
|
|
|
$jobs[$jobNumber][PC_CRONLINE] = $file[$i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($PC_debug) var_dump($jobs);
|
|
|
|
|
if ($PC_debug)
|
|
|
|
|
var_dump($jobs);
|
|
|
|
|
return $jobs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class cCronJob {
|
|
|
|
|
|
|
|
|
|
protected $_sCronTabFileName = "crontab.txt";
|
|
|
|
|
protected $_sCronTabLocalFileName = "crontab.local.txt";
|
|
|
|
|
protected $_sLogFileName = "pseudo-cron.log";
|
|
|
|
|
protected $_sJobDir;
|
|
|
|
|
protected $_sCronDir;
|
|
|
|
|
protected $_sLogDir;
|
|
|
|
|
private $_bUseLog;
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
$this->_sJobDir = cRegistry::getConfigValue('path', 'conlite') . cRegistry::getConfigValue('path', 'cronjobs');
|
|
|
|
|
$this->_sCronDir = cRegistry::getConfigValue('path', 'conlite_cronlog');
|
|
|
|
|
$this->_sLogDir = cRegistry::getConfigValue('path', 'conlite_logs');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function runJob() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function useCronLog($bUse = TRUE) {
|
|
|
|
|
$this->_bUseLog = boolval($bUse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function logMessages($sMsg) {
|
|
|
|
|
if (!$this->_bUseLog) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (is_dir($this->_sLogDir) && is_writable($this->_sLogDir)) {
|
|
|
|
|
$logfile = $this->_sLogDir . $this->_sLogFileName;
|
|
|
|
|
} else if (is_dir($this->_sCronDir) && is_writable($this->_sCronDir)) {
|
|
|
|
|
$logfile = $this->_sCronDir . $this->_sLogFileName;
|
|
|
|
|
} else {
|
|
|
|
|
cWarning(__FILE__, __LINE__, "PseudoCron: Cannot write cronlog file!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($sMsg[strlen($sMsg) - 1] != "\n") {
|
|
|
|
|
$sMsg .= "\r\n";
|
|
|
|
|
}
|
|
|
|
|
file_put_contents($logfile, $sMsg, FILE_APPEND);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|