ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
21  public $ini; // ini file object
22  public $ini_file_path; // full path to setup.ini, containing the client list
23  public $error = ""; // error text
24 
25  public $ini_ilias_exists = false; // control flag ilias.ini
26  public $ini_client_exists = false; // control flag client.ini
27 
28  public $setup_defaults; // ilias.master.ini
29  public $ilias_nic_server = "https://nic.ilias.de/index.php"; // URL to ilias nic server
30 
31  public $preliminaries_result = array(); // preliminaries check results
32  public $preliminaries = true; //
33 
39  public $SQL_FILE = "./setup/sql/ilias3.sql";
40 
46  public $dsn = "";
47 
53  public $db;
54 
55  public $setup_password; // master setup password
56  public $default_client; // client id of default client
57 
58  public $safe_mode; // safe mode enabled (true) or disabled (false)
59  public $safe_mode_exec_dir; // contains exec_dir_path
60 
61  public $auth; // current user is authenticated? (true)
62  public $access_mode; // if "admin", admin functions are enabled
63 
64 
71  public function __construct($a_auth, $a_auth_type)
72  {
73  global $lng;
74 
75  $this->lng = $lng;
76 
77  $this->db_connections = new ilDBConnections();
78 
79  define("ILIAS_MODULE", "setup");
80 
81  $this->auth = ($this->checkAuth()) ? true : false;
82  $this->access_mode = $a_auth_type;
83 
84  // safe mode status & exec_dir
85  if ($this->safe_mode = ini_get("safe_mode")) {
86  $this->safe_mode_exec_dir = ilFile::deleteTrailingSlash(ini_get("safe_mode_exec_dir"));
87  }
88 
89  // set path to ilias.ini
90  $this->ini_file_path = ILIAS_ABSOLUTE_PATH . "/ilias.ini.php";
91  $this->setup_defaults = ILIAS_ABSOLUTE_PATH . "/setup/ilias.master.ini.php";
92 
93  // init setup.ini
94  $this->ini_ilias_exists = $this->init();
95 
96  /*
97  if ($this->ini_ilias_exists)
98  {
99  if ($this->ini->readVariable("log","path") != "")
100  {
101  $log->path = $this->ini->readVariable("log","path");
102  }
103 
104  if ($this->ini->readVariable("log","file") != "")
105  {
106  $log->filename = $this->ini->readVariable("log","file");
107  }
108 
109  if ($this->ini->readVariable("log","enabled") != "")
110  {
111  $log->enabled = $this->ini->readVariable("log","enabled");
112  }
113  }
114  */
115  }
116 
117 
121  public $client;
122 
123 
127  public function setClient($a_cl)
128  {
129  $this->client = $a_cl;
130  }
131 
132 
136  public function getClient()
137  {
138  return $this->client;
139  }
140 
146  public function init()
147  {
148  // load data from setup.ini file
149  $this->ini = new ilIniFile($this->ini_file_path);
150 
151  if (!$this->ini->read()) {
152  $this->ini->GROUPS = parse_ini_file($this->setup_defaults, true);
153  $this->error = get_class($this) . ": " . $this->ini->getError();
154  return false;
155  }
156 
157  $this->setup_password = $this->ini->readVariable("setup", "pass");
158  $this->default_client = $this->ini->readVariable("clients", "default");
159 
160  define("ILIAS_DATA_DIR", $this->ini->readVariable("clients", "datadir"));
161  define("ILIAS_WEB_DIR", $this->ini->readVariable("clients", "path"));
162 
163  return true;
164  }
165 
170  public function saveNewClient()
171  {
172  // save client id to session
173  $_SESSION["ClientId"] = $this->client->getId();
174 
175  // create client
176  if (!$this->client->create()) {
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  public function updateNewClient($a_old_client_id)
193  {
194  return true;
195  //var_dump("<pre>",$this->client,"</pre>");exit;
196  //Error Handling disabled!! caused by missing PEAR
197  if ($a_old_client_id != $this->client->getId()) {
198  $this->saveNewClient();
199 
200  ilUtil::delDir(ILIAS_ABSOLUTE_PATH . "/" . ILIAS_WEB_DIR . "/" . $a_old_client_id);
201  ilUtil::delDir(ILIAS_DATA_DIR . "/" . $a_old_client_id);
202  }
203 
204  //everything okay
205  $this->ini_client_exists = true;
206 
207  return true;
208  }
209 
214  public function createDatabase($a_collation = "")
215  {
216  if ($this->client->getDBSetup()->isDatabaseInstalled()) {
217  $this->error = $this->lng->txt("database_exists");
218 
219  return false;
220  }
221 
222  $db_setup = $this->client->getDBSetup();
223  return $db_setup->createDatabase($a_collation);
224  }
225 
231  public function installDatabase()
232  {
233  if (!$this->client->getDBSetup()->isDatabaseConnectable()) {
234  return false;
235  }
236 
237  if ($this->client->getDBSetup()->installDatabase()) {
238  $this->client->db_installed = true;
239 
240  return true;
241  }
242 
243  return false;
244  }
245 
246 
251  public function checkIniFileExists()
252  {
253  $a = @file_exists($this->INI_FILE);
254  return $a;
255  }
256 
262  public function checkWritable()
263  {
264  clearstatcache();
265  if (is_writable(".")) {
266  $arr["status"] = true;
267  //$cdir = getcwd();
268  //chdir("..");
269  $arr["comment"] = getcwd();
270  //chdir($cdir);
271  } else {
272  $arr["status"] = false;
273  $arr["comment"] = $this->lng->txt("pre_folder_write_error");
274  //$cdir = getcwd();
275  //chdir("..");
276  $arr["comment"] = getcwd() . ": " . $arr["comment"];
277  //chdir($cdir);
278  }
279 
280  return $arr;
281  }
282 
288  public function checkCreatable($a_dir = ".")
289  {
290  clearstatcache();
291  if (@mkdir($a_dir . "/crst879dldsk9d", 0774)) {
292  $arr["status"] = true;
293  $arr["comment"] = "";
294 
295  @rmdir($a_dir . "/crst879dldsk9d");
296  } else {
297  $arr["status"] = false;
298  //$cdir = getcwd();
299  //chdir("..");
300  $arr["comment"] = getcwd() . ": " . $this->lng->txt("pre_folder_create_error");
301  //chdir($cdir);
302  }
303 
304  return $arr;
305  }
306 
311  public function checkCookiesEnabled()
312  {
313  global $sess;
314 
315  if ($sess->usesCookies) {
316  $arr["status"] = true;
317  $arr["comment"] = "";
318  } else {
319  $arr["status"] = false;
320  $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
321  }
322 
323  return $arr;
324  }
325 
330  public function checkPHPVersion()
331  {
332  $version = PHP_VERSION;
333 
334  $arr["status"] = true;
335  $arr["comment"] = "PHP " . $version;
336  if (version_compare($version, '5.3.0', '<')) {
337  $arr["status"] = false;
338  $arr["comment"] = "PHP " . $version . ". " . $this->lng->txt("pre_php_version_too_low");
339  }
340 
341  return $arr;
342  }
343 
348  public function checkMySQL()
349  {
350  global $ilDB;
351 
352  if (function_exists("mysql_query")) {
353  $arr["status"] = true;
354  $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
355  } else {
356  $arr["status"] = false;
357  $arr["comment"] = $this->lng->txt("pre_mysql_missing");
358  }
359 
360  return $arr;
361  }
362 
367  public function checkAuth()
368  {
369  if ($_SESSION["auth"] === true && $_SESSION["auth_path"] == ILIAS_HTTP_PATH) {
370  return true;
371  }
372 
373  return false;
374  }
375 
376 
381  public function checkDom()
382  {
383  global $ilDB;
384 
385  if (class_exists("DOMDocument")) {
386  $arr["status"] = true;
387  } else {
388  $arr["status"] = false;
389  $arr["comment"] = $this->lng->txt("pre_dom_missing");
390  }
391 
392  return $arr;
393  }
394 
399  public function checkXsl()
400  {
401  global $ilDB;
402 
403  if (class_exists("XSLTProcessor")) {
404  $arr["status"] = true;
405  } else {
406  $arr["status"] = false;
407  $arr["comment"] = sprintf(
408  $this->lng->txt("pre_xsl_missing"),
409  "http://php.net/manual/en/book.xsl.php"
410  );
411  }
412 
413  return $arr;
414  }
415 
420  public function checkGd()
421  {
422  global $ilDB;
423 
424  if (function_exists("imagefill") && function_exists("imagecolorallocate")) {
425  $arr["status"] = true;
426  } else {
427  $arr["status"] = false;
428  $arr["comment"] = sprintf(
429  $this->lng->txt("pre_gd_missing"),
430  "http://php.net/manual/en/book.image.php"
431  );
432  }
433 
434  return $arr;
435  }
436 
441  public function checkMemoryLimit()
442  {
443  global $ilDB;
444 
445  $limit = ini_get("memory_limit");
446 
447  $limit_ok = true;
448  if (is_int(strpos($limit, "M"))) {
449  $limit_n = (int) $limit;
450  if ($limit_n < 40) {
451  $limit_ok = false;
452  }
453  }
454 
455  if ($limit_ok) {
456  $arr["status"] = true;
457  $arr["comment"] = $limit . ". " . $this->lng->txt("pre_memory_limit_recommend");
458  } else {
459  $arr["status"] = false;
460  $arr["comment"] = $limit . ". " . $this->lng->txt("pre_memory_limit_too_low");
461  }
462 
463  return $arr;
464  }
465 
466 
470  protected function checkOpcacheSettings()
471  {
472  $arr = array();
473  // correct-with-php5-removal FSX start
474  if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
475  $arr["status"] = true;
476 
477  return $arr;
478  }
479  // correct-with-php5-removal FSX end
480 
481  $load_comments = ini_get("opcache.load_comments");
482  if ($load_comments == 1) {
483  $arr["status"] = true;
484  } else {
485  $arr["status"] = false;
486  $arr["comment"] = $this->lng->txt("pre_opcache_comments");
487  }
488 
489  return $arr;
490  }
491 
499  public function queryPreliminaries()
500  {
501  $a = array();
502  $a["php"] = $this->checkPHPVersion();
503  // $a["mysql"] = $this->checkMySQL();
504  $a["root"] = $this->checkWritable();
505  $a["folder_create"] = $this->checkCreatable();
506  $a["cookies_enabled"] = $this->checkCookiesEnabled();
507  $a["dom"] = $this->checkDom();
508  $a["xsl"] = $this->checkXsl();
509  $a["gd"] = $this->checkGd();
510  $a["memory"] = $this->checkMemoryLimit();
511 
512  if ($this->hasOpCacheEnabled()) {
513  $a["load_comments"] = $this->checkOpcacheSettings();
514  }
515 
516  return $a;
517  }
518 
523  public function checkPreliminaries()
524  {
525  $this->preliminaries_result = $this->queryPreliminaries();
526 
527  foreach ($this->preliminaries_result as $val) {
528  if ($val["status"] === false) {
529  $this->preliminaries = false;
530  return false;
531  }
532  }
533 
534  return true;
535  }
536 
541  public function getPassword()
542  {
543  return $this->ini->readVariable("setup", "pass");
544  }
545 
551  public function setPassword($a_password)
552  {
553  $this->ini->setVariable("setup", "pass", md5($a_password));
554 
555  if ($this->ini->write() == false) {
556  $this->error = $this->ini->getError();
557  return false;
558  }
559 
560  return true;
561  }
562 
568  public function loginAsClient($a_auth_data)
569  {
570  global $ilDB;
571 
572  if (empty($a_auth_data["client_id"])) {
573  $this->error = "no_client_id";
574  return false;
575  }
576 
577  if (empty($a_auth_data["username"])) {
578  $this->error = "no_username";
579  return false;
580  }
581 
582  if (empty($a_auth_data["password"])) {
583  $this->error = "no_password";
584  return false;
585  }
586 
587  if (!$this->newClient($a_auth_data["client_id"])) { //TT: comment out to get around null db
588  $this->error = "unknown_client_id";
589  unset($this->client);
590  return false;
591  }
592 
593  if (!$this->client->db_exists) {
594  $this->error = "no_db_connect_consult_admin";
595  unset($this->client);
596  return false;
597  }
598 
599  $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = " .
600  $this->client->db->quote('system_role_id', 'text'));
601  $r1 = $this->client->db->fetchAssoc($s1);
602  $system_role_id = $r1["value"];
603 
604  $add_usrfields = '';
605  if ($this->client->db->tableColumnExists('usr_data', 'passwd_enc_type')) {
606  $add_usrfields .= ' , usr_data.passwd_enc_type, usr_data.passwd_salt ';
607  }
608  $q = "SELECT usr_data.usr_id, usr_data.passwd $add_usrfields " .
609  "FROM usr_data " .
610  "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id " .
611  "WHERE rbac_ua.rol_id = " . $this->client->db->quote((int) $system_role_id, 'integer') . " " .
612  "AND usr_data.login=" . $this->client->db->quote($a_auth_data["username"], 'text');
613  $r = $this->client->db->query($q);
614  if (!$this->client->db->numRows($r)) {
615  $this->error = 'login_invalid';
616  return false;
617  }
618 
619  $data = $this->client->db->fetchAssoc($r);
620 
621  global $ilClientIniFile;
622 
623  $ilClientIniFile = $this->client->ini;
624 
625  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
626  $crypt_type = ilUserPasswordManager::getInstance()->getEncoderName();
627  if (strlen($add_usrfields) && ilUserPasswordManager::getInstance()->isEncodingTypeSupported($crypt_type)) {
628  require_once 'setup/classes/class.ilObjSetupUser.php';
629  $user = new ilObjSetupUser();
630  $user->setPasswd($data['passwd'], IL_PASSWD_CRYPTED);
631  $user->setPasswordEncodingType($data['passwd_enc_type']);
632  $user->setPasswordSalt($data['passwd_salt']);
633 
634  $password_valid = ilUserPasswordManager::getInstance()->verifyPassword($user, $a_auth_data['password']);
635  } else {
636  $password_valid = $data['passwd'] == md5($a_auth_data['password']);
637  }
638 
639  if ($password_valid) {
640  // all checks passed -> user valid
641  $_SESSION['auth'] = true;
642  $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
643  $_SESSION['access_mode'] = 'client';
644  $_SESSION['ClientId'] = $this->client->getId();
645  return true;
646  } else {
647  $this->error = 'login_invalid';
648  return false;
649  }
650  }
651 
657  public function loginAsAdmin($a_password)
658  {
659  $a_password = md5($a_password);
660 
661  if ($this->ini->readVariable("setup", "pass") == $a_password) {
662  $_SESSION["auth"] = true;
663  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
664  $_SESSION["access_mode"] = "admin";
665  return true;
666  }
667 
668  return false;
669  }
670 
676  public function newClient($a_client_id = 0)
677  {
678  if (!$this->isInstalled()) {
679  return false;
680  }
681 
682  $this->client = new ilClient($a_client_id, $this->db_connections);
683 
684  if (!$this->client->init()) {
685  //echo "<br>noclientinit";
686  $this->error = get_class($this) . ": " . $this->client->getError();
687  $_SESSION["ClientId"] = "";
688  return false;
689  }
690 
691  $_SESSION["ClientId"] = $a_client_id;
692 
693  return true;
694  }
695 
701  public function getStatus($client = 0)
702  {
703  if (!is_object($client)) {
704  if ($this->ini_client_exists) {
706  } else {
707  $client = new ilClient(0, $this->db_connections);
708  }
709  }
710 
711  $status = array();
712  $status["ini"] = $this->checkClientIni($client); // check this one
713  $status["db"] = $this->checkClientDatabase($client);
714  if ($status["db"]["status"] === false and $status["db"]["update"] !== true) {
715  //$status["sess"]["status"] = false;
716  //$status["sess"]["comment"] = $status["db"]["comment"];
717  $status["lang"]["status"] = false;
718  $status["lang"]["comment"] = $status["db"]["comment"];
719  $status["contact"]["status"] = false;
720  $status["contact"]["comment"] = $status["db"]["comment"];
721 
722  $status["proxy"]["status"] = false;
723  $status["proxy"]["comment"] = $status["db"]["comment"];
724 
725  $status["nic"]["status"] = false;
726  $status["nic"]["comment"] = $status["db"]["comment"];
727  } else {
728  //$status["sess"] = $this->checkClientSessionSettings($client);
729  $status["lang"] = $this->checkClientLanguages($client);
730  $status["contact"] = $this->checkClientContact($client);
731  $status["proxy"] = $this->checkClientProxySettings($client);
732  $status["nic"] = $this->checkClientNIC($client);
733  $status["finish"] = $this->checkFinish($client);
734  $status["access"] = $this->checkAccess($client);
735  }
736 
737  //return value
738  return $status;
739  }
740 
746  public function checkFinish(&$client)
747  {
748  if ($client->getSetting("setup_ok")) {
749  $arr["status"] = true;
750  //$arr["comment"] = $this->lng->txt("setup_finished");
751  } else {
752  $arr["status"] = false;
753  $arr["comment"] = $this->lng->txt("setup_not_finished");
754  }
755 
756  return $arr;
757  }
758 
764  public function checkAccess(&$client)
765  {
766  if ($client->ini->readVariable("client", "access") == "1") {
767  $arr["status"] = true;
768  $arr["comment"] = $this->lng->txt("online");
769  } else {
770  $arr["status"] = false;
771  $arr["comment"] = $this->lng->txt("disabled");
772  }
773 
774  return $arr;
775  }
776 
782  public function checkClientIni(&$client)
783  {
784  if (!$arr["status"] = $client->init()) {
785  $arr["comment"] = $client->getError();
786  } else {
787  //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
788  }
789 
790  return $arr;
791  }
792 
793 
799  {
800  $arr = array();
801  $client->provideGlobalDB();
802  if (!$arr["status"] = $client->db_exists) {
803  $arr["comment"] = $this->lng->txt("no_database");
804 
805  return $arr;
806  }
807 
808  if (!$arr["status"] = $client->db_installed) {
809  $arr["comment"] = $this->lng->txt("db_not_installed");
810 
811  return $arr;
812  }
813  // TODO: move this to client class!!
814  $client->setup_ok = (bool) $client->getSetting("setup_ok");
815 
816  include_once "./Services/Database/classes/class.ilDBUpdate.php";
817  $this->lng->setDbHandler($client->db);
818  $dbupdate = new ilDBUpdate($client->db);
819 
820  if (!$arr["status"] = $dbupdate->getDBVersionStatus()) {
821  $arr["comment"] = $this->lng->txt("db_needs_update");
822  $arr["update"] = true;
823 
824  return $arr;
825  } else {
826  if ($dbupdate->hotfixAvailable()) {
827  $arr["status"] = false;
828  $arr["comment"] = $this->lng->txt("hotfix_available");
829  $arr["update"] = true;
830 
831  return $arr;
832  } else {
833  if ($dbupdate->customUpdatesAvailable()) {
834  $arr["status"] = false;
835  $arr["comment"] = $this->lng->txt("custom_updates_available");
836  $arr["update"] = true;
837 
838  return $arr;
839  }
840  }
841  }
842 
843  // check control information
844  global $ilDB;
845  $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
846  $crec = $ilDB->fetchAssoc($cset);
847  $client->revokeGlobalDB();
848  if ($crec["cnt"] == 0) {
849  $arr["status"] = false;
850  $arr["comment"] = $this->lng->txt("db_control_structure_missing");
851  $arr["update"] = true;
852 
853  return $arr;
854  }
855 
856  return $arr;
857  }
858 
864  public function checkClientSessionSettings(&$client, $a_as_bool = false)
865  {
866  require_once('Services/Authentication/classes/class.ilSessionControl.php');
867 
868  global $ilDB;
869  $db = $ilDB;
870 
872 
873  $query = "SELECT keyword, value FROM settings WHERE " . $db->in('keyword', $fields, false, 'text');
874  $res = $db->query($query);
875 
876  $rows = array();
877  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
878  if ($row['value'] != '') {
879  $rows[] = $row;
880  } else {
881  break;
882  }
883  }
884 
885  if (count($rows) != count($fields)) {
886  if ($a_as_bool) {
887  return false;
888  }
889  $arr["status"] = false;
890  $arr["comment"] = $this->lng->txt("session_management_not_configured");
891  } else {
892  if ($a_as_bool) {
893  return true;
894  }
895  $arr["status"] = true;
896  $arr["comment"] = $this->lng->txt("session_management_configured");
897  }
898 
899  return $arr;
900  }
901 
902 
908  {
909  $client->provideGlobalDB();
910  global $ilDB;
911  $arr = array();
912  $fields = array( 'proxy_status', 'proxy_host', 'proxy_port' );
913 
914  $query = "SELECT keyword, value FROM settings WHERE " . $ilDB->in('keyword', $fields, false, 'text');
915  $res = $ilDB->query($query);
916 
917  $proxy_settings = array();
918  $already_saved = false;
919  while ($row = $ilDB->fetchAssoc($res)) {
920  $already_saved = true;
921  $proxy_settings[$row['keyword']] = $row['value'];
922  }
923 
924  if (!$already_saved) {
925  $arr["status"] = false;
926  $arr["comment"] = $this->lng->txt("proxy");
927  $arr["text"] = $this->lng->txt("proxy");
928  } else {
929  if ((bool) $proxy_settings["proxy_status"] == false) {
930  $arr["status"] = true;
931  $arr["comment"] = $this->lng->txt("proxy_disabled");
932  $arr["text"] = $this->lng->txt("proxy_disabled");
933  } else {
934  $arr["status"] = true;
935  $arr["comment"] = $this->lng->txt("proxy_activated_configurated");
936  $arr["text"] = $this->lng->txt("proxy_activated_configurated");
937  }
938  }
939 
940  return $arr;
941  }
942 
943 
949  {
950  $client->provideGlobalDB();
951  $installed_langs = $this->lng->getInstalledLanguages();
952 
953  $count = count($installed_langs);
954  $arr = array();
955  if ($count < 1) {
956  $arr["status"] = false;
957  $arr["comment"] = $this->lng->txt("lang_none_installed");
958  } else {
959  $arr["status"] = true;
960  //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
961  }
962  $client->revokeGlobalDB();
963  return $arr;
964  }
965 
971  public function checkClientContact(&$client)
972  {
973  $arr["status"] = true;
974  //$arr["comment"] = $this->lng->txt("filled_out");
975 
976  $settings = $client->getAllSettings();
977  $client_name = $client->getName();
978 
979  // check required fields
980  if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
981  empty($settings["admin_email"]) or empty($client_name)) {
982  $arr["status"] = false;
983  $arr["comment"] = $this->lng->txt("missing_data");
984  }
985 
986  // admin email
987  if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false) {
988  $arr["status"] = false;
989  $arr["comment"] = $this->lng->txt("email_not_valid");
990  }
991 
992  return $arr;
993  }
994 
1000  public function checkClientNIC(&$client)
1001  {
1002  $settings = $client->getAllSettings();
1003 
1004  if (!isset($settings["nic_enabled"])) {
1005  $arr["status"] = false;
1006  $arr["comment"] = $this->lng->txt("nic_not_disabled");
1007  return $arr;
1008  }
1009 
1010  $arr["status"] = true;
1011 
1012  if ($settings["nic_enabled"] == "-1") {
1013  $arr["comment"] = $this->lng->txt("nic_reg_failed");
1014  return $arr;
1015  }
1016 
1017  if (!$settings["nic_enabled"]) {
1018  $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1019  } else {
1020  $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1021  if ($settings["inst_id"] <= 0) {
1022  $arr["status"] = false;
1023  }
1024  }
1025 
1026  return $arr;
1027  }
1028 
1033  public function isInstalled()
1034  {
1035  return $this->ini_ilias_exists;
1036  }
1037 
1042  public function isAuthenticated()
1043  {
1044  return $this->auth;
1045  }
1046 
1051  public function isAdmin()
1052  {
1053  return ($this->access_mode == "admin") ? true : false;
1054  }
1055 
1061  public function saveMasterSetup($a_formdata)
1062  {
1063  $datadir_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1064 
1065  if ($a_formdata["chk_datadir_path"] == 1) { // mode create dir
1066  if (!ilUtil::makeDir($datadir_path)) {
1067  $this->error = "create_datadir_failed";
1068  return false;
1069  }
1070  }
1071 
1072  // create webspace dir if it does not exist
1073  if (!@file_exists(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path")) and !@is_dir(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path"))) {
1074  if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path"))) {
1075  $this->error = "create_webdir_failed";
1076  return false;
1077  }
1078  }
1079 
1080  $form_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1081  $log_path = substr($form_log_path, 0, strrpos($form_log_path, "/"));
1082  $log_file = substr($form_log_path, strlen($log_path)+1);
1083  $error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1084 
1085  $this->ini->setVariable("server", "http_path", ILIAS_HTTP_PATH);
1086  $this->ini->setVariable("server", "absolute_path", ILIAS_ABSOLUTE_PATH);
1087  $this->ini->setVariable("server", "timezone", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["time_zone"])));
1088  $this->ini->setVariable("clients", "datadir", $datadir_path);
1089  $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"])));
1090  $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"])));
1091  $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"])));
1092  $this->ini->setVariable("tools", "ghostscript", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"])));
1093  $this->ini->setVariable("tools", "java", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"])));
1094  //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1095  $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1096  $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1097  $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1098  $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["scan_command"])));
1099  $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["clean_command"])));
1100  $this->ini->setVariable("tools", "enable_system_styles_management", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["enable_system_styles_management"])));
1101  $this->ini->setVariable("tools", "lessc", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["lessc_path"])));
1102  $this->ini->setVariable("tools", "phantomjs", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["phantomjs_path"])));
1103 
1104  $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
1105  $this->ini->setVariable("log", "path", $log_path);
1106  $this->ini->setVariable("log", "file", $log_file);
1107  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1108  $this->ini->setVariable("log", "error_path", $error_log_path);
1109 
1110  $this->ini->setVariable("https", "auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1111  $this->ini->setVariable("https", "auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1112  $this->ini->setVariable("https", "auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1113 
1114  if (!$this->ini->write()) {
1115  $this->error = get_class($this) . ": " . $this->ini->getError();
1116  return false;
1117  }
1118 
1119  // everything is fine. so we authenticate the user and set access mode to 'admin'
1120  $_SESSION["auth"] = true;
1121  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1122  $_SESSION["access_mode"] = "admin";
1123 
1124  return true;
1125  }
1126 
1132  public function updateMasterSettings($a_formdata)
1133  {
1134  $convert_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"]));
1135  $zip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"]));
1136  $unzip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"]));
1137  $ghostscript_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1138  $java_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"]));
1139  //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1140  $ffmpeg_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1141  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1142  $fop_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["fop_path"]));
1143  $scan_type = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1144  $scan_command = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["scan_command"]));
1145  $clean_command = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["clean_command"]));
1146  $enable_system_styles_management = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["enable_system_styles_management"]));
1147  $lessc_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["lessc_path"]));
1148  $phantomjs_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["phantomjs_path"]));
1149 
1150  $this->ini->setVariable("tools", "convert", $convert_path);
1151  $this->ini->setVariable("tools", "zip", $zip_path);
1152  $this->ini->setVariable("tools", "unzip", $unzip_path);
1153  $this->ini->setVariable("tools", "ghostscript", $ghostscript_path);
1154  $this->ini->setVariable("tools", "java", $java_path);
1155  //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1156  $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1157  $this->ini->setVariable("tools", "latex", $latex_url);
1158  $this->ini->setVariable("tools", "fop", $fop_path);
1159  $this->ini->setVariable("tools", "vscantype", $scan_type);
1160  $this->ini->setVariable("tools", "scancommand", $scan_command);
1161  $this->ini->setVariable("tools", "cleancommand", $clean_command);
1162  $this->ini->setVariable("tools", "lessc", $lessc_path);
1163  $this->ini->setVariable("tools", "enable_system_styles_management", $enable_system_styles_management);
1164  $this->ini->setVariable("tools", "phantomjs", $phantomjs_path);
1165 
1166  $form_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1167  $log_path = substr($form_log_path, 0, strrpos($form_log_path, "/"));
1168  $log_file = substr($form_log_path, strlen($log_path)+1);
1169 
1170  $error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1171 
1172  $this->ini->setVariable("log", "path", $log_path);
1173  $this->ini->setVariable("log", "file", $log_file);
1174  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1175  $this->ini->setVariable("log", "error_path", $error_log_path);
1176  $this->ini->setVariable("server", "timezone", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["time_zone"])));
1177 
1178  $this->ini->setVariable("https", "auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1179  $this->ini->setVariable("https", "auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1180  $this->ini->setVariable("https", "auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1181 
1182  if (!$this->ini->write()) {
1183  $this->error = get_class($this) . ": " . $this->ini->getError();
1184  return false;
1185  }
1186 
1187  return true;
1188  }
1189 
1195  public function checkToolsSetup($a_formdata)
1196  {
1197  // convert path
1198  if (!isset($a_formdata["chk_convert_path"])) {
1199  // convert backslashes to forwardslashes
1200  $convert_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"]));
1201 
1202  if (($err = $this->testConvert($convert_path)) != "") {
1203  $this->error = $err;
1204  return false;
1205  }
1206  }
1207 
1208  // zip path
1209  if (!isset($a_formdata["chk_zip_path"])) {
1210  // convert backslashes to forwardslashes
1211  $zip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"]));
1212 
1213  if (empty($zip_path)) {
1214  $this->error = "no_path_zip";
1215  return false;
1216  }
1217 
1218  if (!$this->testZip($zip_path)) {
1219  $this->error = "check_failed_zip";
1220  return false;
1221  }
1222  }
1223 
1224  // unzip path
1225  if (!isset($a_formdata["chk_unzip_path"])) {
1226  // convert backslashes to forwardslashes
1227  $unzip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"]));
1228 
1229  if (empty($unzip_path)) {
1230  $this->error = "no_path_unzip";
1231  return false;
1232  }
1233 
1234  if (!$this->testUnzip($unzip_path)) {
1235  $this->error = "check_failed_unzip";
1236  return false;
1237  }
1238  }
1239 
1240  // ghostscript path
1241  if (!isset($a_formdata["chk_ghostscript_path"])) {
1242  // convert backslashes to forwardslashes
1243  $ghostscript_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1244 
1245  if (($err = $this->testGhostscript($ghostscript_path)) != "") {
1246  $this->error = $err;
1247  return false;
1248  }
1249  }
1250 
1251  // java path
1252  if (!isset($a_formdata["chk_java_path"])) {
1253  // convert backslashes to forwardslashes
1254  $java_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"]));
1255 
1256  if (empty($java_path)) {
1257  $this->error = "no_path_java";
1258  return false;
1259  }
1260 
1261  if (!$this->testJava($java_path)) {
1262  $this->error = "check_failed_java";
1263  return false;
1264  }
1265  }
1266 
1267  /*if (!isset($a_formdata["chk_mkisofs_path"]))
1268  {
1269  // convert backslashes to forwardslashes
1270  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1271 
1272  if (empty($mkisofs_path))
1273  {
1274  $this->error = "no_path_mkisofs";
1275  return false;
1276  }
1277  }*/
1278 
1279  if (!isset($a_formdata["chk_ffmpeg_path"])) {
1280  // convert backslashes to forwardslashes
1281  $ffmpeg_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1282 
1283  if (empty($ffmpeg_path)) {
1284  $this->error = "no_path_ffmpeg";
1285  return false;
1286  }
1287 
1288  if (!$this->testFFMpeg($ffmpeg_path)) {
1289  $this->error = "check_failed_ffmpeg";
1290  return false;
1291  }
1292  }
1293 
1294  // latex url
1295  if (!isset($a_formdata["chk_latex_url"])) {
1296  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1297  if (empty($latex_url)) {
1298  $this->error = "no_latex_url";
1299  return false;
1300  }
1301 
1302  if (!$this->testLatex($latex_url)) {
1303  $this->error = "check_failed_latex";
1304  return false;
1305  }
1306  }
1307 
1308  return true;
1309  }
1310 
1316  public function checkDataDirSetup($a_formdata)
1317  {
1318  // remove trailing slash & convert backslashes to forwardslashes
1319  $datadir_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1320 
1321  if (empty($datadir_path)) {
1322  $this->error = "no_path_datadir";
1323  return false;
1324  }
1325 
1326  $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1327 
1328  // datadir may not point to webspace dir or to any place under webspace_dir
1329  if (strpos($datadir_path, $webspace_dir) !== false) {
1330  $this->error = "datadir_webspacedir_match";
1331  return false;
1332  }
1333 
1334  // create dir
1335  if ($a_formdata["chk_datadir_path"] == 1) {
1336  $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1337  $dir_to_check = substr($datadir_path, 0, -strlen($dir_to_create)-1);
1338 
1339  if ($this->isDirectoryInOther($dir_to_create, ILIAS_ABSOLUTE_PATH)) {
1340  $this->error = "cannot_create_datadir_inside_webdir";
1341  return false;
1342  }
1343 
1344  if (is_writable($datadir_path)) {
1345  $this->error = "dir_exists_create";
1346  return false;
1347  }
1348 
1349  if (!is_writable($dir_to_check)) {
1350  $this->error = "cannot_create_datadir_no_write_access";
1351  return false;
1352  }
1353  } else { // check set target dir
1354  if ($this->isDirectoryInOther($datadir_path, ILIAS_ABSOLUTE_PATH)) {
1355  $this->error = "cannot_create_datadir_inside_webdir";
1356  return false;
1357  }
1358 
1359  if (!is_writable($datadir_path)) {
1360  $this->error = "cannot_create_datadir_no_write_access";
1361  return false;
1362  }
1363  }
1364 
1365  return true;
1366  }
1367 
1373  public function checkPasswordSetup($a_formdata)
1374  {
1375  if (!$a_formdata["setup_pass"]) {
1376  $this->error = "no_setup_pass_given";
1377  return false;
1378  }
1379 
1380  if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"]) {
1381  $this->error = "pass_does_not_match";
1382  return false;
1383  }
1384 
1385  return true;
1386  }
1387 
1393  public function checkLogSetup($a_formdata)
1394  {
1395  // log path
1396  if (!$a_formdata["chk_log_status"]) {
1397  // remove trailing slash & convert backslashes to forwardslashes
1398  $log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1399 
1400  if (empty($log_path)) {
1401  $this->error = "no_path_log";
1402  return false;
1403  }
1404 
1405  if (is_dir($log_path)) {
1406  $this->error = 'could_not_create_logfile';
1407  return false;
1408  }
1409 
1410  if ($this->isDirectoryInOther($log_path, ILIAS_ABSOLUTE_PATH)) {
1411  $this->error = "cannot_create_logdir_inside_webdir";
1412  return false;
1413  }
1414 
1415  if (!@touch($log_path)) {
1416  $this->error = "could_not_create_logfile";
1417  return false;
1418  }
1419  }
1420 
1421  return true;
1422  }
1423 
1431  public function checkErrorLogSetup($error_log_path)
1432  {
1433  // remove trailing slash & convert backslashes to forwardslashes
1434  $clean_error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($error_log_path)));
1435 
1436  if (!empty($clean_error_log_path)) {
1437  if (!ilUtil::makeDirParents($clean_error_log_path)) {
1438  $this->error = "could_not_create_error_directory";
1439  return false;
1440  }
1441  }
1442 
1443  return true;
1444  }
1445 
1450  public function getError()
1451  {
1452  if (empty($this->error)) {
1453  return false;
1454  }
1455 
1456  $error = $this->error;
1457  $this->error = "";
1458 
1459  return $error;
1460  }
1461 
1467  public function _ilSetup()
1468  {
1469  //if ($this->ini->readVariable("db","type") != "")
1470  //{
1471  // $this->db->disconnect();
1472  //}
1473  return true;
1474  }
1475 
1482  public function testConvert($a_convert_path)
1483  {
1484  if (trim($a_convert_path) == "") {
1485  return "no_path_convert";
1486  }
1487  if (!is_file($a_convert_path)) {
1488  return "check_failed_convert";
1489  }
1490 
1491  return "";
1492  }
1493 
1500  public function testGhostscript($a_ghostscript_path)
1501  {
1502  // ghostscript is optional, so empty path is ok
1503  if (trim($a_ghostscript_path) == "") {
1504  return "";
1505  }
1506  if (!is_file($a_ghostscript_path)) {
1507  return "check_failed_ghostscript";
1508  }
1509 
1510  return "";
1511  }
1512 
1519  public function testJava($a_java_path)
1520  {
1521  // java is optional, so empty path is ok
1522  if (trim($a_java_path) == "") {
1523  return "";
1524  }
1525 
1526  if (!is_file($a_java_path)) {
1527  return "check_failed_java";
1528  }
1529 
1530  return "";
1531  /*
1532  exec($a_java_path, $out, $back);
1533 
1534  unset($out);
1535 
1536  return ($back != 1) ? false : true;
1537  */
1538  }
1539 
1546  public function testLatex($a_latex_url)
1547  {
1548  // latex is optional, so empty path is ok
1549  if (trim($a_latex_url) == "") {
1550  return "";
1551  }
1552 
1553  // open the URL
1554  include_once "./setup/classes/class.ilHttpRequest.php";
1555  $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1556  $result = @$http->downloadToString();
1557  if ((strpos((substr($result, 0, 5)), "PNG") !== false) || (strpos((substr($result, 0, 5)), "GIF") !== false)) {
1558  return "";
1559  } else {
1560  return "check_failed_latex";
1561  ;
1562  }
1563  }
1564 
1571  public function testZip($a_zip_path)
1572  {
1573  if (trim($a_zip_path) == "") {
1574  return "no_path_zip";
1575  }
1576  if (!is_file($a_zip_path)) {
1577  return "check_failed_zip";
1578  }
1579 
1580  return "";
1581  /*
1582  // create test file and run zip
1583  $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1584 
1585  fwrite($fp, "test");
1586  fclose($fp);
1587 
1588  if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1589  {
1590  $curDir = getcwd();
1591  chdir(ILIAS_ABSOLUTE_PATH);
1592 
1593  $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1594 
1595  exec($zipCmd);
1596 
1597  chdir($curDir);
1598 
1599  }
1600 
1601  // check wether zip generated test file or not
1602  if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1603  {
1604  unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1605  return true;
1606  }
1607  else
1608  {
1609  unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1610  return false;
1611  }
1612  */
1613  }
1614 
1615 
1622  public function testUnzip($a_unzip_path)
1623  {
1624  if (trim($a_unzip_path) == "") {
1625  return "no_path_unzip";
1626  }
1627  if (!is_file($a_unzip_path)) {
1628  return "check_failed_unzip";
1629  }
1630 
1631  return "";
1632  /*
1633  $curDir = getcwd();
1634 
1635  chdir(ILIAS_ABSOLUTE_PATH);
1636 
1637  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1638  {
1639  $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1640  exec($unzipCmd);
1641  }
1642 
1643  chdir($curDir);
1644 
1645  // check wether unzip extracted the test file or not
1646  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1647  {
1648  unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1649 
1650  return true;
1651  }
1652  else
1653  {
1654  return false;
1655  }
1656  */
1657  }
1658 
1665  public function unzip($a_file, $overwrite = false)
1666  {
1667  //global $ilias;
1668 
1669  $pathinfo = pathinfo($a_file);
1670  $dir = $pathinfo["dirname"];
1671  $file = $pathinfo["basename"];
1672 
1673  // unzip
1674  $cdir = getcwd();
1675  chdir($dir);
1676  $unzip = $this->ini->readVariable("tools", "unzip");
1677  $unzipcmd = $unzip . " -Z -1 " . ilUtil::escapeShellArg($file);
1678  exec($unzipcmd, $arr);
1679  $zdirs = array();
1680 
1681  foreach ($arr as $line) {
1682  if (is_int(strpos($line, "/"))) {
1683  $zdir = substr($line, 0, strrpos($line, "/"));
1684  $nr = substr_count($zdir, "/");
1685  //echo $zdir." ".$nr."<br>";
1686  while ($zdir != "") {
1687  $nr = substr_count($zdir, "/");
1688  $zdirs[$zdir] = $nr; // collect directories
1689  //echo $dir." ".$nr."<br>";
1690  $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1691  }
1692  }
1693  }
1694 
1695  asort($zdirs);
1696 
1697  foreach ($zdirs as $zdir => $nr) { // create directories
1698  ilUtil::createDirectory($zdir);
1699  }
1700 
1701  // real unzip
1702  if ($overvwrite) {
1703  $unzipcmd = $unzip . " " . ilUtil::escapeShellArg($file);
1704  } else {
1705  $unzipcmd = $unzip . " -o " . ilUtil::escapeShellArg($file);
1706  }
1707  exec($unzipcmd);
1708 
1709  chdir($cdir);
1710  }
1711 
1717  public function setSessionSettings($session_settings)
1718  {
1719  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1720 
1721  $db = $this->client->getDB();
1722 
1723  $setting_fields = ilSessionControl::getSettingFields();
1724 
1725  $i = 0;
1726  foreach ($setting_fields as $field) {
1727  if (isset($session_settings[$field])) {
1728  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1729  $res = $db->queryF(
1730  $query,
1731  array('text', 'text'),
1732  array('common', $field)
1733  );
1734 
1735  $row = array();
1736  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1737  break;
1738  }
1739 
1740  if (count($row) > 0) {
1741  $db->update(
1742  'settings',
1743  array(
1744  'value' => array('text', $session_settings[$field])
1745  ),
1746  array(
1747  'module' => array('text', 'common'),
1748  'keyword' => array('text', $field)
1749  )
1750  );
1751  } else {
1752  $db->insert(
1753  'settings',
1754  array(
1755  'module' => array('text', 'common'),
1756  'keyword' => array('text', $field),
1757  'value' => array('text', $session_settings[$field])
1758  )
1759  );
1760  }
1761 
1762  $i++;
1763  }
1764  }
1765 
1766  if ($i < 4) {
1767  $message = $this->lng->txt("session_settings_not_saved");
1768  } else {
1769  $message = $this->lng->txt("settings_saved");
1770  }
1771 
1773  }
1774 
1780  public function getSessionSettings()
1781  {
1782  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1783 
1784  $db = $this->client->getDB();
1785 
1786  $setting_fields = ilSessionControl::getSettingFields();
1787 
1788  $query = "SELECT * FROM settings WHERE module = %s " .
1789  "AND " . $db->in('keyword', $setting_fields, false, 'text');
1790 
1791  $res = $db->queryF($query, array('text'), array('common'));
1792 
1793  $session_settings = array();
1794  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1795  $session_settings[$row['keyword']] = $row['value'];
1796  }
1797 
1798  foreach ($setting_fields as $field) {
1799  if (!isset($session_settings[$field])) {
1800  $value = 1;
1801 
1802  switch ($field) {
1803  case 'session_max_count':
1804 
1806  break;
1807 
1808  case 'session_min_idle':
1809 
1811  break;
1812 
1813  case 'session_max_idle':
1814 
1816  break;
1817 
1818  case 'session_max_idle_after_first_request':
1819 
1821  break;
1822 
1823  case 'session_allow_client_maintenance':
1824 
1826  break;
1827  }
1828 
1829  $session_settings[$field] = $value;
1830  }
1831  }
1832 
1833  return $session_settings;
1834  }
1835 
1841  public function cloneFromSource($source_id)
1842  {
1843  // Getting source and targets
1844  $source = new ilClient($source_id, $this->db_connections);
1845  $source->init();
1847 
1848  // ************************************************
1849  // ** COPY FILES
1850 
1851  // Cleaning up datadir
1852  if (!ilUtil::delDir($target->getDataDir())) {
1853  $this->error = "Could not delete data dir $target->getDataDir()";
1854  //return false;
1855  }
1856 
1857  // Create empty datadir
1858  if (!ilUtil::makeDir($target->getDataDir())) {
1859  $this->error = "could_not_create_base_data_dir :" . $target->getDataDir();
1860  return false;
1861  }
1862 
1863  // Copying datadir
1864  if (!ilUtil::rCopy($source->getDataDir(), $target->getDataDir())) {
1865  $this->error = "clone_datadircopyfail";
1866  $target->ini->write();
1867  return false;
1868  }
1869 
1870  // Cleaning up Webspacedir
1871  if (!ilUtil::delDir($target->getWebspaceDir())) {
1872  $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
1873  //return false;
1874  }
1875 
1876  // Create empty Webspacedir
1877  if (!ilUtil::makeDir($target->getWebspaceDir())) {
1878  $this->error = "could_not_create_base_webspace_dir :" . $target->getWebspaceDir();
1879  return false;
1880  }
1881 
1882  // Copying Webspacedir
1883  if (!ilUtil::rCopy($source->getWebspaceDir(), $target->getWebspaceDir())) {
1884  $this->error = "clone_websipacedircopyfail";
1885  $target->ini->write();
1886  return false;
1887  }
1888 
1889  // Restore ini file
1890  $target->ini->write();
1891 
1892  // ************************************************
1893  // ** COPY DATABASE
1894 
1895  $source->connect();
1896  if (!$source->db) {
1897  $this->error = "Source database connection failed.";
1898  return false;
1899  }
1900 
1901  $target->connect();
1902  if (!$target->db) {
1903  $this->error = "Target database connection failed.";
1904  return false;
1905  }
1906 
1907  $source->connect();
1908  $srcTables = $source->db->query("SHOW TABLES");
1909  $target->connect();
1910 
1911  // drop all tables of the target db
1912  $tarTables = $target->db->query("SHOW TABLES");
1913  foreach ($tarTables->fetchAll() as $cTable) {
1914  $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
1915  }
1916 
1917  foreach ($srcTables->fetchAll() as $cTable) {
1918  $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
1919  $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
1920  if (!$create) {
1921  $error = true;
1922  }
1923  $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM " . $source->getDbName() . "." . $cTable[0]);
1924  }
1925 
1926  $target->db->query("UPDATE settings SET VALUE = " . $target->db->quote(0, "integer") . " WHERE keyword = " . $target->db->quote("inst_id", "text"));
1927  $target->db->query("UPDATE settings SET VALUE = " . $target->db->quote(0, "integer") . " WHERE keyword = " . $target->db->quote("nic_enabled", "text"));
1928  return true;
1929  }
1937  public function printProxyStatus($client)
1938  {
1939  require_once './Services/Http/exceptions/class.ilProxyException.php';
1940  $settings = $client->getAllSettings();
1941 
1942  if ((bool) $settings['proxy_status'] == true) {
1943  try {
1944  $err_str = false;
1945  $wait_timeout = 100;
1946 
1947  $fp = @fsockopen($settings['proxy_host'], $settings['proxy_port'], $err_code, $err_str, $wait_timeout);
1948 
1949  if ($err_str) {
1950  throw new ilProxyException($err_str);
1951  }
1952 
1953  fclose($fp);
1954 
1955  ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
1956  } catch (Exception $e) {
1957  ilUtil::sendFailure($this->lng->txt('proxy_not_connectable') . ": " . $e->getMessage());
1958  }
1959  }
1960  }
1961 
1962  public function saveProxySettings($proxy_settings)
1963  {
1964  $db = $this->client->getDB();
1965  $proxy_fields = array('proxy_status','proxy_host','proxy_port');
1966 
1967  foreach ($proxy_fields as $field) {
1968  if (isset($proxy_settings[$field])) {
1969  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1970  $res = $db->queryF(
1971  $query,
1972  array('text', 'text'),
1973  array('common', $field)
1974  );
1975 
1976  $row = array();
1977  while ($row = $db->fetchAssoc($res)) {
1978  break;
1979  }
1980 
1981  if (is_array($row) && count($row) > 0) {
1982  $db->update(
1983  'settings',
1984  array(
1985  'value' => array('text', $proxy_settings[$field])
1986  ),
1987  array(
1988  'module' => array('text', 'common'),
1989  'keyword' => array('text', $field)
1990  )
1991  );
1992  } else {
1993  $db->insert(
1994  'settings',
1995  array(
1996  'module' => array('text', 'common'),
1997  'keyword' => array('text', $field),
1998  'value' => array('text', $proxy_settings[$field])
1999  )
2000  );
2001  }
2002  }
2003  }
2004  }
2005 
2009  public function hasOpCacheEnabled()
2010  {
2011  $ini_get = ini_get('opcache.enable');
2012 
2013  return ($ini_get === 1 or $ini_get === '1' or strtolower($ini_get) === 'on');
2014  }
2015 
2022  public function isValidClientId($a_client_id)
2023  {
2024  if (!preg_match("/^[A-Za-z0-9]+$/", $a_client_id)) {
2025  return false;
2026  }
2027  return true;
2028  }
2029 
2037  protected function isDirectoryInOther($directory, $other_directory)
2038  {
2039  $other_directory = $other_directory . "/";
2040 
2041  return !(strpos($directory, $other_directory) !== 0);
2042  }
2043 }
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.
static is_email($a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
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()
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
catch(Exception $e) $message
checkErrorLogSetup($error_log_path)
check error log path
foreach($_POST as $key=> $value) $res
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
$query
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
$rows
Definition: xhr_table.php:10
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
$i
Definition: disco.tpl.php:19
$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
$source
Definition: linkback.php:22
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.