ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilInitialisation.php
Go to the documentation of this file.
1<?php
2
19// TODO:
37use ILIAS\User\PublicInterface as UserPublicInterface;
38
39// needed for slow queries, etc.
40if (!isset($GLOBALS['ilGlobalStartTime']) || !$GLOBALS['ilGlobalStartTime']) {
41 $GLOBALS['ilGlobalStartTime'] = microtime();
42}
43
54{
58 protected static function removeUnsafeCharacters(): void
59 {
60 // Remove unsafe characters from GET parameters.
61 // We do not need this characters in any case, so it is
62 // feasible to filter them everytime. POST parameters
63 // need attention through ilUtil::stripSlashes() and similar functions)
65 }
66
71 protected static function recursivelyRemoveUnsafeCharacters($var)
72 {
73 if (is_array($var)) {
74 $mod = [];
75 foreach ($var as $k => $v) {
78 }
79 return $mod;
80 }
81 return strip_tags(
82 str_replace(
83 array("\x00", "\n", "\r", "\\", "'", '"', "\x1a"),
84 "",
85 $var
86 )
87 );
88 }
89
93 protected static function requireCommonIncludes(): void
94 {
96 require_once(__DIR__ . "/../../../../ilias_version.php");
97 self::initGlobal("ilBench", "ilBenchmark", "./components/ILIAS/Utilities/classes/class.ilBenchmark.php");
98 }
99
106 protected static function initIliasIniFile(): void
107 {
108 $ilIliasIniFile = new ilIniFile(__DIR__ . "/../../../../ilias.ini.php");
109 $ilIliasIniFile->read();
110 self::initGlobal('ilIliasIniFile', $ilIliasIniFile);
111
112 // initialize constants
113 // aka internal data directory
114 if (!defined('ILIAS_DATA_DIR')) {
115 define("ILIAS_DATA_DIR", $ilIliasIniFile->readVariable("clients", "datadir"));
116 }
117 // aka Public Web Directory in Web, relative path to the webroot (public).
118 if (!defined('ILIAS_WEB_DIR')) {
119 $from_ilias_ini = $ilIliasIniFile->readVariable("clients", "path");
120 $from_ilias_ini = str_replace('public/', '', $from_ilias_ini);
121 define("ILIAS_WEB_DIR", $from_ilias_ini);
122 }
123 if (!defined("ILIAS_ABSOLUTE_PATH")) {
124 define("ILIAS_ABSOLUTE_PATH", $ilIliasIniFile->readVariable('server', 'absolute_path'));
125 }
126
127 // logging
128 define("ILIAS_LOG_DIR", $ilIliasIniFile->readVariable("log", "path"));
129 define("ILIAS_LOG_FILE", $ilIliasIniFile->readVariable("log", "file"));
130 if (!defined("ILIAS_LOG_ENABLED")) {
131 define("ILIAS_LOG_ENABLED", $ilIliasIniFile->readVariable("log", "enabled"));
132 }
133 define("ILIAS_LOG_LEVEL", $ilIliasIniFile->readVariable("log", "level"));
134
135 // read path + command for third party tools from ilias.ini
136 define("PATH_TO_CONVERT", $ilIliasIniFile->readVariable("tools", "convert"));
137 define("PATH_TO_FFMPEG", $ilIliasIniFile->readVariable("tools", "ffmpeg"));
138 define("PATH_TO_ZIP", $ilIliasIniFile->readVariable("tools", "zip"));
139 define("PATH_TO_MKISOFS", $ilIliasIniFile->readVariable("tools", "mkisofs"));
140 define("PATH_TO_UNZIP", $ilIliasIniFile->readVariable("tools", "unzip"));
141 define("PATH_TO_GHOSTSCRIPT", $ilIliasIniFile->readVariable("tools", "ghostscript"));
142 define("PATH_TO_JAVA", $ilIliasIniFile->readVariable("tools", "java"));
143 define("PATH_TO_FOP", $ilIliasIniFile->readVariable("tools", "fop"));
144 define("PATH_TO_SCSS", $ilIliasIniFile->readVariable("tools", "scss"));
145
146 if ($ilIliasIniFile->groupExists('error')) {
147 if ($ilIliasIniFile->variableExists('error', 'editor_url')) {
148 define("ERROR_EDITOR_URL", $ilIliasIniFile->readVariable('error', 'editor_url'));
149 }
150
151 if ($ilIliasIniFile->variableExists('error', 'editor_path_translations')) {
152 define(
153 "ERROR_EDITOR_PATH_TRANSLATIONS",
154 $ilIliasIniFile->readVariable('error', 'editor_path_translations')
155 );
156 }
157 }
158
159 // read virus scanner settings
160 switch ($ilIliasIniFile->readVariable("tools", "vscantype")) {
161 case "sophos":
162 define("IL_VIRUS_SCANNER", "Sophos");
163 define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
164 define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
165 break;
166
167 case "antivir":
168 define("IL_VIRUS_SCANNER", "AntiVir");
169 define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
170 define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
171 break;
172
173 case "clamav":
174 define("IL_VIRUS_SCANNER", "ClamAV");
175 define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
176 define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
177 break;
178 case "icap":
179 define("IL_VIRUS_SCANNER", "icap");
180 define("IL_ICAP_HOST", $ilIliasIniFile->readVariable("tools", "icap_host"));
181 define("IL_ICAP_PORT", $ilIliasIniFile->readVariable("tools", "icap_port"));
182 define("IL_ICAP_AV_COMMAND", $ilIliasIniFile->readVariable("tools", "icap_service_name"));
183 define("IL_ICAP_CLIENT", $ilIliasIniFile->readVariable("tools", "icap_client_path"));
184 break;
185
186 default:
187 define("IL_VIRUS_SCANNER", "None");
188 define("IL_VIRUS_CLEAN_COMMAND", '');
189 break;
190 }
191
193 define("IL_TIMEZONE", $tz);
194 }
195
196 protected static function initResourceStorage(): void
197 {
198 global $DIC;
199 (new InitResourceStorage())->init($DIC);
200 }
201
212 public static function bootstrapFilesystems(): void
213 {
214 global $DIC;
215
216 $DIC['filesystem.security.sanitizing.filename'] = function (Container $c) {
218 $c->fileServiceSettings()
219 );
220 };
221
222 $DIC['filesystem.factory'] = function ($c) {
223 return new \ILIAS\Filesystem\Provider\DelegatingFilesystemFactory($c['filesystem.security.sanitizing.filename']);
224 };
225
226 $DIC['filesystem.web'] = function ($c) {
227 //web
228
232 $delegatingFactory = $c['filesystem.factory'];
233 $webConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_ABSOLUTE_PATH . '/public/' . ILIAS_WEB_DIR . '/' . CLIENT_ID);
234 return $delegatingFactory->getLocal($webConfiguration);
235 };
236
237 $DIC['filesystem.storage'] = function ($c) {
238 //storage
239
243 $delegatingFactory = $c['filesystem.factory'];
244 $storageConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_DATA_DIR . '/' . CLIENT_ID);
245 return $delegatingFactory->getLocal($storageConfiguration);
246 };
247
248 $DIC['filesystem.temp'] = function ($c) {
249 //temp
250
254 $delegatingFactory = $c['filesystem.factory'];
255 $tempConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_DATA_DIR . '/' . CLIENT_ID . '/temp');
256 return $delegatingFactory->getLocal($tempConfiguration);
257 };
258
259 $DIC['filesystem.customizing'] = function ($c) {
260 //customizing
261
265 $delegatingFactory = $c['filesystem.factory'];
266 $customizingConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_ABSOLUTE_PATH . '/public/' . 'Customizing');
267 return $delegatingFactory->getLocal($customizingConfiguration);
268 };
269
270 $DIC['filesystem.libs'] = function ($c) {
271 //customizing
272
276 $delegatingFactory = $c['filesystem.factory'];
277 $customizingConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_ABSOLUTE_PATH . '/' . 'vendor');
278 return $delegatingFactory->getLocal($customizingConfiguration, true);
279 };
280
281 $DIC['filesystem.node_modules'] = function ($c) {
282 //customizing
283
287 $delegatingFactory = $c['filesystem.factory'];
288 $customizingConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_ABSOLUTE_PATH . '/' . 'node_modules');
289 return $delegatingFactory->getLocal($customizingConfiguration, true);
290 };
291
292 $DIC['filesystem'] = function ($c) {
293 return new \ILIAS\Filesystem\FilesystemsImpl(
294 $c['filesystem.storage'],
295 $c['filesystem.web'],
296 $c['filesystem.temp'],
297 $c['filesystem.customizing'],
298 $c['filesystem.libs'],
299 $c['filesystem.node_modules']
300 );
301 };
302 }
303
310 public static function initFileUploadService(\ILIAS\DI\Container $dic): void
311 {
312 $dic['upload.processor-manager'] = function ($c) {
313 return new PreProcessorManagerImpl();
314 };
315
316 $dic['upload'] = function (\ILIAS\DI\Container $c) {
317 $fileUploadImpl = new \ILIAS\FileUpload\FileUploadImpl(
318 $c['upload.processor-manager'],
319 $c['filesystem'],
320 $c['http']
321 );
322 if ((defined('IL_VIRUS_SCANNER') && IL_VIRUS_SCANNER != "None") || (defined('IL_SCANNER_TYPE') && IL_SCANNER_TYPE == "1")) {
323 $fileUploadImpl->register(new ilVirusScannerPreProcessor(ilVirusScannerFactory::_getInstance()));
324 }
325
326 $fileUploadImpl->register(new FilenameSanitizerPreProcessor());
327 $fileUploadImpl->register(
329 $c->fileServiceSettings(),
330 $c->language()->txt("msg_info_blacklisted")
331 )
332 );
333 $fileUploadImpl->register(new InsecureFilenameSanitizerPreProcessor());
334 $fileUploadImpl->register(new SVGBlacklistPreProcessor(
335 $c->language()->txt("upload_svg_rejection_message"),
336 $c->language()->txt("upload_svg_rejection_message_script"),
337 $c->language()->txt("upload_svg_rejection_message_base64"),
338 $c->language()->txt("upload_svg_rejection_message_elements")
339 ));
340
341 return $fileUploadImpl;
342 };
343 }
344
345 protected static function initUploadPolicies(\ILIAS\DI\Container $dic): void
346 {
347 $dic['upload_policy_repository'] = static function ($dic) {
348 return new UploadPolicyDBRepository($dic->database());
349 };
350
351 $dic['upload_policy_resolver'] = static function ($dic): UploadPolicyResolver {
352 return new UploadPolicyResolver(
353 $dic->rbac()->review(),
354 $dic->user(),
355 $dic['upload_policy_repository']->getAll(),
356 );
357 };
358 }
359
360 protected static function buildHTTPPath(): bool
361 {
362 global $DIC;
363
364 return define(
365 'ILIAS_HTTP_PATH',
366 (new \ILIAS\Init\Environment\HttpPathBuilder(
367 $DIC[\ILIAS\Data\Factory::class],
368 $DIC->settings(),
369 $DIC['https'],
370 $DIC['ilIliasIniFile'],
372 ))->build()->getBaseURI()
373 );
374 }
375
380 protected static function determineClient(): void
381 {
382 if (defined('CLIENT_ID')) {
383 return;
384 }
385 global $DIC;
386 $df = $DIC[\ILIAS\Data\Factory::class];
387
388 // check whether ini file object exists
389 if (!$DIC->isDependencyAvailable('iliasIni')) {
390 self::abortAndDie('Fatal Error: ilInitialisation::determineClient called without initialisation of ILIAS ini file object.');
391 }
392
393 $in_unit_tests = defined('IL_PHPUNIT_TEST');
394 $context_supports_persitent_session = ilContext::supportsPersistentSessions();
395 $can_set_cookie = !$in_unit_tests && $context_supports_persitent_session;
396 $has_request_client_id = $DIC->http()->wrapper()->query()->has('client_id');
397 $has_cookie_client_id = $DIC->http()->cookieJar()->has('ilClientId');
398
399 // determine the available clientIds (default, request, cookie)
400 $default_client_id = $DIC->iliasIni()->readVariable('clients', 'default');
401
402 if ($DIC->http()->wrapper()->query()->has('client_id')) {
403 $client_id_from_get = $DIC->http()->wrapper()->query()->retrieve(
404 'client_id',
405 self::getClientIdTransformation()
406 );
407 }
408 if ($DIC->http()->wrapper()->cookie()->has('ilClientId')) {
409 $client_id_from_cookie = $DIC->http()->wrapper()->cookie()->retrieve(
410 'ilClientId',
411 self::getClientIdTransformation()
412 );
413 }
414
415 // set the clientId by availability: 1. request, 2. cookie, fallback to defined default
416 $client_id_to_use = '';
417 if (isset($client_id_from_get) && $client_id_from_get !== '') {
418 $client_id_to_use = $client_id_from_get;
419 }
420 // we found a client_id in $GET
421 if (isset($client_id_from_get) && strlen($client_id_from_get) > 0) {
422 // @todo refinery undefined
423 $client_id_to_use = $_GET['client_id'] = $df->clientId($client_id_from_get)->toString();
424 if ($can_set_cookie) {
425 ilUtil::setCookie('ilClientId', $client_id_to_use);
426 }
427 } else {
428 $client_id_to_use = $default_client_id;
429 if (!isset($_COOKIE['ilClientId'])) {
430 ilUtil::setCookie('ilClientId', $client_id_to_use);
431 }
432 }
433
434 $client_id_to_use = $client_id_to_use ?: $default_client_id;
435
436 define('CLIENT_ID', $df->clientId($client_id_to_use)->toString());
437 }
438
439
446 private static function getClientIdTransformation(): Transformation
447 {
448 return new class () implements Transformation {
452 public function transform($from): string
453 {
454 if (!is_string($from)) {
455 throw new InvalidArgumentException(__METHOD__ . " the argument is not a string.");
456 }
457 return strip_tags($from);
458 }
459
463 public function applyTo(Result $result): Result
464 {
465 return $result->then(function ($value): Result {
466 try {
467 return new Ok($this->transform($value));
468 } catch (Exception $exception) {
469 return new Error($exception);
470 }
471 });
472 }
473
477 public function __invoke($from): string
478 {
479 return $this->transform($from);
480 }
481 };
482 }
483
493 protected static function initClientIniFile(): void
494 {
495 global $ilIliasIniFile;
496
497 // check whether ILIAS_WEB_DIR is set.
498 if (!defined('ILIAS_WEB_DIR') || empty(ILIAS_WEB_DIR)) {
499 self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without ILIAS_WEB_DIR.");
500 }
501
502 // check whether CLIENT_ID is set.
503 if (CLIENT_ID == "") {
504 self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without CLIENT_ID.");
505 }
506
507 $ini_file = "/client.ini.php";
508 if (defined('CLIENT_WEB_DIR')) {
509 $ini_file = CLIENT_WEB_DIR . $ini_file;
510 } else {
511 $ini_file = __DIR__ . '/../../../../public/' . ILIAS_WEB_DIR . '/' . CLIENT_ID . '/client.ini.php';
512 }
513
514 $ilClientIniFile = new ilIniFile($ini_file);
515 $ilClientIniFile->read();
516
517 // invalid client id / client ini
518 if ($ilClientIniFile->ERROR != "") {
519 $default_client = $ilIliasIniFile->readVariable("clients", "default");
520 if (CLIENT_ID !== "") {
521 $mess = array("en" => "Client does not exist.",
522 "de" => "Mandant ist ungültig."
523 );
524 self::redirect("index.php?client_id=" . $default_client, '', $mess);
525 } else {
526 self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile initializing client ini file abborted with: " . $ilClientIniFile->ERROR);
527 }
528 }
529
530 self::initGlobal("ilClientIniFile", $ilClientIniFile);
531 // set constants
532 define("DEVMODE", (int) $ilClientIniFile->readVariable("system", "DEVMODE"));
533 define("SHOWNOTICES", (int) $ilClientIniFile->readVariable("system", "SHOWNOTICES"));
534 if (!defined("ROOT_FOLDER_ID")) {
535 define("ROOT_FOLDER_ID", (int) $ilClientIniFile->readVariable('system', 'ROOT_FOLDER_ID'));
536 }
537 if (!defined("SYSTEM_FOLDER_ID")) {
538 define("SYSTEM_FOLDER_ID", (int) $ilClientIniFile->readVariable('system', 'SYSTEM_FOLDER_ID'));
539 }
540 if (!defined("ROLE_FOLDER_ID")) {
541 define("ROLE_FOLDER_ID", (int) $ilClientIniFile->readVariable('system', 'ROLE_FOLDER_ID'));
542 }
543 define("MAIL_SETTINGS_ID", (int) $ilClientIniFile->readVariable('system', 'MAIL_SETTINGS_ID'));
544 $error_handler = $ilClientIniFile->readVariable('system', 'ERROR_HANDLER');
545 define("ERROR_HANDLER", $error_handler ?: "PRETTY_PAGE");
546
547 // this is for the online help installation, which sets OH_REF_ID to the
548 // ref id of the online module
549 define("OH_REF_ID", (int) $ilClientIniFile->readVariable("system", "OH_REF_ID"));
550
551 // see ilObject::TITLE_LENGTH, ilObject::DESC_LENGTH
552 // define ("MAXLENGTH_OBJ_TITLE",125);#$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_TITLE'));
553 // define ("MAXLENGTH_OBJ_DESC",$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_DESC'));
554
555 if (!defined("CLIENT_DATA_DIR")) {
556 define("CLIENT_DATA_DIR", ILIAS_DATA_DIR . "/" . CLIENT_ID);
557 }
558 if (!defined("CLIENT_WEB_DIR")) {
559 define("CLIENT_WEB_DIR", ILIAS_ABSOLUTE_PATH . "/public/" . ILIAS_WEB_DIR . "/" . CLIENT_ID);
560 }
561 define("CLIENT_NAME", $ilClientIniFile->readVariable('client', 'name')); // Change SS
562
563 $db_type = $ilClientIniFile->readVariable("db", "type");
564 if ($db_type === "") {
565 define("IL_DB_TYPE", ilDBConstants::TYPE_INNODB);
566 } else {
567 define("IL_DB_TYPE", $db_type);
568 }
569 }
570
574 protected static function handleMaintenanceMode(): void
575 {
576 global $ilClientIniFile;
577
578 if (!$ilClientIniFile->readVariable("client", "access")) {
579 $mess = array(
580 "en" => "The server is not available due to maintenance." .
581 " We apologise for any inconvenience.",
582 "de" => "Der Server ist aufgrund von Wartungsarbeiten aktuell nicht verf&uuml;gbar." .
583 " Wir bitten um Verst&auml;ndnis. Versuchen Sie es sp&auml;ter noch einmal."
584 );
585 $mess_id = "init_error_maintenance";
586
587 if (ilContext::hasHTML() && is_file("./maintenance.html")) {
588 self::redirect("./maintenance.html", $mess_id, $mess);
589 } else {
590 $mess = self::translateMessage($mess_id, $mess);
591 self::abortAndDie($mess);
592 }
593 }
594 }
595
599 protected static function initDatabase(): void
600 {
601 // build dsn of database connection and connect
603 $ilDB->initFromIniFile();
604 $ilDB->connect();
605
606 self::initGlobal("ilDB", $ilDB);
607 }
608
609 protected static function initGlobalCache(): void
610 {
611 global $DIC;
612 $legacy_settings = new ilGlobalCacheSettingsAdapter(
613 $DIC->clientIni(),
614 $DIC->database(),
615 );
616 $DIC['global_cache'] = new \ILIAS\Cache\Services(
617 $legacy_settings->getConfig()
618 );
619 }
620
625 public static function setSessionHandler(): void
626 {
627 $db_session_handler = new ilSessionDBHandler();
628 if (!$db_session_handler->setSaveHandler()) {
629 self::abortAndDie("Cannot start session handling.");
630 }
631
632 // Do not accept external session ids
633 if (!ilSession::_exists(session_id()) && !defined('IL_PHPUNIT_TEST')) {
634 // php7-todo, correct-with-php5-removal : alex, 1.3.2016: added if, please check
635 if (function_exists("session_status") && session_status() == PHP_SESSION_ACTIVE) {
636 session_regenerate_id();
637 }
638 }
639 }
640
644 protected static function setCookieConstants(): void
645 {
647 $cookie_path = '/';
648 } elseif (isset($GLOBALS['COOKIE_PATH'])) {
649 // use a predefined cookie path from WebAccessChecker
650 $cookie_path = $GLOBALS['COOKIE_PATH'];
651 } else {
652 $cookie_path = dirname($_SERVER['SCRIPT_NAME']);
653 }
654
655 /* if ilias is called directly within the docroot $cookie_path
656 is set to '/' expecting on servers running under windows..
657 here it is set to '\'.
658 in both cases a further '/' won't be appended due to the following regex
659 */
660 $cookie_path .= (!preg_match("/[\/|\\\\]$/", $cookie_path)) ? "/" : "";
661
662 if ($cookie_path == "\\") {
663 $cookie_path = '/';
664 }
665
666 define('IL_COOKIE_HTTPONLY', true); // Default Value
667 define('IL_COOKIE_EXPIRE', 0);
668 define('IL_COOKIE_DOMAIN', '');
669 if (!defined('IL_COOKIE_PATH')) {
670 // Might be already defined by ./public/sso/index.php or other scripts (like those in ./components/ILIAS/SAML/lib/*)
671 define('IL_COOKIE_PATH', $cookie_path);
672 }
673 }
674
675 private static function setClientIdCookie(): void
676 {
677 if (defined('CLIENT_ID') &&
678 !defined('IL_PHPUNIT_TEST') &&
680 ilUtil::setCookie('ilClientId', CLIENT_ID);
681 }
682 }
683
687 protected static function setSessionCookieParams(): void
688 {
689 global $ilSetting, $DIC;
690
691 if (!defined('IL_COOKIE_SECURE')) {
692 // If this code is executed, we can assume that \ilHTTPS::enableSecureCookies was NOT called before
693 // \ilHTTPS::enableSecureCookies already executes session_set_cookie_params()
694
695 $cookie_secure = !$ilSetting->get('https', '0') && $DIC['https']->isDetected();
696 define('IL_COOKIE_SECURE', $cookie_secure); // Default Value
697
698 $cookie_parameters = [
699 'lifetime' => IL_COOKIE_EXPIRE,
700 'path' => IL_COOKIE_PATH,
701 'domain' => IL_COOKIE_DOMAIN,
702 'secure' => IL_COOKIE_SECURE,
703 'httponly' => IL_COOKIE_HTTPONLY,
704 ];
705
706 if (
707 $cookie_secure &&
708 (!isset(session_get_cookie_params()['samesite']) || strtolower(session_get_cookie_params()['samesite']) !== 'strict')
709 ) {
710 $cookie_parameters['samesite'] = 'Lax';
711 }
712
713 session_set_cookie_params($cookie_parameters);
714 }
715 }
716
717 protected static function initCron(\ILIAS\DI\Container $c): void
718 {
719 $c['cron.repository'] = static function (\ILIAS\DI\Container $c): ILIAS\Cron\Job\JobRepository {
721 $c->database(),
722 $c->settings(),
723 $c->logger()->cron(),
724 $c['component.repository'],
725 $c['component.factory']
726 );
727 };
728
729 $c['cron.manager'] = static function (\ILIAS\DI\Container $c): ILIAS\Cron\Job\JobManager {
731 $c['cron.repository'],
732 $c->database(),
733 $c->settings(),
734 $c->logger()->cron(),
735 $c[\ILIAS\Data\Factory::class]->clock(),
736 );
737 };
738 }
739
743 protected static function initCustomObjectIcons(\ILIAS\DI\Container $c): void
744 {
745 $c["object.customicons.factory"] = function ($c) {
746 return new CustomIconFactory(
747 $c->filesystem()->web(),
748 $c->upload(),
749 $c['ilObjDataCache']
750 );
751 };
752 }
753
754 protected static function initAvatar(\ILIAS\DI\Container $c): void
755 {
756 $c["user.avatar.factory"] = function ($c) {
757 return new \ilUserAvatarFactory($c);
758 };
759 }
760
761 protected static function initLegalDocuments(Container $c): void
762 {
763 $c['legalDocuments'] = static fn(Container $c) => new Conductor($c);
764 }
765
766 protected static function initAccessibilityControlConcept(\ILIAS\DI\Container $c): void
767 {
768 $c['acc.criteria.type.factory'] = function (\ILIAS\DI\Container $c) {
769 return new ilAccessibilityCriterionTypeFactory($c->rbac()->review(), $c['ilObjDataCache']);
770 };
771
772 $c['acc.document.evaluator'] = function (\ILIAS\DI\Container $c) {
775 $c['acc.criteria.type.factory'],
776 $c->user(),
777 $c->logger()->acc()
778 ),
779 $c->user(),
780 $c->logger()->acc(),
781 \ilAccessibilityDocument::orderBy('sorting')->get()
782 );
783 };
784 }
785
790 protected static function initSettings(): void
791 {
792 global $ilSetting;
793
795 "ilSetting",
796 "ilSetting",
797 "components/ILIAS/Administration/classes/class.ilSetting.php"
798 );
799
800 // check correct setup
801 if (!$ilSetting->get("setup_ok")) {
802 self::abortAndDie("Setup is not completed. Please run setup routine again.");
803 }
804
805 // set anonymous user & role id and system role id
806 define("ANONYMOUS_USER_ID", (int) $ilSetting->get("anonymous_user_id"));
807 define("ANONYMOUS_ROLE_ID", (int) $ilSetting->get("anonymous_role_id"));
808 define("SYSTEM_USER_ID", (int) $ilSetting->get("system_user_id"));
809 define("SYSTEM_ROLE_ID", (int) $ilSetting->get("system_role_id"));
810 define("USER_FOLDER_ID", 7);
811
812 // recovery folder
813 define("RECOVERY_FOLDER_ID", (int) $ilSetting->get("recovery_folder_id"));
814
815 // installation id
816 define("IL_INST_ID", $ilSetting->get("inst_id", '0'));
817
818 // define default suffix replacements
819 define("SUFFIX_REPL_DEFAULT", "php,php3,php4,inc,lang,phtml,htaccess");
820 define("SUFFIX_REPL_ADDITIONAL", $ilSetting->get("suffix_repl_additional", ""));
821
822 if (ilContext::usesHTTP()) {
824 }
825 }
826
830 protected static function initStyle(): void
831 {
832 global $DIC;
833 $component_factory = $DIC["component.factory"];
834
835 // load style definitions
837 "styleDefinition",
838 "ilStyleDefinition",
839 "./components/ILIAS/Style/System/classes/class.ilStyleDefinition.php"
840 );
841
842 // add user interface hook for style initialisation
843 foreach ($component_factory->getActivePluginsInSlot("uihk") as $ui_plugin) {
844 $gui_class = $ui_plugin->getUIClassInstance();
845 $gui_class->modifyGUI("components/ILIAS/Init", "init_style", array("styleDefinition" => $DIC->systemStyle()));
846 }
847 }
848
852 public static function initUserAccount(): void
853 {
854 global $DIC;
855
856 static $context_init;
857
858 $uid = $GLOBALS['DIC']['ilAuthSession']->getUserId();
859 if ($uid) {
860 $DIC->user()->setId($uid);
861 $DIC->user()->read();
862 if (!isset($context_init)) {
863 if ($DIC->user()->isAnonymous()) {
864 $DIC->globalScreen()->tool()->context()->claim()->external();
865 } else {
866 $DIC->globalScreen()->tool()->context()->claim()->internal();
867 }
868 $context_init = true;
869 }
870 // init console log handler
871 ilLoggerFactory::getInstance()->initUser($DIC->user()->getLogin());
873 } else {
874 if (is_object($GLOBALS['ilLog'])) {
875 $GLOBALS['ilLog']->logStack();
876 }
877 self::abortAndDie("Init user account failed");
878 }
879 }
880
884 protected static function initLocale(): void
885 {
886 global $ilSetting;
887
888 if ($ilSetting->get("locale") && trim($ilSetting->get("locale")) !== "") {
889 $larr = explode(",", trim($ilSetting->get("locale")));
890 $ls = array();
891 $first = $larr[0];
892 foreach ($larr as $l) {
893 if (trim($l) != "") {
894 $ls[] = $l;
895 }
896 }
897 if (count($ls) > 0) {
898 setlocale(LC_ALL, $ls);
899
900 // #15347 - making sure that floats are not changed
901 setlocale(LC_NUMERIC, "C");
902 }
903 }
904 }
905
909 public static function goToPublicSection(): void
910 {
911 global $DIC;
912
913 if (ANONYMOUS_USER_ID == "") {
914 self::abortAndDie("Public Section enabled, but no Anonymous user found.");
915 }
916
917 $session_destroyed = false;
918 if ($DIC['ilAuthSession']->isExpired()) {
919 $session_destroyed = true;
921 }
922 if (!$DIC['ilAuthSession']->isAuthenticated()) {
923 $session_destroyed = true;
925 }
926
927 if ($session_destroyed) {
928 $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, ANONYMOUS_USER_ID);
929 }
930
932
933 $target = '';
934 if ($DIC->http()->wrapper()->query()->has('target')) {
935 $target = $DIC->http()->wrapper()->query()->retrieve(
936 'target',
937 $DIC->refinery()->kindlyTo()->string()
938 );
939 }
940
941 // if target given, try to go there
942 if (strlen($target)) {
943 // when we are already "inside" goto.php no redirect is needed
944 $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
945 if ($current_script == "goto.php") {
946 return;
947 }
948 // goto will check if target is accessible or redirect to login
949 self::redirect("goto.php?target=" . $target);
950 }
951
952 // we do not know if ref_id of request is accesible, so redirecting to root
954 "ilias.php?baseClass=ilrepositorygui&reloadpublic=1&cmd=&ref_id=" . (defined(
955 'ROOT_FOLDER_ID'
956 ) ? (string) ROOT_FOLDER_ID : '0')
957 );
958 }
959
963 protected static function goToLogin(): void
964 {
965 global $DIC;
966
967 $session_expired = false;
968 ilLoggerFactory::getLogger('init')->debug('Redirecting to login page.');
969
970 if ($DIC['ilAuthSession']->isExpired()) {
972 $session_expired = true;
973 }
974 if (!$DIC['ilAuthSession']->isAuthenticated()) {
976 }
977
978 $target = $DIC->http()->wrapper()->query()->has('target')
979 ? $DIC->http()->wrapper()->query()->retrieve(
980 'target',
981 $DIC->refinery()->kindlyTo()->string()
982 )
983 : '';
984
985 if (strlen($target)) {
986 $target = "target=" . $target . "&";
987 }
988
989 $client_id = $DIC->http()->wrapper()->cookie()->retrieve(
990 'ilClientId',
991 $DIC->refinery()->byTrying([
992 $DIC->refinery()->kindlyTo()->string(),
993 $DIC->refinery()->always('')
994 ])
995 );
996
997 $script = "login.php?" . $target . "client_id=" . $client_id;
998 $script .= $session_expired ? "&session_expired=1" : "";
999
1001 $script,
1002 "init_error_authentication_fail",
1003 array(
1004 "en" => "Authentication failed.",
1005 "de" => "Authentifizierung fehlgeschlagen."
1006 )
1007 );
1008 }
1009
1013 protected static function initLanguage(bool $a_use_user_language = true): void
1014 {
1015 global $DIC;
1016
1020 global $rbacsystem;
1021
1022 if ($a_use_user_language) {
1023 if ($DIC->offsetExists('lng')) {
1024 $DIC->offsetUnset('lng');
1025 }
1027 } else {
1029 }
1030 if (is_object($rbacsystem) && $DIC->offsetExists('tree')) {
1031 $rbacsystem->initMemberView();
1032 }
1033 }
1034
1038 protected static function initAccessHandling(): void
1039 {
1041 "rbacreview",
1042 "ilRbacReview",
1043 "./components/ILIAS/AccessControl/classes/class.ilRbacReview.php",
1044 true
1045 );
1046
1047 $rbacsystem = ilRbacSystem::getInstance();
1048 self::initGlobal('rbacsystem', $rbacsystem, null, true);
1049
1051 "rbacadmin",
1052 "ilRbacAdmin",
1053 "./components/ILIAS/AccessControl/classes/class.ilRbacAdmin.php",
1054 true
1055 );
1056
1058 "ilAccess",
1059 "ilAccess",
1060 "./components/ILIAS/AccessControl/classes/class.ilAccess.php",
1061 true
1062 );
1063 }
1064
1068 protected static function initLog(): void
1069 {
1071
1072 self::initGlobal("ilLog", $log);
1073 // deprecated
1074 self::initGlobal("log", $log);
1075 }
1076
1080 protected static function initGlobal(
1081 string $a_name,
1082 $a_class,
1083 ?string $a_source_file = null,
1084 ?bool $destroy_existing = false
1085 ): void {
1086 global $DIC;
1087
1088 if ($destroy_existing) {
1089 if (isset($GLOBALS[$a_name])) {
1090 unset($GLOBALS[$a_name]);
1091 }
1092 if (isset($DIC[$a_name])) {
1093 unset($DIC[$a_name]);
1094 }
1095 }
1096
1097 $GLOBALS[$a_name] = is_object($a_class) ? $a_class : new $a_class();
1098
1099 $DIC[$a_name] = static function (Container $c) use ($a_name) {
1100 return $GLOBALS[$a_name];
1101 };
1102 }
1103
1104 protected static function abortAndDie(string $a_message): void
1105 {
1106 if (isset($GLOBALS['ilLog'])) {
1107 $GLOBALS['ilLog']->write("Fatal Error: ilInitialisation - " . $a_message);
1108 $GLOBALS['ilLog']->logStack();
1109 }
1110 die($a_message);
1111 }
1112
1116 protected static function handleDevMode(): void
1117 {
1118 error_reporting(-1);
1119 }
1120
1121 protected static bool $already_initialized = false;
1122
1123 public static function reinitILIAS(): void
1124 {
1125 self::$already_initialized = false;
1126 self::initILIAS();
1127 }
1128
1129 public static function reInitUser(): void
1130 {
1132 self::initSession();
1133 self::initUser();
1134
1136 self::resumeUserSession();
1137 }
1138 }
1139 }
1140
1144 public static function initILIAS(): void
1145 {
1146 if (self::$already_initialized) {
1147 return;
1148 }
1149
1150 $GLOBALS["DIC"]["ilLoggerFactory"] = function ($c) {
1152 };
1153
1154 self::$already_initialized = true;
1155
1156 self::initCore();
1157 self::initHTTPServices($GLOBALS["DIC"]);
1158 if (ilContext::initClient()) {
1159 self::initFileUploadService($GLOBALS["DIC"]);
1160 Init::init($GLOBALS["DIC"]);
1161 self::initClient();
1162 self::initSession();
1163
1164 if (ilContext::hasUser()) {
1165 self::initUser();
1166
1168 self::resumeUserSession();
1169 }
1170 }
1171
1172 // language may depend on user setting
1173 self::initLanguage(true);
1174 $GLOBALS['DIC']['tree']->initLangCode();
1175
1176 self::initInjector($GLOBALS['DIC']);
1177 self::initBackgroundTasks($GLOBALS['DIC']);
1178 self::initKioskMode($GLOBALS['DIC']);
1179
1180 if (ilContext::hasHTML()) {
1181 self::initHTML();
1182 }
1183 }
1184
1185 // this MUST happen after everything else is initialized,
1186 // because this leads to rather unexpected behaviour which
1187 // is super hard to track down to this.
1188 self::replaceSuperGlobals($GLOBALS['DIC']);
1189 }
1190
1194 protected static function initSession(): void
1195 {
1196 if (isset($GLOBALS['DIC']['ilAuthSession'])) {
1197 unset($GLOBALS['DIC']['ilAuthSession']);
1198 }
1199
1200 $GLOBALS['DIC']['ilAuthSession'] = static function (Container $c): ilAuthSession {
1201 $auth_session = ilAuthSession::getInstance(
1202 $c['ilLoggerFactory']->getLogger('auth')
1203 );
1204 $auth_session->init();
1205 return $auth_session;
1206 };
1207 }
1208
1212 public static function handleErrorReporting(): void
1213 {
1214 // push the error level as high as possible / sane
1215 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
1216
1217 // see handleDevMode() - error reporting might be overwritten again
1218 // but we need the client ini first
1219 }
1220
1224 protected static function initCore(): void
1225 {
1226 global $ilErr;
1227
1228 self::handleErrorReporting();
1229
1230 self::requireCommonIncludes();
1231 $GLOBALS["DIC"]["ilias.version"] = $GLOBALS["DIC"][\ILIAS\Data\Factory::class]->version(ILIAS_VERSION_NUMERIC);
1232
1233 // error handler
1234 self::initGlobal(
1235 "ilErr",
1236 "ilErrorHandling",
1237 "./components/ILIAS/Init/classes/class.ilErrorHandling.php"
1238 );
1239
1240 self::removeUnsafeCharacters();
1241
1242 self::initIliasIniFile();
1243
1244 define('IL_INITIAL_WD', getcwd());
1245
1246 // deprecated
1247 self::initGlobal("ilias", "ILIAS", "./components/ILIAS/Init/classes/class.ilias.php");
1248 }
1249
1253 protected static function initClient(): void
1254 {
1255 global $https, $ilias, $DIC;
1256
1257 self::setCookieConstants();
1258
1259 self::determineClient();
1260
1261 self::bootstrapFilesystems();
1262
1263 self::initResourceStorage();
1264
1265 self::initClientIniFile();
1266
1267 // --- needs client ini
1268
1269 $ilias->client_id = (string) CLIENT_ID;
1270
1271 if (DEVMODE) {
1272 self::handleDevMode();
1273 }
1274
1275 self::handleMaintenanceMode();
1276
1277 self::initDatabase();
1278
1279 self::initGlobalCache();
1280
1281 self::initComponentService($DIC);
1282
1283 // init dafault language
1284 self::initLanguage(false);
1285
1286 // moved after databases
1287 self::initLog();
1288
1289 self::initGlobal(
1290 "ilAppEventHandler",
1291 "ilAppEventHandler",
1292 "./components/ILIAS/EventHandling/classes/class.ilAppEventHandler.php"
1293 );
1294
1295 // there are rare cases where initILIAS is called twice for a request
1296 // example goto.php is called and includes ilias.php later
1297 // we must prevent that ilPluginAdmin is initialized twice in
1298 // this case, since this won't get the values out of plugin.php the
1299 // second time properly
1300 if (!isset($DIC["ilPluginAdmin"]) || !$DIC["ilPluginAdmin"] instanceof ilPluginAdmin) {
1301 self::initGlobal(
1302 "ilPluginAdmin",
1303 new ilPluginAdmin($DIC["component.repository"]),
1304 "./components/ILIAS/Component/classes/class.ilPluginAdmin.php"
1305 );
1306 }
1307 self::initGlobal("https", "ilHTTPS", "./components/ILIAS/Http/classes/class.ilHTTPS.php");
1308 self::initSettings();
1309 self::setSessionHandler();
1310 self::initCron($GLOBALS['DIC']);
1311 self::initAvatar($GLOBALS['DIC']);
1312 self::initCustomObjectIcons($GLOBALS['DIC']);
1313 self::initLegalDocuments($GLOBALS['DIC']);
1314 self::initAccessibilityControlConcept($GLOBALS['DIC']);
1315 self::initLearningObjectMetadata($GLOBALS['DIC']);
1316
1317 // --- needs settings
1318
1319 self::initLocale();
1320
1321 if (ilContext::usesHTTP()) {
1322 $https->enableSecureCookies();
1323 $https->checkProtocolAndRedirectIfNeeded();
1324 }
1325
1326 // --- object handling
1327
1328 self::initGlobal(
1329 "ilObjDataCache",
1330 "ilObjectDataCache",
1331 "./components/ILIAS/Object/classes/class.ilObjectDataCache.php"
1332 );
1333
1334 self::initGlobal(
1335 "objDefinition",
1336 "ilObjectDefinition",
1337 "./components/ILIAS/Object/classes/class.ilObjectDefinition.php"
1338 );
1339
1340 // $tree
1341 $tree = new ilTree(ROOT_FOLDER_ID);
1342 self::initGlobal("tree", $tree);
1343 unset($tree);
1344
1345 self::setSessionCookieParams();
1346 self::setClientIdCookie();
1347
1348 (new InitCtrlService())->init($DIC);
1349
1350 // Init GlobalScreen
1351 self::initGlobalScreen($DIC);
1352 }
1353
1357 protected static function initUser(): void
1358 {
1359 global $ilias, $ilUser;
1360
1361 // $ilUser
1362 self::initGlobal(
1363 "ilUser",
1365 "./components/ILIAS/User/classes/class.ilObjUser.php",
1366 true
1367 );
1368
1369 self::initGlobal(
1370 'user',
1371 new UserPublicInterface($ilUser)
1372 );
1373
1374 $ilias->account = $ilUser;
1375
1376 self::initAccessHandling();
1377 }
1378
1382 public static function resumeUserSession(): void
1383 {
1384 global $DIC;
1385
1388 }
1389
1390 if (
1391 !$DIC['ilAuthSession']->isAuthenticated() ||
1392 $DIC['ilAuthSession']->isExpired()
1393 ) {
1394 if ($GLOBALS['DIC']['ilAuthSession']->isExpired()) {
1396 }
1397
1398 ilLoggerFactory::getLogger('init')->debug('Current session is invalid: ' . $GLOBALS['DIC']['ilAuthSession']->getId());
1399 $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
1400 if (self::blockedAuthentication($current_script)) {
1401 ilLoggerFactory::getLogger('init')->debug('Authentication is started in current script.');
1402 // nothing todo: authentication is done in current script
1403 return;
1404 }
1405
1406 self::handleAuthenticationFail();
1407 return;
1408 }
1409 // valid session
1410
1411 self::initUserAccount();
1412 }
1413
1417 protected static function handleAuthenticationSuccess(): void
1418 {
1422 global $ilUser;
1423
1425 }
1426
1430 protected static function handleAuthenticationFail(): void
1431 {
1432 global $DIC;
1433
1434 ilLoggerFactory::getLogger('init')->debug('Handling of failed authentication.');
1435
1436 // #10608
1437 if (
1440 throw new Exception("Authentication failed.");
1441 }
1442
1443 if (($DIC->http()->request()->getQueryParams()['cmdMode'] ?? 0) === 'asynch') {
1444 $DIC->language()->loadLanguageModule('init');
1445 $DIC->http()->saveResponse(
1446 $DIC->http()->response()
1447 ->withStatus(403)
1448 ->withBody(Streams::ofString($DIC->language()->txt('init_error_authentication_fail')))
1449 );
1450 $DIC->http()->sendResponse();
1451 $DIC->http()->close();
1452 }
1453 if (
1454 $DIC['ilAuthSession']->isExpired() &&
1455 !\ilObjUser::_isAnonymous($DIC['ilAuthSession']->getUserId())
1456 ) {
1457 ilLoggerFactory::getLogger('init')->debug('Expired session found -> redirect to login page');
1458 self::goToLogin();
1459 return;
1460 }
1461 if (ilPublicSectionSettings::getInstance()->isEnabledForDomain($_SERVER['SERVER_NAME']) &&
1462 $DIC->access()->checkAccessOfUser(ANONYMOUS_USER_ID, 'read', '', ROOT_FOLDER_ID)) {
1463 ilLoggerFactory::getLogger('init')->debug('Redirect to public section.');
1464 self::goToPublicSection();
1465 return;
1466 }
1467 ilLoggerFactory::getLogger('init')->debug('Redirect to login page.');
1468 self::goToLogin();
1469 }
1470
1474 protected static function initHTTPServices(\ILIAS\DI\Container $container): void
1475 {
1476 $init_http = new InitHttpServices();
1477 $init_http->init($container);
1478
1480 }
1481
1485 private static function initGlobalScreen(\ILIAS\DI\Container $c): void
1486 {
1487 $c['global_screen'] = function () use ($c) {
1488 return new Services(
1490 $c->ui(),
1491 htmlentities(str_replace([" ", ".", "-"], "_", ILIAS_VERSION_NUMERIC))
1492 );
1493 };
1494 $c->globalScreen()->tool()->context()->stack()->clear();
1495 $c->globalScreen()->tool()->context()->claim()->main();
1496 }
1497
1503 {
1504 $component_repository = $c["component.repository"];
1505 $component_factory = $c["component.factory"];
1506 foreach ($component_repository->getPlugins() as $pl) {
1507 if (!$pl->isActive()) {
1508 continue;
1509 }
1510 $plugin = $component_factory->getPlugin($pl->getId());
1511 $c['ui.renderer'] = $plugin->exchangeUIRendererAfterInitialization($c);
1512
1513 foreach ($c->keys() as $key) {
1514 if (strpos($key, "ui.factory") === 0) {
1515 $c[$key] = $plugin->exchangeUIFactoryAfterInitialization($key, $c);
1516 }
1517 }
1518 }
1519 }
1520
1524 protected static function replaceSuperGlobals(\ILIAS\DI\Container $container): void
1525 {
1527 $client_ini = $container['ilClientIniFile'];
1528
1529 $replace_super_globals = (
1530 !$client_ini->variableExists('server', 'prevent_super_global_replacement') ||
1531 !(bool) $client_ini->readVariable('server', 'prevent_super_global_replacement')
1532 );
1533
1534 if ($replace_super_globals) {
1535 $throwOnValueAssignment = defined('DEVMODE') && DEVMODE;
1536
1537 $_GET = new SuperGlobalDropInReplacement($container['refinery'], $_GET, $throwOnValueAssignment);
1538 $_POST = new SuperGlobalDropInReplacement($container['refinery'], $_POST, $throwOnValueAssignment);
1539 $_COOKIE = new SuperGlobalDropInReplacement($container['refinery'], $_COOKIE, $throwOnValueAssignment);
1540 $_REQUEST = new SuperGlobalDropInReplacement($container['refinery'], $_REQUEST, $throwOnValueAssignment);
1541 }
1542 }
1543
1544 protected static function initComponentService(\ILIAS\DI\Container $container): void
1545 {
1546 $init = new InitComponentService();
1547 $init->init($container);
1548 }
1549
1553 protected static function initHTML(): void
1554 {
1555 global $ilUser, $DIC;
1556
1557 if (ilContext::hasUser()) {
1558 // load style definitions
1559 // use the init function with plugin hook here, too
1560 self::initStyle();
1561
1562 self::initUploadPolicies($DIC);
1563 }
1564
1565 self::applyPluginManipulationsToUiFramework($GLOBALS["DIC"]);
1566 $tpl = new ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
1567 self::initGlobal("tpl", $tpl);
1568
1569 if (ilContext::hasUser()) {
1570 $dispatcher = new \ILIAS\Init\StartupSequence\StartUpSequenceDispatcher($DIC);
1571 $dispatcher->dispatch();
1572 }
1573
1574 self::initGlobal(
1575 "ilNavigationHistory",
1576 "ilNavigationHistory",
1577 "components/ILIAS/Navigation/classes/class.ilNavigationHistory.php"
1578 );
1579
1580 self::initGlobal(
1581 "ilHelp",
1582 "ilHelpGUI",
1583 "components/ILIAS/Help/classes/class.ilHelpGUI.php"
1584 );
1585
1586 if (DEVMODE) {
1587 $DIC["help.text_retriever"] = new ILIAS\UI\Help\TextRetriever\Echoing();
1588 } else {
1589 $DIC["help.text_retriever"] = new ilHelpUITextRetriever();
1590 }
1591
1592 self::initGlobal(
1593 "ilToolbar",
1594 "ilToolbarGUI",
1595 "./components/ILIAS/UIComponent/Toolbar/classes/class.ilToolbarGUI.php"
1596 );
1597
1598 self::initGlobal(
1599 "ilLocator",
1600 "ilLocatorGUI",
1601 "./components/ILIAS/Locator/classes/class.ilLocatorGUI.php"
1602 );
1603
1604 self::initGlobal(
1605 "ilTabs",
1606 "ilTabsGUI",
1607 "./components/ILIAS/UIComponent/Tabs/classes/class.ilTabsGUI.php"
1608 );
1609
1610 if (ilContext::hasUser()) {
1611 // the next line makes it impossible to save the offset somehow in a session for
1612 // a specific table (I tried it for the user administration).
1613 // its not posssible to distinguish whether it has been set to page 1 (=offset = 0)
1614 // or not set at all (then we want the last offset, e.g. being used from a session var).
1615 // So I added the wrapping if statement. Seems to work (hopefully).
1616 // Alex April 14th 2006
1617 // @todo not replaced by refinery due to unknown sideeffects
1618 if (isset($_GET['offset']) && $_GET['offset'] != "") {
1619 $_GET['offset'] = (int) $_GET['offset']; // old code
1620 }
1621
1622 self::initGlobal("lti", "ilLTIViewGUI", "./components/ILIAS/LTIProvider/classes/class.ilLTIViewGUI.php");
1623 $GLOBALS["DIC"]["lti"]->init();
1624 self::initKioskMode($GLOBALS["DIC"]);
1625 }
1626 }
1627
1631 protected static function blockedAuthentication(string $a_current_script): bool
1632 {
1633 global $DIC;
1634
1636 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for WAC request.');
1637 return true;
1638 }
1640 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for sso request.');
1641 return true;
1642 }
1644 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for webdav request');
1645 return true;
1646 }
1648 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for shibboleth request.');
1649 return true;
1650 }
1652 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for lti provider requests.');
1653 return true;
1654 }
1656 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for SAML request.');
1657 return true;
1658 }
1659 if (
1660 $a_current_script == "register.php" ||
1661 $a_current_script == "pwassist.php" ||
1662 $a_current_script == "confirmReg.php" ||
1663 $a_current_script == "il_securimage_play.php" ||
1664 $a_current_script == "il_securimage_show.php" ||
1665 $a_current_script == 'login.php'
1666 ) {
1667 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for script: ' . $a_current_script);
1668 return true;
1669 }
1670
1671 // @todo refinery undefined
1672 $requestBaseClass = strtolower((string) ($_GET['baseClass'] ?? ''));
1673 if ($requestBaseClass == strtolower(ilStartUpGUI::class)) {
1674 $requestCmdClass = strtolower((string) ($_GET['cmdClass'] ?? ''));
1675 if (
1676 $requestCmdClass == strtolower(ilAccountRegistrationGUI::class) ||
1677 $requestCmdClass == strtolower(ilPasswordAssistanceGUI::class)
1678 ) {
1679 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmdClass: ' . $requestCmdClass);
1680 return true;
1681 }
1682 $cmd = $DIC->ctrl()->getCmd();
1683
1684 if (in_array($cmd, [
1685 'showLegalDocuments',
1686 'showAccountMigration',
1687 'migrateAccount',
1688 'processCode',
1689 'showLoginPage',
1690 'showLogout',
1691 'doStandardAuthentication',
1692 'doCasAuthentication',
1693 ], true)) {
1694 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmd: ' . $cmd);
1695 return true;
1696 }
1697 }
1698
1699 $target = '';
1700 if ($DIC->http()->wrapper()->query()->has('target')) {
1701 // @todo refinery undefined
1702 $target = $_GET['target'];
1703 }
1704
1705 // #12884
1706 if (
1707 ($a_current_script == "goto.php" && $target == "impr_0") ||
1708 $requestBaseClass == strtolower(ilImprintGUI::class)
1709 ) {
1710 // @todo refinery undefind
1711 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for baseClass: ' . ($_GET['baseClass'] ?? ""));
1712 return true;
1713 }
1714
1715 if (
1716 (strtolower($requestCmdClass ?? "") === strtolower(ilAccessibilityControlConceptGUI::class))
1717 ) {
1718 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmdClass: ' . $requestCmdClass);
1719 return true;
1720 }
1721
1722 if ($a_current_script == 'goto.php' && in_array($target, array(
1723 'usr_registration',
1724 'usr_nameassist',
1725 'usr_pwassist',
1726 'usr_agreement'
1727 ))) {
1728 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for goto target: ' . $target);
1729 return true;
1730 }
1731
1732
1733 $current_ref_id = $DIC->http()->wrapper()->query()->has('ref_id')
1734 ? $DIC->http()->wrapper()->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int())
1735 : null;
1736
1737 if (null !== $current_ref_id
1738 && $DIC->user()->getId() === 0
1739 && $DIC->access()->checkAccessOfUser(
1741 'visible',
1742 '',
1743 $current_ref_id
1744 )) {
1745 return true;
1746 }
1747
1748
1749 ilLoggerFactory::getLogger('auth')->debug('Authentication required');
1750 return false;
1751 }
1752
1756 protected static function translateMessage(string $a_message_id, ?array $a_message_static = null): string
1757 {
1758 global $ilDB, $lng, $ilSetting, $ilClientIniFile, $ilUser;
1759
1760 // current language
1761 if (!$lng) {
1762 $lang = "en";
1763 if ($ilUser) {
1764 $lang = $ilUser->getLanguage();
1765 } elseif (isset($_REQUEST["lang"])) {
1766 $lang = (string) $_REQUEST["lang"];
1767 } elseif ($ilSetting) {
1768 $lang = $ilSetting->get("language", '');
1769 } elseif ($ilClientIniFile) {
1770 $lang = $ilClientIniFile->readVariable("language", "default");
1771 }
1772 } else {
1773 $lang = $lng->getLangKey();
1774 }
1775
1776 $message = "";
1777 if ($ilDB && $a_message_id) {
1778 if (!$lng) {
1779 $lng = new ilLanguage($lang);
1780 }
1781
1782 $lng->loadLanguageModule("init");
1783 $message = $lng->txt($a_message_id);
1784 } elseif (is_array($a_message_static)) {
1785 if (!isset($a_message_static[$lang])) {
1786 $lang = "en";
1787 }
1788 $message = $a_message_static[$lang];
1789 }
1790 return $message;
1791 }
1792
1796 protected static function redirect(
1797 string $a_target,
1798 string $a_message_id = '',
1799 ?array $a_message_static = null
1800 ): void {
1801 // #12739
1802 if (defined("ILIAS_HTTP_PATH") &&
1803 !stristr($a_target, ILIAS_HTTP_PATH)) {
1804 $a_target = ILIAS_HTTP_PATH . "/" . $a_target;
1805 }
1806
1807 foreach (['ext_uid', 'soap_pw'] as $param) {
1808 if (false === strpos(
1809 $a_target,
1810 $param . '='
1811 ) && isset($GLOBALS['DIC']->http()->request()->getQueryParams()[$param])) {
1812 $a_target = \ilUtil::appendUrlParameterString($a_target, $param . '=' . \ilUtil::stripSlashes(
1813 $GLOBALS['DIC']->http()->request()->getQueryParams()[$param]
1814 ));
1815 }
1816 }
1817
1819 ilUtil::redirect($a_target);
1820 } else {
1821 $message = self::translateMessage($a_message_id, $a_message_static);
1822
1823 // user-directed linked message
1825 $link = self::translateMessage(
1826 "init_error_redirect_click",
1827 array("en" => 'Please click to continue.',
1828 "de" => 'Bitte klicken um fortzufahren.'
1829 )
1830 );
1831 $mess = $message .
1832 '<br /><a href="' . $a_target . '">' . $link . '</a>';
1833 } // plain text
1834 else {
1835 // not much we can do here
1836 $mess = $message;
1837
1838 if (!trim($mess)) {
1839 $mess = self::translateMessage(
1840 "init_error_redirect_info",
1841 array("en" => 'Redirect not supported by context.',
1842 "de" => 'Weiterleitungen werden durch Kontext nicht unterstützt.'
1843 )
1844 ) .
1845 ' (' . $a_target . ')';
1846 }
1847 }
1848
1849 self::abortAndDie($mess);
1850 }
1851 }
1852
1853 public static function redirectToStartingPage(string $target = ''): void
1854 {
1855 global $DIC;
1856
1857 // fallback, should never happen
1858 if ($DIC->user()->getId() === ANONYMOUS_USER_ID) {
1859 self::goToPublicSection();
1860 return;
1861 }
1862
1863 if (
1864 $target === '' &&
1865 $DIC->http()->wrapper()->query()->has('target')
1866 ) {
1867 $target = $DIC->http()->wrapper()->query()->retrieve(
1868 'target',
1869 $DIC->refinery()->kindlyTo()->string()
1870 );
1871 }
1872
1873 // for password change and incomplete profile
1874 // see ilDashboardGUI
1875 if ($target === '') {
1876 ilLoggerFactory::getLogger('init')->debug('Redirect to default starting page');
1877 $DIC->ctrl()->redirectToURL(ilUserUtil::getStartingPointAsUrl());
1878 } else {
1879 ilLoggerFactory::getLogger('init')->debug('Redirect to target: ' . $target);
1880 $DIC->ctrl()->redirectToURL("goto.php?target=" . $target);
1881 }
1882 }
1883
1884 private static function initBackgroundTasks(\ILIAS\DI\Container $c): void
1885 {
1886 global $ilIliasIniFile;
1887
1888 $n_of_tasks = $ilIliasIniFile->readVariable("background_tasks", "number_of_concurrent_tasks");
1889 $sync = $ilIliasIniFile->readVariable("background_tasks", "concurrency");
1890
1891 $n_of_tasks = $n_of_tasks ?: 5;
1892 $sync = $sync ?: 'sync'; // The default value is sync.
1893
1894 $c["bt.task_factory"] = function ($c) {
1895 return new \ILIAS\BackgroundTasks\Implementation\Tasks\BasicTaskFactory($c["di.injector"]);
1896 };
1897
1898 $c["bt.persistence"] = function ($c) {
1899 return \ILIAS\BackgroundTasks\Implementation\Persistence\BasicPersistence::instance($c->database());
1900 };
1901
1902 $c["bt.injector"] = function ($c) {
1903 return new \ILIAS\BackgroundTasks\Dependencies\Injector($c, new BaseDependencyMap());
1904 };
1905
1906 $c["bt.task_manager"] = function ($c) use ($sync) {
1907 if ($sync == 'sync') {
1908 return new \ILIAS\BackgroundTasks\Implementation\TaskManager\SyncTaskManager($c["bt.persistence"]);
1909 } elseif ($sync == 'async') {
1910 return new \ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager($c["bt.persistence"]);
1911 } else {
1912 throw new ilException("The supported Background Task Managers are sync and async. $sync given.");
1913 }
1914 };
1915 }
1916
1917 private static function initInjector(\ILIAS\DI\Container $c): void
1918 {
1919 $c["di.dependency_map"] = function ($c) {
1920 return new \ILIAS\BackgroundTasks\Dependencies\DependencyMap\BaseDependencyMap();
1921 };
1922
1923 $c["di.injector"] = function ($c) {
1924 return new \ILIAS\BackgroundTasks\Dependencies\Injector($c, $c["di.dependency_map"]);
1925 };
1926 }
1927
1928 private static function initKioskMode(\ILIAS\DI\Container $c): void
1929 {
1930 $c["service.kiosk_mode"] = function ($c) {
1931 return new ilKioskModeService(
1932 $c['ilCtrl'],
1933 $c['lng'],
1934 $c['ilAccess'],
1935 $c['objDefinition']
1936 );
1937 };
1938 }
1939
1940 private static function initLearningObjectMetadata(\ILIAS\DI\Container $c): void
1941 {
1942 $c['learning_object_metadata'] = function ($c) {
1943 return new \ILIAS\MetaData\Services\Services($c);
1944 };
1945 }
1946}
$cookie_path
Definition: index.php:29
const IL_COOKIE_PATH(isset($_GET['client_id']))
Definition: index.php:47
static orderBy(string $orderBy, string $orderDirection='ASC')
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
Class SuperGlobalDropInReplacement This Class wraps SuperGlobals such as $_GET and $_POST to prevent ...
static init(Container $c)
Definition: Init.php:36
This HelpTextRetriever simply echo the purpose and the topics for debugging and development purpose.
Definition: Echoing.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class InitCtrlService wraps the initialization of ilCtrl.
Responsible for loading the HTTP Service into the dependency injection container of ILIAS.
Responsible for loading the Resource Storage into the dependency injection container of ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const int CONTEXT_HTTP
HTTP Auth used for WebDAV and CalDAV If a special handling for WebDAV or CalDAV is required overwrite...
static getInstance(ilLogger $logger)
static isAuthenticationForced()
static handleForcedAuthentication()
const CONTEXT_WEBDAV
const CONTEXT_SHIBBOLETH
const CONTEXT_APACHE_SSO
static supportsRedirects()
Are redirects supported?
static hasUser()
Based on user authentication?
const CONTEXT_SAML
static supportsPersistentSessions()
Check if context supports persistent session handling.
static getType()
Get context type.
static hasHTML()
Has HTML output.
static usesHTTP()
Uses HTTP aka browser.
const CONTEXT_LTI_PROVIDER
static initClient()
Init client.
const CONTEXT_SOAP
const CONTEXT_WAC
static getWrapper(string $a_type)
Base class for ILIAS Exception handling.
Class ilFileServicesFilenameSanitizer.
This describes a facility that the UI framework can use to retrieve some help text.
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
ILIAS Initialisation Utility Class perform basic setup: init database handler, load configuration fil...
static initDatabase()
initialise database object $ilDB
static initHTTPServices(\ILIAS\DI\Container $container)
static goToLogin()
go to login
static initILIAS()
ilias initialisation
static initLocale()
Init Locale.
static removeUnsafeCharacters()
Remove unsafe characters from GET.
static requireCommonIncludes()
get common include code files
static initClientIniFile()
This method provides a global instance of class ilIniFile for the client.ini.php file in variable $il...
static initSession()
Init auth session.
static initClient()
Init client-based objects (level 1)
static initCore()
Init core objects (level 0)
static recursivelyRemoveUnsafeCharacters($var)
static translateMessage(string $a_message_id, ?array $a_message_static=null)
Translate message if possible.
static applyPluginManipulationsToUiFramework(\ILIAS\DI\Container $c)
static handleErrorReporting()
Set error reporting level.
static initFileUploadService(\ILIAS\DI\Container $dic)
Initializes the file upload service.
static initLegalDocuments(Container $c)
static initComponentService(\ILIAS\DI\Container $container)
static initLearningObjectMetadata(\ILIAS\DI\Container $c)
static determineClient()
This method determines the current client and sets the constant CLIENT_ID.
static initHTML()
init HTML output (level 3)
static initLog()
Init log instance.
static initAvatar(\ILIAS\DI\Container $c)
static goToPublicSection()
go to public section
static resumeUserSession()
Resume an existing user session.
static setSessionHandler()
set session handler to db Used in Soap
static handleDevMode()
Prepare developer tools.
static initUser()
Init user / authentification (level 2)
static initKioskMode(\ILIAS\DI\Container $c)
static initGlobal(string $a_name, $a_class, ?string $a_source_file=null, ?bool $destroy_existing=false)
static initBackgroundTasks(\ILIAS\DI\Container $c)
static initInjector(\ILIAS\DI\Container $c)
static setSessionCookieParams()
set session cookie params
static abortAndDie(string $a_message)
static blockedAuthentication(string $a_current_script)
Block authentication based on current request.
static initSettings()
initialise $ilSettings object and define constants Used in Soap
static initGlobalScreen(\ILIAS\DI\Container $c)
static redirectToStartingPage(string $target='')
static initUploadPolicies(\ILIAS\DI\Container $dic)
static initAccessibilityControlConcept(\ILIAS\DI\Container $c)
static redirect(string $a_target, string $a_message_id='', ?array $a_message_static=null)
Redirects to target url if context supports it.
static getClientIdTransformation()
Refinery is not initialized early enough to provide a transformation to be used with the \ILIAS\HTTP ...
static handleMaintenanceMode()
handle maintenance mode
static initAccessHandling()
$ilAccess and $rbac... initialisation
static initUserAccount()
Init user with current account id.
static initCustomObjectIcons(\ILIAS\DI\Container $c)
static initCron(\ILIAS\DI\Container $c)
static initIliasIniFile()
This method provides a global instance of class ilIniFile for the ilias.ini.php file in variable $ilI...
static initStyle()
provide $styleDefinition object
Central entry point for users of the service.
language handling
static getFallbackInstance()
Builds a global default language instance.
static getGlobalInstance()
Builds the global language object.
static getRootLogger()
The unique root logger has a fixed error level.
static getLogger(string $a_component_id)
Get component logger.
User class.
static _isAnonymous(int $usr_id)
static updateAccess(ilObjUser $user)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(string $a_session_id)
const int SESSION_CLOSE_LOGIN
const int SESSION_CLOSE_PUBLIC
static setClosingContext(int $a_context)
set closing context (for statistics)
const int SESSION_CLOSE_EXPIRE
static _destroy($a_session_id, ?int $a_closing_context=null, $a_expired_at=null)
Destroy session.
static initDefaultTimeZone(ilIniFile $ini)
Initialize default timezone from system settings.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static getStartingPointAsUrl()
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
static redirect(string $a_script)
static setCookie(string $a_cookie_name, string $a_cookie_value='', bool $a_also_set_super_global=true, bool $a_set_cookie_invalid=false)
const CLIENT_ID
Definition: constants.php:41
const ILIAS_DATA_DIR
Definition: constants.php:44
const ILIAS_WEB_DIR
Definition: constants.php:45
const CLIENT_WEB_DIR
Definition: constants.php:47
const ANONYMOUS_USER_ID
Definition: constants.php:27
const ROOT_FOLDER_ID
Definition: constants.php:32
$c
Definition: deliver.php:25
const ILIAS_VERSION_NUMERIC
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
then(callable $f)
Get a new result from the callable or do nothing if this is an error.
A transformation is a function from one datatype to another.
$_GET['cmd']
Definition: lti.php:26
$_POST['cmd']
Definition: lti.php:27
$client_id
Definition: ltiauth.php:67
$log
Definition: ltiresult.php:34
$dic
Definition: ltiresult.php:33
Class HTTPServicesTest.
static http()
Fetches the global http state from ILIAS.
applyTo(Result $result)
@inheritDoc
__invoke($from)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
global $ilSetting
Definition: privfeed.php:31
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$ilErr
Definition: raiseError.php:33
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$ilIliasIniFile
Definition: server.php:37
$container
@noRector
Definition: wac.php:37
$GLOBALS["DIC"]
Definition: wac.php:54
$lang
Definition: xapiexit.php:25
$message
Definition: xapiexit.php:31
$_COOKIE[session_name()]
Definition: xapitoken.php:54
$param
Definition: xapitoken.php:46