Commit | Line | Data |
---|---|---|
f578af59 | 1 | <?php |
f9903ed0 | 2 | |
28bd3d9a PS |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * Web cron | |
20 | * | |
21 | * This script looks through all the module directories for cron.php files | |
22 | * and runs them. These files can contain cleanup functions, email functions | |
23 | * or anything that needs to be run on a regular basis. | |
24 | * | |
25 | * This file is best run from cron on the host system (ie outside PHP). | |
26 | * It is strongly recommended to add password protection via admin settings. | |
27 | * | |
28 | * eg wget -q -O /dev/null 'http: *moodle.somewhere.edu/admin/cron.php?password=SeCreT666' | |
29 | * | |
30 | * It is also possible to use CLI script admin/cli/cron.php instead, | |
31 | * you can not call this script from command line any more. | |
32 | * | |
33 | * @package core | |
34 | * @subpackage admin | |
35 | * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com | |
36 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
37 | */ | |
38 | ||
39 | // This is a fake CLI script, it is a really ugly hack which emulates | |
40 | // CLI via web interface, please do not use this hack elsewhere | |
41 | define('CLI_SCRIPT', true); | |
42 | define('WEB_CRON_EMULATED_CLI', 'defined'); // ugly ugly hack, do not use elsewhere please | |
43 | ||
44 | require('../config.php'); | |
45 | require_once($CFG->libdir.'/clilib.php'); | |
46 | require_once($CFG->libdir.'/cronlib.php'); | |
47 | ||
48 | // extra safety | |
49 | session_get_instance()->write_close(); | |
50 | ||
51 | // check if execution allowed | |
52 | if (!empty($CFG->cronclionly)) { | |
53 | // This script can only be run via the cli. | |
54 | print_error('cronerrorclionly', 'admin'); | |
55 | exit; | |
56 | } | |
57 | // This script is being called via the web, so check the password if there is one. | |
58 | if (!empty($CFG->cronremotepassword)) { | |
59 | $pass = optional_param('password', '', PARAM_RAW); | |
60 | if ($pass != $CFG->cronremotepassword) { | |
61 | // wrong password. | |
62 | print_error('cronerrorpassword', 'admin'); | |
63 | exit; | |
64 | } | |
65 | } | |
66 | ||
67 | // send mime type and encoding | |
68 | if (check_browser_version('MSIE')) { | |
69 | //ugly IE hack to work around downloading instead of viewing | |
70 | @header('Content-Type: text/html; charset=utf-8'); | |
71 | echo "<xmp>"; //<pre> is not good enough for us here | |
72 | } else { | |
73 | //send proper plaintext header | |
74 | @header('Content-Type: text/plain; charset=utf-8'); | |
75 | } | |
76 | ||
77 | // no more headers and buffers | |
78 | while(@ob_end_flush()); | |
79 | ||
80 | // execute the cron | |
81 | cron_run(); | |
82 | ||
83 | // finish the IE hack | |
84 | if (check_browser_version('MSIE')) { | |
85 | echo "</xmp>"; | |
86 | } | |
58e8f85b | 87 | |
f578af59 | 88 |