fix pseudo-cron and move job-files to data-dir. See bugtracker #168 and #169

Dieser Commit ist enthalten in:
Oldperl 2016-10-07 16:24:28 +00:00
Ursprung 3b98b5f4e1
Commit 8287e479f0
8 geänderte Dateien mit 351 neuen und 324 gelöschten Zeilen

Datei anzeigen

@ -1,55 +1,56 @@
<?php <?php
/***************************************************************************
pseudo-cron v1.2.1.con // modified version for contenido /* * *************************************************************************
(c) 2003 Kai Blankenhorn
www.bitfolge.de/en
kaib@bitfolge.de
This program is free software; you can redistribute it and/or pseudo-cron v1.2.1.con // modified version for contenido
modify it under the terms of the GNU General Public License (c) 2003 Kai Blankenhorn
as published by the Free Software Foundation; either version 2 www.bitfolge.de/en
of the License, or (at your option) any later version. kaib@bitfolge.de
This program is distributed in the hope that it will be useful, This program is free software; you can redistribute it and/or
but WITHOUT ANY WARRANTY; without even the implied warranty of modify it under the terms of the GNU General Public License
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the as published by the Free Software Foundation; either version 2
GNU General Public License for more details. of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public License This program is distributed in the hope that it will be useful,
along with this program; if not, write to the Free Software but WITHOUT ANY WARRANTY; without even the implied warranty of
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
**************************************************************************** You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* ***************************************************************************
Usually regular tasks like backup up the site's database are run using cron Usually regular tasks like backup up the site's database are run using cron
jobs. With cron jobs, you can exactly plan when a certain command is to be jobs. With cron jobs, you can exactly plan when a certain command is to be
executed. But most homepage owners can't create cron jobs on their web executed. But most homepage owners can't create cron jobs on their web
server - providers demand some extra money for that. server - providers demand some extra money for that.
The only thing that's certain to happen quite regularly on a web page are The only thing that's certain to happen quite regularly on a web page are
page requests. This is where pseudo-cron comes into play: With every page page requests. This is where pseudo-cron comes into play: With every page
request it checks if any cron jobs should have been run since the previous request it checks if any cron jobs should have been run since the previous
request. If there are, they are run and logged. request. If there are, they are run and logged.
Pseudo-cron uses a syntax very much like the Unix cron's one. For an Pseudo-cron uses a syntax very much like the Unix cron's one. For an
overview of the syntax used, see a page of the UNIXGEEKS. The syntax overview of the syntax used, see a page of the UNIXGEEKS. The syntax
pseudo-cron uses is different from the one described on that page in pseudo-cron uses is different from the one described on that page in
the following points: the following points:
- there is no user column - there is no user column
- the executed command has to be an include()able file (which may contain further PHP code) - the executed command has to be an include()able file (which may contain further PHP code)
All job definitions are made in a text file on the server with a All job definitions are made in a text file on the server with a
user-definable name. A valid command line in this file is, for example: user-definable name. A valid command line in this file is, for example:
* 2 1,15 * * samplejob.inc.php * 2 1,15 * * samplejob.inc.php
This runs samplejob.inc.php at 2am on the 1st and 15th of each month. This runs samplejob.inc.php at 2am on the 1st and 15th of each month.
Features: Features:
- runs any PHP script - runs any PHP script
- periodical or time-controlled script execution - periodical or time-controlled script execution
- logs all executed jobs - logs all executed jobs
@ -57,81 +58,75 @@ Features:
- follow Unix cron syntax for crontabs - follow Unix cron syntax for crontabs
Usage: Usage:
- Modify the variables in the config section below to match your server. - Modify the variables in the config section below to match your server.
- Write a PHP script that does the job you want to be run regularly. Be - Write a PHP script that does the job you want to be run regularly. Be
sure that any paths in it are relative to the script that will run sure that any paths in it are relative to the script that will run
pseudo-cron in the end. pseudo-cron in the end.
- Set up your crontab file with your script - Set up your crontab file with your script
- Wait for the next scheduled run :) - Wait for the next scheduled run :)
Note: Note:
You can log messages to pseudo-cron's log file by calling You can log messages to pseudo-cron's log file by calling
logMessage("log a message", $PC_writeDir, $PC_useLog, $PC_debug); logMessage("log a message", $PC_writeDir, $PC_useLog, $PC_debug);
Changelog: Changelog:
v1.2.1.con 11-28-03 v1.2.1.con 11-28-03
changed: removed all global variables changed: removed all global variables
changed: renamed intern variables changed: renamed intern variables
changed: intern function calls changed: intern function calls
changed: extended debug information changed: extended debug information
modified by horwath@opensa.org modified by horwath@opensa.org
v1.2.1 02-03-03 v1.2.1 02-03-03
fixed: jobs may be run too often under certain conditions fixed: jobs may be run too often under certain conditions
added: global debug switch added: global debug switch
changed: typo in imagecron.php which prevented it from working changed: typo in imagecron.php which prevented it from working
v1.2 01-31-03 v1.2 01-31-03
added: more documentation added: more documentation
changed: log file should now be easier to use changed: log file should now be easier to use
changed: log file name changed: log file name
v1.1 01-29-03 v1.1 01-29-03
changed: renamed pseudo-cron.php to pseudo-cron.inc.php changed: renamed pseudo-cron.php to pseudo-cron.inc.php
fixed: comments at the end of a line don't work fixed: comments at the end of a line don't work
fixed: empty lines in crontab file create nonsense jobs fixed: empty lines in crontab file create nonsense jobs
changed: log file grows big very quickly changed: log file grows big very quickly
changed: included config file in main file to avoid directory confusion changed: included config file in main file to avoid directory confusion
added: day of week abbreviations may now be used (three letters, english) added: day of week abbreviations may now be used (three letters, english)
v1.0 01-17-03 v1.0 01-17-03
inital release inital release
***************************************************************************/ * ************************************************************************* */
if(!defined('CON_FRAMEWORK')) { if (!defined('CON_FRAMEWORK')) {
die('Illegal call'); die('Illegal call');
} }
/****************************************/ /* * ************************************* */
/* config section */ /* config section */
/****************************************/ /* * ************************************* */
// || PLEASE NOTE: // || PLEASE NOTE:
// || all paths used here and in cron scripts // || all paths used here and in cron scripts
// || must be absolute or relative to the script which includes pseudo-cron.inc.php! // || must be absolute or relative to the script which includes pseudo-cron.inc.php!
// the file that contains the job descriptions // the file that contains the job descriptions
// for a description of the format, see http://www.unixgeeks.org/security/newbie/unix/cron-1.html // for a description of the format, see http://www.unixgeeks.org/security/newbie/unix/cron-1.html
// and http://www.bitfolge.de/pseudocron // and http://www.bitfolge.de/pseudocron
$PC_cronTab = $cfg["path"]["contenido"].$cfg['path']['cronjobs']."crontab.txt"; $PC_cronTab = $cfg['path']['conlite_cronlog'] . "crontab.txt";
$PC_localCronTab = $cfg["path"]["contenido"].$cfg['path']['cronjobs']."crontab.local.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 $PC_writeDir = $cfg['path']['conlite_cronlog'];
// include trailing slash $PC_jobDir = $cfg['path']['conlite'] . $cfg['path']['cronjobs'];
$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'];
// store directory information // store directory information
$PC_reqDir = getcwd(); $PC_reqDir = getcwd();
@ -143,26 +138,26 @@ $PC_useLog = 1;
// DO NOT use this on live servers! // DO NOT use this on live servers!
$PC_debug = false; $PC_debug = false;
/****************************************/ /* * ************************************* */
/* don't change anything here */ /* don't change anything here */
/****************************************/ /* * ************************************* */
define("PC_MINUTE", 1); define("PC_MINUTE", 1);
define("PC_HOUR", 2); define("PC_HOUR", 2);
define("PC_DOM", 3); define("PC_DOM", 3);
define("PC_MONTH", 4); define("PC_MONTH", 4);
define("PC_DOW", 5); define("PC_DOW", 5);
define("PC_CMD", 7); define("PC_CMD", 7);
define("PC_CRONLINE", 8); define("PC_CRONLINE", 8);
if ($PC_debug) { if ($PC_debug) {
echo "<pre>Configuration:"; echo "<pre>Configuration:";
echo "\nPC_cronTab = ".$PC_cronTab; echo "\nPC_cronTab = " . $PC_cronTab;
echo "\nPC_writeDir = ".$PC_writeDir; echo "\nPC_writeDir = " . $PC_writeDir;
echo "\nPC_jobDir = ".$PC_jobDir; echo "\nPC_jobDir = " . $PC_jobDir;
echo "\nPC_reqDir = ".$PC_reqDir; echo "\nPC_reqDir = " . $PC_reqDir;
echo "\nPC_useLog = ".$PC_useLog; echo "\nPC_useLog = " . $PC_useLog;
echo "\n"; echo "\n";
} }
global $bJobRunned; global $bJobRunned;
@ -172,276 +167,308 @@ $bJobRunned = false;
chdir($PC_jobDir); chdir($PC_jobDir);
$PC_jobs = parseCronFile($PC_cronTab, $PC_debug); $PC_jobs = parseCronFile($PC_cronTab, $PC_debug);
for ($i=0;$i<count($PC_jobs);$i++) { for ($i = 0; $i < count($PC_jobs); $i++) {
$bJobRunned = true; $bJobRunned = true;
runJob($PC_jobs[$i], $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug); runJob($PC_jobs[$i], $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug);
} }
$PC_jobs = parseCronFile($PC_localCronTab, $PC_debug); $PC_jobs = parseCronFile($PC_localCronTab, $PC_debug);
for ($i=0;$i<count($PC_jobs);$i++) { for ($i = 0; $i < count($PC_jobs); $i++) {
$bJobRunned = true; $bJobRunned = true;
runJob($PC_jobs[$i], $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug); runJob($PC_jobs[$i], $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug);
} }
chdir($PC_reqDir); chdir($PC_reqDir);
if ($PC_debug) echo "\n</pre>"; if ($PC_debug)
echo "\n</pre>";
function logMessage($msg, $PC_writeDir, $PC_useLog, $PC_debug) { 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) { if ($PC_debug) {
$logfile = $PC_writeDir."pseudo-cron.log"; echo $msg;
}
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);
}
}
} }
function lTrimZeros($number) { function lTrimZeros($number) {
while ($number[0]=='0') { while ($number[0] == '0') {
$number = substr($number,1); $number = substr($number, 1);
} }
return $number; return $number;
} }
function parseElement($element, &$targetArray, $numberOfElements) { function parseElement($element, &$targetArray, $numberOfElements) {
$subelements = explode(",",$element); $subelements = explode(",", $element);
for ($i=0;$i<$numberOfElements;$i++) { for ($i = 0; $i < $numberOfElements; $i++) {
$targetArray[$i] = $subelements[0]=="*"; $targetArray[$i] = $subelements[0] == "*";
} }
for ($i=0;$i<count($subelements);$i++) { for ($i = 0; $i < count($subelements); $i++) {
if (preg_match("~^(\\*|([0-9]{1,2})(-([0-9]{1,2}))?)(/([0-9]{1,2}))?$~",$subelements[$i],$matches)) { if (preg_match("~^(\\*|([0-9]{1,2})(-([0-9]{1,2}))?)(/([0-9]{1,2}))?$~", $subelements[$i], $matches)) {
if ($matches[1]=="*") { if ($matches[1] == "*") {
$matches[2] = 0; // from $matches[2] = 0; // from
$matches[4] = $numberOfElements; //to $matches[4] = $numberOfElements; //to
} elseif (!array_key_exists(4,$matches) || $matches[4]=="") { } elseif (!array_key_exists(4, $matches) || $matches[4] == "") {
$matches[4] = $matches[2]; $matches[4] = $matches[2];
} }
if (array_key_exists(5, $matches)) if (array_key_exists(5, $matches)) {
{ if ($matches[5][0] != "/") {
if ($matches[5][0]!="/") { $matches[6] = 1; // step
}
} else {
$matches[6] = 1; // step $matches[6] = 1; // step
} }
} else { for ($j = lTrimZeros($matches[2]); $j <= lTrimZeros($matches[4]); $j += lTrimZeros($matches[6])) {
$matches[6] = 1; // step $targetArray[$j] = TRUE;
} }
for ($j=lTrimZeros($matches[2]);$j<=lTrimZeros($matches[4]);$j+=lTrimZeros($matches[6])) { }
$targetArray[$j] = TRUE; }
}
}
}
} }
function decDate(&$dateArr, $amount, $unit, $PC_debug) { 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)
if ($unit=="mday") { echo sprintf("Decreasing from %02d.%02d. %02d:%02d by %d %6s ", $dateArr[mday], $dateArr[mon], $dateArr[hours], $dateArr[minutes], $amount, $unit);
$dateArr["hours"] = 23; if ($unit == "mday") {
$dateArr["minutes"] = 59; $dateArr["hours"] = 23;
$dateArr["seconds"] = 59; $dateArr["minutes"] = 59;
$dateArr["mday"] -= $amount; $dateArr["seconds"] = 59;
$dateArr["wday"] -= $amount % 7; $dateArr["mday"] -= $amount;
if ($dateArr["wday"]<0) { $dateArr["wday"] -= $amount % 7;
$dateArr["wday"]+=7; if ($dateArr["wday"] < 0) {
} $dateArr["wday"] += 7;
if ($dateArr["mday"]<1) { }
$dateArr["mon"]--; if ($dateArr["mday"] < 1) {
switch ($dateArr["mon"]) { $dateArr["mon"] --;
case 0: switch ($dateArr["mon"]) {
$dateArr["mon"] = 12; case 0:
$dateArr["year"]--; $dateArr["mon"] = 12;
// fall through $dateArr["year"] --;
case 1: // fall through
case 3: case 1:
case 5: case 3:
case 7: case 5:
case 8: case 7:
case 10: case 8:
case 12: case 10:
$dateArr["mday"] = 31; case 12:
break; $dateArr["mday"] = 31;
case 4: break;
case 6: case 4:
case 9: case 6:
case 11: case 9:
$dateArr["mday"] = 30; case 11:
break; $dateArr["mday"] = 30;
case 2: break;
$dateArr["mday"] = 28; case 2:
break; $dateArr["mday"] = 28;
} break;
} }
} elseif ($unit=="hour") { }
if ($dateArr["hours"]==0) { } elseif ($unit == "hour") {
decDate($dateArr, 1, "mday",$PC_debug); if ($dateArr["hours"] == 0) {
} else { decDate($dateArr, 1, "mday", $PC_debug);
$dateArr["minutes"] = 59; } else {
$dateArr["seconds"] = 59; $dateArr["minutes"] = 59;
$dateArr["hours"]--; $dateArr["seconds"] = 59;
} $dateArr["hours"] --;
} elseif ($unit=="minute") { }
if ($dateArr["minutes"]==0) { } elseif ($unit == "minute") {
decDate($dateArr, 1, "hour",$PC_debug); if ($dateArr["minutes"] == 0) {
} else { decDate($dateArr, 1, "hour", $PC_debug);
$dateArr["seconds"] = 59; } else {
$dateArr["minutes"]--; $dateArr["seconds"] = 59;
} $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) { function getLastScheduledRunTime($job, $PC_debug) {
$dateArr = getdate(); $dateArr = getdate();
$minutesBack = 0; $minutesBack = 0;
while ( while (
$minutesBack<525600 AND $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"]])
(!$job[PC_MINUTE][$dateArr["minutes"]] OR ) {
!$job[PC_HOUR][$dateArr["hours"]] OR if (!$job[PC_DOM][$dateArr["mday"]] OR ! $job[PC_DOW][$dateArr["wday"]]) {
(!$job[PC_DOM][$dateArr["mday"]] OR !$job[PC_DOW][$dateArr["wday"]]) OR decDate($dateArr, 1, "mday", $PC_debug);
!$job[PC_MONTH][$dateArr["mon"]]) $minutesBack += 1440;
) { continue;
if (!$job[PC_DOM][$dateArr["mday"]] OR !$job[PC_DOW][$dateArr["wday"]]) { }
decDate($dateArr,1,"mday",$PC_debug); if (!$job[PC_HOUR][$dateArr["hours"]]) {
$minutesBack+=1440; decDate($dateArr, 1, "hour", $PC_debug);
continue; $minutesBack += 60;
} continue;
if (!$job[PC_HOUR][$dateArr["hours"]]) { }
decDate($dateArr,1,"hour",$PC_debug); if (!$job[PC_MINUTE][$dateArr["minutes"]]) {
$minutesBack+=60; decDate($dateArr, 1, "minute", $PC_debug);
continue; $minutesBack++;
} continue;
if (!$job[PC_MINUTE][$dateArr["minutes"]]) { }
decDate($dateArr,1,"minute",$PC_debug); }
$minutesBack++;
continue;
}
}
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"]); return mktime($dateArr["hours"], $dateArr["minutes"], 0, $dateArr["mon"], $dateArr["mday"], $dateArr["year"]);
} }
function getJobFileName($jobname, $PC_writeDir) { function getJobFileName($jobname, $PC_writeDir) {
$jobfile = $PC_writeDir.urlencode($jobname).".job"; $jobfile = $PC_writeDir . urlencode($jobname) . ".job";
return $jobfile; return $jobfile;
} }
function getLastActialRunTime($jobname, $PC_writeDir) { function getLastActialRunTime($jobname, $PC_writeDir) {
$jobfile = getJobFileName($jobname, $PC_writeDir); $jobfile = getJobFileName($jobname, $PC_writeDir);
if (file_exists($jobfile)) { if (file_exists($jobfile)) {
$file = fopen($jobfile,"rb"); $file = fopen($jobfile, "rb");
$lastRun = fgets($file,100); $lastRun = fgets($file, 100);
fclose($file); fclose($file);
if (is_numeric($lastRun)) { if (is_numeric($lastRun)) {
return $lastRun; return $lastRun;
} }
} }
return 0; return 0;
} }
function markLastRun($jobname, $lastRun, $PC_writeDir) function markLastRun($jobname, $lastRun, $PC_writeDir) {
{
$jobfile = getJobFileName($jobname, $PC_writeDir); $jobfile = getJobFileName($jobname, $PC_writeDir);
if ($file = @fopen($jobfile,"w")) if ($file = @fopen($jobfile, "w")) {
{ fputs($file, $lastRun);
fputs($file,$lastRun); fclose($file);
fclose($file); } else {
} else { //echo "Could not write into file $jobfile - permission denied.";
//echo "Could not write into file $jobfile - permission denied."; }
}
} }
function runJob($job, $PC_jobDir, $PC_writeDir, $PC_useLog, $PC_debug=false) { 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)) { if (!is_writable($PC_writeDir)) {
return false; return false;
} }
$extjob = Array(); $extjob = Array();
$jobfile = getJobFileName($job[PC_CMD], $PC_writeDir); $jobfile = getJobFileName($job[PC_CMD], $PC_writeDir);
parseElement($job[PC_MINUTE], $extjob[PC_MINUTE], 60); parseElement($job[PC_MINUTE], $extjob[PC_MINUTE], 60);
parseElement($job[PC_HOUR], $extjob[PC_HOUR], 24); parseElement($job[PC_HOUR], $extjob[PC_HOUR], 24);
parseElement($job[PC_DOM], $extjob[PC_DOM], 31); parseElement($job[PC_DOM], $extjob[PC_DOM], 31);
parseElement($job[PC_MONTH], $extjob[PC_MONTH], 12); parseElement($job[PC_MONTH], $extjob[PC_MONTH], 12);
parseElement($job[PC_DOW], $extjob[PC_DOW], 7); parseElement($job[PC_DOW], $extjob[PC_DOW], 7);
$lastActual = getLastActialRunTime($job[PC_CMD], $PC_writeDir); $lastActual = getLastActialRunTime($job[PC_CMD], $PC_writeDir);
$lastScheduled = getLastScheduledRunTime($extjob, $PC_debug); $lastScheduled = getLastScheduledRunTime($extjob, $PC_debug);
if ($lastScheduled>$lastActual) { //echo "LastSch: " . $lastScheduled . " ::: LastAct: " . $lastActual . "\n";
logMessage("Running ".$job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug);
logMessage(" Last run: ".date("r",$lastActual), $PC_writeDir, $PC_useLog, $PC_debug);
logMessage(" Last scheduled: ".date("r",$lastScheduled), $PC_writeDir, $PC_useLog, $PC_debug);
markLastRun($job[PC_CMD], $lastScheduled, $PC_writeDir);
if ($PC_debug) { if ($lastScheduled > $lastActual) {
echo getcwd(); logMessage("Running " . $job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug);
include($PC_jobDir.$job[PC_CMD]); // display errors only when debugging logMessage(" Last run: " . date("r", $lastActual), $PC_writeDir, $PC_useLog, $PC_debug);
} else { logMessage(" Last scheduled: " . date("r", $lastScheduled), $PC_writeDir, $PC_useLog, $PC_debug);
if (is_object($sess)) markLastRun($job[PC_CMD], $lastScheduled, $PC_writeDir);
{
$sess->freeze(); if ($PC_debug) {
} echo getcwd();
@include($PC_jobDir.$job[PC_CMD]); // any error messages are supressed include($PC_jobDir . $job[PC_CMD]); // display errors only when debugging
if (is_object($sess)) } else {
{ if (is_object($sess)) {
$sess->thaw(); $sess->freeze();
} }
} @include($PC_jobDir . $job[PC_CMD]); // any error messages are supressed
logMessage("Completed ".$job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug); if (is_object($sess)) {
return true; $sess->thaw();
} else { }
if ($PC_debug) { }
logMessage("Skipping ".$job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug); logMessage("Completed " . $job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug);
logMessage(" Last run: ".date("r",$lastActual), $PC_writeDir, $PC_useLog, $PC_debug); return true;
logMessage(" Last scheduled: ".date("r",$lastScheduled), $PC_writeDir, $PC_useLog, $PC_debug); } else {
logMessage("Completed ".$job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug); if ($PC_debug) {
} logMessage("Skipping " . $job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug);
return false; logMessage(" Last run: " . date("r", $lastActual), $PC_writeDir, $PC_useLog, $PC_debug);
} logMessage(" Last scheduled: " . date("r", $lastScheduled), $PC_writeDir, $PC_useLog, $PC_debug);
logMessage("Completed " . $job[PC_CRONLINE], $PC_writeDir, $PC_useLog, $PC_debug);
}
return false;
}
} }
function parseCronFile($PC_cronTabFile, $PC_debug) { function parseCronFile($PC_cronTabFile, $PC_debug) {
$file = @file($PC_cronTabFile); $file = @file($PC_cronTabFile);
$job = Array(); $job = Array();
$jobs = Array(); $jobs = Array();
for ($i=0;$i<count($file);$i++) { for ($i = 0; $i < count($file); $i++) {
if ($file[$i][0]!='#') { if ($file[$i][0] != '#') {
// old regex, without dow abbreviations: // old regex, without dow abbreviations:
// if (preg_match("~^([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-7,/*]+|Sun|Mon|Tue|Wen|Thu|Fri|Sat)\\s+([^#]*)(#.*)?$~i",$file[$i],$job)) { // if (preg_match("~^([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-7,/*]+|Sun|Mon|Tue|Wen|Thu|Fri|Sat)\\s+([^#]*)(#.*)?$~i",$file[$i],$job)) {
if (preg_match("~^([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-7,/*]+|(-|/|Sun|Mon|Tue|Wed|Thu|Fri|Sat)+)\\s+([^#]*)(#.*)?$~i",$file[$i],$job)) { if (preg_match("~^([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-9,/*]+)\\s+([-0-7,/*]+|(-|/|Sun|Mon|Tue|Wed|Thu|Fri|Sat)+)\\s+([^#]*)(#.*)?$~i", $file[$i], $job)) {
$jobNumber = count($jobs); $jobNumber = count($jobs);
$jobs[$jobNumber] = $job; $jobs[$jobNumber] = $job;
if ($jobs[$jobNumber][PC_DOW][0]!='*' AND !is_numeric($jobs[$jobNumber][PC_DOW])) { if ($jobs[$jobNumber][PC_DOW][0] != '*' AND ! is_numeric($jobs[$jobNumber][PC_DOW])) {
$jobs[$jobNumber][PC_DOW] = str_replace( $jobs[$jobNumber][PC_DOW] = str_replace(
Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"), Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), Array(0, 1, 2, 3, 4, 5, 6), $jobs[$jobNumber][PC_DOW]);
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];
} }
$jobs[$jobNumber][PC_CMD] = trim($job[PC_CMD]); }
$jobs[$jobNumber][PC_CRONLINE] = $file[$i]; }
} if ($PC_debug)
} var_dump($jobs);
} return $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);
}
}
?>

Datei anzeigen

@ -71,7 +71,7 @@ if (!defined('CL_ENVIRONMENT')) {
*/ */
if (!defined('CL_VERSION')) { if (!defined('CL_VERSION')) {
define('CL_VERSION', '2.0.0RC3'); define('CL_VERSION', '2.0.1');
} }

Datei anzeigen

@ -64,7 +64,7 @@ cInclude ("includes", 'cfg_language_de.inc.php');
if ($cfg["use_pseudocron"] == true) if ($cfg["use_pseudocron"] == true)
{ {
/* Include cronjob-Emulator, but only for frame 1 */ /* Include cronjob-Emulator, but only for frame 1 */
if($frame == 1) { if($frame == 4) {
$sess->freeze(); $sess->freeze();
$oldpwd = getcwd(); $oldpwd = getcwd();

Datei anzeigen

@ -1,4 +0,0 @@
[Dolphin]
Timestamp=2016,9,20,14,43,24
Version=3
ViewMode=1

Datei anzeigen

@ -47,7 +47,7 @@ $cfg['datetag'] = '$Date: 2015-11-09 22:02:55 +0100 (Mon, 09 Nov 2015) $';
/* Backend timeout */ /* Backend timeout */
$cfg["backend"]["timeout"] = 60; $cfg["backend"]["timeout"] = 60;
$cfg["develop"]["show_errors"] = true; $cfg["develop"]["show_errors"] = false;
$cfg["develop"]["show_deprecated"] = false; $cfg["develop"]["show_deprecated"] = false;
/* Use Pseudo-Cron? */ /* Use Pseudo-Cron? */

Datei anzeigen

@ -54,15 +54,15 @@ $cfg['path']['temp'] = $cfg['path']['data'].'temp/';
$cfg['path']['cache'] = $cfg['path']['data'].'cache/'; $cfg['path']['cache'] = $cfg['path']['data'].'cache/';
$cfg['path']['config'] = $cfg['path']['data'].'config/'; $cfg['path']['config'] = $cfg['path']['data'].'config/';
$cfg['path']['logs'] = $cfg['path']['data'].'logs/'; $cfg['path']['logs'] = $cfg['path']['data'].'logs/';
$cfg['path']['backup'] = $cfg['path']['data'].'backup/'; $cfg['path']['backup'] = $cfg['path']['data'].'backup/';
//$cfg['path']['cronlog'] = $cfg['path']['data'].'cronlog/'; $cfg['path']['cronlog'] = $cfg['path']['data'].'cronlog/';
//$cfg['path']['locale'] = $cfg['path']['data'].'locale/'; //$cfg['path']['locale'] = $cfg['path']['data'].'locale/';
$cfg['path']['conlite_temp'] = $cfg['path']['frontend']. '/' .$cfg['path']['temp']; $cfg['path']['conlite_temp'] = $cfg['path']['frontend']. '/' .$cfg['path']['temp'];
$cfg['path']['conlite_cache'] = $cfg['path']['frontend']. '/' .$cfg['path']['cache']; $cfg['path']['conlite_cache'] = $cfg['path']['frontend']. '/' .$cfg['path']['cache'];
$cfg['path']['conlite_logs'] = $cfg['path']['frontend']. '/' .$cfg['path']['logs']; $cfg['path']['conlite_logs'] = $cfg['path']['frontend']. '/' .$cfg['path']['logs'];
$cfg['path']['conlite_backup'] = $cfg['path']['frontend']. '/' .$cfg['path']['backup']; $cfg['path']['conlite_backup'] = $cfg['path']['frontend']. '/' .$cfg['path']['backup'];
//$cfg['path']['conlite_cronlog'] = $cfg['path']['frontend']. '/' .$cfg['path']['cronlog']; $cfg['path']['conlite_cronlog'] = $cfg['path']['frontend']. '/' .$cfg['path']['cronlog'];
//$cfg['path']['conlite_locale'] = $cfg['path']['frontend']. '/' .$cfg['path']['locale']; //$cfg['path']['conlite_locale'] = $cfg['path']['frontend']. '/' .$cfg['path']['locale'];
$cfg['path']['repository'] = $cfg["path"]['plugins'] . 'repository/'; $cfg['path']['repository'] = $cfg["path"]['plugins'] . 'repository/';

4
data/cronlog/index.php Normale Datei
Datei anzeigen

@ -0,0 +1,4 @@
<?php
header("Location:/index.php");
exit;
?>