ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
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 = "https://nic.ilias.de/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  public function __construct($a_auth, $a_auth_type)
68  {
69  global $lng;
70 
71  $this->lng = $lng;
72 
73  $this->db_connections = new ilDBConnections();
74 
75  define("ILIAS_MODULE","setup");
76 
77  $this->auth = ($this->checkAuth()) ? true : false;
78  $this->access_mode = $a_auth_type;
79 
80  // safe mode status & exec_dir
81  if ($this->safe_mode = ini_get("safe_mode"))
82  {
83  $this->safe_mode_exec_dir = ilFile::deleteTrailingSlash(ini_get("safe_mode_exec_dir"));
84  }
85 
86  // set path to ilias.ini
87  $this->ini_file_path = ILIAS_ABSOLUTE_PATH."/ilias.ini.php";
88  $this->setup_defaults = ILIAS_ABSOLUTE_PATH."/setup/ilias.master.ini.php";
89 
90  // init setup.ini
91  $this->ini_ilias_exists = $this->init();
92 
93  /*
94  if ($this->ini_ilias_exists)
95  {
96  if ($this->ini->readVariable("log","path") != "")
97  {
98  $log->path = $this->ini->readVariable("log","path");
99  }
100 
101  if ($this->ini->readVariable("log","file") != "")
102  {
103  $log->filename = $this->ini->readVariable("log","file");
104  }
105 
106  if ($this->ini->readVariable("log","enabled") != "")
107  {
108  $log->enabled = $this->ini->readVariable("log","enabled");
109  }
110  }
111  */
112  }
113 
114 
118  public $client;
119 
120 
124  public function setClient($a_cl) {
125  $this->client = $a_cl;
126  }
127 
128 
132  public function getClient() {
133  return $this->client;
134  }
135 
141  function init()
142  {
143  // load data from setup.ini file
144  $this->ini = new ilIniFile($this->ini_file_path);
145 
146  if (!$this->ini->read())
147  {
148  $this->ini->GROUPS = parse_ini_file($this->setup_defaults,true);
149  $this->error = get_class($this).": ".$this->ini->getError();
150  return false;
151  }
152 
153  $this->setup_password = $this->ini->readVariable("setup","pass");
154  $this->default_client = $this->ini->readVariable("clients","default");
155 
156  define("ILIAS_DATA_DIR",$this->ini->readVariable("clients","datadir"));
157  define("ILIAS_WEB_DIR",$this->ini->readVariable("clients","path"));
158 
159  return true;
160  }
161 
166  function saveNewClient()
167  {
168  // save client id to session
169  $_SESSION["ClientId"] = $this->client->getId();
170 
171  // create client
172  if (!$this->client->create())
173  {
174  $this->error = $this->client->getError();
175  return false;
176  }
177 
178  //everything okay
179  $this->ini_client_exists = true;
180 
181  return true;
182  }
183 
189  function updateNewClient($a_old_client_id)
190  {
191  return true;
192  //var_dump("<pre>",$this->client,"</pre>");exit;
193  //Error Handling disabled!! caused by missing PEAR
194  if ($a_old_client_id != $this->client->getId())
195  {
196  $this->saveNewClient();
197 
198  ilUtil::delDir(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$a_old_client_id);
199  ilUtil::delDir(ILIAS_DATA_DIR."/".$a_old_client_id);
200  }
201 
202  //everything okay
203  $this->ini_client_exists = true;
204 
205  return true;
206  }
207 
212  function createDatabase($a_collation = "")
213  {
214  if ($this->client->getDBSetup()->isDatabaseInstalled()) {
215  $this->error = $this->lng->txt("database_exists");
216 
217  return false;
218  }
219 
220  $db_setup = $this->client->getDBSetup();
221  return $db_setup->createDatabase($a_collation);
222  }
223 
229  public function installDatabase()
230  {
231  if (!$this->client->getDBSetup()->isDatabaseConnectable()) {
232  return false;
233  }
234 
235  if ($this->client->getDBSetup()->installDatabase()) {
236  $this->client->db_installed = true;
237 
238  return true;
239  }
240 
241  return false;
242  }
243 
244 
250  {
251  $a = @file_exists($this->INI_FILE);
252  return $a;
253  }
254 
260  function checkWritable()
261  {
262  clearstatcache();
263  if (is_writable("."))
264  {
265  $arr["status"] = true;
266  //$cdir = getcwd();
267  //chdir("..");
268  $arr["comment"] = getcwd();
269  //chdir($cdir);
270  }
271  else
272  {
273  $arr["status"] = false;
274  $arr["comment"] = $this->lng->txt("pre_folder_write_error");
275  //$cdir = getcwd();
276  //chdir("..");
277  $arr["comment"] = getcwd().": ".$arr["comment"];
278  //chdir($cdir);
279  }
280 
281  return $arr;
282  }
283 
289  function checkCreatable($a_dir = ".")
290  {
291  clearstatcache();
292  if (@mkdir($a_dir."/crst879dldsk9d", 0774))
293  {
294  $arr["status"] = true;
295  $arr["comment"] = "";
296 
297  @rmdir($a_dir."/crst879dldsk9d");
298  }
299  else
300  {
301  $arr["status"] = false;
302  //$cdir = getcwd();
303  //chdir("..");
304  $arr["comment"] = getcwd().": ".$this->lng->txt("pre_folder_create_error");
305  //chdir($cdir);
306  }
307 
308  return $arr;
309  }
310 
316  {
317  global $sess;
318 
319  if ($sess->usesCookies)
320  {
321  $arr["status"] = true;
322  $arr["comment"] = "";
323  }
324  else
325  {
326  $arr["status"] = false;
327  $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
328  }
329 
330  return $arr;
331  }
332 
337  function checkPHPVersion()
338  {
339  $version = PHP_VERSION;
340 
341  $arr["status"] = true;
342  $arr["comment"] = "PHP ".$version;
343  if (version_compare($version, '5.3.0', '<'))
344  {
345  $arr["status"] = false;
346  $arr["comment"] = "PHP ".$version.". ".$this->lng->txt("pre_php_version_too_low");
347  }
348 
349  return $arr;
350  }
351 
356  function checkMySQL()
357  {
358  global $ilDB;
359 
360  if (function_exists("mysql_query"))
361  {
362  $arr["status"] = true;
363  $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
364  }
365  else
366  {
367  $arr["status"] = false;
368  $arr["comment"] = $this->lng->txt("pre_mysql_missing");
369  }
370 
371  return $arr;
372  }
373 
378  function checkAuth()
379  {
380  if ($_SESSION["auth"] === true && $_SESSION["auth_path"] == ILIAS_HTTP_PATH)
381  {
382  return true;
383  }
384 
385  return false;
386  }
387 
388 
393  function checkDom()
394  {
395  global $ilDB;
396 
397  if (class_exists("DOMDocument"))
398  {
399  $arr["status"] = true;
400  }
401  else
402  {
403  $arr["status"] = false;
404  $arr["comment"] = $this->lng->txt("pre_dom_missing");
405  }
406 
407  return $arr;
408  }
409 
414  function checkXsl()
415  {
416  global $ilDB;
417 
418  if (class_exists("XSLTProcessor"))
419  {
420  $arr["status"] = true;
421  }
422  else
423  {
424  $arr["status"] = false;
425  $arr["comment"] = sprintf($this->lng->txt("pre_xsl_missing"),
426  "http://php.net/manual/en/book.xsl.php");
427  }
428 
429  return $arr;
430  }
431 
436  function checkGd()
437  {
438  global $ilDB;
439 
440  if (function_exists("imagefill") && function_exists("imagecolorallocate"))
441  {
442  $arr["status"] = true;
443  }
444  else
445  {
446  $arr["status"] = false;
447  $arr["comment"] = sprintf($this->lng->txt("pre_gd_missing"),
448  "http://php.net/manual/en/book.image.php");
449  }
450 
451  return $arr;
452  }
453 
458  function checkMemoryLimit()
459  {
460  global $ilDB;
461 
462  $limit = ini_get("memory_limit");
463 
464  $limit_ok = true;
465  if (is_int(strpos($limit, "M")))
466  {
467  $limit_n = (int) $limit;
468  if ($limit_n < 40)
469  {
470  $limit_ok = false;
471  }
472  }
473 
474  if ($limit_ok)
475  {
476  $arr["status"] = true;
477  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_recommend");
478  }
479  else
480  {
481  $arr["status"] = false;
482  $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_too_low");
483  }
484 
485  return $arr;
486  }
487 
488 
492  protected function checkOpcacheSettings() {
493  $arr = array();
494  // correct-with-php5-removal FSX start
495  if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
496  $arr["status"] = true;
497 
498  return $arr;
499  }
500  // correct-with-php5-removal FSX end
501 
502  $load_comments = ini_get("opcache.load_comments");
503  if ($load_comments == 1) {
504  $arr["status"] = true;
505  } else {
506  $arr["status"] = false;
507  $arr["comment"] = $this->lng->txt("pre_opcache_comments");
508  }
509 
510  return $arr;
511  }
512 
521  {
522  $a = array();
523  $a["php"] = $this->checkPHPVersion();
524 // $a["mysql"] = $this->checkMySQL();
525  $a["root"] = $this->checkWritable();
526  $a["folder_create"] = $this->checkCreatable();
527  $a["cookies_enabled"] = $this->checkCookiesEnabled();
528  $a["dom"] = $this->checkDom();
529  $a["xsl"] = $this->checkXsl();
530  $a["gd"] = $this->checkGd();
531  $a["memory"] = $this->checkMemoryLimit();
532 
533  if ($this->hasOpCacheEnabled()) {
534  $a["load_comments"] = $this->checkOpcacheSettings();
535  }
536 
537  return $a;
538  }
539 
545  {
546  $this->preliminaries_result = $this->queryPreliminaries();
547 
548  foreach ($this->preliminaries_result as $val)
549  {
550  if ($val["status"] === false)
551  {
552  $this->preliminaries = false;
553  return false;
554  }
555  }
556 
557  return true;
558  }
559 
564  function getPassword ()
565  {
566  return $this->ini->readVariable("setup","pass");
567  }
568 
574  function setPassword ($a_password)
575  {
576  $this->ini->setVariable("setup","pass",md5($a_password));
577 
578  if ($this->ini->write() == false)
579  {
580  $this->error = $this->ini->getError();
581  return false;
582  }
583 
584  return true;
585  }
586 
592  function loginAsClient($a_auth_data)
593  {
594  global $ilDB;
595 
596  if (empty($a_auth_data["client_id"]))
597  {
598  $this->error = "no_client_id";
599  return false;
600  }
601 
602  if (empty($a_auth_data["username"]))
603  {
604  $this->error = "no_username";
605  return false;
606  }
607 
608  if (empty($a_auth_data["password"]))
609  {
610  $this->error = "no_password";
611  return false;
612  }
613 
614  if (!$this->newClient($a_auth_data["client_id"])) //TT: comment out to get around null db
615  {
616  $this->error = "unknown_client_id";
617  unset($this->client);
618  return false;
619  }
620 
621  if (!$this->client->db_exists)
622  {
623  $this->error = "no_db_connect_consult_admin";
624  unset($this->client);
625  return false;
626  }
627 
628  $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = ".
629  $this->client->db->quote('system_role_id','text'));
630  $r1 = $this->client->db->fetchAssoc($s1);
631  $system_role_id = $r1["value"];
632 
633  $add_usrfields = '';
634  if($this->client->db->tableColumnExists('usr_data', 'passwd_enc_type'))
635  {
636  $add_usrfields .= ' , usr_data.passwd_enc_type, usr_data.passwd_salt ';
637  }
638  $q = "SELECT usr_data.usr_id, usr_data.passwd $add_usrfields " .
639  "FROM usr_data " .
640  "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id " .
641  "WHERE rbac_ua.rol_id = " . $this->client->db->quote((int)$system_role_id, 'integer') . " " .
642  "AND usr_data.login=" . $this->client->db->quote($a_auth_data["username"], 'text');
643  $r = $this->client->db->query($q);
644  if(!$this->client->db->numRows($r))
645  {
646  $this->error = 'login_invalid';
647  return false;
648  }
649 
650  $data = $this->client->db->fetchAssoc($r);
651 
652  global $ilClientIniFile;
653 
654  $ilClientIniFile = $this->client->ini;
655 
656  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
657  $crypt_type = ilUserPasswordManager::getInstance()->getEncoderName();
658  if(strlen($add_usrfields) && ilUserPasswordManager::getInstance()->isEncodingTypeSupported($crypt_type))
659  {
660  require_once 'setup/classes/class.ilObjSetupUser.php';
661  $user = new ilObjSetupUser();
662  $user->setPasswd($data['passwd'], IL_PASSWD_CRYPTED);
663  $user->setPasswordEncodingType($data['passwd_enc_type']);
664  $user->setPasswordSalt($data['passwd_salt']);
665 
666  $password_valid = ilUserPasswordManager::getInstance()->verifyPassword($user, $a_auth_data['password']);
667  }
668  else
669  {
670  $password_valid = $data['passwd'] == md5($a_auth_data['password']);
671  }
672 
673  if($password_valid)
674  {
675  // all checks passed -> user valid
676  $_SESSION['auth'] = true;
677  $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
678  $_SESSION['access_mode'] = 'client';
679  $_SESSION['ClientId'] = $this->client->getId();
680  return true;
681  }
682  else
683  {
684  $this->error = 'login_invalid';
685  return false;
686  }
687  }
688 
694  function loginAsAdmin($a_password)
695  {
696  $a_password = md5($a_password);
697 
698  if ($this->ini->readVariable("setup","pass") == $a_password)
699  {
700  $_SESSION["auth"] = true;
701  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
702  $_SESSION["access_mode"] = "admin";
703  return true;
704  }
705 
706  return false;
707  }
708 
714  function newClient($a_client_id = 0)
715  {
716  if (!$this->isInstalled())
717  {
718  return false;
719  }
720 
721  $this->client = new ilClient($a_client_id, $this->db_connections);
722 
723  if (!$this->client->init())
724  {
725 //echo "<br>noclientinit";
726  $this->error = get_class($this).": ".$this->client->getError();
727  $_SESSION["ClientId"] = "";
728  return false;
729  }
730 
731  $_SESSION["ClientId"] = $a_client_id;
732 
733  return true;
734  }
735 
741  function getStatus ($client = 0)
742  {
743  if (!is_object($client))
744  {
745  if ($this->ini_client_exists)
746  {
748  }
749  else
750  {
751  $client = new ilClient(0, $this->db_connections);
752  }
753  }
754 
755  $status = array();
756  $status["ini"] = $this->checkClientIni($client); // check this one
757  $status["db"] = $this->checkClientDatabase($client);
758  if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
759  {
760  //$status["sess"]["status"] = false;
761  //$status["sess"]["comment"] = $status["db"]["comment"];
762  $status["lang"]["status"] = false;
763  $status["lang"]["comment"] = $status["db"]["comment"];
764  $status["contact"]["status"] = false;
765  $status["contact"]["comment"] = $status["db"]["comment"];
766 
767  $status["proxy"]["status"] = false;
768  $status["proxy"]["comment"] = $status["db"]["comment"];
769 
770  $status["nic"]["status"] = false;
771  $status["nic"]["comment"] = $status["db"]["comment"];
772  }
773  else
774  {
775  //$status["sess"] = $this->checkClientSessionSettings($client);
776  $status["lang"] = $this->checkClientLanguages($client);
777  $status["contact"] = $this->checkClientContact($client);
778  $status["proxy"] = $this->checkClientProxySettings($client);
779  $status["nic"] = $this->checkClientNIC($client);
780  $status["finish"] = $this->checkFinish($client);
781  $status["access"] = $this->checkAccess($client);
782  }
783 
784  //return value
785  return $status;
786  }
787 
793  function checkFinish(&$client)
794  {
795  if ($client->getSetting("setup_ok"))
796  {
797  $arr["status"] = true;
798  //$arr["comment"] = $this->lng->txt("setup_finished");
799  }
800  else
801  {
802  $arr["status"] = false;
803  $arr["comment"] = $this->lng->txt("setup_not_finished");
804  }
805 
806  return $arr;
807  }
808 
814  function checkAccess(&$client)
815  {
816  if ($client->ini->readVariable("client","access") == "1")
817  {
818  $arr["status"] = true;
819  $arr["comment"] = $this->lng->txt("online");
820  }
821  else
822  {
823  $arr["status"] = false;
824  $arr["comment"] = $this->lng->txt("disabled");
825  }
826 
827  return $arr;
828  }
829 
836  {
837  if (!$arr["status"] = $client->init())
838  {
839  $arr["comment"] = $client->getError();
840  }
841  else
842  {
843  //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
844  }
845 
846  return $arr;
847  }
848 
849 
855  $arr = array();
856  $client->provideGlobalDB();
857  if (!$arr["status"] = $client->db_exists) {
858  $arr["comment"] = $this->lng->txt("no_database");
859 
860  return $arr;
861  }
862 
863  if (!$arr["status"] = $client->db_installed) {
864  $arr["comment"] = $this->lng->txt("db_not_installed");
865 
866  return $arr;
867  }
868  // TODO: move this to client class!!
869  $client->setup_ok = (bool)$client->getSetting("setup_ok");
870 
871  include_once "./Services/Database/classes/class.ilDBUpdate.php";
872  $this->lng->setDbHandler($client->db);
873  $dbupdate = new ilDBUpdate($client->db);
874 
875  if (!$arr["status"] = $dbupdate->getDBVersionStatus()) {
876  $arr["comment"] = $this->lng->txt("db_needs_update");
877  $arr["update"] = true;
878 
879  return $arr;
880  } else {
881  if ($dbupdate->hotfixAvailable()) {
882  $arr["status"] = false;
883  $arr["comment"] = $this->lng->txt("hotfix_available");
884  $arr["update"] = true;
885 
886  return $arr;
887  } else {
888  if ($dbupdate->customUpdatesAvailable()) {
889  $arr["status"] = false;
890  $arr["comment"] = $this->lng->txt("custom_updates_available");
891  $arr["update"] = true;
892 
893  return $arr;
894  }
895  }
896  }
897 
898  // check control information
899  global $ilDB;
900  $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
901  $crec = $ilDB->fetchAssoc($cset);
902  $client->revokeGlobalDB();
903  if ($crec["cnt"] == 0) {
904  $arr["status"] = false;
905  $arr["comment"] = $this->lng->txt("db_control_structure_missing");
906  $arr["update"] = true;
907 
908  return $arr;
909  }
910 
911  return $arr;
912  }
913 
919  function checkClientSessionSettings(&$client, $a_as_bool = false)
920  {
921  require_once('Services/Authentication/classes/class.ilSessionControl.php');
922 
923  global $ilDB;
924  $db = $ilDB;
925 
927 
928  $query = "SELECT keyword, value FROM settings WHERE ".$db->in('keyword', $fields, false, 'text');
929  $res = $db->query($query);
930 
931  $rows = array();
932  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
933  {
934  if( $row['value'] != '' )
935  $rows[] = $row;
936  else break;
937  }
938 
939  if (count($rows) != count($fields))
940  {
941  if($a_as_bool) return false;
942  $arr["status"] = false;
943  $arr["comment"] = $this->lng->txt("session_management_not_configured");
944  }
945  else
946  {
947  if($a_as_bool) return true;
948  $arr["status"] = true;
949  $arr["comment"] = $this->lng->txt("session_management_configured");
950  }
951 
952  return $arr;
953  }
954 
955 
961  $client->provideGlobalDB();
962  global $ilDB;
963  $arr = array();
964  $fields = array( 'proxy_status', 'proxy_host', 'proxy_port' );
965 
966  $query = "SELECT keyword, value FROM settings WHERE " . $ilDB->in('keyword', $fields, false, 'text');
967  $res = $ilDB->query($query);
968 
969  $proxy_settings = array();
970  $already_saved = false;
971  while ($row = $ilDB->fetchAssoc($res)) {
972  $already_saved = true;
973  $proxy_settings[$row['keyword']] = $row['value'];
974  }
975 
976  if (!$already_saved) {
977  $arr["status"] = false;
978  $arr["comment"] = $this->lng->txt("proxy");
979  $arr["text"] = $this->lng->txt("proxy");
980  } else {
981  if ((bool)$proxy_settings["proxy_status"] == false) {
982  $arr["status"] = true;
983  $arr["comment"] = $this->lng->txt("proxy_disabled");
984  $arr["text"] = $this->lng->txt("proxy_disabled");
985  } else {
986  $arr["status"] = true;
987  $arr["comment"] = $this->lng->txt("proxy_activated_configurated");
988  $arr["text"] = $this->lng->txt("proxy_activated_configurated");
989  }
990  }
991 
992  return $arr;
993  }
994 
995 
1001  $client->provideGlobalDB();
1002  $installed_langs = $this->lng->getInstalledLanguages();
1003 
1004  $count = count($installed_langs);
1005  $arr = array();
1006  if ($count < 1) {
1007  $arr["status"] = false;
1008  $arr["comment"] = $this->lng->txt("lang_none_installed");
1009  } else {
1010  $arr["status"] = true;
1011  //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
1012  }
1013  $client->revokeGlobalDB();
1014  return $arr;
1015  }
1016 
1023  {
1024  $arr["status"] = true;
1025  //$arr["comment"] = $this->lng->txt("filled_out");
1026 
1027  $settings = $client->getAllSettings();
1028  $client_name = $client->getName();
1029 
1030  // check required fields
1031  if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
1032  empty($settings["admin_email"]) or empty($client_name))
1033  {
1034  $arr["status"] = false;
1035  $arr["comment"] = $this->lng->txt("missing_data");
1036  }
1037 
1038  // admin email
1039  if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
1040  {
1041  $arr["status"] = false;
1042  $arr["comment"] = $this->lng->txt("email_not_valid");
1043  }
1044 
1045  return $arr;
1046  }
1047 
1054  {
1055  $settings = $client->getAllSettings();
1056 
1057  if (!isset($settings["nic_enabled"]))
1058  {
1059  $arr["status"] = false;
1060  $arr["comment"] = $this->lng->txt("nic_not_disabled");
1061  return $arr;
1062  }
1063 
1064  $arr["status"] = true;
1065 
1066  if ($settings["nic_enabled"] == "-1")
1067  {
1068  $arr["comment"] = $this->lng->txt("nic_reg_failed");
1069  return $arr;
1070  }
1071 
1072  if (!$settings["nic_enabled"])
1073  {
1074  $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1075  }
1076  else
1077  {
1078  $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1079  if ($settings["inst_id"] <= 0)
1080  {
1081  $arr["status"] = false;
1082  }
1083  }
1084 
1085  return $arr;
1086  }
1087 
1092  function isInstalled()
1093  {
1094  return $this->ini_ilias_exists;
1095  }
1096 
1101  function isAuthenticated()
1102  {
1103  return $this->auth;
1104  }
1105 
1110  function isAdmin()
1111  {
1112  return ($this->access_mode == "admin") ? true : false;
1113  }
1114 
1120  function saveMasterSetup($a_formdata)
1121  {
1122  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1123 
1124  if ($a_formdata["chk_datadir_path"] == 1) // mode create dir
1125  {
1126  if (!ilUtil::makeDir($datadir_path))
1127  {
1128  $this->error = "create_datadir_failed";
1129  return false;
1130  }
1131  }
1132 
1133  // create webspace dir if it does not exist
1134  if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1135  {
1136  if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1137  {
1138  $this->error = "create_webdir_failed";
1139  return false;
1140  }
1141  }
1142 
1143  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1144  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1145  $log_file = substr($form_log_path,strlen($log_path)+1);
1146  $error_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1147 
1148  $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
1149  $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
1150  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1151  $this->ini->setVariable("clients", "datadir", $datadir_path);
1152  $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
1153  $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
1154  $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
1155  $this->ini->setVariable("tools", "ghostscript", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"])));
1156  $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
1157  //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1158  $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1159  $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1160  $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1161  $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
1162  $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
1163  $this->ini->setVariable("tools", "enable_system_styles_management", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["enable_system_styles_management"])));
1164  $this->ini->setVariable("tools", "lessc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["lessc_path"])));
1165 
1166  $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
1167  $this->ini->setVariable("log", "path", $log_path);
1168  $this->ini->setVariable("log", "file", $log_file);
1169  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1170  $this->ini->setVariable("log", "error_path", $error_log_path);
1171 
1172  $this->ini->setVariable("https","auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1173  $this->ini->setVariable("https","auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1174  $this->ini->setVariable("https","auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1175 
1176  if (!$this->ini->write())
1177  {
1178  $this->error = get_class($this).": ".$this->ini->getError();
1179  return false;
1180  }
1181 
1182  // everything is fine. so we authenticate the user and set access mode to 'admin'
1183  $_SESSION["auth"] = true;
1184  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1185  $_SESSION["access_mode"] = "admin";
1186 
1187  return true;
1188  }
1189 
1195  function updateMasterSettings($a_formdata)
1196  {
1197  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1198  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1199  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1200  $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1201  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1202  //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1203  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1204  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1205  $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
1206  $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1207  $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
1208  $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
1209  $enable_system_styles_management = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["enable_system_styles_management"]));
1210  $lessc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["lessc_path"]));
1211 
1212  $this->ini->setVariable("tools", "convert", $convert_path);
1213  $this->ini->setVariable("tools", "zip", $zip_path);
1214  $this->ini->setVariable("tools", "unzip", $unzip_path);
1215  $this->ini->setVariable("tools", "ghostscript", $ghostscript_path);
1216  $this->ini->setVariable("tools", "java", $java_path);
1217  //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1218  $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1219  $this->ini->setVariable("tools", "latex", $latex_url);
1220  $this->ini->setVariable("tools", "fop", $fop_path);
1221  $this->ini->setVariable("tools", "vscantype", $scan_type);
1222  $this->ini->setVariable("tools", "scancommand", $scan_command);
1223  $this->ini->setVariable("tools", "cleancommand", $clean_command);
1224  $this->ini->setVariable("tools", "lessc", $lessc_path);
1225  $this->ini->setVariable("tools", "enable_system_styles_management", $enable_system_styles_management);
1226 
1227  $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1228  $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1229  $log_file = substr($form_log_path,strlen($log_path)+1);
1230 
1231  $error_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1232 
1233  $this->ini->setVariable("log", "path", $log_path);
1234  $this->ini->setVariable("log", "file", $log_file);
1235  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1236  $this->ini->setVariable("log", "error_path", $error_log_path);
1237  $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1238 
1239  $this->ini->setVariable("https","auto_https_detect_enabled",($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1240  $this->ini->setVariable("https","auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1241  $this->ini->setVariable("https","auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1242 
1243  if (!$this->ini->write())
1244  {
1245  $this->error = get_class($this).": ".$this->ini->getError();
1246  return false;
1247  }
1248 
1249  return true;
1250  }
1251 
1257  function checkToolsSetup($a_formdata)
1258  {
1259  // convert path
1260  if (!isset($a_formdata["chk_convert_path"]))
1261  {
1262  // convert backslashes to forwardslashes
1263  $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1264 
1265  if (($err = $this->testConvert($convert_path)) != "")
1266  {
1267  $this->error = $err;
1268  return false;
1269  }
1270  }
1271 
1272  // zip path
1273  if (!isset($a_formdata["chk_zip_path"]))
1274  {
1275  // convert backslashes to forwardslashes
1276  $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1277 
1278  if (empty($zip_path))
1279  {
1280  $this->error = "no_path_zip";
1281  return false;
1282  }
1283 
1284  if (!$this->testZip($zip_path))
1285  {
1286  $this->error = "check_failed_zip";
1287  return false;
1288  }
1289  }
1290 
1291  // unzip path
1292  if (!isset($a_formdata["chk_unzip_path"]))
1293  {
1294  // convert backslashes to forwardslashes
1295  $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1296 
1297  if (empty($unzip_path))
1298  {
1299  $this->error = "no_path_unzip";
1300  return false;
1301  }
1302 
1303  if (!$this->testUnzip($unzip_path))
1304  {
1305  $this->error = "check_failed_unzip";
1306  return false;
1307  }
1308  }
1309 
1310  // ghostscript path
1311  if (!isset($a_formdata["chk_ghostscript_path"]))
1312  {
1313  // convert backslashes to forwardslashes
1314  $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1315 
1316  if (($err = $this->testGhostscript($ghostscript_path)) != "")
1317  {
1318  $this->error = $err;
1319  return false;
1320  }
1321  }
1322 
1323  // java path
1324  if (!isset($a_formdata["chk_java_path"]))
1325  {
1326  // convert backslashes to forwardslashes
1327  $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1328 
1329  if (empty($java_path))
1330  {
1331  $this->error = "no_path_java";
1332  return false;
1333  }
1334 
1335  if (!$this->testJava($java_path))
1336  {
1337  $this->error = "check_failed_java";
1338  return false;
1339  }
1340  }
1341 
1342  /*if (!isset($a_formdata["chk_mkisofs_path"]))
1343  {
1344  // convert backslashes to forwardslashes
1345  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1346 
1347  if (empty($mkisofs_path))
1348  {
1349  $this->error = "no_path_mkisofs";
1350  return false;
1351  }
1352  }*/
1353 
1354  if (!isset($a_formdata["chk_ffmpeg_path"]))
1355  {
1356  // convert backslashes to forwardslashes
1357  $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1358 
1359  if (empty($ffmpeg_path))
1360  {
1361  $this->error = "no_path_ffmpeg";
1362  return false;
1363  }
1364 
1365  if (!$this->testFFMpeg($ffmpeg_path))
1366  {
1367  $this->error = "check_failed_ffmpeg";
1368  return false;
1369  }
1370  }
1371 
1372  // latex url
1373  if (!isset($a_formdata["chk_latex_url"]))
1374  {
1375  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1376  if (empty($latex_url))
1377  {
1378  $this->error = "no_latex_url";
1379  return false;
1380  }
1381 
1382  if (!$this->testLatex($latex_url))
1383  {
1384  $this->error = "check_failed_latex";
1385  return false;
1386  }
1387  }
1388 
1389  return true;
1390  }
1391 
1397  function checkDataDirSetup($a_formdata)
1398  {
1399  // remove trailing slash & convert backslashes to forwardslashes
1400  $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1401 
1402  if (empty($datadir_path))
1403  {
1404  $this->error = "no_path_datadir";
1405  return false;
1406  }
1407 
1408  $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1409 
1410  // datadir may not point to webspace dir or to any place under webspace_dir
1411  if (strpos($datadir_path,$webspace_dir) !== false)
1412  {
1413  $this->error = "datadir_webspacedir_match";
1414  return false;
1415  }
1416 
1417  // create dir
1418  if ($a_formdata["chk_datadir_path"] == 1)
1419  {
1420  $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1421  $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
1422 
1423  if ($this->isDirectoryInOther($dir_to_create, ILIAS_ABSOLUTE_PATH)) {
1424  $this->error = "cannot_create_datadir_inside_webdir";
1425  return false;
1426  }
1427 
1428  if (is_writable($datadir_path))
1429  {
1430  $this->error = "dir_exists_create";
1431  return false;
1432  }
1433 
1434  if (!is_writable($dir_to_check))
1435  {
1436  $this->error = "cannot_create_datadir_no_write_access";
1437  return false;
1438  }
1439  }
1440  else // check set target dir
1441  {
1442  if ($this->isDirectoryInOther($datadir_path, ILIAS_ABSOLUTE_PATH)) {
1443  $this->error = "cannot_create_datadir_inside_webdir";
1444  return false;
1445  }
1446 
1447  if (!is_writable($datadir_path))
1448  {
1449  $this->error = "cannot_create_datadir_no_write_access";
1450  return false;
1451  }
1452  }
1453 
1454  return true;
1455  }
1456 
1462  function checkPasswordSetup($a_formdata)
1463  {
1464  if (!$a_formdata["setup_pass"])
1465  {
1466  $this->error = "no_setup_pass_given";
1467  return false;
1468  }
1469 
1470  if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
1471  {
1472  $this->error = "pass_does_not_match";
1473  return false;
1474  }
1475 
1476  return true;
1477  }
1478 
1484  function checkLogSetup($a_formdata)
1485  {
1486  // log path
1487  if (!$a_formdata["chk_log_status"])
1488  {
1489  // remove trailing slash & convert backslashes to forwardslashes
1490  $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1491 
1492  if (empty($log_path))
1493  {
1494  $this->error = "no_path_log";
1495  return false;
1496  }
1497 
1498  if(is_dir($log_path))
1499  {
1500  $this->error = 'could_not_create_logfile';
1501  return false;
1502  }
1503 
1504  if ($this->isDirectoryInOther($log_path, ILIAS_ABSOLUTE_PATH)) {
1505  $this->error = "cannot_create_logdir_inside_webdir";
1506  return false;
1507  }
1508 
1509  if (!@touch($log_path))
1510  {
1511  $this->error = "could_not_create_logfile";
1512  return false;
1513  }
1514  }
1515 
1516  return true;
1517  }
1518 
1526  public function checkErrorLogSetup($error_log_path) {
1527  // remove trailing slash & convert backslashes to forwardslashes
1528  $clean_error_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($error_log_path)));
1529 
1530  if (!empty($clean_error_log_path)) {
1531  if (!ilUtil::makeDirParents($clean_error_log_path)) {
1532  $this->error = "could_not_create_error_directory";
1533  return false;
1534  }
1535  }
1536 
1537  return true;
1538  }
1539 
1544  function getError()
1545  {
1546  if (empty($this->error))
1547  {
1548  return false;
1549  }
1550 
1551  $error = $this->error;
1552  $this->error = "";
1553 
1554  return $error;
1555  }
1556 
1562  function _ilSetup()
1563  {
1564  //if ($this->ini->readVariable("db","type") != "")
1565  //{
1566  // $this->db->disconnect();
1567  //}
1568  return true;
1569  }
1570 
1577  function testConvert($a_convert_path)
1578  {
1579  if (trim($a_convert_path) == "")
1580  {
1581  return "no_path_convert";
1582  }
1583  if (!is_file($a_convert_path))
1584  {
1585  return "check_failed_convert";
1586  }
1587 
1588  return "";
1589 
1590  }
1591 
1598  function testGhostscript($a_ghostscript_path)
1599  {
1600  // ghostscript is optional, so empty path is ok
1601  if (trim($a_ghostscript_path) == "")
1602  {
1603  return "";
1604  }
1605  if (!is_file($a_ghostscript_path))
1606  {
1607  return "check_failed_ghostscript";
1608  }
1609 
1610  return "";
1611  }
1612 
1619  function testJava ($a_java_path)
1620  {
1621  // java is optional, so empty path is ok
1622  if (trim($a_java_path) == "")
1623  {
1624  return "";
1625  }
1626 
1627  if (!is_file($a_java_path))
1628  {
1629  return "check_failed_java";
1630  }
1631 
1632  return "";
1633 /*
1634  exec($a_java_path, $out, $back);
1635 
1636  unset($out);
1637 
1638  return ($back != 1) ? false : true;
1639 */
1640  }
1641 
1648  function testLatex($a_latex_url)
1649  {
1650  // latex is optional, so empty path is ok
1651  if (trim($a_latex_url) == "")
1652  {
1653  return "";
1654  }
1655 
1656  // open the URL
1657  include_once "./setup/classes/class.ilHttpRequest.php";
1658  $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1659  $result = @$http->downloadToString();
1660  if ((strpos((substr($result, 0, 5)), "PNG") !== FALSE) || (strpos((substr($result, 0, 5)), "GIF") !== FALSE))
1661  {
1662  return "";
1663  }
1664  else
1665  {
1666  return "check_failed_latex";;
1667  }
1668  }
1669 
1676  function testZip ($a_zip_path)
1677  {
1678  if (trim($a_zip_path) == "")
1679  {
1680  return "no_path_zip";
1681  }
1682  if (!is_file($a_zip_path))
1683  {
1684  return "check_failed_zip";
1685  }
1686 
1687  return "";
1688 /*
1689  // create test file and run zip
1690  $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1691 
1692  fwrite($fp, "test");
1693  fclose($fp);
1694 
1695  if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1696  {
1697  $curDir = getcwd();
1698  chdir(ILIAS_ABSOLUTE_PATH);
1699 
1700  $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1701 
1702  exec($zipCmd);
1703 
1704  chdir($curDir);
1705 
1706  }
1707 
1708  // check wether zip generated test file or not
1709  if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1710  {
1711  unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1712  return true;
1713  }
1714  else
1715  {
1716  unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1717  return false;
1718  }
1719 */
1720  }
1721 
1722 
1729  function testUnzip ($a_unzip_path)
1730  {
1731  if (trim($a_unzip_path) == "")
1732  {
1733  return "no_path_unzip";
1734  }
1735  if (!is_file($a_unzip_path))
1736  {
1737  return "check_failed_unzip";
1738  }
1739 
1740  return "";
1741 /*
1742  $curDir = getcwd();
1743 
1744  chdir(ILIAS_ABSOLUTE_PATH);
1745 
1746  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1747  {
1748  $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1749  exec($unzipCmd);
1750  }
1751 
1752  chdir($curDir);
1753 
1754  // check wether unzip extracted the test file or not
1755  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1756  {
1757  unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1758 
1759  return true;
1760  }
1761  else
1762  {
1763  return false;
1764  }
1765 */
1766  }
1767 
1774  function unzip($a_file, $overwrite = false)
1775  {
1776  //global $ilias;
1777 
1778  $pathinfo = pathinfo($a_file);
1779  $dir = $pathinfo["dirname"];
1780  $file = $pathinfo["basename"];
1781 
1782  // unzip
1783  $cdir = getcwd();
1784  chdir($dir);
1785  $unzip = $this->ini->readVariable("tools","unzip");
1786  $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
1787  exec($unzipcmd, $arr);
1788  $zdirs = array();
1789 
1790  foreach($arr as $line)
1791  {
1792  if(is_int(strpos($line, "/")))
1793  {
1794  $zdir = substr($line, 0, strrpos($line, "/"));
1795  $nr = substr_count($zdir, "/");
1796  //echo $zdir." ".$nr."<br>";
1797  while ($zdir != "")
1798  {
1799  $nr = substr_count($zdir, "/");
1800  $zdirs[$zdir] = $nr; // collect directories
1801  //echo $dir." ".$nr."<br>";
1802  $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1803  }
1804  }
1805  }
1806 
1807  asort($zdirs);
1808 
1809  foreach($zdirs as $zdir => $nr) // create directories
1810  {
1811  ilUtil::createDirectory($zdir);
1812  }
1813 
1814  // real unzip
1815  if ($overvwrite)
1816  {
1817  $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
1818  }
1819  else
1820  {
1821  $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
1822  }
1823  exec($unzipcmd);
1824 
1825  chdir($cdir);
1826  }
1827 
1833  function setSessionSettings($session_settings)
1834  {
1835  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1836 
1837  $db = $this->client->getDB();
1838 
1839  $setting_fields = ilSessionControl::getSettingFields();
1840 
1841  $i = 0;
1842  foreach($setting_fields as $field)
1843  {
1844  if( isset($session_settings[$field]) )
1845  {
1846  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1847  $res = $db->queryF($query,
1848  array('text', 'text'), array('common', $field));
1849 
1850  $row = array();
1851  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) break;
1852 
1853  if( count($row) > 0 )
1854  {
1855  $db->update(
1856  'settings',
1857  array(
1858  'value' => array('text', $session_settings[$field])
1859  ),
1860  array(
1861  'module' => array('text', 'common'),
1862  'keyword' => array('text', $field)
1863  )
1864  );
1865  }
1866  else
1867  {
1868  $db->insert(
1869  'settings',
1870  array(
1871  'module' => array('text', 'common'),
1872  'keyword' => array('text', $field),
1873  'value' => array('text', $session_settings[$field])
1874  )
1875  );
1876  }
1877 
1878  $i++;
1879  }
1880  }
1881 
1882  if($i < 4) $message = $this->lng->txt("session_settings_not_saved");
1883  else $message = $this->lng->txt("settings_saved");
1884 
1885  ilUtil::sendInfo($message);
1886  }
1887 
1894  {
1895  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1896 
1897  $db = $this->client->getDB();
1898 
1899  $setting_fields = ilSessionControl::getSettingFields();
1900 
1901  $query = "SELECT * FROM settings WHERE module = %s " .
1902  "AND ".$db->in('keyword', $setting_fields, false, 'text');
1903 
1904  $res = $db->queryF($query, array('text'), array('common'));
1905 
1906  $session_settings = array();
1907  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
1908  {
1909  $session_settings[$row['keyword']] = $row['value'];
1910  }
1911 
1912  foreach( $setting_fields as $field )
1913  {
1914  if( !isset($session_settings[$field]) )
1915  {
1916  $value = 1;
1917 
1918  switch($field)
1919  {
1920  case 'session_max_count':
1921 
1923  break;
1924 
1925  case 'session_min_idle':
1926 
1928  break;
1929 
1930  case 'session_max_idle':
1931 
1933  break;
1934 
1935  case 'session_max_idle_after_first_request':
1936 
1938  break;
1939 
1940  case 'session_allow_client_maintenance':
1941 
1943  break;
1944  }
1945 
1946  $session_settings[$field] = $value;
1947  }
1948  }
1949 
1950  return $session_settings;
1951  }
1952 
1958  function cloneFromSource($source_id)
1959  {
1960  // Getting source and targets
1961  $source = new ilClient($source_id, $this->db_connections);
1962  $source->init();
1964 
1965  // ************************************************
1966  // ** COPY FILES
1967 
1968  // Cleaning up datadir
1969  if (! ilUtil::delDir($target->getDataDir())) {
1970  $this->error = "Could not delete data dir $target->getDataDir()";
1971  //return false;
1972  }
1973 
1974  // Create empty datadir
1975  if (!ilUtil::makeDir($target->getDataDir()))
1976  {
1977  $this->error = "could_not_create_base_data_dir :".$target->getDataDir();
1978  return false;
1979  }
1980 
1981  // Copying datadir
1982  if (! ilUtil::rCopy($source->getDataDir(),$target->getDataDir())) {
1983  $this->error = "clone_datadircopyfail";
1984  $target->ini->write();
1985  return false;
1986  }
1987 
1988  // Cleaning up Webspacedir
1989  if (! ilUtil::delDir($target->getWebspaceDir())) {
1990  $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
1991  //return false;
1992  }
1993 
1994  // Create empty Webspacedir
1995  if (!ilUtil::makeDir($target->getWebspaceDir()))
1996  {
1997  $this->error = "could_not_create_base_webspace_dir :".$target->getWebspaceDir();
1998  return false;
1999  }
2000 
2001  // Copying Webspacedir
2002  if (! ilUtil::rCopy($source->getWebspaceDir(),$target->getWebspaceDir())) {
2003  $this->error = "clone_websipacedircopyfail";
2004  $target->ini->write();
2005  return false;
2006  }
2007 
2008  // Restore ini file
2009  $target->ini->write();
2010 
2011  // ************************************************
2012  // ** COPY DATABASE
2013 
2014  $source->connect();
2015  if (!$source->db)
2016  {
2017  $this->error = "Source database connection failed.";
2018  return false;
2019  }
2020 
2021  $target->connect();
2022  if (!$target->db)
2023  {
2024  $this->error = "Target database connection failed.";
2025  return false;
2026  }
2027 
2028  $source->connect();
2029  $srcTables = $source->db->query("SHOW TABLES");
2030  $target->connect();
2031 
2032  // drop all tables of the target db
2033  $tarTables = $target->db->query("SHOW TABLES");
2034  foreach($tarTables->fetchAll() as $cTable)
2035  {
2036  $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2037  }
2038 
2039  foreach($srcTables->fetchAll() as $cTable){
2040  $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2041  $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
2042  if(!$create) {
2043  $error = true;
2044  }
2045  $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM ".$source->getDbName().".".$cTable[0]);
2046  }
2047 
2048  $target->db->query("UPDATE settings SET VALUE = ".$target->db->quote(0, "integer")." WHERE keyword = ".$target->db->quote("inst_id", "text"));
2049  $target->db->query("UPDATE settings SET VALUE = ".$target->db->quote(0, "integer")." WHERE keyword = ".$target->db->quote("nic_enabled", "text"));
2050  return true;
2051  }
2059  public function printProxyStatus($client)
2060  {
2061  require_once './Services/Http/exceptions/class.ilProxyException.php';
2062  $settings = $client->getAllSettings();
2063 
2064  if((bool)$settings['proxy_status'] == true)
2065  {
2066  try
2067  {
2068  $err_str = false;
2069  $wait_timeout = 100;
2070 
2071  $fp = @fsockopen($settings['proxy_host'], $settings['proxy_port'],$err_code,$err_str,$wait_timeout);
2072 
2073  if($err_str)
2074  {
2075  throw new ilProxyException($err_str);
2076  }
2077 
2078  fclose($fp);
2079 
2080  ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
2081 
2082  }
2083  catch(Exception $e)
2084  {
2085  ilUtil::sendFailure($this->lng->txt('proxy_not_connectable') . ": " . $e->getMessage());
2086  }
2087  }
2088 
2089  }
2090 
2091  public function saveProxySettings($proxy_settings)
2092  {
2093  $db = $this->client->getDB();
2094  $proxy_fields = array('proxy_status','proxy_host','proxy_port');
2095 
2096  foreach($proxy_fields as $field)
2097  {
2098  if( isset($proxy_settings[$field]) )
2099  {
2100  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
2101  $res = $db->queryF($query,
2102  array('text', 'text'), array('common', $field));
2103 
2104  $row = array();
2105  while($row = $db->fetchAssoc($res)) break;
2106 
2107  if( count($row) > 0 )
2108  {
2109  $db->update(
2110  'settings',
2111  array(
2112  'value' => array('text', $proxy_settings[$field])
2113  ),
2114  array(
2115  'module' => array('text', 'common'),
2116  'keyword' => array('text', $field)
2117  )
2118  );
2119  }
2120  else
2121  {
2122  $db->insert(
2123  'settings',
2124  array(
2125  'module' => array('text', 'common'),
2126  'keyword' => array('text', $field),
2127  'value' => array('text', $proxy_settings[$field])
2128  )
2129  );
2130  }
2131  }
2132  }
2133  }
2134 
2138  public function hasOpCacheEnabled() {
2139  $ini_get = ini_get('opcache.enable');
2140 
2141  return ($ini_get === 1 OR $ini_get === '1' OR strtolower($ini_get) === 'on');
2142  }
2143 
2150  function isValidClientId($a_client_id)
2151  {
2152  if (!preg_match("/^[A-Za-z0-9]+$/", $a_client_id))
2153  {
2154  return false;
2155  }
2156  return true;
2157  }
2158 
2166  protected function isDirectoryInOther($directory, $other_directory) {
2167  $other_directory = $other_directory."/";
2168 
2169  return !(strpos($directory, $other_directory) !== 0);
2170  }
2171 }
2172 
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet ...
static makeDirParents($a_dir)
Create a new directory and all parent directories.
isAuthenticated()
check if current user is authenticated
__construct($a_auth, $a_auth_type)
constructor
checkClientIni(&$client)
check client ini status
isDirectoryInOther($directory, $other_directory)
Checks if directory is subdirectory of other directory.
checkXsl()
Check MySQL.
getStatus($client=0)
coumpute client status
checkClientLanguages(ilClient $client)
checkCreatable($a_dir=".")
check for permission to create new folders in specified directory
Administrates DB connections in setup.
queryPreliminaries()
preliminaries
$_SESSION["AccountId"]
$result
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
cloneFromSource($source_id)
Clone source client into current client.
checkLogSetup($a_formdata)
check log path
checkWritable()
check for writable directory
isAdmin()
check if current user is admin
testLatex($a_latex_url)
Check latex cgi script.
checkPreliminaries()
check all prliminaries
_ilSetup()
destructor
const IL_PASSWD_CRYPTED
setClient($a_cl)
checkOpcacheSettings()
static is_email($a_email)
This preg-based function checks whether an e-mail address is formally valid.
checkDom()
Check MySQL.
updateNewClient($a_old_client_id)
update client.ini & move data dirs does not work correctly at this time - DISABLED ...
saveProxySettings($proxy_settings)
checkMemoryLimit()
Check Memory Limit.
static getSettingFields()
returns the array of setting fields
Class for proxy related exception handling in ILIAS.
checkIniFileExists()
check if inifile exists
testZip($a_zip_path)
Check zip program.
unzip($a_file, $overwrite=false)
unzip file
testJava($a_java_path)
Check JVM.
checkClientDatabase(ilClient $client)
setPassword($a_password)
set setup master password
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
createDatabase($a_collation="")
create client database
testConvert($a_convert_path)
Check convert program.
isInstalled()
check if client&#39;s db is installed
$r
Definition: example_031.php:79
loginAsAdmin($a_password)
process setup admin login
checkErrorLogSetup($error_log_path)
check error log path
getPassword()
get setup master password
deleteTrailingSlash($a_path)
delete trailing slash of path variables
checkClientContact(&$client)
check client contact data status
ilHttpRequest class
installDatabase()
set the database data
checkPasswordSetup($a_formdata)
check setup password
setSessionSettings($session_settings)
saves session settings to db
loginAsClient($a_auth_data)
process client login
checkCookiesEnabled()
check cookies enabled
saveMasterSetup($a_formdata)
saves intial settings
printProxyStatus($client)
Print proxy settings.
static createDirectory($a_dir, $a_mod=0755)
create directory
init()
init setup load settings from ilias.ini if exists and sets some constants
getError()
get Error message
Database Update class.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$http
Definition: raiseError.php:7
newClient($a_client_id=0)
creates a client object in $this->client
updateMasterSettings($a_formdata)
updates settings
Class ilObjSetupUser A class derived from ilObjUser for authentication purposes in the ILIAS setup...
getSessionSettings()
reads session settings from db
checkToolsSetup($a_formdata)
check pathes to 3rd party software
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
checkFinish(&$client)
check if client setup was finished
checkMySQL()
Check MySQL.
isValidClientId($a_client_id)
Is valid client id.
checkAuth()
check authentication status
checkClientNIC(&$client)
check client nic status
Client Management.
testGhostscript($a_ghostscript_path)
Check ghostscript program.
static escapeShellArg($a_arg)
global $lng
Definition: privfeed.php:17
checkGd()
Check MySQL.
global $ilDB
$preliminaries_result
getSetting($a_keyword)
read one value from settings table
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
checkPHPVersion()
check for PHP version
checkClientProxySettings(ilClient $client)
checkClientSessionSettings(&$client, $a_as_bool=false)
check client session config status
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
checkAccess(&$client)
check client access status
static getInstance()
Single method to reduce footprint (included files, created instances)
INIFile Parser.
testUnzip($a_unzip_path)
Check unzip program.
checkDataDirSetup($a_formdata)
check datadir path
saveNewClient()
saves client.ini & updates client list in ilias.ini
$insert
Setup class.