ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
67  protected $passwordManager;
68 
75  public function __construct(\ilSetupPasswordManager $passwordManager, $a_auth, $a_auth_type)
76  {
77  global $lng;
78 
79  $this->passwordManager = $passwordManager;
80 
81  $this->lng = $lng;
82 
83  $this->db_connections = new ilDBConnections();
84 
85  define("ILIAS_MODULE", "setup");
86 
87  $this->auth = ($this->checkAuth()) ? true : false;
88  $this->access_mode = $a_auth_type;
89 
90  // safe mode status & exec_dir
91  if ($this->safe_mode = ini_get("safe_mode")) {
92  $this->safe_mode_exec_dir = ilFile::deleteTrailingSlash(ini_get("safe_mode_exec_dir"));
93  }
94 
95  // set path to ilias.ini
96  $this->ini_file_path = ILIAS_ABSOLUTE_PATH . "/ilias.ini.php";
97  $this->setup_defaults = ILIAS_ABSOLUTE_PATH . "/setup/ilias.master.ini.php";
98 
99  // init setup.ini
100  $this->ini_ilias_exists = $this->init();
101 
102  /*
103  if ($this->ini_ilias_exists)
104  {
105  if ($this->ini->readVariable("log","path") != "")
106  {
107  $log->path = $this->ini->readVariable("log","path");
108  }
109 
110  if ($this->ini->readVariable("log","file") != "")
111  {
112  $log->filename = $this->ini->readVariable("log","file");
113  }
114 
115  if ($this->ini->readVariable("log","enabled") != "")
116  {
117  $log->enabled = $this->ini->readVariable("log","enabled");
118  }
119  }
120  */
121  }
122 
123 
127  public $client;
128 
129 
133  public function setClient($a_cl)
134  {
135  $this->client = $a_cl;
136  }
137 
138 
142  public function getClient()
143  {
144  return $this->client;
145  }
146 
152  public function init()
153  {
154  // load data from setup.ini file
155  $this->ini = new ilIniFile($this->ini_file_path);
156 
157  if (!$this->ini->read()) {
158  $this->ini->GROUPS = parse_ini_file($this->setup_defaults, true);
159  $this->error = get_class($this) . ": " . $this->ini->getError();
160  return false;
161  }
162 
163  $this->setup_password = $this->ini->readVariable("setup", "pass");
164  $this->default_client = $this->ini->readVariable("clients", "default");
165 
166  define("ILIAS_DATA_DIR", $this->ini->readVariable("clients", "datadir"));
167  define("ILIAS_WEB_DIR", $this->ini->readVariable("clients", "path"));
168 
169  return true;
170  }
171 
176  public function saveNewClient()
177  {
178  // save client id to session
179  $_SESSION["ClientId"] = $this->client->getId();
180 
181  // create client
182  if (!$this->client->create()) {
183  $this->error = $this->client->getError();
184  return false;
185  }
186 
187  //everything okay
188  $this->ini_client_exists = true;
189 
190  return true;
191  }
192 
198  public function updateNewClient($a_old_client_id)
199  {
200  return true;
201  //var_dump("<pre>",$this->client,"</pre>");exit;
202  //Error Handling disabled!! caused by missing PEAR
203  if ($a_old_client_id != $this->client->getId()) {
204  $this->saveNewClient();
205 
206  ilUtil::delDir(ILIAS_ABSOLUTE_PATH . "/" . ILIAS_WEB_DIR . "/" . $a_old_client_id);
207  ilUtil::delDir(ILIAS_DATA_DIR . "/" . $a_old_client_id);
208  }
209 
210  //everything okay
211  $this->ini_client_exists = true;
212 
213  return true;
214  }
215 
220  public function createDatabase($a_collation = "")
221  {
222  if ($this->client->getDBSetup()->isDatabaseInstalled()) {
223  $this->error = $this->lng->txt("database_exists");
224 
225  return false;
226  }
227 
228  $db_setup = $this->client->getDBSetup();
229  return $db_setup->createDatabase($a_collation);
230  }
231 
237  public function installDatabase()
238  {
239  if (!$this->client->getDBSetup()->isDatabaseConnectable()) {
240  return false;
241  }
242 
243  if ($this->client->getDBSetup()->installDatabase()) {
244  $this->client->db_installed = true;
245 
246  return true;
247  }
248 
249  return false;
250  }
251 
252 
257  public function checkIniFileExists()
258  {
259  $a = @file_exists($this->INI_FILE);
260  return $a;
261  }
262 
268  public function checkWritable()
269  {
270  clearstatcache();
271  if (is_writable(".")) {
272  $arr["status"] = true;
273  //$cdir = getcwd();
274  //chdir("..");
275  $arr["comment"] = getcwd();
276  //chdir($cdir);
277  } else {
278  $arr["status"] = false;
279  $arr["comment"] = $this->lng->txt("pre_folder_write_error");
280  //$cdir = getcwd();
281  //chdir("..");
282  $arr["comment"] = getcwd() . ": " . $arr["comment"];
283  //chdir($cdir);
284  }
285 
286  return $arr;
287  }
288 
294  public function checkCreatable($a_dir = ".")
295  {
296  clearstatcache();
297  if (@mkdir($a_dir . "/crst879dldsk9d", 0774)) {
298  $arr["status"] = true;
299  $arr["comment"] = "";
300 
301  @rmdir($a_dir . "/crst879dldsk9d");
302  } else {
303  $arr["status"] = false;
304  //$cdir = getcwd();
305  //chdir("..");
306  $arr["comment"] = getcwd() . ": " . $this->lng->txt("pre_folder_create_error");
307  //chdir($cdir);
308  }
309 
310  return $arr;
311  }
312 
317  public function checkCookiesEnabled()
318  {
319  global $sess;
320 
321  if ($sess->usesCookies) {
322  $arr["status"] = true;
323  $arr["comment"] = "";
324  } else {
325  $arr["status"] = false;
326  $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
327  }
328 
329  return $arr;
330  }
331 
336  public function checkPHPVersion()
337  {
338  $version = PHP_VERSION;
339 
340  $arr["status"] = true;
341  $arr["comment"] = "PHP " . $version;
342  if (version_compare($version, '5.3.0', '<')) {
343  $arr["status"] = false;
344  $arr["comment"] = "PHP " . $version . ". " . $this->lng->txt("pre_php_version_too_low");
345  }
346 
347  return $arr;
348  }
349 
354  public function checkMySQL()
355  {
356  global $ilDB;
357 
358  if (function_exists("mysql_query")) {
359  $arr["status"] = true;
360  $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
361  } else {
362  $arr["status"] = false;
363  $arr["comment"] = $this->lng->txt("pre_mysql_missing");
364  }
365 
366  return $arr;
367  }
368 
373  public function checkAuth()
374  {
375  if ($_SESSION["auth"] === true && $_SESSION["auth_path"] == ILIAS_HTTP_PATH) {
376  return true;
377  }
378 
379  return false;
380  }
381 
382 
387  public function checkDom()
388  {
389  global $ilDB;
390 
391  if (class_exists("DOMDocument")) {
392  $arr["status"] = true;
393  } else {
394  $arr["status"] = false;
395  $arr["comment"] = $this->lng->txt("pre_dom_missing");
396  }
397 
398  return $arr;
399  }
400 
405  public function checkXsl()
406  {
407  global $ilDB;
408 
409  if (class_exists("XSLTProcessor")) {
410  $arr["status"] = true;
411  } else {
412  $arr["status"] = false;
413  $arr["comment"] = sprintf(
414  $this->lng->txt("pre_xsl_missing"),
415  "http://php.net/manual/en/book.xsl.php"
416  );
417  }
418 
419  return $arr;
420  }
421 
426  public function checkGd()
427  {
428  global $ilDB;
429 
430  if (function_exists("imagefill") && function_exists("imagecolorallocate")) {
431  $arr["status"] = true;
432  } else {
433  $arr["status"] = false;
434  $arr["comment"] = sprintf(
435  $this->lng->txt("pre_gd_missing"),
436  "http://php.net/manual/en/book.image.php"
437  );
438  }
439 
440  return $arr;
441  }
442 
447  public function checkMemoryLimit()
448  {
449  global $ilDB;
450 
451  $limit = ini_get("memory_limit");
452 
453  $limit_ok = true;
454  if (is_int(strpos($limit, "M"))) {
455  $limit_n = (int) $limit;
456  if ($limit_n < 40) {
457  $limit_ok = false;
458  }
459  }
460 
461  if ($limit_ok) {
462  $arr["status"] = true;
463  $arr["comment"] = $limit . ". " . $this->lng->txt("pre_memory_limit_recommend");
464  } else {
465  $arr["status"] = false;
466  $arr["comment"] = $limit . ". " . $this->lng->txt("pre_memory_limit_too_low");
467  }
468 
469  return $arr;
470  }
471 
472 
476  protected function checkOpcacheSettings()
477  {
478  $arr = array();
479  // correct-with-php5-removal FSX start
480  if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
481  $arr["status"] = true;
482 
483  return $arr;
484  }
485  // correct-with-php5-removal FSX end
486 
487  $load_comments = ini_get("opcache.load_comments");
488  if ($load_comments == 1) {
489  $arr["status"] = true;
490  } else {
491  $arr["status"] = false;
492  $arr["comment"] = $this->lng->txt("pre_opcache_comments");
493  }
494 
495  return $arr;
496  }
497 
505  public function queryPreliminaries()
506  {
507  $a = array();
508  $a["php"] = $this->checkPHPVersion();
509  // $a["mysql"] = $this->checkMySQL();
510  $a["root"] = $this->checkWritable();
511  $a["folder_create"] = $this->checkCreatable();
512  $a["cookies_enabled"] = $this->checkCookiesEnabled();
513  $a["dom"] = $this->checkDom();
514  $a["xsl"] = $this->checkXsl();
515  $a["gd"] = $this->checkGd();
516  $a["memory"] = $this->checkMemoryLimit();
517 
518  if ($this->hasOpCacheEnabled()) {
519  $a["load_comments"] = $this->checkOpcacheSettings();
520  }
521 
522  return $a;
523  }
524 
529  public function checkPreliminaries()
530  {
531  $this->preliminaries_result = $this->queryPreliminaries();
532 
533  foreach ($this->preliminaries_result as $val) {
534  if ($val["status"] === false) {
535  $this->preliminaries = false;
536  return false;
537  }
538  }
539 
540  return true;
541  }
542 
546  public function getMasterPassword() : string
547  {
548  return $this->ini->readVariable('setup', 'pass');
549  }
550 
555  public function storeMasterPassword(string $raw) : bool
556  {
557  $this->ini->setVariable('setup', 'pass', $this->passwordManager->encodePassword($raw));
558 
559  if ($this->ini->write() == false) {
560  $this->error = $this->ini->getError();
561  return false;
562  }
563 
564  return true;
565  }
566 
572  public function verifyMasterPassword(string $raw) : bool
573  {
574  $passwordReHashCallback = function ($raw) {
575  $this->storeMasterPassword($raw);
576  };
577 
578  return $this->passwordManager->verifyPassword(
579  $this->getMasterPassword(),
580  $raw,
581  $passwordReHashCallback
582  );
583  }
584 
590  public function loginAsClient($a_auth_data)
591  {
592  global $ilDB;
593 
594  if (empty($a_auth_data["client_id"])) {
595  $this->error = "no_client_id";
596  return false;
597  }
598 
599  if (empty($a_auth_data["username"])) {
600  $this->error = "no_username";
601  return false;
602  }
603 
604  if (empty($a_auth_data["password"])) {
605  $this->error = "no_password";
606  return false;
607  }
608 
609  if (!$this->newClient($a_auth_data["client_id"])) { //TT: comment out to get around null db
610  $this->error = "unknown_client_id";
611  unset($this->client);
612  return false;
613  }
614 
615  if (!$this->client->db_exists) {
616  $this->error = "no_db_connect_consult_admin";
617  unset($this->client);
618  return false;
619  }
620 
621  $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = " .
622  $this->client->db->quote('system_role_id', 'text'));
623  $r1 = $this->client->db->fetchAssoc($s1);
624  $system_role_id = $r1["value"];
625 
626  $add_usrfields = '';
627  if ($this->client->db->tableColumnExists('usr_data', 'passwd_enc_type')) {
628  $add_usrfields .= ' , usr_data.passwd_enc_type, usr_data.passwd_salt ';
629  }
630  $q = "SELECT usr_data.usr_id, usr_data.passwd $add_usrfields " .
631  "FROM usr_data " .
632  "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id " .
633  "WHERE rbac_ua.rol_id = " . $this->client->db->quote((int) $system_role_id, 'integer') . " " .
634  "AND usr_data.login=" . $this->client->db->quote($a_auth_data["username"], 'text');
635  $r = $this->client->db->query($q);
636  if (!$this->client->db->numRows($r)) {
637  $this->error = 'login_invalid';
638  return false;
639  }
640 
641  $data = $this->client->db->fetchAssoc($r);
642 
643  global $ilClientIniFile;
644 
645  $ilClientIniFile = $this->client->ini;
646 
647  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
648  $crypt_type = ilUserPasswordManager::getInstance()->getEncoderName();
649  if (strlen($add_usrfields) && ilUserPasswordManager::getInstance()->isEncodingTypeSupported($crypt_type)) {
650  require_once 'setup/classes/class.ilObjSetupUser.php';
651  $user = new ilObjSetupUser();
652  $user->setPasswd($data['passwd'], IL_PASSWD_CRYPTED);
653  $user->setPasswordEncodingType($data['passwd_enc_type']);
654  $user->setPasswordSalt($data['passwd_salt']);
655 
656  $password_valid = ilUserPasswordManager::getInstance()->verifyPassword($user, $a_auth_data['password']);
657  } else {
658  $password_valid = $data['passwd'] == md5($a_auth_data['password']);
659  }
660 
661  if ($password_valid) {
662  // all checks passed -> user valid
663  $_SESSION['auth'] = true;
664  $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
665  $_SESSION['access_mode'] = 'client';
666  $_SESSION['ClientId'] = $this->client->getId();
667  return true;
668  } else {
669  $this->error = 'login_invalid';
670  return false;
671  }
672  }
673 
680  public function loginAsAdmin(string $raw) : bool
681  {
682  $passwordReHashCallback = function ($raw) {
683  $this->storeMasterPassword($raw);
684  };
685 
686  if ($this->passwordManager->verifyPassword($this->getMasterPassword(), $raw, $passwordReHashCallback)) {
687  $_SESSION['auth'] = true;
688  $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
689  $_SESSION['access_mode'] = 'admin';
690  return true;
691  }
692 
693  return false;
694  }
695 
701  public function newClient($a_client_id = 0)
702  {
703  if (!$this->isInstalled()) {
704  return false;
705  }
706 
707  $this->client = new ilClient($a_client_id, $this->db_connections);
708 
709  if (!$this->client->init()) {
710  //echo "<br>noclientinit";
711  $this->error = get_class($this) . ": " . $this->client->getError();
712  $_SESSION["ClientId"] = "";
713  return false;
714  }
715 
716  $_SESSION["ClientId"] = $a_client_id;
717 
718  return true;
719  }
720 
726  public function getStatus($client = 0)
727  {
728  if (!is_object($client)) {
729  if ($this->ini_client_exists) {
731  } else {
732  $client = new ilClient(0, $this->db_connections);
733  }
734  }
735 
736  $status = array();
737  $status["ini"] = $this->checkClientIni($client); // check this one
738  $status["db"] = $this->checkClientDatabase($client);
739  if ($status["db"]["status"] === false and $status["db"]["update"] !== true) {
740  //$status["sess"]["status"] = false;
741  //$status["sess"]["comment"] = $status["db"]["comment"];
742  $status["lang"]["status"] = false;
743  $status["lang"]["comment"] = $status["db"]["comment"];
744  $status["contact"]["status"] = false;
745  $status["contact"]["comment"] = $status["db"]["comment"];
746 
747  $status["proxy"]["status"] = false;
748  $status["proxy"]["comment"] = $status["db"]["comment"];
749 
750  $status["nic"]["status"] = false;
751  $status["nic"]["comment"] = $status["db"]["comment"];
752  } else {
753  //$status["sess"] = $this->checkClientSessionSettings($client);
754  $status["lang"] = $this->checkClientLanguages($client);
755  $status["contact"] = $this->checkClientContact($client);
756  $status["proxy"] = $this->checkClientProxySettings($client);
757  $status["nic"] = $this->checkClientNIC($client);
758  $status["finish"] = $this->checkFinish($client);
759  $status["access"] = $this->checkAccess($client);
760  }
761 
762  //return value
763  return $status;
764  }
765 
771  public function checkFinish(&$client)
772  {
773  if ($client->getSetting("setup_ok")) {
774  $arr["status"] = true;
775  //$arr["comment"] = $this->lng->txt("setup_finished");
776  } else {
777  $arr["status"] = false;
778  $arr["comment"] = $this->lng->txt("setup_not_finished");
779  }
780 
781  return $arr;
782  }
783 
789  public function checkAccess(&$client)
790  {
791  if ($client->ini->readVariable("client", "access") == "1") {
792  $arr["status"] = true;
793  $arr["comment"] = $this->lng->txt("online");
794  } else {
795  $arr["status"] = false;
796  $arr["comment"] = $this->lng->txt("disabled");
797  }
798 
799  return $arr;
800  }
801 
807  public function checkClientIni(&$client)
808  {
809  if (!$arr["status"] = $client->init()) {
810  $arr["comment"] = $client->getError();
811  } else {
812  //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
813  }
814 
815  return $arr;
816  }
817 
818 
824  {
825  $arr = array();
826  $client->provideGlobalDB();
827  if (!$arr["status"] = $client->db_exists) {
828  $arr["comment"] = $this->lng->txt("no_database");
829 
830  return $arr;
831  }
832 
833  if (!$arr["status"] = $client->db_installed) {
834  $arr["comment"] = $this->lng->txt("db_not_installed");
835 
836  return $arr;
837  }
838  // TODO: move this to client class!!
839  $client->setup_ok = (bool) $client->getSetting("setup_ok");
840 
841  include_once "./Services/Database/classes/class.ilDBUpdate.php";
842  $this->lng->setDbHandler($client->db);
843  $dbupdate = new ilDBUpdate($client->db);
844 
845  if (!$arr["status"] = $dbupdate->getDBVersionStatus()) {
846  $arr["comment"] = $this->lng->txt("db_needs_update");
847  $arr["update"] = true;
848 
849  return $arr;
850  } else {
851  if ($dbupdate->hotfixAvailable()) {
852  $arr["status"] = false;
853  $arr["comment"] = $this->lng->txt("hotfix_available");
854  $arr["update"] = true;
855 
856  return $arr;
857  } else {
858  if ($dbupdate->customUpdatesAvailable()) {
859  $arr["status"] = false;
860  $arr["comment"] = $this->lng->txt("custom_updates_available");
861  $arr["update"] = true;
862 
863  return $arr;
864  }
865  }
866  }
867 
868  // check control information
869  global $ilDB;
870  $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
871  $crec = $ilDB->fetchAssoc($cset);
872  $client->revokeGlobalDB();
873  if ($crec["cnt"] == 0) {
874  $arr["status"] = false;
875  $arr["comment"] = $this->lng->txt("db_control_structure_missing");
876  $arr["update"] = true;
877 
878  return $arr;
879  }
880 
881  return $arr;
882  }
883 
889  public function checkClientSessionSettings(&$client, $a_as_bool = false)
890  {
891  require_once('Services/Authentication/classes/class.ilSessionControl.php');
892 
893  global $ilDB;
894  $db = $ilDB;
895 
897 
898  $query = "SELECT keyword, value FROM settings WHERE " . $db->in('keyword', $fields, false, 'text');
899  $res = $db->query($query);
900 
901  $rows = array();
902  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
903  if ($row['value'] != '') {
904  $rows[] = $row;
905  } else {
906  break;
907  }
908  }
909 
910  if (count($rows) != count($fields)) {
911  if ($a_as_bool) {
912  return false;
913  }
914  $arr["status"] = false;
915  $arr["comment"] = $this->lng->txt("session_management_not_configured");
916  } else {
917  if ($a_as_bool) {
918  return true;
919  }
920  $arr["status"] = true;
921  $arr["comment"] = $this->lng->txt("session_management_configured");
922  }
923 
924  return $arr;
925  }
926 
927 
933  {
934  $client->provideGlobalDB();
935  global $ilDB;
936  $arr = array();
937  $fields = array( 'proxy_status', 'proxy_host', 'proxy_port' );
938 
939  $query = "SELECT keyword, value FROM settings WHERE " . $ilDB->in('keyword', $fields, false, 'text');
940  $res = $ilDB->query($query);
941 
942  $proxy_settings = array();
943  $already_saved = false;
944  while ($row = $ilDB->fetchAssoc($res)) {
945  $already_saved = true;
946  $proxy_settings[$row['keyword']] = $row['value'];
947  }
948 
949  if (!$already_saved) {
950  $arr["status"] = false;
951  $arr["comment"] = $this->lng->txt("proxy");
952  $arr["text"] = $this->lng->txt("proxy");
953  } else {
954  if ((bool) $proxy_settings["proxy_status"] == false) {
955  $arr["status"] = true;
956  $arr["comment"] = $this->lng->txt("proxy_disabled");
957  $arr["text"] = $this->lng->txt("proxy_disabled");
958  } else {
959  $arr["status"] = true;
960  $arr["comment"] = $this->lng->txt("proxy_activated_configurated");
961  $arr["text"] = $this->lng->txt("proxy_activated_configurated");
962  }
963  }
964 
965  return $arr;
966  }
967 
968 
974  {
975  $client->provideGlobalDB();
976  $installed_langs = $this->lng->getInstalledLanguages();
977 
978  $count = count($installed_langs);
979  $arr = array();
980  if ($count < 1) {
981  $arr["status"] = false;
982  $arr["comment"] = $this->lng->txt("lang_none_installed");
983  } else {
984  $arr["status"] = true;
985  //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
986  }
987  $client->revokeGlobalDB();
988  return $arr;
989  }
990 
996  public function checkClientContact(&$client)
997  {
998  $arr["status"] = true;
999  //$arr["comment"] = $this->lng->txt("filled_out");
1000 
1001  $settings = $client->getAllSettings();
1002  $client_name = $client->getName();
1003 
1004  // check required fields
1005  if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
1006  empty($settings["admin_email"]) or empty($client_name)) {
1007  $arr["status"] = false;
1008  $arr["comment"] = $this->lng->txt("missing_data");
1009  }
1010 
1011  // admin email
1012  if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false) {
1013  $arr["status"] = false;
1014  $arr["comment"] = $this->lng->txt("email_not_valid");
1015  }
1016 
1017  return $arr;
1018  }
1019 
1025  public function checkClientNIC(&$client)
1026  {
1027  $settings = $client->getAllSettings();
1028 
1029  if (!isset($settings["nic_enabled"])) {
1030  $arr["status"] = false;
1031  $arr["comment"] = $this->lng->txt("nic_not_disabled");
1032  return $arr;
1033  }
1034 
1035  $arr["status"] = true;
1036 
1037  if ($settings["nic_enabled"] == "-1") {
1038  $arr["comment"] = $this->lng->txt("nic_reg_failed");
1039  return $arr;
1040  }
1041 
1042  if (!$settings["nic_enabled"]) {
1043  $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1044  } else {
1045  $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1046  if ($settings["inst_id"] <= 0) {
1047  $arr["status"] = false;
1048  }
1049  }
1050 
1051  return $arr;
1052  }
1053 
1058  public function isInstalled()
1059  {
1060  return $this->ini_ilias_exists;
1061  }
1062 
1067  public function isAuthenticated()
1068  {
1069  return $this->auth;
1070  }
1071 
1076  public function isAdmin()
1077  {
1078  return ($this->access_mode == "admin") ? true : false;
1079  }
1080 
1086  public function saveMasterSetup($a_formdata)
1087  {
1088  $datadir_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1089 
1090  if ($a_formdata["chk_datadir_path"] == 1) { // mode create dir
1091  if (!ilUtil::makeDir($datadir_path)) {
1092  $this->error = "create_datadir_failed";
1093  return false;
1094  }
1095  }
1096 
1097  // create webspace dir if it does not exist
1098  if (!@file_exists(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path")) and !@is_dir(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path"))) {
1099  if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path"))) {
1100  $this->error = "create_webdir_failed";
1101  return false;
1102  }
1103  }
1104 
1105  $form_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1106  $log_path = substr($form_log_path, 0, strrpos($form_log_path, "/"));
1107  $log_file = substr($form_log_path, strlen($log_path) + 1);
1108  $error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1109 
1110  $this->ini->setVariable("server", "http_path", ILIAS_HTTP_PATH);
1111  $this->ini->setVariable("server", "absolute_path", ILIAS_ABSOLUTE_PATH);
1112  $this->ini->setVariable("server", "timezone", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["time_zone"])));
1113  $this->ini->setVariable("clients", "datadir", $datadir_path);
1114  $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"])));
1115  $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"])));
1116  $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"])));
1117  $this->ini->setVariable("tools", "ghostscript", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"])));
1118  $this->ini->setVariable("tools", "java", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"])));
1119  //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1120  $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1121  $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1122  $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1123  $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["scan_command"])));
1124  $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["clean_command"])));
1125  $this->ini->setVariable("tools", "enable_system_styles_management", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["enable_system_styles_management"])));
1126  $this->ini->setVariable("tools", "lessc", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["lessc_path"])));
1127  $this->ini->setVariable("tools", "phantomjs", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["phantomjs_path"])));
1128 
1129  $this->ini->setVariable('setup', 'pass', $this->passwordManager->encodePassword($a_formdata['setup_pass']));
1130  $this->ini->setVariable("log", "path", $log_path);
1131  $this->ini->setVariable("log", "file", $log_file);
1132  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1133  $this->ini->setVariable("log", "error_path", $error_log_path);
1134 
1135  $this->ini->setVariable("https", "auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1136  $this->ini->setVariable("https", "auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1137  $this->ini->setVariable("https", "auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1138 
1139  if (!$this->ini->write()) {
1140  $this->error = get_class($this) . ": " . $this->ini->getError();
1141  return false;
1142  }
1143 
1144  // everything is fine. so we authenticate the user and set access mode to 'admin'
1145  $_SESSION["auth"] = true;
1146  $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1147  $_SESSION["access_mode"] = "admin";
1148 
1149  return true;
1150  }
1151 
1157  public function updateMasterSettings($a_formdata)
1158  {
1159  $convert_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"]));
1160  $zip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"]));
1161  $unzip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"]));
1162  $ghostscript_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1163  $java_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"]));
1164  //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1165  $ffmpeg_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1166  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1167  $fop_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["fop_path"]));
1168  $scan_type = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1169  $scan_command = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["scan_command"]));
1170  $clean_command = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["clean_command"]));
1171  $enable_system_styles_management = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["enable_system_styles_management"]));
1172  $lessc_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["lessc_path"]));
1173  $phantomjs_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["phantomjs_path"]));
1174 
1175  $this->ini->setVariable("tools", "convert", $convert_path);
1176  $this->ini->setVariable("tools", "zip", $zip_path);
1177  $this->ini->setVariable("tools", "unzip", $unzip_path);
1178  $this->ini->setVariable("tools", "ghostscript", $ghostscript_path);
1179  $this->ini->setVariable("tools", "java", $java_path);
1180  //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1181  $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1182  $this->ini->setVariable("tools", "latex", $latex_url);
1183  $this->ini->setVariable("tools", "fop", $fop_path);
1184  $this->ini->setVariable("tools", "vscantype", $scan_type);
1185  $this->ini->setVariable("tools", "scancommand", $scan_command);
1186  $this->ini->setVariable("tools", "cleancommand", $clean_command);
1187  $this->ini->setVariable("tools", "lessc", $lessc_path);
1188  $this->ini->setVariable("tools", "enable_system_styles_management", $enable_system_styles_management);
1189  $this->ini->setVariable("tools", "phantomjs", $phantomjs_path);
1190 
1191  $form_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1192  $log_path = substr($form_log_path, 0, strrpos($form_log_path, "/"));
1193  $log_file = substr($form_log_path, strlen($log_path) + 1);
1194 
1195  $error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1196 
1197  $this->ini->setVariable("log", "path", $log_path);
1198  $this->ini->setVariable("log", "file", $log_file);
1199  $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1200  $this->ini->setVariable("log", "error_path", $error_log_path);
1201  $this->ini->setVariable("server", "timezone", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["time_zone"])));
1202 
1203  $this->ini->setVariable("https", "auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1204  $this->ini->setVariable("https", "auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1205  $this->ini->setVariable("https", "auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1206 
1207  if (!$this->ini->write()) {
1208  $this->error = get_class($this) . ": " . $this->ini->getError();
1209  return false;
1210  }
1211 
1212  return true;
1213  }
1214 
1220  public function checkToolsSetup($a_formdata)
1221  {
1222  // convert path
1223  if (!isset($a_formdata["chk_convert_path"])) {
1224  // convert backslashes to forwardslashes
1225  $convert_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"]));
1226 
1227  if (($err = $this->testConvert($convert_path)) != "") {
1228  $this->error = $err;
1229  return false;
1230  }
1231  }
1232 
1233  // zip path
1234  if (!isset($a_formdata["chk_zip_path"])) {
1235  // convert backslashes to forwardslashes
1236  $zip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"]));
1237 
1238  if (empty($zip_path)) {
1239  $this->error = "no_path_zip";
1240  return false;
1241  }
1242 
1243  if (!$this->testZip($zip_path)) {
1244  $this->error = "check_failed_zip";
1245  return false;
1246  }
1247  }
1248 
1249  // unzip path
1250  if (!isset($a_formdata["chk_unzip_path"])) {
1251  // convert backslashes to forwardslashes
1252  $unzip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"]));
1253 
1254  if (empty($unzip_path)) {
1255  $this->error = "no_path_unzip";
1256  return false;
1257  }
1258 
1259  if (!$this->testUnzip($unzip_path)) {
1260  $this->error = "check_failed_unzip";
1261  return false;
1262  }
1263  }
1264 
1265  // ghostscript path
1266  if (!isset($a_formdata["chk_ghostscript_path"])) {
1267  // convert backslashes to forwardslashes
1268  $ghostscript_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1269 
1270  if (($err = $this->testGhostscript($ghostscript_path)) != "") {
1271  $this->error = $err;
1272  return false;
1273  }
1274  }
1275 
1276  // java path
1277  if (!isset($a_formdata["chk_java_path"])) {
1278  // convert backslashes to forwardslashes
1279  $java_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"]));
1280 
1281  if (empty($java_path)) {
1282  $this->error = "no_path_java";
1283  return false;
1284  }
1285 
1286  if (!$this->testJava($java_path)) {
1287  $this->error = "check_failed_java";
1288  return false;
1289  }
1290  }
1291 
1292  /*if (!isset($a_formdata["chk_mkisofs_path"]))
1293  {
1294  // convert backslashes to forwardslashes
1295  $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1296 
1297  if (empty($mkisofs_path))
1298  {
1299  $this->error = "no_path_mkisofs";
1300  return false;
1301  }
1302  }*/
1303 
1304  if (!isset($a_formdata["chk_ffmpeg_path"])) {
1305  // convert backslashes to forwardslashes
1306  $ffmpeg_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1307 
1308  if (empty($ffmpeg_path)) {
1309  $this->error = "no_path_ffmpeg";
1310  return false;
1311  }
1312 
1313  if (!$this->testFFMpeg($ffmpeg_path)) {
1314  $this->error = "check_failed_ffmpeg";
1315  return false;
1316  }
1317  }
1318 
1319  // latex url
1320  if (!isset($a_formdata["chk_latex_url"])) {
1321  $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1322  if (empty($latex_url)) {
1323  $this->error = "no_latex_url";
1324  return false;
1325  }
1326 
1327  if (!$this->testLatex($latex_url)) {
1328  $this->error = "check_failed_latex";
1329  return false;
1330  }
1331  }
1332 
1333  return true;
1334  }
1335 
1341  public function checkDataDirSetup($a_formdata)
1342  {
1343  // remove trailing slash & convert backslashes to forwardslashes
1344  $datadir_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1345 
1346  if (empty($datadir_path)) {
1347  $this->error = "no_path_datadir";
1348  return false;
1349  }
1350 
1351  $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1352 
1353  // datadir may not point to webspace dir or to any place under webspace_dir
1354  if (strpos($datadir_path, $webspace_dir) !== false) {
1355  $this->error = "datadir_webspacedir_match";
1356  return false;
1357  }
1358 
1359  // create dir
1360  if ($a_formdata["chk_datadir_path"] == 1) {
1361  $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1362  $dir_to_check = substr($datadir_path, 0, -strlen($dir_to_create) - 1);
1363 
1364  if ($this->isDirectoryInOther($dir_to_create, ILIAS_ABSOLUTE_PATH)) {
1365  $this->error = "cannot_create_datadir_inside_webdir";
1366  return false;
1367  }
1368 
1369  if (is_writable($datadir_path)) {
1370  $this->error = "dir_exists_create";
1371  return false;
1372  }
1373 
1374  if (!is_writable($dir_to_check)) {
1375  $this->error = "cannot_create_datadir_no_write_access";
1376  return false;
1377  }
1378  } else { // check set target dir
1379  if ($this->isDirectoryInOther($datadir_path, ILIAS_ABSOLUTE_PATH)) {
1380  $this->error = "cannot_create_datadir_inside_webdir";
1381  return false;
1382  }
1383 
1384  if (!is_writable($datadir_path)) {
1385  $this->error = "cannot_create_datadir_no_write_access";
1386  return false;
1387  }
1388  }
1389 
1390  return true;
1391  }
1392 
1398  public function checkPasswordSetup($a_formdata)
1399  {
1400  if (!$a_formdata["setup_pass"]) {
1401  $this->error = "no_setup_pass_given";
1402  return false;
1403  }
1404 
1405  if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"]) {
1406  $this->error = "pass_does_not_match";
1407  return false;
1408  }
1409 
1410  return true;
1411  }
1412 
1418  public function checkLogSetup($a_formdata)
1419  {
1420  // log path
1421  if (!$a_formdata["chk_log_status"]) {
1422  // remove trailing slash & convert backslashes to forwardslashes
1423  $log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1424 
1425  if (empty($log_path)) {
1426  $this->error = "no_path_log";
1427  return false;
1428  }
1429 
1430  if (is_dir($log_path)) {
1431  $this->error = 'could_not_create_logfile';
1432  return false;
1433  }
1434 
1435  if ($this->isDirectoryInOther($log_path, ILIAS_ABSOLUTE_PATH)) {
1436  $this->error = "cannot_create_logdir_inside_webdir";
1437  return false;
1438  }
1439 
1440  if (!@touch($log_path)) {
1441  $this->error = "could_not_create_logfile";
1442  return false;
1443  }
1444  }
1445 
1446  return true;
1447  }
1448 
1456  public function checkErrorLogSetup($error_log_path)
1457  {
1458  // remove trailing slash & convert backslashes to forwardslashes
1459  $clean_error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($error_log_path)));
1460 
1461  if (!empty($clean_error_log_path)) {
1462  if (!ilUtil::makeDirParents($clean_error_log_path)) {
1463  $this->error = "could_not_create_error_directory";
1464  return false;
1465  }
1466  }
1467 
1468  return true;
1469  }
1470 
1475  public function getError()
1476  {
1477  if (empty($this->error)) {
1478  return false;
1479  }
1480 
1481  $error = $this->error;
1482  $this->error = "";
1483 
1484  return $error;
1485  }
1486 
1492  public function _ilSetup()
1493  {
1494  //if ($this->ini->readVariable("db","type") != "")
1495  //{
1496  // $this->db->disconnect();
1497  //}
1498  return true;
1499  }
1500 
1507  public function testConvert($a_convert_path)
1508  {
1509  if (trim($a_convert_path) == "") {
1510  return "no_path_convert";
1511  }
1512  if (!is_file($a_convert_path)) {
1513  return "check_failed_convert";
1514  }
1515 
1516  return "";
1517  }
1518 
1525  public function testGhostscript($a_ghostscript_path)
1526  {
1527  // ghostscript is optional, so empty path is ok
1528  if (trim($a_ghostscript_path) == "") {
1529  return "";
1530  }
1531  if (!is_file($a_ghostscript_path)) {
1532  return "check_failed_ghostscript";
1533  }
1534 
1535  return "";
1536  }
1537 
1544  public function testJava($a_java_path)
1545  {
1546  // java is optional, so empty path is ok
1547  if (trim($a_java_path) == "") {
1548  return "";
1549  }
1550 
1551  if (!is_file($a_java_path)) {
1552  return "check_failed_java";
1553  }
1554 
1555  return "";
1556  /*
1557  exec($a_java_path, $out, $back);
1558 
1559  unset($out);
1560 
1561  return ($back != 1) ? false : true;
1562  */
1563  }
1564 
1571  public function testLatex($a_latex_url)
1572  {
1573  // latex is optional, so empty path is ok
1574  if (trim($a_latex_url) == "") {
1575  return "";
1576  }
1577 
1578  // open the URL
1579  include_once "./setup/classes/class.ilHttpRequest.php";
1580  $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1581  $result = @$http->downloadToString();
1582  if ((strpos((substr($result, 0, 5)), "PNG") !== false) || (strpos((substr($result, 0, 5)), "GIF") !== false)) {
1583  return "";
1584  } else {
1585  return "check_failed_latex";
1586  ;
1587  }
1588  }
1589 
1596  public function testZip($a_zip_path)
1597  {
1598  if (trim($a_zip_path) == "") {
1599  return "no_path_zip";
1600  }
1601  if (!is_file($a_zip_path)) {
1602  return "check_failed_zip";
1603  }
1604 
1605  return "";
1606  /*
1607  // create test file and run zip
1608  $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1609 
1610  fwrite($fp, "test");
1611  fclose($fp);
1612 
1613  if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1614  {
1615  $curDir = getcwd();
1616  chdir(ILIAS_ABSOLUTE_PATH);
1617 
1618  $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1619 
1620  exec($zipCmd);
1621 
1622  chdir($curDir);
1623 
1624  }
1625 
1626  // check wether zip generated test file or not
1627  if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1628  {
1629  unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1630  return true;
1631  }
1632  else
1633  {
1634  unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1635  return false;
1636  }
1637  */
1638  }
1639 
1640 
1647  public function testUnzip($a_unzip_path)
1648  {
1649  if (trim($a_unzip_path) == "") {
1650  return "no_path_unzip";
1651  }
1652  if (!is_file($a_unzip_path)) {
1653  return "check_failed_unzip";
1654  }
1655 
1656  return "";
1657  /*
1658  $curDir = getcwd();
1659 
1660  chdir(ILIAS_ABSOLUTE_PATH);
1661 
1662  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1663  {
1664  $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1665  exec($unzipCmd);
1666  }
1667 
1668  chdir($curDir);
1669 
1670  // check wether unzip extracted the test file or not
1671  if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1672  {
1673  unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1674 
1675  return true;
1676  }
1677  else
1678  {
1679  return false;
1680  }
1681  */
1682  }
1683 
1690  public function unzip($a_file, $overwrite = false)
1691  {
1692  //global $ilias;
1693 
1694  $pathinfo = pathinfo($a_file);
1695  $dir = $pathinfo["dirname"];
1696  $file = $pathinfo["basename"];
1697 
1698  // unzip
1699  $cdir = getcwd();
1700  chdir($dir);
1701  $unzip = $this->ini->readVariable("tools", "unzip");
1702  $unzipcmd = $unzip . " -Z -1 " . ilUtil::escapeShellArg($file);
1703  exec($unzipcmd, $arr);
1704  $zdirs = array();
1705 
1706  foreach ($arr as $line) {
1707  if (is_int(strpos($line, "/"))) {
1708  $zdir = substr($line, 0, strrpos($line, "/"));
1709  $nr = substr_count($zdir, "/");
1710  //echo $zdir." ".$nr."<br>";
1711  while ($zdir != "") {
1712  $nr = substr_count($zdir, "/");
1713  $zdirs[$zdir] = $nr; // collect directories
1714  //echo $dir." ".$nr."<br>";
1715  $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1716  }
1717  }
1718  }
1719 
1720  asort($zdirs);
1721 
1722  foreach ($zdirs as $zdir => $nr) { // create directories
1723  ilUtil::createDirectory($zdir);
1724  }
1725 
1726  // real unzip
1727  if ($overvwrite) {
1728  $unzipcmd = $unzip . " " . ilUtil::escapeShellArg($file);
1729  } else {
1730  $unzipcmd = $unzip . " -o " . ilUtil::escapeShellArg($file);
1731  }
1732  exec($unzipcmd);
1733 
1734  chdir($cdir);
1735  }
1736 
1742  public function setSessionSettings($session_settings)
1743  {
1744  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1745 
1746  $db = $this->client->getDB();
1747 
1748  $setting_fields = ilSessionControl::getSettingFields();
1749 
1750  $i = 0;
1751  foreach ($setting_fields as $field) {
1752  if (isset($session_settings[$field])) {
1753  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1754  $res = $db->queryF(
1755  $query,
1756  array('text', 'text'),
1757  array('common', $field)
1758  );
1759 
1760  $row = array();
1761  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1762  break;
1763  }
1764 
1765  if (count($row) > 0) {
1766  $db->update(
1767  'settings',
1768  array(
1769  'value' => array('text', $session_settings[$field])
1770  ),
1771  array(
1772  'module' => array('text', 'common'),
1773  'keyword' => array('text', $field)
1774  )
1775  );
1776  } else {
1777  $db->insert(
1778  'settings',
1779  array(
1780  'module' => array('text', 'common'),
1781  'keyword' => array('text', $field),
1782  'value' => array('text', $session_settings[$field])
1783  )
1784  );
1785  }
1786 
1787  $i++;
1788  }
1789  }
1790 
1791  if ($i < 4) {
1792  $message = $this->lng->txt("session_settings_not_saved");
1793  } else {
1794  $message = $this->lng->txt("settings_saved");
1795  }
1796 
1798  }
1799 
1805  public function getSessionSettings()
1806  {
1807  require_once('Services/Authentication/classes/class.ilSessionControl.php');
1808 
1809  $db = $this->client->getDB();
1810 
1811  $setting_fields = ilSessionControl::getSettingFields();
1812 
1813  $query = "SELECT * FROM settings WHERE module = %s " .
1814  "AND " . $db->in('keyword', $setting_fields, false, 'text');
1815 
1816  $res = $db->queryF($query, array('text'), array('common'));
1817 
1818  $session_settings = array();
1819  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1820  $session_settings[$row['keyword']] = $row['value'];
1821  }
1822 
1823  foreach ($setting_fields as $field) {
1824  if (!isset($session_settings[$field])) {
1825  $value = 1;
1826 
1827  switch ($field) {
1828  case 'session_max_count':
1829 
1831  break;
1832 
1833  case 'session_min_idle':
1834 
1836  break;
1837 
1838  case 'session_max_idle':
1839 
1841  break;
1842 
1843  case 'session_max_idle_after_first_request':
1844 
1846  break;
1847 
1848  case 'session_allow_client_maintenance':
1849 
1851  break;
1852  }
1853 
1854  $session_settings[$field] = $value;
1855  }
1856  }
1857 
1858  return $session_settings;
1859  }
1860 
1866  public function cloneFromSource($source_id)
1867  {
1868  // Getting source and targets
1869  $source = new ilClient($source_id, $this->db_connections);
1870  $source->init();
1872 
1873  // ************************************************
1874  // ** COPY FILES
1875 
1876  // Cleaning up datadir
1877  if (!ilUtil::delDir($target->getDataDir())) {
1878  $this->error = "Could not delete data dir $target->getDataDir()";
1879  //return false;
1880  }
1881 
1882  // Create empty datadir
1883  if (!ilUtil::makeDir($target->getDataDir())) {
1884  $this->error = "could_not_create_base_data_dir :" . $target->getDataDir();
1885  return false;
1886  }
1887 
1888  // Copying datadir
1889  if (!ilUtil::rCopy($source->getDataDir(), $target->getDataDir())) {
1890  $this->error = "clone_datadircopyfail";
1891  $target->ini->write();
1892  return false;
1893  }
1894 
1895  // Cleaning up Webspacedir
1896  if (!ilUtil::delDir($target->getWebspaceDir())) {
1897  $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
1898  //return false;
1899  }
1900 
1901  // Create empty Webspacedir
1902  if (!ilUtil::makeDir($target->getWebspaceDir())) {
1903  $this->error = "could_not_create_base_webspace_dir :" . $target->getWebspaceDir();
1904  return false;
1905  }
1906 
1907  // Copying Webspacedir
1908  if (!ilUtil::rCopy($source->getWebspaceDir(), $target->getWebspaceDir())) {
1909  $this->error = "clone_websipacedircopyfail";
1910  $target->ini->write();
1911  return false;
1912  }
1913 
1914  // Restore ini file
1915  $target->ini->write();
1916 
1917  // ************************************************
1918  // ** COPY DATABASE
1919 
1920  $source->connect();
1921  if (!$source->db) {
1922  $this->error = "Source database connection failed.";
1923  return false;
1924  }
1925 
1926  $target->connect();
1927  if (!$target->db) {
1928  $this->error = "Target database connection failed.";
1929  return false;
1930  }
1931 
1932  $source->connect();
1933  $srcTables = $source->db->query("SHOW TABLES");
1934  $target->connect();
1935 
1936  // drop all tables of the target db
1937  $tarTables = $target->db->query("SHOW TABLES");
1938  foreach ($tarTables->fetchAll() as $cTable) {
1939  $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
1940  }
1941 
1942  foreach ($srcTables->fetchAll() as $cTable) {
1943  $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
1944  $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
1945  if (!$create) {
1946  $error = true;
1947  }
1948  $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM " . $source->getDbName() . "." . $cTable[0]);
1949  }
1950 
1951  $target->db->query("UPDATE settings SET VALUE = " . $target->db->quote(0, "integer") . " WHERE keyword = " . $target->db->quote("inst_id", "text"));
1952  $target->db->query("UPDATE settings SET VALUE = " . $target->db->quote(0, "integer") . " WHERE keyword = " . $target->db->quote("nic_enabled", "text"));
1953  return true;
1954  }
1962  public function printProxyStatus($client)
1963  {
1964  require_once './Services/Http/exceptions/class.ilProxyException.php';
1965  $settings = $client->getAllSettings();
1966 
1967  if ((bool) $settings['proxy_status'] == true) {
1968  try {
1969  $err_str = false;
1970  $wait_timeout = 100;
1971 
1972  $fp = @fsockopen($settings['proxy_host'], $settings['proxy_port'], $err_code, $err_str, $wait_timeout);
1973 
1974  if ($err_str) {
1975  throw new ilProxyException($err_str);
1976  }
1977 
1978  fclose($fp);
1979 
1980  ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
1981  } catch (Exception $e) {
1982  ilUtil::sendFailure($this->lng->txt('proxy_not_connectable') . ": " . $e->getMessage());
1983  }
1984  }
1985  }
1986 
1987  public function saveProxySettings($proxy_settings)
1988  {
1989  $db = $this->client->getDB();
1990  $proxy_fields = array('proxy_status','proxy_host','proxy_port');
1991 
1992  foreach ($proxy_fields as $field) {
1993  if (isset($proxy_settings[$field])) {
1994  $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1995  $res = $db->queryF(
1996  $query,
1997  array('text', 'text'),
1998  array('common', $field)
1999  );
2000 
2001  $row = array();
2002  while ($row = $db->fetchAssoc($res)) {
2003  break;
2004  }
2005 
2006  if (is_array($row) && count($row) > 0) {
2007  $db->update(
2008  'settings',
2009  array(
2010  'value' => array('text', $proxy_settings[$field])
2011  ),
2012  array(
2013  'module' => array('text', 'common'),
2014  'keyword' => array('text', $field)
2015  )
2016  );
2017  } else {
2018  $db->insert(
2019  'settings',
2020  array(
2021  'module' => array('text', 'common'),
2022  'keyword' => array('text', $field),
2023  'value' => array('text', $proxy_settings[$field])
2024  )
2025  );
2026  }
2027  }
2028  }
2029  }
2030 
2034  public function hasOpCacheEnabled()
2035  {
2036  $ini_get = ini_get('opcache.enable');
2037 
2038  return ($ini_get === 1 or $ini_get === '1' or strtolower($ini_get) === 'on');
2039  }
2040 
2047  public function isValidClientId($a_client_id)
2048  {
2049  if (!preg_match("/^[A-Za-z0-9]+$/", $a_client_id)) {
2050  return false;
2051  }
2052  return true;
2053  }
2054 
2062  protected function isDirectoryInOther($directory, $other_directory)
2063  {
2064  $other_directory = $other_directory . "/";
2065 
2066  return !(strpos($directory, $other_directory) !== 0);
2067  }
2068 }
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
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
loginAsAdmin(string $raw)
Process setup admin login.
_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)
$version
Definition: build.php:27
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.
getMasterPassword()
isInstalled()
check if client&#39;s db is installed
$r
Definition: example_031.php:79
catch(Exception $e) $message
checkErrorLogSetup($error_log_path)
check error log path
foreach($_POST as $key=> $value) $res
deleteTrailingSlash($a_path)
delete trailing slash of path variables
$lng
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
$user
Definition: migrateto20.php:57
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
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 ...
$row
checkFinish(&$client)
check if client setup was finished
$rows
Definition: xhr_table.php:10
storeMasterPassword(string $raw)
verifyMasterPassword(string $raw)
__construct(\ilSetupPasswordManager $passwordManager, $a_auth, $a_auth_type)
constructor
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)
checkGd()
Check MySQL.
global $ilDB
$i
Definition: disco.tpl.php:19
$preliminaries_result
getSetting($a_keyword)
read one value from settings table
checkPHPVersion()
check for PHP version
$source
Definition: linkback.php:22
checkClientProxySettings(ilClient $client)
checkClientSessionSettings(&$client, $a_as_bool=false)
check client session config status
$target
Definition: test.php:19
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
Class ilSetupPasswordManager.
$data
Definition: bench.php:6
saveNewClient()
saves client.ini & updates client list in ilias.ini
Setup class.