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