00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00037 class ILIAS
00038 {
00043 var $INI_FILE;
00044
00050 var $dsn = "";
00051
00057 var $db;
00058
00064 var $tplPath = "./templates/";
00065
00071 var $account;
00072
00078 var $auth_params = array();
00079
00085 var $auth;
00086
00092 var $ini = array();
00093
00099 var $error_obj;
00100
00107 var $obj_factory;
00108
00115 var $styles;
00116
00123 var $skins;
00124
00130 function ILIAS($a_client_id = 0)
00131 {
00132 global $ilErr, $ilDB;
00133
00134
00135 $this->ini_ilias = new ilIniFile("./ilias.ini.php");
00136 $this->ini_ilias->read();
00137
00138 define("ILIAS_DATA_DIR",$this->ini_ilias->readVariable("clients","datadir"));
00139 define("ILIAS_WEB_DIR",$this->ini_ilias->readVariable("clients","path"));
00140
00141 $this->__buildHTTPPath();
00142 define ("ILIAS_ABSOLUTE_PATH",$this->ini_ilias->readVariable('server','absolute_path'));
00143
00144
00145 define ("ILIAS_LOG_DIR",$this->ini_ilias->readVariable("log","path"));
00146 define ("ILIAS_LOG_FILE",$this->ini_ilias->readVariable("log","file"));
00147 define ("ILIAS_LOG_ENABLED",$this->ini_ilias->readVariable("log","enabled"));
00148 define ("ILIAS_LOG_LEVEL",$this->ini_ilias->readVariable("log","level"));
00149
00150
00151 define ("PATH_TO_CONVERT",$this->ini_ilias->readVariable("tools","convert"));
00152 define ("PATH_TO_ZIP",$this->ini_ilias->readVariable("tools","zip"));
00153 define ("PATH_TO_UNZIP",$this->ini_ilias->readVariable("tools","unzip"));
00154 define ("PATH_TO_JAVA",$this->ini_ilias->readVariable("tools","java"));
00155 define ("PATH_TO_HTMLDOC",$this->ini_ilias->readVariable("tools","htmldoc"));
00156 define ("PATH_TO_FOP",$this->ini_ilias->readVariable("tools","fop"));
00157
00158
00159 switch ($this->ini_ilias->readVariable("tools", "vscantype"))
00160 {
00161 case "sophos":
00162 define("IL_VIRUS_SCANNER", "Sophos");
00163 define("IL_VIRUS_SCAN_COMMAND", $this->ini_ilias->readVariable("tools", "scancommand"));
00164 define("IL_VIRUS_CLEAN_COMMAND", $this->ini_ilias->readVariable("tools", "cleancommand"));
00165 break;
00166
00167 case "antivir":
00168 define("IL_VIRUS_SCANNER", "AntiVir");
00169 define("IL_VIRUS_SCAN_COMMAND", $this->ini_ilias->readVariable("tools", "scancommand"));
00170 define("IL_VIRUS_CLEAN_COMMAND", $this->ini_ilias->readVariable("tools", "cleancommand"));
00171 break;
00172
00173 default:
00174 define("IL_VIRUS_SCANNER", "None");
00175 break;
00176 }
00177
00178
00179 if (!$a_client_id)
00180 {
00181 $this->client_id = $this->ini_ilias->readVariable("clients","default");
00182 setcookie("ilClientId",$this->client_id);
00183 $_COOKIE["ilClientId"] = $this->client_id;
00184 }
00185 else
00186 {
00187 $this->client_id = $_COOKIE["ilClientId"];
00188 }
00189
00190 $this->INI_FILE = "./".ILIAS_WEB_DIR."/".$this->client_id."/client.ini.php";
00191
00192
00193
00194
00195 umask(0117);
00196
00197
00198 $this->ini = new ilIniFile($this->INI_FILE);
00199 $this->ini->read();
00200
00201
00202 if ($this->ini->ERROR != "")
00203 {
00204 ilUtil::redirect("./setup/setup.php");
00205 }
00206
00207 if (!$this->ini->readVariable("client","access"))
00208 {
00209 if (is_file("./maintenance.html"))
00210 {
00211 ilUtil::redirect("./maintenance.html");
00212 }
00213 else
00214 {
00215 echo '<br /><p style="text-align:center;">The server is not '.
00216 'available due to maintenance. We apologise for any inconvenience.</p>';
00217 exit;
00218 }
00219 }
00220
00221
00222 define ("DEBUG",$this->ini->readVariable("system","DEBUG"));
00223 define ("DEVMODE",$this->ini->readVariable("system","DEVMODE"));
00224 define ("ROOT_FOLDER_ID",$this->ini->readVariable('system','ROOT_FOLDER_ID'));
00225 define ("SYSTEM_FOLDER_ID",$this->ini->readVariable('system','SYSTEM_FOLDER_ID'));
00226 define ("ROLE_FOLDER_ID",$this->ini->readVariable('system','ROLE_FOLDER_ID'));
00227 define ("MAIL_SETTINGS_ID",$this->ini->readVariable('system','MAIL_SETTINGS_ID'));
00228
00229 define ("MAXLENGTH_OBJ_TITLE",$this->ini->readVariable('system','MAXLENGTH_OBJ_TITLE'));
00230 define ("MAXLENGTH_OBJ_DESC",$this->ini->readVariable('system','MAXLENGTH_OBJ_DESC'));
00231
00232 define ("CLIENT_DATA_DIR",ILIAS_DATA_DIR."/".$this->client_id);
00233 define ("CLIENT_WEB_DIR",ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->client_id);
00234 define ("CLIENT_ID",$this->client_id);
00235
00236
00237 $this->dsn = $this->ini->readVariable("db","type").
00238 "://".$this->ini->readVariable("db", "user").
00239 ":".$this->ini->readVariable("db", "pass").
00240 "@".$this->ini->readVariable("db", "host").
00241 "/".$this->ini->readVariable("db", "name");
00242
00243 $this->db = new ilDBx($this->dsn);
00244
00245
00246 $this->error_obj =& $ilErr;
00247
00248
00249 $ilDB = $this->db;
00250 $GLOBALS['ilDB'] =& $ilDB;
00251
00252
00253 if(ini_get('session.save_handler') != 'user')
00254 {
00255 ini_set("session.save_handler", "user");
00256 }
00257
00258
00259 if (!db_set_save_handler())
00260 {
00261 $message = "Please turn off Safe mode OR set session.save_handler to \"user\" in your php.ini";
00262 $this->raiseError($message, $this->error_obj->FATAL);
00263 }
00264
00265
00266 define ("ANONYMOUS_USER_ID",$this->getSetting("anonymous_user_id"));
00267 define ("ANONYMOUS_ROLE_ID",$this->getSetting("anonymous_role_id"));
00268 define ("SYSTEM_USER_ID",$this->getSetting("system_user_id"));
00269 define ("SYSTEM_ROLE_ID",$this->getSetting("system_role_id"));
00270 define ("RECOVERY_FOLDER_ID",$this->getSetting("recovery_folder_id"));
00271
00272
00273 define ("IL_INST_ID", $this->getSetting("inst_id"));
00274
00275
00276 define ("AUTH_LOCAL",1);
00277 define ("AUTH_LDAP",2);
00278 define ("AUTH_RADIUS",3);
00279 define ("AUTH_SCRIPT",4);
00280 define ("AUTH_SHIBBOLETH",5);
00281
00282
00283
00284 define ("AUTH_DEFAULT", $this->getSetting("auth_mode") ? $this->getSetting("auth_mode") : AUTH_LOCAL);
00285
00286
00287
00288
00289
00290
00291
00292
00293 if (empty($_SESSION) ||
00294 (!isset($_SESSION['_authsession']['registered']) ||
00295 $_SESSION['_authsession']['registered'] !== true))
00296 {
00297
00298 if ($_POST['username'] != '' and $_POST['password'] != '')
00299 {
00300 include_once(ILIAS_ABSOLUTE_PATH.'/classes/class.ilAuthUtils.php');
00301 $user_auth_mode = ilAuthUtils::_getAuthModeOfUser($_POST['username'],$_POST['password'],$this->db);
00302 }
00303 }
00304
00305
00306
00307 if (
00308 $this->getSetting("shib_active")
00309 && $_SERVER[$this->getSetting("shib_login")]
00310 )
00311 {
00312 define ("AUTH_CURRENT",AUTH_SHIBBOLETH);
00313 }
00314 else
00315 {
00316 define ("AUTH_CURRENT",$user_auth_mode);
00317 }
00318
00319 switch (AUTH_CURRENT)
00320 {
00321 case AUTH_LOCAL:
00322
00323 $this->auth_params = array(
00324 'dsn' => $this->dsn,
00325 'table' => $this->ini->readVariable("auth", "table"),
00326 'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00327 'passwordcol' => $this->ini->readVariable("auth", "passcol")
00328 );
00329
00330 $this->auth = new Auth("DB", $this->auth_params,"",false);
00331 break;
00332
00333 case AUTH_LDAP:
00334 $settings = $this->getAllSettings();
00335
00336
00337 $this->auth_params = array(
00338 'host' => $settings["ldap_server"],
00339 'port' => $settings["ldap_port"],
00340 'basedn' => $settings["ldap_basedn"],
00341 'userdn' => $settings["ldap_search_base"],
00342 'useroc' => $settings["ldap_objectclass"],
00343 'userattr' => $settings["ldap_login_key"]
00344 );
00345 $this->auth = new Auth("LDAP", $this->auth_params,"",false);
00346 break;
00347
00348 case AUTH_RADIUS:
00349 include_once('classes/class.ilRADIUSAuthentication.php');
00350 $radius_servers = ilRADIUSAuthentication::_getServers($this->db);
00351
00352 $settings = $this->getAllSettings();
00353
00354 foreach ($radius_servers as $radius_server)
00355 {
00356 $rad_params['servers'][] = array($radius_server,$settings["radius_port"],$settings["radius_shared_secret"]);
00357 }
00358
00359
00360
00361 $this->auth_params = $rad_params;
00362 $this->auth = new Auth("RADIUS", $this->auth_params,"",false);
00363 break;
00364
00365 case AUTH_SHIBBOLETH:
00366 $settings = $this->getAllSettings();
00367
00368
00369 $this->auth_params = array();
00370 $this->auth = new ShibAuth($this->auth_params,true);
00371 break;
00372
00373 default:
00374
00375 $this->auth_params = array(
00376 'dsn' => $this->dsn,
00377 'table' => $this->ini->readVariable("auth", "table"),
00378 'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00379 'passwordcol' => $this->ini->readVariable("auth", "passcol")
00380 );
00381
00382 $this->auth = new Auth("DB", $this->auth_params,"",false);
00383 break;
00384
00385 }
00386
00387 $this->auth->setIdle($this->ini->readVariable("session","expire"), false);
00388 $this->auth->setExpire(0);
00389 ini_set("session.cookie_lifetime", "0");
00390
00391
00392 require_once("classes/class.ilObjectFactory.php");
00393 $this->obj_factory =& new ilObjectFactory();
00394 }
00395
00401 function _ILIAS()
00402 {
00403 if ($this->ini->readVariable("db", "type") != "")
00404 {
00405 $this->db->disconnect();
00406 }
00407
00408 return true;
00409 }
00410
00411
00418 function setAuthError($a_error_obj)
00419 {
00420 $this->auth_error =& $a_error_obj;
00421 }
00422
00426 function &getAuthError()
00427 {
00428 return $this->auth_error;
00429 }
00430
00439 function getSetting($a_keyword, $a_default_value = false)
00440 {
00441
00442 if ($a_keyword == "ilias_version")
00443 {
00444 return ILIAS_VERSION;
00445 }
00446
00447 $query = "SELECT value FROM settings WHERE keyword='".$a_keyword."'";
00448 $res = $this->db->query($query);
00449
00450 if ($res->numRows() > 0)
00451 {
00452 $row = $res->fetchRow();
00453 return $row[0];
00454
00455 }
00456 else
00457 {
00458 return $a_default_value;
00459 }
00460 }
00461
00468 function deleteSetting($a_keyword)
00469 {
00470 $query = "DELETE FROM settings WHERE keyword = '".$a_keyword."'";
00471 $this->db->query($query);
00472
00473 return true;
00474 }
00475
00476
00482 function getAllSettings()
00483 {
00484 $query = "SELECT * FROM settings";
00485 $res = $this->db->query($query);
00486
00487 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00488 {
00489 $arr[$row["keyword"]] = $row["value"];
00490
00491 }
00492
00493 return $arr;
00494 }
00495
00505 function setSetting($a_key, $a_val)
00506 {
00507 $sql = "DELETE FROM settings WHERE keyword='".$a_key."'";
00508 $r = $this->db->query($sql);
00509
00510 $sql = "INSERT INTO settings (keyword, value) VALUES ('".$a_key."','".addslashes($a_val)."')";
00511 $r = $this->db->query($sql);
00512
00513 return true;
00514 }
00515
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00608 function getFirstStyle($a_skin)
00609 {
00610 if (!is_array($this->styles))
00611 {
00612 $this->getStyles($a_skin);
00613 }
00614
00615 return $this->styles[0]["name"];
00616 }
00617
00624 function checkTemplate($a_name)
00625 {
00626 return file_exists($this->tplPath.$a_name);
00627 }
00628
00632 function &getCurrentUser()
00633 {
00634 return $this->account;
00635 }
00636
00637 function getClientId()
00638 {
00639 return $this->client_id;
00640 }
00641
00645 function raiseError($a_msg,$a_err_obj)
00646 {
00647 global $ilErr;
00648
00649 $ilErr->raiseError($a_msg,$a_err_obj);
00650 }
00651
00652
00653 function __buildHTTPPath()
00654 {
00655 if($_SERVER['HTTPS'] == 'on')
00656 {
00657 $protocol = 'https://';
00658 }
00659 else
00660 {
00661 $protocol = 'http://';
00662 }
00663 $host = $_SERVER['HTTP_HOST'];
00664
00665 if(!defined('ILIAS_MODULE'))
00666 {
00667 $path = pathinfo($_SERVER['REQUEST_URI']);
00668 if(!$path['extension'])
00669 {
00670 $uri = $_SERVER['REQUEST_URI'];
00671 }
00672 else
00673 {
00674 $uri = dirname($_SERVER['REQUEST_URI']);
00675 }
00676 }
00677 else
00678 {
00679
00680 $path = dirname($_SERVER['REQUEST_URI']);
00681
00682
00683
00684 $module = ilUtil::removeTrailingPathSeparators(ILIAS_MODULE);
00685
00686 $dirs = explode('/',$module);
00687 $uri = $path;
00688 foreach($dirs as $dir)
00689 {
00690 $uri = dirname($uri);
00691 }
00692 }
00693 return define('ILIAS_HTTP_PATH',$protocol.$host.$uri);
00694 }
00695
00696 }
00697 ?>