• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

setup/classes/class.ilSetup.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00035 class ilSetup extends PEAR
00036 {
00037         var $ini;                       // ini file object
00038         var $ini_file_path;     // full path to setup.ini, containing the client list
00039         var $error = "";        // error text
00040 
00041         var $ini_ilias_exists = false;  // control flag ilias.ini
00042         var $ini_client_exists = false; // control flag client.ini
00043         
00044         var $setup_defaults;                    // ilias.master.ini
00045         var $ilias_nic_server = "http://homer.ilias.uni-koeln.de/ilias-nic/index.php";  // URL to ilias nic server
00046 
00047         var $preliminaries_result = array();    // preliminaries check results
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;            // master setup password
00072         var $default_client;            // client id of default client
00073         
00074         var $safe_mode;                         // safe mode enabled (true) or disabled (false)
00075         var $safe_mode_exec_dir;        // contains exec_dir_path 
00076         
00077         var $auth;                                      // current user is authenticated? (true)
00078         var $access_mode;                       // if "admin", admin functions are enabled
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                 // safe mode status & exec_dir
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                 // Error Handling
00104                 $this->error_obj = new ilErrorHandling();
00105                 $this->setErrorHandling(PEAR_ERROR_CALLBACK,array($this->error_obj,'errorHandler'));
00106 
00107                 // set path to ilias.ini
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                 // init setup.ini
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                 // load data from setup.ini file
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                 // save client id to session
00166                 $_SESSION["ClientId"] = $this->client->getId();
00167                 
00168                 // create client
00169                 if (!$this->client->create())
00170                 {
00171                         $this->error = $this->client->getError();
00172                         return false;
00173                 }
00174 
00175                 //everything okay
00176                 $this->ini_client_exists = true;
00177 
00178                 return true;            
00179         }
00180         
00186         function updateNewClient($a_old_client_id)
00187         {
00188                 return true;
00189                 //var_dump("<pre>",$this->client,"</pre>");exit;
00190 
00191                 if ($a_old_client_id != $this->client->getId())
00192                 {
00193                         // check for existing client dir
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                 //everything okay
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                                 //take line per line, until last char is ";"
00229                                 if (substr($sql[$i],-1)==";")
00230                                 {
00231                                         //query is complete
00232                                         $q .= " ".substr($sql[$i],0,-1);
00233                                         $r = $db->query($q);
00234                                         if ($r == false)
00235                                                 return false;
00236                                         unset($q);
00237                                 } //if
00238                                 else
00239                                 {
00240                                         $q .= " ".$sql[$i];
00241                                 } //else
00242                         } //if
00243                 } //for
00244                 return true;
00245         }
00246 
00251         function createDatabase()
00252         {
00253                 if ($this->client->checkDatabaseExists())
00254                 {
00255                         $this->error = $this->lng->txt("database_exists");
00256                         return false;
00257                 }
00258                 
00259                 //create database
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                 $sql = "CREATE DATABASE ".$this->client->getdbName();
00268                 $r = $db->query($sql);
00269 
00270                 if (DB::isError($r))
00271                 {
00272                         $this->error = "create_database_failed";
00273                         return false;
00274                 }
00275 
00276                 //database is created, now disconnect and reconnect
00277                 $db->disconnect();
00278                 
00279                 $this->client->db_exists = true;
00280                 return true;
00281         }
00282         
00287         function installDatabase()
00288         {
00289                 if (!$this->client->checkDatabaseHost())
00290                 {
00291                         $this->error = "no_connection_to_host";
00292                         return false;
00293                 }
00294 
00295                 if (!$this->client->connect())
00296                 {
00297                         return false;
00298                 }
00299 
00300                 //take sql dump an put it in
00301                 $q = file($this->SQL_FILE);
00302                 $q = implode("\n",$q);
00303 
00304                 if ($this->execQuery($this->client->db,$q) === false)
00305                 {
00306                         $this->error = "dump_error";
00307                         return false;
00308                 }
00309 
00310                 $this->client->db_installed = true;
00311                 return true;
00312         }
00313 
00318         function checkIniFileExists()
00319         {
00320                 $a = @file_exists($this->INI_FILE);
00321                 return $a;
00322         }
00323 
00329         function checkWritable($a_dir = "..")
00330         {
00331                 clearstatcache();
00332                 if (is_writable($a_dir))
00333                 {
00334                         $arr["status"] = true;
00335                         $arr["comment"] = "";
00336                 }
00337                 else
00338                 {
00339                         $arr["status"] = false;
00340                         $arr["comment"] = $this->lng->txt("pre_folder_write_error");
00341                 }
00342 
00343                 return $arr;
00344         }
00345 
00351         function checkCreatable($a_dir = "..")
00352         {
00353                 clearstatcache();
00354                 if (mkdir($a_dir."/crst879dldsk9d", 0774))
00355                 {
00356                         $arr["status"] = true;
00357                         $arr["comment"] = "";
00358 
00359                         rmdir($a_dir."/crst879dldsk9d");
00360                 }
00361                 else
00362                 {
00363                         $arr["status"] = false;
00364                         $arr["comment"] = $this->lng->txt("pre_folder_create_error");
00365                 }
00366 
00367                 return $arr;
00368         }
00369 
00374         function checkCookiesEnabled()
00375         {
00376                 global $sess;
00377 
00378                 if ($sess->usesCookies)
00379                 {
00380                         $arr["status"] = true;
00381                         $arr["comment"] = "";
00382                 }
00383                 else
00384                 {
00385                         $arr["status"] = false;
00386                         $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
00387                 }
00388 
00389                 return $arr;
00390         }
00391 
00396         function checkPHPVersion()
00397         {
00398                 $version =  phpversion();
00399                 $arr["version"] = $version;
00400                 $first = (integer) substr($version,0,1);
00401 
00402                 switch ($first)
00403                 {
00404                         case 2:
00405                         case 3:
00406                                 $arr["status"] = false;
00407                                 $arr["comment"] = $this->lng->txt("pre_php_version_3");
00408                                 break;
00409 
00410                         case 4:
00411                                 $second = (integer) substr($version,2,1);
00412                                 if ($second >= 3)
00413                                 {
00414                                         $arr["status"] = true;
00415                                         $arr["comment"] = "";
00416                                 }
00417                                 elseif ($second == 2)
00418                                 {
00419                                         $arr["status"] = false;
00420                                         $arr["comment"] = $this->lng->txt("pre_php_version_4.2");
00421                                 }
00422                                 else
00423                                 {
00424                                         $arr["status"] = false;
00425                                         $arr["comment"] = $this->lng->txt("pre_php_version_4.1");
00426                                 }
00427                                 break;
00428 
00429                         case 5:
00430                                 $arr["status"] = true;
00431                                 $arr["comment"] = $this->lng->txt("pre_php_version_5");
00432                                 break;
00433 
00434                         default:
00435                                 $arr["status"] = true;
00436                                 $arr["comment"] = $this->lng->txt("pre_php_version_unknown");
00437                                 break;
00438                 }
00439 
00440                 return $arr;
00441         }
00442 
00447         function checkAuth()
00448         {
00449                 if ($_SESSION["auth"] === true)
00450                 {
00451                         return true;
00452                 }
00453 
00454                 return false;
00455         }
00456         
00464         function queryPreliminaries()
00465         {
00466                 $a = array();
00467                 $a["php"] = $this->checkPHPVersion();
00468                 $a["root"] = $this->checkWritable();
00469                 $a["create"] = $this->checkCreatable();
00470                 $a["cookies"] = $this->checkCookiesEnabled();
00471 
00472                 return $a;
00473         }
00474 
00479         function checkPreliminaries()
00480         {
00481                 $this->preliminaries_result = $this->queryPreliminaries();
00482 
00483                 foreach ($this->preliminaries_result as $val)
00484                 {
00485                         if ($val["status"] === false)
00486                         {
00487                                 $this->preliminaries = false;
00488                                 return false;
00489                         }
00490                 }
00491 
00492                 return true;
00493         }
00494 
00499         function getPassword ()
00500         {
00501                 return $this->ini->readVariable("setup","pass");
00502         }
00503 
00509         function setPassword ($a_password)
00510         {
00511                 $this->ini->setVariable("setup","pass",md5($a_password));
00512 
00513                 if ($this->ini->write() == false)
00514                 {
00515                         $this->error = $this->ini->getError();
00516                         return false;
00517                 }
00518                 
00519                 return true;
00520         }
00521         
00527         function loginAsClient($a_auth_data)
00528         {
00529                 if (empty($a_auth_data["client_id"]))
00530                 {
00531                         $this->error = "no_client_id";
00532                         return false;
00533                 }
00534 
00535                 if (empty($a_auth_data["username"]))
00536                 {
00537                         $this->error = "no_username";
00538                         return false;
00539                 }
00540 
00541                 if (empty($a_auth_data["password"]))
00542                 {
00543                         $this->error = "no_password";
00544                         return false;
00545                 }
00546                 
00547                 if (!$this->newClient($a_auth_data["client_id"]))
00548                 {
00549                         $this->error = "unknown_client_id";
00550                         unset($this->client);
00551                         return false;
00552                 }
00553                 
00554                 if (!$this->client->db_exists)
00555                 {
00556                         $this->error = "no_db_connect_consult_admin";
00557                         unset($this->client);
00558                         return false;           
00559                 }
00560                 
00561                 $q = "SELECT usr_data.usr_id FROM usr_data ".
00562                          "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id ".
00563                          "LEFT JOIN settings ON settings.value = rbac_ua.rol_id ".
00564                          "WHERE settings.keyword='system_role_id' ".
00565                          "AND usr_data.login='".$a_auth_data["username"]."' ".
00566                          "AND usr_data.passwd='".md5($a_auth_data["password"])."'";
00567                 $r = $this->client->db->query($q);
00568                 
00569                 if (!$r->numRows())
00570                 {
00571                         $this->error = "login_invalid";
00572                         return false;
00573                 }
00574 
00575                 // all checks passed -> user valid
00576                 $_SESSION["auth"] = true;
00577                 $_SESSION["access_mode"] = "client";
00578                 $_SESSION["ClientId"] = $this->client->getId();         
00579                 return true;
00580         }
00581 
00587         function loginAsAdmin($a_password)
00588         {
00589                 $a_password = md5($a_password);
00590                 
00591                 if ($this->ini->readVariable("setup","pass") == $a_password)
00592                 {
00593                         $_SESSION["auth"] = true;
00594                         $_SESSION["access_mode"] = "admin";
00595                         return true;
00596                 }
00597                 
00598                 return false;
00599         }
00600 
00606         function newClient($a_client_id = 0)
00607         {
00608                 if (!$this->isInstalled())
00609                 {
00610                         return false;
00611                 }
00612 
00613                 $this->client = new ilClient($a_client_id);
00614 
00615                 if (!$this->client->init())
00616                 {
00617                         $this->error = get_class($this).": ".$this->client->getError();
00618                         $_SESSION["ClientId"] = "";
00619                         return false;
00620                 }
00621                 
00622                 $_SESSION["ClientId"] = $a_client_id;
00623                 
00624                 return true;
00625         }
00626         
00632         function getStatus ($client = 0)
00633         {
00634                 if (!is_object($client))
00635                 {
00636                         if ($this->ini_client_exists)
00637                         {
00638                                 $client =& $this->client;
00639                         }
00640                         else
00641                         {
00642                                 $client = new ilClient();
00643                         }
00644                 }
00645                 
00646                 $status = array();
00647                 $status["ini"] = $this->checkClientIni($client);
00648                 $status["db"] = $this->checkClientDatabase($client);
00649                 
00650                 if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
00651                 {
00652                         $status["lang"]["status"] = false;
00653                         $status["lang"]["comment"] = $status["db"]["comment"];
00654                         $status["contact"]["status"] = false;
00655                         $status["contact"]["comment"] = $status["db"]["comment"];
00656                         $status["nic"]["status"] = false;
00657                         $status["nic"]["comment"] = $status["db"]["comment"];
00658                 }
00659                 else
00660                 {
00661                         $status["lang"] = $this->checkClientLanguages($client);
00662                         $status["contact"] = $this->checkClientContact($client);
00663                         $status["nic"] = $this->checkClientNIC($client);
00664                         $status["finish"] = $this->checkFinish($client);
00665                         $status["access"] = $this->checkAccess($client);
00666                 }
00667 
00668                 //return value
00669                 return $status;
00670         }
00671         
00677         function checkFinish(&$client)
00678         {
00679                 if ($client->getSetting("setup_ok"))
00680                 {
00681                         $arr["status"] = true;
00682                         $arr["comment"] = $this->lng->txt("setup_finished");
00683                 }
00684                 else
00685                 {
00686                         $arr["status"] = false;
00687                         $arr["comment"] = $this->lng->txt("setup_not_finished");
00688                 }
00689                 
00690                 return $arr;
00691         }
00692         
00698         function checkAccess(&$client)
00699         {
00700                 if ($client->ini->readVariable("client","access") == "1")
00701                 {
00702                         $arr["status"] = true;
00703                         $arr["comment"] = $this->lng->txt("online");
00704                 }
00705                 else
00706                 {
00707                         $arr["status"] = false;
00708                         $arr["comment"] = $this->lng->txt("disabled");
00709                 }
00710                 
00711                 return $arr;
00712         }
00713 
00719         function checkClientIni(&$client)
00720         {
00721                 if (!$arr["status"] = $client->init())
00722                 {
00723                         $arr["comment"] = $client->getError();
00724                 }
00725                 else
00726                 {
00727                         $arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();                  
00728                 }
00729                 
00730                 return $arr; 
00731         }
00732         
00738         function checkClientDatabase(&$client)
00739         {
00740                 if (!$arr["status"] = $client->db_exists)
00741                 {
00742                         $arr["comment"] = $this->lng->txt("no_database");
00743                         return $arr;
00744                 }
00745                 
00746                 if (!$arr["status"] = $client->db_installed)
00747                 {
00748                         $arr["comment"] = $this->lng->txt("db_not_installed");
00749                         return $arr;
00750                 }
00751                 
00752                 // TODO: move this to client class!!
00753                 $client->setup_ok = (bool) $client->getSetting("setup_ok");
00754                         
00755                 $this->lng->setDbHandler($client->db);
00756                 include_once "../classes/class.ilDBUpdate.php";
00757                 $dbupdate = new ilDBUpdate($client->db);
00758                                 
00759                 if (!$arr["status"] = $dbupdate->getDBVersionStatus())
00760                 {
00761                         $arr["comment"] = $this->lng->txt("db_needs_update");
00762                         $arr["update"] = true;
00763                         return $arr;
00764                 }
00765 
00766                 $arr["comment"] = "version ".$dbupdate->getCurrentVersion();
00767                 return $arr;
00768         }
00769 
00775         function checkClientLanguages(&$client)
00776         {
00777                 $installed_langs = $this->lng->getInstalledLanguages();
00778                 
00779                 $count = count($installed_langs);
00780                 
00781                 if ($count < 1)
00782                 {
00783                         $arr["status"] = false;
00784                         $arr["comment"] = $this->lng->txt("lang_none_installed");               
00785                 }
00786                 else
00787                 {
00788                         $arr["status"] = true;
00789                         $arr["comment"] = $count." ".$this->lng->txt("languages_installed");
00790                 }
00791                 
00792                 return $arr;
00793         }
00794         
00800         function checkClientContact(&$client)
00801         {
00802                 $arr["status"] = true;
00803                 $arr["comment"] = $this->lng->txt("filled_out");
00804 
00805                 $settings = $client->getAllSettings();
00806                 $client_name = $client->getName();
00807 
00808                 // check required fields
00809                 if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"])
00810                         or empty($settings["admin_street"]) or empty($settings["admin_zipcode"])
00811                         or empty($settings["admin_country"]) or empty($settings["admin_city"])
00812                         or empty($settings["admin_phone"]) or empty($settings["admin_email"])
00813                         or empty($client_name) or empty($settings["inst_institution"]))
00814                 {
00815                         $arr["status"] = false;
00816                         $arr["comment"] = $this->lng->txt("missing_data");
00817                 }
00818                         
00819                 // admin email
00820                 if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
00821                 {
00822                         $arr["status"] = false;
00823                         $arr["comment"] = $this->lng->txt("email_not_valid");
00824                 }
00825                 
00826                 return $arr;
00827         }
00828         
00834         function checkClientNIC(&$client)
00835         {
00836                 $settings = $client->getAllSettings();
00837                 
00838                 if (!isset($settings["nic_enabled"]))
00839                 {
00840                         $arr["status"] = false;
00841                         $arr["comment"] = $this->lng->txt("nic_not_disabled");
00842                         return $arr;
00843                 }
00844                 
00845                 $arr["status"] = true;
00846 
00847                 if ($settings["nic_enabled"] == "-1")
00848                 {
00849                         $arr["comment"] = $this->lng->txt("nic_reg_failed");
00850                         return $arr;
00851                 }
00852 
00853                 if (!$settings["nic_enabled"])
00854                 {
00855                         $arr["comment"] = $this->lng->txt("nic_reg_disabled");
00856                 }
00857                 else
00858                 {
00859                         $arr["comment"] = $this->lng->txt("nic_reg_enabled");
00860                 }
00861 
00862                 return $arr;
00863         }
00864         
00869         function isInstalled()
00870         {
00871                 return $this->ini_ilias_exists;
00872         }
00873         
00878         function isAuthenticated()
00879         {
00880                 return $this->auth;
00881         }
00882 
00887         function isAdmin()
00888         {
00889                 return ($this->access_mode == "admin") ? true : false;
00890         }
00891         
00897         function saveMasterSetup($a_formdata)
00898         {
00899                 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
00900 
00901                 if ($a_formdata["chk_datadir_path"] == 1)       // mode create dir 
00902                 {
00903                         if (!ilUtil::makeDir($datadir_path))
00904                         {
00905                                 $this->error = "create_datadir_failed";
00906                                 return false;
00907                         }
00908                 }
00909 
00910                 // create webspace dir if it does not exist
00911                 if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00912                 {
00913                         if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00914                         {
00915                                 $this->error = "create_webdir_failed";
00916                                 return false;
00917                         }                       
00918                 }
00919                 
00920                 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
00921                 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
00922                 $log_file = substr($form_log_path,strlen($log_path)+1);
00923                 
00924                 $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
00925                 $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
00926                 $this->ini->setVariable("clients", "datadir", $datadir_path);
00927                 $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
00928                 $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
00929                 $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
00930                 $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
00931                 $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
00932                 $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
00933                 $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
00934                 $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
00935                 $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
00936                 $this->ini->setVariable("log", "path", $log_path);
00937                 $this->ini->setVariable("log", "file", $log_file);
00938                 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
00939 
00940                 if (!$this->ini->write())
00941                 {
00942                         $this->error = get_class($this).": ".$this->ini->getError();
00943                         return false;
00944                 }
00945 
00946                 // everything is fine. so we authenticate the user and set access mode to 'admin'
00947                 $_SESSION["auth"] = true;
00948                 $_SESSION["access_mode"] = "admin";     
00949 
00950                 return true;
00951         }
00952         
00958         function updateMasterSettings($a_formdata)
00959         {
00960                 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
00961                 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
00962                 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
00963                 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
00964                 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
00965                 $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
00966                 $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
00967                 $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
00968                 $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
00969 
00970                 $this->ini->setVariable("tools", "convert", $convert_path);
00971                 $this->ini->setVariable("tools", "zip", $zip_path);
00972                 $this->ini->setVariable("tools", "unzip", $unzip_path);
00973                 $this->ini->setVariable("tools", "java", $java_path);
00974                 $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
00975                 $this->ini->setVariable("tools", "fop", $fop_path);
00976                 $this->ini->setVariable("tools", "vscantype", $scan_type);
00977                 $this->ini->setVariable("tools", "scancommand", $scan_command);
00978                 $this->ini->setVariable("tools", "cleancommand", $clean_command);
00979 
00980                 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
00981                 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
00982                 $log_file = substr($form_log_path,strlen($log_path)+1);
00983 
00984                 $this->ini->setVariable("log", "path", $log_path);
00985                 $this->ini->setVariable("log", "file", $log_file);
00986                 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
00987 
00988                 if (!$this->ini->write())
00989                 {
00990                         $this->error = get_class($this).": ".$this->ini->getError();
00991                         return false;
00992                 }
00993 
00994                 return true;
00995         }
00996 
01002         function checkToolsSetup($a_formdata)
01003         {
01004                 // convert path
01005                 if (!isset($a_formdata["chk_convert_path"]))
01006                 {
01007                         // convert backslashes to forwardslashes
01008                         $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
01009 
01010                         if (empty($convert_path))
01011                         {
01012                                 $this->error = "no_path_convert";
01013                                 return false;
01014                         }
01015                         
01016                         if (!$this->testConvert($convert_path))
01017                         {
01018                                 $this->error = "check_failed_convert";
01019                                 return false;
01020                         }
01021                 }
01022                 
01023                 // zip path
01024                 if (!isset($a_formdata["chk_zip_path"]))
01025                 {
01026                         // convert backslashes to forwardslashes
01027                         $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
01028                         
01029                         if (empty($zip_path))
01030                         {
01031                                 $this->error = "no_path_zip";
01032                                 return false;
01033                         }
01034                 
01035                         if (!$this->testZip($zip_path))
01036                         {
01037                                 $this->error = "check_failed_zip";
01038                                 return false;
01039                         }
01040                 }
01041 
01042                 // unzip path
01043                 if (!isset($a_formdata["chk_unzip_path"]))
01044                 {
01045                         // convert backslashes to forwardslashes
01046                         $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
01047 
01048                         if (empty($unzip_path))
01049                         {
01050                                 $this->error = "no_path_unzip";
01051                                 return false;
01052                         }
01053 
01054                         if (!$this->testUnzip($unzip_path))
01055                         {
01056                                 $this->error = "check_failed_unzip";
01057                                 return false;
01058                         }
01059                 }
01060                 
01061                 // java path
01062                 if (!isset($a_formdata["chk_java_path"]))
01063                 {
01064                         // convert backslashes to forwardslashes
01065                         $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
01066 
01067                         if (empty($java_path))
01068                         {
01069                                 $this->error = "no_path_java";
01070                                 return false;
01071                         }
01072                 
01073                         if (!$this->testJava($java_path))
01074                         {
01075                                 $this->error = "check_failed_java";
01076                                 return false;
01077                         }
01078                 }
01079                 
01080                 // htmldoc path
01081                 if (!isset($a_formdata["chk_htmldoc_path"]))
01082                 {
01083                         // convert backslashes to forwardslashes
01084                         $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
01085 
01086                         if (empty($htmldoc_path))
01087                         {
01088                                 $this->error = "no_path_htmldoc";
01089                                 return false;
01090                         }
01091                 
01092                         if (!$this->testHtmldoc($htmldoc_path))
01093                         {
01094                                 $this->error = "check_failed_htmldoc";
01095                                 return false;
01096                         }
01097                 }
01098                 
01099                 return true;
01100         }
01101                 
01107         function checkDataDirSetup($a_formdata)
01108         {
01109                 // remove trailing slash & convert backslashes to forwardslashes
01110                 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
01111 
01112                 if (empty($datadir_path))
01113                 {
01114                         $this->error = "no_path_datadir";
01115                         return false;
01116                 }
01117 
01118                 $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
01119                 
01120                 // datadir may not point to webspace dir or to any place under webspace_dir
01121                 if (strpos($datadir_path,$webspace_dir) !== false)
01122                 {
01123                         $this->error = "datadir_webspacedir_match";
01124                         return false;
01125                 }
01126 
01127                 // create dir
01128                 if ($a_formdata["chk_datadir_path"] == 1)
01129                 {
01130                         $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
01131                         $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
01132 
01133                         if (is_writable($datadir_path))
01134                         {
01135                                 $this->error = "dir_exists_create";
01136                                 return false;
01137                         }
01138 
01139                         if (!is_writable($dir_to_check))
01140                         {
01141                                 $this->error = "cannot_create_datadir_no_write_access";
01142                                 return false;
01143                         }
01144                 }
01145                 else    // check set target dir
01146                 {
01147                         if (!is_writable($datadir_path))
01148                         {
01149                                 $this->error = "cannot_create_datadir_no_write_access";
01150                                 return false;
01151                         }
01152                 }
01153 
01154                 return true;
01155         }
01156 
01162         function checkPasswordSetup($a_formdata)
01163         {
01164                 if (!$a_formdata["setup_pass"])
01165                 {
01166                         $this->error = "no_setup_pass_given";
01167                         return false;
01168                 }
01169 
01170                 if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
01171                 {
01172                         $this->error = "pass_does_not_match";
01173                         return false;
01174                 }
01175                 
01176                 return true;
01177         }
01178         
01184         function checkLogSetup($a_formdata)
01185         {
01186                 // log path
01187                 if (!isset($a_formdata["chk_log_status"]))
01188                 {
01189                         // remove trailing slash & convert backslashes to forwardslashes
01190                         $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
01191 
01192                         if (empty($log_path))
01193                         {
01194                                 $this->error = "no_path_log";
01195                                 return false;
01196                         }
01197 
01198                         if (!@touch($log_path))
01199                         {
01200                                 $this->error = "could_not_create_logfile";
01201                                 return false;
01202                         }
01203                 }
01204                 
01205                 return true;
01206         }
01207         
01212         function getError()
01213         {
01214                 if (empty($this->error))
01215                 {
01216                         return false;
01217                 }
01218                 
01219                 $error = $this->error;
01220                 $this->error = "";
01221                 
01222                 return $error;
01223         }
01224 
01230         function _ilSetup()
01231         {
01232                 //if ($this->ini->readVariable("db","type") != "")
01233                 //{
01234                 //      $this->db->disconnect();
01235                 //}
01236                 return true;
01237         }
01238 
01245         function testConvert ($a_convert_path)
01246         {
01247                 // generate gif with convert
01248                 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01249                 {
01250                         unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01251                 }
01252 
01253                 system($a_convert_path." ".ILIAS_ABSOLUTE_PATH."/images/test.jpg GIF:".ILIAS_ABSOLUTE_PATH."/images/test.gif");
01254         
01255                 // check wether convert generated file
01256                 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01257                 {
01258                         unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01259                         return true;
01260                 }
01261                 else
01262                 {
01263                         return false;
01264                 }
01265         }
01266 
01273         function testJava ($a_java_path)
01274         {
01275                 exec($a_java_path, $out, $back);
01276         
01277                 unset($out);
01278         
01279                 return ($back != 1) ? false : true;
01280         }
01281 
01288         function testZip ($a_zip_path)
01289         {
01290                 // create test file and run zip
01291                 $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
01292                         
01293                 fwrite($fp, "test");
01294                 fclose($fp);
01295                                         
01296                 if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
01297                 {
01298                         $curDir = getcwd();
01299                         chdir(ILIAS_ABSOLUTE_PATH);
01300                                 
01301                         $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
01302                                 
01303                         exec($zipCmd);
01304                                 
01305                         chdir($curDir);
01306 
01307                 }
01308         
01309                 // check wether zip generated test file or not
01310                 if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
01311                 {
01312                         unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
01313                         return true;
01314                 }
01315                 else
01316                 {
01317                         unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
01318                         return false;
01319                 }
01320         }
01321         
01322         
01329         function testUnzip ($a_unzip_path)
01330         {
01331                 $curDir = getcwd();
01332                                 
01333                 chdir(ILIAS_ABSOLUTE_PATH);
01334                                 
01335                 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
01336                 {
01337                         $unzipCmd = $a_unzip_path." unzip_test_file.zip";
01338                         exec($unzipCmd);
01339                 }
01340 
01341                 chdir($curDir);
01342         
01343                 // check wether unzip extracted the test file or not
01344                 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
01345                 {
01346                         unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
01347                 
01348                         return true;
01349                 }
01350                 else
01351                 {
01352                         return false;
01353                 }
01354         }
01355 
01362         function testHtmldoc($a_htmldoc_path)
01363         {
01364                 $curDir = getcwd();
01365                                 
01366                 chdir(ILIAS_ABSOLUTE_PATH);
01367 
01368                 $html = "<html><head><title></title></head><body><p>test</p></body></html>";
01369 
01370                 $html_file = "htmldoc_test_file.html";
01371         
01372         $fp = fopen( $html_file ,"wb");
01373         fwrite($fp, $html);
01374         fclose($fp);
01375 
01376         $htmldoc = $a_htmldoc_path." ";
01377         $htmldoc .= "--no-toc ";
01378         $htmldoc .= "--no-jpeg ";
01379         $htmldoc .= "--webpage ";
01380         $htmldoc .= "--outfile htmldoc_test_file.pdf ";
01381         $htmldoc .= "--bodyfont Arial ";
01382         $htmldoc .= "--charset iso-8859-15 ";
01383         $htmldoc .= "--color ";
01384         $htmldoc .= "--size A4  ";      // --landscape
01385         $htmldoc .= "--format pdf ";
01386         $htmldoc .= "--footer ... ";
01387         $htmldoc .= "--header ... ";
01388         $htmldoc .= "--left 60 ";
01389         // $htmldoc .= "--right 200 ";
01390         $htmldoc .= $html_file;
01391                 exec($htmldoc);
01392 
01393                 unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
01394 
01395                 chdir($curDir);
01396 
01397                 if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
01398                 {
01399                         unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
01400                         return true;
01401                 }
01402                 else
01403                 {
01404                         return false;
01405                 }
01406         }
01407 } // END class.ilSetup
01408 ?>

Generated on Fri Dec 13 2013 08:00:18 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1