ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilInitialisation.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 // TODO:
11 
12 require_once("libs/composer/vendor/autoload.php");
13 
14 // needed for slow queries, etc.
15 if (!isset($GLOBALS['ilGlobalStartTime']) || !$GLOBALS['ilGlobalStartTime']) {
16  $GLOBALS['ilGlobalStartTime'] = microtime();
17 }
18 
19 include_once "Services/Context/classes/class.ilContext.php";
20 
37 {
41  protected static function removeUnsafeCharacters()
42  {
43  // Remove unsafe characters from GET parameters.
44  // We do not need this characters in any case, so it is
45  // feasible to filter them everytime. POST parameters
46  // need attention through ilUtil::stripSlashes() and similar functions)
47  $_GET = self::recursivelyRemoveUnsafeCharacters($_GET);
48  }
49 
50  protected static function recursivelyRemoveUnsafeCharacters($var)
51  {
52  if (is_array($var)) {
53  $mod = [];
54  foreach ($var as $k => $v) {
55  $k = self::recursivelyRemoveUnsafeCharacters($k);
56  $mod[$k] = self::recursivelyRemoveUnsafeCharacters($v);
57  }
58  return $mod;
59  }
60  return strip_tags(
61  str_replace(
62  array("\x00", "\n", "\r", "\\", "'", '"', "\x1a"),
63  "",
64  $var
65  )
66  );
67  }
68 
72  protected static function requireCommonIncludes()
73  {
74  // ilTemplate
76  require_once "./Services/UICore/classes/class.ilTemplate.php";
77  }
78 
79  // really always required?
80  require_once "./Services/Utilities/classes/class.ilUtil.php";
81  require_once "./Services/Calendar/classes/class.ilDatePresentation.php";
82  require_once "include/inc.ilias_version.php";
83 
84  include_once './Services/Authentication/classes/class.ilAuthUtils.php';
85 
86  self::initGlobal("ilBench", "ilBenchmark", "./Services/Utilities/classes/class.ilBenchmark.php");
87  }
88 
94  protected static function includePhp5Compliance()
95  {
96  include_once 'Services/Authentication/classes/class.ilAuthFactory.php';
98  require_once("include/inc.xml5compliance.php");
99  }
100  require_once("include/inc.xsl5compliance.php");
101  }
102 
110  protected static function initIliasIniFile()
111  {
112  require_once("./Services/Init/classes/class.ilIniFile.php");
113  $ilIliasIniFile = new ilIniFile("./ilias.ini.php");
114  $ilIliasIniFile->read();
115  self::initGlobal('ilIliasIniFile', $ilIliasIniFile);
116 
117  // initialize constants
118  define("ILIAS_DATA_DIR", $ilIliasIniFile->readVariable("clients", "datadir"));
119  define("ILIAS_WEB_DIR", $ilIliasIniFile->readVariable("clients", "path"));
120  define("ILIAS_ABSOLUTE_PATH", $ilIliasIniFile->readVariable('server', 'absolute_path'));
121 
122  // logging
123  define("ILIAS_LOG_DIR", $ilIliasIniFile->readVariable("log", "path"));
124  define("ILIAS_LOG_FILE", $ilIliasIniFile->readVariable("log", "file"));
125  define("ILIAS_LOG_ENABLED", $ilIliasIniFile->readVariable("log", "enabled"));
126  define("ILIAS_LOG_LEVEL", $ilIliasIniFile->readVariable("log", "level"));
127  define("SLOW_REQUEST_TIME", $ilIliasIniFile->readVariable("log", "slow_request_time"));
128 
129  // read path + command for third party tools from ilias.ini
130  define("PATH_TO_CONVERT", $ilIliasIniFile->readVariable("tools", "convert"));
131  define("PATH_TO_FFMPEG", $ilIliasIniFile->readVariable("tools", "ffmpeg"));
132  define("PATH_TO_ZIP", $ilIliasIniFile->readVariable("tools", "zip"));
133  define("PATH_TO_MKISOFS", $ilIliasIniFile->readVariable("tools", "mkisofs"));
134  define("PATH_TO_UNZIP", $ilIliasIniFile->readVariable("tools", "unzip"));
135  define("PATH_TO_GHOSTSCRIPT", $ilIliasIniFile->readVariable("tools", "ghostscript"));
136  define("PATH_TO_JAVA", $ilIliasIniFile->readVariable("tools", "java"));
137  define("URL_TO_LATEX", $ilIliasIniFile->readVariable("tools", "latex"));
138  define("PATH_TO_FOP", $ilIliasIniFile->readVariable("tools", "fop"));
139  define("PATH_TO_LESSC", $ilIliasIniFile->readVariable("tools", "lessc"));
140  define("PATH_TO_PHANTOMJS", $ilIliasIniFile->readVariable("tools", "phantomjs"));
141 
142  // read virus scanner settings
143  switch ($ilIliasIniFile->readVariable("tools", "vscantype")) {
144  case "sophos":
145  define("IL_VIRUS_SCANNER", "Sophos");
146  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
147  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
148  break;
149 
150  case "antivir":
151  define("IL_VIRUS_SCANNER", "AntiVir");
152  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
153  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
154  break;
155 
156  case "clamav":
157  define("IL_VIRUS_SCANNER", "ClamAV");
158  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
159  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
160  break;
161 
162  default:
163  define("IL_VIRUS_SCANNER", "None");
164  break;
165  }
166 
167  include_once './Services/Calendar/classes/class.ilTimeZone.php';
169  define("IL_TIMEZONE", $tz);
170  }
171 
183  public static function bootstrapFilesystems()
184  {
185  global $DIC;
186 
187  $DIC['filesystem.security.sanitizing.filename'] = function ($c) {
188  return new FilenameSanitizerImpl();
189  };
190 
191  $DIC['filesystem.factory'] = function ($c) {
192  return new \ILIAS\Filesystem\Provider\DelegatingFilesystemFactory($c['filesystem.security.sanitizing.filename']);
193  };
194 
195  $DIC['filesystem.web'] = function ($c) {
196  //web
197 
201  $delegatingFactory = $c['filesystem.factory'];
202  $webConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_ABSOLUTE_PATH . '/' . ILIAS_WEB_DIR . '/' . CLIENT_ID);
203  return $delegatingFactory->getLocal($webConfiguration);
204  };
205 
206  $DIC['filesystem.storage'] = function ($c) {
207  //storage
208 
212  $delegatingFactory = $c['filesystem.factory'];
213  $storageConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_DATA_DIR . '/' . CLIENT_ID);
214  return $delegatingFactory->getLocal($storageConfiguration);
215  };
216 
217  $DIC['filesystem.temp'] = function ($c) {
218  //temp
219 
223  $delegatingFactory = $c['filesystem.factory'];
224  $tempConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_DATA_DIR . '/' . CLIENT_ID . '/temp');
225  return $delegatingFactory->getLocal($tempConfiguration);
226  };
227 
228  $DIC['filesystem.customizing'] = function ($c) {
229  //customizing
230 
234  $delegatingFactory = $c['filesystem.factory'];
235  $customizingConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_ABSOLUTE_PATH . '/' . 'Customizing');
236  return $delegatingFactory->getLocal($customizingConfiguration);
237  };
238 
239  $DIC['filesystem.libs'] = function ($c) {
240  //customizing
241 
245  $delegatingFactory = $c['filesystem.factory'];
246  $customizingConfiguration = new \ILIAS\Filesystem\Provider\Configuration\LocalConfig(ILIAS_ABSOLUTE_PATH . '/' . 'libs');
247  return $delegatingFactory->getLocal($customizingConfiguration, true);
248  };
249 
250  $DIC['filesystem'] = function ($c) {
251  return new \ILIAS\Filesystem\FilesystemsImpl(
252  $c['filesystem.storage'],
253  $c['filesystem.web'],
254  $c['filesystem.temp'],
255  $c['filesystem.customizing'],
256  $c['filesystem.libs']
257  );
258  };
259  }
260 
261 
270  public static function initFileUploadService(\ILIAS\DI\Container $dic)
271  {
272  $dic['upload.processor-manager'] = function ($c) {
273  return new \ILIAS\FileUpload\Processor\PreProcessorManagerImpl();
274  };
275 
276  $dic['upload'] = function ($c) {
277  $fileUploadImpl = new \ILIAS\FileUpload\FileUploadImpl($c['upload.processor-manager'], $c['filesystem'], $c['http']);
278  if (IL_VIRUS_SCANNER != "None") {
279  $fileUploadImpl->register(new \ILIAS\FileUpload\Processor\VirusScannerPreProcessor(ilVirusScannerFactory::_getInstance()));
280  }
281 
282  return $fileUploadImpl;
283  };
284  }
285 
289  protected static function buildHTTPPath()
290  {
291  include_once './Services/Http/classes/class.ilHTTPS.php';
292  $https = new ilHTTPS();
293 
294  if ($https->isDetected()) {
295  $protocol = 'https://';
296  } else {
297  $protocol = 'http://';
298  }
299  $host = $_SERVER['HTTP_HOST'];
300 
301  $rq_uri = strip_tags($_SERVER['REQUEST_URI']);
302 
303  // security fix: this failed, if the URI contained "?" and following "/"
304  // -> we remove everything after "?"
305  if (is_int($pos = strpos($rq_uri, "?"))) {
306  $rq_uri = substr($rq_uri, 0, $pos);
307  }
308 
309  if (!defined('ILIAS_MODULE')) {
310  $path = pathinfo($rq_uri);
311  if (!$path['extension']) {
312  $uri = $rq_uri;
313  } else {
314  $uri = dirname($rq_uri);
315  }
316  } else {
317  // if in module remove module name from HTTP_PATH
318  $path = dirname($rq_uri);
319 
320  // dirname cuts the last directory from a directory path e.g content/classes return content
321 
323 
324  $dirs = explode('/', $module);
325  $uri = $path;
326  foreach ($dirs as $dir) {
327  $uri = dirname($uri);
328  }
329  }
331  return define('ILIAS_HTTP_PATH', ilUtil::removeTrailingPathSeparators(dirname($protocol . $host . $uri)));
332  }
333  return define('ILIAS_HTTP_PATH', ilUtil::removeTrailingPathSeparators($protocol . $host . $uri));
334  }
335 
340  protected static function determineClient()
341  {
342  global $ilIliasIniFile;
343 
344  // check whether ini file object exists
345  if (!is_object($ilIliasIniFile)) {
346  self::abortAndDie('Fatal Error: ilInitialisation::determineClient called without initialisation of ILIAS ini file object.');
347  }
348 
349  if (isset($_GET['client_id']) && strlen($_GET['client_id']) > 0) {
350  $_GET['client_id'] = \ilUtil::getClientIdByString((string) $_GET['client_id'])->toString();
351  if (!defined('IL_PHPUNIT_TEST')) {
353  ilUtil::setCookie('ilClientId', $_GET['client_id']);
354  }
355  }
356  } elseif (!isset($_COOKIE['ilClientId'])) {
357  ilUtil::setCookie('ilClientId', $ilIliasIniFile->readVariable('clients', 'default'));
358  }
359 
360  if (!defined('IL_PHPUNIT_TEST') && ilContext::supportsPersistentSessions()) {
361  $clientId = $_COOKIE['ilClientId'];
362  } else {
363  $clientId = $_GET['client_id'];
364  }
365 
366  define('CLIENT_ID', \ilUtil::getClientIdByString((string) $clientId)->toString());
367  }
368 
381  protected static function initClientIniFile()
382  {
383  global $ilIliasIniFile;
384 
385  // check whether ILIAS_WEB_DIR is set.
386  if (ILIAS_WEB_DIR == "") {
387  self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without ILIAS_WEB_DIR.");
388  }
389 
390  // check whether CLIENT_ID is set.
391  if (CLIENT_ID == "") {
392  self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without CLIENT_ID.");
393  }
394 
395  $ini_file = "./" . ILIAS_WEB_DIR . "/" . CLIENT_ID . "/client.ini.php";
396 
397  // get settings from ini file
398  $ilClientIniFile = new ilIniFile($ini_file);
399  $ilClientIniFile->read();
400 
401  // invalid client id / client ini
402  if ($ilClientIniFile->ERROR != "") {
403  $c = $_COOKIE["ilClientId"];
404  $default_client = $ilIliasIniFile->readVariable("clients", "default");
405  ilUtil::setCookie("ilClientId", $default_client);
406  if (CLIENT_ID != "" && CLIENT_ID != $default_client) {
407  $mess = array("en" => "Client does not exist.",
408  "de" => "Mandant ist ungültig.");
409  self::redirect("index.php?client_id=" . $default_client, null, $mess);
410  } else {
411  self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile initializing client ini file abborted with: " . $ilClientIniFile->ERROR);
412  }
413  }
414 
415  self::initGlobal("ilClientIniFile", $ilClientIniFile);
416 
417  // set constants
418  define("SESSION_REMINDER_LEADTIME", 30);
419  define("DEBUG", $ilClientIniFile->readVariable("system", "DEBUG"));
420  define("DEVMODE", $ilClientIniFile->readVariable("system", "DEVMODE"));
421  define("SHOWNOTICES", $ilClientIniFile->readVariable("system", "SHOWNOTICES"));
422  define("DEBUGTOOLS", $ilClientIniFile->readVariable("system", "DEBUGTOOLS"));
423  define("ROOT_FOLDER_ID", $ilClientIniFile->readVariable('system', 'ROOT_FOLDER_ID'));
424  define("SYSTEM_FOLDER_ID", $ilClientIniFile->readVariable('system', 'SYSTEM_FOLDER_ID'));
425  define("ROLE_FOLDER_ID", $ilClientIniFile->readVariable('system', 'ROLE_FOLDER_ID'));
426  define("MAIL_SETTINGS_ID", $ilClientIniFile->readVariable('system', 'MAIL_SETTINGS_ID'));
427  $error_handler = $ilClientIniFile->readVariable('system', 'ERROR_HANDLER');
428  define("ERROR_HANDLER", $error_handler ? $error_handler : "PRETTY_PAGE");
429 
430  // this is for the online help installation, which sets OH_REF_ID to the
431  // ref id of the online module
432  define("OH_REF_ID", $ilClientIniFile->readVariable("system", "OH_REF_ID"));
433 
434  define("SYSTEM_MAIL_ADDRESS", $ilClientIniFile->readVariable('system', 'MAIL_SENT_ADDRESS')); // Change SS
435  define("MAIL_REPLY_WARNING", $ilClientIniFile->readVariable('system', 'MAIL_REPLY_WARNING')); // Change SS
436 
437  // see ilObject::TITLE_LENGTH, ilObject::DESC_LENGTH
438  // define ("MAXLENGTH_OBJ_TITLE",125);#$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_TITLE'));
439  // define ("MAXLENGTH_OBJ_DESC",$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_DESC'));
440 
441  define("CLIENT_DATA_DIR", ILIAS_DATA_DIR . "/" . CLIENT_ID);
442  define("CLIENT_WEB_DIR", ILIAS_ABSOLUTE_PATH . "/" . ILIAS_WEB_DIR . "/" . CLIENT_ID);
443  define("CLIENT_NAME", $ilClientIniFile->readVariable('client', 'name')); // Change SS
444 
445  $val = $ilClientIniFile->readVariable("db", "type");
446  if ($val == "") {
447  define("IL_DB_TYPE", "mysql");
448  } else {
449  define("IL_DB_TYPE", $val);
450  }
451 
452  $ilGlobalCacheSettings = new ilGlobalCacheSettings();
453  $ilGlobalCacheSettings->readFromIniFile($ilClientIniFile);
454  ilGlobalCache::setup($ilGlobalCacheSettings);
455 
456  return true;
457  }
458 
462  protected static function handleMaintenanceMode()
463  {
464  global $ilClientIniFile;
465 
466  if (!$ilClientIniFile->readVariable("client", "access")) {
467  $mess = array("en" => "The server is not available due to maintenance." .
468  " We apologise for any inconvenience.",
469  "de" => "Der Server ist aufgrund von Wartungsarbeiten nicht verfügbar." .
470  " Wir bitten um Verständnis.");
471  $mess_id = "init_error_maintenance";
472 
473  if (ilContext::hasHTML() && is_file("./maintenance.html")) {
474  self::redirect("./maintenance.html", $mess_id, $mess);
475  } else {
476  $mess = self::translateMessage($mess_id, $mess);
477  self::abortAndDie($mess);
478  }
479  }
480  }
481 
486  protected static function initDatabase()
487  {
488  // build dsn of database connection and connect
489  require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
490  $ilDB = ilDBWrapperFactory::getWrapper(IL_DB_TYPE);
491  $ilDB->initFromIniFile();
492  $ilDB->connect();
493 
494  self::initGlobal("ilDB", $ilDB);
495  }
496 
502  public static function setSessionHandler()
503  {
504  if (ini_get('session.save_handler') != 'user' && version_compare(PHP_VERSION, '7.2.0', '<')) {
505  ini_set("session.save_handler", "user");
506  }
507 
508  require_once "Services/Authentication/classes/class.ilSessionDBHandler.php";
509  $db_session_handler = new ilSessionDBHandler();
510  if (!$db_session_handler->setSaveHandler()) {
511  self::abortAndDie("Please turn off Safe mode OR set session.save_handler to \"user\" in your php.ini");
512  }
513 
514  // Do not accept external session ids
515  if (!ilSession::_exists(session_id()) && !defined('IL_PHPUNIT_TEST')) {
516  // php7-todo, correct-with-php5-removal : alex, 1.3.2016: added if, please check
517  if (function_exists("session_status") && session_status() == PHP_SESSION_ACTIVE) {
518  session_regenerate_id();
519  }
520  }
521  }
522 
526  protected static function setCookieConstants()
527  {
528  include_once 'Services/Authentication/classes/class.ilAuthFactory.php';
530  $cookie_path = '/';
531  } elseif ($GLOBALS['COOKIE_PATH']) {
532  // use a predefined cookie path from WebAccessChecker
533  $cookie_path = $GLOBALS['COOKIE_PATH'];
534  } else {
535  $cookie_path = dirname($_SERVER['PHP_SELF']);
536  }
537 
538  /* if ilias is called directly within the docroot $cookie_path
539  is set to '/' expecting on servers running under windows..
540  here it is set to '\'.
541  in both cases a further '/' won't be appended due to the following regex
542  */
543  $cookie_path .= (!preg_match("/[\/|\\\\]$/", $cookie_path)) ? "/" : "";
544 
545  if ($cookie_path == "\\") {
546  $cookie_path = '/';
547  }
548 
549  define('IL_COOKIE_HTTPONLY', true); // Default Value
550  define('IL_COOKIE_EXPIRE', 0);
551  define('IL_COOKIE_PATH', $cookie_path);
552  define('IL_COOKIE_DOMAIN', '');
553  }
554 
558  protected static function setSessionCookieParams()
559  {
560  global $ilSetting;
561 
562  if (!defined('IL_COOKIE_SECURE')) {
563  // If this code is executed, we can assume that \ilHTTPS::enableSecureCookies was NOT called before
564  // \ilHTTPS::enableSecureCookies already executes session_set_cookie_params()
565 
566  include_once './Services/Http/classes/class.ilHTTPS.php';
567  $cookie_secure = !$ilSetting->get('https', 0) && ilHTTPS::getInstance()->isDetected();
568  define('IL_COOKIE_SECURE', $cookie_secure); // Default Value
569 
570  session_set_cookie_params(
571  IL_COOKIE_EXPIRE,
573  IL_COOKIE_DOMAIN,
574  IL_COOKIE_SECURE,
575  IL_COOKIE_HTTPONLY
576  );
577  }
578  }
579 
583  protected static function initMail(\ILIAS\DI\Container $c)
584  {
585  $c["mail.mime.transport.factory"] = function ($c) {
586  require_once 'Services/Mail/classes/Mime/Transport/class.ilMailMimeTransportFactory.php';
587  return new ilMailMimeTransportFactory($c["ilSetting"]);
588  };
589  $c["mail.mime.sender.factory"] = function ($c) {
590  require_once 'Services/Mail/classes/Mime/Sender/class.ilMailMimeSenderFactory.php';
591  return new ilMailMimeSenderFactory($c["ilSetting"]);
592  };
593  }
594 
598  protected static function initAvatar(\ILIAS\DI\Container $c)
599  {
600  $c["user.avatar.factory"] = function ($c) {
601  require_once 'Services/User/Avatar/classes/class.ilUserAvatarFactory.php';
602  return new ilUserAvatarFactory($c);
603  };
604  }
605 
611  protected static function initSettings()
612  {
613  global $ilSetting;
614 
615  self::initGlobal(
616  "ilSetting",
617  "ilSetting",
618  "Services/Administration/classes/class.ilSetting.php"
619  );
620 
621  // check correct setup
622  if (!$ilSetting->get("setup_ok")) {
623  self::abortAndDie("Setup is not completed. Please run setup routine again.");
624  }
625 
626  // set anonymous user & role id and system role id
627  define("ANONYMOUS_USER_ID", $ilSetting->get("anonymous_user_id"));
628  define("ANONYMOUS_ROLE_ID", $ilSetting->get("anonymous_role_id"));
629  define("SYSTEM_USER_ID", $ilSetting->get("system_user_id"));
630  define("SYSTEM_ROLE_ID", $ilSetting->get("system_role_id"));
631  define("USER_FOLDER_ID", 7);
632 
633  // recovery folder
634  define("RECOVERY_FOLDER_ID", $ilSetting->get("recovery_folder_id"));
635 
636  // installation id
637  define("IL_INST_ID", $ilSetting->get("inst_id", 0));
638 
639  // define default suffix replacements
640  define("SUFFIX_REPL_DEFAULT", "php,php3,php4,inc,lang,phtml,htaccess");
641  define("SUFFIX_REPL_ADDITIONAL", $ilSetting->get("suffix_repl_additional"));
642 
643  if (ilContext::usesHTTP()) {
644  self::buildHTTPPath();
645  }
646  }
647 
651  protected static function initStyle()
652  {
653  global $styleDefinition, $ilPluginAdmin;
654 
655  // load style definitions
656  self::initGlobal(
657  "styleDefinition",
658  "ilStyleDefinition",
659  "./Services/Style/System/classes/class.ilStyleDefinition.php"
660  );
661 
662  // add user interface hook for style initialisation
663  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
664  foreach ($pl_names as $pl) {
665  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
666  $gui_class = $ui_plugin->getUIClassInstance();
667  $gui_class->modifyGUI("Services/Init", "init_style", array("styleDefinition" => $styleDefinition));
668  }
669  }
670 
674  public static function initUserAccount()
675  {
679  global $ilUser;
680 
681  $uid = $GLOBALS['DIC']['ilAuthSession']->getUserId();
682  if ($uid) {
683  $ilUser->setId($uid);
684  $ilUser->read();
685 
686  // init console log handler
687  include_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
688  ilLoggerFactory::getInstance()->initUser($ilUser->getLogin());
689  \ilOnlineTracking::updateAccess($ilUser);
690  } else {
691  if (is_object($GLOBALS['ilLog'])) {
692  $GLOBALS['ilLog']->logStack();
693  }
694  self::abortAndDie("Init user account failed");
695  }
696  }
697 
701  protected static function initLocale()
702  {
703  global $ilSetting;
704 
705  if (trim($ilSetting->get("locale") != "")) {
706  $larr = explode(",", trim($ilSetting->get("locale")));
707  $ls = array();
708  $first = $larr[0];
709  foreach ($larr as $l) {
710  if (trim($l) != "") {
711  $ls[] = $l;
712  }
713  }
714  if (count($ls) > 0) {
715  setlocale(LC_ALL, $ls);
716 
717  // #15347 - making sure that floats are not changed
718  setlocale(LC_NUMERIC, "C");
719 
720  if (class_exists("Collator")) {
721  $GLOBALS["ilCollator"] = new Collator($first);
722  $GLOBALS["DIC"]["ilCollator"] = function ($c) {
723  return $GLOBALS["ilCollator"];
724  };
725  }
726  }
727  }
728  }
729 
735  public static function goToPublicSection()
736  {
737  global $ilAuth;
738 
739  if (ANONYMOUS_USER_ID == "") {
740  self::abortAndDie("Public Section enabled, but no Anonymous user found.");
741  }
742 
743  $session_destroyed = false;
744  if ($GLOBALS['DIC']['ilAuthSession']->isExpired()) {
745  $session_destroyed = true;
747  }
748  if (!$GLOBALS['DIC']['ilAuthSession']->isAuthenticated()) {
749  $session_destroyed = true;
751  }
752 
753  if ($session_destroyed) {
754  $GLOBALS['DIC']['ilAuthSession']->setAuthenticated(true, ANONYMOUS_USER_ID);
755  }
756 
757  self::initUserAccount();
758 
759  // if target given, try to go there
760  if (strlen($_GET["target"])) {
761  // when we are already "inside" goto.php no redirect is needed
762  $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
763  if ($current_script == "goto.php") {
764  return;
765  }
766  // goto will check if target is accessible or redirect to login
767  self::redirect("goto.php?target=" . $_GET["target"]);
768  }
769 
770  // check access of root folder otherwise redirect to login
771  #if(!$GLOBALS['DIC']->rbac()->system()->checkAccess('read', ROOT_FOLDER_ID))
772  #{
773  # return self::goToLogin();
774  #}
775 
776  // we do not know if ref_id of request is accesible, so redirecting to root
777  $_GET["ref_id"] = ROOT_FOLDER_ID;
778  $_GET["cmd"] = "frameset";
779  self::redirect(
780  "ilias.php?baseClass=ilrepositorygui&reloadpublic=1&cmd=" .
781  $_GET["cmd"] . "&ref_id=" . $_GET["ref_id"]
782  );
783  }
784 
790  protected static function goToLogin()
791  {
792  ilLoggerFactory::getLogger('init')->debug('Redirecting to login page.');
793 
794  if ($GLOBALS['DIC']['ilAuthSession']->isExpired()) {
796  }
797  if (!$GLOBALS['DIC']['ilAuthSession']->isAuthenticated()) {
799  }
800 
801  $script = "login.php?target=" . $_GET["target"] . "&client_id=" . $_COOKIE["ilClientId"] .
802  "&auth_stat=" . $a_auth_stat;
803 
804  self::redirect(
805  $script,
806  "init_error_authentication_fail",
807  array(
808  "en" => "Authentication failed.",
809  "de" => "Authentifizierung fehlgeschlagen.")
810  );
811  }
812 
816  protected static function initLanguage($a_use_user_language = true)
817  {
818  global $DIC;
819 
823  global $rbacsystem;
824 
825  require_once 'Services/Language/classes/class.ilLanguage.php';
826 
827  if ($a_use_user_language) {
828  if ($DIC->offsetExists('lng')) {
829  $DIC->offsetUnset('lng');
830  }
831  self::initGlobal('lng', ilLanguage::getGlobalInstance());
832  } else {
833  self::initGlobal('lng', ilLanguage::getFallbackInstance());
834  }
835  if (is_object($rbacsystem)) {
836  $rbacsystem->initMemberView();
837  }
838  }
839 
843  protected static function initAccessHandling()
844  {
845  self::initGlobal(
846  "rbacreview",
847  "ilRbacReview",
848  "./Services/AccessControl/classes/class.ilRbacReview.php"
849  );
850 
851  require_once "./Services/AccessControl/classes/class.ilRbacSystem.php";
852  $rbacsystem = ilRbacSystem::getInstance();
853  self::initGlobal("rbacsystem", $rbacsystem);
854 
855  self::initGlobal(
856  "rbacadmin",
857  "ilRbacAdmin",
858  "./Services/AccessControl/classes/class.ilRbacAdmin.php"
859  );
860 
861  self::initGlobal(
862  "ilAccess",
863  "ilAccess",
864  "./Services/AccessControl/classes/class.ilAccess.php"
865  );
866 
867  require_once "./Services/AccessControl/classes/class.ilConditionHandler.php";
868  }
869 
873  protected static function initLog()
874  {
875  include_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
877 
878  self::initGlobal("ilLog", $log);
879  // deprecated
880  self::initGlobal("log", $log);
881  }
882 
890  protected static function initGlobal($a_name, $a_class, $a_source_file = null)
891  {
892  global $DIC;
893 
894  if ($a_source_file) {
895  include_once $a_source_file;
896  $GLOBALS[$a_name] = new $a_class;
897  } else {
898  $GLOBALS[$a_name] = $a_class;
899  }
900 
901  $DIC[$a_name] = function ($c) use ($a_name) {
902  return $GLOBALS[$a_name];
903  };
904  }
905 
911  protected static function abortAndDie($a_message)
912  {
913  if (is_object($GLOBALS['ilLog'])) {
914  $GLOBALS['ilLog']->write("Fatal Error: ilInitialisation - " . $a_message);
915  }
916  die($a_message);
917  }
918 
922  protected static function handleDevMode()
923  {
924  if (defined(SHOWNOTICES) && SHOWNOTICES) {
925  // no further differentiating of php version regarding to 5.4 neccessary
926  // when the error reporting is set to E_ALL anyway
927 
928  // add notices to error reporting
929  error_reporting(E_ALL);
930  }
931 
932  if (defined('DEBUGTOOLS') && DEBUGTOOLS) {
933  include_once "include/inc.debug.php";
934  }
935  }
936 
937  protected static $already_initialized;
938 
939 
940  public static function reinitILIAS()
941  {
942  self::$already_initialized = false;
943  self::initILIAS();
944  }
945 
949  public static function initILIAS()
950  {
951  if (self::$already_initialized) {
952  // workaround for bug #17990
953  // big mess. we prevent double initialisations with ILIAS 5.1, which is good, but...
954  // the style service uses $_GET["ref_id"] to determine
955  // the context styles. $_GET["ref_id"] is "corrected" by the "goto" procedure and which calls
956  // initILIAS again.
957  // we need a mechanism that detemines our repository context and stores that in an information object
958  // usable by the style component afterwars. This needs new concepts and a refactoring.
959  if (ilContext::initClient()) {
960  global $tpl;
961  if (is_object($tpl)) {
962  // load style sheet depending on user's settings
963  $location_stylesheet = ilUtil::getStyleSheetLocation();
964  $tpl->setVariable("LOCATION_STYLESHEET", $location_stylesheet);
965  }
966  }
967 
968  return;
969  }
970 
971  $GLOBALS["DIC"] = new \ILIAS\DI\Container();
972  $GLOBALS["DIC"]["ilLoggerFactory"] = function ($c) {
974  };
975 
976  self::$already_initialized = true;
977 
978  self::initCore();
979  self::initHTTPServices($GLOBALS["DIC"]);
980  if (ilContext::initClient()) {
981  self::initClient();
982  self::initFileUploadService($GLOBALS["DIC"]);
983  self::initSession();
984 
985  if (ilContext::hasUser()) {
986  self::initUser();
987 
989  self::resumeUserSession();
990  }
991  }
992 
993  // init after Auth otherwise breaks CAS
994  self::includePhp5Compliance();
995 
996  // language may depend on user setting
997  self::initLanguage(true);
998  $GLOBALS['DIC']['tree']->initLangCode();
999 
1000  self::initInjector($GLOBALS['DIC']);
1001  self::initBackgroundTasks($GLOBALS['DIC']);
1002 
1003  if (ilContext::hasHTML()) {
1004  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
1006 
1007  self::initHTML();
1008  }
1009  }
1010  }
1011 
1015  protected static function initSession()
1016  {
1017  $GLOBALS["DIC"]["ilAuthSession"] = function ($c) {
1018  $auth_session = ilAuthSession::getInstance(
1019  $c['ilLoggerFactory']->getLogger('auth')
1020  );
1021  $auth_session->init();
1022  return $auth_session;
1023  };
1024  }
1025 
1026 
1030  public static function handleErrorReporting()
1031  {
1032  // push the error level as high as possible / sane
1033  error_reporting(E_ALL & ~E_NOTICE);
1034 
1035  // see handleDevMode() - error reporting might be overwritten again
1036  // but we need the client ini first
1037  }
1038 
1042  protected static function initCore()
1043  {
1044  global $ilErr;
1045 
1046  self::handleErrorReporting();
1047 
1048  // breaks CAS: must be included after CAS context isset in AuthUtils
1049  //self::includePhp5Compliance();
1050 
1051  self::requireCommonIncludes();
1052 
1053 
1054  // error handler
1055  self::initGlobal(
1056  "ilErr",
1057  "ilErrorHandling",
1058  "./Services/Init/classes/class.ilErrorHandling.php"
1059  );
1060  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK, array($ilErr, 'errorHandler'));
1061 
1062  // :TODO: obsolete?
1063  // PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ilErr, "errorHandler"));
1064 
1065  // workaround: load old post variables if error handler 'message' was called
1066  include_once "Services/Authentication/classes/class.ilSession.php";
1067  if (ilSession::get("message")) {
1068  $_POST = ilSession::get("post_vars");
1069  }
1070 
1071  self::removeUnsafeCharacters();
1072 
1073  self::initIliasIniFile();
1074 
1075  define('IL_INITIAL_WD', getcwd());
1076 
1077  // deprecated
1078  self::initGlobal("ilias", "ILIAS", "./Services/Init/classes/class.ilias.php");
1079  }
1080 
1084  protected static function initClient()
1085  {
1086  global $https, $ilias, $DIC;
1087 
1088  self::setCookieConstants();
1089 
1090  self::determineClient();
1091 
1092  self::bootstrapFilesystems();
1093 
1094  self::initClientIniFile();
1095 
1096 
1097  // --- needs client ini
1098 
1099  $ilias->client_id = CLIENT_ID;
1100 
1101  if (DEVMODE) {
1102  self::handleDevMode();
1103  }
1104 
1105 
1106  self::handleMaintenanceMode();
1107 
1108  self::initDatabase();
1109 
1110  // init dafault language
1111  self::initLanguage(false);
1112 
1113  // moved after databases
1114  self::initLog();
1115 
1116  self::initGlobal(
1117  "ilAppEventHandler",
1118  "ilAppEventHandler",
1119  "./Services/EventHandling/classes/class.ilAppEventHandler.php"
1120  );
1121 
1122  // there are rare cases where initILIAS is called twice for a request
1123  // example goto.php is called and includes ilias.php later
1124  // we must prevent that ilPluginAdmin is initialized twice in
1125  // this case, since this won't get the values out of plugin.php the
1126  // second time properly
1127  if (!isset($DIC["ilPluginAdmin"]) || !$DIC["ilPluginAdmin"] instanceof ilPluginAdmin) {
1128  self::initGlobal(
1129  "ilPluginAdmin",
1130  "ilPluginAdmin",
1131  "./Services/Component/classes/class.ilPluginAdmin.php"
1132  );
1133  }
1134 
1135  self::initSettings();
1136  self::setSessionHandler();
1137  self::initMail($GLOBALS['DIC']);
1138  self::initAvatar($GLOBALS['DIC']);
1139 
1140 
1141  // --- needs settings
1142 
1143  self::initLocale();
1144 
1145  if (ilContext::usesHTTP()) {
1146  // $https
1147  self::initGlobal("https", "ilHTTPS", "./Services/Http/classes/class.ilHTTPS.php");
1148  $https->enableSecureCookies();
1149  $https->checkPort();
1150  }
1151 
1152 
1153  // --- object handling
1154 
1155  self::initGlobal(
1156  "ilObjDataCache",
1157  "ilObjectDataCache",
1158  "./Services/Object/classes/class.ilObjectDataCache.php"
1159  );
1160 
1161  // needed in ilObjectDefinition
1162  require_once "./Services/Xml/classes/class.ilSaxParser.php";
1163 
1164  self::initGlobal(
1165  "objDefinition",
1166  "ilObjectDefinition",
1167  "./Services/Object/classes/class.ilObjectDefinition.php"
1168  );
1169 
1170  // $tree
1171  require_once "./Services/Tree/classes/class.ilTree.php";
1172  $tree = new ilTree(ROOT_FOLDER_ID);
1173  self::initGlobal("tree", $tree);
1174  unset($tree);
1175 
1176  self::initGlobal(
1177  "ilCtrl",
1178  "ilCtrl",
1179  "./Services/UICore/classes/class.ilCtrl.php"
1180  );
1181 
1182  self::setSessionCookieParams();
1183  }
1184 
1188  protected static function initUser()
1189  {
1190  global $ilias, $ilUser;
1191 
1192  // $ilUser
1193  self::initGlobal(
1194  "ilUser",
1195  "ilObjUser",
1196  "./Services/User/classes/class.ilObjUser.php"
1197  );
1198  $ilias->account = $ilUser;
1199 
1200  self::initAccessHandling();
1201  }
1202 
1206  public static function resumeUserSession()
1207  {
1208  include_once './Services/Authentication/classes/class.ilAuthUtils.php';
1211  }
1212 
1213  if (
1214  !$GLOBALS['DIC']['ilAuthSession']->isAuthenticated() or
1215  $GLOBALS['DIC']['ilAuthSession']->isExpired()
1216  ) {
1217  ilLoggerFactory::getLogger('init')->debug('Current session is invalid: ' . $GLOBALS['DIC']['ilAuthSession']->getId());
1218  $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
1219  if (self::blockedAuthentication($current_script)) {
1220  ilLoggerFactory::getLogger('init')->debug('Authentication is started in current script.');
1221  // nothing todo: authentication is done in current script
1222  return;
1223  }
1224  return self::handleAuthenticationFail();
1225  }
1226  // valid session
1227  return self::initUserAccount();
1228  }
1229 
1235  public static function authenticate()
1236  {
1237  global $ilAuth, $ilias, $ilErr;
1238 
1239  $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
1240 
1241  if (self::blockedAuthentication($current_script)) {
1242  return;
1243  }
1244 
1245  $oldSid = session_id();
1246 
1247  $ilAuth->start();
1248  $ilias->setAuthError($ilErr->getLastError());
1249 
1250  if ($ilAuth->getAuth() && $ilAuth->getStatus() == '') {
1251  self::initUserAccount();
1252 
1253  self::handleAuthenticationSuccess();
1254  } else {
1255  if (!self::showingLoginForm($current_script)) {
1256  // :TODO: should be moved to context?!
1257  $mandatory_auth = ($current_script != "shib_login.php"
1258  && $current_script != "shib_logout.php"
1259  && $current_script != "saml.php"
1260  && $current_script != "error.php"
1261  && $current_script != "chat.php"
1262  && $current_script != "wac.php"
1263  && $current_script != "index.php"); // #10316
1264 
1265  if ($mandatory_auth) {
1266  self::handleAuthenticationFail();
1267  }
1268  }
1269  }
1270  }
1271 
1275  protected static function handleAuthenticationSuccess()
1276  {
1280  global $ilUser;
1281 
1282  require_once 'Services/Tracking/classes/class.ilOnlineTracking.php';
1283  ilOnlineTracking::updateAccess($ilUser);
1284  }
1285 
1289  protected static function handleAuthenticationFail()
1290  {
1295  global $ilAuth, $ilSetting;
1296 
1297  ilLoggerFactory::getLogger('init')->debug('Handling of failed authentication.');
1298 
1299  // #10608
1300  if (
1303  throw new Exception("Authentication failed.");
1304  }
1305  if ($GLOBALS['DIC']['ilAuthSession']->isExpired()) {
1306  ilLoggerFactory::getLogger('init')->debug('Expired session found -> redirect to login page');
1307  return self::goToLogin();
1308  }
1309  if (ilPublicSectionSettings::getInstance()->isEnabledForDomain($_SERVER['SERVER_NAME'])) {
1310  ilLoggerFactory::getLogger('init')->debug('Redirect to public section.');
1311  return self::goToPublicSection();
1312  }
1313  ilLoggerFactory::getLogger('init')->debug('Redirect to login page.');
1314  return self::goToLogin();
1315  }
1316 
1320  protected static function initHTTPServices(\ILIAS\DI\Container $container)
1321  {
1322  $container['http.request_factory'] = function ($c) {
1323  return new \ILIAS\HTTP\Request\RequestFactoryImpl();
1324  };
1325 
1326  $container['http.response_factory'] = function ($c) {
1327  return new \ILIAS\HTTP\Response\ResponseFactoryImpl();
1328  };
1329 
1330  $container['http.cookie_jar_factory'] = function ($c) {
1331  return new \ILIAS\HTTP\Cookies\CookieJarFactoryImpl();
1332  };
1333 
1334  $container['http.response_sender_strategy'] = function ($c) {
1335  return new \ILIAS\HTTP\Response\Sender\DefaultResponseSenderStrategy();
1336  };
1337 
1338  $container['http'] = function ($c) {
1339  return new \ILIAS\DI\HTTPServices(
1340  $c['http.response_sender_strategy'],
1341  $c['http.cookie_jar_factory'],
1342  $c['http.request_factory'],
1343  $c['http.response_factory']
1344  );
1345  };
1346  }
1347 
1351  protected static function initUIFramework(\ILIAS\DI\Container $c)
1352  {
1353  $c["ui.factory"] = function ($c) {
1354  return new ILIAS\UI\Implementation\Factory();
1355  };
1356  $c["ui.renderer"] = function ($c) {
1358  $c["ui.component_renderer_loader"]
1359  );
1360  };
1361  $c["ui.component_renderer_loader"] = function ($c) {
1363  new ILIAS\UI\Implementation\Render\LoaderResourceRegistryWrapper(
1364  $c["ui.resource_registry"],
1365  new ILIAS\UI\Implementation\Render\FSLoader(
1366  new ILIAS\UI\Implementation\Render\DefaultRendererFactory(
1367  $c["ui.factory"],
1368  $c["ui.template_factory"],
1369  $c["lng"],
1370  $c["ui.javascript_binding"]
1371  )
1372  )
1373  )
1374  );
1375  };
1376  $c["ui.template_factory"] = function ($c) {
1378  $c["tpl"]
1379  );
1380  };
1381  $c["ui.resource_registry"] = function ($c) {
1383  };
1384  $c["ui.javascript_binding"] = function ($c) {
1386  };
1387  }
1388 
1392  protected static function initHTML()
1393  {
1394  global $ilUser;
1395  require_once "./Services/LTI/classes/class.ilLTIViewGUI.php";
1396  $lti = new ilLTIViewGUI($ilUser);
1397  $GLOBALS["DIC"]["lti"] = $lti;
1398 
1399  if (ilContext::hasUser()) {
1400  // load style definitions
1401  // use the init function with plugin hook here, too
1402  self::initStyle();
1403  }
1404 
1405  self::initUIFramework($GLOBALS["DIC"]);
1406 
1407  // LTI
1408  if ($lti->isActive()) {
1409  include_once "./Services/LTI/classes/class.ilTemplate.php";
1410  $tpl = new LTI\ilTemplate("tpl.main.html", true, true, "Services/LTI");
1411  } else {
1412  $tpl = new ilTemplate("tpl.main.html", true, true);
1413  }
1414 
1415  self::initGlobal("tpl", $tpl);
1416 
1417  if (ilContext::hasUser()) {
1418  require_once 'Services/User/classes/class.ilUserRequestTargetAdjustment.php';
1419  $request_adjuster = new ilUserRequestTargetAdjustment($ilUser, $GLOBALS['DIC']['ilCtrl']);
1420  $request_adjuster->adjust();
1421  }
1422 
1423 
1424  // load style sheet depending on user's settings
1425  $location_stylesheet = ilUtil::getStyleSheetLocation();
1426  $tpl->setVariable("LOCATION_STYLESHEET", $location_stylesheet);
1427 
1428  require_once "./Services/UICore/classes/class.ilFrameTargetInfo.php";
1429 
1430  self::initGlobal(
1431  "ilNavigationHistory",
1432  "ilNavigationHistory",
1433  "Services/Navigation/classes/class.ilNavigationHistory.php"
1434  );
1435 
1436  self::initGlobal(
1437  "ilBrowser",
1438  "ilBrowser",
1439  "./Services/Utilities/classes/class.ilBrowser.php"
1440  );
1441 
1442  self::initGlobal(
1443  "ilHelp",
1444  "ilHelpGUI",
1445  "Services/Help/classes/class.ilHelpGUI.php"
1446  );
1447 
1448  self::initGlobal(
1449  "ilToolbar",
1450  "ilToolbarGUI",
1451  "./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php"
1452  );
1453 
1454  self::initGlobal(
1455  "ilLocator",
1456  "ilLocatorGUI",
1457  "./Services/Locator/classes/class.ilLocatorGUI.php"
1458  );
1459 
1460  self::initGlobal(
1461  "ilTabs",
1462  "ilTabsGUI",
1463  "./Services/UIComponent/Tabs/classes/class.ilTabsGUI.php"
1464  );
1465 
1466  if (ilContext::hasUser()) {
1467  // LTI
1468  if ($lti->isActive()) {
1469  include_once './Services/LTI/classes/class.ilMainMenuGUI.php';
1470  $ilMainMenu = new LTI\ilMainMenuGUI("_top");
1471  } else {
1472  include_once './Services/MainMenu/classes/class.ilMainMenuGUI.php';
1473  $ilMainMenu = new ilMainMenuGUI("_top");
1474  }
1475 
1476  self::initGlobal("ilMainMenu", $ilMainMenu);
1477  unset($ilMainMenu);
1478 
1479  // :TODO: tableGUI related
1480 
1481  // set hits per page for all lists using table module
1482  $_GET['limit'] = (int) $ilUser->getPref('hits_per_page');
1483  ilSession::set('tbl_limit', $_GET['limit']);
1484 
1485  // the next line makes it impossible to save the offset somehow in a session for
1486  // a specific table (I tried it for the user administration).
1487  // its not posssible to distinguish whether it has been set to page 1 (=offset = 0)
1488  // or not set at all (then we want the last offset, e.g. being used from a session var).
1489  // So I added the wrapping if statement. Seems to work (hopefully).
1490  // Alex April 14th 2006
1491  if (isset($_GET['offset']) && $_GET['offset'] != "") { // added April 14th 2006
1492  $_GET['offset'] = (int) $_GET['offset']; // old code
1493  }
1494  } else {
1495  // several code parts rely on ilObjUser being always included
1496  include_once "Services/User/classes/class.ilObjUser.php";
1497  }
1498  }
1499 
1505  protected static function getCurrentCmd()
1506  {
1507  $cmd = $_REQUEST["cmd"];
1508  if (is_array($cmd)) {
1509  return array_shift(array_keys($cmd));
1510  } else {
1511  return $cmd;
1512  }
1513  }
1514 
1520  protected static function blockedAuthentication($a_current_script)
1521  {
1523  ilLoggerFactory::getLogger('init')->debug('Blocked authentication for WAC request.');
1524  return true;
1525  }
1527  ilLoggerFactory::getLogger('init')->debug('Blocked authentication for sso request.');
1528  return true;
1529  }
1531  ilLoggerFactory::getLogger('init')->debug('Blocked authentication for webdav request');
1532  return true;
1533  }
1535  ilLoggerFactory::getLogger('init')->debug('Blocked authentication for shibboleth request.');
1536  return true;
1537  }
1539  ilLoggerFactory::getLogger('init')->debug('Blocked authentication for lti provider requests.');
1540  return true;
1541  }
1543  ilLoggerFactory::getLogger('init')->debug('Blocked authentication for SAML request.');
1544  return true;
1545  }
1546  if (
1547  $a_current_script == "register.php" ||
1548  $a_current_script == "pwassist.php" ||
1549  $a_current_script == "confirmReg.php" ||
1550  $a_current_script == "il_securimage_play.php" ||
1551  $a_current_script == "il_securimage_show.php" ||
1552  $a_current_script == 'login.php'
1553  ) {
1554  ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for script: ' . $a_current_script);
1555  return true;
1556  }
1557 
1558  if ($_REQUEST["baseClass"] == "ilStartUpGUI") {
1559  $cmd_class = $_REQUEST["cmdClass"];
1560 
1561  if ($cmd_class == "ilaccountregistrationgui" ||
1562  $cmd_class == "ilpasswordassistancegui") {
1563  ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmdClass: ' . $cmd_class);
1564  return true;
1565  }
1566 
1567  $cmd = self::getCurrentCmd();
1568  if (
1569  $cmd == "showTermsOfService" || $cmd == "showClientList" ||
1570  $cmd == 'showAccountMigration' || $cmd == 'migrateAccount' ||
1571  $cmd == 'processCode' || $cmd == 'showLoginPage' || $cmd == 'doStandardAuthentication' || $cmd == 'doCasAuthentication'
1572  ) {
1573  ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for cmd: ' . $cmd);
1574  return true;
1575  }
1576  }
1577 
1578  // #12884
1579  if (($a_current_script == "goto.php" && $_GET["target"] == "impr_0") ||
1580  $_GET["baseClass"] == "ilImprintGUI") {
1581  ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for baseClass: ' . $_GET['baseClass']);
1582  return true;
1583  }
1584 
1585  if ($a_current_script == 'goto.php' && in_array($_GET['target'], array(
1586  'usr_registration', 'usr_nameassist', 'usr_pwassist', 'usr_agreement'
1587  ))) {
1588  ilLoggerFactory::getLogger('auth')->debug('Blocked authentication for goto target: ' . $_GET['target']);
1589  return true;
1590  }
1591 
1592  ilLoggerFactory::getLogger('auth')->debug('Authentication required');
1593  return false;
1594  }
1595 
1601  protected static function showingLoginForm($a_current_script)
1602  {
1603  if ($a_current_script == "login.php") {
1604  return true;
1605  }
1606 
1607  if ($_REQUEST["baseClass"] == "ilStartUpGUI" &&
1608  self::getCurrentCmd() == "showLoginPage") {
1609  return true;
1610  }
1611 
1612  return false;
1613  }
1614 
1622  protected static function translateMessage($a_message_id, array $a_message_static = null)
1623  {
1624  global $ilDB, $lng, $ilSetting, $ilClientIniFile, $ilUser;
1625 
1626  // current language
1627  if (!$lng) {
1628  $lang = "en";
1629  if ($ilUser) {
1630  $lang = $ilUser->getLanguage();
1631  } elseif ($_REQUEST["lang"]) {
1632  $lang = (string) $_REQUEST["lang"];
1633  } elseif ($ilSetting) {
1634  $lang = $ilSetting->get("language");
1635  } elseif ($ilClientIniFile) {
1636  $lang = $ilClientIniFile->readVariable("language", "default");
1637  }
1638  } else {
1639  $lang = $lng->getLangKey();
1640  }
1641 
1642  $message = "";
1643  if ($ilDB && $a_message_id) {
1644  if (!$lng) {
1645  require_once "./Services/Language/classes/class.ilLanguage.php";
1646  $lng = new ilLanguage($lang);
1647  }
1648 
1649  $lng->loadLanguageModule("init");
1650  $message = $lng->txt($a_message_id);
1651  } elseif (is_array($a_message_static)) {
1652  if (!isset($a_message_static[$lang])) {
1653  $lang = "en";
1654  }
1655  $message = $a_message_static[$lang];
1656  }
1657 
1658  return utf8_decode($message);
1659  }
1660 
1668  protected static function redirect($a_target, $a_message_id = '', array $a_message_static = null)
1669  {
1670  // #12739
1671  if (defined("ILIAS_HTTP_PATH") &&
1672  !stristr($a_target, ILIAS_HTTP_PATH)) {
1673  $a_target = ILIAS_HTTP_PATH . "/" . $a_target;
1674  }
1675 
1677  ilUtil::redirect($a_target);
1678  } else {
1679  $message = self::translateMessage($a_message_id, $a_message_static);
1680 
1681  // user-directed linked message
1683  $link = self::translateMessage(
1684  "init_error_redirect_click",
1685  array("en" => 'Please click to continue.',
1686  "de" => 'Bitte klicken um fortzufahren.')
1687  );
1688  $mess = $message .
1689  '<br /><a href="' . $a_target . '">' . $link . '</a>';
1690  }
1691  // plain text
1692  else {
1693  // not much we can do here
1694  $mess = $message;
1695 
1696  if (!trim($mess)) {
1697  $mess = self::translateMessage(
1698  "init_error_redirect_info",
1699  array("en" => 'Redirect not supported by context.',
1700  "de" => 'Weiterleitungen werden durch Kontext nicht unterstützt.')
1701  ) .
1702  ' (' . $a_target . ')';
1703  }
1704  }
1705 
1706  self::abortAndDie($mess);
1707  }
1708  }
1709 
1713  public static function redirectToStartingPage()
1714  {
1718  global $ilUser;
1719 
1720  // fallback, should never happen
1721  if ($ilUser->getId() == ANONYMOUS_USER_ID) {
1723  return true;
1724  }
1725 
1726  // for password change and incomplete profile
1727  // see ilPersonalDesktopGUI
1728  if (!$_GET["target"]) {
1729  ilLoggerFactory::getLogger('init')->debug('Redirect to default starting page');
1730  // Redirect here to switch back to http if desired
1731  include_once './Services/User/classes/class.ilUserUtil.php';
1733  } else {
1734  ilLoggerFactory::getLogger('init')->debug('Redirect to target: ' . $_GET['target']);
1735  ilUtil::redirect("goto.php?target=" . $_GET["target"]);
1736  }
1737  }
1738 
1739 
1740  private static function initBackgroundTasks(\ILIAS\DI\Container $c)
1741  {
1742  global $ilIliasIniFile;
1743 
1744  $n_of_tasks = $ilIliasIniFile->readVariable("background_tasks", "number_of_concurrent_tasks");
1745  $sync = $ilIliasIniFile->readVariable("background_tasks", "concurrency");
1746 
1747  $n_of_tasks = $n_of_tasks ? $n_of_tasks : 5;
1748  $sync = $sync ? $sync : 'sync'; // The default value is sync.
1749 
1750  $c["bt.task_factory"] = function ($c) {
1751  return new \ILIAS\BackgroundTasks\Implementation\Tasks\BasicTaskFactory($c["di.injector"]);
1752  };
1753 
1754  $c["bt.persistence"] = function ($c) {
1755  return new \ILIAS\BackgroundTasks\Implementation\Persistence\BasicPersistence();
1756  };
1757 
1758  $c["bt.injector"] = function ($c) {
1759  return new \ILIAS\BackgroundTasks\Dependencies\Injector($c, new BaseDependencyMap());
1760  };
1761 
1762  $c["bt.task_manager"] = function ($c) use ($sync) {
1763  if ($sync == 'sync') {
1764  return new \ILIAS\BackgroundTasks\Implementation\TaskManager\BasicTaskManager($c["bt.persistence"]);
1765  } elseif ($sync == 'async') {
1766  return new \ILIAS\BackgroundTasks\Implementation\TaskManager\AsyncTaskManager($c["bt.persistence"]);
1767  } else {
1768  throw new ilException("The supported Background Task Managers are sync and async. $sync given.");
1769  }
1770  };
1771  }
1772 
1773 
1774  private static function initInjector(\ILIAS\DI\Container $c)
1775  {
1776  $c["di.dependency_map"] = function ($c) {
1777  return new \ILIAS\BackgroundTasks\Dependencies\DependencyMap\BaseDependencyMap();
1778  };
1779 
1780  $c["di.injector"] = function ($c) {
1781  return new \ILIAS\BackgroundTasks\Dependencies\Injector($c, $c["di.dependency_map"]);
1782  };
1783  }
1784 }
static initHTTPServices(\ILIAS\DI\Container $container)
Class ilUserAvatarFactory.
static initAvatar(\ILIAS\DI\Container $c)
global $ilErr
Definition: raiseError.php:16
Add rich text string
$cookie_path
Definition: metadata.php:7
$_COOKIE['client_id']
Definition: server.php:9
static handleMaintenanceMode()
handle maintenance mode
Handles display of the main menu.
static hasUser()
Based on user authentication?
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
Class ilMailMimeSenderFactory.
const CONTEXT_WAC
Class Factory.
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
static includePhp5Compliance()
This is a hack for authentication.
static usesHTTP()
Uses HTTP aka browser.
static initFileUploadService(\ILIAS\DI\Container $dic)
Initializes the file upload service.
global $DIC
Definition: saml.php:7
static initHTML()
init HTML output (level 3)
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
static blockedAuthentication($a_current_script)
Block authentication based on current request.
$tpl
Definition: ilias.php:10
const CONTEXT_WEBDAV
Class BaseForm.
Class ilGlobalCacheSettings.
Database Session Handling.
static setup(ilGlobalCacheSettings $ilGlobalCacheSettings)
Wraps global ilTemplate to provide JavaScriptBinding.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const SESSION_CLOSE_LOGIN
static determineClient()
This method determines the current client and sets the constant CLIENT_ID.
static get($a_var)
Get a value.
static isAuthenticationForced()
Check if authentication is should be forced.
Caches renderers loaded by another loader.
static set($a_var, $a_val)
Set a value.
const CONTEXT_LTI_PROVIDER
static initDefaultTimeZone(ilIniFile $ini)
Initialize default timezone from system settings.
const CONTEXT_SHIBBOLETH
static goToPublicSection()
go to public section
static getClientIdByString($clientId)
static resumeUserSession()
Resume an existing user session.
static getStartingPointAsUrl()
Get current starting point setting as URL.
static setSessionHandler()
set session handler to db
static initSession()
Init auth session.
static getCurrentCmd()
Extract current cmd from request.
$container
Definition: wac.php:13
if($modEnd===false) $module
Definition: module.php:59
static initBackgroundTasks(\ILIAS\DI\Container $c)
static initAccessHandling()
$ilAccess and $rbac...
const SESSION_CLOSE_EXPIRE
Administration class for plugins.
static initILIAS()
ilias initialisation
static handleForcedAuthentication()
static usesTemplate()
Uses template engine.
HTTPS.
static setCookie($a_cookie_name, $a_cookie_value='', $a_also_set_super_global=true, $a_set_cookie_invalid=false)
catch(Exception $e) $message
static start()
Start task scheduler for each server instance.
static initDatabase()
initialise database object $ilDB
static initMail(\ILIAS\DI\Container $c)
const CONTEXT_SAML
static initUIFramework(\ILIAS\DI\Container $c)
init the ILIAS UI framework.
static _exists($a_session_id)
Check whether session exists.
static initClientIniFile()
This method provides a global instance of class ilIniFile for the client.ini.php file in variable $il...
static hasHTML()
Has HTML output.
Class HTTPServicesTest.
static abortAndDie($a_message)
Exit.
special template class to simplify handling of ITX/PEAR
const IL_COOKIE_PATH(isset($_GET["client_id"]))
Definition: metadata.php:36
$ilUser
Definition: imgupload.php:18
$https
Definition: imgupload.php:19
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
$sync
static initLocale()
Init Locale.
static requireCommonIncludes()
get common include code files
static initLog()
Init log instance.
static removeTrailingPathSeparators($path)
Class ilUserAccountMaintenanceEnforcement.
static initStyle()
provide $styleDefinition object
static getFallbackInstance()
Builds a global default language instance.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
static initClient()
Init client-based objects (level 1)
static initIliasIniFile()
This method provides a global instance of class ilIniFile for the ilias.ini.php file in variable $ilI...
static getInstance()
Get https instance.
const SESSION_CLOSE_PUBLIC
static redirect($a_target, $a_message_id='', array $a_message_static=null)
Redirects to target url if context supports it.
static removeUnsafeCharacters()
Remove unsafe characters from GET.
static initCore()
Init core objects (level 0)
static authenticate()
Try authentication.
static setSessionCookieParams()
set session cookie params
static supportsPersistentSessions()
Check if context supports persistent session handling.
static setClosingContext($a_context)
set closing context (for statistics)
global $l
Definition: afr.php:30
global $ilSetting
Definition: privfeed.php:17
ILIAS Initialisation Utility Class perform basic setup: init database handler, load configuration fil...
static initClient()
Init client.
global $lng
Definition: privfeed.php:17
global $ilDB
static initGlobal($a_name, $a_class, $a_source_file=null)
Initialize global instance.
static initInjector(\ILIAS\DI\Container $c)
const ILIAS_MODULE
Definition: server.php:14
$ilIliasIniFile
language handling
static goToLogin()
go to login
static getLogger($a_component_id)
Get component logger.
static getInstance(\ilLogger $logger)
Get instance.
static getType()
Get context type.
static translateMessage($a_message_id, array $a_message_static=null)
Translate message if possible.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
static recursivelyRemoveUnsafeCharacters($var)
const CONTEXT_SOAP
static redirect($a_script)
static handleErrorReporting()
Set error reporting level.
class for ILIAS ViewLTI
static showingLoginForm($a_current_script)
Is current view the login form?
static initSettings()
initialise $ilSettings object and define constants
$_POST["username"]
INIFile Parser.
const CONTEXT_APACHE_SSO
const IL_COMP_SERVICE
static initUser()
Init user / authentification (level 2)
static buildHTTPPath()
builds http path
special template class to simplify handling of ITX/PEAR
static getRootLogger()
The unique root logger has a fixed error level.
static supportsRedirects()
Are redirects supported?
static handleDevMode()
Prepare developer tools.