ILIAS  release_4-3 Revision
 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-2012mk 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 = ($this->checkAuth()) ? 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 
326  if ($db->getErrorNo() > 0)
327  {
328  echo "<br />ERROR: ".$db->getError().
329  "<br />SQL: $q";
330  return false;
331  }
332  unset($q);
333  unset($line);
334  } //if
335  else
336  {
337  $q .= " ".$line;
338  } //else
339  } //if
340  } //for
341 
342  fclose($fp);
343  }
344 
345  #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
346  if (in_array($db->getDBType(), array("oracle", "postgres", "innodb")))
347  {
348  if(@is_dir('./setup/sql/ilDBTemplate'))
349  {
350  include_once './Services/Database/classes/class.ilArrayTableDataParser.php';
351  include_once './Services/Xml/exceptions/class.ilSaxParserException.php';
352  $reader = new tmpDirectoyIterator('./setup/sql/ilDBTemplate');
353  foreach($reader as $file)
354  {
355  eval(file_get_contents('./setup/sql/ilDBTemplate/'.$file));
356  try
357  {
358  $parser = new ilArrayTableDataParser('./setup/sql/ilDBTemplate/'.$file.'_inserts');
359  #$parser = new ilSimpleXMLTableDataParser('./setup/sql/ilDBTemplate/'.$file.'.xml');
360  $parser->startParsing();
361  #echo 'Table: '.$file.', memory: '.memory_get_peak_usage().' peak: '.memory_get_peak_usage().'<br />';flush();
362 
363  }
364  catch(ilSaxParserException $e)
365  {
366  die($e);
367  }
368  }
369  }
370  else
371  {
372  include_once("./setup/sql/ilDBTemplate.php");
373  setupILIASDatabase();
374  }
375  }
376  #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
377  return true;
378  }
379 
380 
386  {
387  $a = @file_exists($this->INI_FILE);
388  return $a;
389  }
390 
396  function checkWritable()
397  {
398  clearstatcache();
399  if (is_writable("."))
400  {
401  $arr["status"] = true;
402  //$cdir = getcwd();
403  //chdir("..");
404  $arr["comment"] = getcwd();
405  //chdir($cdir);
406  }
407  else
408  {
409  $arr["status"] = false;
410  $arr["comment"] = $this->lng->txt("pre_folder_write_error");
411  //$cdir = getcwd();
412  //chdir("..");
413  $arr["comment"] = getcwd().": ".$arr["comment"];
414  //chdir($cdir);
415  }
416 
417  return $arr;
418  }
419 
425  function checkCreatable($a_dir = ".")
426  {
427  clearstatcache();
428  if (@mkdir($a_dir."/crst879dldsk9d", 0774))
429  {
430  $arr["status"] = true;
431  $arr["comment"] = "";
432 
433  @rmdir($a_dir."/crst879dldsk9d");
434  }
435  else
436  {
437  $arr["status"] = false;
438  //$cdir = getcwd();
439  //chdir("..");
440  $arr["comment"] = getcwd().": ".$this->lng->txt("pre_folder_create_error");
441  //chdir($cdir);
442  }
443 
444  return $arr;
445  }
446 
452  {
453  global $sess;
454 
455  if ($sess->usesCookies)
456  {
457  $arr["status"] = true;
458  $arr["comment"] = "";
459  }
460  else
461  {
462  $arr["status"] = false;
463  $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
464  }
465 
466  return $arr;
467  }
468 
473  function checkPHPVersion()
474  {
475  $version = PHP_VERSION;
476 
477  $arr["status"] = true;
478  $arr["comment"] = "PHP ".$version;
479  if (version_compare($version, '5.2.6', '<'))
480  {
481  $arr["status"] = false;
482  $arr["comment"] = "PHP ".$version.". ".$this->lng->txt("pre_php_version_too_low");
483  }
484 
485  return $arr;
486  }
487 
492  function checkMySQL()
493  {
494  global $ilDB;
495 
496  if (function_exists("mysql_query"))
497  {
498  $arr["status"] = true;
499  $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
500  }
501  else
502  {
503  $arr["status"] = false;
504  $arr["comment"] = $this->lng->txt("pre_mysql_missing");
505  }
506 
507  return $arr;
508  }
509 
514  function checkAuth()
515  {
516  if ($_SESSION["auth"] === true && $_SESSION["auth_path"] == ILIAS_HTTP_PATH)
517  {
518  return true;
519  }
520 
521  return false;
522  }
523 
524 
529  function checkDom()
530  {
531  global $ilDB;
532 
533  if (class_exists("DOMDocument"))
534  {
535  $arr["status"] = true;
536  }
537  else
538  {
539  $arr["status"] = false;
540  $arr["comment"] = $this->lng->txt("pre_dom_missing");
541  }
542 
543  return $arr;
544  }
545 
550  function checkXsl()
551  {
552  global $ilDB;
553 
554  if (class_exists("XSLTProcessor"))
555  {
556  $arr["status"] = true;
557  }
558  else
559  {
560  $arr["status"] = false;
561  $arr["comment"] = sprintf($this->lng->txt("pre_xsl_missing"),
562  "http://php.net/manual/en/book.xsl.php");
563  }
564 
565  return $arr;
566  }
567 
572  function checkGd()
573  {
574  global $ilDB;
575 
576  if (function_exists("imagefill") && function_exists("imagecolorallocate"))
577  {
578  $arr["status"] = true;
579  }
580  else
581  {
582  $arr["status"] = false;
583  $arr["comment"] = sprintf($this->lng->txt("pre_gd_missing"),
584  "http://php.net/manual/en/book.image.php");
585  }
586 
587  return $arr;
588  }
589 
594  function checkMemoryLimit()
595  {
596  global $ilDB;
597 
598  $limit = ini_get("memory_limit");
599 
600  $limit_ok = true;
601  if (is_int(strpos($limit, "M")))
602  {
603  $limit_n = (int) $limit;
604  if ($limit_n < 40)
605  {
606  $limit_ok = false;
607  }
608  }
609 
610  if ($limit_ok)
611  {
612  $arr["status"] = true;
613  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_recommend");
614  }
615  else
616  {
617  $arr["status"] = false;
618  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_too_low");
619  }
620 
621  return $arr;
622  }
623 
632  {
633  $a = array();
634  $a["php"] = $this->checkPHPVersion();
635 // $a["mysql"] = $this->checkMySQL();
636  $a["root"] = $this->checkWritable();
637  $a["folder_create"] = $this->checkCreatable();
638  $a["cookies_enabled"] = $this->checkCookiesEnabled();
639  $a["dom"] = $this->checkDom();
640  $a["xsl"] = $this->checkXsl();
641  $a["gd"] = $this->checkGd();
642  $a["memory"] = $this->checkMemoryLimit();
643 
644  return $a;
645  }
646 
652  {
653  $this->preliminaries_result = $this->queryPreliminaries();
654 
655  foreach ($this->preliminaries_result as $val)
656  {
657  if ($val["status"] === false)
658  {
659  $this->preliminaries = false;
660  return false;
661  }
662  }
663 
664  return true;
665  }
666 
671  function getPassword ()
672  {
673  return $this->ini->readVariable("setup","pass");
674  }
675 
681  function setPassword ($a_password)
682  {
683  $this->ini->setVariable("setup","pass",md5($a_password));
684 
685  if ($this->ini->write() == false)
686  {
687  $this->error = $this->ini->getError();
688  return false;
689  }
690 
691  return true;
692  }
693 
699  function loginAsClient($a_auth_data)
700  {
701  global $ilDB;
702 
703  if (empty($a_auth_data["client_id"]))
704  {
705  $this->error = "no_client_id";
706  return false;
707  }
708 
709  if (empty($a_auth_data["username"]))
710  {
711  $this->error = "no_username";
712  return false;
713  }
714 
715  if (empty($a_auth_data["password"]))
716  {
717  $this->error = "no_password";
718  return false;
719  }
720 
721  if (!$this->newClient($a_auth_data["client_id"]))
722  {
723  $this->error = "unknown_client_id";
724  unset($this->client);
725  return false;
726  }
727 
728  if (!$this->client->db_exists)
729  {
730  $this->error = "no_db_connect_consult_admin";
731  unset($this->client);
732  return false;
733  }
734 
735  $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = ".
736  $this->client->db->quote('system_role_id','text'));
737  $r1 = $this->client->db->fetchAssoc($s1);
738  $system_role_id = $r1["value"];
739  $q = "SELECT usr_data.usr_id FROM usr_data ".
740  "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id ".
741  "WHERE rbac_ua.rol_id = ".$this->client->db->quote((int) $system_role_id,'integer')." ".
742  "AND usr_data.login=".$this->client->db->quote($a_auth_data["username"],'text')." ".
743  "AND usr_data.passwd=".$this->client->db->quote(md5($a_auth_data["password"]),'text');
744 
745  $r = $this->client->db->query($q);
746 
747  if (!$r->numRows())
748  {
749  $this->error = "login_invalid";
750  return false;
751  }
752 
753  // all checks passed -> user valid
754  $_SESSION["auth"] = true;
755  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
756  $_SESSION["access_mode"] = "client";
757  $_SESSION["ClientId"] = $this->client->getId();
758  return true;
759  }
760 
766  function loginAsAdmin($a_password)
767  {
768  $a_password = md5($a_password);
769 
770  if ($this->ini->readVariable("setup","pass") == $a_password)
771  {
772  $_SESSION["auth"] = true;
773  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
774  $_SESSION["access_mode"] = "admin";
775  return true;
776  }
777 
778  return false;
779  }
780 
786  function newClient($a_client_id = 0)
787  {
788  if (!$this->isInstalled())
789  {
790  return false;
791  }
792 
793  $this->client = new ilClient($a_client_id, $this->db_connections);
794 
795  if (!$this->client->init())
796  {
797 //echo "<br>noclientinit";
798  $this->error = get_class($this).": ".$this->client->getError();
799  $_SESSION["ClientId"] = "";
800  return false;
801  }
802 
803  $_SESSION["ClientId"] = $a_client_id;
804 
805  return true;
806  }
807 
813  function getStatus ($client = 0)
814  {
815  if (!is_object($client))
816  {
817  if ($this->ini_client_exists)
818  {
820  }
821  else
822  {
823  $client = new ilClient(0, $this->db_connections);
824  }
825  }
826 
827  $status = array();
828  $status["ini"] = $this->checkClientIni($client); // check this one
829  $status["db"] = $this->checkClientDatabase($client);
830  if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
831  {
832  //$status["sess"]["status"] = false;
833  //$status["sess"]["comment"] = $status["db"]["comment"];
834  $status["lang"]["status"] = false;
835  $status["lang"]["comment"] = $status["db"]["comment"];
836  $status["contact"]["status"] = false;
837  $status["contact"]["comment"] = $status["db"]["comment"];
838 
839  $status["proxy"]["status"] = false;
840  $status["proxy"]["comment"] = $status["db"]["comment"];
841 
842  $status["nic"]["status"] = false;
843  $status["nic"]["comment"] = $status["db"]["comment"];
844  }
845  else
846  {
847  //$status["sess"] = $this->checkClientSessionSettings($client);
848  $status["lang"] = $this->checkClientLanguages($client);
849  $status["contact"] = $this->checkClientContact($client);
850  $status["proxy"] = $this->checkClientProxySettings($client);
851  $status["nic"] = $this->checkClientNIC($client);
852  $status["finish"] = $this->checkFinish($client);
853  $status["access"] = $this->checkAccess($client);
854  }
855 
856  //return value
857  return $status;
858  }
859 
865  function checkFinish(&$client)
866  {
867  if ($client->getSetting("setup_ok"))
868  {
869  $arr["status"] = true;
870  //$arr["comment"] = $this->lng->txt("setup_finished");
871  }
872  else
873  {
874  $arr["status"] = false;
875  $arr["comment"] = $this->lng->txt("setup_not_finished");
876  }
877 
878  return $arr;
879  }
880 
886  function checkAccess(&$client)
887  {
888  if ($client->ini->readVariable("client","access") == "1")
889  {
890  $arr["status"] = true;
891  $arr["comment"] = $this->lng->txt("online");
892  }
893  else
894  {
895  $arr["status"] = false;
896  $arr["comment"] = $this->lng->txt("disabled");
897  }
898 
899  return $arr;
900  }
901 
908  {
909  if (!$arr["status"] = $client->init())
910  {
911  $arr["comment"] = $client->getError();
912  }
913  else
914  {
915  //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
916  }
917 
918  return $arr;
919  }
920 
927  {
928  if (!$arr["status"] = $client->db_exists)
929  {
930  $arr["comment"] = $this->lng->txt("no_database");
931  return $arr;
932  }
933 
934  if (!$arr["status"] = $client->db_installed)
935  {
936  $arr["comment"] = $this->lng->txt("db_not_installed");
937  return $arr;
938  }
939 
940  // TODO: move this to client class!!
941  $client->setup_ok = (bool) $client->getSetting("setup_ok");
942 
943  //$this->lng->setDbHandler($client->db);
944  include_once "./Services/Database/classes/class.ilDBUpdate.php";
945  $ilDB = $client->db;
946  $this->lng->setDbHandler($client->db);
947  $dbupdate = new ilDBUpdate($client->db);
948 
949  if (!$arr["status"] = $dbupdate->getDBVersionStatus())
950  {
951  $arr["comment"] = $this->lng->txt("db_needs_update");
952  $arr["update"] = true;
953  return $arr;
954  }
955  else if ($dbupdate->hotfixAvailable())
956  {
957  $arr["status"] = false;
958  $arr["comment"] = $this->lng->txt("hotfix_available");
959  $arr["update"] = true;
960  return $arr;
961  }
962  else if ($dbupdate->customUpdatesAvailable())
963  {
964  $arr["status"] = false;
965  $arr["comment"] = $this->lng->txt("custom_updates_available");
966  $arr["update"] = true;
967  return $arr;
968  }
969 
970  // check control information
971 
972  $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
973  $crec = $ilDB->fetchAssoc($cset);
974  if ($crec["cnt"] == 0)
975  {
976  $arr["status"] = false;
977  $arr["comment"] = $this->lng->txt("db_control_structure_missing");
978  $arr["update"] = true;
979  return $arr;
980  }
981 
982  //$arr["comment"] = "version ".$dbupdate->getCurrentVersion();
983  return $arr;
984  }
985 
991  function checkClientSessionSettings(&$client, $a_as_bool = false)
992  {
993  require_once('Services/Authentication/classes/class.ilSessionControl.php');
994 
995  global $ilDB;
996  $db = $ilDB;
997 
999 
1000  $query = "SELECT keyword, value FROM settings WHERE ".$db->in('keyword', $fields, false, 'text');
1001  $res = $db->query($query);
1002 
1003  $rows = array();
1004  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
1005  {
1006  if( $row['value'] != '' )
1007  $rows[] = $row;
1008  else break;
1009  }
1010 
1011  if (count($rows) != count($fields))
1012  {
1013  if($a_as_bool) return false;
1014  $arr["status"] = false;
1015  $arr["comment"] = $this->lng->txt("session_management_not_configured");
1016  }
1017  else
1018  {
1019  if($a_as_bool) return true;
1020  $arr["status"] = true;
1021  $arr["comment"] = $this->lng->txt("session_management_configured");
1022  }
1023 
1024  return $arr;
1025  }
1026 
1032  {
1033  global $ilDB;
1034  $db = $ilDB;
1035 
1036  $fields = array('proxy_status','proxy_host','proxy_port');
1037 
1038  $query = "SELECT keyword, value FROM settings WHERE ".$db->in('keyword', $fields, false, 'text');
1039  $res = $db->query($query);
1040 
1041  $proxy_settings = array();
1042  $already_saved = false;
1043  while($row = $db->fetchAssoc($res))
1044  {
1045  $already_saved = true;
1046  $proxy_settings[$row['keyword']] = $row['value'];
1047  }
1048 
1049  if(!$already_saved)
1050  {
1051  $arr["status"] = false;
1052  $arr["comment"] = $this->lng->txt("proxy");
1053  $arr["text"] = $this->lng->txt("proxy");
1054  }
1055  else if((bool)$proxy_settings["proxy_status"] == false)
1056  {
1057  $arr["status"] = true;
1058  $arr["comment"] = $this->lng->txt("proxy_disabled");
1059  $arr["text"] = $this->lng->txt("proxy_disabled");
1060  }
1061  else
1062  {
1063  $arr["status"] = true;
1064  $arr["comment"] = $this->lng->txt("proxy_activated_configurated");
1065  $arr["text"] = $this->lng->txt("proxy_activated_configurated");
1066 
1067  }
1068  return $arr;
1069  }
1070 
1077  {
1078  $installed_langs = $this->lng->getInstalledLanguages();
1079 
1080  $count = count($installed_langs);
1081 
1082  if ($count < 1)
1083  {
1084  $arr["status"] = false;
1085  $arr["comment"] = $this->lng->txt("lang_none_installed");
1086  }
1087  else
1088  {
1089  $arr["status"] = true;
1090  //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
1091  }
1092 
1093  return $arr;
1094  }
1095 
1102  {
1103  $arr["status"] = true;
1104  //$arr["comment"] = $this->lng->txt("filled_out");
1105 
1106  $settings = $client->getAllSettings();
1107  $client_name = $client->getName();
1108 
1109  // check required fields
1110  if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
1111  empty($settings["admin_email"]) or empty($client_name))
1112  {
1113  $arr["status"] = false;
1114  $arr["comment"] = $this->lng->txt("missing_data");
1115  }
1116 
1117  // admin email
1118  if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
1119  {
1120  $arr["status"] = false;
1121  $arr["comment"] = $this->lng->txt("email_not_valid");
1122  }
1123 
1124  return $arr;
1125  }
1126 
1133  {
1134  $settings = $client->getAllSettings();
1135 
1136  if (!isset($settings["nic_enabled"]))
1137  {
1138  $arr["status"] = false;
1139  $arr["comment"] = $this->lng->txt("nic_not_disabled");
1140  return $arr;
1141  }
1142 
1143  $arr["status"] = true;
1144 
1145  if ($settings["nic_enabled"] == "-1")
1146  {
1147  $arr["comment"] = $this->lng->txt("nic_reg_failed");
1148  return $arr;
1149  }
1150 
1151  if (!$settings["nic_enabled"])
1152  {
1153  $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1154  }
1155  else
1156  {
1157  $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1158  if ($settings["inst_id"] <= 0)
1159  {
1160  $arr["status"] = false;
1161  }
1162  }
1163 
1164  return $arr;
1165  }
1166 
1171  function isInstalled()
1172  {
1173  return $this->ini_ilias_exists;
1174  }
1175 
1180  function isAuthenticated()
1181  {
1182  return $this->auth;
1183  }
1184 
1189  function isAdmin()
1190  {
1191  return ($this->access_mode == "admin") ? true : false;
1192  }
1193 
1199  function saveMasterSetup($a_formdata)
1200  {
1201  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1202 
1203  if ($a_formdata["chk_datadir_path"] == 1) // mode create dir
1204  {
1205  if (!ilUtil::makeDir($datadir_path))
1206  {
1207  $this->error = "create_datadir_failed";
1208  return false;
1209  }
1210  }
1211 
1212  // create webspace dir if it does not exist
1213  if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1214  {
1215  if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1216  {
1217  $this->error = "create_webdir_failed";
1218  return false;
1219  }
1220  }
1221 
1222  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1223  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1224  $log_file = substr($form_log_path,strlen($log_path)+1);
1225 
1226  $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
1227  $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
1228  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1229  $this->ini->setVariable("clients", "datadir", $datadir_path);
1230  $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
1231  $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
1232  $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
1233  $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
1234  $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
1235  //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1236  $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1237  $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1238  $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1239  $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
1240  $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
1241  $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
1242  $this->ini->setVariable("log", "path", $log_path);
1243  $this->ini->setVariable("log", "file", $log_file);
1244  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1245 
1246  if (!$this->ini->write())
1247  {
1248  $this->error = get_class($this).": ".$this->ini->getError();
1249  return false;
1250  }
1251 
1252  // everything is fine. so we authenticate the user and set access mode to 'admin'
1253  $_SESSION["auth"] = true;
1254  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1255  $_SESSION["access_mode"] = "admin";
1256 
1257  return true;
1258  }
1259 
1265  function updateMasterSettings($a_formdata)
1266  {
1267  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1268  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1269  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1270  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1271  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1272  //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1273  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1274  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1275  $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
1276  $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1277  $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
1278  $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
1279 
1280  $this->ini->setVariable("tools", "convert", $convert_path);
1281  $this->ini->setVariable("tools", "zip", $zip_path);
1282  $this->ini->setVariable("tools", "unzip", $unzip_path);
1283  $this->ini->setVariable("tools", "java", $java_path);
1284  $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
1285  //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1286  $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1287  $this->ini->setVariable("tools", "latex", $latex_url);
1288  $this->ini->setVariable("tools", "fop", $fop_path);
1289  $this->ini->setVariable("tools", "vscantype", $scan_type);
1290  $this->ini->setVariable("tools", "scancommand", $scan_command);
1291  $this->ini->setVariable("tools", "cleancommand", $clean_command);
1292 
1293  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1294  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1295  $log_file = substr($form_log_path,strlen($log_path)+1);
1296 
1297  $this->ini->setVariable("log", "path", $log_path);
1298  $this->ini->setVariable("log", "file", $log_file);
1299  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1300  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1301 
1302  if (!$this->ini->write())
1303  {
1304  $this->error = get_class($this).": ".$this->ini->getError();
1305  return false;
1306  }
1307 
1308  return true;
1309  }
1310 
1316  function checkToolsSetup($a_formdata)
1317  {
1318  // convert path
1319  if (!isset($a_formdata["chk_convert_path"]))
1320  {
1321  // convert backslashes to forwardslashes
1322  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1323 
1324  if (($err = $this->testConvert($convert_path)) != "")
1325  {
1326  $this->error = $err;
1327  return false;
1328  }
1329  }
1330 
1331  // zip path
1332  if (!isset($a_formdata["chk_zip_path"]))
1333  {
1334  // convert backslashes to forwardslashes
1335  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1336 
1337  if (empty($zip_path))
1338  {
1339  $this->error = "no_path_zip";
1340  return false;
1341  }
1342 
1343  if (!$this->testZip($zip_path))
1344  {
1345  $this->error = "check_failed_zip";
1346  return false;
1347  }
1348  }
1349 
1350  // unzip path
1351  if (!isset($a_formdata["chk_unzip_path"]))
1352  {
1353  // convert backslashes to forwardslashes
1354  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1355 
1356  if (empty($unzip_path))
1357  {
1358  $this->error = "no_path_unzip";
1359  return false;
1360  }
1361 
1362  if (!$this->testUnzip($unzip_path))
1363  {
1364  $this->error = "check_failed_unzip";
1365  return false;
1366  }
1367  }
1368 
1369  // java path
1370  if (!isset($a_formdata["chk_java_path"]))
1371  {
1372  // convert backslashes to forwardslashes
1373  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1374 
1375  if (empty($java_path))
1376  {
1377  $this->error = "no_path_java";
1378  return false;
1379  }
1380 
1381  if (!$this->testJava($java_path))
1382  {
1383  $this->error = "check_failed_java";
1384  return false;
1385  }
1386  }
1387 
1388  // htmldoc path
1389  if (!isset($a_formdata["chk_htmldoc_path"]))
1390  {
1391  // convert backslashes to forwardslashes
1392  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1393 
1394  if (empty($htmldoc_path))
1395  {
1396  $this->error = "no_path_htmldoc";
1397  return false;
1398  }
1399 
1400  if (!$this->testHtmldoc($htmldoc_path))
1401  {
1402  $this->error = "check_failed_htmldoc";
1403  return false;
1404  }
1405  }
1406  /*if (!isset($a_formdata["chk_mkisofs_path"]))
1407  {
1408  // convert backslashes to forwardslashes
1409  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1410 
1411  if (empty($mkisofs_path))
1412  {
1413  $this->error = "no_path_mkisofs";
1414  return false;
1415  }
1416 
1417  if (!$this->testHtmldoc($mkisofs_path))
1418  {
1419  $this->error = "check_failed_mkisofs";
1420  return false;
1421  }
1422  }*/
1423 
1424  if (!isset($a_formdata["chk_ffmpeg_path"]))
1425  {
1426  // convert backslashes to forwardslashes
1427  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1428 
1429  if (empty($ffmpeg_path))
1430  {
1431  $this->error = "no_path_ffmpeg";
1432  return false;
1433  }
1434 
1435  if (!$this->testFFMpeg($ffmpeg_path))
1436  {
1437  $this->error = "check_failed_ffmpeg";
1438  return false;
1439  }
1440  }
1441 
1442  // latex url
1443  if (!isset($a_formdata["chk_latex_url"]))
1444  {
1445  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1446  if (empty($latex_url))
1447  {
1448  $this->error = "no_latex_url";
1449  return false;
1450  }
1451 
1452  if (!$this->testLatex($latex_url))
1453  {
1454  $this->error = "check_failed_latex";
1455  return false;
1456  }
1457  }
1458 
1459  return true;
1460  }
1461 
1467  function checkDataDirSetup($a_formdata)
1468  {
1469  // remove trailing slash & convert backslashes to forwardslashes
1470  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1471 
1472  if (empty($datadir_path))
1473  {
1474  $this->error = "no_path_datadir";
1475  return false;
1476  }
1477 
1478  $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1479 
1480  // datadir may not point to webspace dir or to any place under webspace_dir
1481  if (strpos($datadir_path,$webspace_dir) !== false)
1482  {
1483  $this->error = "datadir_webspacedir_match";
1484  return false;
1485  }
1486 
1487  // create dir
1488  if ($a_formdata["chk_datadir_path"] == 1)
1489  {
1490  $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1491  $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
1492 
1493  if (is_writable($datadir_path))
1494  {
1495  $this->error = "dir_exists_create";
1496  return false;
1497  }
1498 
1499  if (!is_writable($dir_to_check))
1500  {
1501  $this->error = "cannot_create_datadir_no_write_access";
1502  return false;
1503  }
1504  }
1505  else // check set target dir
1506  {
1507  if (!is_writable($datadir_path))
1508  {
1509  $this->error = "cannot_create_datadir_no_write_access";
1510  return false;
1511  }
1512  }
1513 
1514  return true;
1515  }
1516 
1522  function checkPasswordSetup($a_formdata)
1523  {
1524  if (!$a_formdata["setup_pass"])
1525  {
1526  $this->error = "no_setup_pass_given";
1527  return false;
1528  }
1529 
1530  if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
1531  {
1532  $this->error = "pass_does_not_match";
1533  return false;
1534  }
1535 
1536  return true;
1537  }
1538 
1544  function checkLogSetup($a_formdata)
1545  {
1546  // log path
1547  if (!$a_formdata["chk_log_status"])
1548  {
1549  // remove trailing slash & convert backslashes to forwardslashes
1550  $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1551 
1552  if (empty($log_path))
1553  {
1554  $this->error = "no_path_log";
1555  return false;
1556  }
1557 
1558  if (!@touch($log_path))
1559  {
1560  $this->error = "could_not_create_logfile";
1561  return false;
1562  }
1563  }
1564 
1565  return true;
1566  }
1567 
1572  function getError()
1573  {
1574  if (empty($this->error))
1575  {
1576  return false;
1577  }
1578 
1579  $error = $this->error;
1580  $this->error = "";
1581 
1582  return $error;
1583  }
1584 
1590  function _ilSetup()
1591  {
1592  //if ($this->ini->readVariable("db","type") != "")
1593  //{
1594  // $this->db->disconnect();
1595  //}
1596  return true;
1597  }
1598 
1605  function testConvert($a_convert_path)
1606  {
1607  if (trim($a_convert_path) == "")
1608  {
1609  return "no_path_convert";
1610  }
1611  if (!is_file($a_convert_path))
1612  {
1613  return "check_failed_convert";
1614  }
1615 
1616  return "";
1617 
1618 /*
1619  // generate gif with convert
1620  if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
1621  {
1622  unlink(ILIAS_ABSOLUTE_PATH."/images/test.png");
1623  }
1624 
1625  system($a_convert_path." ".ILIAS_ABSOLUTE_PATH."/setup/test/test.jpg GIF:".ILIAS_ABSOLUTE_PATH."/setup/test/test.png");
1626 
1627  // check wether convert generated file
1628  if (file_exists(ILIAS_ABSOLUTE_PATH."/setup/test/test.png"))
1629  {
1630  unlink(ILIAS_ABSOLUTE_PATH."/setup/test/test.png");
1631  return true;
1632  }
1633  else
1634  {
1635  return false;
1636  }
1637 */
1638  }
1639 
1646  function testJava ($a_java_path)
1647  {
1648  // java is optional, so empty path is ok
1649  if (trim($a_java_path) == "")
1650  {
1651  return "";
1652  }
1653 
1654  if (!is_file($a_java_path))
1655  {
1656  return "check_failed_java";
1657  }
1658 
1659  return "";
1660 /*
1661  exec($a_java_path, $out, $back);
1662 
1663  unset($out);
1664 
1665  return ($back != 1) ? false : true;
1666 */
1667  }
1668 
1675  function testLatex($a_latex_url)
1676  {
1677  // latex is optional, so empty path is ok
1678  if (trim($a_latex_url) == "")
1679  {
1680  return "";
1681  }
1682 
1683  // open the URL
1684  include_once "./setup/classes/class.ilHttpRequest.php";
1685  $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1686  $result = @$http->downloadToString();
1687  if ((strpos((substr($result, 0, 5)), "PNG") !== FALSE) || (strpos((substr($result, 0, 5)), "GIF") !== FALSE))
1688  {
1689  return "";
1690  }
1691  else
1692  {
1693  return "check_failed_latex";;
1694  }
1695  }
1696 
1703  function testZip ($a_zip_path)
1704  {
1705  if (trim($a_zip_path) == "")
1706  {
1707  return "no_path_zip";
1708  }
1709  if (!is_file($a_zip_path))
1710  {
1711  return "check_failed_zip";
1712  }
1713 
1714  return "";
1715 /*
1716  // create test file and run zip
1717  $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1718 
1719  fwrite($fp, "test");
1720  fclose($fp);
1721 
1722  if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1723  {
1724  $curDir = getcwd();
1725  chdir(ILIAS_ABSOLUTE_PATH);
1726 
1727  $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1728 
1729  exec($zipCmd);
1730 
1731  chdir($curDir);
1732 
1733  }
1734 
1735  // check wether zip generated test file or not
1736  if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1737  {
1738  unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1739  return true;
1740  }
1741  else
1742  {
1743  unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1744  return false;
1745  }
1746 */
1747  }
1748 
1749 
1756  function testUnzip ($a_unzip_path)
1757  {
1758  if (trim($a_unzip_path) == "")
1759  {
1760  return "no_path_unzip";
1761  }
1762  if (!is_file($a_unzip_path))
1763  {
1764  return "check_failed_unzip";
1765  }
1766 
1767  return "";
1768 /*
1769  $curDir = getcwd();
1770 
1771  chdir(ILIAS_ABSOLUTE_PATH);
1772 
1773  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1774  {
1775  $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1776  exec($unzipCmd);
1777  }
1778 
1779  chdir($curDir);
1780 
1781  // check wether unzip extracted the test file or not
1782  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1783  {
1784  unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1785 
1786  return true;
1787  }
1788  else
1789  {
1790  return false;
1791  }
1792 */
1793  }
1794 
1801  function testHtmldoc($a_htmldoc_path)
1802  {
1803  // java is optional, so empty path is ok
1804  if (trim($a_htmldoc_path) == "")
1805  {
1806  return "";
1807  }
1808 
1809  if (!is_file($a_htmldoc_path))
1810  {
1811  return "check_failed_htmldoc";
1812  }
1813 
1814  return "";
1815 
1816 
1817  $curDir = getcwd();
1818 
1819  chdir(ILIAS_ABSOLUTE_PATH);
1820 
1821  $html = "<html><head><title></title></head><body><p>test</p></body></html>";
1822 
1823  $html_file = "htmldoc_test_file.html";
1824 
1825  $fp = fopen( $html_file ,"wb");
1826  fwrite($fp, $html);
1827  fclose($fp);
1828 
1829  $htmldoc = $a_htmldoc_path." ";
1830  $htmldoc .= "--no-toc ";
1831  $htmldoc .= "--no-jpeg ";
1832  $htmldoc .= "--webpage ";
1833  $htmldoc .= "--outfile htmldoc_test_file.pdf ";
1834  $htmldoc .= "--bodyfont Arial ";
1835  $htmldoc .= "--charset iso-8859-15 ";
1836  $htmldoc .= "--color ";
1837  $htmldoc .= "--size A4 "; // --landscape
1838  $htmldoc .= "--format pdf ";
1839  $htmldoc .= "--footer ... ";
1840  $htmldoc .= "--header ... ";
1841  $htmldoc .= "--left 60 ";
1842  // $htmldoc .= "--right 200 ";
1843  $htmldoc .= $html_file;
1844  exec($htmldoc);
1845 
1846  unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
1847 
1848  chdir($curDir);
1849 
1850  if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
1851  {
1852  unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
1853  return true;
1854  }
1855  else
1856  {
1857  return false;
1858  }
1859  }
1860 
1861 
1868  function unzip($a_file, $overwrite = false)
1869  {
1870  //global $ilias;
1871 
1872  $pathinfo = pathinfo($a_file);
1873  $dir = $pathinfo["dirname"];
1874  $file = $pathinfo["basename"];
1875 
1876  // unzip
1877  $cdir = getcwd();
1878  chdir($dir);
1879  $unzip = $this->ini->readVariable("tools","unzip");
1880  $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
1881  exec($unzipcmd, $arr);
1882  $zdirs = array();
1883 
1884  foreach($arr as $line)
1885  {
1886  if(is_int(strpos($line, "/")))
1887  {
1888  $zdir = substr($line, 0, strrpos($line, "/"));
1889  $nr = substr_count($zdir, "/");
1890  //echo $zdir." ".$nr."<br>";
1891  while ($zdir != "")
1892  {
1893  $nr = substr_count($zdir, "/");
1894  $zdirs[$zdir] = $nr; // collect directories
1895  //echo $dir." ".$nr."<br>";
1896  $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1897  }
1898  }
1899  }
1900 
1901  asort($zdirs);
1902 
1903  foreach($zdirs as $zdir => $nr) // create directories
1904  {
1905  ilUtil::createDirectory($zdir);
1906  }
1907 
1908  // real unzip
1909  if ($overvwrite)
1910  {
1911  $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
1912  }
1913  else
1914  {
1915  $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
1916  }
1917  exec($unzipcmd);
1918 
1919  chdir($cdir);
1920  }
1921 
1927  function setSessionSettings($session_settings)
1928  {
1929  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1930 
1931  $db = $this->client->getDB();
1932 
1933  $setting_fields = ilSessionControl::getSettingFields();
1934 
1935  $i = 0;
1936  foreach($setting_fields as $field)
1937  {
1938  if( isset($session_settings[$field]) )
1939  {
1940  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1941  $res = $db->queryF($query,
1942  array('text', 'text'), array('common', $field));
1943 
1944  $row = array();
1945  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) break;
1946 
1947  if( count($row) > 0 )
1948  {
1949  $db->update(
1950  'settings',
1951  array(
1952  'value' => array('text', $session_settings[$field])
1953  ),
1954  array(
1955  'module' => array('text', 'common'),
1956  'keyword' => array('text', $field)
1957  )
1958  );
1959  }
1960  else
1961  {
1962  $db->insert(
1963  'settings',
1964  array(
1965  'module' => array('text', 'common'),
1966  'keyword' => array('text', $field),
1967  'value' => array('text', $session_settings[$field])
1968  )
1969  );
1970  }
1971 
1972  $i++;
1973  }
1974  }
1975 
1976  if($i < 4) $message = $this->lng->txt("session_settings_not_saved");
1977  else $message = $this->lng->txt("settings_saved");
1978 
1979  ilUtil::sendInfo($message);
1980  }
1981 
1988  {
1989  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1990 
1991  $db = $this->client->getDB();
1992 
1993  $setting_fields = ilSessionControl::getSettingFields();
1994 
1995  $query = "SELECT * FROM settings WHERE module = %s " .
1996  "AND ".$db->in('keyword', $setting_fields, false, 'text');
1997 
1998  $res = $db->queryF($query, array('text'), array('common'));
1999 
2000  $session_settings = array();
2001  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
2002  {
2003  $session_settings[$row['keyword']] = $row['value'];
2004  }
2005 
2006  foreach( $setting_fields as $field )
2007  {
2008  if( !isset($session_settings[$field]) )
2009  {
2010  $value = 1;
2011 
2012  switch($field)
2013  {
2014  case 'session_max_count':
2015 
2017  break;
2018 
2019  case 'session_min_idle':
2020 
2022  break;
2023 
2024  case 'session_max_idle':
2025 
2027  break;
2028 
2029  case 'session_max_idle_after_first_request':
2030 
2032  break;
2033 
2034  case 'session_allow_client_maintenance':
2035 
2037  break;
2038  }
2039 
2040  $session_settings[$field] = $value;
2041  }
2042  }
2043 
2044  return $session_settings;
2045  }
2046 
2052  function cloneFromSource($source_id)
2053  {
2054  // Getting source and targets
2055  $source = new ilClient($source_id, $this->db_connections);
2056  $source->init();
2057  $target = $this->client;
2058 
2059  // ************************************************
2060  // ** COPY FILES
2061 
2062  // Cleaning up datadir
2063  if (! ilUtil::delDir($target->getDataDir())) {
2064  $this->error = "Could not delete data dir $target->getDataDir()";
2065  //return false;
2066  }
2067 
2068  // Create empty datadir
2069  if (!ilUtil::makeDir($target->getDataDir()))
2070  {
2071  $this->error = "could_not_create_base_data_dir :".$target->getDataDir();
2072  return false;
2073  }
2074 
2075  // Copying datadir
2076  if (! ilUtil::rCopy($source->getDataDir(),$target->getDataDir())) {
2077  $this->error = "clone_datadircopyfail";
2078  $target->ini->write();
2079  return false;
2080  }
2081 
2082  // Cleaning up Webspacedir
2083  if (! ilUtil::delDir($target->getWebspaceDir())) {
2084  $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
2085  //return false;
2086  }
2087 
2088  // Create empty Webspacedir
2089  if (!ilUtil::makeDir($target->getWebspaceDir()))
2090  {
2091  $this->error = "could_not_create_base_webspace_dir :".$target->getWebspaceDir();
2092  return false;
2093  }
2094 
2095  // Copying Webspacedir
2096  if (! ilUtil::rCopy($source->getWebspaceDir(),$target->getWebspaceDir())) {
2097  $this->error = "clone_websipacedircopyfail";
2098  $target->ini->write();
2099  return false;
2100  }
2101 
2102  // Restore ini file
2103  $target->ini->write();
2104 
2105  // ************************************************
2106  // ** COPY DATABASE
2107 
2108  $source->connect();
2109  if (!$source->db)
2110  {
2111  $this->error = "Source database connection failed.";
2112  return false;
2113  }
2114 
2115  $target->connect();
2116  if (!$target->db)
2117  {
2118  $this->error = "Target database connection failed.";
2119  return false;
2120  }
2121 
2122  $source->connect();
2123  $srcTables = $source->db->query("SHOW TABLES");
2124  $target->connect();
2125 
2126  // drop all tables of the target db
2127  $tarTables = $target->db->query("SHOW TABLES");
2128  foreach($tarTables->fetchAll() as $cTable)
2129  {
2130  $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2131  }
2132 
2133  foreach($srcTables->fetchAll() as $cTable){
2134  $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2135  $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
2136  if(!$create) {
2137  $error = true;
2138  }
2139  $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM ".$source->getDbName().".".$cTable[0]);
2140  }
2141  return true;
2142  }
2150  public function printProxyStatus($client)
2151  {
2152  require_once './Services/Http/exceptions/class.ilProxyException.php';
2153  $settings = $client->getAllSettings();
2154 
2155  if((bool)$settings['proxy_status'] == true)
2156  {
2157  try
2158  {
2164  require_once 'Services/PEAR/lib/Net/Socket.php';
2165 
2166  $socket = new Net_Socket();
2167  $socket->setErrorHandling(PEAR_ERROR_RETURN);
2168  $response = $socket->connect($settings['proxy_host'], $settings['proxy_port']);
2169  if(!is_bool($response))
2170  {
2171  global $lng;
2172  throw new ilProxyException(strlen($response) ? $response : $lng->txt('proxy_not_connectable'));
2173  }
2174 
2175  ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
2176 
2177  }
2178  catch(ilProxyException $e)
2179  {
2180  ilUtil::sendFailure($this->lng->txt('proxy_pear_net_socket_error').': '.$e->getMessage());
2181  }
2182  }
2183 
2184  }
2185 
2186  public function saveProxySettings($proxy_settings)
2187  {
2188  $db = $this->client->getDB();
2189  $proxy_fields = array('proxy_status','proxy_host','proxy_port');
2190 
2191  foreach($proxy_fields as $field)
2192  {
2193  if( isset($proxy_settings[$field]) )
2194  {
2195  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
2196  $res = $db->queryF($query,
2197  array('text', 'text'), array('common', $field));
2198 
2199  $row = array();
2200  while($row = $db->fetchAssoc($res)) break;
2201 
2202  if( count($row) > 0 )
2203  {
2204  $db->update(
2205  'settings',
2206  array(
2207  'value' => array('text', $proxy_settings[$field])
2208  ),
2209  array(
2210  'module' => array('text', 'common'),
2211  'keyword' => array('text', $field)
2212  )
2213  );
2214  }
2215  else
2216  {
2217  $db->insert(
2218  'settings',
2219  array(
2220  'module' => array('text', 'common'),
2221  'keyword' => array('text', $field),
2222  'value' => array('text', $proxy_settings[$field])
2223  )
2224  );
2225  }
2226  }
2227  }
2228  }
2229 
2230 
2231 } // END class.ilSetup
2232 
2234 {
2235  public function current()
2236  {
2237  return parent::getFileName();
2238  }
2239 
2240  public function valid()
2241  {
2242  if(!parent::valid())
2243  {
2244  return false;
2245  }
2246  if($this->isFile() and substr(parent::getFileName(),-4) == '.xml')
2247  {
2248  return false;
2249  }
2250  if($this->isFile() and substr(parent::getFileName(),-8) != '_inserts')
2251  {
2252  return true;
2253  }
2254  parent::next();
2255  return $this->valid();
2256  }
2257 
2258  public function rewind()
2259  {
2260  parent::rewind();
2261  }
2262 }
2263 ?>