ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSetup.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-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 
117 
121  public $client;
122 
123 
127  public function setClient($a_cl) {
128  $this->client = $a_cl;
129  }
130 
131 
135  public function getClient() {
136  return $this->client;
137  }
138 
144  function init()
145  {
146  // load data from setup.ini file
147  $this->ini = new ilIniFile($this->ini_file_path);
148 
149  if (!$this->ini->read())
150  {
151  $this->ini->GROUPS = parse_ini_file($this->setup_defaults,true);
152  $this->error = get_class($this).": ".$this->ini->getError();
153  return false;
154  }
155 
156  $this->setup_password = $this->ini->readVariable("setup","pass");
157  $this->default_client = $this->ini->readVariable("clients","default");
158 
159  define("ILIAS_DATA_DIR",$this->ini->readVariable("clients","datadir"));
160  define("ILIAS_WEB_DIR",$this->ini->readVariable("clients","path"));
161 
162  return true;
163  }
164 
169  function saveNewClient()
170  {
171  // save client id to session
172  $_SESSION["ClientId"] = $this->client->getId();
173 
174  // create client
175  if (!$this->client->create())
176  {
177  $this->error = $this->client->getError();
178  return false;
179  }
180 
181  //everything okay
182  $this->ini_client_exists = true;
183 
184  return true;
185  }
186 
192  function updateNewClient($a_old_client_id)
193  {
194  return true;
195  //var_dump("<pre>",$this->client,"</pre>");exit;
196 
197  if ($a_old_client_id != $this->client->getId())
198  {
199  // check for existing client dir
200  if (file_exists(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->client->getId()))
201  {
202  $this->raiseError($this->lng->txt("client_id_already_exists"),$this->error_obj->MESSAGE);
203  }
204 
205  if (!$this->saveNewClient())
206  {
207  $this->raiseError($this->lng->txt("save_error"),$this->error_obj->MESSAGE);
208  }
209 
210  ilUtil::delDir(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$a_old_client_id);
211  ilUtil::delDir(ILIAS_DATA_DIR."/".$a_old_client_id);
212  }
213 
214  //everything okay
215  $this->ini_client_exists = true;
216 
217  return true;
218  }
219 
224  function createDatabase($a_collation = "")
225  {
226  if ($this->client->checkDatabaseExists())
227  {
228  $this->error = $this->lng->txt("database_exists");
229  return false;
230  }
231 
232  $this->client->getDB()->connectHost(true);
233 
234  //create database
235  $db = $this->client->getDB();
236  if (MDB2::isError($db))
237  {
238  $this->error = "connection_failed";
239  return false;
240  }
241 
242  $r = $db->createDatabase($this->client->getdbName(),
243  "utf8", $a_collation);
244 
245  if (MDB2::isError($r))
246  {
247  $this->error = "create_database_failed";
248  return false;
249  }
250 
251  //database is created, now disconnect and reconnect
252  $db->disconnect();
253 
254  $this->client->db_exists = true;
255  return true;
256  }
257 
262  function installDatabase()
263  {
264 /* if (!$this->client->checkDatabaseHost())
265  {
266  $this->error = "no_connection_to_host";
267  return false;
268  }*/
269 
270  if (!$this->client->connect())
271  {
272  return false;
273  }
274 
275  //take sql dump an put it in
276  if ($this->readDump($this->client->db, $this->SQL_FILE))
277  {
278  $this->client->db_installed = true;
279  return true;
280  }
281  else
282  {
283  return false;
284  }
285  }
286 
287  function getline( $fp, $delim )
288  {
289  $result = "";
290  while( !feof( $fp ) )
291  {
292  $tmp = fgetc( $fp );
293  if( $tmp == $delim )
294  return $result;
295  $result .= $tmp;
296  }
297  return $result;
298  }
299 
306  function readDump($db, $file)
307  {
308  // mysql (old procedure)
309  if ($db->getDBType() == "mysql")
310  {
311  $fp = fopen($file, 'r');
312 
313  while(!feof($fp))
314  {
315  //$line = trim(fgets($fp, 200000));
316  $line = trim($this->getline($fp, "\n"));
317 
318  if ($line != "" && substr($line,0,1)!="#"
319  && substr($line,0,1)!="-")
320  {
321  //take line per line, until last char is ";"
322  if (substr($line,-1)==";")
323  {
324  //query is complete
325  $q .= " ".substr($line,0,-1);
326  $r = $db->query($q);
327 
328  if ($db->getErrorNo() > 0)
329  {
330  echo "<br />ERROR: ".$db->getError().
331  "<br />SQL: $q";
332  return false;
333  }
334  unset($q);
335  unset($line);
336  } //if
337  else
338  {
339  $q .= " ".$line;
340  } //else
341  } //if
342  } //for
343 
344  fclose($fp);
345  }
346 
347  #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
348  if (in_array($db->getDBType(), array("oracle", "postgres", "innodb")))
349  {
350  if(@is_dir('./setup/sql/ilDBTemplate'))
351  {
352  include_once './Services/Database/classes/class.ilArrayTableDataParser.php';
353  include_once './Services/Xml/exceptions/class.ilSaxParserException.php';
354  $reader = new tmpDirectoyIterator('./setup/sql/ilDBTemplate');
355  foreach($reader as $file)
356  {
357  eval(file_get_contents('./setup/sql/ilDBTemplate/'.$file));
358  try
359  {
360  $parser = new ilArrayTableDataParser('./setup/sql/ilDBTemplate/'.$file.'_inserts');
361  #$parser = new ilSimpleXMLTableDataParser('./setup/sql/ilDBTemplate/'.$file.'.xml');
362  $parser->startParsing();
363  #echo 'Table: '.$file.', memory: '.memory_get_peak_usage().' peak: '.memory_get_peak_usage().'<br />';flush();
364 
365  }
366  catch(ilSaxParserException $e)
367  {
368  die($e);
369  }
370  }
371  }
372  else
373  {
374  include_once("./setup/sql/ilDBTemplate.php");
375  setupILIASDatabase();
376  }
377  }
378  #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
379  return true;
380  }
381 
382 
388  {
389  $a = @file_exists($this->INI_FILE);
390  return $a;
391  }
392 
398  function checkWritable()
399  {
400  clearstatcache();
401  if (is_writable("."))
402  {
403  $arr["status"] = true;
404  //$cdir = getcwd();
405  //chdir("..");
406  $arr["comment"] = getcwd();
407  //chdir($cdir);
408  }
409  else
410  {
411  $arr["status"] = false;
412  $arr["comment"] = $this->lng->txt("pre_folder_write_error");
413  //$cdir = getcwd();
414  //chdir("..");
415  $arr["comment"] = getcwd().": ".$arr["comment"];
416  //chdir($cdir);
417  }
418 
419  return $arr;
420  }
421 
427  function checkCreatable($a_dir = ".")
428  {
429  clearstatcache();
430  if (@mkdir($a_dir."/crst879dldsk9d", 0774))
431  {
432  $arr["status"] = true;
433  $arr["comment"] = "";
434 
435  @rmdir($a_dir."/crst879dldsk9d");
436  }
437  else
438  {
439  $arr["status"] = false;
440  //$cdir = getcwd();
441  //chdir("..");
442  $arr["comment"] = getcwd().": ".$this->lng->txt("pre_folder_create_error");
443  //chdir($cdir);
444  }
445 
446  return $arr;
447  }
448 
454  {
455  global $sess;
456 
457  if ($sess->usesCookies)
458  {
459  $arr["status"] = true;
460  $arr["comment"] = "";
461  }
462  else
463  {
464  $arr["status"] = false;
465  $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
466  }
467 
468  return $arr;
469  }
470 
475  function checkPHPVersion()
476  {
477  $version = PHP_VERSION;
478 
479  $arr["status"] = true;
480  $arr["comment"] = "PHP ".$version;
481  if (version_compare($version, '5.3.0', '<'))
482  {
483  $arr["status"] = false;
484  $arr["comment"] = "PHP ".$version.". ".$this->lng->txt("pre_php_version_too_low");
485  }
486 
487  return $arr;
488  }
489 
494  function checkMySQL()
495  {
496  global $ilDB;
497 
498  if (function_exists("mysql_query"))
499  {
500  $arr["status"] = true;
501  $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
502  }
503  else
504  {
505  $arr["status"] = false;
506  $arr["comment"] = $this->lng->txt("pre_mysql_missing");
507  }
508 
509  return $arr;
510  }
511 
516  function checkAuth()
517  {
518  if ($_SESSION["auth"] === true && $_SESSION["auth_path"] == ILIAS_HTTP_PATH)
519  {
520  return true;
521  }
522 
523  return false;
524  }
525 
526 
531  function checkDom()
532  {
533  global $ilDB;
534 
535  if (class_exists("DOMDocument"))
536  {
537  $arr["status"] = true;
538  }
539  else
540  {
541  $arr["status"] = false;
542  $arr["comment"] = $this->lng->txt("pre_dom_missing");
543  }
544 
545  return $arr;
546  }
547 
552  function checkXsl()
553  {
554  global $ilDB;
555 
556  if (class_exists("XSLTProcessor"))
557  {
558  $arr["status"] = true;
559  }
560  else
561  {
562  $arr["status"] = false;
563  $arr["comment"] = sprintf($this->lng->txt("pre_xsl_missing"),
564  "http://php.net/manual/en/book.xsl.php");
565  }
566 
567  return $arr;
568  }
569 
574  function checkGd()
575  {
576  global $ilDB;
577 
578  if (function_exists("imagefill") && function_exists("imagecolorallocate"))
579  {
580  $arr["status"] = true;
581  }
582  else
583  {
584  $arr["status"] = false;
585  $arr["comment"] = sprintf($this->lng->txt("pre_gd_missing"),
586  "http://php.net/manual/en/book.image.php");
587  }
588 
589  return $arr;
590  }
591 
596  function checkMemoryLimit()
597  {
598  global $ilDB;
599 
600  $limit = ini_get("memory_limit");
601 
602  $limit_ok = true;
603  if (is_int(strpos($limit, "M")))
604  {
605  $limit_n = (int) $limit;
606  if ($limit_n < 40)
607  {
608  $limit_ok = false;
609  }
610  }
611 
612  if ($limit_ok)
613  {
614  $arr["status"] = true;
615  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_recommend");
616  }
617  else
618  {
619  $arr["status"] = false;
620  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_too_low");
621  }
622 
623  return $arr;
624  }
625 
626 
630  protected function checkOpcacheSettings() {
631  $arr = array();
632  $load_comments = ini_get("opcache.load_comments");
633  if($load_comments == 1) {
634  $arr["status"] = true;
635  } else {
636  $arr["status"] = false;
637  $arr["comment"] = $this->lng->txt("pre_opcache_comments");
638  }
639 
640  return $arr;
641  }
642 
651  {
652  $a = array();
653  $a["php"] = $this->checkPHPVersion();
654 // $a["mysql"] = $this->checkMySQL();
655  $a["root"] = $this->checkWritable();
656  $a["folder_create"] = $this->checkCreatable();
657  $a["cookies_enabled"] = $this->checkCookiesEnabled();
658  $a["dom"] = $this->checkDom();
659  $a["xsl"] = $this->checkXsl();
660  $a["gd"] = $this->checkGd();
661  $a["memory"] = $this->checkMemoryLimit();
662 // var_dump(ini_get('opcache.enable') ); // FSX
663  if ($this->hasOpCacheEnabled()) {
664  $a["load_comments"] = $this->checkOpcacheSettings();
665  }
666 
667  return $a;
668  }
669 
675  {
676  $this->preliminaries_result = $this->queryPreliminaries();
677 
678  foreach ($this->preliminaries_result as $val)
679  {
680  if ($val["status"] === false)
681  {
682  $this->preliminaries = false;
683  return false;
684  }
685  }
686 
687  return true;
688  }
689 
694  function getPassword ()
695  {
696  return $this->ini->readVariable("setup","pass");
697  }
698 
704  function setPassword ($a_password)
705  {
706  $this->ini->setVariable("setup","pass",md5($a_password));
707 
708  if ($this->ini->write() == false)
709  {
710  $this->error = $this->ini->getError();
711  return false;
712  }
713 
714  return true;
715  }
716 
722  function loginAsClient($a_auth_data)
723  {
724  global $ilDB;
725 
726  if (empty($a_auth_data["client_id"]))
727  {
728  $this->error = "no_client_id";
729  return false;
730  }
731 
732  if (empty($a_auth_data["username"]))
733  {
734  $this->error = "no_username";
735  return false;
736  }
737 
738  if (empty($a_auth_data["password"]))
739  {
740  $this->error = "no_password";
741  return false;
742  }
743 
744  if (!$this->newClient($a_auth_data["client_id"]))
745  {
746  $this->error = "unknown_client_id";
747  unset($this->client);
748  return false;
749  }
750 
751  if (!$this->client->db_exists)
752  {
753  $this->error = "no_db_connect_consult_admin";
754  unset($this->client);
755  return false;
756  }
757 
758  $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = ".
759  $this->client->db->quote('system_role_id','text'));
760  $r1 = $this->client->db->fetchAssoc($s1);
761  $system_role_id = $r1["value"];
762 
763  $add_usrfields = '';
764  if($this->client->db->tableColumnExists('usr_data', 'passwd_enc_type'))
765  {
766  $add_usrfields .= ' , usr_data.passwd_enc_type, usr_data.passwd_salt ';
767  }
768  $q = "SELECT usr_data.usr_id, usr_data.passwd $add_usrfields " .
769  "FROM usr_data " .
770  "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id " .
771  "WHERE rbac_ua.rol_id = " . $this->client->db->quote((int)$system_role_id, 'integer') . " " .
772  "AND usr_data.login=" . $this->client->db->quote($a_auth_data["username"], 'text');
773  $r = $this->client->db->query($q);
774  if(!$this->client->db->numRows($r))
775  {
776  $this->error = 'login_invalid';
777  return false;
778  }
779 
780  $data = $this->client->db->fetchAssoc($r);
781 
782  global $ilClientIniFile;
783 
784  $ilClientIniFile = $this->client->ini;
785 
786  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
787  $crypt_type = ilUserPasswordManager::getInstance()->getEncoderName();
788  if(strlen($add_usrfields) && ilUserPasswordManager::getInstance()->isEncodingTypeSupported($crypt_type))
789  {
790  require_once 'setup/classes/class.ilObjSetupUser.php';
791  $user = new ilObjSetupUser();
792  $user->setPasswd($data['passwd'], IL_PASSWD_CRYPTED);
793  $user->setPasswordEncodingType($data['passwd_enc_type']);
794  $user->setPasswordSalt($data['passwd_salt']);
795 
796  $password_valid = ilUserPasswordManager::getInstance()->verifyPassword($user, $a_auth_data['password']);
797  }
798  else
799  {
800  $password_valid = $data['passwd'] == md5($a_auth_data['password']);
801  }
802 
803  if($password_valid)
804  {
805  // all checks passed -> user valid
806  $_SESSION['auth'] = true;
807  $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
808  $_SESSION['access_mode'] = 'client';
809  $_SESSION['ClientId'] = $this->client->getId();
810  return true;
811  }
812  else
813  {
814  $this->error = 'login_invalid';
815  return false;
816  }
817  }
818 
824  function loginAsAdmin($a_password)
825  {
826  $a_password = md5($a_password);
827 
828  if ($this->ini->readVariable("setup","pass") == $a_password)
829  {
830  $_SESSION["auth"] = true;
831  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
832  $_SESSION["access_mode"] = "admin";
833  return true;
834  }
835 
836  return false;
837  }
838 
844  function newClient($a_client_id = 0)
845  {
846  if (!$this->isInstalled())
847  {
848  return false;
849  }
850 
851  $this->client = new ilClient($a_client_id, $this->db_connections);
852 
853  if (!$this->client->init())
854  {
855 //echo "<br>noclientinit";
856  $this->error = get_class($this).": ".$this->client->getError();
857  $_SESSION["ClientId"] = "";
858  return false;
859  }
860 
861  $_SESSION["ClientId"] = $a_client_id;
862 
863  return true;
864  }
865 
871  function getStatus ($client = 0)
872  {
873  if (!is_object($client))
874  {
875  if ($this->ini_client_exists)
876  {
878  }
879  else
880  {
881  $client = new ilClient(0, $this->db_connections);
882  }
883  }
884 
885  $status = array();
886  $status["ini"] = $this->checkClientIni($client); // check this one
887  $status["db"] = $this->checkClientDatabase($client);
888  if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
889  {
890  //$status["sess"]["status"] = false;
891  //$status["sess"]["comment"] = $status["db"]["comment"];
892  $status["lang"]["status"] = false;
893  $status["lang"]["comment"] = $status["db"]["comment"];
894  $status["contact"]["status"] = false;
895  $status["contact"]["comment"] = $status["db"]["comment"];
896 
897  $status["proxy"]["status"] = false;
898  $status["proxy"]["comment"] = $status["db"]["comment"];
899 
900  $status["passwd"]["status"] = false;
901  $status["passwd"]["comment"] = $status["db"]["comment"];
902 
903  $status["nic"]["status"] = false;
904  $status["nic"]["comment"] = $status["db"]["comment"];
905  }
906  else
907  {
908  //$status["sess"] = $this->checkClientSessionSettings($client);
909  $status["lang"] = $this->checkClientLanguages($client);
910  $status["contact"] = $this->checkClientContact($client);
911  $status["proxy"] = $this->checkClientProxySettings($client);
912  $status["passwd"] = $this->checkClientPasswordSettings($client);
913  $status["nic"] = $this->checkClientNIC($client);
914  $status["finish"] = $this->checkFinish($client);
915  $status["access"] = $this->checkAccess($client);
916  }
917 
918  //return value
919  return $status;
920  }
921 
927  function checkFinish(&$client)
928  {
929  if ($client->getSetting("setup_ok"))
930  {
931  $arr["status"] = true;
932  //$arr["comment"] = $this->lng->txt("setup_finished");
933  }
934  else
935  {
936  $arr["status"] = false;
937  $arr["comment"] = $this->lng->txt("setup_not_finished");
938  }
939 
940  return $arr;
941  }
942 
948  function checkAccess(&$client)
949  {
950  if ($client->ini->readVariable("client","access") == "1")
951  {
952  $arr["status"] = true;
953  $arr["comment"] = $this->lng->txt("online");
954  }
955  else
956  {
957  $arr["status"] = false;
958  $arr["comment"] = $this->lng->txt("disabled");
959  }
960 
961  return $arr;
962  }
963 
970  {
971  if (!$arr["status"] = $client->init())
972  {
973  $arr["comment"] = $client->getError();
974  }
975  else
976  {
977  //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
978  }
979 
980  return $arr;
981  }
982 
989  {
990  if (!$arr["status"] = $client->db_exists)
991  {
992  $arr["comment"] = $this->lng->txt("no_database");
993  return $arr;
994  }
995 
996  if (!$arr["status"] = $client->db_installed)
997  {
998  $arr["comment"] = $this->lng->txt("db_not_installed");
999  return $arr;
1000  }
1001 
1002  // TODO: move this to client class!!
1003  $client->setup_ok = (bool) $client->getSetting("setup_ok");
1004 
1005  //$this->lng->setDbHandler($client->db);
1006  include_once "./Services/Database/classes/class.ilDBUpdate.php";
1007  $ilDB = $client->db;
1008  $this->lng->setDbHandler($client->db);
1009  $dbupdate = new ilDBUpdate($client->db);
1010 
1011  if (!$arr["status"] = $dbupdate->getDBVersionStatus())
1012  {
1013  $arr["comment"] = $this->lng->txt("db_needs_update");
1014  $arr["update"] = true;
1015  return $arr;
1016  }
1017  else if ($dbupdate->hotfixAvailable())
1018  {
1019  $arr["status"] = false;
1020  $arr["comment"] = $this->lng->txt("hotfix_available");
1021  $arr["update"] = true;
1022  return $arr;
1023  }
1024  else if ($dbupdate->customUpdatesAvailable())
1025  {
1026  $arr["status"] = false;
1027  $arr["comment"] = $this->lng->txt("custom_updates_available");
1028  $arr["update"] = true;
1029  return $arr;
1030  }
1031 
1032  // check control information
1033 
1034  $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
1035  $crec = $ilDB->fetchAssoc($cset);
1036  if ($crec["cnt"] == 0)
1037  {
1038  $arr["status"] = false;
1039  $arr["comment"] = $this->lng->txt("db_control_structure_missing");
1040  $arr["update"] = true;
1041  return $arr;
1042  }
1043 
1044  //$arr["comment"] = "version ".$dbupdate->getCurrentVersion();
1045  return $arr;
1046  }
1047 
1053  function checkClientSessionSettings(&$client, $a_as_bool = false)
1054  {
1055  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1056 
1057  global $ilDB;
1058  $db = $ilDB;
1059 
1061 
1062  $query = "SELECT keyword, value FROM settings WHERE ".$db->in('keyword', $fields, false, 'text');
1063  $res = $db->query($query);
1064 
1065  $rows = array();
1066  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
1067  {
1068  if( $row['value'] != '' )
1069  $rows[] = $row;
1070  else break;
1071  }
1072 
1073  if (count($rows) != count($fields))
1074  {
1075  if($a_as_bool) return false;
1076  $arr["status"] = false;
1077  $arr["comment"] = $this->lng->txt("session_management_not_configured");
1078  }
1079  else
1080  {
1081  if($a_as_bool) return true;
1082  $arr["status"] = true;
1083  $arr["comment"] = $this->lng->txt("session_management_configured");
1084  }
1085 
1086  return $arr;
1087  }
1088 
1094  {
1095  global $ilDB;
1096  $db = $ilDB;
1097 
1098  $fields = array('proxy_status','proxy_host','proxy_port');
1099 
1100  $query = "SELECT keyword, value FROM settings WHERE ".$db->in('keyword', $fields, false, 'text');
1101  $res = $db->query($query);
1102 
1103  $proxy_settings = array();
1104  $already_saved = false;
1105  while($row = $db->fetchAssoc($res))
1106  {
1107  $already_saved = true;
1108  $proxy_settings[$row['keyword']] = $row['value'];
1109  }
1110 
1111  if(!$already_saved)
1112  {
1113  $arr["status"] = false;
1114  $arr["comment"] = $this->lng->txt("proxy");
1115  $arr["text"] = $this->lng->txt("proxy");
1116  }
1117  else if((bool)$proxy_settings["proxy_status"] == false)
1118  {
1119  $arr["status"] = true;
1120  $arr["comment"] = $this->lng->txt("proxy_disabled");
1121  $arr["text"] = $this->lng->txt("proxy_disabled");
1122  }
1123  else
1124  {
1125  $arr["status"] = true;
1126  $arr["comment"] = $this->lng->txt("proxy_activated_configurated");
1127  $arr["text"] = $this->lng->txt("proxy_activated_configurated");
1128 
1129  }
1130  return $arr;
1131  }
1132 
1139  {
1140  $installed_langs = $this->lng->getInstalledLanguages();
1141 
1142  $count = count($installed_langs);
1143 
1144  if ($count < 1)
1145  {
1146  $arr["status"] = false;
1147  $arr["comment"] = $this->lng->txt("lang_none_installed");
1148  }
1149  else
1150  {
1151  $arr["status"] = true;
1152  //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
1153  }
1154 
1155  return $arr;
1156  }
1157 
1164  {
1165  $arr["status"] = true;
1166  //$arr["comment"] = $this->lng->txt("filled_out");
1167 
1168  $settings = $client->getAllSettings();
1169  $client_name = $client->getName();
1170 
1171  // check required fields
1172  if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
1173  empty($settings["admin_email"]) or empty($client_name))
1174  {
1175  $arr["status"] = false;
1176  $arr["comment"] = $this->lng->txt("missing_data");
1177  }
1178 
1179  // admin email
1180  if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
1181  {
1182  $arr["status"] = false;
1183  $arr["comment"] = $this->lng->txt("email_not_valid");
1184  }
1185 
1186  return $arr;
1187  }
1188 
1195  {
1196  $settings = $client->getAllSettings();
1197 
1198  if (!isset($settings["nic_enabled"]))
1199  {
1200  $arr["status"] = false;
1201  $arr["comment"] = $this->lng->txt("nic_not_disabled");
1202  return $arr;
1203  }
1204 
1205  $arr["status"] = true;
1206 
1207  if ($settings["nic_enabled"] == "-1")
1208  {
1209  $arr["comment"] = $this->lng->txt("nic_reg_failed");
1210  return $arr;
1211  }
1212 
1213  if (!$settings["nic_enabled"])
1214  {
1215  $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1216  }
1217  else
1218  {
1219  $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1220  if ($settings["inst_id"] <= 0)
1221  {
1222  $arr["status"] = false;
1223  }
1224  }
1225 
1226  return $arr;
1227  }
1228 
1233  function isInstalled()
1234  {
1235  return $this->ini_ilias_exists;
1236  }
1237 
1242  function isAuthenticated()
1243  {
1244  return $this->auth;
1245  }
1246 
1251  function isAdmin()
1252  {
1253  return ($this->access_mode == "admin") ? true : false;
1254  }
1255 
1261  function saveMasterSetup($a_formdata)
1262  {
1263  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1264 
1265  if ($a_formdata["chk_datadir_path"] == 1) // mode create dir
1266  {
1267  if (!ilUtil::makeDir($datadir_path))
1268  {
1269  $this->error = "create_datadir_failed";
1270  return false;
1271  }
1272  }
1273 
1274  // create webspace dir if it does not exist
1275  if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1276  {
1277  if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1278  {
1279  $this->error = "create_webdir_failed";
1280  return false;
1281  }
1282  }
1283 
1284  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1285  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1286  $log_file = substr($form_log_path,strlen($log_path)+1);
1287 
1288  $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
1289  $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
1290  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1291  $this->ini->setVariable("clients", "datadir", $datadir_path);
1292  $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
1293  $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
1294  $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
1295  $this->ini->setVariable("tools", "ghostscript", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"])));
1296  $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
1297  $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
1298  //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1299  $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1300  $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1301  $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1302  $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
1303  $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
1304  $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
1305  $this->ini->setVariable("log", "path", $log_path);
1306  $this->ini->setVariable("log", "file", $log_file);
1307  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1308 
1309  $this->ini->setVariable("https","auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1310  $this->ini->setVariable("https","auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1311  $this->ini->setVariable("https","auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1312 
1313  if (!$this->ini->write())
1314  {
1315  $this->error = get_class($this).": ".$this->ini->getError();
1316  return false;
1317  }
1318 
1319  // everything is fine. so we authenticate the user and set access mode to 'admin'
1320  $_SESSION["auth"] = true;
1321  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1322  $_SESSION["access_mode"] = "admin";
1323 
1324  return true;
1325  }
1326 
1332  function updateMasterSettings($a_formdata)
1333  {
1334  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1335  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1336  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1337  $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1338  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1339  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1340  //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1341  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1342  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1343  $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
1344  $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1345  $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
1346  $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
1347 
1348  $this->ini->setVariable("tools", "convert", $convert_path);
1349  $this->ini->setVariable("tools", "zip", $zip_path);
1350  $this->ini->setVariable("tools", "unzip", $unzip_path);
1351  $this->ini->setVariable("tools", "ghostscript", $ghostscript_path);
1352  $this->ini->setVariable("tools", "java", $java_path);
1353  $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
1354  //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1355  $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1356  $this->ini->setVariable("tools", "latex", $latex_url);
1357  $this->ini->setVariable("tools", "fop", $fop_path);
1358  $this->ini->setVariable("tools", "vscantype", $scan_type);
1359  $this->ini->setVariable("tools", "scancommand", $scan_command);
1360  $this->ini->setVariable("tools", "cleancommand", $clean_command);
1361 
1362  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1363  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1364  $log_file = substr($form_log_path,strlen($log_path)+1);
1365 
1366  $this->ini->setVariable("log", "path", $log_path);
1367  $this->ini->setVariable("log", "file", $log_file);
1368  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1369  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1370 
1371  $this->ini->setVariable("https","auto_https_detect_enabled",($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1372  $this->ini->setVariable("https","auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1373  $this->ini->setVariable("https","auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1374 
1375  if (!$this->ini->write())
1376  {
1377  $this->error = get_class($this).": ".$this->ini->getError();
1378  return false;
1379  }
1380 
1381  return true;
1382  }
1383 
1389  function checkToolsSetup($a_formdata)
1390  {
1391  // convert path
1392  if (!isset($a_formdata["chk_convert_path"]))
1393  {
1394  // convert backslashes to forwardslashes
1395  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1396 
1397  if (($err = $this->testConvert($convert_path)) != "")
1398  {
1399  $this->error = $err;
1400  return false;
1401  }
1402  }
1403 
1404  // zip path
1405  if (!isset($a_formdata["chk_zip_path"]))
1406  {
1407  // convert backslashes to forwardslashes
1408  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1409 
1410  if (empty($zip_path))
1411  {
1412  $this->error = "no_path_zip";
1413  return false;
1414  }
1415 
1416  if (!$this->testZip($zip_path))
1417  {
1418  $this->error = "check_failed_zip";
1419  return false;
1420  }
1421  }
1422 
1423  // unzip path
1424  if (!isset($a_formdata["chk_unzip_path"]))
1425  {
1426  // convert backslashes to forwardslashes
1427  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1428 
1429  if (empty($unzip_path))
1430  {
1431  $this->error = "no_path_unzip";
1432  return false;
1433  }
1434 
1435  if (!$this->testUnzip($unzip_path))
1436  {
1437  $this->error = "check_failed_unzip";
1438  return false;
1439  }
1440  }
1441 
1442  // ghostscript path
1443  if (!isset($a_formdata["chk_ghostscript_path"]))
1444  {
1445  // convert backslashes to forwardslashes
1446  $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1447 
1448  if (($err = $this->testGhostscript($ghostscript_path)) != "")
1449  {
1450  $this->error = $err;
1451  return false;
1452  }
1453  }
1454 
1455  // java path
1456  if (!isset($a_formdata["chk_java_path"]))
1457  {
1458  // convert backslashes to forwardslashes
1459  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1460 
1461  if (empty($java_path))
1462  {
1463  $this->error = "no_path_java";
1464  return false;
1465  }
1466 
1467  if (!$this->testJava($java_path))
1468  {
1469  $this->error = "check_failed_java";
1470  return false;
1471  }
1472  }
1473 
1474  // htmldoc path
1475  if (!isset($a_formdata["chk_htmldoc_path"]))
1476  {
1477  // convert backslashes to forwardslashes
1478  $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1479 
1480  if (empty($htmldoc_path))
1481  {
1482  $this->error = "no_path_htmldoc";
1483  return false;
1484  }
1485 
1486  if (!$this->testHtmldoc($htmldoc_path))
1487  {
1488  $this->error = "check_failed_htmldoc";
1489  return false;
1490  }
1491  }
1492  /*if (!isset($a_formdata["chk_mkisofs_path"]))
1493  {
1494  // convert backslashes to forwardslashes
1495  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1496 
1497  if (empty($mkisofs_path))
1498  {
1499  $this->error = "no_path_mkisofs";
1500  return false;
1501  }
1502 
1503  if (!$this->testHtmldoc($mkisofs_path))
1504  {
1505  $this->error = "check_failed_mkisofs";
1506  return false;
1507  }
1508  }*/
1509 
1510  if (!isset($a_formdata["chk_ffmpeg_path"]))
1511  {
1512  // convert backslashes to forwardslashes
1513  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1514 
1515  if (empty($ffmpeg_path))
1516  {
1517  $this->error = "no_path_ffmpeg";
1518  return false;
1519  }
1520 
1521  if (!$this->testFFMpeg($ffmpeg_path))
1522  {
1523  $this->error = "check_failed_ffmpeg";
1524  return false;
1525  }
1526  }
1527 
1528  // latex url
1529  if (!isset($a_formdata["chk_latex_url"]))
1530  {
1531  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1532  if (empty($latex_url))
1533  {
1534  $this->error = "no_latex_url";
1535  return false;
1536  }
1537 
1538  if (!$this->testLatex($latex_url))
1539  {
1540  $this->error = "check_failed_latex";
1541  return false;
1542  }
1543  }
1544 
1545  return true;
1546  }
1547 
1553  function checkDataDirSetup($a_formdata)
1554  {
1555  // remove trailing slash & convert backslashes to forwardslashes
1556  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1557 
1558  if (empty($datadir_path))
1559  {
1560  $this->error = "no_path_datadir";
1561  return false;
1562  }
1563 
1564  $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1565 
1566  // datadir may not point to webspace dir or to any place under webspace_dir
1567  if (strpos($datadir_path,$webspace_dir) !== false)
1568  {
1569  $this->error = "datadir_webspacedir_match";
1570  return false;
1571  }
1572 
1573  // create dir
1574  if ($a_formdata["chk_datadir_path"] == 1)
1575  {
1576  $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1577  $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
1578 
1579  if (is_writable($datadir_path))
1580  {
1581  $this->error = "dir_exists_create";
1582  return false;
1583  }
1584 
1585  if (!is_writable($dir_to_check))
1586  {
1587  $this->error = "cannot_create_datadir_no_write_access";
1588  return false;
1589  }
1590  }
1591  else // check set target dir
1592  {
1593  if (!is_writable($datadir_path))
1594  {
1595  $this->error = "cannot_create_datadir_no_write_access";
1596  return false;
1597  }
1598  }
1599 
1600  return true;
1601  }
1602 
1608  function checkPasswordSetup($a_formdata)
1609  {
1610  if (!$a_formdata["setup_pass"])
1611  {
1612  $this->error = "no_setup_pass_given";
1613  return false;
1614  }
1615 
1616  if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
1617  {
1618  $this->error = "pass_does_not_match";
1619  return false;
1620  }
1621 
1622  return true;
1623  }
1624 
1630  function checkLogSetup($a_formdata)
1631  {
1632  // log path
1633  if (!$a_formdata["chk_log_status"])
1634  {
1635  // remove trailing slash & convert backslashes to forwardslashes
1636  $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1637 
1638  if (empty($log_path))
1639  {
1640  $this->error = "no_path_log";
1641  return false;
1642  }
1643 
1644  if (!@touch($log_path))
1645  {
1646  $this->error = "could_not_create_logfile";
1647  return false;
1648  }
1649  }
1650 
1651  return true;
1652  }
1653 
1658  function getError()
1659  {
1660  if (empty($this->error))
1661  {
1662  return false;
1663  }
1664 
1665  $error = $this->error;
1666  $this->error = "";
1667 
1668  return $error;
1669  }
1670 
1676  function _ilSetup()
1677  {
1678  //if ($this->ini->readVariable("db","type") != "")
1679  //{
1680  // $this->db->disconnect();
1681  //}
1682  return true;
1683  }
1684 
1691  function testConvert($a_convert_path)
1692  {
1693  if (trim($a_convert_path) == "")
1694  {
1695  return "no_path_convert";
1696  }
1697  if (!is_file($a_convert_path))
1698  {
1699  return "check_failed_convert";
1700  }
1701 
1702  return "";
1703 
1704  }
1705 
1712  function testGhostscript($a_ghostscript_path)
1713  {
1714  // ghostscript is optional, so empty path is ok
1715  if (trim($a_ghostscript_path) == "")
1716  {
1717  return "";
1718  }
1719  if (!is_file($a_ghostscript_path))
1720  {
1721  return "check_failed_ghostscript";
1722  }
1723 
1724  return "";
1725  }
1726 
1733  function testJava ($a_java_path)
1734  {
1735  // java is optional, so empty path is ok
1736  if (trim($a_java_path) == "")
1737  {
1738  return "";
1739  }
1740 
1741  if (!is_file($a_java_path))
1742  {
1743  return "check_failed_java";
1744  }
1745 
1746  return "";
1747 /*
1748  exec($a_java_path, $out, $back);
1749 
1750  unset($out);
1751 
1752  return ($back != 1) ? false : true;
1753 */
1754  }
1755 
1762  function testLatex($a_latex_url)
1763  {
1764  // latex is optional, so empty path is ok
1765  if (trim($a_latex_url) == "")
1766  {
1767  return "";
1768  }
1769 
1770  // open the URL
1771  include_once "./setup/classes/class.ilHttpRequest.php";
1772  $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1773  $result = @$http->downloadToString();
1774  if ((strpos((substr($result, 0, 5)), "PNG") !== FALSE) || (strpos((substr($result, 0, 5)), "GIF") !== FALSE))
1775  {
1776  return "";
1777  }
1778  else
1779  {
1780  return "check_failed_latex";;
1781  }
1782  }
1783 
1790  function testZip ($a_zip_path)
1791  {
1792  if (trim($a_zip_path) == "")
1793  {
1794  return "no_path_zip";
1795  }
1796  if (!is_file($a_zip_path))
1797  {
1798  return "check_failed_zip";
1799  }
1800 
1801  return "";
1802 /*
1803  // create test file and run zip
1804  $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1805 
1806  fwrite($fp, "test");
1807  fclose($fp);
1808 
1809  if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1810  {
1811  $curDir = getcwd();
1812  chdir(ILIAS_ABSOLUTE_PATH);
1813 
1814  $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1815 
1816  exec($zipCmd);
1817 
1818  chdir($curDir);
1819 
1820  }
1821 
1822  // check wether zip generated test file or not
1823  if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1824  {
1825  unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1826  return true;
1827  }
1828  else
1829  {
1830  unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1831  return false;
1832  }
1833 */
1834  }
1835 
1836 
1843  function testUnzip ($a_unzip_path)
1844  {
1845  if (trim($a_unzip_path) == "")
1846  {
1847  return "no_path_unzip";
1848  }
1849  if (!is_file($a_unzip_path))
1850  {
1851  return "check_failed_unzip";
1852  }
1853 
1854  return "";
1855 /*
1856  $curDir = getcwd();
1857 
1858  chdir(ILIAS_ABSOLUTE_PATH);
1859 
1860  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1861  {
1862  $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1863  exec($unzipCmd);
1864  }
1865 
1866  chdir($curDir);
1867 
1868  // check wether unzip extracted the test file or not
1869  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1870  {
1871  unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1872 
1873  return true;
1874  }
1875  else
1876  {
1877  return false;
1878  }
1879 */
1880  }
1881 
1888  function testHtmldoc($a_htmldoc_path)
1889  {
1890  // java is optional, so empty path is ok
1891  if (trim($a_htmldoc_path) == "")
1892  {
1893  return "";
1894  }
1895 
1896  if (!is_file($a_htmldoc_path))
1897  {
1898  return "check_failed_htmldoc";
1899  }
1900 
1901  return "";
1902 
1903 
1904  $curDir = getcwd();
1905 
1906  chdir(ILIAS_ABSOLUTE_PATH);
1907 
1908  $html = "<html><head><title></title></head><body><p>test</p></body></html>";
1909 
1910  $html_file = "htmldoc_test_file.html";
1911 
1912  $fp = fopen( $html_file ,"wb");
1913  fwrite($fp, $html);
1914  fclose($fp);
1915 
1916  $htmldoc = $a_htmldoc_path." ";
1917  $htmldoc .= "--no-toc ";
1918  $htmldoc .= "--no-jpeg ";
1919  $htmldoc .= "--webpage ";
1920  $htmldoc .= "--outfile htmldoc_test_file.pdf ";
1921  $htmldoc .= "--bodyfont Arial ";
1922  $htmldoc .= "--charset iso-8859-15 ";
1923  $htmldoc .= "--color ";
1924  $htmldoc .= "--size A4 "; // --landscape
1925  $htmldoc .= "--format pdf ";
1926  $htmldoc .= "--footer ... ";
1927  $htmldoc .= "--header ... ";
1928  $htmldoc .= "--left 60 ";
1929  // $htmldoc .= "--right 200 ";
1930  $htmldoc .= $html_file;
1931  exec($htmldoc);
1932 
1933  unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
1934 
1935  chdir($curDir);
1936 
1937  if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
1938  {
1939  unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
1940  return true;
1941  }
1942  else
1943  {
1944  return false;
1945  }
1946  }
1947 
1948 
1955  function unzip($a_file, $overwrite = false)
1956  {
1957  //global $ilias;
1958 
1959  $pathinfo = pathinfo($a_file);
1960  $dir = $pathinfo["dirname"];
1961  $file = $pathinfo["basename"];
1962 
1963  // unzip
1964  $cdir = getcwd();
1965  chdir($dir);
1966  $unzip = $this->ini->readVariable("tools","unzip");
1967  $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
1968  exec($unzipcmd, $arr);
1969  $zdirs = array();
1970 
1971  foreach($arr as $line)
1972  {
1973  if(is_int(strpos($line, "/")))
1974  {
1975  $zdir = substr($line, 0, strrpos($line, "/"));
1976  $nr = substr_count($zdir, "/");
1977  //echo $zdir." ".$nr."<br>";
1978  while ($zdir != "")
1979  {
1980  $nr = substr_count($zdir, "/");
1981  $zdirs[$zdir] = $nr; // collect directories
1982  //echo $dir." ".$nr."<br>";
1983  $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1984  }
1985  }
1986  }
1987 
1988  asort($zdirs);
1989 
1990  foreach($zdirs as $zdir => $nr) // create directories
1991  {
1992  ilUtil::createDirectory($zdir);
1993  }
1994 
1995  // real unzip
1996  if ($overvwrite)
1997  {
1998  $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
1999  }
2000  else
2001  {
2002  $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
2003  }
2004  exec($unzipcmd);
2005 
2006  chdir($cdir);
2007  }
2008 
2014  function setSessionSettings($session_settings)
2015  {
2016  require_once('Services/Authentication/classes/class.ilSessionControl.php');
2017 
2018  $db = $this->client->getDB();
2019 
2020  $setting_fields = ilSessionControl::getSettingFields();
2021 
2022  $i = 0;
2023  foreach($setting_fields as $field)
2024  {
2025  if( isset($session_settings[$field]) )
2026  {
2027  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
2028  $res = $db->queryF($query,
2029  array('text', 'text'), array('common', $field));
2030 
2031  $row = array();
2032  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) break;
2033 
2034  if( count($row) > 0 )
2035  {
2036  $db->update(
2037  'settings',
2038  array(
2039  'value' => array('text', $session_settings[$field])
2040  ),
2041  array(
2042  'module' => array('text', 'common'),
2043  'keyword' => array('text', $field)
2044  )
2045  );
2046  }
2047  else
2048  {
2049  $db->insert(
2050  'settings',
2051  array(
2052  'module' => array('text', 'common'),
2053  'keyword' => array('text', $field),
2054  'value' => array('text', $session_settings[$field])
2055  )
2056  );
2057  }
2058 
2059  $i++;
2060  }
2061  }
2062 
2063  if($i < 4) $message = $this->lng->txt("session_settings_not_saved");
2064  else $message = $this->lng->txt("settings_saved");
2065 
2066  ilUtil::sendInfo($message);
2067  }
2068 
2075  {
2076  require_once('Services/Authentication/classes/class.ilSessionControl.php');
2077 
2078  $db = $this->client->getDB();
2079 
2080  $setting_fields = ilSessionControl::getSettingFields();
2081 
2082  $query = "SELECT * FROM settings WHERE module = %s " .
2083  "AND ".$db->in('keyword', $setting_fields, false, 'text');
2084 
2085  $res = $db->queryF($query, array('text'), array('common'));
2086 
2087  $session_settings = array();
2088  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
2089  {
2090  $session_settings[$row['keyword']] = $row['value'];
2091  }
2092 
2093  foreach( $setting_fields as $field )
2094  {
2095  if( !isset($session_settings[$field]) )
2096  {
2097  $value = 1;
2098 
2099  switch($field)
2100  {
2101  case 'session_max_count':
2102 
2104  break;
2105 
2106  case 'session_min_idle':
2107 
2109  break;
2110 
2111  case 'session_max_idle':
2112 
2114  break;
2115 
2116  case 'session_max_idle_after_first_request':
2117 
2119  break;
2120 
2121  case 'session_allow_client_maintenance':
2122 
2124  break;
2125  }
2126 
2127  $session_settings[$field] = $value;
2128  }
2129  }
2130 
2131  return $session_settings;
2132  }
2133 
2139  function cloneFromSource($source_id)
2140  {
2141  // Getting source and targets
2142  $source = new ilClient($source_id, $this->db_connections);
2143  $source->init();
2144  $target = $this->client;
2145 
2146  // ************************************************
2147  // ** COPY FILES
2148 
2149  // Cleaning up datadir
2150  if (! ilUtil::delDir($target->getDataDir())) {
2151  $this->error = "Could not delete data dir $target->getDataDir()";
2152  //return false;
2153  }
2154 
2155  // Create empty datadir
2156  if (!ilUtil::makeDir($target->getDataDir()))
2157  {
2158  $this->error = "could_not_create_base_data_dir :".$target->getDataDir();
2159  return false;
2160  }
2161 
2162  // Copying datadir
2163  if (! ilUtil::rCopy($source->getDataDir(),$target->getDataDir())) {
2164  $this->error = "clone_datadircopyfail";
2165  $target->ini->write();
2166  return false;
2167  }
2168 
2169  // Cleaning up Webspacedir
2170  if (! ilUtil::delDir($target->getWebspaceDir())) {
2171  $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
2172  //return false;
2173  }
2174 
2175  // Create empty Webspacedir
2176  if (!ilUtil::makeDir($target->getWebspaceDir()))
2177  {
2178  $this->error = "could_not_create_base_webspace_dir :".$target->getWebspaceDir();
2179  return false;
2180  }
2181 
2182  // Copying Webspacedir
2183  if (! ilUtil::rCopy($source->getWebspaceDir(),$target->getWebspaceDir())) {
2184  $this->error = "clone_websipacedircopyfail";
2185  $target->ini->write();
2186  return false;
2187  }
2188 
2189  // Restore ini file
2190  $target->ini->write();
2191 
2192  // ************************************************
2193  // ** COPY DATABASE
2194 
2195  $source->connect();
2196  if (!$source->db)
2197  {
2198  $this->error = "Source database connection failed.";
2199  return false;
2200  }
2201 
2202  $target->connect();
2203  if (!$target->db)
2204  {
2205  $this->error = "Target database connection failed.";
2206  return false;
2207  }
2208 
2209  $source->connect();
2210  $srcTables = $source->db->query("SHOW TABLES");
2211  $target->connect();
2212 
2213  // drop all tables of the target db
2214  $tarTables = $target->db->query("SHOW TABLES");
2215  foreach($tarTables->fetchAll() as $cTable)
2216  {
2217  $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2218  }
2219 
2220  foreach($srcTables->fetchAll() as $cTable){
2221  $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2222  $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
2223  if(!$create) {
2224  $error = true;
2225  }
2226  $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM ".$source->getDbName().".".$cTable[0]);
2227  }
2228 
2229  $target->db->query("UPDATE settings SET VALUE = ".$target->db->quote(0, "integer")." WHERE keyword = ".$target->db->quote("inst_id", "text"));
2230  $target->db->query("UPDATE settings SET VALUE = ".$target->db->quote(0, "integer")." WHERE keyword = ".$target->db->quote("nic_enabled", "text"));
2231  return true;
2232  }
2240  public function printProxyStatus($client)
2241  {
2242  require_once './Services/Http/exceptions/class.ilProxyException.php';
2243  $settings = $client->getAllSettings();
2244 
2245  if((bool)$settings['proxy_status'] == true)
2246  {
2247  try
2248  {
2254  require_once 'Services/PEAR/lib/Net/Socket.php';
2255 
2256  $socket = new Net_Socket();
2257  $socket->setErrorHandling(PEAR_ERROR_RETURN);
2258  $response = $socket->connect($settings['proxy_host'], $settings['proxy_port']);
2259  if(!is_bool($response))
2260  {
2261  global $lng;
2262  throw new ilProxyException(strlen($response) ? $response : $lng->txt('proxy_not_connectable'));
2263  }
2264 
2265  ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
2266 
2267  }
2268  catch(ilProxyException $e)
2269  {
2270  ilUtil::sendFailure($this->lng->txt('proxy_pear_net_socket_error').': '.$e->getMessage());
2271  }
2272  }
2273 
2274  }
2275 
2276  public function saveProxySettings($proxy_settings)
2277  {
2278  $db = $this->client->getDB();
2279  $proxy_fields = array('proxy_status','proxy_host','proxy_port');
2280 
2281  foreach($proxy_fields as $field)
2282  {
2283  if( isset($proxy_settings[$field]) )
2284  {
2285  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
2286  $res = $db->queryF($query,
2287  array('text', 'text'), array('common', $field));
2288 
2289  $row = array();
2290  while($row = $db->fetchAssoc($res)) break;
2291 
2292  if( count($row) > 0 )
2293  {
2294  $db->update(
2295  'settings',
2296  array(
2297  'value' => array('text', $proxy_settings[$field])
2298  ),
2299  array(
2300  'module' => array('text', 'common'),
2301  'keyword' => array('text', $field)
2302  )
2303  );
2304  }
2305  else
2306  {
2307  $db->insert(
2308  'settings',
2309  array(
2310  'module' => array('text', 'common'),
2311  'keyword' => array('text', $field),
2312  'value' => array('text', $proxy_settings[$field])
2313  )
2314  );
2315  }
2316  }
2317  }
2318  }
2319 
2323  public function savePasswordSettings(array $passwd_settings)
2324  {
2325  $this->getClient()->ini->setVariable('auth', 'password_encoder', $passwd_settings['default_encoder']);
2326  $this->getClient()->ini->write();
2327  }
2328 
2333  public function getPasswordSettings()
2334  {
2335  return array(
2336  'default_encoder' =>
2337  $this->getClient()->ini->readVariable('auth', 'password_encoder') ?
2338  $this->getClient()->ini->readVariable('auth', 'password_encoder') :
2339  'md5'
2340  );
2341  }
2342 
2348  {
2349  $arr['status'] = strlen($client->ini->readVariable('auth', 'password_encoder'));
2350  if($arr['status'])
2351  {
2352  $arr['comment'] = $this->lng->txt('passwd_encoding_configured');
2353  }
2354  else
2355  {
2356  $arr['comment'] = $this->lng->txt('session_management_not_configured');
2357  }
2358  return $arr;
2359  }
2360 
2361 
2365  public function hasOpCacheEnabled() {
2366  $ini_get = ini_get('opcache.enable');
2367 
2368  return ($ini_get === 1 OR $ini_get === '1' OR strtolower($ini_get) === 'on');
2369  }
2370 } // END class.ilSetup
2371 
2373 {
2374  public function current()
2375  {
2376  return parent::getFileName();
2377  }
2378 
2379  public function valid()
2380  {
2381  if(!parent::valid())
2382  {
2383  return false;
2384  }
2385  if($this->isFile() and substr(parent::getFileName(),-4) == '.xml')
2386  {
2387  return false;
2388  }
2389  if($this->isFile() and substr(parent::getFileName(),-8) != '_inserts')
2390  {
2391  return true;
2392  }
2393  parent::next();
2394  return $this->valid();
2395  }
2396 
2397  public function rewind()
2398  {
2399  parent::rewind();
2400  }
2401 }
2402 ?>