MDL-17774 refactored USER switching in cron scripts - now standardised in cron_setup_...
[moodle.git] / lib / setup.php
CommitLineData
da8759cb 1<?php
2/**
3 * setup.php - Sets up sessions, connects to databases and so on
4 *
75249234 5 * Normally this is only called by the main config.php file
6 * Normally this file does not need to be edited.
da8759cb 7 * @author Martin Dougiamas
8 * @version $Id$
9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 * @package moodlecore
11 */
12
13////// DOCUMENTATION IN PHPDOC FORMAT FOR MOODLE GLOBALS AND COMMON OBJECT TYPES /////////////
14/**
735b8567 15 * $USER is a global instance of a typical $user record.
da8759cb 16 *
735b8567 17 * Items found in the user record:
da8759cb 18 * - $USER->emailstop - Does the user want email sent to them?
19 * - $USER->email - The user's email address.
20 * - $USER->id - The unique integer identified of this user in the 'user' table.
21 * - $USER->email - The user's email address.
22 * - $USER->firstname - The user's first name.
23 * - $USER->lastname - The user's last name.
24 * - $USER->username - The user's login username.
25 * - $USER->secret - The user's ?.
26 * - $USER->lang - The user's language choice.
27 *
75249234 28 * @global object(user) $USER
da8759cb 29 */
674fb525 30global $USER;
da8759cb 31/**
735b8567 32 * This global variable is read in from the 'config' table.
da8759cb 33 *
735b8567 34 * Some typical settings in the $CFG global:
da8759cb 35 * - $CFG->wwwroot - Path to moodle index directory in url format.
36 * - $CFG->dataroot - Path to moodle index directory on server's filesystem.
e57d9d69 37 * - $CFG->libdir - Path to moodle's library folder on server's filesystem.
da8759cb 38 *
674fb525 39 * @global object(cfg) $CFG
da8759cb 40 */
674fb525 41global $CFG;
da8759cb 42/**
43 * Definition of session type
75249234 44 * @global object(session) $SESSION
da8759cb 45 */
46global $SESSION;
6800d78e 47/**
419e1d93 48 * Definition of shared memory cache
49 */
50global $MCACHE;
da8759cb 51/**
52 * Definition of course type
75249234 53 * @global object(course) $COURSE
da8759cb 54 */
55global $COURSE;
f33e1ed4 56/**
57 * Database instances
58 * @global object(mdb) $DB
59 */
60global $DB;
da8759cb 61/**
62 * $THEME is a global that defines the site theme.
63 *
64 * Items found in the theme record:
65 * - $THEME->cellheading - Cell colors.
66 * - $THEME->cellheading2 - Alternate cell colors.
67 *
75249234 68 * @global object(theme) $THEME
da8759cb 69 */
70global $THEME;
f9903ed0 71
9d0dd812 72/**
6800d78e
FM
73 * HTTPSPAGEREQUIRED is a global to define if the page being displayed must run under HTTPS.
74 *
9d0dd812 75 * It's primary goal is to allow 100% HTTPS pages when $CFG->loginhttps is enabled. Default to false.
76 * It's enabled only by the httpsrequired() function and used in some pages to update some URLs
77*/
78global $HTTPSPAGEREQUIRED;
79
80
578dcc40 81/// First try to detect some attacks on older buggy PHP versions
735b8567 82 if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
578dcc40 83 die('Fatal: Illegal GLOBALS overwrite attempt detected!');
84 }
85
86
36ec6afe 87 if (!isset($CFG->wwwroot)) {
a670108e 88 trigger_error('Fatal: $CFG->wwwroot is not configured! Exiting.');
36ec6afe 89 die;
90 }
75249234 91
220a90c5 92/// store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
93 $CFG->config_php_settings = (array)$CFG;
94
9d0dd812 95/// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
96/// inside some URLs used in HTTPSPAGEREQUIRED pages.
d3f9f1f8 97 $CFG->httpswwwroot = $CFG->wwwroot;
98
99 $CFG->libdir = $CFG->dirroot .'/lib';
100
101 require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
9d0dd812 102
6800d78e
FM
103/// Time to start counting
104 init_performance_info();
105
b8cea9b2 106
74944b73 107/// If there are any errors in the standard libraries we want to know!
346b1a24 108 error_reporting(E_ALL);
f9903ed0 109
d7196099 110/// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
0a194c4c 111/// http://www.google.com/webmasters/faq.html#prefetchblock
d7196099 112 if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
6800d78e 113 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
d7196099 114 trigger_error('Prefetch request forbidden.');
115 exit;
116 }
117
dae73c05 118/// Define admin directory
dae73c05 119 if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
1040ea85 120 $CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
dae73c05 121 }
122
f33e1ed4 123 if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
124 $CFG->prefix = '';
125 }
a8a71844 126
75249234 127/// Load up standard libraries
6aaa17c7 128 require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
da8759cb 129 require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
8aff8482 130 require_once($CFG->libdir .'/dmllib.php'); // Database access
7e13be08 131 require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
c4d0753b 132 require_once($CFG->libdir .'/accesslib.php'); // Access control functions
133 require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
da8759cb 134 require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
0856223c 135 require_once($CFG->libdir .'/eventslib.php'); // Events functions
13534ef7 136 require_once($CFG->libdir .'/grouplib.php'); // Groups functions
6800d78e 137 require_once($CFG->libdir .'/sessionlib.php'); // All session and cookie related stuff
a4c371ec 138
7fc1a27d 139 //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
140 //the problem is that we need specific version of quickforms and hacked excel files :-(
141 ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
647a1a82 142 //point zend include path to moodles lib/zend so that includes and requires will search there for files before anywhere else
143 ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path'));
a4c371ec 144
251387d0 145/// set handler for uncought exceptions - equivalent to print_error() call
146 set_exception_handler('default_exception_handler');
147
f33e1ed4 148/// Connect to the database
149 setup_DB();
150
151/// Increase memory limits if possible
152 raise_memory_limit('96M'); // We should never NEED this much but just in case...
153
aa893d6b 154/// Disable errors for now - needed for installation when debug enabled in config.php
155 if (isset($CFG->debug)) {
156 $originalconfigdebug = $CFG->debug;
157 unset($CFG->debug);
158 } else {
159 $originalconfigdebug = -1;
160 }
161
74944b73 162/// Load up any configuration from the config table
c23b0ea1 163 try {
164 $CFG = get_config();
165 } catch (dml_read_exception $e) {
166 // most probably empty db, going to install soon
167 }
f9903ed0 168
a78bee28 169/// Verify upgrade is not running unless we are in a script that needs to execute in any case
170 if (!defined('NO_UPGRADE_CHECK') and isset($CFG->upgraderunning)) {
775f811a 171 if ($CFG->upgraderunning < time()) {
172 unset_config('upgraderunning');
173 } else {
174 print_error('upgraderunning');
175 }
176 }
177
ceff9307 178/// Turn on SQL logging if required
179 if (!empty($CFG->logsql)) {
f33e1ed4 180 $DB->set_logging(true);
ceff9307 181 }
1e3e716f 182
aa893d6b 183/// Prevent warnings from roles when upgrading with debug on
184 if (isset($CFG->debug)) {
185 $originaldatabasedebug = $CFG->debug;
186 unset($CFG->debug);
187 } else {
188 $originaldatabasedebug = -1;
6fbf8d8f 189 }
4fd7ccc0 190
191
cf8133c4 192/// For now, only needed under apache (and probably unstable in other contexts)
cf1348ca 193 if (function_exists('register_shutdown_function')) {
cf8133c4 194 register_shutdown_function('moodle_request_shutdown');
195 }
196
bac6d28a 197/// Defining the site
c23b0ea1 198 try {
199 $SITE = get_site();
200 } catch (dml_read_exception $e) {
201 $SITE = null;
202 }
203
204 if ($SITE) {
475e9de8 205 /**
206 * If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1.
207 */
208 define('SITEID', $SITE->id);
508b76d9 209 /// And the 'default' course
210 $COURSE = clone($SITE); // For now. This will usually get reset later in require_login() etc.
475e9de8 211 } else {
212 /**
213 * @ignore
214 */
215 define('SITEID', 1);
508b76d9 216 /// And the 'default' course
217 $COURSE = new object; // no site created yet
218 $COURSE->id = 1;
475e9de8 219 }
475e9de8 220
7d0c81b3 221 // define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
222 if (!defined('SYSCONTEXTID')) {
0ecff22d 223 get_system_context();
6dd34e93 224 }
475e9de8 225
aa893d6b 226/// Set error reporting back to normal
227 if ($originaldatabasedebug == -1) {
7eb0b60a 228 $CFG->debug = DEBUG_MINIMAL;
aa893d6b 229 } else {
230 $CFG->debug = $originaldatabasedebug;
231 }
232 if ($originalconfigdebug !== -1) {
6800d78e 233 $CFG->debug = $originalconfigdebug;
aa893d6b 234 }
235 unset($originalconfigdebug);
236 unset($originaldatabasedebug);
237 error_reporting($CFG->debug);
238
25338300 239
b3732604 240/// find out if PHP cofigured to display warnings
241 if (ini_get_bool('display_errors')) {
242 define('WARN_DISPLAY_ERRORS_ENABLED', true);
243 }
25338300 244/// If we want to display Moodle errors, then try and set PHP errors to match
6349a3ba 245 if (!isset($CFG->debugdisplay)) {
246 //keep it as is during installation
247 } else if (empty($CFG->debugdisplay)) {
25338300 248 @ini_set('display_errors', '0');
249 @ini_set('log_errors', '1');
250 } else {
251 @ini_set('display_errors', '1');
252 }
8f64ba04 253// Even when users want to see errors in the output,
254// some parts of Moodle cannot display them at all.
255// (Once we are XHTML strict compliant, debugdisplay
256// _must_ go away).
257 if (defined('MOODLE_SANE_OUTPUT')) {
258 @ini_set('display_errors', '0');
259 @ini_set('log_errors', '1');
260 }
25338300 261
f9955801 262/// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
2728a623 263 if (!empty($CFG->version) and $CFG->version < 2007101509) {
6d5a22b2 264 print_error('upgraderequires19', 'error');
f9955801 265 die;
266 }
267
419e1d93 268/// Shared-Memory cache init -- will set $MCACHE
269/// $MCACHE is a global object that offers at least add(), set() and delete()
270/// with similar semantics to the memcached PHP API http://php.net/memcache
392e7363 271/// Ensure we define rcache - so we can later check for it
272/// with a really fast and unambiguous $CFG->rcache === false
bb931a61 273 if (!empty($CFG->cachetype)) {
b1df0eb2 274 if (empty($CFG->rcache)) {
392e7363 275 $CFG->rcache = false;
276 } else {
277 $CFG->rcache = true;
278 }
279
280 // do not try to initialize if cache disabled
281 if (!$CFG->rcache) {
282 $CFG->cachetype = '';
283 }
284
bb931a61 285 if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) {
286 if (!init_memcached()) {
287 debugging("Error initialising memcached");
0a2925be 288 $CFG->cachetype = '';
289 $CFG->rcache = false;
bb931a61 290 }
392e7363 291 } else if ($CFG->cachetype === 'eaccelerator') {
bb931a61 292 if (!init_eaccelerator()) {
293 debugging("Error initialising eaccelerator cache");
0a2925be 294 $CFG->cachetype = '';
6800d78e 295 $CFG->rcache = false;
bb931a61 296 }
297 }
392e7363 298
bb931a61 299 } else { // just make sure it is defined
300 $CFG->cachetype = '';
392e7363 301 $CFG->rcache = false;
2142d492 302 }
aa893d6b 303
0182c65c 304/// Set a default enrolment configuration (see bug 1598)
305 if (!isset($CFG->enrol)) {
a51e2a7f 306 $CFG->enrol = 'manual';
0182c65c 307 }
308
ed8365d9 309/// Set default enabled enrolment plugins
310 if (!isset($CFG->enrol_plugins_enabled)) {
311 $CFG->enrol_plugins_enabled = 'manual';
312 }
313
2e6d4273 314/// File permissions on created directories in the $CFG->dataroot
315
316 if (empty($CFG->directorypermissions)) {
317 $CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
318 }
319
820743c5 320/// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
321/// - WINDOWS: for any Windows flavour.
322/// - UNIX: for the rest
323/// Also, $CFG->os can continue being used if more specialization is required
323edd4b 324 if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
325 $CFG->ostype = 'WINDOWS';
326 } else {
327 $CFG->ostype = 'UNIX';
328 }
329 $CFG->os = PHP_OS;
820743c5 330
d21a5865 331/// Set up default frame target string, based on $CFG->framename
332 $CFG->frametarget = frametarget();
333
d6ead3a2 334/// Setup cache dir for Smarty and others
335 if (!file_exists($CFG->dataroot .'/cache')) {
336 make_upload_directory('cache');
337 }
338
de7e4ac9 339/// Configure ampersands in URLs
de7e4ac9 340 @ini_set('arg_separator.output', '&amp;');
341
e7aa5a88 342/// Work around for a PHP bug see MDL-11237
6800d78e 343 @ini_set('pcre.backtrack_limit', 20971520); // 20 MB
e7aa5a88 344
74944b73 345/// Location of standard files
da8759cb 346 $CFG->wordlist = $CFG->libdir .'/wordlist.txt';
347 $CFG->javascript = $CFG->libdir .'/javascript.php';
1040ea85 348 $CFG->moddata = 'moddata';
f9903ed0 349
8f64ba04 350// Alas, in some cases we cannot deal with magic_quotes.
351 if (defined('MOODLE_SANE_INPUT') && ini_get_bool('magic_quotes_gpc')) {
352 mdie("Facilities that require MOODLE_SANE_INPUT "
353 . "cannot work with magic_quotes_gpc. Please disable "
354 . "magic_quotes_gpc.");
355 }
294ce987 356/// A hack to get around magic_quotes_gpc being turned on
357/// It is strongly recommended to disable "magic_quotes_gpc"!
358 if (ini_get_bool('magic_quotes_gpc')) {
359 function stripslashes_deep($value) {
75249234 360 $value = is_array($value) ?
294ce987 361 array_map('stripslashes_deep', $value) :
362 stripslashes($value);
75249234 363 return $value;
24cc8ec9 364 }
294ce987 365 $_POST = array_map('stripslashes_deep', $_POST);
366 $_GET = array_map('stripslashes_deep', $_GET);
367 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
368 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
578dcc40 369 if (!empty($_SERVER['REQUEST_URI'])) {
294ce987 370 $_SERVER['REQUEST_URI'] = stripslashes($_SERVER['REQUEST_URI']);
578dcc40 371 }
372 if (!empty($_SERVER['QUERY_STRING'])) {
294ce987 373 $_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);
578dcc40 374 }
375 if (!empty($_SERVER['HTTP_REFERER'])) {
294ce987 376 $_SERVER['HTTP_REFERER'] = stripslashes($_SERVER['HTTP_REFERER']);
578dcc40 377 }
378 if (!empty($_SERVER['PATH_INFO'])) {
294ce987 379 $_SERVER['PATH_INFO'] = stripslashes($_SERVER['PATH_INFO']);
578dcc40 380 }
381 if (!empty($_SERVER['PHP_SELF'])) {
294ce987 382 $_SERVER['PHP_SELF'] = stripslashes($_SERVER['PHP_SELF']);
578dcc40 383 }
384 if (!empty($_SERVER['PATH_TRANSLATED'])) {
294ce987 385 $_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
578dcc40 386 }
aa6af0f8 387 }
7a302afc 388
9bda43e6 389/// initialise ME's
f9f4d999 390 if (defined('FULLME')) { // Usually in command-line scripts like admin/cron.php
391 $FULLME = FULLME;
392 $ME = FULLME;
9d378732 393 } else {
9fa49e22 394 $FULLME = qualified_me();
9d378732 395 $ME = strip_querystring($FULLME);
9fa49e22 396 }
f9903ed0 397
9bda43e6 398/// start session and prepare global $SESSION, $USER
399 session_get_instance();
400 $SESSION = &$_SESSION['SESSION'];
401 $USER = &$_SESSION['USER'];
402
18b9d664 403/// Load up theme variables (colours etc)
86cc3e75 404
405 if (!isset($CFG->themedir)) {
a44091bf 406 $CFG->themedir = $CFG->dirroot.'/theme';
407 $CFG->themewww = $CFG->wwwroot.'/theme';
86cc3e75 408 }
6800d78e 409 $CFG->httpsthemewww = $CFG->themewww;
86cc3e75 410
18b9d664 411 if (isset($_GET['theme'])) {
32e2b302 412 if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
a44091bf 413 $themename = clean_param($_GET['theme'], PARAM_SAFEDIR);
414 if (($themename != '') and file_exists($CFG->themedir.'/'.$themename)) {
415 $SESSION->theme = $themename;
18b9d664 416 }
a44091bf 417 unset($themename);
18b9d664 418 }
419 }
420
421 if (!isset($CFG->theme)) {
34137668 422 $CFG->theme = 'standardwhite';
18b9d664 423 }
424
75249234 425/// Set language/locale of printed times. If user has chosen a language that
426/// that is different from the site language, then use the locale specified
339bb559 427/// in the language file. Otherwise, if the admin hasn't specified a locale
75249234 428/// then use the one from the default language. Otherwise (and this is the
339bb559 429/// majority of cases), use the stored locale specified by admin.
6800d78e 430 if (isset($_GET['lang']) && ($lang = clean_param($_GET['lang'], PARAM_SAFEDIR))) {
6ec7ca0f 431 if (file_exists($CFG->dataroot .'/lang/'. $lang) or file_exists($CFG->dirroot .'/lang/'. $lang)) {
32c60ce3 432 $SESSION->lang = $lang;
6800d78e 433 } else if (file_exists($CFG->dataroot.'/lang/'.$lang.'_utf8') or
748390cd 434 file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
435 $SESSION->lang = $lang.'_utf8';
32c60ce3 436 }
3e9b5d5a 437 }
ab036ed9 438
439 setup_lang_from_browser();
440
6ec7ca0f 441 unset($lang);
ab036ed9 442
16ba7351 443 if (empty($CFG->lang)) {
6ec7ca0f 444 if (empty($SESSION->lang)) {
810944af 445 $CFG->lang = 'en_utf8';
6ec7ca0f 446 } else {
447 $CFG->lang = $SESSION->lang;
448 }
16ba7351 449 }
6800d78e 450
dcf6d93c 451 // set default locale and themes - might be changed again later from require_login()
452 course_setup();
1040ea85 453
1b813f5c 454 if (!empty($CFG->guestloginbutton)) {
455 if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
456 if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
457 if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
458 (strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
459 if ($user = get_complete_user_data("username", "w3cvalidator")) {
460 $user->ignoresesskey = true;
461 } else {
462 $user = guest_user();
463 }
464 session_set_user($user);
9610a66e 465 }
466 }
467 }
468 }
469
a559eee6 470/// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
471/// LogFormat to get the current logged in username in moodle.
ac0b19ff 472 if ($USER && function_exists('apache_note')
20e9d26f 473 && !empty($CFG->apacheloguser) && isset($USER->username)) {
2b287cac 474 $apachelog_userid = $USER->id;
ac0b19ff 475 $apachelog_username = clean_filename($USER->username);
476 $apachelog_name = '';
477 if (isset($USER->firstname)) {
478 // We can assume both will be set
479 // - even if to empty.
480 $apachelog_name = clean_filename($USER->firstname . " " .
481 $USER->lastname);
482 }
b7b64ff2 483 if (session_is_loggedinas()) {
484 $realuser = session_get_realuser();
6132768e 485 $apachelog_username = clean_filename($realuser->username." as ".$apachelog_username);
486 $apachelog_name = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$apachelog_name);
487 $apachelog_userid = clean_filename($realuser->id." as ".$apachelog_userid);
96e19e7b 488 }
5c5c16bb 489 switch ($CFG->apacheloguser) {
490 case 3:
2b287cac 491 $logname = $apachelog_username;
5c5c16bb 492 break;
493 case 2:
2b287cac 494 $logname = $apachelog_name;
5c5c16bb 495 break;
496 case 1:
497 default:
2b287cac 498 $logname = $apachelog_userid;
5c5c16bb 499 break;
500 }
501 apache_note('MOODLEUSER', $logname);
a559eee6 502 }
503
5982740d 504/// Adjust ALLOWED_TAGS
505 adjust_allowed_tags();
506
18259d4f 507/// Use a custom script replacement if one exists
508 if (!empty($CFG->customscripts)) {
509 if (($customscript = custom_script_path()) !== false) {
2b0b32d8 510 require ($customscript);
18259d4f 511 }
512 }
513
5035228f 514 // in the first case, ip in allowed list will be performed first
515 // for example, client IP is 192.168.1.1
516 // 192.168 subnet is an entry in allowed list
d255c6e9 517 // 192.168.1.1 is banned in blocked list
5035228f 518 // This ip will be banned finally
d255c6e9 519 if (!empty($CFG->allowbeforeblock)) { // allowed list processed before blocked list?
520 if (!empty($CFG->allowedip)) {
521 if (!remoteip_in_list($CFG->allowedip)) {
522 die(get_string('ipblocked', 'admin'));
523 }
ab99c8f0 524 }
d255c6e9 525 // need further check, client ip may a part of
526 // allowed subnet, but a IP address are listed
5035228f 527 // in blocked list.
d255c6e9 528 if (!empty($CFG->blockedip)) {
529 if (remoteip_in_list($CFG->blockedip)) {
530 die(get_string('ipblocked', 'admin'));
531 }
5035228f 532 }
d255c6e9 533
5035228f 534 } else {
535 // in this case, IPs in blocked list will be performed first
536 // for example, client IP is 192.168.1.1
537 // 192.168 subnet is an entry in blocked list
d255c6e9 538 // 192.168.1.1 is allowed in allowed list
5035228f 539 // This ip will be allowed finally
d255c6e9 540 if (!empty($CFG->blockedip)) {
541 if (remoteip_in_list($CFG->blockedip)) {
542 // if the allowed ip list is not empty
543 // IPs are not included in the allowed list will be
544 // blocked too
545 if (!empty($CFG->allowedip)) {
546 if (!remoteip_in_list($CFG->allowedip)) {
547 die(get_string('ipblocked', 'admin'));
548 }
549 } else {
550 die(get_string('ipblocked', 'admin'));
551 }
552 }
5035228f 553 }
d255c6e9 554 // if blocked list is null
555 // allowed list should be tested
556 if(!empty($CFG->allowedip)) {
557 if (!remoteip_in_list($CFG->allowedip)) {
558 die(get_string('ipblocked', 'admin'));
559 }
5035228f 560 }
d255c6e9 561
ab99c8f0 562 }
563
810944af 564/// note: we can not block non utf-8 installatrions here, because empty mysql database
565/// might be converted to utf-8 in admin/index.php during installation
d3f9f1f8 566?>