ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSetup.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./setup/classes/class.ilDBConnections.php");
5 
15 class ilSetup extends PEAR
16 {
17  var $ini; // ini file object
18  var $ini_file_path; // full path to setup.ini, containing the client list
19  var $error = ""; // error text
20 
21  var $ini_ilias_exists = false; // control flag ilias.ini
22  var $ini_client_exists = false; // control flag client.ini
23 
24  var $setup_defaults; // ilias.master.ini
25  var $ilias_nic_server = "http://www.ilias.de/ilias-nic/index.php"; // URL to ilias nic server
26 
27  var $preliminaries_result = array(); // preliminaries check results
28  var $preliminaries = true; //
29 
35  var $SQL_FILE = "./setup/sql/ilias3.sql";
36 
42  var $dsn = "";
43 
49  var $db;
50 
51  var $setup_password; // master setup password
52  var $default_client; // client id of default client
53 
54  var $safe_mode; // safe mode enabled (true) or disabled (false)
55  var $safe_mode_exec_dir; // contains exec_dir_path
56 
57  var $auth; // current user is authenticated? (true)
58  var $access_mode; // if "admin", admin functions are enabled
59 
60 
67  function ilSetup($a_auth,$a_auth_type)
68  {
69  global $log, $lng;
70 
71  $this->PEAR();
72  $this->lng = $lng;
73 
74  $this->db_connections = new ilDBConnections();
75 
76  define("ILIAS_MODULE","setup");
77 
78  $this->auth = ($a_auth) ? true : false;
79  $this->access_mode = $a_auth_type;
80 
81  // safe mode status & exec_dir
82  if ($this->safe_mode = ini_get("safe_mode"))
83  {
84  $this->safe_mode_exec_dir = ilFile::deleteTrailingSlash(ini_get("safe_mode_exec_dir"));
85  }
86 
87  // Error Handling
88  $this->error_obj = new ilErrorHandling();
89  $this->setErrorHandling(PEAR_ERROR_CALLBACK,array($this->error_obj,'errorHandler'));
90 
91  // set path to ilias.ini
92  $this->ini_file_path = ILIAS_ABSOLUTE_PATH."/ilias.ini.php";
93  $this->setup_defaults = ILIAS_ABSOLUTE_PATH."/setup/ilias.master.ini.php";
94 
95  // init setup.ini
96  $this->ini_ilias_exists = $this->init();
97 
98  if ($this->ini_ilias_exists)
99  {
100  if ($this->ini->readVariable("log","path") != "")
101  {
102  $log->path = $this->ini->readVariable("log","path");
103  }
104 
105  if ($this->ini->readVariable("log","file") != "")
106  {
107  $log->filename = $this->ini->readVariable("log","file");
108  }
109 
110  if ($this->ini->readVariable("log","enabled") != "")
111  {
112  $log->enabled = $this->ini->readVariable("log","enabled");
113  }
114  }
115  }
116 
122  function setClient($a_cl)
123  {
124  $this->client = $a_cl;
125  }
126 
132  function getClient()
133  {
134  return $this->client;
135  }
136 
142  function init()
143  {
144  // load data from setup.ini file
145  $this->ini = new ilIniFile($this->ini_file_path);
146 
147  if (!$this->ini->read())
148  {
149  $this->ini->GROUPS = parse_ini_file($this->setup_defaults,true);
150  $this->error = get_class($this).": ".$this->ini->getError();
151  return false;
152  }
153 
154  $this->setup_password = $this->ini->readVariable("setup","pass");
155  $this->default_client = $this->ini->readVariable("clients","default");
156 
157  define("ILIAS_DATA_DIR",$this->ini->readVariable("clients","datadir"));
158  define("ILIAS_WEB_DIR",$this->ini->readVariable("clients","path"));
159 
160  return true;
161  }
162 
167  function saveNewClient()
168  {
169  // save client id to session
170  $_SESSION["ClientId"] = $this->client->getId();
171 
172  // create client
173  if (!$this->client->create())
174  {
175  $this->error = $this->client->getError();
176  return false;
177  }
178 
179  //everything okay
180  $this->ini_client_exists = true;
181 
182  return true;
183  }
184 
190  function updateNewClient($a_old_client_id)
191  {
192  return true;
193  //var_dump("<pre>",$this->client,"</pre>");exit;
194 
195  if ($a_old_client_id != $this->client->getId())
196  {
197  // check for existing client dir
198  if (file_exists(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->client->getId()))
199  {
200  $this->raiseError($this->lng->txt("client_id_already_exists"),$this->error_obj->MESSAGE);
201  }
202 
203  if (!$this->saveNewClient())
204  {
205  $this->raiseError($this->lng->txt("save_error"),$this->error_obj->MESSAGE);
206  }
207 
208  ilUtil::delDir(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$a_old_client_id);
209  ilUtil::delDir(ILIAS_DATA_DIR."/".$a_old_client_id);
210  }
211 
212  //everything okay
213  $this->ini_client_exists = true;
214 
215  return true;
216  }
217 
222  function createDatabase($a_collation = "")
223  {
224  if ($this->client->checkDatabaseExists())
225  {
226  $this->error = $this->lng->txt("database_exists");
227  return false;
228  }
229 
230  $this->client->getDB()->connectHost(true);
231 
232  //create database
233  $db = $this->client->getDB();
234  if (MDB2::isError($db))
235  {
236  $this->error = "connection_failed";
237  return false;
238  }
239 
240  $r = $db->createDatabase($this->client->getdbName(),
241  "utf8", $a_collation);
242 
243  if (MDB2::isError($r))
244  {
245  $this->error = "create_database_failed";
246  return false;
247  }
248 
249  //database is created, now disconnect and reconnect
250  $db->disconnect();
251 
252  $this->client->db_exists = true;
253  return true;
254  }
255 
260  function installDatabase()
261  {
262 /* if (!$this->client->checkDatabaseHost())
263  {
264  $this->error = "no_connection_to_host";
265  return false;
266  }*/
267 
268  if (!$this->client->connect())
269  {
270  return false;
271  }
272 
273  //take sql dump an put it in
274  if ($this->readDump($this->client->db, $this->SQL_FILE))
275  {
276  $this->client->db_installed = true;
277  return true;
278  }
279  else
280  {
281  return false;
282  }
283  }
284 
285  function getline( $fp, $delim )
286  {
287  $result = "";
288  while( !feof( $fp ) )
289  {
290  $tmp = fgetc( $fp );
291  if( $tmp == $delim )
292  return $result;
293  $result .= $tmp;
294  }
295  return $result;
296  }
297 
304  function readDump($db, $file)
305  {
306  // mysql (old procedure)
307  if ($db->getDBType() == "mysql")
308  {
309  $fp = fopen($file, 'r');
310 
311  while(!feof($fp))
312  {
313  //$line = trim(fgets($fp, 200000));
314  $line = trim($this->getline($fp, "\n"));
315 
316  if ($line != "" && substr($line,0,1)!="#"
317  && substr($line,0,1)!="-")
318  {
319  //take line per line, until last char is ";"
320  if (substr($line,-1)==";")
321  {
322  //query is complete
323  $q .= " ".substr($line,0,-1);
324  $r = $db->query($q);
325  if (mysql_errno() > 0)
326  {
327  echo "<br />ERROR: ".mysql_error().
328  "<br />SQL: $q";
329  return false;
330  }
331  unset($q);
332  unset($line);
333  } //if
334  else
335  {
336  $q .= " ".$line;
337  } //else
338  } //if
339  } //for
340 
341  fclose($fp);
342  }
343 
344  #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
345  if ($db->getDBType() == "oracle")
346  {
347  if(@is_dir('./setup/sql/ilDBTemplate'))
348  {
349  include_once './Services/Database/classes/class.ilArrayTableDataParser.php';
350  include_once './classes/class.ilSaxParserException.php';
351  $reader = new tmpDirectoyIterator('./setup/sql/ilDBTemplate');
352  foreach($reader as $file)
353  {
354  eval(file_get_contents('./setup/sql/ilDBTemplate/'.$file));
355  try
356  {
357  $parser = new ilArrayTableDataParser('./setup/sql/ilDBTemplate/'.$file.'_inserts');
358  #$parser = new ilSimpleXMLTableDataParser('./setup/sql/ilDBTemplate/'.$file.'.xml');
359  $parser->startParsing();
360  #echo 'Table: '.$file.', memory: '.memory_get_peak_usage().' peak: '.memory_get_peak_usage().'<br />';flush();
361 
362  }
363  catch(ilSaxParserException $e)
364  {
365  die($e);
366  }
367  }
368  }
369  else
370  {
371  include_once("./setup/sql/ilDBTemplate.php");
372  setupILIASDatabase();
373  }
374  }
375  #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
376  return true;
377  }
378 
379 
385  {
386  $a = @file_exists($this->INI_FILE);
387  return $a;
388  }
389 
395  function checkWritable()
396  {
397  clearstatcache();
398  if (is_writable("."))
399  {
400  $arr["status"] = true;
401  //$cdir = getcwd();
402  //chdir("..");
403  $arr["comment"] = getcwd();
404  //chdir($cdir);
405  }
406  else
407  {
408  $arr["status"] = false;
409  $arr["comment"] = $this->lng->txt("pre_folder_write_error");
410  //$cdir = getcwd();
411  //chdir("..");
412  $arr["comment"] = getcwd().": ".$arr["comment"];
413  //chdir($cdir);
414  }
415 
416  return $arr;
417  }
418 
424  function checkCreatable($a_dir = ".")
425  {
426  clearstatcache();
427  if (@mkdir($a_dir."/crst879dldsk9d", 0774))
428  {
429  $arr["status"] = true;
430  $arr["comment"] = "";
431 
432  @rmdir($a_dir."/crst879dldsk9d");
433  }
434  else
435  {
436  $arr["status"] = false;
437  //$cdir = getcwd();
438  //chdir("..");
439  $arr["comment"] = getcwd().": ".$this->lng->txt("pre_folder_create_error");
440  //chdir($cdir);
441  }
442 
443  return $arr;
444  }
445 
451  {
452  global $sess;
453 
454  if ($sess->usesCookies)
455  {
456  $arr["status"] = true;
457  $arr["comment"] = "";
458  }
459  else
460  {
461  $arr["status"] = false;
462  $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
463  }
464 
465  return $arr;
466  }
467 
472  function checkPHPVersion()
473  {
474  $version = PHP_VERSION;
475 
476  $arr["status"] = true;
477  $arr["comment"] = "PHP ".$version;
478  if (version_compare($version, '5.1.3', '<'))
479  {
480  $arr["status"] = false;
481  $arr["comment"] = "PHP ".$version.". ".$this->lng->txt("pre_php_version_too_low");
482  }
483 
484  return $arr;
485  }
486 
491  function checkMySQL()
492  {
493  global $ilDB;
494 
495  if (function_exists("mysql_query"))
496  {
497  $arr["status"] = true;
498  $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
499  }
500  else
501  {
502  $arr["status"] = false;
503  $arr["comment"] = $this->lng->txt("pre_mysql_missing");
504  }
505 
506  return $arr;
507  }
508 
513  function checkAuth()
514  {
515  if ($_SESSION["auth"] === true)
516  {
517  return true;
518  }
519 
520  return false;
521  }
522 
523 
528  function checkDom()
529  {
530  global $ilDB;
531 
532  if (class_exists("DOMDocument"))
533  {
534  $arr["status"] = true;
535  }
536  else
537  {
538  $arr["status"] = false;
539  $arr["comment"] = $this->lng->txt("pre_dom_missing");
540  }
541 
542  return $arr;
543  }
544 
549  function checkXsl()
550  {
551  global $ilDB;
552 
553  if (class_exists("XSLTProcessor"))
554  {
555  $arr["status"] = true;
556  }
557  else
558  {
559  $arr["status"] = false;
560  $arr["comment"] = sprintf($this->lng->txt("pre_xsl_missing"),
561  "http://php.net/manual/en/book.xsl.php");
562  }
563 
564  return $arr;
565  }
566 
571  function checkGd()
572  {
573  global $ilDB;
574 
575  if (function_exists("imagefill") && function_exists("imagecolorallocate"))
576  {
577  $arr["status"] = true;
578  }
579  else
580  {
581  $arr["status"] = false;
582  $arr["comment"] = sprintf($this->lng->txt("pre_gd_missing"),
583  "http://php.net/manual/en/book.image.php");
584  }
585 
586  return $arr;
587  }
588 
593  function checkMemoryLimit()
594  {
595  global $ilDB;
596 
597  $limit = ini_get("memory_limit");
598 
599  $limit_ok = true;
600  if (is_int(strpos($limit, "M")))
601  {
602  $limit_n = (int) $limit;
603  if ($limit_n < 40)
604  {
605  $limit_ok = false;
606  }
607  }
608 
609  if ($limit_ok)
610  {
611  $arr["status"] = true;
612  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_recommend");
613  }
614  else
615  {
616  $arr["status"] = false;
617  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_too_low");
618  }
619 
620  return $arr;
621  }
622 
631  {
632  $a = array();
633  $a["php"] = $this->checkPHPVersion();
634 // $a["mysql"] = $this->checkMySQL();
635  $a["root"] = $this->checkWritable();
636  $a["folder_create"] = $this->checkCreatable();
637  $a["cookies_enabled"] = $this->checkCookiesEnabled();
638  $a["dom"] = $this->checkDom();
639  $a["xsl"] = $this->checkXsl();
640  $a["gd"] = $this->checkGd();
641  $a["memory"] = $this->checkMemoryLimit();
642 
643  return $a;
644  }
645 
651  {
652  $this->preliminaries_result = $this->queryPreliminaries();
653 
654  foreach ($this->preliminaries_result as $val)
655  {
656  if ($val["status"] === false)
657  {
658  $this->preliminaries = false;
659  return false;
660  }
661  }
662 
663  return true;
664  }
665 
670  function getPassword ()
671  {
672  return $this->ini->readVariable("setup","pass");
673  }
674 
680  function setPassword ($a_password)
681  {
682  $this->ini->setVariable("setup","pass",md5($a_password));
683 
684  if ($this->ini->write() == false)
685  {
686  $this->error = $this->ini->getError();
687  return false;
688  }
689 
690  return true;
691  }
692 
698  function loginAsClient($a_auth_data)
699  {
700  global $ilDB;
701 
702  if (empty($a_auth_data["client_id"]))
703  {
704  $this->error = "no_client_id";
705  return false;
706  }
707 
708  if (empty($a_auth_data["username"]))
709  {
710  $this->error = "no_username";
711  return false;
712  }
713 
714  if (empty($a_auth_data["password"]))
715  {
716  $this->error = "no_password";
717  return false;
718  }
719 
720  if (!$this->newClient($a_auth_data["client_id"]))
721  {
722  $this->error = "unknown_client_id";
723  unset($this->client);
724  return false;
725  }
726 
727  if (!$this->client->db_exists)
728  {
729  $this->error = "no_db_connect_consult_admin";
730  unset($this->client);
731  return false;
732  }
733 
734  $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = ".
735  $this->client->db->quote('system_role_id','text'));
736  $r1 = $this->client->db->fetchAssoc($s1);
737  $system_role_id = $r1["value"];
738  $q = "SELECT usr_data.usr_id FROM usr_data ".
739  "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id ".
740  "WHERE rbac_ua.rol_id = ".$this->client->db->quote((int) $system_role_id,'integer')." ".
741  "AND usr_data.login=".$this->client->db->quote($a_auth_data["username"],'text')." ".
742  "AND usr_data.passwd=".$this->client->db->quote(md5($a_auth_data["password"]),'text');
743 
744  $r = $this->client->db->query($q);
745 
746  if (!$r->numRows())
747  {
748  $this->error = "login_invalid";
749  return false;
750  }
751 
752  // all checks passed -> user valid
753  $_SESSION["auth"] = true;
754  $_SESSION["access_mode"] = "client";
755  $_SESSION["ClientId"] = $this->client->getId();
756  return true;
757  }
758 
764  function loginAsAdmin($a_password)
765  {
766  $a_password = md5($a_password);
767 
768  if ($this->ini->readVariable("setup","pass") == $a_password)
769  {
770  $_SESSION["auth"] = true;
771  $_SESSION["access_mode"] = "admin";
772  return true;
773  }
774 
775  return false;
776  }
777 
783  function newClient($a_client_id = 0)
784  {
785  if (!$this->isInstalled())
786  {
787  return false;
788  }
789 
790  $this->client = new ilClient($a_client_id, $this->db_connections);
791 
792  if (!$this->client->init())
793  {
794 //echo "<br>noclientinit";
795  $this->error = get_class($this).": ".$this->client->getError();
796  $_SESSION["ClientId"] = "";
797  return false;
798  }
799 
800  $_SESSION["ClientId"] = $a_client_id;
801 
802  return true;
803  }
804 
810  function getStatus ($client = 0)
811  {
812  if (!is_object($client))
813  {
814  if ($this->ini_client_exists)
815  {
817  }
818  else
819  {
820  $client = new ilClient(0, $this->db_connections);
821  }
822  }
823 
824  $status = array();
825  $status["ini"] = $this->checkClientIni($client); // check this one
826  $status["db"] = $this->checkClientDatabase($client);
827 
828  if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
829  {
830  $status["lang"]["status"] = false;
831  $status["lang"]["comment"] = $status["db"]["comment"];
832  $status["contact"]["status"] = false;
833  $status["contact"]["comment"] = $status["db"]["comment"];
834  $status["nic"]["status"] = false;
835  $status["nic"]["comment"] = $status["db"]["comment"];
836  }
837  else
838  {
839  $status["lang"] = $this->checkClientLanguages($client);
840  $status["contact"] = $this->checkClientContact($client);
841  $status["nic"] = $this->checkClientNIC($client);
842  $status["finish"] = $this->checkFinish($client);
843  $status["access"] = $this->checkAccess($client);
844  }
845 
846  //return value
847  return $status;
848  }
849 
855  function checkFinish(&$client)
856  {
857  if ($client->getSetting("setup_ok"))
858  {
859  $arr["status"] = true;
860  //$arr["comment"] = $this->lng->txt("setup_finished");
861  }
862  else
863  {
864  $arr["status"] = false;
865  $arr["comment"] = $this->lng->txt("setup_not_finished");
866  }
867 
868  return $arr;
869  }
870 
876  function checkAccess(&$client)
877  {
878  if ($client->ini->readVariable("client","access") == "1")
879  {
880  $arr["status"] = true;
881  $arr["comment"] = $this->lng->txt("online");
882  }
883  else
884  {
885  $arr["status"] = false;
886  $arr["comment"] = $this->lng->txt("disabled");
887  }
888 
889  return $arr;
890  }
891 
898  {
899  if (!$arr["status"] = $client->init())
900  {
901  $arr["comment"] = $client->getError();
902  }
903  else
904  {
905  //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
906  }
907 
908  return $arr;
909  }
910 
917  {
918  if (!$arr["status"] = $client->db_exists)
919  {
920  $arr["comment"] = $this->lng->txt("no_database");
921  return $arr;
922  }
923 
924  if (!$arr["status"] = $client->db_installed)
925  {
926  $arr["comment"] = $this->lng->txt("db_not_installed");
927  return $arr;
928  }
929 
930  // TODO: move this to client class!!
931  $client->setup_ok = (bool) $client->getSetting("setup_ok");
932 
933  //$this->lng->setDbHandler($client->db);
934  include_once "./Services/Database/classes/class.ilDBUpdate.php";
935  $ilDB = $client->db;
936  $this->lng->setDbHandler($client->db);
937  $dbupdate = new ilDBUpdate($client->db);
938 
939  if (!$arr["status"] = $dbupdate->getDBVersionStatus())
940  {
941  $arr["comment"] = $this->lng->txt("db_needs_update");
942  $arr["update"] = true;
943  return $arr;
944  }
945  else if ($dbupdate->hotfixAvailable())
946  {
947  $arr["status"] = false;
948  $arr["comment"] = $this->lng->txt("hotfix_available");
949  $arr["update"] = true;
950  return $arr;
951  }
952 
953  // check control information
954 
955  $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
956  $crec = $ilDB->fetchAssoc($cset);
957  if ($crec["cnt"] == 0)
958  {
959  $arr["status"] = false;
960  $arr["comment"] = $this->lng->txt("db_control_structure_missing");
961  $arr["update"] = true;
962  return $arr;
963  }
964 
965  //$arr["comment"] = "version ".$dbupdate->getCurrentVersion();
966  return $arr;
967  }
968 
975  {
976  $installed_langs = $this->lng->getInstalledLanguages();
977 
978  $count = count($installed_langs);
979 
980  if ($count < 1)
981  {
982  $arr["status"] = false;
983  $arr["comment"] = $this->lng->txt("lang_none_installed");
984  }
985  else
986  {
987  $arr["status"] = true;
988  //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
989  }
990 
991  return $arr;
992  }
993 
1000  {
1001  $arr["status"] = true;
1002  //$arr["comment"] = $this->lng->txt("filled_out");
1003 
1004  $settings = $client->getAllSettings();
1005  $client_name = $client->getName();
1006 
1007  // check required fields
1008  if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
1009  empty($settings["admin_email"]) or empty($client_name))
1010  {
1011  $arr["status"] = false;
1012  $arr["comment"] = $this->lng->txt("missing_data");
1013  }
1014 
1015  // admin email
1016  if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
1017  {
1018  $arr["status"] = false;
1019  $arr["comment"] = $this->lng->txt("email_not_valid");
1020  }
1021 
1022  return $arr;
1023  }
1024 
1031  {
1032  $settings = $client->getAllSettings();
1033 
1034  if (!isset($settings["nic_enabled"]))
1035  {
1036  $arr["status"] = false;
1037  $arr["comment"] = $this->lng->txt("nic_not_disabled");
1038  return $arr;
1039  }
1040 
1041  $arr["status"] = true;
1042 
1043  if ($settings["nic_enabled"] == "-1")
1044  {
1045  $arr["comment"] = $this->lng->txt("nic_reg_failed");
1046  return $arr;
1047  }
1048 
1049  if (!$settings["nic_enabled"])
1050  {
1051  $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1052  }
1053  else
1054  {
1055  $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1056  if ($settings["inst_id"] <= 0)
1057  {
1058  $arr["status"] = false;
1059  }
1060  }
1061 
1062  return $arr;
1063  }
1064 
1069  function isInstalled()
1070  {
1071  return $this->ini_ilias_exists;
1072  }
1073 
1078  function isAuthenticated()
1079  {
1080  return $this->auth;
1081  }
1082 
1087  function isAdmin()
1088  {
1089  return ($this->access_mode == "admin") ? true : false;
1090  }
1091 
1097  function saveMasterSetup($a_formdata)
1098  {
1099  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1100 
1101  if ($a_formdata["chk_datadir_path"] == 1) // mode create dir
1102  {
1103  if (!ilUtil::makeDir($datadir_path))
1104  {
1105  $this->error = "create_datadir_failed";
1106  return false;
1107  }
1108  }
1109 
1110  // create webspace dir if it does not exist
1111  if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1112  {
1113  if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1114  {
1115  $this->error = "create_webdir_failed";
1116  return false;
1117  }
1118  }
1119 
1120  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1121  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1122  $log_file = substr($form_log_path,strlen($log_path)+1);
1123 
1124  $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
1125  $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
1126  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1127  $this->ini->setVariable("clients", "datadir", $datadir_path);
1128  $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
1129  $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
1130  $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
1131  $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
1132  $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
1133  $this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1134  $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1135  $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1136  $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
1137  $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
1138  $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
1139  $this->ini->setVariable("log", "path", $log_path);
1140  $this->ini->setVariable("log", "file", $log_file);
1141  $this->ini->setVariable("log", "enabled", (isset($a_formdata["chk_log_status"])) ? "0" : 1);
1142 
1143  if (!$this->ini->write())
1144  {
1145  $this->error = get_class($this).": ".$this->ini->getError();
1146  return false;
1147  }
1148 
1149  // everything is fine. so we authenticate the user and set access mode to 'admin'
1150  $_SESSION["auth"] = true;
1151  $_SESSION["access_mode"] = "admin";
1152 
1153  return true;
1154  }
1155 
1161  function updateMasterSettings($a_formdata)
1162  {
1163  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1164  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1165  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1166  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1167  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1168  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1169  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1170  $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
1171  $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1172  $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
1173  $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
1174 
1175  $this->ini->setVariable("tools", "convert", $convert_path);
1176  $this->ini->setVariable("tools", "zip", $zip_path);
1177  $this->ini->setVariable("tools", "unzip", $unzip_path);
1178  $this->ini->setVariable("tools", "java", $java_path);
1179  $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
1180  $this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1181  $this->ini->setVariable("tools", "latex", $latex_url);
1182  $this->ini->setVariable("tools", "fop", $fop_path);
1183  $this->ini->setVariable("tools", "vscantype", $scan_type);
1184  $this->ini->setVariable("tools", "scancommand", $scan_command);
1185  $this->ini->setVariable("tools", "cleancommand", $clean_command);
1186 
1187  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1188  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1189  $log_file = substr($form_log_path,strlen($log_path)+1);
1190 
1191  $this->ini->setVariable("log", "path", $log_path);
1192  $this->ini->setVariable("log", "file", $log_file);
1193  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1194  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1195 
1196  if (!$this->ini->write())
1197  {
1198  $this->error = get_class($this).": ".$this->ini->getError();
1199  return false;
1200  }
1201 
1202  return true;
1203  }
1204 
1210  function checkToolsSetup($a_formdata)
1211  {
1212  // convert path
1213  if (!isset($a_formdata["chk_convert_path"]))
1214  {
1215  // convert backslashes to forwardslashes
1216  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1217 
1218  if (($err = $this->testConvert($convert_path)) != "")
1219  {
1220  $this->error = $err;
1221  return false;
1222  }
1223  }
1224 
1225  // zip path
1226  if (!isset($a_formdata["chk_zip_path"]))
1227  {
1228  // convert backslashes to forwardslashes
1229  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1230 
1231  if (empty($zip_path))
1232  {
1233  $this->error = "no_path_zip";
1234  return false;
1235  }
1236 
1237  if (!$this->testZip($zip_path))
1238  {
1239  $this->error = "check_failed_zip";
1240  return false;
1241  }
1242  }
1243 
1244  // unzip path
1245  if (!isset($a_formdata["chk_unzip_path"]))
1246  {
1247  // convert backslashes to forwardslashes
1248  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1249 
1250  if (empty($unzip_path))
1251  {
1252  $this->error = "no_path_unzip";
1253  return false;
1254  }
1255 
1256  if (!$this->testUnzip($unzip_path))
1257  {
1258  $this->error = "check_failed_unzip";
1259  return false;
1260  }
1261  }
1262 
1263  // java path
1264  if (!isset($a_formdata["chk_java_path"]))
1265  {
1266  // convert backslashes to forwardslashes
1267  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1268 
1269  if (empty($java_path))
1270  {
1271  $this->error = "no_path_java";
1272  return false;
1273  }
1274 
1275  if (!$this->testJava($java_path))
1276  {
1277  $this->error = "check_failed_java";
1278  return false;
1279  }
1280  }
1281 
1282  // htmldoc path
1283  if (!isset($a_formdata["chk_htmldoc_path"]))
1284  {
1285  // convert backslashes to forwardslashes
1286  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1287 
1288  if (empty($htmldoc_path))
1289  {
1290  $this->error = "no_path_htmldoc";
1291  return false;
1292  }
1293 
1294  if (!$this->testHtmldoc($htmldoc_path))
1295  {
1296  $this->error = "check_failed_htmldoc";
1297  return false;
1298  }
1299  }
1300  if (!isset($a_formdata["chk_mkisofs_path"]))
1301  {
1302  // convert backslashes to forwardslashes
1303  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1304 
1305  if (empty($mkisofs_path))
1306  {
1307  $this->error = "no_path_mkisofs";
1308  return false;
1309  }
1310 
1311  if (!$this->testHtmldoc($mkisofs_path))
1312  {
1313  $this->error = "check_failed_mkisofs";
1314  return false;
1315  }
1316  }
1317 
1318  // latex url
1319  if (!isset($a_formdata["chk_latex_url"]))
1320  {
1321  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1322  if (empty($latex_url))
1323  {
1324  $this->error = "no_latex_url";
1325  return false;
1326  }
1327 
1328  if (!$this->testLatex($latex_url))
1329  {
1330  $this->error = "check_failed_latex";
1331  return false;
1332  }
1333  }
1334 
1335  return true;
1336  }
1337 
1343  function checkDataDirSetup($a_formdata)
1344  {
1345  // remove trailing slash & convert backslashes to forwardslashes
1346  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1347 
1348  if (empty($datadir_path))
1349  {
1350  $this->error = "no_path_datadir";
1351  return false;
1352  }
1353 
1354  $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1355 
1356  // datadir may not point to webspace dir or to any place under webspace_dir
1357  if (strpos($datadir_path,$webspace_dir) !== false)
1358  {
1359  $this->error = "datadir_webspacedir_match";
1360  return false;
1361  }
1362 
1363  // create dir
1364  if ($a_formdata["chk_datadir_path"] == 1)
1365  {
1366  $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1367  $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
1368 
1369  if (is_writable($datadir_path))
1370  {
1371  $this->error = "dir_exists_create";
1372  return false;
1373  }
1374 
1375  if (!is_writable($dir_to_check))
1376  {
1377  $this->error = "cannot_create_datadir_no_write_access";
1378  return false;
1379  }
1380  }
1381  else // check set target dir
1382  {
1383  if (!is_writable($datadir_path))
1384  {
1385  $this->error = "cannot_create_datadir_no_write_access";
1386  return false;
1387  }
1388  }
1389 
1390  return true;
1391  }
1392 
1398  function checkPasswordSetup($a_formdata)
1399  {
1400  if (!$a_formdata["setup_pass"])
1401  {
1402  $this->error = "no_setup_pass_given";
1403  return false;
1404  }
1405 
1406  if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
1407  {
1408  $this->error = "pass_does_not_match";
1409  return false;
1410  }
1411 
1412  return true;
1413  }
1414 
1420  function checkLogSetup($a_formdata)
1421  {
1422  // log path
1423  if (!$a_formdata["chk_log_status"])
1424  {
1425  // remove trailing slash & convert backslashes to forwardslashes
1426  $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1427 
1428  if (empty($log_path))
1429  {
1430  $this->error = "no_path_log";
1431  return false;
1432  }
1433 
1434  if (!@touch($log_path))
1435  {
1436  $this->error = "could_not_create_logfile";
1437  return false;
1438  }
1439  }
1440 
1441  return true;
1442  }
1443 
1448  function getError()
1449  {
1450  if (empty($this->error))
1451  {
1452  return false;
1453  }
1454 
1455  $error = $this->error;
1456  $this->error = "";
1457 
1458  return $error;
1459  }
1460 
1466  function _ilSetup()
1467  {
1468  //if ($this->ini->readVariable("db","type") != "")
1469  //{
1470  // $this->db->disconnect();
1471  //}
1472  return true;
1473  }
1474 
1481  function testConvert($a_convert_path)
1482  {
1483  if (trim($a_convert_path) == "")
1484  {
1485  return "no_path_convert";
1486  }
1487  if (!is_file($a_convert_path))
1488  {
1489  return "check_failed_convert";
1490  }
1491 
1492  return "";
1493 
1494 /*
1495  // generate gif with convert
1496  if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
1497  {
1498  unlink(ILIAS_ABSOLUTE_PATH."/images/test.gif");
1499  }
1500 
1501  system($a_convert_path." ".ILIAS_ABSOLUTE_PATH."/setup/test/test.jpg GIF:".ILIAS_ABSOLUTE_PATH."/setup/test/test.gif");
1502 
1503  // check wether convert generated file
1504  if (file_exists(ILIAS_ABSOLUTE_PATH."/setup/test/test.gif"))
1505  {
1506  unlink(ILIAS_ABSOLUTE_PATH."/setup/test/test.gif");
1507  return true;
1508  }
1509  else
1510  {
1511  return false;
1512  }
1513 */
1514  }
1515 
1522  function testJava ($a_java_path)
1523  {
1524  // java is optional, so empty path is ok
1525  if (trim($a_java_path) == "")
1526  {
1527  return "";
1528  }
1529 
1530  if (!is_file($a_java_path))
1531  {
1532  return "check_failed_java";
1533  }
1534 
1535  return "";
1536 /*
1537  exec($a_java_path, $out, $back);
1538 
1539  unset($out);
1540 
1541  return ($back != 1) ? false : true;
1542 */
1543  }
1544 
1551  function testLatex($a_latex_url)
1552  {
1553  // latex is optional, so empty path is ok
1554  if (trim($a_latex_url) == "")
1555  {
1556  return "";
1557  }
1558 
1559  // open the URL
1560  include_once "./setup/classes/class.ilHttpRequest.php";
1561  $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1562  $result = @$http->downloadToString();
1563  if ((strpos((substr($result, 0, 5)), "PNG") !== FALSE) || (strpos((substr($result, 0, 5)), "GIF") !== FALSE))
1564  {
1565  return "";
1566  }
1567  else
1568  {
1569  return "check_failed_latex";;
1570  }
1571  }
1572 
1579  function testZip ($a_zip_path)
1580  {
1581  if (trim($a_zip_path) == "")
1582  {
1583  return "no_path_zip";
1584  }
1585  if (!is_file($a_zip_path))
1586  {
1587  return "check_failed_zip";
1588  }
1589 
1590  return "";
1591 /*
1592  // create test file and run zip
1593  $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1594 
1595  fwrite($fp, "test");
1596  fclose($fp);
1597 
1598  if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1599  {
1600  $curDir = getcwd();
1601  chdir(ILIAS_ABSOLUTE_PATH);
1602 
1603  $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1604 
1605  exec($zipCmd);
1606 
1607  chdir($curDir);
1608 
1609  }
1610 
1611  // check wether zip generated test file or not
1612  if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1613  {
1614  unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1615  return true;
1616  }
1617  else
1618  {
1619  unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1620  return false;
1621  }
1622 */
1623  }
1624 
1625 
1632  function testUnzip ($a_unzip_path)
1633  {
1634  if (trim($a_unzip_path) == "")
1635  {
1636  return "no_path_unzip";
1637  }
1638  if (!is_file($a_unzip_path))
1639  {
1640  return "check_failed_unzip";
1641  }
1642 
1643  return "";
1644 /*
1645  $curDir = getcwd();
1646 
1647  chdir(ILIAS_ABSOLUTE_PATH);
1648 
1649  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1650  {
1651  $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1652  exec($unzipCmd);
1653  }
1654 
1655  chdir($curDir);
1656 
1657  // check wether unzip extracted the test file or not
1658  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1659  {
1660  unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1661 
1662  return true;
1663  }
1664  else
1665  {
1666  return false;
1667  }
1668 */
1669  }
1670 
1677  function testHtmldoc($a_htmldoc_path)
1678  {
1679  // java is optional, so empty path is ok
1680  if (trim($a_htmldoc_path) == "")
1681  {
1682  return "";
1683  }
1684 
1685  if (!is_file($a_htmldoc_path))
1686  {
1687  return "check_failed_htmldoc";
1688  }
1689 
1690  return "";
1691 
1692 
1693  $curDir = getcwd();
1694 
1695  chdir(ILIAS_ABSOLUTE_PATH);
1696 
1697  $html = "<html><head><title></title></head><body><p>test</p></body></html>";
1698 
1699  $html_file = "htmldoc_test_file.html";
1700 
1701  $fp = fopen( $html_file ,"wb");
1702  fwrite($fp, $html);
1703  fclose($fp);
1704 
1705  $htmldoc = $a_htmldoc_path." ";
1706  $htmldoc .= "--no-toc ";
1707  $htmldoc .= "--no-jpeg ";
1708  $htmldoc .= "--webpage ";
1709  $htmldoc .= "--outfile htmldoc_test_file.pdf ";
1710  $htmldoc .= "--bodyfont Arial ";
1711  $htmldoc .= "--charset iso-8859-15 ";
1712  $htmldoc .= "--color ";
1713  $htmldoc .= "--size A4 "; // --landscape
1714  $htmldoc .= "--format pdf ";
1715  $htmldoc .= "--footer ... ";
1716  $htmldoc .= "--header ... ";
1717  $htmldoc .= "--left 60 ";
1718  // $htmldoc .= "--right 200 ";
1719  $htmldoc .= $html_file;
1720  exec($htmldoc);
1721 
1722  unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
1723 
1724  chdir($curDir);
1725 
1726  if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
1727  {
1728  unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
1729  return true;
1730  }
1731  else
1732  {
1733  return false;
1734  }
1735  }
1736 
1737 
1744  function unzip($a_file, $overwrite = false)
1745  {
1746  //global $ilias;
1747 
1748  $pathinfo = pathinfo($a_file);
1749  $dir = $pathinfo["dirname"];
1750  $file = $pathinfo["basename"];
1751 
1752  // unzip
1753  $cdir = getcwd();
1754  chdir($dir);
1755  $unzip = $this->ini->readVariable("tools","unzip");
1756  $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
1757  exec($unzipcmd, $arr);
1758  $zdirs = array();
1759 
1760  foreach($arr as $line)
1761  {
1762  if(is_int(strpos($line, "/")))
1763  {
1764  $zdir = substr($line, 0, strrpos($line, "/"));
1765  $nr = substr_count($zdir, "/");
1766  //echo $zdir." ".$nr."<br>";
1767  while ($zdir != "")
1768  {
1769  $nr = substr_count($zdir, "/");
1770  $zdirs[$zdir] = $nr; // collect directories
1771  //echo $dir." ".$nr."<br>";
1772  $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1773  }
1774  }
1775  }
1776 
1777  asort($zdirs);
1778 
1779  foreach($zdirs as $zdir => $nr) // create directories
1780  {
1781  ilUtil::createDirectory($zdir);
1782  }
1783 
1784  // real unzip
1785  if ($overvwrite)
1786  {
1787  $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
1788  }
1789  else
1790  {
1791  $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
1792  }
1793  exec($unzipcmd);
1794 
1795  chdir($cdir);
1796  }
1797 
1798 } // END class.ilSetup
1799 
1801 {
1802  public function current()
1803  {
1804  return parent::getFileName();
1805  }
1806 
1807  public function valid()
1808  {
1809  if(!parent::valid())
1810  {
1811  return false;
1812  }
1813  if($this->isFile() and substr(parent::getFileName(),-4) == '.xml')
1814  {
1815  return false;
1816  }
1817  if($this->isFile() and substr(parent::getFileName(),-8) != '_inserts')
1818  {
1819  return true;
1820  }
1821  parent::next();
1822  return $this->valid();
1823  }
1824 
1825  public function rewind()
1826  {
1827  parent::rewind();
1828  }
1829 }
1830 ?>