00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035 class ilSetup extends PEAR
00036 {
00037 var $ini;
00038 var $ini_file_path;
00039 var $error = "";
00040
00041 var $ini_ilias_exists = false;
00042 var $ini_client_exists = false;
00043
00044 var $setup_defaults;
00045 var $ilias_nic_server = "http://homer.ilias.uni-koeln.de/ilias-nic/index.php";
00046
00047 var $preliminaries_result = array();
00048 var $preliminaries = true;
00049
00055 var $SQL_FILE = "../sql/ilias3.sql";
00056
00062 var $dsn = "";
00063
00069 var $db;
00070
00071 var $setup_password;
00072 var $default_client;
00073
00074 var $safe_mode;
00075 var $safe_mode_exec_dir;
00076
00077 var $auth;
00078 var $access_mode;
00079
00086 function ilSetup($a_auth,$a_auth_type)
00087 {
00088 global $log;
00089
00090 $this->PEAR();
00091
00092 define("ILIAS_MODULE","setup");
00093
00094 $this->auth = ($a_auth) ? true : false;
00095 $this->access_mode = $a_auth_type;
00096
00097
00098 if ($this->safe_mode = ini_get("safe_mode"))
00099 {
00100 $this->safe_mode_exec_dir = ilFile::deleteTrailingSlash(ini_get("safe_mode_exec_dir"));
00101 }
00102
00103
00104 $this->error_obj = new ilErrorHandling();
00105 $this->setErrorHandling(PEAR_ERROR_CALLBACK,array($this->error_obj,'errorHandler'));
00106
00107
00108 $this->ini_file_path = ILIAS_ABSOLUTE_PATH."/ilias.ini.php";
00109 $this->setup_defaults = ILIAS_ABSOLUTE_PATH."/setup/ilias.master.ini.php";
00110
00111
00112 $this->ini_ilias_exists = $this->init();
00113
00114 if ($this->ini_ilias_exists)
00115 {
00116 if ($this->ini->readVariable("log","path") != "")
00117 {
00118 $log->path = $this->ini->readVariable("log","path");
00119 }
00120
00121 if ($this->ini->readVariable("log","file") != "")
00122 {
00123 $log->filename = $this->ini->readVariable("log","file");
00124 }
00125
00126 if ($this->ini->readVariable("log","enabled") != "")
00127 {
00128 $log->enabled = $this->ini->readVariable("log","enabled");
00129 }
00130 }
00131 }
00132
00138 function init()
00139 {
00140
00141 $this->ini = new ilIniFile($this->ini_file_path);
00142
00143 if (!$this->ini->read())
00144 {
00145 $this->ini->GROUPS = parse_ini_file($this->setup_defaults,true);
00146 $this->error = get_class($this).": ".$this->ini->getError();
00147 return false;
00148 }
00149
00150 $this->setup_password = $this->ini->readVariable("setup","pass");
00151 $this->default_client = $this->ini->readVariable("clients","default");
00152
00153 define("ILIAS_DATA_DIR",$this->ini->readVariable("clients","datadir"));
00154 define("ILIAS_WEB_DIR",$this->ini->readVariable("clients","path"));
00155
00156 return true;
00157 }
00158
00163 function saveNewClient()
00164 {
00165
00166 $_SESSION["ClientId"] = $this->client->getId();
00167
00168
00169 if (!$this->client->create())
00170 {
00171 $this->error = $this->client->getError();
00172 return false;
00173 }
00174
00175
00176 $this->ini_client_exists = true;
00177
00178 return true;
00179 }
00180
00186 function updateNewClient($a_old_client_id)
00187 {
00188 return true;
00189
00190
00191 if ($a_old_client_id != $this->client->getId())
00192 {
00193
00194 if (file_exists(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->client->getId()))
00195 {
00196 $this->raiseError($this->lng->txt("client_id_already_exists"),$this->error_obj->MESSAGE);
00197 }
00198
00199 if (!$this->saveNewClient())
00200 {
00201 $this->raiseError($this->lng->txt("save_error"),$this->error_obj->MESSAGE);
00202 }
00203
00204 ilUtil::delDir(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$a_old_client_id);
00205 ilUtil::delDir(ILIAS_DATA_DIR."/".$a_old_client_id);
00206 }
00207
00208
00209 $this->ini_client_exists = true;
00210
00211 return true;
00212 }
00213
00220 function execQuery($db,$str)
00221 {
00222 $sql = explode("\n",trim($str));
00223 for ($i=0; $i<count($sql); $i++)
00224 {
00225 $sql[$i] = trim($sql[$i]);
00226 if ($sql[$i] != "" && substr($sql[$i],0,1)!="#")
00227 {
00228
00229 if (substr($sql[$i],-1)==";")
00230 {
00231
00232 $q .= " ".substr($sql[$i],0,-1);
00233 $r = $db->query($q);
00234 if ($r == false)
00235 return false;
00236 unset($q);
00237 }
00238 else
00239 {
00240 $q .= " ".$sql[$i];
00241 }
00242 }
00243 }
00244 return true;
00245 }
00246
00251 function createDatabase($a_collation = "")
00252 {
00253 if ($this->client->checkDatabaseExists())
00254 {
00255 $this->error = $this->lng->txt("database_exists");
00256 return false;
00257 }
00258
00259
00260 $db = DB::connect($this->client->dsn_host);
00261 if (DB::isError($db))
00262 {
00263 $this->error = "connection_failed";
00264 return false;
00265 }
00266
00267 if ($a_collation != "")
00268 {
00269 $sql = "CREATE DATABASE ".$this->client->getdbName().
00270 " CHARACTER SET utf8".
00271 " COLLATE ".$a_collation;
00272 }
00273 else
00274 {
00275 $sql = "CREATE DATABASE ".$this->client->getdbName();
00276 }
00277 $r = $db->query($sql);
00278
00279 if (DB::isError($r))
00280 {
00281 $this->error = "create_database_failed";
00282 return false;
00283 }
00284
00285
00286 $db->disconnect();
00287
00288 $this->client->db_exists = true;
00289 return true;
00290 }
00291
00296 function installDatabase()
00297 {
00298 if (!$this->client->checkDatabaseHost())
00299 {
00300 $this->error = "no_connection_to_host";
00301 return false;
00302 }
00303
00304 if (!$this->client->connect())
00305 {
00306 return false;
00307 }
00308
00309
00310 if ($this->readDump($this->client->db, $this->SQL_FILE))
00311 {
00312 $this->client->db_installed = true;
00313 return true;
00314 }
00315 else
00316 {
00317 return false;
00318 }
00319 }
00320
00321 function getline( $fp, $delim )
00322 {
00323 $result = "";
00324 while( !feof( $fp ) )
00325 {
00326 $tmp = fgetc( $fp );
00327 if( $tmp == $delim )
00328 return $result;
00329 $result .= $tmp;
00330 }
00331 return $result;
00332 }
00333
00340 function readDump($db, $file)
00341 {
00342 $fp = fopen($file, 'r');
00343
00344 while(!feof($fp))
00345 {
00346
00347 $line = trim($this->getline($fp, "\n"));
00348
00349 if ($line != "" && substr($line,0,1)!="#"
00350 && substr($line,0,1)!="-")
00351 {
00352
00353 if (substr($line,-1)==";")
00354 {
00355
00356 $q .= " ".substr($line,0,-1);
00357 $r = $db->query($q);
00358 if (mysql_errno() > 0)
00359 {
00360 echo "<br />ERROR: ".mysql_error().
00361 "<br />SQL: $q";
00362 return false;
00363 }
00364 unset($q);
00365 unset($line);
00366 }
00367 else
00368 {
00369 $q .= " ".$line;
00370 }
00371 }
00372 }
00373
00374 fclose($fp);
00375 return true;
00376 }
00377
00378
00383 function checkIniFileExists()
00384 {
00385 $a = @file_exists($this->INI_FILE);
00386 return $a;
00387 }
00388
00394 function checkWritable($a_dir = "..")
00395 {
00396 clearstatcache();
00397 if (is_writable($a_dir))
00398 {
00399 $arr["status"] = true;
00400 $arr["comment"] = "";
00401 }
00402 else
00403 {
00404 $arr["status"] = false;
00405 $arr["comment"] = $this->lng->txt("pre_folder_write_error");
00406 }
00407
00408 return $arr;
00409 }
00410
00416 function checkCreatable($a_dir = "..")
00417 {
00418 clearstatcache();
00419 if (mkdir($a_dir."/crst879dldsk9d", 0774))
00420 {
00421 $arr["status"] = true;
00422 $arr["comment"] = "";
00423
00424 rmdir($a_dir."/crst879dldsk9d");
00425 }
00426 else
00427 {
00428 $arr["status"] = false;
00429 $arr["comment"] = $this->lng->txt("pre_folder_create_error");
00430 }
00431
00432 return $arr;
00433 }
00434
00439 function checkCookiesEnabled()
00440 {
00441 global $sess;
00442
00443 if ($sess->usesCookies)
00444 {
00445 $arr["status"] = true;
00446 $arr["comment"] = "";
00447 }
00448 else
00449 {
00450 $arr["status"] = false;
00451 $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
00452 }
00453
00454 return $arr;
00455 }
00456
00461 function checkPHPVersion()
00462 {
00463 $version = phpversion();
00464 $arr["version"] = $version;
00465 $first = (integer) substr($version,0,1);
00466
00467 switch ($first)
00468 {
00469 case 2:
00470 case 3:
00471 $arr["status"] = false;
00472 $arr["comment"] = $this->lng->txt("pre_php_version_3");
00473 break;
00474
00475 case 4:
00476 $second = (integer) substr($version,2,1);
00477 if ($second >= 3)
00478 {
00479 $arr["status"] = true;
00480 $arr["comment"] = "";
00481 }
00482 elseif ($second == 2)
00483 {
00484 $arr["status"] = false;
00485 $arr["comment"] = $this->lng->txt("pre_php_version_4.2");
00486 }
00487 else
00488 {
00489 $arr["status"] = false;
00490 $arr["comment"] = $this->lng->txt("pre_php_version_4.1");
00491 }
00492 break;
00493
00494 case 5:
00495 $arr["status"] = true;
00496 $arr["comment"] = $this->lng->txt("pre_php_version_5");
00497 break;
00498
00499 default:
00500 $arr["status"] = true;
00501 $arr["comment"] = $this->lng->txt("pre_php_version_unknown");
00502 break;
00503 }
00504
00505 return $arr;
00506 }
00507
00512 function checkAuth()
00513 {
00514 if ($_SESSION["auth"] === true)
00515 {
00516 return true;
00517 }
00518
00519 return false;
00520 }
00521
00529 function queryPreliminaries()
00530 {
00531 $a = array();
00532 $a["php"] = $this->checkPHPVersion();
00533 $a["root"] = $this->checkWritable();
00534 $a["create"] = $this->checkCreatable();
00535 $a["cookies"] = $this->checkCookiesEnabled();
00536
00537 return $a;
00538 }
00539
00544 function checkPreliminaries()
00545 {
00546 $this->preliminaries_result = $this->queryPreliminaries();
00547
00548 foreach ($this->preliminaries_result as $val)
00549 {
00550 if ($val["status"] === false)
00551 {
00552 $this->preliminaries = false;
00553 return false;
00554 }
00555 }
00556
00557 return true;
00558 }
00559
00564 function getPassword ()
00565 {
00566 return $this->ini->readVariable("setup","pass");
00567 }
00568
00574 function setPassword ($a_password)
00575 {
00576 $this->ini->setVariable("setup","pass",md5($a_password));
00577
00578 if ($this->ini->write() == false)
00579 {
00580 $this->error = $this->ini->getError();
00581 return false;
00582 }
00583
00584 return true;
00585 }
00586
00592 function loginAsClient($a_auth_data)
00593 {
00594 if (empty($a_auth_data["client_id"]))
00595 {
00596 $this->error = "no_client_id";
00597 return false;
00598 }
00599
00600 if (empty($a_auth_data["username"]))
00601 {
00602 $this->error = "no_username";
00603 return false;
00604 }
00605
00606 if (empty($a_auth_data["password"]))
00607 {
00608 $this->error = "no_password";
00609 return false;
00610 }
00611
00612 if (!$this->newClient($a_auth_data["client_id"]))
00613 {
00614 $this->error = "unknown_client_id";
00615 unset($this->client);
00616 return false;
00617 }
00618
00619 if (!$this->client->db_exists)
00620 {
00621 $this->error = "no_db_connect_consult_admin";
00622 unset($this->client);
00623 return false;
00624 }
00625
00626 $q = "SELECT usr_data.usr_id FROM usr_data ".
00627 "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id ".
00628 "LEFT JOIN settings ON settings.value = rbac_ua.rol_id ".
00629 "WHERE settings.keyword='system_role_id' ".
00630 "AND usr_data.login='".$a_auth_data["username"]."' ".
00631 "AND usr_data.passwd='".md5($a_auth_data["password"])."'";
00632 $r = $this->client->db->query($q);
00633
00634 if (!$r->numRows())
00635 {
00636 $this->error = "login_invalid";
00637 return false;
00638 }
00639
00640
00641 $_SESSION["auth"] = true;
00642 $_SESSION["access_mode"] = "client";
00643 $_SESSION["ClientId"] = $this->client->getId();
00644 return true;
00645 }
00646
00652 function loginAsAdmin($a_password)
00653 {
00654 $a_password = md5($a_password);
00655
00656 if ($this->ini->readVariable("setup","pass") == $a_password)
00657 {
00658 $_SESSION["auth"] = true;
00659 $_SESSION["access_mode"] = "admin";
00660 return true;
00661 }
00662
00663 return false;
00664 }
00665
00671 function newClient($a_client_id = 0)
00672 {
00673 if (!$this->isInstalled())
00674 {
00675 return false;
00676 }
00677
00678 $this->client = new ilClient($a_client_id);
00679
00680 if (!$this->client->init())
00681 {
00682 $this->error = get_class($this).": ".$this->client->getError();
00683 $_SESSION["ClientId"] = "";
00684 return false;
00685 }
00686
00687 $_SESSION["ClientId"] = $a_client_id;
00688
00689 return true;
00690 }
00691
00697 function getStatus ($client = 0)
00698 {
00699 if (!is_object($client))
00700 {
00701 if ($this->ini_client_exists)
00702 {
00703 $client =& $this->client;
00704 }
00705 else
00706 {
00707 $client = new ilClient();
00708 }
00709 }
00710
00711 $status = array();
00712 $status["ini"] = $this->checkClientIni($client);
00713 $status["db"] = $this->checkClientDatabase($client);
00714
00715 if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
00716 {
00717 $status["lang"]["status"] = false;
00718 $status["lang"]["comment"] = $status["db"]["comment"];
00719 $status["contact"]["status"] = false;
00720 $status["contact"]["comment"] = $status["db"]["comment"];
00721 $status["nic"]["status"] = false;
00722 $status["nic"]["comment"] = $status["db"]["comment"];
00723 }
00724 else
00725 {
00726 $status["lang"] = $this->checkClientLanguages($client);
00727 $status["contact"] = $this->checkClientContact($client);
00728 $status["nic"] = $this->checkClientNIC($client);
00729 $status["finish"] = $this->checkFinish($client);
00730 $status["access"] = $this->checkAccess($client);
00731 }
00732
00733
00734 return $status;
00735 }
00736
00742 function checkFinish(&$client)
00743 {
00744 if ($client->getSetting("setup_ok"))
00745 {
00746 $arr["status"] = true;
00747 $arr["comment"] = $this->lng->txt("setup_finished");
00748 }
00749 else
00750 {
00751 $arr["status"] = false;
00752 $arr["comment"] = $this->lng->txt("setup_not_finished");
00753 }
00754
00755 return $arr;
00756 }
00757
00763 function checkAccess(&$client)
00764 {
00765 if ($client->ini->readVariable("client","access") == "1")
00766 {
00767 $arr["status"] = true;
00768 $arr["comment"] = $this->lng->txt("online");
00769 }
00770 else
00771 {
00772 $arr["status"] = false;
00773 $arr["comment"] = $this->lng->txt("disabled");
00774 }
00775
00776 return $arr;
00777 }
00778
00784 function checkClientIni(&$client)
00785 {
00786 if (!$arr["status"] = $client->init())
00787 {
00788 $arr["comment"] = $client->getError();
00789 }
00790 else
00791 {
00792 $arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
00793 }
00794
00795 return $arr;
00796 }
00797
00803 function checkClientDatabase(&$client)
00804 {
00805 if (!$arr["status"] = $client->db_exists)
00806 {
00807 $arr["comment"] = $this->lng->txt("no_database");
00808 return $arr;
00809 }
00810
00811 if (!$arr["status"] = $client->db_installed)
00812 {
00813 $arr["comment"] = $this->lng->txt("db_not_installed");
00814 return $arr;
00815 }
00816
00817
00818 $client->setup_ok = (bool) $client->getSetting("setup_ok");
00819
00820 $this->lng->setDbHandler($client->db);
00821 include_once "../classes/class.ilDBUpdate.php";
00822 $dbupdate = new ilDBUpdate($client->db);
00823
00824 if (!$arr["status"] = $dbupdate->getDBVersionStatus())
00825 {
00826 $arr["comment"] = $this->lng->txt("db_needs_update");
00827 $arr["update"] = true;
00828 return $arr;
00829 }
00830
00831
00832 $q = "SELECT count(*) as cnt FROM ctrl_calls";
00833 $cset = $client->db->query($q);
00834 $crec = $cset->fetchRow(DB_FETCHMODE_ASSOC);
00835 if ($crec["cnt"] == 0)
00836 {
00837 $arr["status"] = false;
00838 $arr["comment"] = $this->lng->txt("db_control_structure_missing");
00839 $arr["update"] = true;
00840 return $arr;
00841 }
00842
00843 $arr["comment"] = "version ".$dbupdate->getCurrentVersion();
00844 return $arr;
00845 }
00846
00852 function checkClientLanguages(&$client)
00853 {
00854 $installed_langs = $this->lng->getInstalledLanguages();
00855
00856 $count = count($installed_langs);
00857
00858 if ($count < 1)
00859 {
00860 $arr["status"] = false;
00861 $arr["comment"] = $this->lng->txt("lang_none_installed");
00862 }
00863 else
00864 {
00865 $arr["status"] = true;
00866 $arr["comment"] = $count." ".$this->lng->txt("languages_installed");
00867 }
00868
00869 return $arr;
00870 }
00871
00877 function checkClientContact(&$client)
00878 {
00879 $arr["status"] = true;
00880 $arr["comment"] = $this->lng->txt("filled_out");
00881
00882 $settings = $client->getAllSettings();
00883 $client_name = $client->getName();
00884
00885
00886 if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"])
00887 or empty($settings["admin_street"]) or empty($settings["admin_zipcode"])
00888 or empty($settings["admin_country"]) or empty($settings["admin_city"])
00889 or empty($settings["admin_phone"]) or empty($settings["admin_email"])
00890 or empty($client_name) or empty($settings["inst_institution"]))
00891 {
00892 $arr["status"] = false;
00893 $arr["comment"] = $this->lng->txt("missing_data");
00894 }
00895
00896
00897 if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
00898 {
00899 $arr["status"] = false;
00900 $arr["comment"] = $this->lng->txt("email_not_valid");
00901 }
00902
00903 return $arr;
00904 }
00905
00911 function checkClientNIC(&$client)
00912 {
00913 $settings = $client->getAllSettings();
00914
00915 if (!isset($settings["nic_enabled"]))
00916 {
00917 $arr["status"] = false;
00918 $arr["comment"] = $this->lng->txt("nic_not_disabled");
00919 return $arr;
00920 }
00921
00922 $arr["status"] = true;
00923
00924 if ($settings["nic_enabled"] == "-1")
00925 {
00926 $arr["comment"] = $this->lng->txt("nic_reg_failed");
00927 return $arr;
00928 }
00929
00930 if (!$settings["nic_enabled"])
00931 {
00932 $arr["comment"] = $this->lng->txt("nic_reg_disabled");
00933 }
00934 else
00935 {
00936 $arr["comment"] = $this->lng->txt("nic_reg_enabled");
00937 if ($settings["inst_id"] <= 0)
00938 {
00939 $arr["status"] = false;
00940 }
00941 }
00942
00943 return $arr;
00944 }
00945
00950 function isInstalled()
00951 {
00952 return $this->ini_ilias_exists;
00953 }
00954
00959 function isAuthenticated()
00960 {
00961 return $this->auth;
00962 }
00963
00968 function isAdmin()
00969 {
00970 return ($this->access_mode == "admin") ? true : false;
00971 }
00972
00978 function saveMasterSetup($a_formdata)
00979 {
00980 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
00981
00982 if ($a_formdata["chk_datadir_path"] == 1)
00983 {
00984 if (!ilUtil::makeDir($datadir_path))
00985 {
00986 $this->error = "create_datadir_failed";
00987 return false;
00988 }
00989 }
00990
00991
00992 if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00993 {
00994 if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00995 {
00996 $this->error = "create_webdir_failed";
00997 return false;
00998 }
00999 }
01000
01001 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
01002 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
01003 $log_file = substr($form_log_path,strlen($log_path)+1);
01004
01005 $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
01006 $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
01007 $this->ini->setVariable("clients", "datadir", $datadir_path);
01008 $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
01009 $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
01010 $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
01011 $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
01012 $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
01013 $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
01014 $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
01015 $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
01016 $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
01017 $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
01018 $this->ini->setVariable("log", "path", $log_path);
01019 $this->ini->setVariable("log", "file", $log_file);
01020 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
01021
01022 if (!$this->ini->write())
01023 {
01024 $this->error = get_class($this).": ".$this->ini->getError();
01025 return false;
01026 }
01027
01028
01029 $_SESSION["auth"] = true;
01030 $_SESSION["access_mode"] = "admin";
01031
01032 return true;
01033 }
01034
01040 function updateMasterSettings($a_formdata)
01041 {
01042 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
01043 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
01044 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
01045 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
01046 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
01047 $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
01048 $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
01049 $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
01050 $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
01051 $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
01052
01053 $this->ini->setVariable("tools", "convert", $convert_path);
01054 $this->ini->setVariable("tools", "zip", $zip_path);
01055 $this->ini->setVariable("tools", "unzip", $unzip_path);
01056 $this->ini->setVariable("tools", "java", $java_path);
01057 $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
01058 $this->ini->setVariable("tools", "latex", $latex_url);
01059 $this->ini->setVariable("tools", "fop", $fop_path);
01060 $this->ini->setVariable("tools", "vscantype", $scan_type);
01061 $this->ini->setVariable("tools", "scancommand", $scan_command);
01062 $this->ini->setVariable("tools", "cleancommand", $clean_command);
01063
01064 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
01065 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
01066 $log_file = substr($form_log_path,strlen($log_path)+1);
01067
01068 $this->ini->setVariable("log", "path", $log_path);
01069 $this->ini->setVariable("log", "file", $log_file);
01070 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
01071
01072 if (!$this->ini->write())
01073 {
01074 $this->error = get_class($this).": ".$this->ini->getError();
01075 return false;
01076 }
01077
01078 return true;
01079 }
01080
01086 function checkToolsSetup($a_formdata)
01087 {
01088
01089 if (!isset($a_formdata["chk_convert_path"]))
01090 {
01091
01092 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
01093
01094 if (empty($convert_path))
01095 {
01096 $this->error = "no_path_convert";
01097 return false;
01098 }
01099
01100 if (!$this->testConvert($convert_path))
01101 {
01102 $this->error = "check_failed_convert";
01103 return false;
01104 }
01105 }
01106
01107
01108 if (!isset($a_formdata["chk_zip_path"]))
01109 {
01110
01111 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
01112
01113 if (empty($zip_path))
01114 {
01115 $this->error = "no_path_zip";
01116 return false;
01117 }
01118
01119 if (!$this->testZip($zip_path))
01120 {
01121 $this->error = "check_failed_zip";
01122 return false;
01123 }
01124 }
01125
01126
01127 if (!isset($a_formdata["chk_unzip_path"]))
01128 {
01129
01130 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
01131
01132 if (empty($unzip_path))
01133 {
01134 $this->error = "no_path_unzip";
01135 return false;
01136 }
01137
01138 if (!$this->testUnzip($unzip_path))
01139 {
01140 $this->error = "check_failed_unzip";
01141 return false;
01142 }
01143 }
01144
01145
01146 if (!isset($a_formdata["chk_java_path"]))
01147 {
01148
01149 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
01150
01151 if (empty($java_path))
01152 {
01153 $this->error = "no_path_java";
01154 return false;
01155 }
01156
01157 if (!$this->testJava($java_path))
01158 {
01159 $this->error = "check_failed_java";
01160 return false;
01161 }
01162 }
01163
01164
01165 if (!isset($a_formdata["chk_htmldoc_path"]))
01166 {
01167
01168 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
01169
01170 if (empty($htmldoc_path))
01171 {
01172 $this->error = "no_path_htmldoc";
01173 return false;
01174 }
01175
01176 if (!$this->testHtmldoc($htmldoc_path))
01177 {
01178 $this->error = "check_failed_htmldoc";
01179 return false;
01180 }
01181 }
01182
01183
01184 if (!isset($a_formdata["chk_latex_url"]))
01185 {
01186 $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
01187 if (empty($latex_url))
01188 {
01189 $this->error = "no_latex_url";
01190 return false;
01191 }
01192
01193 if (!$this->testLatex($latex_url))
01194 {
01195 $this->error = "check_failed_latex";
01196 return false;
01197 }
01198 }
01199
01200 return true;
01201 }
01202
01208 function checkDataDirSetup($a_formdata)
01209 {
01210
01211 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
01212
01213 if (empty($datadir_path))
01214 {
01215 $this->error = "no_path_datadir";
01216 return false;
01217 }
01218
01219 $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
01220
01221
01222 if (strpos($datadir_path,$webspace_dir) !== false)
01223 {
01224 $this->error = "datadir_webspacedir_match";
01225 return false;
01226 }
01227
01228
01229 if ($a_formdata["chk_datadir_path"] == 1)
01230 {
01231 $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
01232 $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
01233
01234 if (is_writable($datadir_path))
01235 {
01236 $this->error = "dir_exists_create";
01237 return false;
01238 }
01239
01240 if (!is_writable($dir_to_check))
01241 {
01242 $this->error = "cannot_create_datadir_no_write_access";
01243 return false;
01244 }
01245 }
01246 else
01247 {
01248 if (!is_writable($datadir_path))
01249 {
01250 $this->error = "cannot_create_datadir_no_write_access";
01251 return false;
01252 }
01253 }
01254
01255 return true;
01256 }
01257
01263 function checkPasswordSetup($a_formdata)
01264 {
01265 if (!$a_formdata["setup_pass"])
01266 {
01267 $this->error = "no_setup_pass_given";
01268 return false;
01269 }
01270
01271 if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
01272 {
01273 $this->error = "pass_does_not_match";
01274 return false;
01275 }
01276
01277 return true;
01278 }
01279
01285 function checkLogSetup($a_formdata)
01286 {
01287
01288 if (!isset($a_formdata["chk_log_status"]))
01289 {
01290
01291 $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
01292
01293 if (empty($log_path))
01294 {
01295 $this->error = "no_path_log";
01296 return false;
01297 }
01298
01299 if (!@touch($log_path))
01300 {
01301 $this->error = "could_not_create_logfile";
01302 return false;
01303 }
01304 }
01305
01306 return true;
01307 }
01308
01313 function getError()
01314 {
01315 if (empty($this->error))
01316 {
01317 return false;
01318 }
01319
01320 $error = $this->error;
01321 $this->error = "";
01322
01323 return $error;
01324 }
01325
01331 function _ilSetup()
01332 {
01333
01334
01335
01336
01337 return true;
01338 }
01339
01346 function testConvert ($a_convert_path)
01347 {
01348
01349 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01350 {
01351 unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01352 }
01353
01354 system($a_convert_path." ".ILIAS_ABSOLUTE_PATH."/images/test.jpg GIF:".ILIAS_ABSOLUTE_PATH."/images/test.gif");
01355
01356
01357 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01358 {
01359 unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01360 return true;
01361 }
01362 else
01363 {
01364 return false;
01365 }
01366 }
01367
01374 function testJava ($a_java_path)
01375 {
01376 exec($a_java_path, $out, $back);
01377
01378 unset($out);
01379
01380 return ($back != 1) ? false : true;
01381 }
01382
01389 function testLatex($a_latex_url)
01390 {
01391
01392 include_once "class.ilHttpRequest.php";
01393 $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
01394 $result = $http->downloadToString();
01395 if ((strpos((substr($result, 0, 5)), "PNG") !== FALSE) || (strpos((substr($result, 0, 5)), "GIF") !== FALSE))
01396 {
01397 return true;
01398 }
01399 else
01400 {
01401 return false;
01402 }
01403 }
01404
01411 function testZip ($a_zip_path)
01412 {
01413
01414 $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
01415
01416 fwrite($fp, "test");
01417 fclose($fp);
01418
01419 if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
01420 {
01421 $curDir = getcwd();
01422 chdir(ILIAS_ABSOLUTE_PATH);
01423
01424 $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
01425
01426 exec($zipCmd);
01427
01428 chdir($curDir);
01429
01430 }
01431
01432
01433 if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
01434 {
01435 unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
01436 return true;
01437 }
01438 else
01439 {
01440 unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
01441 return false;
01442 }
01443 }
01444
01445
01452 function testUnzip ($a_unzip_path)
01453 {
01454 $curDir = getcwd();
01455
01456 chdir(ILIAS_ABSOLUTE_PATH);
01457
01458 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
01459 {
01460 $unzipCmd = $a_unzip_path." unzip_test_file.zip";
01461 exec($unzipCmd);
01462 }
01463
01464 chdir($curDir);
01465
01466
01467 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
01468 {
01469 unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
01470
01471 return true;
01472 }
01473 else
01474 {
01475 return false;
01476 }
01477 }
01478
01485 function testHtmldoc($a_htmldoc_path)
01486 {
01487 $curDir = getcwd();
01488
01489 chdir(ILIAS_ABSOLUTE_PATH);
01490
01491 $html = "<html><head><title></title></head><body><p>test</p></body></html>";
01492
01493 $html_file = "htmldoc_test_file.html";
01494
01495 $fp = fopen( $html_file ,"wb");
01496 fwrite($fp, $html);
01497 fclose($fp);
01498
01499 $htmldoc = $a_htmldoc_path." ";
01500 $htmldoc .= "--no-toc ";
01501 $htmldoc .= "--no-jpeg ";
01502 $htmldoc .= "--webpage ";
01503 $htmldoc .= "--outfile htmldoc_test_file.pdf ";
01504 $htmldoc .= "--bodyfont Arial ";
01505 $htmldoc .= "--charset iso-8859-15 ";
01506 $htmldoc .= "--color ";
01507 $htmldoc .= "--size A4 ";
01508 $htmldoc .= "--format pdf ";
01509 $htmldoc .= "--footer ... ";
01510 $htmldoc .= "--header ... ";
01511 $htmldoc .= "--left 60 ";
01512
01513 $htmldoc .= $html_file;
01514 exec($htmldoc);
01515
01516 unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
01517
01518 chdir($curDir);
01519
01520 if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
01521 {
01522 unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
01523 return true;
01524 }
01525 else
01526 {
01527 return false;
01528 }
01529 }
01530
01531 function unzipTiny()
01532 {
01533 $this->unzip(ILIAS_ABSOLUTE_PATH . "/Services/RTE/tiny_mce.zip", TRUE);
01534 $this->ini->setVariable("tools", "tiny_md5", md5_file(ILIAS_ABSOLUTE_PATH . "/Services/RTE/tiny_mce.zip"));
01535 if ($this->ini->write() == false)
01536 {
01537 $this->error = $this->ini->getError();
01538 return false;
01539 }
01540 return TRUE;
01541 }
01542
01549 function unzip($a_file, $overwrite = false)
01550 {
01551
01552
01553 $pathinfo = pathinfo($a_file);
01554 $dir = $pathinfo["dirname"];
01555 $file = $pathinfo["basename"];
01556
01557
01558 $cdir = getcwd();
01559 chdir($dir);
01560 $unzip = $this->ini->readVariable("tools","unzip");
01561 $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
01562 exec($unzipcmd, $arr);
01563 $zdirs = array();
01564
01565 foreach($arr as $line)
01566 {
01567 if(is_int(strpos($line, "/")))
01568 {
01569 $zdir = substr($line, 0, strrpos($line, "/"));
01570 $nr = substr_count($zdir, "/");
01571
01572 while ($zdir != "")
01573 {
01574 $nr = substr_count($zdir, "/");
01575 $zdirs[$zdir] = $nr;
01576
01577 $zdir = substr($zdir, 0, strrpos($zdir, "/"));
01578 }
01579 }
01580 }
01581
01582 asort($zdirs);
01583
01584 foreach($zdirs as $zdir => $nr)
01585 {
01586 ilUtil::createDirectory($zdir);
01587 }
01588
01589
01590 if ($overvwrite)
01591 {
01592 $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
01593 }
01594 else
01595 {
01596 $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
01597 }
01598 exec($unzipcmd);
01599
01600 chdir($cdir);
01601 }
01602
01603 }
01604 ?>