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