diff --git a/e107_admin/cron.php b/e107_admin/cron.php index 388908b02..fdc5e5233 100644 --- a/e107_admin/cron.php +++ b/e107_admin/cron.php @@ -1,37 +1,31 @@ cronAction = e_QUERY; - + $pref = e107::getPref(); + $mes = e107::getMessage(); + $this->cronAction = e_QUERY; + // The 'available' flag only gives the option to configure the cron if the underlying feature is enabled $this->coreCrons['_system'] = array( 0 => array('name' => 'Test Email', 'function' => 'sendEmail', 'description' => 'Send a test email to '.$pref['siteadminemail'].'
Recommended to test the scheduling system.'), 1 => array('name' => 'Mail Queue', 'function' => 'procEmailQueue', 'description' => 'Process mail queue'), 2 => array('name' => 'Mail Bounce Check', 'function' => 'procEmailBounce', 'description' => 'Check for bounced emails', 'available' => vartrue($pref['mail_bounce_auto'])), - // 1 => array('name'=>'User Purge', 'function' => 'userPurge', 'description'=>'Purge Unactivated Users'), - // 2 => array('name'=>'User UnActivated', 'function' => 'userUnactivated', 'description'=>'Resend activation email to unactivated users.'), - // 3 => array('name'=>'News Sticky', 'function' => 'newsPurge', 'description'=>'Remove Sticky News Items') - ); - - - if(!vartrue($pref['e_cron_pwd'])) - { + // 1 => array('name'=>'User Purge', 'function' => 'userPurge', 'description'=>'Purge Unactivated Users'), + // 2 => array('name'=>'User UnActivated', 'function' => 'userUnactivated', 'description'=>'Resend activation email to unactivated users.'), + // 3 => array('name'=>'News Sticky', 'function' => 'newsPurge', 'description'=>'Remove Sticky News Items') + ); + + if (!vartrue($pref['e_cron_pwd'])) + { $pwd = $this->setCronPwd(); } - - - if(isset($_POST['submit'])) + if (isset($_POST['submit'])) { - $this->cronSave(); + $this->cronSave(); } - + $this->lastRefresh(); $this->cronLoad(); - if(isset($_POST['save_prefs'])) + if (isset($_POST['save_prefs'])) { - $this -> cronSavePrefs(); + $this->cronSavePrefs(); } - - if(isset($_POST['execute'])) + + if (isset($_POST['execute'])) { $class_func = key($_POST['execute']); - $this -> cronExecute($class_func); + $this->cronExecute($class_func); } // Set Core Cron Options. - - - + // These core functions need to be put into e_BASE/cron.php ie. news_purge() - // These core functions need to be put into e_BASE/cron.php ie. news_purge() - - if($this->cronAction == "" || $this->cronAction == "main") + if ($this->cronAction == "" || $this->cronAction == "main") { - $this -> cronRenderPage(); + $this->cronRenderPage(); } - - - if($this->cronAction == "pref") + if ($this->cronAction == "pref") { - $this -> cronRenderPrefs(); + $this->cronRenderPrefs(); } } - function lastRefresh() { - global $pref; + $pref = e107::getPref(); e107::getCache()->CachePageMD5 = '_'; - $lastload = e107::getCache()->retrieve('cronLastLoad',FALSE,TRUE,TRUE); + $lastload = e107::getCache()->retrieve('cronLastLoad', FALSE, TRUE, TRUE); $mes = e107::getMessage(); - $ago = (time() - $lastload); - + $ago = (time() - $lastload); + $active = ($ago < 901) ? TRUE : FALSE; $status = ($active) ? LAN_ENABLED : LAN_DISABLED; // "Enabled" : "Offline"; - - $mins = floor ($ago / 60); - $secs = $ago % 60; - - $lastRun = ($mins) ? $mins." minutes and ".$secs." seconds ago." : $secs." seconds ago."; - - + + $mins = floor($ago / 60); + $secs = $ago % 60; + + $lastRun = ($mins) ? $mins." minutes and ".$secs." seconds ago." : $secs." seconds ago."; + $lastRefresh = ($ago < 10000) ? $lastRun : 'Never'; - + $mes->add("Status: ".$status."", E_MESSAGE_INFO); - + // print_a($pref['e_cron_pref']); + + if ($pref['e_cron_pref']) // grab cron - if($pref['e_cron_pref']) // grab cron { - foreach($pref['e_cron_pref'] as $func=>$cron) + foreach ($pref['e_cron_pref'] as $func => $cron) { - if($cron['active']==1) + if ($cron['active'] == 1) { - $list[$func] = $cron; + $list[$func] = $cron; } } } - - $mes->add("Active Crons: ".count($list)."", E_MESSAGE_INFO); + + $mes->add("Active Crons: ".count($list)."", E_MESSAGE_INFO); $mes->add("Last cron refresh: ".$lastRefresh, E_MESSAGE_INFO); //FIXME: for Windows, the is_executable() function only checks the file // extensions of exe, com, bat and cmd. - if(!is_executable(e_BASE."cron.php")) + if (!is_executable(e_BASE."cron.php")) { - $mes->add("Please CHMOD /cron.php to 755" , E_MESSAGE_WARNING); + $mes->add("Please CHMOD /cron.php to 755", E_MESSAGE_WARNING); } - elseif(!$active) + elseif (!$active) { - $setpwd_message = "Use the following Cron Command: ".$_SERVER['DOCUMENT_ROOT'].e_HTTP."cron.php ".$pref['e_cron_pwd']."
+ $setpwd_message = "Use the following Cron Command: ".$_SERVER['DOCUMENT_ROOT'].e_HTTP."cron.php ".$pref['e_cron_pwd']."
Using your server control panel (eg. cPanel,Plesk etc.) please create a crontab to run this command on your server every minute."; - $mes->add($setpwd_message, E_MESSAGE_INFO); + $mes->add($setpwd_message, E_MESSAGE_INFO); } - - } - -function cronName($classname,$method) -{ - $tp = e107::getParser(); - - foreach($this->e_cron as $class=>$val) + function cronName($classname, $method) { - - if($class == $classname) + $tp = e107::getParser(); + + foreach ($this->e_cron as $class => $val) { - foreach($val as $func) + + if ($class == $classname) { - if($func['function'] == $method) + foreach ($val as $func) { - return $tp->toHtml($func['name']); + if ($func['function'] == $method) + { + return $tp->toHtml($func['name']); + } } } } } -} - - + function cronExecute($class_func) { //TODO LANs - list($class_name,$method_name) = explode("__",$class_func); + list($class_name, $method_name) = explode("__", $class_func); $mes = e107::getMessage(); - + $taskName = $class_name; - if($class_name =='_system') + if ($class_name == '_system') { require_once(e_HANDLER.'cron_class.php'); } @@ -212,14 +190,14 @@ function cronName($classname,$method) require_once(e_PLUGIN.$class_name.'/e_cron.php'); } $class_name .= '_cron'; - $status = $this->cronExecuteMethod($class_name,$method_name) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; - $mes->add("Running ".$this->cronName($taskName,$method_name)."", $status); + $status = $this->cronExecuteMethod($class_name, $method_name) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes->add("Running ".$this->cronName($taskName, $method_name)."", $status); } - function cronSavePref() + function cronSavePref() { - // Store the USERID with the password. + // Store the USERID with the password. // This way only the one password is needed, and the user login can be looked up in e_base/cron.php } @@ -227,92 +205,91 @@ function cronName($classname,$method) function cronSave() { global $pref; - + $mes = e107::getMessage(); $activeCount = 0; - - foreach($_POST['cron'] as $key=>$val) + + foreach ($_POST['cron'] as $key => $val) { - if(!$val['active']) + if (!$val['active']) { - $val['active'] = 0; + $val['active'] = 0; } else { $activeCount++; } - $t['minute'] = implode(",",$_POST['tab'][$key]['minute']); - $t['hour'] = implode(",",$_POST['tab'][$key]['hour']); - $t['day'] = implode(",",$_POST['tab'][$key]['day']); - $t['month'] = implode(",",$_POST['tab'][$key]['month']); - $t['weekday'] = implode(",",$_POST['tab'][$key]['weekday']); + $t['minute'] = implode(",", $_POST['tab'][$key]['minute']); + $t['hour'] = implode(",", $_POST['tab'][$key]['hour']); + $t['day'] = implode(",", $_POST['tab'][$key]['day']); + $t['month'] = implode(",", $_POST['tab'][$key]['month']); + $t['weekday'] = implode(",", $_POST['tab'][$key]['weekday']); - $val['tab'] = implode(" ",$t); + $val['tab'] = implode(" ", $t); $tabs .= $val['tab']."
"; - - list($class,$func) = explode("__",$key); - + + list($class, $func) = explode("__", $key); + $val['function'] = $func; - $val['class'] = $class; - $val['path'] = $class; - - $cron[$key] = $val; + $val['class'] = $class; + $val['path'] = $class; + + $cron[$key] = $val; } $pref['e_cron_pref'] = $cron; - - if(!vartrue($pref['e_cron_pwd']) || varset($_POST['generate_pwd'])) - { + + if (!vartrue($pref['e_cron_pwd']) || varset($_POST['generate_pwd'])) + { $pwd = $this->setCronPwd(); - + $setpwd_message = "Use the following Cron Command:
".$_SERVER['DOCUMENT_ROOT'].e_HTTP."cron.php ".$pwd."
This cron command is unique and will not be displayed again. Please copy and paste it into your webserver cron area to be run every minute (or 15 minutes) of every day."; $mes->add($setpwd_message, E_MESSAGE_WARNING); } - - - // print_a($pref['e_cron_pref']); - if(save_prefs()) + // print_a($pref['e_cron_pref']); + + if (save_prefs()) { - $mes->add(LAN_SETSAVED, E_MESSAGE_SUCCESS); + $mes->add(LAN_SETSAVED, E_MESSAGE_SUCCESS); $mes->add($activeCount." Cron(s) Active", E_MESSAGE_SUCCESS); } else { - $mes->add("There was a problem saving your settings.", E_MESSAGE_ERROR); + $mes->add("There was a problem saving your settings.", E_MESSAGE_ERROR); } } - -function setCronPwd() -{ - global $pref; - + function setCronPwd() + { + //global $pref; + $userMethods = e107::getUserSession(); $newpwd = $userMethods->generateRandomString('*^*#.**^*'); - $newpwd = sha1($newpwd.time()); - $pref['e_cron_pwd'] = $newpwd; - - return save_prefs(); - -} - - -// -------------------------------------------------------------------------- + $newpwd = sha1($newpwd.time()); + //$pref['e_cron_pwd'] = $newpwd; + e107::getConfig()->set('e_cron_pwd', $newpwd)->save(false); + return true; + + } + + // -------------------------------------------------------------------------- function cronRenderPrefs() { - global $frm,$ns; - - $text = "
-
+ //global $frm,$ns; + $frm = e107::getForm(); + $text = "
+ @@ -320,48 +297,47 @@ function setCronPwd() + $text .= $frm->admin_button('save_prefs', LAN_SAVE, 'update'); + + $text .= "
Cron Password - ".$frm->password('cron_password',100)." + " + .$frm->password('cron_password', 100)."
"; - $text .= $frm->admin_button('save_prefs',LAN_SAVE, 'update'); - - $text .= "
"; - $ns -> tablerender(LAN_PREFS, $text); + e107::getRender()->tablerender(LAN_PREFS, $text); - } + } function cronLoad() //TODO Make a generic function to work with e_cron, e_sitelink, e_url etc. + { - global $pref; - - $core_cron = $this->coreCrons; // May need to check 'available' flag here + $pref = e107::getPref(); + + $core_cron = $this->coreCrons; // May need to check 'available' flag here $new_cron = e107::getAddonConfig('e_cron'); - $this->e_cron = array_merge($core_cron,$new_cron); + $this->e_cron = array_merge($core_cron, $new_cron); return; } - - -// ----------- Grab All e_cron parameters ----------------------------------- + // ----------- Grab All e_cron parameters ----------------------------------- function cronRenderPage() { - global $pref; - $cronpref = $pref['e_cron_pref']; + $pref = e107::getPref(); + $cronpref = $pref['e_cron_pref']; $ns = e107::getRender(); $frm = e107::getForm(); $mes = e107::getMessage(); - + $e_cron = $this->e_cron; - - - // ---------------------- List All Functions ----------------------------- + + // ---------------------- List All Functions ----------------------------- $text = "
-
+ @@ -375,85 +351,95 @@ function setCronPwd() - - - - - - - - + + + + + + + + "; - foreach($e_cron as $plug=>$cfg) - { - foreach($cfg as $class=>$cron) + foreach ($e_cron as $plug => $cfg) { - if (!isset($cron['available']) || $cron['available']) // Only display cron functions which are available + foreach ($cfg as $class => $cron) { - $c = $plug.'__'. $cron['function']; // class and function. - $sep = array(); - - list($sep['minute'],$sep['hour'],$sep['day'],$sep['month'],$sep['weekday']) = explode(" ",$cronpref[$c]['tab']); - - foreach($sep as $key=>$value) + if (!isset($cron['available']) || $cron['available']) // Only display cron functions which are available + { - if($value=="") + $c = $plug.'__'.$cron['function']; // class and function. + $sep = array(); + + list($sep['minute'], $sep['hour'], $sep['day'], $sep['month'], $sep['weekday']) = explode(" ", $cronpref[$c]['tab']); + + foreach ($sep as $key => $value) { - $sep[$key] = "*"; + if ($value == "") + { + $sep[$key] = "*"; + } } - } - $minute = explode(",",$sep['minute']); - $hour = explode(",",$sep['hour']); - $day = explode(",",$sep['day']); - $month = explode(",",$sep['month']); - $weekday = explode(",",$sep['weekday']); + $minute = explode(",", $sep['minute']); + $hour = explode(",", $sep['hour']); + $day = explode(",", $sep['day']); + $month = explode(",", $sep['month']); + $weekday = explode(",", $sep['weekday']); - $min_options = array( - "*" => LAN_CRON_11, - "0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58" => LAN_CRON_12, - "0,5,10,15,20,25,30,35,40,45,50,55" => LAN_CRON_13, - "0,10,20,30,40,50" => LAN_CRON_14, - "0,15,30,45" => LAN_CRON_10, - "0,30" => LAN_CRON_15 - ); + $min_options = array( + "*" => LAN_CRON_11, + "0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58" => LAN_CRON_12, + "0,5,10,15,20,25,30,35,40,45,50,55" => LAN_CRON_13, + "0,10,20,30,40,50" => LAN_CRON_14, + "0,15,30,45" => LAN_CRON_10, + "0,30" => LAN_CRON_15 + ); - $hour_options = array( - "*" => LAN_CRON_16, - "0,2,4,6,8,10,12,14,16,18,20,22" => LAN_CRON_17, - "0,3,6,9,12,15,18,21" => LAN_CRON_18, - "0,6,12,18" => LAN_CRON_19 - ); + $hour_options = array( + "*" => LAN_CRON_16, + "0,2,4,6,8,10,12,14,16,18,20,22" => LAN_CRON_17, + "0,3,6,9,12,15,18,21" => LAN_CRON_18, + "0,6,12,18" => LAN_CRON_19 + ); - $text .= " - - + $text .= " + + @@ -490,9 +476,9 @@ function setCronPwd() $sel_day = ($day[0] == "*") ? "selected='selected'" : ""; $text .= "\n"; // Every Day - for ($i=1; $i<=31; $i++) + for ($i = 1; $i <= 31; $i++) { - $sel = (in_array($i,$day)) ? "selected='selected'" : ""; + $sel = (in_array($i, $day)) ? "selected='selected'" : ""; $text .= "\n"; } $text .= " @@ -503,11 +489,11 @@ function setCronPwd() $sel_month = ($month[0] == "*") ? "selected='selected'" : ""; $text .= "\n"; // Every Month - for ($i=1; $i<=12; $i++) + for ($i = 1; $i <= 12; $i++) { - $sel = (in_array($i,$month)) ? "selected='selected'" : ""; - $diz = mktime(00,00,00,$i,1,2000); - $text .= "\n"; + $sel = (in_array($i, $month)) ? "selected='selected'" : ""; + $diz = mktime(00, 00, 00, $i, 1, 2000); + $text .= "\n"; } $text .= " @@ -516,11 +502,11 @@ function setCronPwd() $sel_weekday = ($weekday[0] == "*") ? "selected='selected'" : ""; $text .= "\n"; // Every Week Day. - $days = array(LAN_SUN,LAN_MON,LAN_TUE,LAN_WED,LAN_THU,LAN_FRI,LAN_SAT); + $days = array(LAN_SUN, LAN_MON, LAN_TUE, LAN_WED, LAN_THU, LAN_FRI, LAN_SAT); - for ($i=0; $i<=6; $i++) + for ($i = 0; $i <= 6; $i++) { - $sel = (in_array(strval($i),$weekday)) ? "selected='selected'" : ""; + $sel = (in_array(strval($i), $weekday)) ? "selected='selected'" : ""; $text .= "\n"; } $text .= " @@ -532,68 +518,67 @@ function setCronPwd() "; + } } } - } $text .= " + // $text .= ""; + $text .= $frm->admin_button('submit', LAN_SAVE, $action = 'update'); + $text .= $frm->checkbox_switch('generate_pwd', 1, '', 'Generate new cron command'); + $text .= "
".LAN_CRON_1."".LAN_CRON_2."".LAN_CRON_3."".LAN_CRON_4."".LAN_CRON_5."".LAN_CRON_6."".LAN_CRON_7."".LAN_CRON_8."" + .LAN_CRON_1."" + .LAN_CRON_2."" + .LAN_CRON_3."" + .LAN_CRON_4."" + .LAN_CRON_5."" + .LAN_CRON_6."" + .LAN_CRON_7."" + .LAN_CRON_8." Run Now
".$cron['name']."".$cron['description']."
" + .$cron['name']."" + .$cron['description']." @@ -462,25 +448,25 @@ function setCronPwd() ".$frm->admin_button('execute['.$c.']', 'Run Now')."
"; - // $text .= ""; - $text .= $frm->admin_button('submit', LAN_SAVE, $action = 'update'); - $text .= $frm->checkbox_switch('generate_pwd',1,'','Generate new cron command'); - $text .= "
"; - $ns -> tablerender(PAGE_NAME, $mes->render() . $text); + $ns->tablerender(PAGE_NAME, $mes->render().$text); } function cronOptions() { - $e107 = &e107::getInstance(); + $e107 = e107::getInstance(); $var['main']['text'] = PAGE_NAME; $var['main']['link'] = e_SELF; -/* - $var['pref']['text'] = LAN_PREFS; - $var['pref']['link'] = e_SELF."?pref"; - $var['pref']['perm'] = "N"; - - */ $action = ($this->cronAction) ? $this->cronAction : 'main'; + /* + $var['pref']['text'] = LAN_PREFS; + $var['pref']['link'] = e_SELF."?pref"; + $var['pref']['perm'] = "N"; + + */ $action = ($this->cronAction) ? $this->cronAction : 'main'; e_admin_menu(PAGE_NAME, $action, $var); } - - function cronExecuteMethod($class_name,$method_name,$return='boolean') + function cronExecuteMethod($class_name, $method_name, $return = 'boolean') { $mes = e107::getMessage(); - if(class_exists($class_name)) + if (class_exists($class_name)) { $obj = new $class_name; - if(method_exists($obj,$method_name)) + if (method_exists($obj, $method_name)) { - $mes->add("Executing config function ".$key." : ".$method_name."()", E_MESSAGE_DEBUG); - if($return == 'boolean') + $mes->add("Executing config function ".$class_name." : ".$method_name."()", E_MESSAGE_DEBUG); + if ($return == 'boolean') { - call_user_func(array($obj,$method_name)); + call_user_func(array($obj, $method_name)); return TRUE; } else { - return call_user_func(array($obj,$method_name)); + return call_user_func(array($obj, $method_name)); } } else { - $mes->add("Config function ".$method_name."() NOT found.", E_MESSAGE_DEBUG); - } + $mes->add("Config function ".$method_name."() NOT found.", E_MESSAGE_DEBUG); + } } return FALSE; } @@ -605,5 +590,4 @@ function cron_adminmenu() $cron->cronOptions(); } - ?> \ No newline at end of file