set_time_limit(0);
$starttime = microtime();
+/// this cron script might be considered to be a CLI script even when accessed over HTTP,
+/// we do not want HTML in output and there is no real session ;-)
+ define('CLI_SCRIPT', true);
+
/// The following is a hack necessary to allow this script to work well
/// from the command line.
-
- define('FULLME', 'cron');
-
+ define('FULLME', 'cron'); //TODO: to be removed soon ;-)
/// Do not set moodle cookie because we do not need it here, it is better to emulate session
define('NO_MOODLE_COOKIES', true);
-/// The current directory in PHP version 4.3.0 and above isn't necessarily the
-/// directory of the script when run from the command line. The require_once()
-/// would fail, so we'll have to chdir()
-
- if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
- chdir(dirname($_SERVER['argv'][0]));
- }
-
require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/gradelib.php');
* php -d error_log=/path/to/log thisfile.php will override the default error log for php cli, which is stderr, so if you want this script to just print stuff out, use php thisfile.php instead.
*/
-require_once($CFG->libdir.'/eventslib.php');
-
-
$fd = fopen('php://stdin','r');
if (!$fd) {
exit();
}
-$FULLME='cron';
require_once(dirname(dirname(__FILE__)).'/config.php');
+require_once($CFG->libdir.'/eventslib.php');
require_once($CFG->dirroot.'/lib/uploadlib.php'); // contains virus handling stuff.
$site = get_site();
#!/usr/bin/php -f
<?php // $Id$
-define('FULLME','cron'); // prevent warnings
+
//error_reporting(0);
//ini_set('display_errors',0);
require_once(dirname(dirname(__FILE__)).'/config.php');
ORDER BY ctx.depth, ctx.path";
$params = array($roleid);
- // we need extra caching in cron only
- if (defined('FULLME') and FULLME === 'cron') {
+ // we need extra caching in CLI scripts and cron
+ if (CLI_SCRIPT) {
static $cron_cache = array();
if (!isset($cron_cache[$roleid])) {
array_shift($contexts);
}
- if (defined('FULLME') && FULLME === 'cron' && !isset($USER->access)) {
+ if (CLI_SCRIPT && !isset($USER->access)) {
// In cron, some modules setup a 'fake' $USER,
// ensure we load the appropriate accessdata.
if (isset($ACCESS[$userid])) {
$ACCESS = array();
$RDEFS = array();
- if (defined('FULLME') && FULLME === 'cron') {
+ if (CLI_SCRIPT) {
load_user_accessdata($userid);
$USER->access = $ACCESS[$userid];
$DIRTYCONTEXTS = array();
$auth = empty($user->auth) ? 'manual' : $user->auth; // use manual if auth not set
if ($auth=='nologin' or !is_enabled_auth($auth)) {
add_to_log(0, 'login', 'error', 'index.php', $username);
- error_log('[client '.$_SERVER['REMOTE_ADDR']."] $CFG->wwwroot Disabled Login: $username ".$_SERVER['HTTP_USER_AGENT']);
+ error_log('[client '.getremoteaddr()."] $CFG->wwwroot Disabled Login: $username ".$_SERVER['HTTP_USER_AGENT']);
return false;
}
if (!empty($user->deleted)) {
add_to_log(0, 'login', 'error', 'index.php', $username);
- error_log('[client '.$_SERVER['REMOTE_ADDR']."] $CFG->wwwroot Deleted Login: $username ".$_SERVER['HTTP_USER_AGENT']);
+ error_log('[client '.getremoteaddr()."] $CFG->wwwroot Deleted Login: $username ".$_SERVER['HTTP_USER_AGENT']);
return false;
}
$auths = array($auth);
// failed if all the plugins have failed
add_to_log(0, 'login', 'error', 'index.php', $username);
if (debugging('', DEBUG_ALL)) {
- error_log('[client '.$_SERVER['REMOTE_ADDR']."] $CFG->wwwroot Failed Login: $username ".$_SERVER['HTTP_USER_AGENT']);
+ error_log('[client '.getremoteaddr()."] $CFG->wwwroot Failed Login: $username ".$_SERVER['HTTP_USER_AGENT']);
}
return false;
}
$continue = $exporter->get('caller')->get_return_url();
}
}
- if (!defined('FULLME') || FULLME != 'cron') {
+ if (!defined('FULLME') || FULLME != 'cron') { // TODO: this is not nice at all
$exporter->process_stage_cleanup();
}
} else {
global $CFG, $nomoodlecookie;
if (!defined('NO_MOODLE_COOKIES')) {
- if (isset($nomoodlecookie)) {
+ if (CLI_SCRIPT) {
+ // CLI scripts can not have session
+ define('NO_MOODLE_COOKIES', true);
+ } else if (isset($nomoodlecookie)) {
// backwards compatibility only
define('NO_MOODLE_COOKIES', $nomoodlecookie);
- unset($nomoodlecookie);
} else {
define('NO_MOODLE_COOKIES', false);
}
}
+ unset($nomoodlecookie); // cleanup
if (!isset($CFG->cookiesecure) or strpos($CFG->wwwroot, 'https://') !== 0) {
$CFG->cookiesecure = 0;
die;
}
+/// Detect CLI scripts - CLI scripts are executed from command line, do not have session and we do not want HTML in output
+ if (!defined('CLI_SCRIPT')) { // CLI_SCRIPT might be defined in 'fake' CLI scripts like admin/cron.php
+ if (isset($_SERVER['REMOTE_ADDR'])) {
+ define('CLI_SCRIPT', false);
+ } else {
+ define('CLI_SCRIPT', true);
+ }
+ }
+
+/// The current directory in PHP version 4.3.0 and above isn't necessarily the
+/// directory of the script when run from the command line. The require_once()
+/// would fail, so we'll have to chdir()
+ if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
+ chdir(dirname($_SERVER['argv'][0]));
+ }
+
+
/// store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
$CFG->config_php_settings = (array)$CFG;
$time = time() - $CFG->cachetext;
$md5key = md5($hashstr);
- if (defined('FULLME') and FULLME == 'cron') {
+ if (CLI_SCRIPT) {
if (isset($croncache[$md5key])) {
return $croncache[$md5key];
}
if ($oldcacheitem = $DB->get_record('cache_text', array('md5key'=>$md5key), '*', true)) {
if ($oldcacheitem->timemodified >= $time) {
- if (defined('FULLME') and FULLME == 'cron') {
+ if (CLI_SCRIPT) {
if (count($croncache) > 150) {
reset($croncache);
$key = key($croncache);
}
if (empty($options->nocache) and !empty($CFG->cachetext) and $CFG->currenttextiscacheable) {
- if (defined('FULLME') and FULLME == 'cron') {
+ if (CLI_SCRIPT) {
// special static cron cache - no need to store it in db if its not already there
if (count($croncache) > 150) {
reset($croncache);
$message = get_string($errorcode, 'moodle', $a);
}
- if (defined('FULLME') && FULLME == 'cron') {
+ if (CLI_SCRIPT) {
// Errors in cron should be mtrace'd.
mtrace($message);
die;
$message = clean_text($message); // In case nasties are in here
- if (defined('FULLME') && FULLME == 'cron') {
+ if (CLI_SCRIPT) {
// notices in cron should be mtrace'd.
mtrace($message);
die;