ILIAS  Release_4_4_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-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.3.0', '<'))
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", "ghostscript", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"])));
1234  $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
1235  $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
1236  //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1237  $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1238  $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1239  $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1240  $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
1241  $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
1242  $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
1243  $this->ini->setVariable("log", "path", $log_path);
1244  $this->ini->setVariable("log", "file", $log_file);
1245  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1246 
1247  if (!$this->ini->write())
1248  {
1249  $this->error = get_class($this).": ".$this->ini->getError();
1250  return false;
1251  }
1252 
1253  // everything is fine. so we authenticate the user and set access mode to 'admin'
1254  $_SESSION["auth"] = true;
1255  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1256  $_SESSION["access_mode"] = "admin";
1257 
1258  return true;
1259  }
1260 
1266  function updateMasterSettings($a_formdata)
1267  {
1268  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1269  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1270  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1271  $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1272  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1273  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1274  //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1275  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1276  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1277  $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
1278  $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1279  $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
1280  $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
1281 
1282  $this->ini->setVariable("tools", "convert", $convert_path);
1283  $this->ini->setVariable("tools", "zip", $zip_path);
1284  $this->ini->setVariable("tools", "unzip", $unzip_path);
1285  $this->ini->setVariable("tools", "ghostscript", $ghostscript_path);
1286  $this->ini->setVariable("tools", "java", $java_path);
1287  $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
1288  //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1289  $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1290  $this->ini->setVariable("tools", "latex", $latex_url);
1291  $this->ini->setVariable("tools", "fop", $fop_path);
1292  $this->ini->setVariable("tools", "vscantype", $scan_type);
1293  $this->ini->setVariable("tools", "scancommand", $scan_command);
1294  $this->ini->setVariable("tools", "cleancommand", $clean_command);
1295 
1296  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1297  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1298  $log_file = substr($form_log_path,strlen($log_path)+1);
1299 
1300  $this->ini->setVariable("log", "path", $log_path);
1301  $this->ini->setVariable("log", "file", $log_file);
1302  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1303  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1304 
1305  if (!$this->ini->write())
1306  {
1307  $this->error = get_class($this).": ".$this->ini->getError();
1308  return false;
1309  }
1310 
1311  return true;
1312  }
1313 
1319  function checkToolsSetup($a_formdata)
1320  {
1321  // convert path
1322  if (!isset($a_formdata["chk_convert_path"]))
1323  {
1324  // convert backslashes to forwardslashes
1325  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1326 
1327  if (($err = $this->testConvert($convert_path)) != "")
1328  {
1329  $this->error = $err;
1330  return false;
1331  }
1332  }
1333 
1334  // zip path
1335  if (!isset($a_formdata["chk_zip_path"]))
1336  {
1337  // convert backslashes to forwardslashes
1338  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1339 
1340  if (empty($zip_path))
1341  {
1342  $this->error = "no_path_zip";
1343  return false;
1344  }
1345 
1346  if (!$this->testZip($zip_path))
1347  {
1348  $this->error = "check_failed_zip";
1349  return false;
1350  }
1351  }
1352 
1353  // unzip path
1354  if (!isset($a_formdata["chk_unzip_path"]))
1355  {
1356  // convert backslashes to forwardslashes
1357  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1358 
1359  if (empty($unzip_path))
1360  {
1361  $this->error = "no_path_unzip";
1362  return false;
1363  }
1364 
1365  if (!$this->testUnzip($unzip_path))
1366  {
1367  $this->error = "check_failed_unzip";
1368  return false;
1369  }
1370  }
1371 
1372  // ghostscript path
1373  if (!isset($a_formdata["chk_ghostscript_path"]))
1374  {
1375  // convert backslashes to forwardslashes
1376  $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1377 
1378  if (($err = $this->testGhostscript($ghostscript_path)) != "")
1379  {
1380  $this->error = $err;
1381  return false;
1382  }
1383  }
1384 
1385  // java path
1386  if (!isset($a_formdata["chk_java_path"]))
1387  {
1388  // convert backslashes to forwardslashes
1389  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1390 
1391  if (empty($java_path))
1392  {
1393  $this->error = "no_path_java";
1394  return false;
1395  }
1396 
1397  if (!$this->testJava($java_path))
1398  {
1399  $this->error = "check_failed_java";
1400  return false;
1401  }
1402  }
1403 
1404  // htmldoc path
1405  if (!isset($a_formdata["chk_htmldoc_path"]))
1406  {
1407  // convert backslashes to forwardslashes
1408  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1409 
1410  if (empty($htmldoc_path))
1411  {
1412  $this->error = "no_path_htmldoc";
1413  return false;
1414  }
1415 
1416  if (!$this->testHtmldoc($htmldoc_path))
1417  {
1418  $this->error = "check_failed_htmldoc";
1419  return false;
1420  }
1421  }
1422  /*if (!isset($a_formdata["chk_mkisofs_path"]))
1423  {
1424  // convert backslashes to forwardslashes
1425  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1426 
1427  if (empty($mkisofs_path))
1428  {
1429  $this->error = "no_path_mkisofs";
1430  return false;
1431  }
1432 
1433  if (!$this->testHtmldoc($mkisofs_path))
1434  {
1435  $this->error = "check_failed_mkisofs";
1436  return false;
1437  }
1438  }*/
1439 
1440  if (!isset($a_formdata["chk_ffmpeg_path"]))
1441  {
1442  // convert backslashes to forwardslashes
1443  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1444 
1445  if (empty($ffmpeg_path))
1446  {
1447  $this->error = "no_path_ffmpeg";
1448  return false;
1449  }
1450 
1451  if (!$this->testFFMpeg($ffmpeg_path))
1452  {
1453  $this->error = "check_failed_ffmpeg";
1454  return false;
1455  }
1456  }
1457 
1458  // latex url
1459  if (!isset($a_formdata["chk_latex_url"]))
1460  {
1461  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1462  if (empty($latex_url))
1463  {
1464  $this->error = "no_latex_url";
1465  return false;
1466  }
1467 
1468  if (!$this->testLatex($latex_url))
1469  {
1470  $this->error = "check_failed_latex";
1471  return false;
1472  }
1473  }
1474 
1475  return true;
1476  }
1477 
1483  function checkDataDirSetup($a_formdata)
1484  {
1485  // remove trailing slash & convert backslashes to forwardslashes
1486  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1487 
1488  if (empty($datadir_path))
1489  {
1490  $this->error = "no_path_datadir";
1491  return false;
1492  }
1493 
1494  $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1495 
1496  // datadir may not point to webspace dir or to any place under webspace_dir
1497  if (strpos($datadir_path,$webspace_dir) !== false)
1498  {
1499  $this->error = "datadir_webspacedir_match";
1500  return false;
1501  }
1502 
1503  // create dir
1504  if ($a_formdata["chk_datadir_path"] == 1)
1505  {
1506  $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1507  $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
1508 
1509  if (is_writable($datadir_path))
1510  {
1511  $this->error = "dir_exists_create";
1512  return false;
1513  }
1514 
1515  if (!is_writable($dir_to_check))
1516  {
1517  $this->error = "cannot_create_datadir_no_write_access";
1518  return false;
1519  }
1520  }
1521  else // check set target dir
1522  {
1523  if (!is_writable($datadir_path))
1524  {
1525  $this->error = "cannot_create_datadir_no_write_access";
1526  return false;
1527  }
1528  }
1529 
1530  return true;
1531  }
1532 
1538  function checkPasswordSetup($a_formdata)
1539  {
1540  if (!$a_formdata["setup_pass"])
1541  {
1542  $this->error = "no_setup_pass_given";
1543  return false;
1544  }
1545 
1546  if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
1547  {
1548  $this->error = "pass_does_not_match";
1549  return false;
1550  }
1551 
1552  return true;
1553  }
1554 
1560  function checkLogSetup($a_formdata)
1561  {
1562  // log path
1563  if (!$a_formdata["chk_log_status"])
1564  {
1565  // remove trailing slash & convert backslashes to forwardslashes
1566  $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1567 
1568  if (empty($log_path))
1569  {
1570  $this->error = "no_path_log";
1571  return false;
1572  }
1573 
1574  if (!@touch($log_path))
1575  {
1576  $this->error = "could_not_create_logfile";
1577  return false;
1578  }
1579  }
1580 
1581  return true;
1582  }
1583 
1588  function getError()
1589  {
1590  if (empty($this->error))
1591  {
1592  return false;
1593  }
1594 
1595  $error = $this->error;
1596  $this->error = "";
1597 
1598  return $error;
1599  }
1600 
1606  function _ilSetup()
1607  {
1608  //if ($this->ini->readVariable("db","type") != "")
1609  //{
1610  // $this->db->disconnect();
1611  //}
1612  return true;
1613  }
1614 
1621  function testConvert($a_convert_path)
1622  {
1623  if (trim($a_convert_path) == "")
1624  {
1625  return "no_path_convert";
1626  }
1627  if (!is_file($a_convert_path))
1628  {
1629  return "check_failed_convert";
1630  }
1631 
1632  return "";
1633 
1634 /*
1635  // generate gif with convert
1636  if (file_exists(ILIAS_ABSOLUTE_PATH."/images/test.gif"))
1637  {
1638  unlink(ILIAS_ABSOLUTE_PATH."/images/test.png");
1639  }
1640 
1641  system($a_convert_path." ".ILIAS_ABSOLUTE_PATH."/setup/test/test.jpg GIF:".ILIAS_ABSOLUTE_PATH."/setup/test/test.png");
1642 
1643  // check wether convert generated file
1644  if (file_exists(ILIAS_ABSOLUTE_PATH."/setup/test/test.png"))
1645  {
1646  unlink(ILIAS_ABSOLUTE_PATH."/setup/test/test.png");
1647  return true;
1648  }
1649  else
1650  {
1651  return false;
1652  }
1653 */
1654  }
1655 
1662  function testGhostscript($a_ghostscript_path)
1663  {
1664  // ghostscript is optional, so empty path is ok
1665  if (trim($a_ghostscript_path) == "")
1666  {
1667  return "";
1668  }
1669  if (!is_file($a_ghostscript_path))
1670  {
1671  return "check_failed_ghostscript";
1672  }
1673 
1674  return "";
1675  }
1676 
1683  function testJava ($a_java_path)
1684  {
1685  // java is optional, so empty path is ok
1686  if (trim($a_java_path) == "")
1687  {
1688  return "";
1689  }
1690 
1691  if (!is_file($a_java_path))
1692  {
1693  return "check_failed_java";
1694  }
1695 
1696  return "";
1697 /*
1698  exec($a_java_path, $out, $back);
1699 
1700  unset($out);
1701 
1702  return ($back != 1) ? false : true;
1703 */
1704  }
1705 
1712  function testLatex($a_latex_url)
1713  {
1714  // latex is optional, so empty path is ok
1715  if (trim($a_latex_url) == "")
1716  {
1717  return "";
1718  }
1719 
1720  // open the URL
1721  include_once "./setup/classes/class.ilHttpRequest.php";
1722  $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1723  $result = @$http->downloadToString();
1724  if ((strpos((substr($result, 0, 5)), "PNG") !== FALSE) || (strpos((substr($result, 0, 5)), "GIF") !== FALSE))
1725  {
1726  return "";
1727  }
1728  else
1729  {
1730  return "check_failed_latex";;
1731  }
1732  }
1733 
1740  function testZip ($a_zip_path)
1741  {
1742  if (trim($a_zip_path) == "")
1743  {
1744  return "no_path_zip";
1745  }
1746  if (!is_file($a_zip_path))
1747  {
1748  return "check_failed_zip";
1749  }
1750 
1751  return "";
1752 /*
1753  // create test file and run zip
1754  $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1755 
1756  fwrite($fp, "test");
1757  fclose($fp);
1758 
1759  if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1760  {
1761  $curDir = getcwd();
1762  chdir(ILIAS_ABSOLUTE_PATH);
1763 
1764  $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1765 
1766  exec($zipCmd);
1767 
1768  chdir($curDir);
1769 
1770  }
1771 
1772  // check wether zip generated test file or not
1773  if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1774  {
1775  unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1776  return true;
1777  }
1778  else
1779  {
1780  unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1781  return false;
1782  }
1783 */
1784  }
1785 
1786 
1793  function testUnzip ($a_unzip_path)
1794  {
1795  if (trim($a_unzip_path) == "")
1796  {
1797  return "no_path_unzip";
1798  }
1799  if (!is_file($a_unzip_path))
1800  {
1801  return "check_failed_unzip";
1802  }
1803 
1804  return "";
1805 /*
1806  $curDir = getcwd();
1807 
1808  chdir(ILIAS_ABSOLUTE_PATH);
1809 
1810  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1811  {
1812  $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1813  exec($unzipCmd);
1814  }
1815 
1816  chdir($curDir);
1817 
1818  // check wether unzip extracted the test file or not
1819  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1820  {
1821  unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1822 
1823  return true;
1824  }
1825  else
1826  {
1827  return false;
1828  }
1829 */
1830  }
1831 
1838  function testHtmldoc($a_htmldoc_path)
1839  {
1840  // java is optional, so empty path is ok
1841  if (trim($a_htmldoc_path) == "")
1842  {
1843  return "";
1844  }
1845 
1846  if (!is_file($a_htmldoc_path))
1847  {
1848  return "check_failed_htmldoc";
1849  }
1850 
1851  return "";
1852 
1853 
1854  $curDir = getcwd();
1855 
1856  chdir(ILIAS_ABSOLUTE_PATH);
1857 
1858  $html = "<html><head><title></title></head><body><p>test</p></body></html>";
1859 
1860  $html_file = "htmldoc_test_file.html";
1861 
1862  $fp = fopen( $html_file ,"wb");
1863  fwrite($fp, $html);
1864  fclose($fp);
1865 
1866  $htmldoc = $a_htmldoc_path." ";
1867  $htmldoc .= "--no-toc ";
1868  $htmldoc .= "--no-jpeg ";
1869  $htmldoc .= "--webpage ";
1870  $htmldoc .= "--outfile htmldoc_test_file.pdf ";
1871  $htmldoc .= "--bodyfont Arial ";
1872  $htmldoc .= "--charset iso-8859-15 ";
1873  $htmldoc .= "--color ";
1874  $htmldoc .= "--size A4 "; // --landscape
1875  $htmldoc .= "--format pdf ";
1876  $htmldoc .= "--footer ... ";
1877  $htmldoc .= "--header ... ";
1878  $htmldoc .= "--left 60 ";
1879  // $htmldoc .= "--right 200 ";
1880  $htmldoc .= $html_file;
1881  exec($htmldoc);
1882 
1883  unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
1884 
1885  chdir($curDir);
1886 
1887  if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
1888  {
1889  unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
1890  return true;
1891  }
1892  else
1893  {
1894  return false;
1895  }
1896  }
1897 
1898 
1905  function unzip($a_file, $overwrite = false)
1906  {
1907  //global $ilias;
1908 
1909  $pathinfo = pathinfo($a_file);
1910  $dir = $pathinfo["dirname"];
1911  $file = $pathinfo["basename"];
1912 
1913  // unzip
1914  $cdir = getcwd();
1915  chdir($dir);
1916  $unzip = $this->ini->readVariable("tools","unzip");
1917  $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
1918  exec($unzipcmd, $arr);
1919  $zdirs = array();
1920 
1921  foreach($arr as $line)
1922  {
1923  if(is_int(strpos($line, "/")))
1924  {
1925  $zdir = substr($line, 0, strrpos($line, "/"));
1926  $nr = substr_count($zdir, "/");
1927  //echo $zdir." ".$nr."<br>";
1928  while ($zdir != "")
1929  {
1930  $nr = substr_count($zdir, "/");
1931  $zdirs[$zdir] = $nr; // collect directories
1932  //echo $dir." ".$nr."<br>";
1933  $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1934  }
1935  }
1936  }
1937 
1938  asort($zdirs);
1939 
1940  foreach($zdirs as $zdir => $nr) // create directories
1941  {
1942  ilUtil::createDirectory($zdir);
1943  }
1944 
1945  // real unzip
1946  if ($overvwrite)
1947  {
1948  $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
1949  }
1950  else
1951  {
1952  $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
1953  }
1954  exec($unzipcmd);
1955 
1956  chdir($cdir);
1957  }
1958 
1964  function setSessionSettings($session_settings)
1965  {
1966  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1967 
1968  $db = $this->client->getDB();
1969 
1970  $setting_fields = ilSessionControl::getSettingFields();
1971 
1972  $i = 0;
1973  foreach($setting_fields as $field)
1974  {
1975  if( isset($session_settings[$field]) )
1976  {
1977  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1978  $res = $db->queryF($query,
1979  array('text', 'text'), array('common', $field));
1980 
1981  $row = array();
1982  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) break;
1983 
1984  if( count($row) > 0 )
1985  {
1986  $db->update(
1987  'settings',
1988  array(
1989  'value' => array('text', $session_settings[$field])
1990  ),
1991  array(
1992  'module' => array('text', 'common'),
1993  'keyword' => array('text', $field)
1994  )
1995  );
1996  }
1997  else
1998  {
1999  $db->insert(
2000  'settings',
2001  array(
2002  'module' => array('text', 'common'),
2003  'keyword' => array('text', $field),
2004  'value' => array('text', $session_settings[$field])
2005  )
2006  );
2007  }
2008 
2009  $i++;
2010  }
2011  }
2012 
2013  if($i < 4) $message = $this->lng->txt("session_settings_not_saved");
2014  else $message = $this->lng->txt("settings_saved");
2015 
2016  ilUtil::sendInfo($message);
2017  }
2018 
2025  {
2026  require_once('Services/Authentication/classes/class.ilSessionControl.php');
2027 
2028  $db = $this->client->getDB();
2029 
2030  $setting_fields = ilSessionControl::getSettingFields();
2031 
2032  $query = "SELECT * FROM settings WHERE module = %s " .
2033  "AND ".$db->in('keyword', $setting_fields, false, 'text');
2034 
2035  $res = $db->queryF($query, array('text'), array('common'));
2036 
2037  $session_settings = array();
2038  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
2039  {
2040  $session_settings[$row['keyword']] = $row['value'];
2041  }
2042 
2043  foreach( $setting_fields as $field )
2044  {
2045  if( !isset($session_settings[$field]) )
2046  {
2047  $value = 1;
2048 
2049  switch($field)
2050  {
2051  case 'session_max_count':
2052 
2054  break;
2055 
2056  case 'session_min_idle':
2057 
2059  break;
2060 
2061  case 'session_max_idle':
2062 
2064  break;
2065 
2066  case 'session_max_idle_after_first_request':
2067 
2069  break;
2070 
2071  case 'session_allow_client_maintenance':
2072 
2074  break;
2075  }
2076 
2077  $session_settings[$field] = $value;
2078  }
2079  }
2080 
2081  return $session_settings;
2082  }
2083 
2089  function cloneFromSource($source_id)
2090  {
2091  // Getting source and targets
2092  $source = new ilClient($source_id, $this->db_connections);
2093  $source->init();
2094  $target = $this->client;
2095 
2096  // ************************************************
2097  // ** COPY FILES
2098 
2099  // Cleaning up datadir
2100  if (! ilUtil::delDir($target->getDataDir())) {
2101  $this->error = "Could not delete data dir $target->getDataDir()";
2102  //return false;
2103  }
2104 
2105  // Create empty datadir
2106  if (!ilUtil::makeDir($target->getDataDir()))
2107  {
2108  $this->error = "could_not_create_base_data_dir :".$target->getDataDir();
2109  return false;
2110  }
2111 
2112  // Copying datadir
2113  if (! ilUtil::rCopy($source->getDataDir(),$target->getDataDir())) {
2114  $this->error = "clone_datadircopyfail";
2115  $target->ini->write();
2116  return false;
2117  }
2118 
2119  // Cleaning up Webspacedir
2120  if (! ilUtil::delDir($target->getWebspaceDir())) {
2121  $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
2122  //return false;
2123  }
2124 
2125  // Create empty Webspacedir
2126  if (!ilUtil::makeDir($target->getWebspaceDir()))
2127  {
2128  $this->error = "could_not_create_base_webspace_dir :".$target->getWebspaceDir();
2129  return false;
2130  }
2131 
2132  // Copying Webspacedir
2133  if (! ilUtil::rCopy($source->getWebspaceDir(),$target->getWebspaceDir())) {
2134  $this->error = "clone_websipacedircopyfail";
2135  $target->ini->write();
2136  return false;
2137  }
2138 
2139  // Restore ini file
2140  $target->ini->write();
2141 
2142  // ************************************************
2143  // ** COPY DATABASE
2144 
2145  $source->connect();
2146  if (!$source->db)
2147  {
2148  $this->error = "Source database connection failed.";
2149  return false;
2150  }
2151 
2152  $target->connect();
2153  if (!$target->db)
2154  {
2155  $this->error = "Target database connection failed.";
2156  return false;
2157  }
2158 
2159  $source->connect();
2160  $srcTables = $source->db->query("SHOW TABLES");
2161  $target->connect();
2162 
2163  // drop all tables of the target db
2164  $tarTables = $target->db->query("SHOW TABLES");
2165  foreach($tarTables->fetchAll() as $cTable)
2166  {
2167  $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2168  }
2169 
2170  foreach($srcTables->fetchAll() as $cTable){
2171  $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2172  $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
2173  if(!$create) {
2174  $error = true;
2175  }
2176  $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM ".$source->getDbName().".".$cTable[0]);
2177  }
2178  return true;
2179  }
2187  public function printProxyStatus($client)
2188  {
2189  require_once './Services/Http/exceptions/class.ilProxyException.php';
2190  $settings = $client->getAllSettings();
2191 
2192  if((bool)$settings['proxy_status'] == true)
2193  {
2194  try
2195  {
2201  require_once 'Services/PEAR/lib/Net/Socket.php';
2202 
2203  $socket = new Net_Socket();
2204  $socket->setErrorHandling(PEAR_ERROR_RETURN);
2205  $response = $socket->connect($settings['proxy_host'], $settings['proxy_port']);
2206  if(!is_bool($response))
2207  {
2208  global $lng;
2209  throw new ilProxyException(strlen($response) ? $response : $lng->txt('proxy_not_connectable'));
2210  }
2211 
2212  ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
2213 
2214  }
2215  catch(ilProxyException $e)
2216  {
2217  ilUtil::sendFailure($this->lng->txt('proxy_pear_net_socket_error').': '.$e->getMessage());
2218  }
2219  }
2220 
2221  }
2222 
2223  public function saveProxySettings($proxy_settings)
2224  {
2225  $db = $this->client->getDB();
2226  $proxy_fields = array('proxy_status','proxy_host','proxy_port');
2227 
2228  foreach($proxy_fields as $field)
2229  {
2230  if( isset($proxy_settings[$field]) )
2231  {
2232  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
2233  $res = $db->queryF($query,
2234  array('text', 'text'), array('common', $field));
2235 
2236  $row = array();
2237  while($row = $db->fetchAssoc($res)) break;
2238 
2239  if( count($row) > 0 )
2240  {
2241  $db->update(
2242  'settings',
2243  array(
2244  'value' => array('text', $proxy_settings[$field])
2245  ),
2246  array(
2247  'module' => array('text', 'common'),
2248  'keyword' => array('text', $field)
2249  )
2250  );
2251  }
2252  else
2253  {
2254  $db->insert(
2255  'settings',
2256  array(
2257  'module' => array('text', 'common'),
2258  'keyword' => array('text', $field),
2259  'value' => array('text', $proxy_settings[$field])
2260  )
2261  );
2262  }
2263  }
2264  }
2265  }
2266 
2267 
2268 } // END class.ilSetup
2269 
2271 {
2272  public function current()
2273  {
2274  return parent::getFileName();
2275  }
2276 
2277  public function valid()
2278  {
2279  if(!parent::valid())
2280  {
2281  return false;
2282  }
2283  if($this->isFile() and substr(parent::getFileName(),-4) == '.xml')
2284  {
2285  return false;
2286  }
2287  if($this->isFile() and substr(parent::getFileName(),-8) != '_inserts')
2288  {
2289  return true;
2290  }
2291  parent::next();
2292  return $this->valid();
2293  }
2294 
2295  public function rewind()
2296  {
2297  parent::rewind();
2298  }
2299 }
2300 ?>