ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 null,
1373 true
1374 );
1375
1376 $ilias->account = $ilUser;
1377
1378 self::initAccessHandling();
1379 }
1380
1384 public static function resumeUserSession(): void
1385 {
1386 global $DIC;
1387
1390 }
1391
1392 if (
1393 !$DIC['ilAuthSession']->isAuthenticated() ||
1394 $DIC['ilAuthSession']->isExpired()
1395 ) {
1396 if ($GLOBALS['DIC']['ilAuthSession']->isExpired()) {
1398 }
1399
1400 ilLoggerFactory::getLogger('init')->debug('Current session is invalid: ' . $GLOBALS['DIC']['ilAuthSession']->getId());
1401 $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
1402 if (self::blockedAuthentication($current_script)) {
1403 ilLoggerFactory::getLogger('init')->debug('Authentication is started in current script.');
1404 // nothing todo: authentication is done in current script
1405 return;
1406 }
1407
1408 self::handleAuthenticationFail();
1409 return;
1410 }
1411 // valid session
1412
1413 self::initUserAccount();
1414 }
1415
1419 protected static function handleAuthenticationSuccess(): void
1420 {
1424 global $ilUser;
1425
1427 }
1428
1432 protected static function handleAuthenticationFail(): void
1433 {
1434 global $DIC;
1435
1436 ilLoggerFactory::getLogger('init')->debug('Handling of failed authentication.');
1437
1438 // #10608
1439 if (
1442 throw new Exception("Authentication failed.");
1443 }
1444
1445 if (($DIC->http()->request()->getQueryParams()['cmdMode'] ?? 0) === 'asynch') {
1446 $DIC->language()->loadLanguageModule('init');
1447 $DIC->http()->saveResponse(
1448 $DIC->http()->response()
1449 ->withStatus(403)
1450 ->withBody(Streams::ofString($DIC->language()->txt('init_error_authentication_fail')))
1451 );
1452 $DIC->http()->sendResponse();
1453 $DIC->http()->close();
1454 }
1455 if (
1456 $DIC['ilAuthSession']->isExpired() &&
1457 !\ilObjUser::_isAnonymous($DIC['ilAuthSession']->getUserId())
1458 ) {
1459 ilLoggerFactory::getLogger('init')->debug('Expired session found -> redirect to login page');
1460 self::goToLogin();
1461 return;
1462 }
1463 if (ilPublicSectionSettings::getInstance()->isEnabledForDomain($_SERVER['SERVER_NAME']) &&
1464 $DIC->access()->checkAccessOfUser(ANONYMOUS_USER_ID, 'read', '', ROOT_FOLDER_ID)) {
1465 ilLoggerFactory::getLogger('init')->debug('Redirect to public section.');
1466 self::goToPublicSection();
1467 return;
1468 }
1469 ilLoggerFactory::getLogger('init')->debug('Redirect to login page.');
1470 self::goToLogin();
1471 }
1472
1476 protected static function initHTTPServices(\ILIAS\DI\Container $container): void
1477 {
1478 $init_http = new InitHttpServices();
1479 $init_http->init($container);
1480
1482 }
1483
1487 private static function initGlobalScreen(\ILIAS\DI\Container $c): void
1488 {
1489 $c['global_screen'] = function () use ($c) {
1490 return new Services(
1492 $c->ui(),
1493 htmlentities(str_replace([" ", ".", "-"], "_", ILIAS_VERSION_NUMERIC))
1494 );
1495 };
1496 $c->globalScreen()->tool()->context()->stack()->clear();
1497 $c->globalScreen()->tool()->context()->claim()->main();
1498 }
1499
1505 {
1506 $component_repository = $c["component.repository"];
1507 $component_factory = $c["component.factory"];
1508 foreach ($component_repository->getPlugins() as $pl) {
1509 if (!$pl->isActive()) {
1510 continue;
1511 }
1512 $plugin = $component_factory->getPlugin($pl->getId());
1513 $closure = $plugin->exchangeUIRendererAfterInitialization($c);
1514 $c->offsetUnset('ui.renderer');
1515 $c['ui.renderer'] = $closure;
1516
1517 foreach ($c->keys() as $key) {
1518 if (strpos($key, "ui.factory") === 0) {
1519 $c[$key] = $plugin->exchangeUIFactoryAfterInitialization($key, $c);
1520 }
1521 }
1522 }
1523 }
1524
1528 protected static function replaceSuperGlobals(\ILIAS\DI\Container $container): void
1529 {
1531 $client_ini = $container['ilClientIniFile'];
1532
1533 $replace_super_globals = (
1534 !$client_ini->variableExists('server', 'prevent_super_global_replacement') ||
1535 !(bool) $client_ini->readVariable('server', 'prevent_super_global_replacement')
1536 );
1537
1538 if ($replace_super_globals) {
1539 $throwOnValueAssignment = defined('DEVMODE') && DEVMODE;
1540
1541 $_GET = new SuperGlobalDropInReplacement($container['refinery'], $_GET, $throwOnValueAssignment);
1542 $_POST = new SuperGlobalDropInReplacement($container['refinery'], $_POST, $throwOnValueAssignment);
1543 $_COOKIE = new SuperGlobalDropInReplacement($container['refinery'], $_COOKIE, $throwOnValueAssignment);
1544 $_REQUEST = new SuperGlobalDropInReplacement($container['refinery'], $_REQUEST, $throwOnValueAssignment);
1545 }
1546 }
1547
1548 protected static function initComponentService(\ILIAS\DI\Container $container): void
1549 {
1550 $init = new InitComponentService();
1551 $init->init($container);
1552 }
1553
1557 protected static function initHTML(): void
1558 {
1559 global $ilUser, $DIC;
1560
1561 if (ilContext::hasUser()) {
1562 // load style definitions
1563 // use the init function with plugin hook here, too
1564 self::initStyle();
1565
1566 self::initUploadPolicies($DIC);
1567 }
1568
1569 self::applyPluginManipulationsToUiFramework($GLOBALS["DIC"]);
1570 $tpl = new ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
1571 self::initGlobal("tpl", $tpl);
1572
1573 if (ilContext::hasUser()) {
1574 $dispatcher = new \ILIAS\Init\StartupSequence\StartUpSequenceDispatcher($DIC);
1575 $dispatcher->dispatch();
1576 }
1577
1578 self::initGlobal(
1579 "ilNavigationHistory",
1580 "ilNavigationHistory",
1581 "components/ILIAS/Navigation/classes/class.ilNavigationHistory.php"
1582 );
1583
1584 self::initGlobal(
1585 "ilHelp",
1586 "ilHelpGUI",
1587 "components/ILIAS/Help/classes/class.ilHelpGUI.php"
1588 );
1589
1590 if (DEVMODE) {
1591 $DIC["help.text_retriever"] = new ILIAS\UI\Help\TextRetriever\Echoing();
1592 } else {
1593 $DIC["help.text_retriever"] = new ilHelpUITextRetriever();
1594 }
1595
1596 self::initGlobal(
1597 "ilToolbar",
1598 "ilToolbarGUI",
1599 "./components/ILIAS/UIComponent/Toolbar/classes/class.ilToolbarGUI.php"
1600 );
1601
1602 self::initGlobal(
1603 "ilLocator",
1604 "ilLocatorGUI",
1605 "./components/ILIAS/Locator/classes/class.ilLocatorGUI.php"
1606 );
1607
1608 self::initGlobal(
1609 "ilTabs",
1610 "ilTabsGUI",
1611 "./components/ILIAS/UIComponent/Tabs/classes/class.ilTabsGUI.php"
1612 );
1613
1614 if (ilContext::hasUser()) {
1615 // the next line makes it impossible to save the offset somehow in a session for
1616 // a specific table (I tried it for the user administration).
1617 // its not posssible to distinguish whether it has been set to page 1 (=offset = 0)
1618 // or not set at all (then we want the last offset, e.g. being used from a session var).
1619 // So I added the wrapping if statement. Seems to work (hopefully).
1620 // Alex April 14th 2006
1621 // @todo not replaced by refinery due to unknown sideeffects
1622 if (isset($_GET['offset']) && $_GET['offset'] != "") {
1623 $_GET['offset'] = (int) $_GET['offset']; // old code
1624 }
1625
1626 self::initGlobal("lti", "ilLTIViewGUI", "./components/ILIAS/LTIProvider/classes/class.ilLTIViewGUI.php");
1627 $GLOBALS["DIC"]["lti"]->init();
1628 self::initKioskMode($GLOBALS["DIC"]);
1629 }
1630 }
1631
1635 protected static function blockedAuthentication(string $a_current_script): bool
1636 {
1637 global $DIC;
1638
1640 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for WAC request.');
1641 return true;
1642 }
1644 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for sso request.');
1645 return true;
1646 }
1648 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for webdav request');
1649 return true;
1650 }
1652 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for shibboleth request.');
1653 return true;
1654 }
1656 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for lti provider requests.');
1657 return true;
1658 }
1660 ilLoggerFactory::getLogger('init')->debug('Blocked authentication for SAML request.');
1661 return true;
1662 }
1663 if (
1664 $a_current_script == "register.php" ||
1665 $a_current_script == "pwassist.php" ||
1666 $a_current_script == "confirmReg.php" ||
1667 $a_current_script == "il_securimage_play.php" ||
1668 $a_current_script == "il_securimage_show.php" ||
1669 $a_current_script == 'login.php'
1670 ) {
1671 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for script: ' . $a_current_script);
1672 return true;
1673 }
1674
1675 // @todo refinery undefined
1676 $requestBaseClass = strtolower((string) ($_GET['baseClass'] ?? ''));
1677 if ($requestBaseClass == strtolower(ilStartUpGUI::class)) {
1678 $requestCmdClass = strtolower((string) ($_GET['cmdClass'] ?? ''));
1679 if (
1680 $requestCmdClass == strtolower(ilAccountRegistrationGUI::class) ||
1681 $requestCmdClass == strtolower(ilPasswordAssistanceGUI::class)
1682 ) {
1683 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmdClass: ' . $requestCmdClass);
1684 return true;
1685 }
1686 $cmd = $DIC->ctrl()->getCmd();
1687
1688 if (in_array($cmd, [
1689 'showLegalDocuments',
1690 'showAccountMigration',
1691 'migrateAccount',
1692 'processCode',
1693 'showLoginPage',
1694 'showLogout',
1695 'doStandardAuthentication',
1696 'doCasAuthentication',
1697 ], true)) {
1698 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmd: ' . $cmd);
1699 return true;
1700 }
1701 }
1702
1703 $target = '';
1704 if ($DIC->http()->wrapper()->query()->has('target')) {
1705 // @todo refinery undefined
1706 $target = $_GET['target'];
1707 }
1708
1709 // #12884
1710 if (
1711 ($a_current_script == "goto.php" && $target == "impr_0") ||
1712 $requestBaseClass == strtolower(ilImprintGUI::class)
1713 ) {
1714 // @todo refinery undefind
1715 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for baseClass: ' . ($_GET['baseClass'] ?? ""));
1716 return true;
1717 }
1718
1719 if (
1720 (strtolower($requestCmdClass ?? "") === strtolower(ilAccessibilityControlConceptGUI::class))
1721 ) {
1722 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmdClass: ' . $requestCmdClass);
1723 return true;
1724 }
1725
1726 if ($a_current_script == 'goto.php' && in_array($target, array(
1727 'usr_registration',
1728 'usr_nameassist',
1729 'usr_pwassist',
1730 'usr_agreement'
1731 ))) {
1732 ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for goto target: ' . $target);
1733 return true;
1734 }
1735
1736
1737 $current_ref_id = $DIC->http()->wrapper()->query()->has('ref_id')
1738 ? $DIC->http()->wrapper()->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int())
1739 : null;
1740
1741 if (null !== $current_ref_id
1742 && $DIC->user()->getId() === 0
1743 && $DIC->access()->checkAccessOfUser(
1745 'visible',
1746 '',
1747 $current_ref_id
1748 )) {
1749 return true;
1750 }
1751
1752
1753 ilLoggerFactory::getLogger('auth')->debug('Authentication required');
1754 return false;
1755 }
1756
1760 protected static function translateMessage(string $a_message_id, ?array $a_message_static = null): string
1761 {
1762 global $ilDB, $lng, $ilSetting, $ilClientIniFile, $ilUser;
1763
1764 // current language
1765 if (!$lng) {
1766 $lang = "en";
1767 if ($ilUser) {
1768 $lang = $ilUser->getLanguage();
1769 } elseif (isset($_REQUEST["lang"])) {
1770 $lang = (string) $_REQUEST["lang"];
1771 } elseif ($ilSetting) {
1772 $lang = $ilSetting->get("language", '');
1773 } elseif ($ilClientIniFile) {
1774 $lang = $ilClientIniFile->readVariable("language", "default");
1775 }
1776 } else {
1777 $lang = $lng->getLangKey();
1778 }
1779
1780 $message = "";
1781 if ($ilDB && $a_message_id) {
1782 if (!$lng) {
1783 $lng = new ilLanguage($lang);
1784 }
1785
1786 $lng->loadLanguageModule("init");
1787 $message = $lng->txt($a_message_id);
1788 } elseif (is_array($a_message_static)) {
1789 if (!isset($a_message_static[$lang])) {
1790 $lang = "en";
1791 }
1792 $message = $a_message_static[$lang];
1793 }
1794 return $message;
1795 }
1796
1800 protected static function redirect(
1801 string $a_target,
1802 string $a_message_id = '',
1803 ?array $a_message_static = null
1804 ): void {
1805 // #12739
1806 if (defined("ILIAS_HTTP_PATH") &&
1807 !stristr($a_target, ILIAS_HTTP_PATH)) {
1808 $a_target = ILIAS_HTTP_PATH . "/" . $a_target;
1809 }
1810
1811 foreach (['ext_uid', 'soap_pw'] as $param) {
1812 if (false === strpos(
1813 $a_target,
1814 $param . '='
1815 ) && isset($GLOBALS['DIC']->http()->request()->getQueryParams()[$param])) {
1816 $a_target = \ilUtil::appendUrlParameterString($a_target, $param . '=' . \ilUtil::stripSlashes(
1817 $GLOBALS['DIC']->http()->request()->getQueryParams()[$param]
1818 ));
1819 }
1820 }
1821
1823 ilUtil::redirect($a_target);
1824 } else {
1825 $message = self::translateMessage($a_message_id, $a_message_static);
1826
1827 // user-directed linked message
1829 $link = self::translateMessage(
1830 "init_error_redirect_click",
1831 array("en" => 'Please click to continue.',
1832 "de" => 'Bitte klicken um fortzufahren.'
1833 )
1834 );
1835 $mess = $message .
1836 '<br /><a href="' . $a_target . '">' . $link . '</a>';
1837 } // plain text
1838 else {
1839 // not much we can do here
1840 $mess = $message;
1841
1842 if (!trim($mess)) {
1843 $mess = self::translateMessage(
1844 "init_error_redirect_info",
1845 array("en" => 'Redirect not supported by context.',
1846 "de" => 'Weiterleitungen werden durch Kontext nicht unterstützt.'
1847 )
1848 ) .
1849 ' (' . $a_target . ')';
1850 }
1851 }
1852
1853 self::abortAndDie($mess);
1854 }
1855 }
1856
1857 public static function redirectToStartingPage(string $target = ''): void
1858 {
1859 global $DIC;
1860
1861 // fallback, should never happen
1862 if ($DIC->user()->getId() === ANONYMOUS_USER_ID) {
1863 self::goToPublicSection();
1864 return;
1865 }
1866
1867 if (
1868 $target === '' &&
1869 $DIC->http()->wrapper()->query()->has('target')
1870 ) {
1871 $target = $DIC->http()->wrapper()->query()->retrieve(
1872 'target',
1873 $DIC->refinery()->kindlyTo()->string()
1874 );
1875 }
1876
1877 // for password change and incomplete profile
1878 // see ilDashboardGUI
1879 if ($target === '') {
1880 ilLoggerFactory::getLogger('init')->debug('Redirect to default starting page');
1881 $DIC->ctrl()->redirectToURL(ilUserUtil::getStartingPointAsUrl());
1882 } else {
1883 ilLoggerFactory::getLogger('init')->debug('Redirect to target: ' . $target);
1884 $DIC->ctrl()->redirectToURL("goto.php?target=" . $target);
1885 }
1886 }
1887
1888 private static function initBackgroundTasks(\ILIAS\DI\Container $c): void
1889 {
1890 global $ilIliasIniFile;
1891
1892 $n_of_tasks = $ilIliasIniFile->readVariable("background_tasks", "number_of_concurrent_tasks");
1893 $sync = $ilIliasIniFile->readVariable("background_tasks", "concurrency");
1894
1895 $n_of_tasks = $n_of_tasks ?: 5;
1896 $sync = $sync ?: 'sync'; // The default value is sync.
1897
1898 $c["bt.task_factory"] = function ($c) {
1899 return new \ILIAS\BackgroundTasks\Implementation\Tasks\BasicTaskFactory($c["di.injector"]);
1900 };
1901
1902 $c["bt.persistence"] = function ($c) {
1903 return \ILIAS\BackgroundTasks\Implementation\Persistence\BasicPersistence::instance($c->database());
1904 };
1905
1906 $c["bt.injector"] = function ($c) {
1907 return new \ILIAS\BackgroundTasks\Dependencies\Injector($c, new BaseDependencyMap());
1908 };
1909
1910 $c["bt.task_manager"] = function ($c) use ($sync) {
1911 if ($sync == 'sync') {
1912 return new \ILIAS\BackgroundTasks\Implementation\TaskManager\SyncTaskManager($c["bt.persistence"]);
1913 } elseif ($sync == 'async') {
1914 return new \ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager($c["bt.persistence"]);
1915 } else {
1916 throw new ilException("The supported Background Task Managers are sync and async. $sync given.");
1917 }
1918 };
1919 }
1920
1921 private static function initInjector(\ILIAS\DI\Container $c): void
1922 {
1923 $c["di.dependency_map"] = function ($c) {
1924 return new \ILIAS\BackgroundTasks\Dependencies\DependencyMap\BaseDependencyMap();
1925 };
1926
1927 $c["di.injector"] = function ($c) {
1928 return new \ILIAS\BackgroundTasks\Dependencies\Injector($c, $c["di.dependency_map"]);
1929 };
1930 }
1931
1932 private static function initKioskMode(\ILIAS\DI\Container $c): void
1933 {
1934 $c["service.kiosk_mode"] = function ($c) {
1935 return new ilKioskModeService(
1936 $c['ilCtrl'],
1937 $c['lng'],
1938 $c['ilAccess'],
1939 $c['objDefinition']
1940 );
1941 };
1942 }
1943
1944 private static function initLearningObjectMetadata(\ILIAS\DI\Container $c): void
1945 {
1946 $c['learning_object_metadata'] = function ($c) {
1947 return new \ILIAS\MetaData\Services\Services($c);
1948 };
1949 }
1950}
$cookie_path
Definition: index.php:29
const IL_COOKIE_PATH
Definition: index.php:48
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
$_COOKIE[session_name()]
Definition: xapitoken.php:52
$param
Definition: xapitoken.php:44