ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 // needed for slow queries, etc.
5 if(!isset($GLOBALS['ilGlobalStartTime']) || !$GLOBALS['ilGlobalStartTime'])
6 {
7  $GLOBALS['ilGlobalStartTime'] = microtime();
8 }
9 
10 include_once "Services/Context/classes/class.ilContext.php";
11 
28 {
32  protected static function removeUnsafeCharacters()
33  {
34  // Remove unsafe characters from GET parameters.
35  // We do not need this characters in any case, so it is
36  // feasible to filter them everytime. POST parameters
37  // need attention through ilUtil::stripSlashes() and similar functions)
38  if (is_array($_GET))
39  {
40  foreach($_GET as $k => $v)
41  {
42  // \r\n used for IMAP MX Injection
43  // ' used for SQL Injection
44  $_GET[$k] = str_replace(array("\x00", "\n", "\r", "\\", "'", '"', "\x1a"), "", $v);
45 
46  // this one is for XSS of any kind
47  $_GET[$k] = strip_tags($_GET[$k]);
48  }
49  }
50  }
51 
55  protected static function requireCommonIncludes()
56  {
57  // pear
58  require_once("include/inc.get_pear.php");
59  require_once("include/inc.check_pear.php");
60  require_once "PEAR.php";
61 
62  // ilTemplate
64  {
65  // HTML_Template_IT support
66  @include_once "HTML/Template/ITX.php"; // new implementation
67  if (class_exists("HTML_Template_ITX"))
68  {
69  include_once "./Services/UICore/classes/class.ilTemplateHTMLITX.php";
70  }
71  else
72  {
73  include_once "HTML/ITX.php"; // old implementation
74  include_once "./Services/UICore/classes/class.ilTemplateITX.php";
75  }
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/Utilities/classes/class.ilFormat.php";
82  require_once "./Services/Calendar/classes/class.ilDatePresentation.php";
83  require_once "include/inc.ilias_version.php";
84 
85  self::initGlobal("ilBench", "ilBenchmark", "./Services/Utilities/classes/class.ilBenchmark.php");
86  }
87 
93  protected static function includePhp5Compliance()
94  {
95  // php5 downward complaince to php 4 dom xml and clone method
96  if (version_compare(PHP_VERSION,'5','>='))
97  {
98  include_once 'Services/Authentication/classes/class.ilAuthFactory.php';
100  {
101  require_once("include/inc.xml5compliance.php");
102  }
103  require_once("include/inc.xsl5compliance.php");
104  }
105  }
106 
114  protected static function initIliasIniFile()
115  {
116  require_once("./Services/Init/classes/class.ilIniFile.php");
117  $ilIliasIniFile = new ilIniFile("./ilias.ini.php");
118  $ilIliasIniFile->read();
119  self::initGlobal('ilIliasIniFile', $ilIliasIniFile);
120 
121  // initialize constants
122  define("ILIAS_DATA_DIR",$ilIliasIniFile->readVariable("clients","datadir"));
123  define("ILIAS_WEB_DIR",$ilIliasIniFile->readVariable("clients","path"));
124  define("ILIAS_ABSOLUTE_PATH",$ilIliasIniFile->readVariable('server','absolute_path'));
125 
126  // logging
127  define ("ILIAS_LOG_DIR",$ilIliasIniFile->readVariable("log","path"));
128  define ("ILIAS_LOG_FILE",$ilIliasIniFile->readVariable("log","file"));
129  define ("ILIAS_LOG_ENABLED",$ilIliasIniFile->readVariable("log","enabled"));
130  define ("ILIAS_LOG_LEVEL",$ilIliasIniFile->readVariable("log","level"));
131  define ("SLOW_REQUEST_TIME",$ilIliasIniFile->readVariable("log","slow_request_time"));
132 
133  // read path + command for third party tools from ilias.ini
134  define ("PATH_TO_CONVERT",$ilIliasIniFile->readVariable("tools","convert"));
135  define ("PATH_TO_FFMPEG",$ilIliasIniFile->readVariable("tools","ffmpeg"));
136  define ("PATH_TO_ZIP",$ilIliasIniFile->readVariable("tools","zip"));
137  define ("PATH_TO_MKISOFS",$ilIliasIniFile->readVariable("tools","mkisofs"));
138  define ("PATH_TO_UNZIP",$ilIliasIniFile->readVariable("tools","unzip"));
139  define ("PATH_TO_GHOSTSCRIPT",$ilIliasIniFile->readVariable("tools","ghostscript"));
140  define ("PATH_TO_JAVA",$ilIliasIniFile->readVariable("tools","java"));
141  define ("PATH_TO_HTMLDOC",$ilIliasIniFile->readVariable("tools","htmldoc"));
142  define ("URL_TO_LATEX",$ilIliasIniFile->readVariable("tools","latex"));
143  define ("PATH_TO_FOP",$ilIliasIniFile->readVariable("tools","fop"));
144 
145  // read virus scanner settings
146  switch ($ilIliasIniFile->readVariable("tools", "vscantype"))
147  {
148  case "sophos":
149  define("IL_VIRUS_SCANNER", "Sophos");
150  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
151  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
152  break;
153 
154  case "antivir":
155  define("IL_VIRUS_SCANNER", "AntiVir");
156  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
157  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
158  break;
159 
160  case "clamav":
161  define("IL_VIRUS_SCANNER", "ClamAV");
162  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
163  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
164  break;
165 
166  default:
167  define("IL_VIRUS_SCANNER", "None");
168  break;
169  }
170 
171  $tz = $ilIliasIniFile->readVariable("server","timezone");
172  if ($tz != "")
173  {
174  if (function_exists('date_default_timezone_set'))
175  {
176  date_default_timezone_set($tz);
177  }
178  }
179  define ("IL_TIMEZONE", $ilIliasIniFile->readVariable("server","timezone"));
180  }
181 
185  protected static function buildHTTPPath()
186  {
187  include_once './Services/Http/classes/class.ilHTTPS.php';
188  $https = new ilHTTPS();
189 
190  if($https->isDetected())
191  {
192  $protocol = 'https://';
193  }
194  else
195  {
196  $protocol = 'http://';
197  }
198  $host = $_SERVER['HTTP_HOST'];
199 
200  $rq_uri = $_SERVER['REQUEST_URI'];
201 
202  // security fix: this failed, if the URI contained "?" and following "/"
203  // -> we remove everything after "?"
204  if (is_int($pos = strpos($rq_uri, "?")))
205  {
206  $rq_uri = substr($rq_uri, 0, $pos);
207  }
208 
209  if(!defined('ILIAS_MODULE'))
210  {
211  $path = pathinfo($rq_uri);
212  if(!$path['extension'])
213  {
214  $uri = $rq_uri;
215  }
216  else
217  {
218  $uri = dirname($rq_uri);
219  }
220  }
221  else
222  {
223  // if in module remove module name from HTTP_PATH
224  $path = dirname($rq_uri);
225 
226  // dirname cuts the last directory from a directory path e.g content/classes return content
227 
229 
230  $dirs = explode('/',$module);
231  $uri = $path;
232  foreach($dirs as $dir)
233  {
234  $uri = dirname($uri);
235  }
236  }
237 
238  return define('ILIAS_HTTP_PATH',ilUtil::removeTrailingPathSeparators($protocol.$host.$uri));
239  }
240 
245  protected static function determineClient()
246  {
247  global $ilIliasIniFile;
248 
249  // check whether ini file object exists
250  if (!is_object($ilIliasIniFile))
251  {
252  self::abortAndDie("Fatal Error: ilInitialisation::determineClient called without initialisation of ILIAS ini file object.");
253  }
254 
255  // set to default client if empty
256  if ($_GET["client_id"] != "")
257  {
258  $_GET["client_id"] = ilUtil::stripSlashes($_GET["client_id"]);
259  if (!defined("IL_PHPUNIT_TEST"))
260  {
261  ilUtil::setCookie("ilClientId", $_GET["client_id"]);
262  }
263  }
264  else if (!$_COOKIE["ilClientId"])
265  {
266  // to do: ilias ini raus nehmen
267  $client_id = $ilIliasIniFile->readVariable("clients","default");
268  ilUtil::setCookie("ilClientId", $client_id);
269  }
270  if (!defined("IL_PHPUNIT_TEST"))
271  {
272  define ("CLIENT_ID", $_COOKIE["ilClientId"]);
273  }
274  else
275  {
276  define ("CLIENT_ID", $_GET["client_id"]);
277  }
278  }
279 
292  protected static function initClientIniFile()
293  {
294  global $ilIliasIniFile;
295 
296  // check whether ILIAS_WEB_DIR is set.
297  if (ILIAS_WEB_DIR == "")
298  {
299  self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without ILIAS_WEB_DIR.");
300  }
301 
302  // check whether CLIENT_ID is set.
303  if (CLIENT_ID == "")
304  {
305  self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without CLIENT_ID.");
306  }
307 
308  $ini_file = "./".ILIAS_WEB_DIR."/".CLIENT_ID."/client.ini.php";
309 
310  // get settings from ini file
311  require_once("./Services/Init/classes/class.ilIniFile.php");
312  $ilClientIniFile = new ilIniFile($ini_file);
313  $ilClientIniFile->read();
314 
315  // invalid client id / client ini
316  if ($ilClientIniFile->ERROR != "")
317  {
318  $c = $_COOKIE["ilClientId"];
319  $default_client = $ilIliasIniFile->readVariable("clients","default");
320  ilUtil::setCookie("ilClientId", $default_client);
321  if (CLIENT_ID != "" && CLIENT_ID != $default_client)
322  {
323  $mess = array("en" => "Client does not exist.",
324  "de" => "Mandant ist ungültig.");
325  self::redirect("index.php?client_id=".$default_client, null, $mess);
326  }
327  else
328  {
329  self::abortAndDie("Invalid client");
330  }
331  }
332 
333  self::initGlobal("ilClientIniFile", $ilClientIniFile);
334 
335  // set constants
336  define ("SESSION_REMINDER_LEADTIME", 30);
337  define ("DEBUG",$ilClientIniFile->readVariable("system","DEBUG"));
338  define ("DEVMODE",$ilClientIniFile->readVariable("system","DEVMODE"));
339  define ("SHOWNOTICES",$ilClientIniFile->readVariable("system","SHOWNOTICES"));
340  define ("ROOT_FOLDER_ID",$ilClientIniFile->readVariable('system','ROOT_FOLDER_ID'));
341  define ("SYSTEM_FOLDER_ID",$ilClientIniFile->readVariable('system','SYSTEM_FOLDER_ID'));
342  define ("ROLE_FOLDER_ID",$ilClientIniFile->readVariable('system','ROLE_FOLDER_ID'));
343  define ("MAIL_SETTINGS_ID",$ilClientIniFile->readVariable('system','MAIL_SETTINGS_ID'));
344 
345  // this is for the online help installation, which sets OH_REF_ID to the
346  // ref id of the online module
347  define ("OH_REF_ID",$ilClientIniFile->readVariable("system","OH_REF_ID"));
348 
349  define ("SYSTEM_MAIL_ADDRESS",$ilClientIniFile->readVariable('system','MAIL_SENT_ADDRESS')); // Change SS
350  define ("MAIL_REPLY_WARNING",$ilClientIniFile->readVariable('system','MAIL_REPLY_WARNING')); // Change SS
351 
352  // see ilObject::TITLE_LENGTH, ilObject::DESC_LENGTH
353  // define ("MAXLENGTH_OBJ_TITLE",125);#$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_TITLE'));
354  // define ("MAXLENGTH_OBJ_DESC",$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_DESC'));
355 
356  define ("CLIENT_DATA_DIR",ILIAS_DATA_DIR."/".CLIENT_ID);
357  define ("CLIENT_WEB_DIR",ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".CLIENT_ID);
358  define ("CLIENT_NAME",$ilClientIniFile->readVariable('client','name')); // Change SS
359 
360  $val = $ilClientIniFile->readVariable("db","type");
361  if ($val == "")
362  {
363  define ("IL_DB_TYPE", "mysql");
364  }
365  else
366  {
367  define ("IL_DB_TYPE", $val);
368  }
369 
370  return true;
371  }
372 
376  protected static function handleMaintenanceMode()
377  {
378  global $ilClientIniFile;
379 
380  if (!$ilClientIniFile->readVariable("client","access"))
381  {
382  $mess = array("en" => "The server is not available due to maintenance.".
383  " We apologise for any inconvenience.",
384  "de" => "Der Server ist aufgrund von Wartungsarbeiten nicht verfügbar.".
385  " Wir bitten um Verständnis.");
386  $mess_id = "init_error_maintenance";
387 
388  if (ilContext::hasHTML() && is_file("./maintenance.html"))
389  {
390  self::redirect("./maintenance.html", $mess_id, $mess);
391  }
392  else
393  {
394  $mess = self::translateMessage($mess_id, $mess);
395  self::abortAndDie($mess);
396  }
397  }
398  }
399 
404  protected static function initDatabase()
405  {
406  // build dsn of database connection and connect
407  require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
408  $ilDB = ilDBWrapperFactory::getWrapper(IL_DB_TYPE);
409  $ilDB->initFromIniFile();
410  $ilDB->connect();
411 
412  self::initGlobal("ilDB", $ilDB);
413  }
414 
420  public static function setSessionHandler()
421  {
422  if(ini_get('session.save_handler') != 'user')
423  {
424  ini_set("session.save_handler", "user");
425  }
426 
427  require_once "Services/Authentication/classes/class.ilSessionDBHandler.php";
428  $db_session_handler = new ilSessionDBHandler();
429  if (!$db_session_handler->setSaveHandler())
430  {
431  self::abortAndDie("Please turn off Safe mode OR set session.save_handler to \"user\" in your php.ini");
432  }
433 
434  // Do not accept external session ids
435  if (!ilSession::_exists(session_id()) && !defined('IL_PHPUNIT_TEST'))
436  {
437  session_regenerate_id();
438  }
439  }
440 
444  protected static function setCookieParams()
445  {
446  include_once 'Services/Authentication/classes/class.ilAuthFactory.php';
448  {
449  $cookie_path = '/';
450  }
451  elseif ($GLOBALS['COOKIE_PATH'])
452  {
453  // use a predefined cookie path from WebAccessChecker
454  $cookie_path = $GLOBALS['COOKIE_PATH'];
455  }
456  else
457  {
458  $cookie_path = dirname( $_SERVER['PHP_SELF'] );
459  }
460 
461  /* if ilias is called directly within the docroot $cookie_path
462  is set to '/' expecting on servers running under windows..
463  here it is set to '\'.
464  in both cases a further '/' won't be appended due to the following regex
465  */
466  $cookie_path .= (!preg_match("/[\/|\\\\]$/", $cookie_path)) ? "/" : "";
467 
468  if($cookie_path == "\\") $cookie_path = '/';
469 
470  define('IL_COOKIE_EXPIRE',0);
471  define('IL_COOKIE_PATH',$cookie_path);
472  define('IL_COOKIE_DOMAIN','');
473  define('IL_COOKIE_SECURE',false); // Default Value
474 
475  // session_set_cookie_params() supports 5th parameter
476  // only for php version 5.2.0 and above
477  if( version_compare(PHP_VERSION, '5.2.0', '>=') )
478  {
479  // PHP version >= 5.2.0
480  define('IL_COOKIE_HTTPONLY',true); // Default Value
481  session_set_cookie_params(
482  IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, IL_COOKIE_SECURE, IL_COOKIE_HTTPONLY
483  );
484  }
485  else
486  {
487  // PHP version < 5.2.0
488  session_set_cookie_params(
489  IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, IL_COOKIE_SECURE
490  );
491  }
492  }
493 
499  protected static function initSettings()
500  {
501  global $ilSetting;
502 
503  self::initGlobal("ilSetting", "ilSetting",
504  "Services/Administration/classes/class.ilSetting.php");
505 
506  // check correct setup
507  if (!$ilSetting->get("setup_ok"))
508  {
509  self::abortAndDie("Setup is not completed. Please run setup routine again.");
510  }
511 
512  // set anonymous user & role id and system role id
513  define ("ANONYMOUS_USER_ID", $ilSetting->get("anonymous_user_id"));
514  define ("ANONYMOUS_ROLE_ID", $ilSetting->get("anonymous_role_id"));
515  define ("SYSTEM_USER_ID", $ilSetting->get("system_user_id"));
516  define ("SYSTEM_ROLE_ID", $ilSetting->get("system_role_id"));
517  define ("USER_FOLDER_ID", 7);
518 
519  // recovery folder
520  define ("RECOVERY_FOLDER_ID", $ilSetting->get("recovery_folder_id"));
521 
522  // installation id
523  define ("IL_INST_ID", $ilSetting->get("inst_id",0));
524 
525  // define default suffix replacements
526  define ("SUFFIX_REPL_DEFAULT", "php,php3,php4,inc,lang,phtml,htaccess");
527  define ("SUFFIX_REPL_ADDITIONAL", $ilSetting->get("suffix_repl_additional"));
528 
529  if(ilContext::usesHTTP())
530  {
532  }
533 
534  // payment setting
535  require_once('Services/Payment/classes/class.ilPaymentSettings.php');
536  define('IS_PAYMENT_ENABLED', ilPaymentSettings::_isPaymentEnabled());
537  }
538 
542  protected static function initStyle()
543  {
544  global $styleDefinition, $ilPluginAdmin;
545 
546  // load style definitions
547  self::initGlobal("styleDefinition", "ilStyleDefinition",
548  "./Services/Style/classes/class.ilStyleDefinition.php");
549 
550  // add user interface hook for style initialisation
551  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
552  foreach ($pl_names as $pl)
553  {
554  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
555  $gui_class = $ui_plugin->getUIClassInstance();
556  $gui_class->modifyGUI("Services/Init", "init_style", array("styleDefinition" => $styleDefinition));
557  }
558 
559  $styleDefinition->startParsing();
560  }
561 
565  public static function initUserAccount()
566  {
570  global $ilUser;
571 
572  // get user id
573  if (!ilSession::get("AccountId"))
574  {
575  ilSession::set("AccountId", $ilUser->checkUserId());
576  ilSession::set('orig_request_target', '');
577  $ilUser->hasToAcceptTermsOfServiceInSession(true);
578  }
579 
580  $uid = ilSession::get("AccountId");
581  if($uid)
582  {
583  $ilUser->setId($uid);
584  $ilUser->read();
585  }
586  else
587  {
588  if(is_object($GLOBALS['ilLog']))
589  {
590  $GLOBALS['ilLog']->logStack();
591  }
592  self::abortAndDie("Init user account failed");
593  }
594  }
595 
599  protected static function initLocale()
600  {
601  global $ilSetting;
602 
603  if (trim($ilSetting->get("locale") != ""))
604  {
605  $larr = explode(",", trim($ilSetting->get("locale")));
606  $ls = array();
607  $first = $larr[0];
608  foreach ($larr as $l)
609  {
610  if (trim($l) != "")
611  {
612  $ls[] = $l;
613  }
614  }
615  if (count($ls) > 0)
616  {
617  setlocale(LC_ALL, $ls);
618  if (class_exists("Collator"))
619  {
620  $GLOBALS["ilCollator"] = new Collator($first);
621  }
622  }
623  }
624  }
625 
631  public static function goToPublicSection($a_auth_stat = "")
632  {
633  global $ilAuth;
634 
635  if (ANONYMOUS_USER_ID == "")
636  {
637  self::abortAndDie("Public Section enabled, but no Anonymous user found.");
638  }
639 
640  // logout and end previous session
641  if($a_auth_stat == AUTH_EXPIRED ||
642  $a_auth_stat == AUTH_IDLED)
643  {
645  }
646  else
647  {
649  }
650  $ilAuth->logout();
651  session_unset();
652  session_destroy();
653 
654  // new session and login as anonymous
656  session_start();
657  $_POST["username"] = "anonymous";
658  $_POST["password"] = "anonymous";
660 
661  // authenticate (anonymous)
662  $oldSid = session_id();
663  $ilAuth->start();
664  if (IS_PAYMENT_ENABLED)
665  {
666  $newSid = session_id();
667  if($oldSid != $newSid)
668  {
669  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
670  ilPaymentShoppingCart::_migrateShoppingCart($oldSid, $newSid);
671  }
672  }
673 
674  if (!$ilAuth->getAuth())
675  {
676  self::abortAndDie("ANONYMOUS user with the object_id ".ANONYMOUS_USER_ID." not found!");
677  }
678 
679  self::initUserAccount();
680 
681  $mess_id = "init_error_authentication_fail";
682  $mess = array("en" => "Authentication failed.",
683  "de" => "Authentifizierung fehlgeschlagen.");
684 
685  // if target given, try to go there
686  if ($_GET["target"] != "")
687  {
688  // when we are already "inside" goto.php no redirect is needed
689  $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
690  if($current_script == "goto.php")
691  {
692  return;
693  }
694 
695  // goto will check if target is accessible or redirect to login
696  self::redirect("goto.php?target=".$_GET["target"], $mess_id, $mess);
697  }
698 
699  // we do not know if ref_id of request is accesible, so redirecting to root
700  $_GET["ref_id"] = ROOT_FOLDER_ID;
701  $_GET["cmd"] = "frameset";
702  self::redirect("ilias.php?baseClass=ilrepositorygui&reloadpublic=1&cmd=".
703  $_GET["cmd"]."&ref_id=".$_GET["ref_id"], $mess_id, $mess);
704  }
705 
711  protected static function goToLogin($a_auth_stat = "")
712  {
713  global $ilAuth;
714 
715  // close current session
716  if($a_auth_stat == AUTH_EXPIRED ||
717  $a_auth_stat == AUTH_IDLED)
718  {
720  }
721  else
722  {
724  }
725  $ilAuth->logout();
726  session_unset();
727  session_destroy();
728 
729  $add = "";
730  if ($_GET["soap_pw"] != "")
731  {
732  $add = "&soap_pw=".$_GET["soap_pw"]."&ext_uid=".$_GET["ext_uid"];
733  }
734 
735  $script = "login.php?target=".$_GET["target"]."&client_id=".$_COOKIE["ilClientId"].
736  "&auth_stat=".$a_auth_stat.$add;
737 
738  self::redirect($script, "init_error_authentication_fail",
739  array("en" => "Authentication failed.",
740  "de" => "Authentifizierung fehlgeschlagen."));
741  }
742 
746  protected static function initLanguage()
747  {
748  global $ilUser, $ilSetting, $rbacsystem;
749 
750  if (!ilSession::get("lang"))
751  {
752  if ($_GET['lang'])
753  {
754  $_GET['lang'] = $_GET['lang'];
755  }
756  else
757  {
758  if (is_object($ilUser))
759  {
760  $_GET['lang'] = $ilUser->getPref('language');
761  }
762  }
763  }
764 
765  if (isset($_POST['change_lang_to']) && $_POST['change_lang_to'] != "")
766  {
767  $_GET['lang'] = ilUtil::stripSlashes($_POST['change_lang_to']);
768  }
769 
770  // prefer personal setting when coming from login screen
771  // Added check for ilUser->getId > 0 because it is 0 when the language is changed and the terms of service should be displayes (Helmut Schottm��ller, 2006-10-14)
772  if (is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID && $ilUser->getId() > 0)
773  {
774  ilSession::set('lang', $ilUser->getPref('language'));
775  }
776 
777  ilSession::set('lang', (isset($_GET['lang']) && $_GET['lang']) ? $_GET['lang'] : ilSession::get('lang'));
778 
779  // check whether lang selection is valid
780  require_once "./Services/Language/classes/class.ilLanguage.php";
782  if (!in_array(ilSession::get('lang'), $langs))
783  {
784  if (is_object($ilSetting) && $ilSetting->get('language') != '')
785  {
786  ilSession::set('lang', $ilSetting->get('language'));
787  }
788  else
789  {
790  ilSession::set('lang', $langs[0]);
791  }
792  }
793  $_GET['lang'] = ilSession::get('lang');
794 
795  $lng = new ilLanguage(ilSession::get('lang'));
796  self::initGlobal('lng', $lng);
797 
798  if(is_object($rbacsystem))
799  {
800  $rbacsystem->initMemberView();
801  }
802  }
803 
807  protected static function initAccessHandling()
808  {
809  self::initGlobal("rbacreview", "ilRbacReview",
810  "./Services/AccessControl/classes/class.ilRbacReview.php");
811 
812  require_once "./Services/AccessControl/classes/class.ilRbacSystem.php";
813  $rbacsystem = ilRbacSystem::getInstance();
814  self::initGlobal("rbacsystem", $rbacsystem);
815 
816  self::initGlobal("rbacadmin", "ilRbacAdmin",
817  "./Services/AccessControl/classes/class.ilRbacAdmin.php");
818 
819  self::initGlobal("ilAccess", "ilAccessHandler",
820  "./Services/AccessControl/classes/class.ilAccessHandler.php");
821 
822  require_once "./Services/AccessControl/classes/class.ilConditionHandler.php";
823  }
824 
828  protected static function initLog()
829  {
830  require_once "./Services/Logging/classes/class.ilLog.php";
831  try
832  {
833  $log = new ilLog(ILIAS_LOG_DIR,ILIAS_LOG_FILE,CLIENT_ID,ILIAS_LOG_ENABLED,ILIAS_LOG_LEVEL);
834  }
835  catch(ilLogException $e)
836  {
837  self::abortAndDie($e->getMessage());
838  }
839  self::initGlobal("ilLog", $log);
840  // deprecated
841  self::initGlobal("log", $log);
842  }
843 
851  protected static function initGlobal($a_name, $a_class, $a_source_file = null)
852  {
853  if($a_source_file)
854  {
855  include_once $a_source_file;
856  $GLOBALS[$a_name] = new $a_class;
857  }
858  else
859  {
860  $GLOBALS[$a_name] = $a_class;
861  }
862  }
863 
869  protected static function abortAndDie($a_message)
870  {
871  if(is_object($GLOBALS['ilLog']))
872  {
873  $GLOBALS['ilLog']->write("Fatal Error: ilInitialisation - ".$a_message);
874  }
875  die($a_message);
876  }
877 
881  protected static function handleDevMode()
882  {
883  if(defined(SHOWNOTICES) && SHOWNOTICES)
884  {
885  // no further differentiating of php version regarding to 5.4 neccessary
886  // when the error reporting is set to E_ALL anyway
887 
888  // remove notices from error reporting
889  if (version_compare(PHP_VERSION, '5.3.0', '>='))
890  {
891  error_reporting(E_ALL);
892  }
893  else
894  {
895  error_reporting(E_ALL);
896  }
897  }
898 
899  include_once "include/inc.debug.php";
900  }
901 
905  public static function initILIAS()
906  {
907  global $tree;
908 
909  self::initCore();
910 
912  {
914 
915  if (ilContext::hasUser())
916  {
917  self::initUser();
918 
920  {
922  }
923  }
924 
925  // init after Auth otherwise breaks CAS
927 
928  // language may depend on user setting
930  $tree->initLangCode();
931 
932  if(ilContext::hasHTML())
933  {
934  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
936 
937  self::initHTML();
938  }
939  }
940  }
941 
945  protected static function initCore()
946  {
947  global $ilErr;
948 
949  // remove notices from error reporting
950  if (version_compare(PHP_VERSION, '5.4.0', '>='))
951  {
952  // Prior to PHP 5.4.0 E_ALL does not include E_STRICT.
953  // With PHP 5.4.0 and above E_ALL >DOES< include E_STRICT.
954 
955  error_reporting(((ini_get("error_reporting") & ~E_NOTICE) & ~E_DEPRECATED) & ~E_STRICT);
956  }
957  elseif (version_compare(PHP_VERSION, '5.3.0', '>='))
958  {
959  error_reporting((ini_get("error_reporting") & ~E_NOTICE) & ~E_DEPRECATED);
960  }
961  else
962  {
963  error_reporting(ini_get('error_reporting') & ~E_NOTICE);
964  }
965  // breaks CAS: must be included after CAS context isset in AuthUtils
966  //self::includePhp5Compliance();
967 
969 
970 
971  // error handler
972  self::initGlobal("ilErr", "ilErrorHandling",
973  "./Services/Init/classes/class.ilErrorHandling.php");
974  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK, array($ilErr, 'errorHandler'));
975 
976  // :TODO: obsolete?
977  PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ilErr, "errorHandler"));
978 
979  // workaround: load old post variables if error handler 'message' was called
980  include_once "Services/Authentication/classes/class.ilSession.php";
981  if (ilSession::get("message"))
982  {
983  $_POST = ilSession::get("post_vars");
984  }
985 
987 
989 
990 
992 
993 
994  // deprecated
995  self::initGlobal("ilias", "ILIAS", "./Services/Init/classes/class.ilias.php");
996  }
997 
1001  protected static function initClient()
1002  {
1003  global $https, $ilias;
1004 
1006 
1008 
1009 
1010  // --- needs client ini
1011 
1012  $ilias->client_id = CLIENT_ID;
1013 
1014  if (DEVMODE)
1015  {
1017  }
1018 
1019  self::initLog();
1020 
1022 
1024 
1025 
1026  // --- needs database
1027 
1028  self::initGlobal("ilAppEventHandler", "ilAppEventHandler",
1029  "./Services/EventHandling/classes/class.ilAppEventHandler.php");
1030 
1031  // there are rare cases where initILIAS is called twice for a request
1032  // example goto.php is called and includes ilias.php later
1033  // we must prevent that ilPluginAdmin is initialized twice in
1034  // this case, since this won't get the values out of plugin.php the
1035  // second time properly
1036  if (!is_object($GLOBALS["ilPluginAdmin"]))
1037  {
1038  self::initGlobal("ilPluginAdmin", "ilPluginAdmin",
1039  "./Services/Component/classes/class.ilPluginAdmin.php");
1040  }
1041 
1043 
1045 
1046 
1047  // --- needs settings
1048 
1049  self::initLocale();
1050 
1051  if(ilContext::usesHTTP())
1052  {
1053  // $https
1054  self::initGlobal("https", "ilHTTPS", "./Services/Http/classes/class.ilHTTPS.php");
1055  $https->enableSecureCookies();
1056  $https->checkPort();
1057  }
1058 
1059 
1060  // --- object handling
1061 
1062  self::initGlobal("ilObjDataCache", "ilObjectDataCache",
1063  "./Services/Object/classes/class.ilObjectDataCache.php");
1064 
1065  // needed in ilObjectDefinition
1066  require_once "./Services/Xml/classes/class.ilSaxParser.php";
1067 
1068  self::initGlobal("objDefinition", "ilObjectDefinition",
1069  "./Services/Object/classes/class.ilObjectDefinition.php");
1070 
1071  // $tree
1072  require_once "./Services/Tree/classes/class.ilTree.php";
1073  $tree = new ilTree(ROOT_FOLDER_ID);
1074  self::initGlobal("tree", $tree);
1075  unset($tree);
1076 
1077  self::initGlobal("ilCtrl", "ilCtrl",
1078  "./Services/UICore/classes/class.ilCtrl.php");
1079  }
1080 
1084  protected static function initUser()
1085  {
1086  global $ilias, $ilAuth, $ilUser;
1087 
1088  if(ilContext::usesHTTP())
1089  {
1090  // allow login by submitting user data
1091  // in query string when DEVMODE is enabled
1092  if( DEVMODE
1093  && isset($_GET['username']) && strlen($_GET['username'])
1094  && isset($_GET['password']) && strlen($_GET['password'])
1095  ){
1096  $_POST['username'] = $_GET['username'];
1097  $_POST['password'] = $_GET['password'];
1098  }
1099  }
1100 
1101  // $ilAuth
1102  require_once "Auth/Auth.php";
1103  require_once "./Services/AuthShibboleth/classes/class.ilShibboleth.php";
1104  include_once("./Services/Authentication/classes/class.ilAuthUtils.php");
1106  $ilias->auth = $ilAuth;
1107 
1108  // $ilUser
1109  self::initGlobal("ilUser", "ilObjUser",
1110  "./Services/User/classes/class.ilObjUser.php");
1111  $ilias->account =& $ilUser;
1112 
1114 
1115 
1116  // force login
1117  if ((isset($_GET["cmd"]) && $_GET["cmd"] == "force_login"))
1118  {
1119  $ilAuth->logout();
1120 
1121  // we need to do this for the session statistics
1122  // could we use session_destroy() instead?
1123  // [this is done after every $ilAuth->logout() call elsewhere]
1125 
1126  // :TODO: keep session because of cart content?
1127  if(!isset($_GET['forceShoppingCartRedirect']))
1128  {
1129  $_SESSION = array();
1130  }
1131  else
1132  {
1133  ilSession::set("AccountId", "");
1134  }
1135  }
1136 
1137  }
1138 
1144  protected static function authenticate()
1145  {
1146  global $ilAuth, $ilias, $ilErr;
1147 
1148  $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
1149 
1150  if(self::blockedAuthentication($current_script))
1151  {
1152  return;
1153  }
1154 
1155  $oldSid = session_id();
1156 
1157  $ilAuth->start();
1158  $ilias->setAuthError($ilErr->getLastError());
1159 
1160  if(IS_PAYMENT_ENABLED)
1161  {
1162  // cart is "attached" to session, has to be updated
1163  $newSid = session_id();
1164  if($oldSid != $newSid)
1165  {
1166  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
1167  ilPaymentShoppingCart::_migrateShoppingCart($oldSid, $newSid);
1168  }
1169  }
1170 
1171  if($ilAuth->getAuth() && $ilAuth->getStatus() == '')
1172  {
1173  self::initUserAccount();
1174 
1175  self::handleAuthenticationSuccess();
1176  }
1177  else
1178  {
1179  if (!self::showingLoginForm($current_script))
1180  {
1181  // :TODO: should be moved to context?!
1182  $mandatory_auth = ($current_script != "shib_login.php"
1183  && $current_script != "shib_logout.php"
1184  && $current_script != "error.php"
1185  && $current_script != "chat.php"
1186  && $current_script != "index.php"); // #10316
1187 
1188  if($mandatory_auth)
1189  {
1190  self::handleAuthenticationFail();
1191  }
1192  }
1193  }
1194  }
1195 
1199  protected static function handleAuthenticationSuccess()
1200  {
1204  global $ilUser;
1205 
1206  require_once 'Services/Tracking/classes/class.ilOnlineTracking.php';
1207  ilOnlineTracking::updateAccess($ilUser);
1208  }
1209 
1213  protected static function handleAuthenticationFail()
1214  {
1219  global $ilAuth, $ilSetting;
1220 
1221  // #10608
1223  {
1224  throw new Exception("Authentication failed.");
1225  }
1226 
1227  $status = $ilAuth->getStatus();
1228 
1229  if($ilSetting->get('pub_section') &&
1230  ($status == '' || $status == AUTH_EXPIRED || $status == AUTH_IDLED) &&
1231  $_GET['reloadpublic'] != '1'
1232  )
1233  {
1234  self::goToPublicSection($status);
1235  }
1236  else
1237  {
1238  self::goToLogin($status);
1239  }
1240  }
1241 
1245  protected static function initHTML()
1246  {
1247  global $ilUser;
1248 
1249  // load style definitions
1250  // use the init function with plugin hook here, too
1251  self::initStyle();
1252 
1253  // $tpl
1254  $tpl = new ilTemplate("tpl.main.html", true, true);
1255  self::initGlobal("tpl", $tpl);
1257  {
1262  global $ilUser, $ilCtrl;
1263 
1264  require_once 'Services/User/classes/class.ilUserRequestTargetAdjustment.php';
1265  $request_adjuster = new ilUserRequestTargetAdjustment($ilUser, $ilCtrl);
1266  $request_adjuster->adjust();
1267  }
1268 
1269  // load style sheet depending on user's settings
1270  $location_stylesheet = ilUtil::getStyleSheetLocation();
1271  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
1272 
1273  require_once "./Services/UICore/classes/class.ilFrameTargetInfo.php";
1274 
1275  self::initGlobal("ilNavigationHistory", "ilNavigationHistory",
1276  "Services/Navigation/classes/class.ilNavigationHistory.php");
1277 
1278  self::initGlobal("ilBrowser", "ilBrowser",
1279  "./Services/Utilities/classes/class.ilBrowser.php");
1280 
1281  self::initGlobal("ilHelp", "ilHelpGUI",
1282  "Services/Help/classes/class.ilHelpGUI.php");
1283 
1284  self::initGlobal("ilToolbar", "ilToolbarGUI",
1285  "./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php");
1286 
1287  self::initGlobal("ilLocator", "ilLocatorGUI",
1288  "./Services/Locator/classes/class.ilLocatorGUI.php");
1289 
1290  self::initGlobal("ilTabs", "ilTabsGUI",
1291  "./Services/UIComponent/Tabs/classes/class.ilTabsGUI.php");
1292 
1293  // $ilMainMenu
1294  include_once './Services/MainMenu/classes/class.ilMainMenuGUI.php';
1295  $ilMainMenu = new ilMainMenuGUI("_top");
1296  self::initGlobal("ilMainMenu", $ilMainMenu);
1297  unset($ilMainMenu);
1298 
1299 
1300  // :TODO: tableGUI related
1301 
1302  // set hits per page for all lists using table module
1303  $_GET['limit'] = (int) $ilUser->getPref('hits_per_page');
1304  ilSession::set('tbl_limit', $_GET['limit']);
1305 
1306  // the next line makes it impossible to save the offset somehow in a session for
1307  // a specific table (I tried it for the user administration).
1308  // its not posssible to distinguish whether it has been set to page 1 (=offset = 0)
1309  // or not set at all (then we want the last offset, e.g. being used from a session var).
1310  // So I added the wrapping if statement. Seems to work (hopefully).
1311  // Alex April 14th 2006
1312  if (isset($_GET['offset']) && $_GET['offset'] != "") // added April 14th 2006
1313  {
1314  $_GET['offset'] = (int) $_GET['offset']; // old code
1315  }
1316  }
1317 
1323  protected static function getCurrentCmd()
1324  {
1325  $cmd = $_REQUEST["cmd"];
1326  if(is_array($cmd))
1327  {
1328  return array_shift(array_keys($cmd));
1329  }
1330  else
1331  {
1332  return $cmd;
1333  }
1334  }
1335 
1341  protected static function blockedAuthentication($a_current_script)
1342  {
1343  if($a_current_script == "register.php" ||
1344  $a_current_script == "pwassist.php" ||
1345  $a_current_script == "confirmReg.php" ||
1346  $a_current_script == "il_securimage_play.php" ||
1347  $a_current_script == "il_securimage_show.php")
1348  {
1349  return true;
1350  }
1351 
1352  if($_REQUEST["baseClass"] == "ilStartUpGUI")
1353  {
1354  $cmd_class = $_REQUEST["cmdClass"];
1355 
1356  if($cmd_class == "ilaccountregistrationgui" ||
1357  $cmd_class == "ilpasswordassistancegui")
1358  {
1359  return true;
1360  }
1361 
1363  if($cmd == "showTermsOfService" || $cmd == "showClientList" ||
1364  $cmd == 'showAccountMigration' || $cmd == 'migrateAccount' ||
1365  $cmd == 'processCode')
1366  {
1367  return true;
1368  }
1369  }
1370 
1371  // #12884
1372  if(($a_current_script == "goto.php" && $_GET["target"] == "impr_0") ||
1373  $_GET["baseClass"] == "ilImprintGUI")
1374  {
1375  return true;
1376  }
1377 
1378  return false;
1379  }
1380 
1386  protected static function showingLoginForm($a_current_script)
1387  {
1388  if($a_current_script == "login.php")
1389  {
1390  return true;
1391  }
1392 
1393  if($_REQUEST["baseClass"] == "ilStartUpGUI" &&
1394  self::getCurrentCmd() == "showLogin")
1395  {
1396  return true;
1397  }
1398 
1399  return false;
1400  }
1401 
1409  protected static function translateMessage($a_message_id, array $a_message_static = null)
1410  {
1411  global $ilDB, $lng, $ilSetting, $ilClientIniFile, $ilUser;
1412 
1413  // current language
1414  if(!$lng)
1415  {
1416  $lang = "en";
1417  if($ilUser)
1418  {
1419  $lang = $ilUser->getLanguage();
1420  }
1421  else if($_REQUEST["lang"])
1422  {
1423  $lang = (string)$_REQUEST["lang"];
1424  }
1425  else if($ilSetting)
1426  {
1427  $lang = $ilSetting->get("language");
1428  }
1429  else if($ilClientIniFile)
1430  {
1431  $lang = $ilClientIniFile->readVariable("language", "default");
1432  }
1433  }
1434  else
1435  {
1436  $lang = $lng->getLangKey();
1437  }
1438 
1439  $message = "";
1440  if($ilDB && $a_message_id)
1441  {
1442  if(!$lng)
1443  {
1444  require_once "./Services/Language/classes/class.ilLanguage.php";
1445  $lng = new ilLanguage($lang);
1446  }
1447 
1448  $lng->loadLanguageModule("init");
1449  $message = $lng->txt($a_message_id);
1450  }
1451  else if(is_array($a_message_static))
1452  {
1453  if(!isset($a_message_static[$lang]))
1454  {
1455  $lang = "en";
1456  }
1457  $message = $a_message_static[$lang];
1458  }
1459 
1460  return utf8_decode($message);
1461  }
1462 
1470  protected static function redirect($a_target, $a_message_id, $a_message_static)
1471  {
1472  // #12739
1473  if(defined("ILIAS_HTTP_PATH") &&
1474  !stristr($a_target, ILIAS_HTTP_PATH))
1475  {
1476  $a_target = ILIAS_HTTP_PATH."/".$a_target;
1477  }
1478 
1480  {
1481  ilUtil::redirect($a_target);
1482  }
1483  else
1484  {
1485  $message = self::translateMessage($a_message_id, $a_message_static);
1486 
1487  // user-directed linked message
1489  {
1490  $link = self::translateMessage("init_error_redirect_click",
1491  array("en" => 'Please click to continue.',
1492  "de" => 'Bitte klicken um fortzufahren.'));
1493  $mess = $message.
1494  '<br /><a href="'.$a_target.'">'.$link.'</a>';
1495  }
1496  // plain text
1497  else
1498  {
1499  // not much we can do here
1500  $mess = $message;
1501 
1502  if(!trim($mess))
1503  {
1504  $mess = self::translateMessage("init_error_redirect_info",
1505  array("en" => 'Redirect not supported by context.',
1506  "de" => 'Weiterleitungen werden durch Kontext nicht unterstützt.')).
1507  ' ('.$a_target.')';
1508  }
1509  }
1510 
1511  self::abortAndDie($mess);
1512  }
1513  }
1514 }
1515 
1516 ?>