1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 20:57:26 +02:00

Cron scripts working correctly.

This commit is contained in:
CaMer0n
2009-10-23 14:16:08 +00:00
parent 4c7bf15d46
commit 7f5cae55a2
6 changed files with 141 additions and 73 deletions

View File

@@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/cron.php,v $ | $Source: /cvs_backup/e107_0.8/cron.php,v $
| $Revision: 1.4 $ | $Revision: 1.5 $
| $Date: 2009-10-23 09:08:15 $ | $Date: 2009-10-23 14:16:07 $
| $Author: e107coders $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -22,11 +22,25 @@
$_E107['cli'] = TRUE; $_E107['cli'] = TRUE;
require_once(realpath(dirname(__FILE__)."/class2.php")); require_once(realpath(dirname(__FILE__)."/class2.php"));
$pwd = trim($_SERVER['argv'][1]);
if($pref['e_cron_pwd'] != $pwd)
{
require_once(e_HANDLER."mail.php");
$message = "Your Cron Schedule is not configured correctly. Your passwords do not match.
<br /><br />
Sent from cron: ".$pwd."<br />
Stored in e107: ".$pref['e_cron_pwd']."<br /><br />
You should regenerate the cron command in admin and enter it again in your server configuration.
";
sendemail($pref['siteadminemail'], "e107 - Cron Schedule Misconfigured.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
exit;
}
// from the plugin directory: // from the plugin directory:
// realpath(dirname(__FILE__)."/../../")."/"; // realpath(dirname(__FILE__)."/../../")."/";
//echo "\n\nUSERNAME= ".USERNAME."\n";
//echo "\nUSEREMAIL= ".USEREMAIL."\n";
if($pref['e_cron_pref']) // grab cron if($pref['e_cron_pref']) // grab cron
{ {
@@ -39,31 +53,44 @@ if($pref['e_cron_pref']) // grab cron
} }
} }
require_once(e_HANDLER."cron_class.php"); require_once(e_HANDLER."cron_class.php");
$cron = new CronParser(); $cron = new CronParser();
foreach($list as $func=>$val) foreach($list as $func=>$val)
{ {
$cron->calcLastRan($val['tab']); $cron->calcLastRan($val['tab']);
$due = $cron->getLastRanUnix(); $due = $cron->getLastRanUnix();
if($due > (time()-45)) if($due > (time()-45))
{ {
if(is_readable(e_PLUGIN.$val['path']."/e_cron.php")) if(($val['path']=='_system') || is_readable(e_PLUGIN.$val['path']."/e_cron.php"))
{ {
// echo date("r")." ".$func."\n"; if($val['path'] != '_system')
require_once(e_PLUGIN.$val['path']."/e_cron.php");
require_once(e_HANDLER."mail.php");
$message = "Your Cron Job worked correctly. Sent at ".date("r").".";
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
if(call_user_func($func)===FALSE)
{ {
include_once(e_PLUGIN.$val['path']."/e_cron.php");
}
$classname = $val['class']."_cron";
if(class_exists($classname))
{
$obj = new $classname;
if(method_exists($obj,$val['function']))
{
// $mes->add("Executing config function <b>".$key." : ".$method_name."()</b>", E_MESSAGE_DEBUG);
$status = call_user_func(array($obj,$val['function']));
if(!$status)
{
//TODO log error in admin log.
// echo "\nerror running the function ".$func.".\n"; log the error. // echo "\nerror running the function ".$func.".\n"; log the error.
} }
} }
} }
}
}
// echo "Cron Unix = ". $cron->getLastRanUnix(); // echo "Cron Unix = ". $cron->getLastRanUnix();
// echo "<br />Now = ".time(); // echo "<br />Now = ".time();
@@ -71,6 +98,32 @@ foreach($list as $func=>$val)
class _system_cron
{
// See admin/cron.php to configure more core cron function to be added below.
function myfunction()
{
// Whatever code you wish.
}
function sendEmail() // Test Email.
{
global $pref;
require_once(e_HANDLER."mail.php");
$message = "Your Cron test worked correctly. Sent at ".date("r").".";
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.".date("r"), $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
}
}
// echo "<br />Cron '$cron_str0' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>"; // echo "<br />Cron '$cron_str0' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
// $cron->getLastRan() returns last due time in an array // $cron->getLastRan() returns last due time in an array

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_admin/cron.php,v $ | $Source: /cvs_backup/e107_0.8/e107_admin/cron.php,v $
| $Revision: 1.5 $ | $Revision: 1.6 $
| $Date: 2009-10-23 09:08:15 $ | $Date: 2009-10-23 14:16:07 $
| $Author: e107coders $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -43,6 +43,7 @@ class cron
function cron() function cron()
{ {
global $pref;
$this->cronAction = e_QUERY; $this->cronAction = e_QUERY;
@@ -58,20 +59,19 @@ class cron
if(isset($_POST['execute'])) if(isset($_POST['execute']))
{ {
$func = key($_POST['execute']); $class_func = key($_POST['execute']);
$this -> cronExecute($func); $this -> cronExecute($class_func);
} }
// Set Core Cron Options. // Set Core Cron Options.
$this->coreCrons['user'] = array( $this->coreCrons['_system'] = array(
0 => array('name'=>'User Purge','function' => 'user_purge', 'description'=>'Purge Unactivated Users'), 0 => array('name' => "Test Email", 'function' => "sendEmail", 'description' => "Send a test email to ".$pref['siteadminemail']."<br />Recommended to test the scheduling system."),
1 => array('name'=>'User UnActivated','function' => 'user_unactivated', 'description'=>'Resend activation email to unactivated users.') // 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')
); );
$this->coreCrons['news'] = array(
0 => array('name'=>'News Sticky','function' => 'news_purge', 'description'=>'Remove Sticky News Items')
);
// 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()
@@ -81,6 +81,8 @@ class cron
$this -> cronRenderPage(); $this -> cronRenderPage();
} }
if($this->cronAction == "pref") if($this->cronAction == "pref")
{ {
$this -> cronRenderPrefs(); $this -> cronRenderPrefs();
@@ -88,7 +90,7 @@ class cron
} }
function cronExecute($func) function cronExecute($class_func)
{ {
//TODO LANs //TODO LANs
$mes = eMessage::getInstance(); $mes = eMessage::getInstance();
@@ -114,6 +116,7 @@ class cron
global $pref; global $pref;
$mes = e107::getMessage(); $mes = e107::getMessage();
$activeCount = 0;
foreach($_POST['cron'] as $key=>$val) foreach($_POST['cron'] as $key=>$val)
{ {
@@ -121,6 +124,10 @@ class cron
{ {
$val['active'] = 0; $val['active'] = 0;
} }
else
{
$activeCount++;
}
$t['minute'] = implode(",",$_POST['tab'][$key]['minute']); $t['minute'] = implode(",",$_POST['tab'][$key]['minute']);
$t['hour'] = implode(",",$_POST['tab'][$key]['hour']); $t['hour'] = implode(",",$_POST['tab'][$key]['hour']);
@@ -135,17 +142,39 @@ class cron
$val['function'] = $func; $val['function'] = $func;
$val['class'] = $class; $val['class'] = $class;
$val['path'] = $class;
$cron[$key] = $val; $cron[$key] = $val;
} }
$pref['e_cron_pref'] = $cron; $pref['e_cron_pref'] = $cron;
if(!vartrue($pref['e_cron_pwd']) || varset($_POST['generate_pwd']))
{
require_once (e_HANDLER.'user_handler.php');
$userMethods = new UserHandler;
// # - an alpha character
// . - a numeric character
// * - an alphanumeric character
// ^ - next character from seed
$newpwd = $userMethods->generateRandomString('*^*#.**^*');
$newpwd = sha1($newpwd.time());
$pref['e_cron_pwd'] = $newpwd;
$setpwd_message = "Use the following Cron Command:<br /><b style='color:black'>".$_SERVER['DOCUMENT_ROOT'].e_HTTP."cron.php ".$pref['e_cron_pwd']."</b><br />
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 of every day.";
$mes->add($setpwd_message, E_MESSAGE_WARNING);
}
// print_a($pref['e_cron_pref']); // print_a($pref['e_cron_pref']);
if(save_prefs()) 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 else
{ {
@@ -168,16 +197,12 @@ class cron
</td> </td>
</tr> </tr>
<tr>
<td style='width:30%'>bcc: </td>
<td style='width:70%'>
<input type='text' name='name2' class='tbox' style='width:80%' value='' />
</td>
</tr>
<tr style='vertical-align:top'> <tr style='vertical-align:top'>
<td colspan='2' class='center buttons-bar'>"; <td colspan='2' class='center buttons-bar'>";
$text .= $frm->admin_button('save_prefs',LAN_SAVE, 'update'); $text .= $frm->admin_button('save_prefs',LAN_SAVE, 'update');
$text .= "</td> $text .= "</td>
</tr> </tr>
</table> </table>
@@ -203,13 +228,15 @@ class cron
$mes = e107::getMessage(); $mes = e107::getMessage();
$core_cron = $this->coreCrons; $core_cron = $this->coreCrons;
$new_cron = array();
foreach($pref['e_cron_list'] as $key=>$val) foreach($pref['e_cron_list'] as $key=>$val)
{ {
$eplug_cron = array(); $eplug_cron = array();
if(is_readable(e_PLUGIN.$key."/e_cron.php")) if(is_readable(e_PLUGIN.$key."/e_cron.php"))
{ {
require_once(e_PLUGIN.$key."/e_cron.php"); include_once(e_PLUGIN.$key."/e_cron.php");
$class_name = $key."_cron"; $class_name = $key."_cron";
$method_name = 'config'; $method_name = 'config';
@@ -235,6 +262,7 @@ class cron
$e_cron = array_merge($core_cron,$new_cron); $e_cron = array_merge($core_cron,$new_cron);
// print_a($e_cron);
// ---------------------- List All Functions ----------------------------- // ---------------------- List All Functions -----------------------------
@@ -316,7 +344,7 @@ class cron
if($sep['minute'] == $key) if($sep['minute'] == $key)
{ {
$sel = "selected='selected'"; $sel = "selected='selected'";
$minute = ""; $minute = array();
} }
else else
{ {
@@ -342,7 +370,7 @@ class cron
if($sep['hour'] == $key) if($sep['hour'] == $key)
{ {
$sel = "selected='selected'"; $sel = "selected='selected'";
$hour = ""; $hour = array();
} }
else else
{ {
@@ -416,6 +444,7 @@ class cron
<div class='center buttons-bar'>"; <div class='center buttons-bar'>";
// $text .= "<input class='button' type='submit' name='submit' value='".LAN_SAVE."' />"; // $text .= "<input class='button' type='submit' name='submit' value='".LAN_SAVE."' />";
$text .= $frm->admin_button('submit', LAN_SAVE, $action = 'update'); $text .= $frm->admin_button('submit', LAN_SAVE, $action = 'update');
$text .= $frm->checkbox_switch('generate_pwd',1,'','Generate new cron command');
$text .= "</div></td> $text .= "</div></td>
</tr> </tr>
</tbody> </tbody>
@@ -433,12 +462,12 @@ class cron
$var['main']['text'] = PAGE_NAME; $var['main']['text'] = PAGE_NAME;
$var['main']['link'] = e_SELF; $var['main']['link'] = e_SELF;
/*
$var['pref']['text'] = LAN_PREFS; $var['pref']['text'] = LAN_PREFS;
$var['pref']['link'] = e_SELF."?pref"; $var['pref']['link'] = e_SELF."?pref";
$var['pref']['perm'] = "N"; $var['pref']['perm'] = "N";
$action = ($this->cronAction) ? $this->cronAction : "main"; */ $action = ($this->cronAction) ? $this->cronAction : "main";
e_admin_menu(PAGE_NAME, $action, $var); e_admin_menu(PAGE_NAME, $action, $var);
} }

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_admin/plugin.php,v $ | $Source: /cvs_backup/e107_0.8/e107_admin/plugin.php,v $
| $Revision: 1.49 $ | $Revision: 1.50 $
| $Date: 2009-10-20 03:49:12 $ | $Date: 2009-10-23 14:16:08 $
| $Author: e107coders $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -220,7 +220,7 @@ class pluginManager{
'del_extended' => varset($_POST['delete_xfields'],FALSE), 'del_extended' => varset($_POST['delete_xfields'],FALSE),
'del_ipool' => varset($_POST['delete_ipool'],FALSE) 'del_ipool' => varset($_POST['delete_ipool'],FALSE)
); );
$text .= $plugin->manage_plugin_xml($this->id, 'uninstall', $options); $text .= $plugin->install_plugin_xml($this->id, 'uninstall', $options);
} }
else else
{ // Deprecated - plugin uses plugin.php { // Deprecated - plugin uses plugin.php
@@ -466,7 +466,7 @@ class pluginManager{
$_path = e_PLUGIN.$plug['plugin_path'].'/'; $_path = e_PLUGIN.$plug['plugin_path'].'/';
if(file_exists($_path.'plugin.xml')) if(file_exists($_path.'plugin.xml'))
{ {
$plugin->manage_plugin_xml($this->id, 'upgrade'); $plugin->install_plugin_xml($this->id, 'upgrade');
} }
else else
{ {
@@ -596,7 +596,7 @@ class pluginManager{
$_path = e_PLUGIN.$plug['plugin_path'].'/'; $_path = e_PLUGIN.$plug['plugin_path'].'/';
if(file_exists($_path.'plugin.xml')) if(file_exists($_path.'plugin.xml'))
{ {
$text .= $plugin->manage_plugin_xml($this->id, 'refresh'); $text .= $plugin->install_plugin_xml($this->id, 'refresh');
$admin_log->log_event('PLUGMAN_04', $this->id.':'.$plug['plugin_path'], E_LOG_INFORMATIVE, ''); $admin_log->log_event('PLUGMAN_04', $this->id.':'.$plug['plugin_path'], E_LOG_INFORMATIVE, '');
} }

View File

@@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt) * Copyright e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id: lan_admin.php,v 1.29 2009-10-06 18:58:08 e107steved Exp $ * $Id: lan_admin.php,v 1.30 2009-10-23 14:16:08 e107coders Exp $
* *
* Admin Language File * Admin Language File
*/ */
@@ -175,8 +175,8 @@ define('ADLAN_154', "Error contacting Sourceforge to check for new version");
define('ADLAN_155', 'System Logs'); define('ADLAN_155', 'System Logs');
define('ADLAN_156', 'Admin log, user audit, rolling log'); define('ADLAN_156', 'Admin log, user audit, rolling log');
define("ADLAN_157", "Schedule Tasks"); define("ADLAN_157", "Schedule Maintenance");
define("ADLAN_158", "Cron Jobs and Automated Tasks"); define("ADLAN_158", "Cron Jobs and Automated Maintenance");
define("ADLAN_159", "URL Configuration"); define("ADLAN_159", "URL Configuration");
define("ADLAN_160", "Configure Site URLs"); define("ADLAN_160", "Configure Site URLs");

View File

@@ -4,12 +4,12 @@
| e107 website system - Language File. | e107 website system - Language File.
| |
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_cron.php,v $ | $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_cron.php,v $
| $Revision: 1.1 $ | $Revision: 1.2 $
| $Date: 2008-06-17 05:39:30 $ | $Date: 2009-10-23 14:16:08 $
| $Author: e107coders $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
if (!defined("PAGE_NAME")) { define("PAGE_NAME", "Schedule Tasks"); } if (!defined("PAGE_NAME")) { define("PAGE_NAME", "Schedule Maintenance"); }
define("LAN_CRON_1", "Name"); define("LAN_CRON_1", "Name");
define("LAN_CRON_2", "Description"); define("LAN_CRON_2", "Description");

View File

@@ -9,8 +9,8 @@
* Plugin configuration module - gsitemap * Plugin configuration module - gsitemap
* *
* $Source: /cvs_backup/e107_0.8/e107_plugins/gsitemap/e_cron.php,v $ * $Source: /cvs_backup/e107_0.8/e107_plugins/gsitemap/e_cron.php,v $
* $Revision: 1.3 $ * $Revision: 1.4 $
* $Date: 2009-10-23 09:08:15 $ * $Date: 2009-10-23 14:16:08 $
* $Author: e107coders $ * $Author: e107coders $
* *
*/ */
@@ -21,20 +21,6 @@ if (!defined('e107_INIT')) { exit; }
return; return;
}*/ }*/
// -------- e_cron setup -----------------------------------------------------
$cron['name'] = "Update Records";
$cron['function'] = "gsitemap_myfunction";
$cron['description'] = "Dummy example.";
$cron2['name'] = "Test Email";
$cron2['function'] = "gsitemap_myfunction2";
$cron2['description'] = "Sends a test email to ".$pref['siteadminemail'];
// $eplug_cron[] = $cron2;
// ------------------------- Functions -----------------------------------------
class gsitemap_cron // include plugin-folder in the name. class gsitemap_cron // include plugin-folder in the name.
{ {
@@ -43,7 +29,7 @@ class gsitemap_cron // include plugin-folder in the name.
global $pref; global $pref;
$cron = array(); $cron = array();
/*
$cron[] = array( $cron[] = array(
'name' => "Update Records", 'name' => "Update Records",
'function' => "myfunction", 'function' => "myfunction",
@@ -54,7 +40,7 @@ class gsitemap_cron // include plugin-folder in the name.
'name' => "Test Email", 'name' => "Test Email",
'function' => "sendEmail", 'function' => "sendEmail",
'description' => "Sends a test email to ".$pref['siteadminemail'] 'description' => "Sends a test email to ".$pref['siteadminemail']
); ); */
return $cron; return $cron;
} }
@@ -73,7 +59,7 @@ class gsitemap_cron // include plugin-folder in the name.
global $pref; global $pref;
require_once(e_HANDLER."mail.php"); require_once(e_HANDLER."mail.php");
$message = "Your Cron Job worked correctly. Sent at ".date("r")."."; $message = "Your Cron Job worked correctly. Sent at ".date("r").".";
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']); sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.".date("r"), $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
} }
} }