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 $q = file($this->SQL_FILE);
00311 $q = implode("\n",$q);
00312
00313 if ($this->execQuery($this->client->db,$q) === false)
00314 {
00315 $this->error = "dump_error";
00316 return false;
00317 }
00318
00319 $this->client->db_installed = true;
00320 return true;
00321 }
00322
00327 function checkIniFileExists()
00328 {
00329 $a = @file_exists($this->INI_FILE);
00330 return $a;
00331 }
00332
00338 function checkWritable($a_dir = "..")
00339 {
00340 clearstatcache();
00341 if (is_writable($a_dir))
00342 {
00343 $arr["status"] = true;
00344 $arr["comment"] = "";
00345 }
00346 else
00347 {
00348 $arr["status"] = false;
00349 $arr["comment"] = $this->lng->txt("pre_folder_write_error");
00350 }
00351
00352 return $arr;
00353 }
00354
00360 function checkCreatable($a_dir = "..")
00361 {
00362 clearstatcache();
00363 if (mkdir($a_dir."/crst879dldsk9d", 0774))
00364 {
00365 $arr["status"] = true;
00366 $arr["comment"] = "";
00367
00368 rmdir($a_dir."/crst879dldsk9d");
00369 }
00370 else
00371 {
00372 $arr["status"] = false;
00373 $arr["comment"] = $this->lng->txt("pre_folder_create_error");
00374 }
00375
00376 return $arr;
00377 }
00378
00383 function checkCookiesEnabled()
00384 {
00385 global $sess;
00386
00387 if ($sess->usesCookies)
00388 {
00389 $arr["status"] = true;
00390 $arr["comment"] = "";
00391 }
00392 else
00393 {
00394 $arr["status"] = false;
00395 $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
00396 }
00397
00398 return $arr;
00399 }
00400
00405 function checkPHPVersion()
00406 {
00407 $version = phpversion();
00408 $arr["version"] = $version;
00409 $first = (integer) substr($version,0,1);
00410
00411 switch ($first)
00412 {
00413 case 2:
00414 case 3:
00415 $arr["status"] = false;
00416 $arr["comment"] = $this->lng->txt("pre_php_version_3");
00417 break;
00418
00419 case 4:
00420 $second = (integer) substr($version,2,1);
00421 if ($second >= 3)
00422 {
00423 $arr["status"] = true;
00424 $arr["comment"] = "";
00425 }
00426 elseif ($second == 2)
00427 {
00428 $arr["status"] = false;
00429 $arr["comment"] = $this->lng->txt("pre_php_version_4.2");
00430 }
00431 else
00432 {
00433 $arr["status"] = false;
00434 $arr["comment"] = $this->lng->txt("pre_php_version_4.1");
00435 }
00436 break;
00437
00438 case 5:
00439 $arr["status"] = true;
00440 $arr["comment"] = $this->lng->txt("pre_php_version_5");
00441 break;
00442
00443 default:
00444 $arr["status"] = true;
00445 $arr["comment"] = $this->lng->txt("pre_php_version_unknown");
00446 break;
00447 }
00448
00449 return $arr;
00450 }
00451
00456 function checkAuth()
00457 {
00458 if ($_SESSION["auth"] === true)
00459 {
00460 return true;
00461 }
00462
00463 return false;
00464 }
00465
00473 function queryPreliminaries()
00474 {
00475 $a = array();
00476 $a["php"] = $this->checkPHPVersion();
00477 $a["root"] = $this->checkWritable();
00478 $a["create"] = $this->checkCreatable();
00479 $a["cookies"] = $this->checkCookiesEnabled();
00480
00481 return $a;
00482 }
00483
00488 function checkPreliminaries()
00489 {
00490 $this->preliminaries_result = $this->queryPreliminaries();
00491
00492 foreach ($this->preliminaries_result as $val)
00493 {
00494 if ($val["status"] === false)
00495 {
00496 $this->preliminaries = false;
00497 return false;
00498 }
00499 }
00500
00501 return true;
00502 }
00503
00508 function getPassword ()
00509 {
00510 return $this->ini->readVariable("setup","pass");
00511 }
00512
00518 function setPassword ($a_password)
00519 {
00520 $this->ini->setVariable("setup","pass",md5($a_password));
00521
00522 if ($this->ini->write() == false)
00523 {
00524 $this->error = $this->ini->getError();
00525 return false;
00526 }
00527
00528 return true;
00529 }
00530
00536 function loginAsClient($a_auth_data)
00537 {
00538 if (empty($a_auth_data["client_id"]))
00539 {
00540 $this->error = "no_client_id";
00541 return false;
00542 }
00543
00544 if (empty($a_auth_data["username"]))
00545 {
00546 $this->error = "no_username";
00547 return false;
00548 }
00549
00550 if (empty($a_auth_data["password"]))
00551 {
00552 $this->error = "no_password";
00553 return false;
00554 }
00555
00556 if (!$this->newClient($a_auth_data["client_id"]))
00557 {
00558 $this->error = "unknown_client_id";
00559 unset($this->client);
00560 return false;
00561 }
00562
00563 if (!$this->client->db_exists)
00564 {
00565 $this->error = "no_db_connect_consult_admin";
00566 unset($this->client);
00567 return false;
00568 }
00569
00570 $q = "SELECT usr_data.usr_id FROM usr_data ".
00571 "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id ".
00572 "LEFT JOIN settings ON settings.value = rbac_ua.rol_id ".
00573 "WHERE settings.keyword='system_role_id' ".
00574 "AND usr_data.login='".$a_auth_data["username"]."' ".
00575 "AND usr_data.passwd='".md5($a_auth_data["password"])."'";
00576 $r = $this->client->db->query($q);
00577
00578 if (!$r->numRows())
00579 {
00580 $this->error = "login_invalid";
00581 return false;
00582 }
00583
00584
00585 $_SESSION["auth"] = true;
00586 $_SESSION["access_mode"] = "client";
00587 $_SESSION["ClientId"] = $this->client->getId();
00588 return true;
00589 }
00590
00596 function loginAsAdmin($a_password)
00597 {
00598 $a_password = md5($a_password);
00599
00600 if ($this->ini->readVariable("setup","pass") == $a_password)
00601 {
00602 $_SESSION["auth"] = true;
00603 $_SESSION["access_mode"] = "admin";
00604 return true;
00605 }
00606
00607 return false;
00608 }
00609
00615 function newClient($a_client_id = 0)
00616 {
00617 if (!$this->isInstalled())
00618 {
00619 return false;
00620 }
00621
00622 $this->client = new ilClient($a_client_id);
00623
00624 if (!$this->client->init())
00625 {
00626 $this->error = get_class($this).": ".$this->client->getError();
00627 $_SESSION["ClientId"] = "";
00628 return false;
00629 }
00630
00631 $_SESSION["ClientId"] = $a_client_id;
00632
00633 return true;
00634 }
00635
00641 function getStatus ($client = 0)
00642 {
00643 if (!is_object($client))
00644 {
00645 if ($this->ini_client_exists)
00646 {
00647 $client =& $this->client;
00648 }
00649 else
00650 {
00651 $client = new ilClient();
00652 }
00653 }
00654
00655 $status = array();
00656 $status["ini"] = $this->checkClientIni($client);
00657 $status["db"] = $this->checkClientDatabase($client);
00658
00659 if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
00660 {
00661 $status["lang"]["status"] = false;
00662 $status["lang"]["comment"] = $status["db"]["comment"];
00663 $status["contact"]["status"] = false;
00664 $status["contact"]["comment"] = $status["db"]["comment"];
00665 $status["nic"]["status"] = false;
00666 $status["nic"]["comment"] = $status["db"]["comment"];
00667 }
00668 else
00669 {
00670 $status["lang"] = $this->checkClientLanguages($client);
00671 $status["contact"] = $this->checkClientContact($client);
00672 $status["nic"] = $this->checkClientNIC($client);
00673 $status["finish"] = $this->checkFinish($client);
00674 $status["access"] = $this->checkAccess($client);
00675 }
00676
00677
00678 return $status;
00679 }
00680
00686 function checkFinish(&$client)
00687 {
00688 if ($client->getSetting("setup_ok"))
00689 {
00690 $arr["status"] = true;
00691 $arr["comment"] = $this->lng->txt("setup_finished");
00692 }
00693 else
00694 {
00695 $arr["status"] = false;
00696 $arr["comment"] = $this->lng->txt("setup_not_finished");
00697 }
00698
00699 return $arr;
00700 }
00701
00707 function checkAccess(&$client)
00708 {
00709 if ($client->ini->readVariable("client","access") == "1")
00710 {
00711 $arr["status"] = true;
00712 $arr["comment"] = $this->lng->txt("online");
00713 }
00714 else
00715 {
00716 $arr["status"] = false;
00717 $arr["comment"] = $this->lng->txt("disabled");
00718 }
00719
00720 return $arr;
00721 }
00722
00728 function checkClientIni(&$client)
00729 {
00730 if (!$arr["status"] = $client->init())
00731 {
00732 $arr["comment"] = $client->getError();
00733 }
00734 else
00735 {
00736 $arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
00737 }
00738
00739 return $arr;
00740 }
00741
00747 function checkClientDatabase(&$client)
00748 {
00749 if (!$arr["status"] = $client->db_exists)
00750 {
00751 $arr["comment"] = $this->lng->txt("no_database");
00752 return $arr;
00753 }
00754
00755 if (!$arr["status"] = $client->db_installed)
00756 {
00757 $arr["comment"] = $this->lng->txt("db_not_installed");
00758 return $arr;
00759 }
00760
00761
00762 $client->setup_ok = (bool) $client->getSetting("setup_ok");
00763
00764 $this->lng->setDbHandler($client->db);
00765 include_once "../classes/class.ilDBUpdate.php";
00766 $dbupdate = new ilDBUpdate($client->db);
00767
00768 if (!$arr["status"] = $dbupdate->getDBVersionStatus())
00769 {
00770 $arr["comment"] = $this->lng->txt("db_needs_update");
00771 $arr["update"] = true;
00772 return $arr;
00773 }
00774
00775
00776 $q = "SELECT count(*) as cnt FROM ctrl_calls";
00777 $cset = $client->db->query($q);
00778 $crec = $cset->fetchRow(DB_FETCHMODE_ASSOC);
00779 if ($crec["cnt"] == 0)
00780 {
00781 $arr["status"] = false;
00782 $arr["comment"] = $this->lng->txt("db_control_structure_missing");
00783 $arr["update"] = true;
00784 return $arr;
00785 }
00786
00787 $arr["comment"] = "version ".$dbupdate->getCurrentVersion();
00788 return $arr;
00789 }
00790
00796 function checkClientLanguages(&$client)
00797 {
00798 $installed_langs = $this->lng->getInstalledLanguages();
00799
00800 $count = count($installed_langs);
00801
00802 if ($count < 1)
00803 {
00804 $arr["status"] = false;
00805 $arr["comment"] = $this->lng->txt("lang_none_installed");
00806 }
00807 else
00808 {
00809 $arr["status"] = true;
00810 $arr["comment"] = $count." ".$this->lng->txt("languages_installed");
00811 }
00812
00813 return $arr;
00814 }
00815
00821 function checkClientContact(&$client)
00822 {
00823 $arr["status"] = true;
00824 $arr["comment"] = $this->lng->txt("filled_out");
00825
00826 $settings = $client->getAllSettings();
00827 $client_name = $client->getName();
00828
00829
00830 if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"])
00831 or empty($settings["admin_street"]) or empty($settings["admin_zipcode"])
00832 or empty($settings["admin_country"]) or empty($settings["admin_city"])
00833 or empty($settings["admin_phone"]) or empty($settings["admin_email"])
00834 or empty($client_name) or empty($settings["inst_institution"]))
00835 {
00836 $arr["status"] = false;
00837 $arr["comment"] = $this->lng->txt("missing_data");
00838 }
00839
00840
00841 if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
00842 {
00843 $arr["status"] = false;
00844 $arr["comment"] = $this->lng->txt("email_not_valid");
00845 }
00846
00847 return $arr;
00848 }
00849
00855 function checkClientNIC(&$client)
00856 {
00857 $settings = $client->getAllSettings();
00858
00859 if (!isset($settings["nic_enabled"]))
00860 {
00861 $arr["status"] = false;
00862 $arr["comment"] = $this->lng->txt("nic_not_disabled");
00863 return $arr;
00864 }
00865
00866 $arr["status"] = true;
00867
00868 if ($settings["nic_enabled"] == "-1")
00869 {
00870 $arr["comment"] = $this->lng->txt("nic_reg_failed");
00871 return $arr;
00872 }
00873
00874 if (!$settings["nic_enabled"])
00875 {
00876 $arr["comment"] = $this->lng->txt("nic_reg_disabled");
00877 }
00878 else
00879 {
00880 $arr["comment"] = $this->lng->txt("nic_reg_enabled");
00881 if ($settings["inst_id"] <= 0)
00882 {
00883 $arr["status"] = false;
00884 }
00885 }
00886
00887 return $arr;
00888 }
00889
00894 function isInstalled()
00895 {
00896 return $this->ini_ilias_exists;
00897 }
00898
00903 function isAuthenticated()
00904 {
00905 return $this->auth;
00906 }
00907
00912 function isAdmin()
00913 {
00914 return ($this->access_mode == "admin") ? true : false;
00915 }
00916
00922 function saveMasterSetup($a_formdata)
00923 {
00924 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
00925
00926 if ($a_formdata["chk_datadir_path"] == 1)
00927 {
00928 if (!ilUtil::makeDir($datadir_path))
00929 {
00930 $this->error = "create_datadir_failed";
00931 return false;
00932 }
00933 }
00934
00935
00936 if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00937 {
00938 if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00939 {
00940 $this->error = "create_webdir_failed";
00941 return false;
00942 }
00943 }
00944
00945 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
00946 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
00947 $log_file = substr($form_log_path,strlen($log_path)+1);
00948
00949 $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
00950 $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
00951 $this->ini->setVariable("clients", "datadir", $datadir_path);
00952 $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
00953 $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
00954 $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
00955 $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
00956 $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
00957 $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
00958 $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
00959 $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
00960 $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
00961 $this->ini->setVariable("log", "path", $log_path);
00962 $this->ini->setVariable("log", "file", $log_file);
00963 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
00964
00965 if (!$this->ini->write())
00966 {
00967 $this->error = get_class($this).": ".$this->ini->getError();
00968 return false;
00969 }
00970
00971
00972 $_SESSION["auth"] = true;
00973 $_SESSION["access_mode"] = "admin";
00974
00975 return true;
00976 }
00977
00983 function updateMasterSettings($a_formdata)
00984 {
00985 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
00986 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
00987 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
00988 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
00989 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
00990 $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
00991 $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
00992 $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
00993 $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
00994
00995 $this->ini->setVariable("tools", "convert", $convert_path);
00996 $this->ini->setVariable("tools", "zip", $zip_path);
00997 $this->ini->setVariable("tools", "unzip", $unzip_path);
00998 $this->ini->setVariable("tools", "java", $java_path);
00999 $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
01000 $this->ini->setVariable("tools", "fop", $fop_path);
01001 $this->ini->setVariable("tools", "vscantype", $scan_type);
01002 $this->ini->setVariable("tools", "scancommand", $scan_command);
01003 $this->ini->setVariable("tools", "cleancommand", $clean_command);
01004
01005 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
01006 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
01007 $log_file = substr($form_log_path,strlen($log_path)+1);
01008
01009 $this->ini->setVariable("log", "path", $log_path);
01010 $this->ini->setVariable("log", "file", $log_file);
01011 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
01012
01013 if (!$this->ini->write())
01014 {
01015 $this->error = get_class($this).": ".$this->ini->getError();
01016 return false;
01017 }
01018
01019 return true;
01020 }
01021
01027 function checkToolsSetup($a_formdata)
01028 {
01029
01030 if (!isset($a_formdata["chk_convert_path"]))
01031 {
01032
01033 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
01034
01035 if (empty($convert_path))
01036 {
01037 $this->error = "no_path_convert";
01038 return false;
01039 }
01040
01041 if (!$this->testConvert($convert_path))
01042 {
01043 $this->error = "check_failed_convert";
01044 return false;
01045 }
01046 }
01047
01048
01049 if (!isset($a_formdata["chk_zip_path"]))
01050 {
01051
01052 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
01053
01054 if (empty($zip_path))
01055 {
01056 $this->error = "no_path_zip";
01057 return false;
01058 }
01059
01060 if (!$this->testZip($zip_path))
01061 {
01062 $this->error = "check_failed_zip";
01063 return false;
01064 }
01065 }
01066
01067
01068 if (!isset($a_formdata["chk_unzip_path"]))
01069 {
01070
01071 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
01072
01073 if (empty($unzip_path))
01074 {
01075 $this->error = "no_path_unzip";
01076 return false;
01077 }
01078
01079 if (!$this->testUnzip($unzip_path))
01080 {
01081 $this->error = "check_failed_unzip";
01082 return false;
01083 }
01084 }
01085
01086
01087 if (!isset($a_formdata["chk_java_path"]))
01088 {
01089
01090 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
01091
01092 if (empty($java_path))
01093 {
01094 $this->error = "no_path_java";
01095 return false;
01096 }
01097
01098 if (!$this->testJava($java_path))
01099 {
01100 $this->error = "check_failed_java";
01101 return false;
01102 }
01103 }
01104
01105
01106 if (!isset($a_formdata["chk_htmldoc_path"]))
01107 {
01108
01109 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
01110
01111 if (empty($htmldoc_path))
01112 {
01113 $this->error = "no_path_htmldoc";
01114 return false;
01115 }
01116
01117 if (!$this->testHtmldoc($htmldoc_path))
01118 {
01119 $this->error = "check_failed_htmldoc";
01120 return false;
01121 }
01122 }
01123
01124 return true;
01125 }
01126
01132 function checkDataDirSetup($a_formdata)
01133 {
01134
01135 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
01136
01137 if (empty($datadir_path))
01138 {
01139 $this->error = "no_path_datadir";
01140 return false;
01141 }
01142
01143 $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
01144
01145
01146 if (strpos($datadir_path,$webspace_dir) !== false)
01147 {
01148 $this->error = "datadir_webspacedir_match";
01149 return false;
01150 }
01151
01152
01153 if ($a_formdata["chk_datadir_path"] == 1)
01154 {
01155 $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
01156 $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
01157
01158 if (is_writable($datadir_path))
01159 {
01160 $this->error = "dir_exists_create";
01161 return false;
01162 }
01163
01164 if (!is_writable($dir_to_check))
01165 {
01166 $this->error = "cannot_create_datadir_no_write_access";
01167 return false;
01168 }
01169 }
01170 else
01171 {
01172 if (!is_writable($datadir_path))
01173 {
01174 $this->error = "cannot_create_datadir_no_write_access";
01175 return false;
01176 }
01177 }
01178
01179 return true;
01180 }
01181
01187 function checkPasswordSetup($a_formdata)
01188 {
01189 if (!$a_formdata["setup_pass"])
01190 {
01191 $this->error = "no_setup_pass_given";
01192 return false;
01193 }
01194
01195 if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
01196 {
01197 $this->error = "pass_does_not_match";
01198 return false;
01199 }
01200
01201 return true;
01202 }
01203
01209 function checkLogSetup($a_formdata)
01210 {
01211
01212 if (!isset($a_formdata["chk_log_status"]))
01213 {
01214
01215 $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
01216
01217 if (empty($log_path))
01218 {
01219 $this->error = "no_path_log";
01220 return false;
01221 }
01222
01223 if (!@touch($log_path))
01224 {
01225 $this->error = "could_not_create_logfile";
01226 return false;
01227 }
01228 }
01229
01230 return true;
01231 }
01232
01237 function getError()
01238 {
01239 if (empty($this->error))
01240 {
01241 return false;
01242 }
01243
01244 $error = $this->error;
01245 $this->error = "";
01246
01247 return $error;
01248 }
01249
01255 function _ilSetup()
01256 {
01257
01258
01259
01260
01261 return true;
01262 }
01263
01270 function testConvert ($a_convert_path)
01271 {
01272
01273 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01274 {
01275 unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01276 }
01277
01278 system($a_convert_path." ".ILIAS_ABSOLUTE_PATH."/images/test.jpg GIF:".ILIAS_ABSOLUTE_PATH."/images/test.gif");
01279
01280
01281 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01282 {
01283 unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01284 return true;
01285 }
01286 else
01287 {
01288 return false;
01289 }
01290 }
01291
01298 function testJava ($a_java_path)
01299 {
01300 exec($a_java_path, $out, $back);
01301
01302 unset($out);
01303
01304 return ($back != 1) ? false : true;
01305 }
01306
01313 function testZip ($a_zip_path)
01314 {
01315
01316 $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
01317
01318 fwrite($fp, "test");
01319 fclose($fp);
01320
01321 if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
01322 {
01323 $curDir = getcwd();
01324 chdir(ILIAS_ABSOLUTE_PATH);
01325
01326 $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
01327
01328 exec($zipCmd);
01329
01330 chdir($curDir);
01331
01332 }
01333
01334
01335 if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
01336 {
01337 unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
01338 return true;
01339 }
01340 else
01341 {
01342 unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
01343 return false;
01344 }
01345 }
01346
01347
01354 function testUnzip ($a_unzip_path)
01355 {
01356 $curDir = getcwd();
01357
01358 chdir(ILIAS_ABSOLUTE_PATH);
01359
01360 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
01361 {
01362 $unzipCmd = $a_unzip_path." unzip_test_file.zip";
01363 exec($unzipCmd);
01364 }
01365
01366 chdir($curDir);
01367
01368
01369 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
01370 {
01371 unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
01372
01373 return true;
01374 }
01375 else
01376 {
01377 return false;
01378 }
01379 }
01380
01387 function testHtmldoc($a_htmldoc_path)
01388 {
01389 $curDir = getcwd();
01390
01391 chdir(ILIAS_ABSOLUTE_PATH);
01392
01393 $html = "<html><head><title></title></head><body><p>test</p></body></html>";
01394
01395 $html_file = "htmldoc_test_file.html";
01396
01397 $fp = fopen( $html_file ,"wb");
01398 fwrite($fp, $html);
01399 fclose($fp);
01400
01401 $htmldoc = $a_htmldoc_path." ";
01402 $htmldoc .= "--no-toc ";
01403 $htmldoc .= "--no-jpeg ";
01404 $htmldoc .= "--webpage ";
01405 $htmldoc .= "--outfile htmldoc_test_file.pdf ";
01406 $htmldoc .= "--bodyfont Arial ";
01407 $htmldoc .= "--charset iso-8859-15 ";
01408 $htmldoc .= "--color ";
01409 $htmldoc .= "--size A4 ";
01410 $htmldoc .= "--format pdf ";
01411 $htmldoc .= "--footer ... ";
01412 $htmldoc .= "--header ... ";
01413 $htmldoc .= "--left 60 ";
01414
01415 $htmldoc .= $html_file;
01416 exec($htmldoc);
01417
01418 unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
01419
01420 chdir($curDir);
01421
01422 if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
01423 {
01424 unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
01425 return true;
01426 }
01427 else
01428 {
01429 return false;
01430 }
01431 }
01432 }
01433 ?>