• 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($a_collation = "")
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                 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                 //database is created, now disconnect and reconnect
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                 //take sql dump an put it in
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                 // all checks passed -> user valid
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                 //return value
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                 // TODO: move this to client class!!
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                 $arr["comment"] = "version ".$dbupdate->getCurrentVersion();
00776                 return $arr;
00777         }
00778 
00784         function checkClientLanguages(&$client)
00785         {
00786                 $installed_langs = $this->lng->getInstalledLanguages();
00787                 
00788                 $count = count($installed_langs);
00789                 
00790                 if ($count < 1)
00791                 {
00792                         $arr["status"] = false;
00793                         $arr["comment"] = $this->lng->txt("lang_none_installed");               
00794                 }
00795                 else
00796                 {
00797                         $arr["status"] = true;
00798                         $arr["comment"] = $count." ".$this->lng->txt("languages_installed");
00799                 }
00800                 
00801                 return $arr;
00802         }
00803         
00809         function checkClientContact(&$client)
00810         {
00811                 $arr["status"] = true;
00812                 $arr["comment"] = $this->lng->txt("filled_out");
00813 
00814                 $settings = $client->getAllSettings();
00815                 $client_name = $client->getName();
00816 
00817                 // check required fields
00818                 if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"])
00819                         or empty($settings["admin_street"]) or empty($settings["admin_zipcode"])
00820                         or empty($settings["admin_country"]) or empty($settings["admin_city"])
00821                         or empty($settings["admin_phone"]) or empty($settings["admin_email"])
00822                         or empty($client_name) or empty($settings["inst_institution"]))
00823                 {
00824                         $arr["status"] = false;
00825                         $arr["comment"] = $this->lng->txt("missing_data");
00826                 }
00827                         
00828                 // admin email
00829                 if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
00830                 {
00831                         $arr["status"] = false;
00832                         $arr["comment"] = $this->lng->txt("email_not_valid");
00833                 }
00834                 
00835                 return $arr;
00836         }
00837         
00843         function checkClientNIC(&$client)
00844         {
00845                 $settings = $client->getAllSettings();
00846                 
00847                 if (!isset($settings["nic_enabled"]))
00848                 {
00849                         $arr["status"] = false;
00850                         $arr["comment"] = $this->lng->txt("nic_not_disabled");
00851                         return $arr;
00852                 }
00853                 
00854                 $arr["status"] = true;
00855 
00856                 if ($settings["nic_enabled"] == "-1")
00857                 {
00858                         $arr["comment"] = $this->lng->txt("nic_reg_failed");
00859                         return $arr;
00860                 }
00861 
00862                 if (!$settings["nic_enabled"])
00863                 {
00864                         $arr["comment"] = $this->lng->txt("nic_reg_disabled");
00865                 }
00866                 else
00867                 {
00868                         $arr["comment"] = $this->lng->txt("nic_reg_enabled");
00869                 }
00870 
00871                 return $arr;
00872         }
00873         
00878         function isInstalled()
00879         {
00880                 return $this->ini_ilias_exists;
00881         }
00882         
00887         function isAuthenticated()
00888         {
00889                 return $this->auth;
00890         }
00891 
00896         function isAdmin()
00897         {
00898                 return ($this->access_mode == "admin") ? true : false;
00899         }
00900         
00906         function saveMasterSetup($a_formdata)
00907         {
00908                 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
00909 
00910                 if ($a_formdata["chk_datadir_path"] == 1)       // mode create dir 
00911                 {
00912                         if (!ilUtil::makeDir($datadir_path))
00913                         {
00914                                 $this->error = "create_datadir_failed";
00915                                 return false;
00916                         }
00917                 }
00918 
00919                 // create webspace dir if it does not exist
00920                 if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00921                 {
00922                         if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
00923                         {
00924                                 $this->error = "create_webdir_failed";
00925                                 return false;
00926                         }                       
00927                 }
00928                 
00929                 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
00930                 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
00931                 $log_file = substr($form_log_path,strlen($log_path)+1);
00932                 
00933                 $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
00934                 $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
00935                 $this->ini->setVariable("clients", "datadir", $datadir_path);
00936                 $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
00937                 $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
00938                 $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
00939                 $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
00940                 $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
00941                 $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
00942                 $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
00943                 $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
00944                 $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
00945                 $this->ini->setVariable("log", "path", $log_path);
00946                 $this->ini->setVariable("log", "file", $log_file);
00947                 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
00948 
00949                 if (!$this->ini->write())
00950                 {
00951                         $this->error = get_class($this).": ".$this->ini->getError();
00952                         return false;
00953                 }
00954 
00955                 // everything is fine. so we authenticate the user and set access mode to 'admin'
00956                 $_SESSION["auth"] = true;
00957                 $_SESSION["access_mode"] = "admin";     
00958 
00959                 return true;
00960         }
00961         
00967         function updateMasterSettings($a_formdata)
00968         {
00969                 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
00970                 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
00971                 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
00972                 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
00973                 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
00974                 $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
00975                 $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
00976                 $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
00977                 $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
00978 
00979                 $this->ini->setVariable("tools", "convert", $convert_path);
00980                 $this->ini->setVariable("tools", "zip", $zip_path);
00981                 $this->ini->setVariable("tools", "unzip", $unzip_path);
00982                 $this->ini->setVariable("tools", "java", $java_path);
00983                 $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
00984                 $this->ini->setVariable("tools", "fop", $fop_path);
00985                 $this->ini->setVariable("tools", "vscantype", $scan_type);
00986                 $this->ini->setVariable("tools", "scancommand", $scan_command);
00987                 $this->ini->setVariable("tools", "cleancommand", $clean_command);
00988 
00989                 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
00990                 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
00991                 $log_file = substr($form_log_path,strlen($log_path)+1);
00992 
00993                 $this->ini->setVariable("log", "path", $log_path);
00994                 $this->ini->setVariable("log", "file", $log_file);
00995                 $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
00996 
00997                 if (!$this->ini->write())
00998                 {
00999                         $this->error = get_class($this).": ".$this->ini->getError();
01000                         return false;
01001                 }
01002 
01003                 return true;
01004         }
01005 
01011         function checkToolsSetup($a_formdata)
01012         {
01013                 // convert path
01014                 if (!isset($a_formdata["chk_convert_path"]))
01015                 {
01016                         // convert backslashes to forwardslashes
01017                         $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
01018 
01019                         if (empty($convert_path))
01020                         {
01021                                 $this->error = "no_path_convert";
01022                                 return false;
01023                         }
01024                         
01025                         if (!$this->testConvert($convert_path))
01026                         {
01027                                 $this->error = "check_failed_convert";
01028                                 return false;
01029                         }
01030                 }
01031                 
01032                 // zip path
01033                 if (!isset($a_formdata["chk_zip_path"]))
01034                 {
01035                         // convert backslashes to forwardslashes
01036                         $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
01037                         
01038                         if (empty($zip_path))
01039                         {
01040                                 $this->error = "no_path_zip";
01041                                 return false;
01042                         }
01043                 
01044                         if (!$this->testZip($zip_path))
01045                         {
01046                                 $this->error = "check_failed_zip";
01047                                 return false;
01048                         }
01049                 }
01050 
01051                 // unzip path
01052                 if (!isset($a_formdata["chk_unzip_path"]))
01053                 {
01054                         // convert backslashes to forwardslashes
01055                         $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
01056 
01057                         if (empty($unzip_path))
01058                         {
01059                                 $this->error = "no_path_unzip";
01060                                 return false;
01061                         }
01062 
01063                         if (!$this->testUnzip($unzip_path))
01064                         {
01065                                 $this->error = "check_failed_unzip";
01066                                 return false;
01067                         }
01068                 }
01069                 
01070                 // java path
01071                 if (!isset($a_formdata["chk_java_path"]))
01072                 {
01073                         // convert backslashes to forwardslashes
01074                         $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
01075 
01076                         if (empty($java_path))
01077                         {
01078                                 $this->error = "no_path_java";
01079                                 return false;
01080                         }
01081                 
01082                         if (!$this->testJava($java_path))
01083                         {
01084                                 $this->error = "check_failed_java";
01085                                 return false;
01086                         }
01087                 }
01088                 
01089                 // htmldoc path
01090                 if (!isset($a_formdata["chk_htmldoc_path"]))
01091                 {
01092                         // convert backslashes to forwardslashes
01093                         $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
01094 
01095                         if (empty($htmldoc_path))
01096                         {
01097                                 $this->error = "no_path_htmldoc";
01098                                 return false;
01099                         }
01100                 
01101                         if (!$this->testHtmldoc($htmldoc_path))
01102                         {
01103                                 $this->error = "check_failed_htmldoc";
01104                                 return false;
01105                         }
01106                 }
01107                 
01108                 return true;
01109         }
01110                 
01116         function checkDataDirSetup($a_formdata)
01117         {
01118                 // remove trailing slash & convert backslashes to forwardslashes
01119                 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
01120 
01121                 if (empty($datadir_path))
01122                 {
01123                         $this->error = "no_path_datadir";
01124                         return false;
01125                 }
01126 
01127                 $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
01128                 
01129                 // datadir may not point to webspace dir or to any place under webspace_dir
01130                 if (strpos($datadir_path,$webspace_dir) !== false)
01131                 {
01132                         $this->error = "datadir_webspacedir_match";
01133                         return false;
01134                 }
01135 
01136                 // create dir
01137                 if ($a_formdata["chk_datadir_path"] == 1)
01138                 {
01139                         $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
01140                         $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
01141 
01142                         if (is_writable($datadir_path))
01143                         {
01144                                 $this->error = "dir_exists_create";
01145                                 return false;
01146                         }
01147 
01148                         if (!is_writable($dir_to_check))
01149                         {
01150                                 $this->error = "cannot_create_datadir_no_write_access";
01151                                 return false;
01152                         }
01153                 }
01154                 else    // check set target dir
01155                 {
01156                         if (!is_writable($datadir_path))
01157                         {
01158                                 $this->error = "cannot_create_datadir_no_write_access";
01159                                 return false;
01160                         }
01161                 }
01162 
01163                 return true;
01164         }
01165 
01171         function checkPasswordSetup($a_formdata)
01172         {
01173                 if (!$a_formdata["setup_pass"])
01174                 {
01175                         $this->error = "no_setup_pass_given";
01176                         return false;
01177                 }
01178 
01179                 if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
01180                 {
01181                         $this->error = "pass_does_not_match";
01182                         return false;
01183                 }
01184                 
01185                 return true;
01186         }
01187         
01193         function checkLogSetup($a_formdata)
01194         {
01195                 // log path
01196                 if (!isset($a_formdata["chk_log_status"]))
01197                 {
01198                         // remove trailing slash & convert backslashes to forwardslashes
01199                         $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
01200 
01201                         if (empty($log_path))
01202                         {
01203                                 $this->error = "no_path_log";
01204                                 return false;
01205                         }
01206 
01207                         if (!@touch($log_path))
01208                         {
01209                                 $this->error = "could_not_create_logfile";
01210                                 return false;
01211                         }
01212                 }
01213                 
01214                 return true;
01215         }
01216         
01221         function getError()
01222         {
01223                 if (empty($this->error))
01224                 {
01225                         return false;
01226                 }
01227                 
01228                 $error = $this->error;
01229                 $this->error = "";
01230                 
01231                 return $error;
01232         }
01233 
01239         function _ilSetup()
01240         {
01241                 //if ($this->ini->readVariable("db","type") != "")
01242                 //{
01243                 //      $this->db->disconnect();
01244                 //}
01245                 return true;
01246         }
01247 
01254         function testConvert ($a_convert_path)
01255         {
01256                 // generate gif with convert
01257                 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01258                 {
01259                         unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01260                 }
01261 
01262                 system($a_convert_path." ".ILIAS_ABSOLUTE_PATH."/images/test.jpg GIF:".ILIAS_ABSOLUTE_PATH."/images/test.gif");
01263         
01264                 // check wether convert generated file
01265                 if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
01266                 {
01267                         unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
01268                         return true;
01269                 }
01270                 else
01271                 {
01272                         return false;
01273                 }
01274         }
01275 
01282         function testJava ($a_java_path)
01283         {
01284                 exec($a_java_path, $out, $back);
01285         
01286                 unset($out);
01287         
01288                 return ($back != 1) ? false : true;
01289         }
01290 
01297         function testZip ($a_zip_path)
01298         {
01299                 // create test file and run zip
01300                 $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
01301                         
01302                 fwrite($fp, "test");
01303                 fclose($fp);
01304                                         
01305                 if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
01306                 {
01307                         $curDir = getcwd();
01308                         chdir(ILIAS_ABSOLUTE_PATH);
01309                                 
01310                         $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
01311                                 
01312                         exec($zipCmd);
01313                                 
01314                         chdir($curDir);
01315 
01316                 }
01317         
01318                 // check wether zip generated test file or not
01319                 if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
01320                 {
01321                         unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
01322                         return true;
01323                 }
01324                 else
01325                 {
01326                         unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
01327                         return false;
01328                 }
01329         }
01330         
01331         
01338         function testUnzip ($a_unzip_path)
01339         {
01340                 $curDir = getcwd();
01341                                 
01342                 chdir(ILIAS_ABSOLUTE_PATH);
01343                                 
01344                 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
01345                 {
01346                         $unzipCmd = $a_unzip_path." unzip_test_file.zip";
01347                         exec($unzipCmd);
01348                 }
01349 
01350                 chdir($curDir);
01351         
01352                 // check wether unzip extracted the test file or not
01353                 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
01354                 {
01355                         unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
01356                 
01357                         return true;
01358                 }
01359                 else
01360                 {
01361                         return false;
01362                 }
01363         }
01364 
01371         function testHtmldoc($a_htmldoc_path)
01372         {
01373                 $curDir = getcwd();
01374                                 
01375                 chdir(ILIAS_ABSOLUTE_PATH);
01376 
01377                 $html = "<html><head><title></title></head><body><p>test</p></body></html>";
01378 
01379                 $html_file = "htmldoc_test_file.html";
01380         
01381         $fp = fopen( $html_file ,"wb");
01382         fwrite($fp, $html);
01383         fclose($fp);
01384 
01385         $htmldoc = $a_htmldoc_path." ";
01386         $htmldoc .= "--no-toc ";
01387         $htmldoc .= "--no-jpeg ";
01388         $htmldoc .= "--webpage ";
01389         $htmldoc .= "--outfile htmldoc_test_file.pdf ";
01390         $htmldoc .= "--bodyfont Arial ";
01391         $htmldoc .= "--charset iso-8859-15 ";
01392         $htmldoc .= "--color ";
01393         $htmldoc .= "--size A4  ";      // --landscape
01394         $htmldoc .= "--format pdf ";
01395         $htmldoc .= "--footer ... ";
01396         $htmldoc .= "--header ... ";
01397         $htmldoc .= "--left 60 ";
01398         // $htmldoc .= "--right 200 ";
01399         $htmldoc .= $html_file;
01400                 exec($htmldoc);
01401 
01402                 unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
01403 
01404                 chdir($curDir);
01405 
01406                 if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
01407                 {
01408                         unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
01409                         return true;
01410                 }
01411                 else
01412                 {
01413                         return false;
01414                 }
01415         }
01416 } // END class.ilSetup
01417 ?>

Generated on Fri Dec 13 2013 09:06:37 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1