ILIAS  release_4-3 Revision
 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_JAVA",$ilIliasIniFile->readVariable("tools","java"));
140  define ("PATH_TO_HTMLDOC",$ilIliasIniFile->readVariable("tools","htmldoc"));
141  define ("URL_TO_LATEX",$ilIliasIniFile->readVariable("tools","latex"));
142  define ("PATH_TO_FOP",$ilIliasIniFile->readVariable("tools","fop"));
143 
144  // read virus scanner settings
145  switch ($ilIliasIniFile->readVariable("tools", "vscantype"))
146  {
147  case "sophos":
148  define("IL_VIRUS_SCANNER", "Sophos");
149  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
150  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
151  break;
152 
153  case "antivir":
154  define("IL_VIRUS_SCANNER", "AntiVir");
155  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
156  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
157  break;
158 
159  case "clamav":
160  define("IL_VIRUS_SCANNER", "ClamAV");
161  define("IL_VIRUS_SCAN_COMMAND", $ilIliasIniFile->readVariable("tools", "scancommand"));
162  define("IL_VIRUS_CLEAN_COMMAND", $ilIliasIniFile->readVariable("tools", "cleancommand"));
163  break;
164 
165  default:
166  define("IL_VIRUS_SCANNER", "None");
167  break;
168  }
169 
170  $tz = $ilIliasIniFile->readVariable("server","timezone");
171  if ($tz != "")
172  {
173  if (function_exists('date_default_timezone_set'))
174  {
175  date_default_timezone_set($tz);
176  }
177  }
178  define ("IL_TIMEZONE", $ilIliasIniFile->readVariable("server","timezone"));
179  }
180 
184  protected static function buildHTTPPath()
185  {
186  include_once './Services/Http/classes/class.ilHTTPS.php';
187  $https = new ilHTTPS();
188 
189  if($https->isDetected())
190  {
191  $protocol = 'https://';
192  }
193  else
194  {
195  $protocol = 'http://';
196  }
197  $host = $_SERVER['HTTP_HOST'];
198 
199  $rq_uri = $_SERVER['REQUEST_URI'];
200 
201  // security fix: this failed, if the URI contained "?" and following "/"
202  // -> we remove everything after "?"
203  if (is_int($pos = strpos($rq_uri, "?")))
204  {
205  $rq_uri = substr($rq_uri, 0, $pos);
206  }
207 
208  if(!defined('ILIAS_MODULE'))
209  {
210  $path = pathinfo($rq_uri);
211  if(!$path['extension'])
212  {
213  $uri = $rq_uri;
214  }
215  else
216  {
217  $uri = dirname($rq_uri);
218  }
219  }
220  else
221  {
222  // if in module remove module name from HTTP_PATH
223  $path = dirname($rq_uri);
224 
225  // dirname cuts the last directory from a directory path e.g content/classes return content
226 
228 
229  $dirs = explode('/',$module);
230  $uri = $path;
231  foreach($dirs as $dir)
232  {
233  $uri = dirname($uri);
234  }
235  }
236 
237  return define('ILIAS_HTTP_PATH',ilUtil::removeTrailingPathSeparators($protocol.$host.$uri));
238  }
239 
244  protected static function determineClient()
245  {
246  global $ilIliasIniFile;
247 
248  // check whether ini file object exists
249  if (!is_object($ilIliasIniFile))
250  {
251  self::abortAndDie("Fatal Error: ilInitialisation::determineClient called without initialisation of ILIAS ini file object.");
252  }
253 
254  // set to default client if empty
255  if ($_GET["client_id"] != "")
256  {
257  $_GET["client_id"] = ilUtil::stripSlashes($_GET["client_id"]);
258  if (!defined("IL_PHPUNIT_TEST"))
259  {
260  ilUtil::setCookie("ilClientId", $_GET["client_id"]);
261  }
262  }
263  else if (!$_COOKIE["ilClientId"])
264  {
265  // to do: ilias ini raus nehmen
266  $client_id = $ilIliasIniFile->readVariable("clients","default");
267  ilUtil::setCookie("ilClientId", $client_id);
268  }
269  if (!defined("IL_PHPUNIT_TEST"))
270  {
271  define ("CLIENT_ID", $_COOKIE["ilClientId"]);
272  }
273  else
274  {
275  define ("CLIENT_ID", $_GET["client_id"]);
276  }
277  }
278 
291  protected static function initClientIniFile()
292  {
293  global $ilIliasIniFile;
294 
295  // check whether ILIAS_WEB_DIR is set.
296  if (ILIAS_WEB_DIR == "")
297  {
298  self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without ILIAS_WEB_DIR.");
299  }
300 
301  // check whether CLIENT_ID is set.
302  if (CLIENT_ID == "")
303  {
304  self::abortAndDie("Fatal Error: ilInitialisation::initClientIniFile called without CLIENT_ID.");
305  }
306 
307  $ini_file = "./".ILIAS_WEB_DIR."/".CLIENT_ID."/client.ini.php";
308 
309  // get settings from ini file
310  require_once("./Services/Init/classes/class.ilIniFile.php");
311  $ilClientIniFile = new ilIniFile($ini_file);
312  $ilClientIniFile->read();
313 
314  // invalid client id / client ini
315  if ($ilClientIniFile->ERROR != "")
316  {
317  $c = $_COOKIE["ilClientId"];
318  $default_client = $ilIliasIniFile->readVariable("clients","default");
319  ilUtil::setCookie("ilClientId", $default_client);
320  if (CLIENT_ID != "" && CLIENT_ID != $default_client)
321  {
322  self::redirect("index.php?client_id=".$default_client,
323  "Client does not exist.");
324  }
325  else
326  {
327  self::abortAndDie("Invalid client");
328  }
329  }
330 
331  self::initGlobal("ilClientIniFile", $ilClientIniFile);
332 
333  // set constants
334  define ("SESSION_REMINDER_LEADTIME", 30);
335  define ("DEBUG",$ilClientIniFile->readVariable("system","DEBUG"));
336  define ("DEVMODE",$ilClientIniFile->readVariable("system","DEVMODE"));
337  define ("SHOWNOTICES",$ilClientIniFile->readVariable("system","SHOWNOTICES"));
338  define ("ROOT_FOLDER_ID",$ilClientIniFile->readVariable('system','ROOT_FOLDER_ID'));
339  define ("SYSTEM_FOLDER_ID",$ilClientIniFile->readVariable('system','SYSTEM_FOLDER_ID'));
340  define ("ROLE_FOLDER_ID",$ilClientIniFile->readVariable('system','ROLE_FOLDER_ID'));
341  define ("MAIL_SETTINGS_ID",$ilClientIniFile->readVariable('system','MAIL_SETTINGS_ID'));
342 
343  // this is for the online help installation, which sets OH_REF_ID to the
344  // ref id of the online module
345  define ("OH_REF_ID",$ilClientIniFile->readVariable("system","OH_REF_ID"));
346 
347  define ("SYSTEM_MAIL_ADDRESS",$ilClientIniFile->readVariable('system','MAIL_SENT_ADDRESS')); // Change SS
348  define ("MAIL_REPLY_WARNING",$ilClientIniFile->readVariable('system','MAIL_REPLY_WARNING')); // Change SS
349 
350  define ("MAXLENGTH_OBJ_TITLE",125);#$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_TITLE'));
351  define ("MAXLENGTH_OBJ_DESC",$ilClientIniFile->readVariable('system','MAXLENGTH_OBJ_DESC'));
352 
353  define ("CLIENT_DATA_DIR",ILIAS_DATA_DIR."/".CLIENT_ID);
354  define ("CLIENT_WEB_DIR",ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".CLIENT_ID);
355  define ("CLIENT_NAME",$ilClientIniFile->readVariable('client','name')); // Change SS
356 
357  $val = $ilClientIniFile->readVariable("db","type");
358  if ($val == "")
359  {
360  define ("IL_DB_TYPE", "mysql");
361  }
362  else
363  {
364  define ("IL_DB_TYPE", $val);
365  }
366 
367  return true;
368  }
369 
373  protected static function handleMaintenanceMode()
374  {
375  global $ilClientIniFile;
376 
377  if (!$ilClientIniFile->readVariable("client","access"))
378  {
379  $mess = "The server is not available due to maintenance.".
380  " We apologise for any inconvenience.";
381 
382  if (ilContext::hasHTML() && is_file("./maintenance.html"))
383  {
384  self::redirect("./maintenance.html", $mess);
385  }
386  else
387  {
388  self::abortAndDie($mess);
389  }
390  }
391  }
392 
397  protected static function initDatabase()
398  {
399  // build dsn of database connection and connect
400  require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
401  $ilDB = ilDBWrapperFactory::getWrapper(IL_DB_TYPE);
402  $ilDB->initFromIniFile();
403  $ilDB->connect();
404 
405  self::initGlobal("ilDB", $ilDB);
406  }
407 
413  public static function setSessionHandler()
414  {
415  if(ini_get('session.save_handler') != 'user')
416  {
417  ini_set("session.save_handler", "user");
418  }
419 
420  require_once "Services/Authentication/classes/class.ilSessionDBHandler.php";
421  $db_session_handler = new ilSessionDBHandler();
422  if (!$db_session_handler->setSaveHandler())
423  {
424  self::abortAndDie("Please turn off Safe mode OR set session.save_handler to \"user\" in your php.ini");
425  }
426 
427  // Do not accept external session ids
428  if (!ilSession::_exists(session_id()) && !defined('IL_PHPUNIT_TEST'))
429  {
430  session_regenerate_id();
431  }
432  }
433 
437  protected static function setCookieParams()
438  {
439  include_once 'Services/Authentication/classes/class.ilAuthFactory.php';
441  {
442  $cookie_path = '/';
443  }
444  elseif ($GLOBALS['COOKIE_PATH'])
445  {
446  // use a predefined cookie path from WebAccessChecker
447  $cookie_path = $GLOBALS['COOKIE_PATH'];
448  }
449  else
450  {
451  $cookie_path = dirname( $_SERVER['PHP_SELF'] );
452  }
453 
454  /* if ilias is called directly within the docroot $cookie_path
455  is set to '/' expecting on servers running under windows..
456  here it is set to '\'.
457  in both cases a further '/' won't be appended due to the following regex
458  */
459  $cookie_path .= (!preg_match("/[\/|\\\\]$/", $cookie_path)) ? "/" : "";
460 
461  if($cookie_path == "\\") $cookie_path = '/';
462 
463  define('IL_COOKIE_EXPIRE',0);
464  define('IL_COOKIE_PATH',$cookie_path);
465  define('IL_COOKIE_DOMAIN','');
466  define('IL_COOKIE_SECURE',false); // Default Value
467 
468  // session_set_cookie_params() supports 5th parameter
469  // only for php version 5.2.0 and above
470  if( version_compare(PHP_VERSION, '5.2.0', '>=') )
471  {
472  // PHP version >= 5.2.0
473  define('IL_COOKIE_HTTPONLY',false); // Default Value
474  session_set_cookie_params(
475  IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, IL_COOKIE_SECURE, IL_COOKIE_HTTPONLY
476  );
477  }
478  else
479  {
480  // PHP version < 5.2.0
481  session_set_cookie_params(
482  IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, IL_COOKIE_SECURE
483  );
484  }
485  }
486 
492  protected static function initSettings()
493  {
494  global $ilSetting;
495 
496  self::initGlobal("ilSetting", "ilSetting",
497  "Services/Administration/classes/class.ilSetting.php");
498 
499  // check correct setup
500  if (!$ilSetting->get("setup_ok"))
501  {
502  self::abortAndDie("Setup is not completed. Please run setup routine again.");
503  }
504 
505  // set anonymous user & role id and system role id
506  define ("ANONYMOUS_USER_ID", $ilSetting->get("anonymous_user_id"));
507  define ("ANONYMOUS_ROLE_ID", $ilSetting->get("anonymous_role_id"));
508  define ("SYSTEM_USER_ID", $ilSetting->get("system_user_id"));
509  define ("SYSTEM_ROLE_ID", $ilSetting->get("system_role_id"));
510  define ("USER_FOLDER_ID", 7);
511 
512  // recovery folder
513  define ("RECOVERY_FOLDER_ID", $ilSetting->get("recovery_folder_id"));
514 
515  // installation id
516  define ("IL_INST_ID", $ilSetting->get("inst_id",0));
517 
518  // define default suffix replacements
519  define ("SUFFIX_REPL_DEFAULT", "php,php3,php4,inc,lang,phtml,htaccess");
520  define ("SUFFIX_REPL_ADDITIONAL", $ilSetting->get("suffix_repl_additional"));
521 
522  if(ilContext::usesHTTP())
523  {
525  }
526 
527  // payment setting
528  require_once('Services/Payment/classes/class.ilPaymentSettings.php');
529  define('IS_PAYMENT_ENABLED', ilPaymentSettings::_isPaymentEnabled());
530  }
531 
535  protected static function initStyle()
536  {
537  global $styleDefinition, $ilPluginAdmin;
538 
539  // load style definitions
540  self::initGlobal("styleDefinition", "ilStyleDefinition",
541  "./Services/Style/classes/class.ilStyleDefinition.php");
542 
543  // add user interface hook for style initialisation
544  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
545  foreach ($pl_names as $pl)
546  {
547  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
548  $gui_class = $ui_plugin->getUIClassInstance();
549  $gui_class->modifyGUI("Services/Init", "init_style", array("styleDefinition" => $styleDefinition));
550  }
551 
552  $styleDefinition->startParsing();
553  }
554 
558  public static function initUserAccount()
559  {
560  global $ilUser;
561 
562  // get user id
563  if (!ilSession::get("AccountId"))
564  {
565  ilSession::set("AccountId", $ilUser->checkUserId());
566  }
567 
568  $uid = ilSession::get("AccountId");
569  if($uid)
570  {
571  $ilUser->setId($uid);
572  $ilUser->read();
573 
574  // #10822 - Terms of service accepted?
575  self::checkUserAgreement($ilUser);
576  }
577  else
578  {
579  if(is_object($GLOBALS['ilLog']))
580  {
581  $GLOBALS['ilLog']->logStack();
582  }
583  self::abortAndDie("Init user account failed");
584  }
585  }
586 
592  protected static function checkUserAgreement(ilObjUser $a_user)
593  {
594  // are we currently in user agreement acceptance?
595  if (strtolower($_GET["cmdClass"]) == "ilstartupgui" &&
596  (strtolower($_GET["cmd"]) == "getacceptance" ||
597  (is_array($_POST["cmd"]) &&
598  key($_POST["cmd"]) == "getAcceptance")))
599  {
600  return;
601  }
602 
603  if(!$a_user->hasAcceptedUserAgreement() &&
604  $a_user->getId() != ANONYMOUS_USER_ID &&
605  $a_user->checkTimeLimit())
606  {
607  if(!defined('IL_CERT_SSO'))
608  {
609  self::redirect('ilias.php?baseClass=ilStartUpGUI&cmdClass=ilstartupgui&target='.$_GET['target'].'&cmd=getAcceptance',
610  'User Agreement not accepted.');
611  }
612  }
613  }
614 
618  protected static function initLocale()
619  {
620  global $ilSetting;
621 
622  if (trim($ilSetting->get("locale") != ""))
623  {
624  $larr = explode(",", trim($ilSetting->get("locale")));
625  $ls = array();
626  $first = $larr[0];
627  foreach ($larr as $l)
628  {
629  if (trim($l) != "")
630  {
631  $ls[] = $l;
632  }
633  }
634  if (count($ls) > 0)
635  {
636  setlocale(LC_ALL, $ls);
637  if (class_exists("Collator"))
638  {
639  $GLOBALS["ilCollator"] = new Collator($first);
640  }
641  }
642  }
643  }
644 
650  public static function goToPublicSection($a_auth_stat = "")
651  {
652  global $ilAuth;
653 
654  if (ANONYMOUS_USER_ID == "")
655  {
656  self::abortAndDie("Public Section enabled, but no Anonymous user found.");
657  }
658 
659  // logout and end previous session
660  if($a_auth_stat == AUTH_EXPIRED ||
661  $a_auth_stat == AUTH_IDLED)
662  {
664  }
665  else
666  {
668  }
669  $ilAuth->logout();
670  session_unset();
671  session_destroy();
672 
673  // new session and login as anonymous
675  session_start();
676  $_POST["username"] = "anonymous";
677  $_POST["password"] = "anonymous";
679 
680  // authenticate (anonymous)
681  $oldSid = session_id();
682  $ilAuth->start();
683  if (IS_PAYMENT_ENABLED)
684  {
685  $newSid = session_id();
686  if($oldSid != $newSid)
687  {
688  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
689  ilPaymentShoppingCart::_migrateShoppingCart($oldSid, $newSid);
690  }
691  }
692 
693  if (!$ilAuth->getAuth())
694  {
695  self::abortAndDie("ANONYMOUS user with the object_id ".ANONYMOUS_USER_ID." not found!");
696  }
697 
699 
700  $mess = "Authentication failed.";
701 
702  // if target given, try to go there
703  if ($_GET["target"] != "")
704  {
705  // when we are already "inside" goto.php no redirect is needed
706  $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
707  if($current_script == "goto.php")
708  {
709  return;
710  }
711 
712  // goto will check if target is accessible or redirect to login
713  self::redirect("goto.php?target=".$_GET["target"], $mess);
714  }
715 
716  // we do not know if ref_id of request is accesible, so redirecting to root
717  $_GET["ref_id"] = ROOT_FOLDER_ID;
718  $_GET["cmd"] = "frameset";
719  self::redirect("ilias.php?baseClass=ilrepositorygui&reloadpublic=1&cmd=".
720  $_GET["cmd"]."&ref_id=".$_GET["ref_id"], $mess);
721  }
722 
728  protected static function goToLogin($a_auth_stat = "")
729  {
730  global $ilAuth;
731 
732  // close current session
733  if($a_auth_stat == AUTH_EXPIRED ||
734  $a_auth_stat == AUTH_IDLED)
735  {
737  }
738  else
739  {
741  }
742  $ilAuth->logout();
743  session_unset();
744  session_destroy();
745 
746  $add = "";
747  if ($_GET["soap_pw"] != "")
748  {
749  $add = "&soap_pw=".$_GET["soap_pw"]."&ext_uid=".$_GET["ext_uid"];
750  }
751 
752  $script = "login.php?target=".$_GET["target"]."&client_id=".$_COOKIE["ilClientId"].
753  "&auth_stat=".$a_auth_stat.$add;
754 
755  self::redirect($script, "Authentication failed.");
756  }
757 
761  protected static function initLanguage()
762  {
763  global $ilUser, $ilSetting, $rbacsystem;
764 
765  if (!ilSession::get("lang"))
766  {
767  if ($_GET['lang'])
768  {
769  $_GET['lang'] = $_GET['lang'];
770  }
771  else
772  {
773  if (is_object($ilUser))
774  {
775  $_GET['lang'] = $ilUser->getPref('language');
776  }
777  }
778  }
779 
780  if (isset($_POST['change_lang_to']) && $_POST['change_lang_to'] != "")
781  {
782  $_GET['lang'] = ilUtil::stripSlashes($_POST['change_lang_to']);
783  }
784 
785  // prefer personal setting when coming from login screen
786  // Added check for ilUser->getId > 0 because it is 0 when the language is changed and the user agreement should be displayes (Helmut Schottm��ller, 2006-10-14)
787  if (is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID && $ilUser->getId() > 0)
788  {
789  ilSession::set('lang', $ilUser->getPref('language'));
790  }
791 
792  ilSession::set('lang', (isset($_GET['lang']) && $_GET['lang']) ? $_GET['lang'] : ilSession::get('lang'));
793 
794  // check whether lang selection is valid
795  require_once "./Services/Language/classes/class.ilLanguage.php";
797  if (!in_array(ilSession::get('lang'), $langs))
798  {
799  if (is_object($ilSetting) && $ilSetting->get('language') != '')
800  {
801  ilSession::set('lang', $ilSetting->get('language'));
802  }
803  else
804  {
805  ilSession::set('lang', $langs[0]);
806  }
807  }
808  $_GET['lang'] = ilSession::get('lang');
809 
810  $lng = new ilLanguage(ilSession::get('lang'));
811  self::initGlobal('lng', $lng);
812 
813  if(is_object($rbacsystem))
814  {
815  $rbacsystem->initMemberView();
816  }
817  }
818 
822  protected static function initAccessHandling()
823  {
824  self::initGlobal("rbacreview", "ilRbacReview",
825  "./Services/AccessControl/classes/class.ilRbacReview.php");
826 
827  require_once "./Services/AccessControl/classes/class.ilRbacSystem.php";
828  $rbacsystem = ilRbacSystem::getInstance();
829  self::initGlobal("rbacsystem", $rbacsystem);
830 
831  self::initGlobal("rbacadmin", "ilRbacAdmin",
832  "./Services/AccessControl/classes/class.ilRbacAdmin.php");
833 
834  self::initGlobal("ilAccess", "ilAccessHandler",
835  "./Services/AccessControl/classes/class.ilAccessHandler.php");
836 
837  require_once "./Services/AccessControl/classes/class.ilConditionHandler.php";
838  }
839 
843  protected static function initLog()
844  {
845  require_once "./Services/Logging/classes/class.ilLog.php";
846  $log = new ilLog(ILIAS_LOG_DIR,ILIAS_LOG_FILE,CLIENT_ID,ILIAS_LOG_ENABLED,ILIAS_LOG_LEVEL);
847  self::initGlobal("ilLog", $log);
848 
849  // deprecated
850  self::initGlobal("log", $log);
851  }
852 
860  protected static function initGlobal($a_name, $a_class, $a_source_file = null)
861  {
862  if($a_source_file)
863  {
864  include_once $a_source_file;
865  $GLOBALS[$a_name] = new $a_class;
866  }
867  else
868  {
869  $GLOBALS[$a_name] = $a_class;
870  }
871  }
872 
878  protected static function abortAndDie($a_message)
879  {
880  if(is_object($GLOBALS['ilLog']))
881  {
882  $GLOBALS['ilLog']->write("Fatal Error: ilInitialisation - ".$a_message);
883  }
884  die($a_message);
885  }
886 
890  protected static function handleDevMode()
891  {
892  if(defined(SHOWNOTICES) && SHOWNOTICES)
893  {
894  // no further differentiating of php version regarding to 5.4 neccessary
895  // when the error reporting is set to E_ALL anyway
896 
897  // remove notices from error reporting
898  if (version_compare(PHP_VERSION, '5.3.0', '>='))
899  {
900  error_reporting(E_ALL);
901  }
902  else
903  {
904  error_reporting(E_ALL);
905  }
906  }
907 
908  include_once "include/inc.debug.php";
909  }
910 
914  public static function initILIAS()
915  {
916  global $tree;
917 
918  self::initCore();
919 
921  {
923 
924  if (ilContext::hasUser())
925  {
926  self::initUser();
927 
929  {
931  }
932  }
933 
934  // init after Auth otherwise breaks CAS
936 
937  // language may depend on user setting
939  $tree->initLangCode();
940 
941  if(ilContext::hasHTML())
942  {
943  include_once('./Services/WebServices/ECS/classes/class.ilECSTaskScheduler.php');
945 
946  self::initHTML();
947  }
948  }
949  }
950 
954  protected static function initCore()
955  {
956  global $ilErr;
957 
958  // remove notices from error reporting
959  if (version_compare(PHP_VERSION, '5.4.0', '>='))
960  {
961  // Prior to PHP 5.4.0 E_ALL does not include E_STRICT.
962  // With PHP 5.4.0 and above E_ALL >DOES< include E_STRICT.
963 
964  error_reporting(((ini_get("error_reporting") & ~E_NOTICE) & ~E_DEPRECATED) & ~E_STRICT);
965  }
966  elseif (version_compare(PHP_VERSION, '5.3.0', '>='))
967  {
968  error_reporting((ini_get("error_reporting") & ~E_NOTICE) & ~E_DEPRECATED);
969  }
970  else
971  {
972  error_reporting(ini_get('error_reporting') & ~E_NOTICE);
973  }
974  // breaks CAS: must be included after CAS context isset in AuthUtils
975  //self::includePhp5Compliance();
976 
978 
979 
980  // error handler
981  self::initGlobal("ilErr", "ilErrorHandling",
982  "./Services/Init/classes/class.ilErrorHandling.php");
983  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK, array($ilErr, 'errorHandler'));
984 
985  // :TODO: obsolete?
986  PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ilErr, "errorHandler"));
987 
988  // workaround: load old post variables if error handler 'message' was called
989  include_once "Services/Authentication/classes/class.ilSession.php";
990  if (ilSession::get("message"))
991  {
992  $_POST = ilSession::get("post_vars");
993  }
994 
996 
998 
999 
1001 
1002 
1003  // deprecated
1004  self::initGlobal("ilias", "ILIAS", "./Services/Init/classes/class.ilias.php");
1005  }
1006 
1010  protected static function initClient()
1011  {
1012  global $https, $ilias;
1013 
1015 
1017 
1018 
1019  // --- needs client ini
1020 
1021  $ilias->client_id = CLIENT_ID;
1022 
1023  if (DEVMODE)
1024  {
1026  }
1027 
1028  self::initLog();
1029 
1031 
1033 
1034 
1035  // --- needs database
1036 
1037  self::initGlobal("ilAppEventHandler", "ilAppEventHandler",
1038  "./Services/EventHandling/classes/class.ilAppEventHandler.php");
1039 
1040  // there are rare cases where initILIAS is called twice for a request
1041  // example goto.php is called and includes ilias.php later
1042  // we must prevent that ilPluginAdmin is initialized twice in
1043  // this case, since this won't get the values out of plugin.php the
1044  // second time properly
1045  if (!is_object($GLOBALS["ilPluginAdmin"]))
1046  {
1047  self::initGlobal("ilPluginAdmin", "ilPluginAdmin",
1048  "./Services/Component/classes/class.ilPluginAdmin.php");
1049  }
1050 
1052 
1054 
1055 
1056  // --- needs settings
1057 
1058  self::initLocale();
1059 
1060  if(ilContext::usesHTTP())
1061  {
1062  // $https
1063  self::initGlobal("https", "ilHTTPS", "./Services/Http/classes/class.ilHTTPS.php");
1064  $https->enableSecureCookies();
1065  $https->checkPort();
1066  }
1067 
1068 
1069  // --- object handling
1070 
1071  self::initGlobal("ilObjDataCache", "ilObjectDataCache",
1072  "./Services/Object/classes/class.ilObjectDataCache.php");
1073 
1074  // needed in ilObjectDefinition
1075  require_once "./Services/Xml/classes/class.ilSaxParser.php";
1076 
1077  self::initGlobal("objDefinition", "ilObjectDefinition",
1078  "./Services/Object/classes/class.ilObjectDefinition.php");
1079 
1080  // $tree
1081  require_once "./Services/Tree/classes/class.ilTree.php";
1082  $tree = new ilTree(ROOT_FOLDER_ID);
1083  self::initGlobal("tree", $tree);
1084  unset($tree);
1085 
1086  self::initGlobal("ilCtrl", "ilCtrl",
1087  "./Services/UICore/classes/class.ilCtrl.php");
1088  }
1089 
1093  protected static function initUser()
1094  {
1095  global $ilias, $ilAuth, $ilUser;
1096 
1097  if(ilContext::usesHTTP())
1098  {
1099  // allow login by submitting user data
1100  // in query string when DEVMODE is enabled
1101  if( DEVMODE
1102  && isset($_GET['username']) && strlen($_GET['username'])
1103  && isset($_GET['password']) && strlen($_GET['password'])
1104  ){
1105  $_POST['username'] = $_GET['username'];
1106  $_POST['password'] = $_GET['password'];
1107  }
1108  }
1109 
1110  // $ilAuth
1111  require_once "Auth/Auth.php";
1112  require_once "./Services/AuthShibboleth/classes/class.ilShibboleth.php";
1113  include_once("./Services/Authentication/classes/class.ilAuthUtils.php");
1115  $ilias->auth = $ilAuth;
1116 
1117  // $ilUser
1118  self::initGlobal("ilUser", "ilObjUser",
1119  "./Services/User/classes/class.ilObjUser.php");
1120  $ilias->account =& $ilUser;
1121 
1123 
1124 
1125  // force login
1126  if ((isset($_GET["cmd"]) && $_GET["cmd"] == "force_login"))
1127  {
1128  $ilAuth->logout();
1129 
1130  // we need to do this for the session statistics
1131  // could we use session_destroy() instead?
1132  // [this is done after every $ilAuth->logout() call elsewhere]
1134 
1135  // :TODO: keep session because of cart content?
1136  if(!isset($_GET['forceShoppingCartRedirect']))
1137  {
1138  $_SESSION = array();
1139  }
1140  else
1141  {
1142  ilSession::set("AccountId", "");
1143  }
1144  }
1145 
1146  }
1147 
1153  protected static function authenticate()
1154  {
1155  global $ilAuth, $ilias, $ilErr;
1156 
1157  $current_script = substr(strrchr($_SERVER["PHP_SELF"], "/"), 1);
1158 
1159  if(self::blockedAuthentication($current_script))
1160  {
1161  return;
1162  }
1163 
1164  $oldSid = session_id();
1165 
1166  $ilAuth->start();
1167  $ilias->setAuthError($ilErr->getLastError());
1168 
1169  if(IS_PAYMENT_ENABLED)
1170  {
1171  // cart is "attached" to session, has to be updated
1172  $newSid = session_id();
1173  if($oldSid != $newSid)
1174  {
1175  include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
1176  ilPaymentShoppingCart::_migrateShoppingCart($oldSid, $newSid);
1177  }
1178  }
1179 
1180  if($ilAuth->getAuth() && $ilAuth->getStatus() == '')
1181  {
1183 
1184  self::handleAuthenticationSuccess();
1185  }
1186  else
1187  {
1188  if (!self::showingLoginForm($current_script))
1189  {
1190  // :TODO: should be moved to context?!
1191  $mandatory_auth = ($current_script != "shib_login.php"
1192  && $current_script != "shib_logout.php"
1193  && $current_script != "error.php"
1194  && $current_script != "chat.php"
1195  && $current_script != "index.php"); // #10316
1196 
1197  if($mandatory_auth)
1198  {
1199  self::handleAuthenticationFail();
1200  }
1201  }
1202  }
1203  }
1204 
1208  protected static function handleAuthenticationSuccess()
1209  {
1213  global $ilUser;
1214 
1215  require_once 'Services/Tracking/classes/class.ilOnlineTracking.php';
1216  ilOnlineTracking::updateAccess($ilUser);
1217  }
1218 
1222  protected static function handleAuthenticationFail()
1223  {
1228  global $ilAuth, $ilSetting;
1229 
1230  // #10608
1232  {
1233  throw new Exception("Authentication failed.");
1234  }
1235 
1236  $status = $ilAuth->getStatus();
1237 
1238  if($ilSetting->get('pub_section') &&
1239  ($status == '' || $status == AUTH_EXPIRED || $status == AUTH_IDLED) &&
1240  $_GET['reloadpublic'] != '1'
1241  )
1242  {
1243  self::goToPublicSection($status);
1244  }
1245  else
1246  {
1247  self::goToLogin($status);
1248  }
1249  }
1250 
1254  protected static function initHTML()
1255  {
1256  global $ilUser;
1257 
1258  // load style definitions
1259  // use the init function with plugin hook here, too
1260  self::initStyle();
1261 
1262  // $tpl
1263  $tpl = new ilTemplate("tpl.main.html", true, true);
1264  self::initGlobal("tpl", $tpl);
1265 
1266  // load style sheet depending on user's settings
1267  $location_stylesheet = ilUtil::getStyleSheetLocation();
1268  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
1269 
1270  require_once "./Services/UICore/classes/class.ilFrameTargetInfo.php";
1271 
1272  self::initGlobal("ilNavigationHistory", "ilNavigationHistory",
1273  "Services/Navigation/classes/class.ilNavigationHistory.php");
1274 
1275  self::initGlobal("ilBrowser", "ilBrowser",
1276  "./Services/Utilities/classes/class.ilBrowser.php");
1277 
1278  self::initGlobal("ilHelp", "ilHelpGUI",
1279  "Services/Help/classes/class.ilHelpGUI.php");
1280 
1281  self::initGlobal("ilToolbar", "ilToolbarGUI",
1282  "./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php");
1283 
1284  self::initGlobal("ilLocator", "ilLocatorGUI",
1285  "./Services/Locator/classes/class.ilLocatorGUI.php");
1286 
1287  self::initGlobal("ilTabs", "ilTabsGUI",
1288  "./Services/UIComponent/Tabs/classes/class.ilTabsGUI.php");
1289 
1290  // $ilMainMenu
1291  include_once './Services/MainMenu/classes/class.ilMainMenuGUI.php';
1292  $ilMainMenu = new ilMainMenuGUI("_top");
1293  self::initGlobal("ilMainMenu", $ilMainMenu);
1294  unset($ilMainMenu);
1295 
1296 
1297  // :TODO: tableGUI related
1298 
1299  // set hits per page for all lists using table module
1300  $_GET['limit'] = (int) $ilUser->getPref('hits_per_page');
1301  ilSession::set('tbl_limit', $_GET['limit']);
1302 
1303  // the next line makes it impossible to save the offset somehow in a session for
1304  // a specific table (I tried it for the user administration).
1305  // its not posssible to distinguish whether it has been set to page 1 (=offset = 0)
1306  // or not set at all (then we want the last offset, e.g. being used from a session var).
1307  // So I added the wrapping if statement. Seems to work (hopefully).
1308  // Alex April 14th 2006
1309  if (isset($_GET['offset']) && $_GET['offset'] != "") // added April 14th 2006
1310  {
1311  $_GET['offset'] = (int) $_GET['offset']; // old code
1312  }
1313  }
1314 
1320  protected static function getCurrentCmd()
1321  {
1322  $cmd = $_REQUEST["cmd"];
1323  if(is_array($cmd))
1324  {
1325  return array_shift(array_keys($cmd));
1326  }
1327  else
1328  {
1329  return $cmd;
1330  }
1331  }
1332 
1338  protected static function blockedAuthentication($a_current_script)
1339  {
1340  if($a_current_script == "register.php" ||
1341  $a_current_script == "pwassist.php" ||
1342  $a_current_script == "confirmReg.php")
1343  {
1344  return true;
1345  }
1346 
1347  if($_REQUEST["baseClass"] == "ilStartUpGUI")
1348  {
1349  $cmd_class = $_REQUEST["cmdClass"];
1350 
1351  if($cmd_class == "ilaccountregistrationgui" ||
1352  $cmd_class == "ilpasswordassistancegui")
1353  {
1354  return true;
1355  }
1356 
1358  if($cmd == "showUserAgreement" || $cmd == "showClientList" ||
1359  $cmd == 'showAccountMigration' || $cmd == 'migrateAccount' ||
1360  $cmd == 'processCode')
1361  {
1362  return true;
1363  }
1364  }
1365 
1366  return false;
1367  }
1368 
1374  protected static function showingLoginForm($a_current_script)
1375  {
1376  if($a_current_script == "login.php")
1377  {
1378  return true;
1379  }
1380 
1381  if($_REQUEST["baseClass"] == "ilStartUpGUI" &&
1382  self::getCurrentCmd() == "showLogin")
1383  {
1384  return true;
1385  }
1386 
1387  return false;
1388  }
1389 
1396  protected static function redirect($a_target, $a_message_details)
1397  {
1398  // #12739
1399  if(defined("ILIAS_HTTP_PATH") &&
1400  !stristr($a_target, ILIAS_HTTP_PATH))
1401  {
1402  $a_target = ILIAS_HTTP_PATH."/".$a_target;
1403  }
1404 
1406  {
1407  ilUtil::redirect($a_target);
1408  }
1409  else
1410  {
1411  // user-directed linked message
1413  {
1414  $mess = $a_message_details.
1415  ' Please <a href="'.$a_target.'">click here</a> to continue.';
1416  }
1417  // plain text
1418  else
1419  {
1420  // not much we can do here
1421  $mess = $a_message_details;
1422 
1423  if(!trim($mess))
1424  {
1425  $mess = 'Redirect not supported by context ('.$a_target.')';
1426  }
1427  }
1428 
1429  self::abortAndDie($mess);
1430  }
1431  }
1432 }
1433 
1434 ?>