diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index fc845f24585..1c68f79f0c0 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -43,6 +43,7 @@ $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $cancel=GETPOST('cancel'); $backtourl=GETPOST('backtourl','alpha'); +$securitykey = GETPOST('securitykey','alpha'); /* @@ -100,30 +101,38 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del // Execute jobs if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) { - $now = dol_now(); // Date we start + if (! empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) + { + setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors'); + $action=''; + } + else + { + $now = dol_now(); // Date we start + + $result=$object->run_jobs($user->login); - $result=$object->run_jobs($user->login); - - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $action=''; - } - else - { - $res = $object->reprogram_jobs($user->login, $now); - if ($res > 0) - { - if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings'); - else setEventMessages($langs->trans("JobFinished"), null, 'mesgs'); - $action=''; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - $action=''; - } - } + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } + else + { + $res = $object->reprogram_jobs($user->login, $now); + if ($res > 0) + { + if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings'); + else setEventMessages($langs->trans("JobFinished"), null, 'mesgs'); + $action=''; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } + } + } } @@ -284,7 +293,7 @@ if ($action == 'delete') } if ($action == 'execute'){ - print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id.(empty($conf->global->CRON_KEY)?'':'&securitykey='.$conf->global->CRON_KEY),$langs->trans("CronExecute"),$langs->trans("CronConfirmExecute"),"confirm_execute",'','',1); + print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id.'&securitykey='.$securitykey,$langs->trans("CronExecute"),$langs->trans("CronConfirmExecute"),"confirm_execute",'','',1); $action=''; } diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 1f06bb81612..712f4e94234 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -363,6 +363,9 @@ class Cronjob extends CommonObject function fetch_all($sortorder='DESC', $sortfield='t.rowid', $limit=0, $offset=0, $status=1, $filter='') { global $langs; + + $this->lines=array(); + $sql = "SELECT"; $sql.= " t.rowid,"; $sql.= " t.tms,"; @@ -399,8 +402,10 @@ class Cronjob extends CommonObject if ($status == 2) $sql.= " AND t.status = 2"; //Manage filter if (is_array($filter) && count($filter)>0) { - foreach($filter as $key => $value) { - $sql.= ' AND '.$key.' LIKE \'%'.$value.'%\''; + foreach($filter as $key => $value) + { + if ($key == 't.rowid') $sql.= ' AND '.$key.' = '.$this->db->escape($value); + else $sql.= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\''; } } @@ -427,8 +432,6 @@ class Cronjob extends CommonObject if ($num) { - $this->lines=array(); - while ($i < $num) { diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php index 618af2c1778..aa7d6e8790c 100644 --- a/htdocs/cron/list.php +++ b/htdocs/cron/list.php @@ -57,6 +57,7 @@ if ($status == '') $status=-2; //Search criteria $search_label=GETPOST("search_label",'alpha'); +$securitykey = GETPOST('securitykey','alpha'); if (empty($sortorder)) $sortorder="DESC"; if (empty($sortfield)) $sortfield="t.status"; @@ -99,35 +100,43 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del // Execute jobs if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) { - $object = new Cronjob($db); - $job = $object->fetch($id); - - $now = dol_now(); // Date we start - - $resrunjob = $object->run_jobs($user->login); // Return -1 if KO, 1 if OK - if ($resrunjob < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - - // Programm next run - $res = $object->reprogram_jobs($user->login, $now); - if ($res > 0) - { - if ($resrunjob >= 0) // We add result of reprogram ony if no error message already reported - { - if ($object->lastresult >= 0) setEventMessages($langs->trans("JobFinished"), null, 'mesgs'); - else setEventMessages($langs->trans("JobFinished"), null, 'errors'); - } - $action=''; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - $action=''; - } - - header("Location: ".DOL_URL_ROOT.'/cron/list.php?status=-2'); // Make a call to avoid to run twice job when using back - exit; + if (! empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) + { + setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors'); + $action=''; + } + else + { + $object = new Cronjob($db); + $job = $object->fetch($id); + + $now = dol_now(); // Date we start + + $resrunjob = $object->run_jobs($user->login); // Return -1 if KO, 1 if OK + if ($resrunjob < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + + // Programm next run + $res = $object->reprogram_jobs($user->login, $now); + if ($res > 0) + { + if ($resrunjob >= 0) // We add result of reprogram ony if no error message already reported + { + if ($object->lastresult >= 0) setEventMessages($langs->trans("JobFinished"), null, 'mesgs'); + else setEventMessages($langs->trans("JobFinished"), null, 'errors'); + } + $action=''; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } + + header("Location: ".DOL_URL_ROOT.'/cron/list.php?status=-2'); // Make a call to avoid to run twice job when using back + exit; + } } @@ -166,7 +175,7 @@ if ($action == 'delete') if ($action == 'execute') { - print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&status='.$status,$langs->trans("CronExecute"),$langs->trans("CronConfirmExecute"),"confirm_execute",'','',1); + print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&status='.$status.'&securitykey='.$securitykey,$langs->trans("CronExecute"),$langs->trans("CronConfirmExecute"),"confirm_execute",'','',1); }