mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 07:04:57 +00:00
require basic auth and login as user cli_scheduler
This commit is contained in:
parent
31fda7e60e
commit
542a6cb045
|
@ -24,8 +24,9 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
|||
|
||||
public function run() { /* {{{ */
|
||||
$dms = $this->params['dms'];
|
||||
$user = $this->params['user'];
|
||||
$settings = $this->params['settings'];
|
||||
$mode = 'run'; //$this->params['mode'];
|
||||
$mode = $this->params['mode'];
|
||||
$db = $dms->getDb();
|
||||
|
||||
$scheduler = new SeedDMS_Scheduler($db);
|
||||
|
@ -35,19 +36,24 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
|||
if(isset($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()]) && is_object($taskobj = resolveTask($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()]))) {
|
||||
switch($mode) {
|
||||
case "run":
|
||||
case "dryrun":
|
||||
if(method_exists($taskobj, 'execute')) {
|
||||
if(!$task->getDisabled() && $task->isDue()) {
|
||||
if($user = $dms->getUserByLogin('cli_scheduler')) {
|
||||
if($mode == 'run') {
|
||||
/* Schedule the next run right away to prevent a second execution
|
||||
* of the task when the cron job of the scheduler is called before
|
||||
* the last run was finished. The task itself can still be scheduled
|
||||
* to fast, but this is up to the admin of seeddms.
|
||||
*/
|
||||
$task->updateLastNextRun();
|
||||
if($taskobj->execute($task)) {
|
||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful.");
|
||||
$task->updateLastNextRun();
|
||||
} else {
|
||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR);
|
||||
$task->setDisabled(1);
|
||||
}
|
||||
} else {
|
||||
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed because of missing user 'cli_scheduler'. Task has been disabled.", PEAR_LOG_ERR);
|
||||
$task->setDisabled(1);
|
||||
} elseif($mode == 'dryrun') {
|
||||
echo "Running ".$task->getExtension()."::".$task->getTask()." in dry mode\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +62,7 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
|
|||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} /* }}} */
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,18 @@ include("../inc/inc.ClassNotificationService.php");
|
|||
include("../inc/inc.ClassEmailNotify.php");
|
||||
include("../inc/inc.ClassController.php");
|
||||
include("../inc/inc.Scheduler.php");
|
||||
include("../inc/inc.BasicAuthentication.php");
|
||||
|
||||
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||
$controller = Controller::factory($tmp[1], array('dms'=>$dms));
|
||||
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
|
||||
|
||||
$controller->setParam('settings', $settings);
|
||||
header("Content-Type: text/plain");
|
||||
if($user->getLogin() != 'cli_scheduler') {
|
||||
echo "Wrong user";
|
||||
exit;
|
||||
}
|
||||
$controller->setParam('settings', $settings);
|
||||
$controller->setParam('mode', 'dryrun');
|
||||
if(!$controller->run()) {
|
||||
echo getMLText("error_occured");
|
||||
exit;
|
||||
|
|
Loading…
Reference in New Issue
Block a user