Updated the HEAD build version to 20080722
[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
7e13be08 130 require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
c4d0753b 131 require_once($CFG->libdir .'/accesslib.php'); // Access control functions
132 require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
da8759cb 133 require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
0856223c 134 require_once($CFG->libdir .'/eventslib.php'); // Events functions
13534ef7 135 require_once($CFG->libdir .'/grouplib.php'); // Groups functions
6800d78e 136 require_once($CFG->libdir .'/sessionlib.php'); // All session and cookie related stuff
a4c371ec 137
7fc1a27d 138 //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
139 //the problem is that we need specific version of quickforms and hacked excel files :-(
140 ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
a4c371ec 141
251387d0 142/// set handler for uncought exceptions - equivalent to print_error() call
143 set_exception_handler('default_exception_handler');
144
f33e1ed4 145/// Connect to the database
146 setup_DB();
147
148/// Increase memory limits if possible
149 raise_memory_limit('96M'); // We should never NEED this much but just in case...
150
aa893d6b 151/// Disable errors for now - needed for installation when debug enabled in config.php
152 if (isset($CFG->debug)) {
153 $originalconfigdebug = $CFG->debug;
154 unset($CFG->debug);
155 } else {
156 $originalconfigdebug = -1;
157 }
158
74944b73 159/// Load up any configuration from the config table
a4080313 160 $CFG = get_config();
f9903ed0 161
ceff9307 162/// Turn on SQL logging if required
163 if (!empty($CFG->logsql)) {
f33e1ed4 164 $DB->set_logging(true);
ceff9307 165 }
1e3e716f 166
aa893d6b 167/// Prevent warnings from roles when upgrading with debug on
168 if (isset($CFG->debug)) {
169 $originaldatabasedebug = $CFG->debug;
170 unset($CFG->debug);
171 } else {
172 $originaldatabasedebug = -1;
6fbf8d8f 173 }
4fd7ccc0 174
175
cf8133c4 176/// For now, only needed under apache (and probably unstable in other contexts)
cf1348ca 177 if (function_exists('register_shutdown_function')) {
cf8133c4 178 register_shutdown_function('moodle_request_shutdown');
179 }
180
bac6d28a 181/// Defining the site
475e9de8 182 if ($SITE = get_site()) {
183 /**
184 * If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1.
185 */
186 define('SITEID', $SITE->id);
508b76d9 187 /// And the 'default' course
188 $COURSE = clone($SITE); // For now. This will usually get reset later in require_login() etc.
475e9de8 189 } else {
190 /**
191 * @ignore
192 */
193 define('SITEID', 1);
508b76d9 194 /// And the 'default' course
195 $COURSE = new object; // no site created yet
196 $COURSE->id = 1;
475e9de8 197 }
475e9de8 198
7d0c81b3 199 // define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
200 if (!defined('SYSCONTEXTID')) {
201 get_system_context();
6dd34e93 202 }
475e9de8 203
aa893d6b 204/// Set error reporting back to normal
205 if ($originaldatabasedebug == -1) {
7eb0b60a 206 $CFG->debug = DEBUG_MINIMAL;
aa893d6b 207 } else {
208 $CFG->debug = $originaldatabasedebug;
209 }
210 if ($originalconfigdebug !== -1) {
6800d78e 211 $CFG->debug = $originalconfigdebug;
aa893d6b 212 }
213 unset($originalconfigdebug);
214 unset($originaldatabasedebug);
215 error_reporting($CFG->debug);
216
25338300 217
b3732604 218/// find out if PHP cofigured to display warnings
219 if (ini_get_bool('display_errors')) {
220 define('WARN_DISPLAY_ERRORS_ENABLED', true);
221 }
25338300 222/// If we want to display Moodle errors, then try and set PHP errors to match
6349a3ba 223 if (!isset($CFG->debugdisplay)) {
224 //keep it as is during installation
225 } else if (empty($CFG->debugdisplay)) {
25338300 226 @ini_set('display_errors', '0');
227 @ini_set('log_errors', '1');
228 } else {
229 @ini_set('display_errors', '1');
230 }
8f64ba04 231// Even when users want to see errors in the output,
232// some parts of Moodle cannot display them at all.
233// (Once we are XHTML strict compliant, debugdisplay
234// _must_ go away).
235 if (defined('MOODLE_SANE_OUTPUT')) {
236 @ini_set('display_errors', '0');
237 @ini_set('log_errors', '1');
238 }
25338300 239
f9955801 240/// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
2728a623 241 if (!empty($CFG->version) and $CFG->version < 2007101509) {
6d5a22b2 242 print_error('upgraderequires19', 'error');
f9955801 243 die;
244 }
245
419e1d93 246/// Shared-Memory cache init -- will set $MCACHE
247/// $MCACHE is a global object that offers at least add(), set() and delete()
248/// with similar semantics to the memcached PHP API http://php.net/memcache
392e7363 249/// Ensure we define rcache - so we can later check for it
250/// with a really fast and unambiguous $CFG->rcache === false
bb931a61 251 if (!empty($CFG->cachetype)) {
b1df0eb2 252 if (empty($CFG->rcache)) {
392e7363 253 $CFG->rcache = false;
254 } else {
255 $CFG->rcache = true;
256 }
257
258 // do not try to initialize if cache disabled
259 if (!$CFG->rcache) {
260 $CFG->cachetype = '';
261 }
262
bb931a61 263 if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) {
264 if (!init_memcached()) {
265 debugging("Error initialising memcached");
0a2925be 266 $CFG->cachetype = '';
267 $CFG->rcache = false;
bb931a61 268 }
392e7363 269 } else if ($CFG->cachetype === 'eaccelerator') {
bb931a61 270 if (!init_eaccelerator()) {
271 debugging("Error initialising eaccelerator cache");
0a2925be 272 $CFG->cachetype = '';
6800d78e 273 $CFG->rcache = false;
bb931a61 274 }
275 }
392e7363 276
bb931a61 277 } else { // just make sure it is defined
278 $CFG->cachetype = '';
392e7363 279 $CFG->rcache = false;
2142d492 280 }
aa893d6b 281
0182c65c 282/// Set a default enrolment configuration (see bug 1598)
283 if (!isset($CFG->enrol)) {
a51e2a7f 284 $CFG->enrol = 'manual';
0182c65c 285 }
286
ed8365d9 287/// Set default enabled enrolment plugins
288 if (!isset($CFG->enrol_plugins_enabled)) {
289 $CFG->enrol_plugins_enabled = 'manual';
290 }
291
2e6d4273 292/// File permissions on created directories in the $CFG->dataroot
293
294 if (empty($CFG->directorypermissions)) {
295 $CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
296 }
297
820743c5 298/// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
299/// - WINDOWS: for any Windows flavour.
300/// - UNIX: for the rest
301/// Also, $CFG->os can continue being used if more specialization is required
323edd4b 302 if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
303 $CFG->ostype = 'WINDOWS';
304 } else {
305 $CFG->ostype = 'UNIX';
306 }
307 $CFG->os = PHP_OS;
820743c5 308
d21a5865 309/// Set up default frame target string, based on $CFG->framename
310 $CFG->frametarget = frametarget();
311
d6ead3a2 312/// Setup cache dir for Smarty and others
313 if (!file_exists($CFG->dataroot .'/cache')) {
314 make_upload_directory('cache');
315 }
316
de7e4ac9 317/// Configure ampersands in URLs
de7e4ac9 318 @ini_set('arg_separator.output', '&amp;');
319
e7aa5a88 320/// Work around for a PHP bug see MDL-11237
6800d78e 321 @ini_set('pcre.backtrack_limit', 20971520); // 20 MB
e7aa5a88 322
74944b73 323/// Location of standard files
da8759cb 324 $CFG->wordlist = $CFG->libdir .'/wordlist.txt';
325 $CFG->javascript = $CFG->libdir .'/javascript.php';
1040ea85 326 $CFG->moddata = 'moddata';
f9903ed0 327
8f64ba04 328// Alas, in some cases we cannot deal with magic_quotes.
329 if (defined('MOODLE_SANE_INPUT') && ini_get_bool('magic_quotes_gpc')) {
330 mdie("Facilities that require MOODLE_SANE_INPUT "
331 . "cannot work with magic_quotes_gpc. Please disable "
332 . "magic_quotes_gpc.");
333 }
294ce987 334/// A hack to get around magic_quotes_gpc being turned on
335/// It is strongly recommended to disable "magic_quotes_gpc"!
336 if (ini_get_bool('magic_quotes_gpc')) {
337 function stripslashes_deep($value) {
75249234 338 $value = is_array($value) ?
294ce987 339 array_map('stripslashes_deep', $value) :
340 stripslashes($value);
75249234 341 return $value;
24cc8ec9 342 }
294ce987 343 $_POST = array_map('stripslashes_deep', $_POST);
344 $_GET = array_map('stripslashes_deep', $_GET);
345 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
346 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
578dcc40 347 if (!empty($_SERVER['REQUEST_URI'])) {
294ce987 348 $_SERVER['REQUEST_URI'] = stripslashes($_SERVER['REQUEST_URI']);
578dcc40 349 }
350 if (!empty($_SERVER['QUERY_STRING'])) {
294ce987 351 $_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);
578dcc40 352 }
353 if (!empty($_SERVER['HTTP_REFERER'])) {
294ce987 354 $_SERVER['HTTP_REFERER'] = stripslashes($_SERVER['HTTP_REFERER']);
578dcc40 355 }
356 if (!empty($_SERVER['PATH_INFO'])) {
294ce987 357 $_SERVER['PATH_INFO'] = stripslashes($_SERVER['PATH_INFO']);
578dcc40 358 }
359 if (!empty($_SERVER['PHP_SELF'])) {
294ce987 360 $_SERVER['PHP_SELF'] = stripslashes($_SERVER['PHP_SELF']);
578dcc40 361 }
362 if (!empty($_SERVER['PATH_TRANSLATED'])) {
294ce987 363 $_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
578dcc40 364 }
aa6af0f8 365 }
7a302afc 366
6800d78e
FM
367/// start session and prepare global $SESSION
368 $SESSION = new moodle_session();
4ea8df21 369
6800d78e
FM
370/// set up global $USER
371 if (!NO_MOODLE_COOKIES) {
372 $USER = &$_SESSION['USER'];
373 } else {
8d2b18a8 374 $USER = new object();
375 $USER->id = 0; // user not logged in when session disabled
1d19804a 376 if (isset($CFG->mnet_localhost_id)) {
377 $USER->mnethostid = $CFG->mnet_localhost_id;
378 }
24cc8ec9 379 }
08c17336 380
f9f4d999 381 if (defined('FULLME')) { // Usually in command-line scripts like admin/cron.php
382 $FULLME = FULLME;
383 $ME = FULLME;
9d378732 384 } else {
9fa49e22 385 $FULLME = qualified_me();
9d378732 386 $ME = strip_querystring($FULLME);
9fa49e22 387 }
f9903ed0 388
18b9d664 389/// Load up theme variables (colours etc)
86cc3e75 390
391 if (!isset($CFG->themedir)) {
a44091bf 392 $CFG->themedir = $CFG->dirroot.'/theme';
393 $CFG->themewww = $CFG->wwwroot.'/theme';
86cc3e75 394 }
6800d78e 395 $CFG->httpsthemewww = $CFG->themewww;
86cc3e75 396
18b9d664 397 if (isset($_GET['theme'])) {
32e2b302 398 if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
a44091bf 399 $themename = clean_param($_GET['theme'], PARAM_SAFEDIR);
400 if (($themename != '') and file_exists($CFG->themedir.'/'.$themename)) {
401 $SESSION->theme = $themename;
18b9d664 402 }
a44091bf 403 unset($themename);
18b9d664 404 }
405 }
406
407 if (!isset($CFG->theme)) {
34137668 408 $CFG->theme = 'standardwhite';
18b9d664 409 }
410
16303ee9 411/// now do a session test to prevent random user switching - observed on some PHP/Apache combinations,
6800d78e 412 $SESSION->session_verify();
18b9d664 413
75249234 414/// Set language/locale of printed times. If user has chosen a language that
415/// that is different from the site language, then use the locale specified
339bb559 416/// in the language file. Otherwise, if the admin hasn't specified a locale
75249234 417/// then use the one from the default language. Otherwise (and this is the
339bb559 418/// majority of cases), use the stored locale specified by admin.
6800d78e 419 if (isset($_GET['lang']) && ($lang = clean_param($_GET['lang'], PARAM_SAFEDIR))) {
6ec7ca0f 420 if (file_exists($CFG->dataroot .'/lang/'. $lang) or file_exists($CFG->dirroot .'/lang/'. $lang)) {
32c60ce3 421 $SESSION->lang = $lang;
6800d78e 422 } else if (file_exists($CFG->dataroot.'/lang/'.$lang.'_utf8') or
748390cd 423 file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
424 $SESSION->lang = $lang.'_utf8';
32c60ce3 425 }
3e9b5d5a 426 }
ab036ed9 427
428 setup_lang_from_browser();
429
6ec7ca0f 430 unset($lang);
ab036ed9 431
16ba7351 432 if (empty($CFG->lang)) {
6ec7ca0f 433 if (empty($SESSION->lang)) {
810944af 434 $CFG->lang = 'en_utf8';
6ec7ca0f 435 } else {
436 $CFG->lang = $SESSION->lang;
437 }
16ba7351 438 }
6800d78e 439
dcf6d93c 440 // set default locale and themes - might be changed again later from require_login()
441 course_setup();
1040ea85 442
18845ac3 443 if (!empty($CFG->opentogoogle)) {
6800d78e 444 if (!NO_MOODLE_COOKIES and empty($USER->id)) { // Ignore anyone logged in, or scripts without cookies
18845ac3 445 if (!empty($_SERVER['HTTP_USER_AGENT'])) {
446 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ) {
447 $USER = guest_user();
43ee1454 448 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false ) { // Google
a33c4e5a 449 $USER = guest_user();
43ee1454 450 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo! Slurp') !== false ) { // Yahoo
a33c4e5a 451 $USER = guest_user();
43ee1454 452 } else if (strpos($_SERVER['HTTP_USER_AGENT'], '[ZSEBOT]') !== false ) { // Zoomspider
453 $USER = guest_user();
454 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSNBOT') !== false ) { // MSN Search
2d33fc00 455 $USER = guest_user();
456 }
18845ac3 457 }
a33c4e5a 458 if (empty($USER) && !empty($_SERVER['HTTP_REFERER'])) {
18845ac3 459 if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false ) {
460 $USER = guest_user();
33674080 461 } else if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false ) {
462 $USER = guest_user();
18845ac3 463 }
464 }
6800d78e 465 if (!empty($USER->id)) {
2f32eed1 466 load_all_capabilities();
467 }
18845ac3 468 }
469 }
470
8d62ca68 471 if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
6800d78e 472 if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
75249234 473 if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
98de6431 474 (strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
7c12949d 475 if ($USER = get_complete_user_data("username", "w3cvalidator")) {
b60f0ee5 476 $USER->ignoresesskey = true;
003c49cb 477 } else {
9610a66e 478 $USER = guest_user();
479 }
480 }
481 }
482 }
483
a559eee6 484/// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
485/// LogFormat to get the current logged in username in moodle.
ac0b19ff 486 if ($USER && function_exists('apache_note')
487 && !empty($CFG->apacheloguser) && isset($user->username)) {
2b287cac 488 $apachelog_userid = $USER->id;
ac0b19ff 489 $apachelog_username = clean_filename($USER->username);
490 $apachelog_name = '';
491 if (isset($USER->firstname)) {
492 // We can assume both will be set
493 // - even if to empty.
494 $apachelog_name = clean_filename($USER->firstname . " " .
495 $USER->lastname);
496 }
96e19e7b 497 if (isset($USER->realuser)) {
f33e1ed4 498 if ($realuser = $DB->get_record('user', array('id'=>$USER->realuser))) {
2b287cac 499 $apachelog_username = clean_filename($realuser->username." as ".$apachelog_username);
500 $apachelog_name = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$apachelog_name);
501 $apachelog_userid = clean_filename($realuser->id." as ".$apachelog_userid);
96e19e7b 502 }
503 }
5c5c16bb 504 switch ($CFG->apacheloguser) {
505 case 3:
2b287cac 506 $logname = $apachelog_username;
5c5c16bb 507 break;
508 case 2:
2b287cac 509 $logname = $apachelog_name;
5c5c16bb 510 break;
511 case 1:
512 default:
2b287cac 513 $logname = $apachelog_userid;
5c5c16bb 514 break;
515 }
516 apache_note('MOODLEUSER', $logname);
a559eee6 517 }
518
5982740d 519/// Adjust ALLOWED_TAGS
520 adjust_allowed_tags();
521
18259d4f 522
523/// Use a custom script replacement if one exists
524 if (!empty($CFG->customscripts)) {
525 if (($customscript = custom_script_path()) !== false) {
2b0b32d8 526 require ($customscript);
18259d4f 527 }
528 }
529
4e639121 530 $allowediponly = get_config(null, 'enableallowedip');
531 if(!empty($allowediponly)){
532 $allowediplist = get_config(null, 'allowedip');
533 $blockediplist = get_config(null, 'blockedip');
534 } else {
535 $blockediplist = get_config(null, 'blockedip');
536 }
537 if(!empty($blockediplist)) {
538 $blockediplist = explode("\n", $blockediplist);
539 foreach($blockediplist as $ip) {
540 $ip = trim($ip);
ab99c8f0 541 if(address_in_subnet(getremoteaddr(), $ip)){
542 // Telling the banned user the site is not
543 // available currently.
4e639121 544 die(get_string('ipinblockedlist', 'admin'));
545 }
546 }
547 }
548 if(!empty($allowediplist)) {
549 $allowediplist = explode("\n", $allowediplist);
550 foreach($allowediplist as $ip) {
551 $ip = trim($ip);
552 if(!address_in_subnet(getremoteaddr(), $ip)){
553 // Telling users only specfied users are
554 // allowed accessing this site.
555 die(get_string('ipoutallowedlist', 'admin'));
556 }
ab99c8f0 557 }
558 }
559
810944af 560/// note: we can not block non utf-8 installatrions here, because empty mysql database
561/// might be converted to utf-8 in admin/index.php during installation
d3f9f1f8 562?>