ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
14{
15
19 public $ini; // ini file object
20 public $ini_file_path; // full path to setup.ini, containing the client list
21 public $error = ""; // error text
22
23 public $ini_ilias_exists = false; // control flag ilias.ini
24 public $ini_client_exists = false; // control flag client.ini
25
26 public $setup_defaults; // ilias.master.ini
27 public $ilias_nic_server = "https://nic.ilias.de/index.php"; // URL to ilias nic server
28
29 public $preliminaries_result = array(); // preliminaries check results
30 public $preliminaries = true; //
31
37 public $SQL_FILE = "./setup/sql/ilias3.sql";
38
44 public $dsn = "";
45
51 public $db;
52
53 public $setup_password; // master setup password
54 public $default_client; // client id of default client
55
56 public $safe_mode; // safe mode enabled (true) or disabled (false)
57 public $safe_mode_exec_dir; // contains exec_dir_path
58
59 public $auth; // current user is authenticated? (true)
60 public $access_mode; // if "admin", admin functions are enabled
61
66
73 public function __construct(\ilSetupPasswordManager $passwordManager, $a_auth, $a_auth_type)
74 {
75 global $lng;
76
77 $this->passwordManager = $passwordManager;
78
79 $this->lng = $lng;
80
81 define("ILIAS_MODULE", "setup");
82
83 $this->auth = ($this->checkAuth()) ? true : false;
84 $this->access_mode = $a_auth_type;
85
86 // safe mode status & exec_dir
87 if ($this->safe_mode = ini_get("safe_mode")) {
88 $this->safe_mode_exec_dir = ilFile::deleteTrailingSlash(ini_get("safe_mode_exec_dir"));
89 }
90
91 // set path to ilias.ini
92 $this->ini_file_path = ILIAS_ABSOLUTE_PATH . "/ilias.ini.php";
93 $this->setup_defaults = ILIAS_ABSOLUTE_PATH . "/setup/ilias.master.ini.php";
94
95 // init setup.ini
96 $this->ini_ilias_exists = $this->init();
97
98 /*
99 if ($this->ini_ilias_exists)
100 {
101 if ($this->ini->readVariable("log","path") != "")
102 {
103 $log->path = $this->ini->readVariable("log","path");
104 }
105
106 if ($this->ini->readVariable("log","file") != "")
107 {
108 $log->filename = $this->ini->readVariable("log","file");
109 }
110
111 if ($this->ini->readVariable("log","enabled") != "")
112 {
113 $log->enabled = $this->ini->readVariable("log","enabled");
114 }
115 }
116 */
117 }
118
119
123 public $client;
124
125
129 public function setClient($a_cl)
130 {
131 $this->client = $a_cl;
132 }
133
134
138 public function getClient()
139 {
140 return $this->client;
141 }
142
148 public function init()
149 {
150 // load data from setup.ini file
151 $this->ini = new ilIniFile($this->ini_file_path);
152
153 if (!$this->ini->read()) {
154 $this->ini->GROUPS = parse_ini_file($this->setup_defaults, true);
155 $this->error = get_class($this) . ": " . $this->ini->getError();
156 return false;
157 }
158
159 $this->setup_password = $this->ini->readVariable("setup", "pass");
160 $this->default_client = $this->ini->readVariable("clients", "default");
161
162 define("ILIAS_DATA_DIR", $this->ini->readVariable("clients", "datadir"));
163 define("ILIAS_WEB_DIR", $this->ini->readVariable("clients", "path"));
164
165 return true;
166 }
167
172 public function saveNewClient()
173 {
174 // save client id to session
175 $_SESSION["ClientId"] = $this->client->getId();
176
177 // create client
178 if (!$this->client->create()) {
179 $this->error = $this->client->getError();
180 return false;
181 }
182
183 //everything okay
184 $this->ini_client_exists = true;
185
186 return true;
187 }
188
194 public function updateNewClient($a_old_client_id)
195 {
196 return true;
197 //var_dump("<pre>",$this->client,"</pre>");exit;
198 //Error Handling disabled!! caused by missing PEAR
199 if ($a_old_client_id != $this->client->getId()) {
200 $this->saveNewClient();
201
202 ilUtil::delDir(ILIAS_ABSOLUTE_PATH . "/" . ILIAS_WEB_DIR . "/" . $a_old_client_id);
203 ilUtil::delDir(ILIAS_DATA_DIR . "/" . $a_old_client_id);
204 }
205
206 //everything okay
207 $this->ini_client_exists = true;
208
209 return true;
210 }
211
216 public function createDatabase($a_collation = "")
217 {
218 if ($this->client->getDBSetup()->isDatabaseInstalled()) {
219 $this->error = $this->lng->txt("database_exists");
220
221 return false;
222 }
223
224 $db_setup = $this->client->getDBSetup();
225 return $db_setup->createDatabase($a_collation);
226 }
227
233 public function installDatabase()
234 {
235 if (!$this->client->getDBSetup()->isDatabaseConnectable()) {
236 return false;
237 }
238
239 if ($this->client->getDBSetup()->installDatabase()) {
240 $this->client->db_installed = true;
241
242 return true;
243 }
244
245 return false;
246 }
247
248
253 public function checkIniFileExists()
254 {
255 $a = @file_exists($this->INI_FILE);
256 return $a;
257 }
258
264 public function checkWritable()
265 {
266 clearstatcache();
267 if (is_writable(".")) {
268 $arr["status"] = true;
269 //$cdir = getcwd();
270 //chdir("..");
271 $arr["comment"] = getcwd();
272 //chdir($cdir);
273 } else {
274 $arr["status"] = false;
275 $arr["comment"] = $this->lng->txt("pre_folder_write_error");
276 //$cdir = getcwd();
277 //chdir("..");
278 $arr["comment"] = getcwd() . ": " . $arr["comment"];
279 //chdir($cdir);
280 }
281
282 return $arr;
283 }
284
290 public function checkCreatable($a_dir = ".")
291 {
292 clearstatcache();
293 if (@mkdir($a_dir . "/crst879dldsk9d", 0774)) {
294 $arr["status"] = true;
295 $arr["comment"] = "";
296
297 @rmdir($a_dir . "/crst879dldsk9d");
298 } else {
299 $arr["status"] = false;
300 //$cdir = getcwd();
301 //chdir("..");
302 $arr["comment"] = getcwd() . ": " . $this->lng->txt("pre_folder_create_error");
303 //chdir($cdir);
304 }
305
306 return $arr;
307 }
308
313 public function checkCookiesEnabled()
314 {
315 global $sess;
316
317 if ($sess->usesCookies) {
318 $arr["status"] = true;
319 $arr["comment"] = "";
320 } else {
321 $arr["status"] = false;
322 $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
323 }
324
325 return $arr;
326 }
327
332 public function checkPHPVersion()
333 {
334 $version = PHP_VERSION;
335
336 $arr["status"] = true;
337 $arr["comment"] = "PHP " . $version;
338 if (version_compare($version, '5.3.0', '<')) {
339 $arr["status"] = false;
340 $arr["comment"] = "PHP " . $version . ". " . $this->lng->txt("pre_php_version_too_low");
341 }
342
343 return $arr;
344 }
345
350 public function checkMySQL()
351 {
352 global $ilDB;
353
354 if (function_exists("mysql_query")) {
355 $arr["status"] = true;
356 $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
357 } else {
358 $arr["status"] = false;
359 $arr["comment"] = $this->lng->txt("pre_mysql_missing");
360 }
361
362 return $arr;
363 }
364
369 public function checkAuth()
370 {
371 if ($_SESSION["auth"] === true && $_SESSION["auth_path"] == ILIAS_HTTP_PATH) {
372 return true;
373 }
374
375 return false;
376 }
377
378
383 public function checkDom()
384 {
385 global $ilDB;
386
387 if (class_exists("DOMDocument")) {
388 $arr["status"] = true;
389 } else {
390 $arr["status"] = false;
391 $arr["comment"] = $this->lng->txt("pre_dom_missing");
392 }
393
394 return $arr;
395 }
396
401 public function checkXsl()
402 {
403 global $ilDB;
404
405 if (class_exists("XSLTProcessor")) {
406 $arr["status"] = true;
407 } else {
408 $arr["status"] = false;
409 $arr["comment"] = sprintf(
410 $this->lng->txt("pre_xsl_missing"),
411 "http://php.net/manual/en/book.xsl.php"
412 );
413 }
414
415 return $arr;
416 }
417
422 public function checkGd()
423 {
424 global $ilDB;
425
426 if (function_exists("imagefill") && function_exists("imagecolorallocate")) {
427 $arr["status"] = true;
428 } else {
429 $arr["status"] = false;
430 $arr["comment"] = sprintf(
431 $this->lng->txt("pre_gd_missing"),
432 "http://php.net/manual/en/book.image.php"
433 );
434 }
435
436 return $arr;
437 }
438
443 public function checkMemoryLimit()
444 {
445 global $ilDB;
446
447 $limit = ini_get("memory_limit");
448
449 $limit_ok = true;
450 if (is_int(strpos($limit, "M"))) {
451 $limit_n = (int) $limit;
452 if ($limit_n < 40) {
453 $limit_ok = false;
454 }
455 }
456
457 if ($limit_ok) {
458 $arr["status"] = true;
459 $arr["comment"] = $limit . ". " . $this->lng->txt("pre_memory_limit_recommend");
460 } else {
461 $arr["status"] = false;
462 $arr["comment"] = $limit . ". " . $this->lng->txt("pre_memory_limit_too_low");
463 }
464
465 return $arr;
466 }
467
468
476 public function queryPreliminaries()
477 {
478 $a = array();
479 $a["php"] = $this->checkPHPVersion();
480 // $a["mysql"] = $this->checkMySQL();
481 $a["root"] = $this->checkWritable();
482 $a["folder_create"] = $this->checkCreatable();
483 $a["cookies_enabled"] = $this->checkCookiesEnabled();
484 $a["dom"] = $this->checkDom();
485 $a["xsl"] = $this->checkXsl();
486 $a["gd"] = $this->checkGd();
487 $a["memory"] = $this->checkMemoryLimit();
488
489 return $a;
490 }
491
496 public function checkPreliminaries()
497 {
498 $this->preliminaries_result = $this->queryPreliminaries();
499
500 foreach ($this->preliminaries_result as $val) {
501 if ($val["status"] === false) {
502 $this->preliminaries = false;
503 return false;
504 }
505 }
506
507 return true;
508 }
509
513 public function getMasterPassword() : string
514 {
515 return $this->ini->readVariable('setup', 'pass');
516 }
517
522 public function storeMasterPassword(string $raw) : bool
523 {
524 $this->ini->setVariable('setup', 'pass', $this->passwordManager->encodePassword($raw));
525
526 if ($this->ini->write() == false) {
527 $this->error = $this->ini->getError();
528 return false;
529 }
530
531 return true;
532 }
533
539 public function verifyMasterPassword(string $raw) : bool
540 {
541 $passwordReHashCallback = function ($raw) {
542 $this->storeMasterPassword($raw);
543 };
544
545 return $this->passwordManager->verifyPassword(
546 $this->getMasterPassword(),
547 $raw,
548 $passwordReHashCallback
549 );
550 }
551
557 public function loginAsClient($a_auth_data)
558 {
559 global $ilDB;
560
561 if (empty($a_auth_data["client_id"])) {
562 $this->error = "no_client_id";
563 return false;
564 }
565
566 if (empty($a_auth_data["username"])) {
567 $this->error = "no_username";
568 return false;
569 }
570
571 if (empty($a_auth_data["password"])) {
572 $this->error = "no_password";
573 return false;
574 }
575
576 if (!$this->newClient($a_auth_data["client_id"])) { //TT: comment out to get around null db
577 $this->error = "unknown_client_id";
578 unset($this->client);
579 return false;
580 }
581
582 if (!$this->client->db_exists) {
583 $this->error = "no_db_connect_consult_admin";
584 unset($this->client);
585 return false;
586 }
587
588 $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = " .
589 $this->client->db->quote('system_role_id', 'text'));
590 $r1 = $this->client->db->fetchAssoc($s1);
591 $system_role_id = $r1["value"];
592
593 $add_usrfields = '';
594 if ($this->client->db->tableColumnExists('usr_data', 'passwd_enc_type')) {
595 $add_usrfields .= ' , usr_data.passwd_enc_type, usr_data.passwd_salt ';
596 }
597 $q = "SELECT usr_data.usr_id, usr_data.passwd $add_usrfields " .
598 "FROM usr_data " .
599 "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id " .
600 "WHERE rbac_ua.rol_id = " . $this->client->db->quote((int) $system_role_id, 'integer') . " " .
601 "AND usr_data.login=" . $this->client->db->quote($a_auth_data["username"], 'text');
602 $r = $this->client->db->query($q);
603 if (!$this->client->db->numRows($r)) {
604 $this->error = 'login_invalid';
605 return false;
606 }
607
608 $data = $this->client->db->fetchAssoc($r);
609
610 global $ilClientIniFile;
611
612 $ilClientIniFile = $this->client->ini;
613
614 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
615 $crypt_type = ilUserPasswordManager::getInstance()->getEncoderName();
616 if (strlen($add_usrfields) && ilUserPasswordManager::getInstance()->isEncodingTypeSupported($crypt_type)) {
617 require_once 'setup/classes/class.ilObjSetupUser.php';
618 $user = new ilObjSetupUser();
619 $user->setPasswd($data['passwd'], IL_PASSWD_CRYPTED);
620 $user->setPasswordEncodingType($data['passwd_enc_type']);
621 $user->setPasswordSalt($data['passwd_salt']);
622
623 $password_valid = ilUserPasswordManager::getInstance()->verifyPassword($user, $a_auth_data['password']);
624 } else {
625 $password_valid = $data['passwd'] == md5($a_auth_data['password']);
626 }
627
628 if ($password_valid) {
629 // all checks passed -> user valid
630 $_SESSION['auth'] = true;
631 $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
632 $_SESSION['access_mode'] = 'client';
633 $_SESSION['ClientId'] = $this->client->getId();
634 return true;
635 } else {
636 $this->error = 'login_invalid';
637 return false;
638 }
639 }
640
647 public function loginAsAdmin(string $raw) : bool
648 {
649 $passwordReHashCallback = function ($raw) {
650 $this->storeMasterPassword($raw);
651 };
652
653 if ($this->passwordManager->verifyPassword($this->getMasterPassword(), $raw, $passwordReHashCallback)) {
654 $_SESSION['auth'] = true;
655 $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
656 $_SESSION['access_mode'] = 'admin';
657 return true;
658 }
659
660 return false;
661 }
662
668 public function newClient($a_client_id = 0)
669 {
670 if (!$this->isInstalled()) {
671 return false;
672 }
673
674 $this->client = new ilClient($a_client_id);
675
676 if (!$this->client->init()) {
677 //echo "<br>noclientinit";
678 $this->error = get_class($this) . ": " . $this->client->getError();
679 $_SESSION["ClientId"] = "";
680 return false;
681 }
682
683 $_SESSION["ClientId"] = $a_client_id;
684
685 return true;
686 }
687
693 public function getStatus($client = 0)
694 {
695 if (!is_object($client)) {
696 if ($this->ini_client_exists) {
698 } else {
699 $client = new ilClient(0);
700 }
701 }
702
703 $status = array();
704 $status["ini"] = $this->checkClientIni($client); // check this one
705 $status["db"] = $this->checkClientDatabase($client);
706 if ($status["db"]["status"] === false and $status["db"]["update"] !== true) {
707 //$status["sess"]["status"] = false;
708 //$status["sess"]["comment"] = $status["db"]["comment"];
709 $status["lang"]["status"] = false;
710 $status["lang"]["comment"] = $status["db"]["comment"];
711 $status["contact"]["status"] = false;
712 $status["contact"]["comment"] = $status["db"]["comment"];
713
714 $status["proxy"]["status"] = false;
715 $status["proxy"]["comment"] = $status["db"]["comment"];
716
717 $status["nic"]["status"] = false;
718 $status["nic"]["comment"] = $status["db"]["comment"];
719 } else {
720 //$status["sess"] = $this->checkClientSessionSettings($client);
721 $status["lang"] = $this->checkClientLanguages($client);
722 $status["contact"] = $this->checkClientContact($client);
723 $status["proxy"] = $this->checkClientProxySettings($client);
724 $status["nic"] = $this->checkClientNIC($client);
725 $status["finish"] = $this->checkFinish($client);
726 $status["access"] = $this->checkAccess($client);
727 }
728
729 //return value
730 return $status;
731 }
732
738 public function checkFinish(&$client)
739 {
740 if ($client->getSetting("setup_ok")) {
741 $arr["status"] = true;
742 //$arr["comment"] = $this->lng->txt("setup_finished");
743 } else {
744 $arr["status"] = false;
745 $arr["comment"] = $this->lng->txt("setup_not_finished");
746 }
747
748 return $arr;
749 }
750
756 public function checkAccess(&$client)
757 {
758 if ($client->ini->readVariable("client", "access") == "1") {
759 $arr["status"] = true;
760 $arr["comment"] = $this->lng->txt("online");
761 } else {
762 $arr["status"] = false;
763 $arr["comment"] = $this->lng->txt("disabled");
764 }
765
766 return $arr;
767 }
768
774 public function checkClientIni(&$client)
775 {
776 if (!$arr["status"] = $client->init()) {
777 $arr["comment"] = $client->getError();
778 } else {
779 //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
780 }
781
782 return $arr;
783 }
784
785
791 {
792 $arr = array();
793 $client->provideGlobalDB();
794 if (!$arr["status"] = $client->db_exists) {
795 $arr["comment"] = $this->lng->txt("no_database");
796
797 return $arr;
798 }
799
800 if (!$arr["status"] = $client->db_installed) {
801 $arr["comment"] = $this->lng->txt("db_not_installed");
802
803 return $arr;
804 }
805 // TODO: move this to client class!!
806 $client->setup_ok = (bool) $client->getSetting("setup_ok");
807
808 $this->lng->setDbHandler($client->db);
809 $dbupdate = new ilDBUpdate($client->db);
810
811 if (!$arr["status"] = $dbupdate->getDBVersionStatus()) {
812 $arr["comment"] = $this->lng->txt("db_needs_update");
813 $arr["update"] = true;
814
815 return $arr;
816 } else {
817 if ($dbupdate->hotfixAvailable()) {
818 $arr["status"] = false;
819 $arr["comment"] = $this->lng->txt("hotfix_available");
820 $arr["update"] = true;
821
822 return $arr;
823 } else {
824 if ($dbupdate->customUpdatesAvailable()) {
825 $arr["status"] = false;
826 $arr["comment"] = $this->lng->txt("custom_updates_available");
827 $arr["update"] = true;
828
829 return $arr;
830 }
831 }
832 }
833
834 // check control information
835 global $ilDB;
836 $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
837 $crec = $ilDB->fetchAssoc($cset);
838 $client->revokeGlobalDB();
839 if ($crec["cnt"] == 0) {
840 $arr["status"] = false;
841 $arr["comment"] = $this->lng->txt("db_control_structure_missing");
842 $arr["update"] = true;
843
844 return $arr;
845 }
846
847 return $arr;
848 }
849
855 public function checkClientSessionSettings(&$client, $a_as_bool = false)
856 {
857 require_once('Services/Authentication/classes/class.ilSessionControl.php');
858
859 global $ilDB;
860 $db = $ilDB;
861
863
864 $query = "SELECT keyword, value FROM settings WHERE " . $db->in('keyword', $fields, false, 'text');
865 $res = $db->query($query);
866
867 $rows = array();
868 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
869 if ($row['value'] != '') {
870 $rows[] = $row;
871 } else {
872 break;
873 }
874 }
875
876 if (count($rows) != count($fields)) {
877 if ($a_as_bool) {
878 return false;
879 }
880 $arr["status"] = false;
881 $arr["comment"] = $this->lng->txt("session_management_not_configured");
882 } else {
883 if ($a_as_bool) {
884 return true;
885 }
886 $arr["status"] = true;
887 $arr["comment"] = $this->lng->txt("session_management_configured");
888 }
889
890 return $arr;
891 }
892
893
899 {
900 $client->provideGlobalDB();
901 global $ilDB;
902 $arr = array();
903 $fields = array( 'proxy_status', 'proxy_host', 'proxy_port' );
904
905 $query = "SELECT keyword, value FROM settings WHERE " . $ilDB->in('keyword', $fields, false, 'text');
906 $res = $ilDB->query($query);
907
908 $proxy_settings = array();
909 $already_saved = false;
910 while ($row = $ilDB->fetchAssoc($res)) {
911 $already_saved = true;
912 $proxy_settings[$row['keyword']] = $row['value'];
913 }
914
915 if (!$already_saved) {
916 $arr["status"] = false;
917 $arr["comment"] = $this->lng->txt("proxy");
918 $arr["text"] = $this->lng->txt("proxy");
919 } else {
920 if ((bool) $proxy_settings["proxy_status"] == false) {
921 $arr["status"] = true;
922 $arr["comment"] = $this->lng->txt("proxy_disabled");
923 $arr["text"] = $this->lng->txt("proxy_disabled");
924 } else {
925 $arr["status"] = true;
926 $arr["comment"] = $this->lng->txt("proxy_activated_configurated");
927 $arr["text"] = $this->lng->txt("proxy_activated_configurated");
928 }
929 }
930
931 return $arr;
932 }
933
934
940 {
941 $client->provideGlobalDB();
942 $installed_langs = $this->lng->getInstalledLanguages();
943
944 $count = count($installed_langs);
945 $arr = array();
946 if ($count < 1) {
947 $arr["status"] = false;
948 $arr["comment"] = $this->lng->txt("lang_none_installed");
949 } else {
950 $arr["status"] = true;
951 //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
952 }
953 $client->revokeGlobalDB();
954 return $arr;
955 }
956
962 public function checkClientContact(&$client)
963 {
964 $arr["status"] = true;
965 //$arr["comment"] = $this->lng->txt("filled_out");
966
967 $settings = $client->getAllSettings();
968 $client_name = $client->getName();
969
970 // check required fields
971 if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
972 empty($settings["admin_email"]) or empty($client_name)) {
973 $arr["status"] = false;
974 $arr["comment"] = $this->lng->txt("missing_data");
975 }
976
977 // admin email
978 if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false) {
979 $arr["status"] = false;
980 $arr["comment"] = $this->lng->txt("email_not_valid");
981 }
982
983 return $arr;
984 }
985
991 public function checkClientNIC(&$client)
992 {
993 $settings = $client->getAllSettings();
994
995 if (!isset($settings["nic_enabled"])) {
996 $arr["status"] = false;
997 $arr["comment"] = $this->lng->txt("nic_not_disabled");
998 return $arr;
999 }
1000
1001 $arr["status"] = true;
1002
1003 if ($settings["nic_enabled"] == "-1") {
1004 $arr["comment"] = $this->lng->txt("nic_reg_failed");
1005 return $arr;
1006 }
1007
1008 if (!$settings["nic_enabled"]) {
1009 $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1010 } else {
1011 $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1012 if ($settings["inst_id"] <= 0) {
1013 $arr["status"] = false;
1014 }
1015 }
1016
1017 return $arr;
1018 }
1019
1024 public function isInstalled()
1025 {
1027 }
1028
1033 public function isAuthenticated()
1034 {
1035 return $this->auth;
1036 }
1037
1042 public function isAdmin()
1043 {
1044 return ($this->access_mode == "admin") ? true : false;
1045 }
1046
1052 public function saveMasterSetup($a_formdata)
1053 {
1054 $datadir_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1055
1056 if ($a_formdata["chk_datadir_path"] == 1) { // mode create dir
1057 if (!ilUtil::makeDir($datadir_path)) {
1058 $this->error = "create_datadir_failed";
1059 return false;
1060 }
1061 }
1062
1063 // create webspace dir if it does not exist
1064 if (!@file_exists(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path")) and !@is_dir(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path"))) {
1065 if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH . "/" . $this->ini->readVariable("clients", "path"))) {
1066 $this->error = "create_webdir_failed";
1067 return false;
1068 }
1069 }
1070
1071 $form_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1072 $log_path = substr($form_log_path, 0, strrpos($form_log_path, "/"));
1073 $log_file = substr($form_log_path, strlen($log_path) + 1);
1074 $error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1075
1076 $this->ini->setVariable("server", "http_path", ILIAS_HTTP_PATH);
1077 $this->ini->setVariable("server", "absolute_path", ILIAS_ABSOLUTE_PATH);
1078 $this->ini->setVariable("server", "timezone", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["time_zone"])));
1079 $this->ini->setVariable("clients", "datadir", $datadir_path);
1080 $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"])));
1081 $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"])));
1082 $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"])));
1083 $this->ini->setVariable("tools", "ghostscript", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"])));
1084 $this->ini->setVariable("tools", "java", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"])));
1085 //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1086 $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1087 $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1088 $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1089 $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["scan_command"])));
1090 $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["clean_command"])));
1091 $this->ini->setVariable("tools", "enable_system_styles_management", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["enable_system_styles_management"])));
1092 $this->ini->setVariable("tools", "lessc", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["lessc_path"])));
1093 $this->ini->setVariable("tools", "phantomjs", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["phantomjs_path"])));
1094
1095 $this->ini->setVariable('setup', 'pass', $this->passwordManager->encodePassword($a_formdata['setup_pass']));
1096 $this->ini->setVariable("log", "path", $log_path);
1097 $this->ini->setVariable("log", "file", $log_file);
1098 $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1099 $this->ini->setVariable("log", "error_path", $error_log_path);
1100
1101 $this->ini->setVariable("https", "auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1102 $this->ini->setVariable("https", "auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1103 $this->ini->setVariable("https", "auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1104
1105 if (!$this->ini->write()) {
1106 $this->error = get_class($this) . ": " . $this->ini->getError();
1107 return false;
1108 }
1109
1110 // everything is fine. so we authenticate the user and set access mode to 'admin'
1111 $_SESSION["auth"] = true;
1112 $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1113 $_SESSION["access_mode"] = "admin";
1114
1115 return true;
1116 }
1117
1123 public function updateMasterSettings($a_formdata)
1124 {
1125 $convert_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"]));
1126 $zip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"]));
1127 $unzip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"]));
1128 $ghostscript_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1129 $java_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"]));
1130 //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1131 $ffmpeg_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1132 $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1133 $fop_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["fop_path"]));
1134 $scan_type = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1135 $scan_command = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["scan_command"]));
1136 $clean_command = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["clean_command"]));
1137 $enable_system_styles_management = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["enable_system_styles_management"]));
1138 $lessc_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["lessc_path"]));
1139 $phantomjs_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["phantomjs_path"]));
1140
1141 $this->ini->setVariable("tools", "convert", $convert_path);
1142 $this->ini->setVariable("tools", "zip", $zip_path);
1143 $this->ini->setVariable("tools", "unzip", $unzip_path);
1144 $this->ini->setVariable("tools", "ghostscript", $ghostscript_path);
1145 $this->ini->setVariable("tools", "java", $java_path);
1146 //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1147 $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1148 $this->ini->setVariable("tools", "latex", $latex_url);
1149 $this->ini->setVariable("tools", "fop", $fop_path);
1150 $this->ini->setVariable("tools", "vscantype", $scan_type);
1151 $this->ini->setVariable("tools", "scancommand", $scan_command);
1152 $this->ini->setVariable("tools", "cleancommand", $clean_command);
1153 $this->ini->setVariable("tools", "lessc", $lessc_path);
1154 $this->ini->setVariable("tools", "enable_system_styles_management", $enable_system_styles_management);
1155 $this->ini->setVariable("tools", "phantomjs", $phantomjs_path);
1156
1157 $form_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1158 $log_path = substr($form_log_path, 0, strrpos($form_log_path, "/"));
1159 $log_file = substr($form_log_path, strlen($log_path) + 1);
1160
1161 $error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["error_log_path"])));
1162
1163 $this->ini->setVariable("log", "path", $log_path);
1164 $this->ini->setVariable("log", "file", $log_file);
1165 $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1166 $this->ini->setVariable("log", "error_path", $error_log_path);
1167 $this->ini->setVariable("server", "timezone", preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["time_zone"])));
1168
1169 $this->ini->setVariable("https", "auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1170 $this->ini->setVariable("https", "auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1171 $this->ini->setVariable("https", "auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1172
1173 if (!$this->ini->write()) {
1174 $this->error = get_class($this) . ": " . $this->ini->getError();
1175 return false;
1176 }
1177
1178 return true;
1179 }
1180
1186 public function checkToolsSetup($a_formdata)
1187 {
1188 // convert path
1189 if (!isset($a_formdata["chk_convert_path"])) {
1190 // convert backslashes to forwardslashes
1191 $convert_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["convert_path"]));
1192
1193 if (($err = $this->testConvert($convert_path)) != "") {
1194 $this->error = $err;
1195 return false;
1196 }
1197 }
1198
1199 // zip path
1200 if (!isset($a_formdata["chk_zip_path"])) {
1201 // convert backslashes to forwardslashes
1202 $zip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["zip_path"]));
1203
1204 if (empty($zip_path)) {
1205 $this->error = "no_path_zip";
1206 return false;
1207 }
1208
1209 if (!$this->testZip($zip_path)) {
1210 $this->error = "check_failed_zip";
1211 return false;
1212 }
1213 }
1214
1215 // unzip path
1216 if (!isset($a_formdata["chk_unzip_path"])) {
1217 // convert backslashes to forwardslashes
1218 $unzip_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["unzip_path"]));
1219
1220 if (empty($unzip_path)) {
1221 $this->error = "no_path_unzip";
1222 return false;
1223 }
1224
1225 if (!$this->testUnzip($unzip_path)) {
1226 $this->error = "check_failed_unzip";
1227 return false;
1228 }
1229 }
1230
1231 // ghostscript path
1232 if (!isset($a_formdata["chk_ghostscript_path"])) {
1233 // convert backslashes to forwardslashes
1234 $ghostscript_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1235
1236 if (($err = $this->testGhostscript($ghostscript_path)) != "") {
1237 $this->error = $err;
1238 return false;
1239 }
1240 }
1241
1242 // java path
1243 if (!isset($a_formdata["chk_java_path"])) {
1244 // convert backslashes to forwardslashes
1245 $java_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["java_path"]));
1246
1247 if (empty($java_path)) {
1248 $this->error = "no_path_java";
1249 return false;
1250 }
1251
1252 if (!$this->testJava($java_path)) {
1253 $this->error = "check_failed_java";
1254 return false;
1255 }
1256 }
1257
1258 /*if (!isset($a_formdata["chk_mkisofs_path"]))
1259 {
1260 // convert backslashes to forwardslashes
1261 $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1262
1263 if (empty($mkisofs_path))
1264 {
1265 $this->error = "no_path_mkisofs";
1266 return false;
1267 }
1268 }*/
1269
1270 if (!isset($a_formdata["chk_ffmpeg_path"])) {
1271 // convert backslashes to forwardslashes
1272 $ffmpeg_path = preg_replace("/\\\\/", "/", ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1273
1274 if (empty($ffmpeg_path)) {
1275 $this->error = "no_path_ffmpeg";
1276 return false;
1277 }
1278
1279 if (!$this->testFFMpeg($ffmpeg_path)) {
1280 $this->error = "check_failed_ffmpeg";
1281 return false;
1282 }
1283 }
1284
1285 // latex url
1286 if (!isset($a_formdata["chk_latex_url"])) {
1287 $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1288 if (empty($latex_url)) {
1289 $this->error = "no_latex_url";
1290 return false;
1291 }
1292
1293 if (!$this->testLatex($latex_url)) {
1294 $this->error = "check_failed_latex";
1295 return false;
1296 }
1297 }
1298
1299 return true;
1300 }
1301
1307 public function checkDataDirSetup($a_formdata)
1308 {
1309 // remove trailing slash & convert backslashes to forwardslashes
1310 $datadir_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1311
1312 if (empty($datadir_path)) {
1313 $this->error = "no_path_datadir";
1314 return false;
1315 }
1316
1317 $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1318
1319 // datadir may not point to webspace dir or to any place under webspace_dir
1320 if (strpos($datadir_path, $webspace_dir) !== false) {
1321 $this->error = "datadir_webspacedir_match";
1322 return false;
1323 }
1324
1325 // create dir
1326 if ($a_formdata["chk_datadir_path"] == 1) {
1327 $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1328 $dir_to_check = substr($datadir_path, 0, -strlen($dir_to_create) - 1);
1329
1330 if ($this->isDirectoryInOther($dir_to_create, ILIAS_ABSOLUTE_PATH)) {
1331 $this->error = "cannot_create_datadir_inside_webdir";
1332 return false;
1333 }
1334
1335 if (is_writable($datadir_path)) {
1336 $this->error = "dir_exists_create";
1337 return false;
1338 }
1339
1340 if (!is_writable($dir_to_check)) {
1341 $this->error = "cannot_create_datadir_no_write_access";
1342 return false;
1343 }
1344 } else { // check set target dir
1345 if ($this->isDirectoryInOther($datadir_path, ILIAS_ABSOLUTE_PATH)) {
1346 $this->error = "cannot_create_datadir_inside_webdir";
1347 return false;
1348 }
1349
1350 if (!is_writable($datadir_path)) {
1351 $this->error = "cannot_create_datadir_no_write_access";
1352 return false;
1353 }
1354 }
1355
1356 return true;
1357 }
1358
1364 public function checkPasswordSetup($a_formdata)
1365 {
1366 if (!$a_formdata["setup_pass"]) {
1367 $this->error = "no_setup_pass_given";
1368 return false;
1369 }
1370
1371 if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"]) {
1372 $this->error = "pass_does_not_match";
1373 return false;
1374 }
1375
1376 return true;
1377 }
1378
1384 public function checkLogSetup($a_formdata)
1385 {
1386 // log path
1387 if (!$a_formdata["chk_log_status"]) {
1388 // remove trailing slash & convert backslashes to forwardslashes
1389 $log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1390
1391 if (empty($log_path)) {
1392 $this->error = "no_path_log";
1393 return false;
1394 }
1395
1396 if (is_dir($log_path)) {
1397 $this->error = 'could_not_create_logfile';
1398 return false;
1399 }
1400
1401 if ($this->isDirectoryInOther($log_path, ILIAS_ABSOLUTE_PATH)) {
1402 $this->error = "cannot_create_logdir_inside_webdir";
1403 return false;
1404 }
1405
1406 if (!@touch($log_path)) {
1407 $this->error = "could_not_create_logfile";
1408 return false;
1409 }
1410 }
1411
1412 return true;
1413 }
1414
1422 public function checkErrorLogSetup($error_log_path)
1423 {
1424 // remove trailing slash & convert backslashes to forwardslashes
1425 $clean_error_log_path = preg_replace("/\\\\/", "/", ilFile::deleteTrailingSlash(ilUtil::stripSlashes($error_log_path)));
1426
1427 if (!empty($clean_error_log_path)) {
1428 if (!ilUtil::makeDirParents($clean_error_log_path)) {
1429 $this->error = "could_not_create_error_directory";
1430 return false;
1431 }
1432 }
1433
1434 return true;
1435 }
1436
1441 public function getError()
1442 {
1443 if (empty($this->error)) {
1444 return false;
1445 }
1446
1448 $this->error = "";
1449
1450 return $error;
1451 }
1452
1458 public function _ilSetup()
1459 {
1460 //if ($this->ini->readVariable("db","type") != "")
1461 //{
1462 // $this->db->disconnect();
1463 //}
1464 return true;
1465 }
1466
1473 public function testConvert($a_convert_path)
1474 {
1475 if (trim($a_convert_path) == "") {
1476 return "no_path_convert";
1477 }
1478 if (!is_file($a_convert_path)) {
1479 return "check_failed_convert";
1480 }
1481
1482 return "";
1483 }
1484
1491 public function testGhostscript($a_ghostscript_path)
1492 {
1493 // ghostscript is optional, so empty path is ok
1494 if (trim($a_ghostscript_path) == "") {
1495 return "";
1496 }
1497 if (!is_file($a_ghostscript_path)) {
1498 return "check_failed_ghostscript";
1499 }
1500
1501 return "";
1502 }
1503
1510 public function testJava($a_java_path)
1511 {
1512 // java is optional, so empty path is ok
1513 if (trim($a_java_path) == "") {
1514 return "";
1515 }
1516
1517 if (!is_file($a_java_path)) {
1518 return "check_failed_java";
1519 }
1520
1521 return "";
1522 /*
1523 exec($a_java_path, $out, $back);
1524
1525 unset($out);
1526
1527 return ($back != 1) ? false : true;
1528 */
1529 }
1530
1537 public function testLatex($a_latex_url)
1538 {
1539 // latex is optional, so empty path is ok
1540 if (trim($a_latex_url) == "") {
1541 return "";
1542 }
1543
1544 // open the URL
1545 include_once "./setup/classes/class.ilHttpRequest.php";
1546 $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1547 $result = @$http->downloadToString();
1548 if ((strpos((substr($result, 0, 5)), "PNG") !== false) || (strpos((substr($result, 0, 5)), "GIF") !== false)) {
1549 return "";
1550 } else {
1551 return "check_failed_latex";
1552 ;
1553 }
1554 }
1555
1562 public function testZip($a_zip_path)
1563 {
1564 if (trim($a_zip_path) == "") {
1565 return "no_path_zip";
1566 }
1567 if (!is_file($a_zip_path)) {
1568 return "check_failed_zip";
1569 }
1570
1571 return "";
1572 /*
1573 // create test file and run zip
1574 $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1575
1576 fwrite($fp, "test");
1577 fclose($fp);
1578
1579 if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1580 {
1581 $curDir = getcwd();
1582 chdir(ILIAS_ABSOLUTE_PATH);
1583
1584 $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1585
1586 exec($zipCmd);
1587
1588 chdir($curDir);
1589
1590 }
1591
1592 // check wether zip generated test file or not
1593 if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1594 {
1595 unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1596 return true;
1597 }
1598 else
1599 {
1600 unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1601 return false;
1602 }
1603 */
1604 }
1605
1606
1613 public function testUnzip($a_unzip_path)
1614 {
1615 if (trim($a_unzip_path) == "") {
1616 return "no_path_unzip";
1617 }
1618 if (!is_file($a_unzip_path)) {
1619 return "check_failed_unzip";
1620 }
1621
1622 return "";
1623 /*
1624 $curDir = getcwd();
1625
1626 chdir(ILIAS_ABSOLUTE_PATH);
1627
1628 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1629 {
1630 $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1631 exec($unzipCmd);
1632 }
1633
1634 chdir($curDir);
1635
1636 // check wether unzip extracted the test file or not
1637 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1638 {
1639 unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1640
1641 return true;
1642 }
1643 else
1644 {
1645 return false;
1646 }
1647 */
1648 }
1649
1656 public function unzip($a_file, $overwrite = false)
1657 {
1658 //global $ilias;
1659
1660 $pathinfo = pathinfo($a_file);
1661 $dir = $pathinfo["dirname"];
1662 $file = $pathinfo["basename"];
1663
1664 // unzip
1665 $cdir = getcwd();
1666 chdir($dir);
1667 $unzip = $this->ini->readVariable("tools", "unzip");
1668 $unzipcmd = $unzip . " -Z -1 " . ilUtil::escapeShellArg($file);
1669 exec($unzipcmd, $arr);
1670 $zdirs = array();
1671
1672 foreach ($arr as $line) {
1673 if (is_int(strpos($line, "/"))) {
1674 $zdir = substr($line, 0, strrpos($line, "/"));
1675 $nr = substr_count($zdir, "/");
1676 //echo $zdir." ".$nr."<br>";
1677 while ($zdir != "") {
1678 $nr = substr_count($zdir, "/");
1679 $zdirs[$zdir] = $nr; // collect directories
1680 //echo $dir." ".$nr."<br>";
1681 $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1682 }
1683 }
1684 }
1685
1686 asort($zdirs);
1687
1688 foreach ($zdirs as $zdir => $nr) { // create directories
1690 }
1691
1692 // real unzip
1693 if ($overvwrite) {
1694 $unzipcmd = $unzip . " " . ilUtil::escapeShellArg($file);
1695 } else {
1696 $unzipcmd = $unzip . " -o " . ilUtil::escapeShellArg($file);
1697 }
1698 exec($unzipcmd);
1699
1700 chdir($cdir);
1701 }
1702
1708 public function setSessionSettings($session_settings)
1709 {
1710 require_once('Services/Authentication/classes/class.ilSessionControl.php');
1711
1712 $db = $this->client->getDB();
1713
1714 $setting_fields = ilSessionControl::getSettingFields();
1715
1716 $i = 0;
1717 foreach ($setting_fields as $field) {
1718 if (isset($session_settings[$field])) {
1719 $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1720 $res = $db->queryF(
1721 $query,
1722 array('text', 'text'),
1723 array('common', $field)
1724 );
1725
1726 $row = array();
1727 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1728 break;
1729 }
1730
1731 if (count($row) > 0) {
1732 $db->update(
1733 'settings',
1734 array(
1735 'value' => array('text', $session_settings[$field])
1736 ),
1737 array(
1738 'module' => array('text', 'common'),
1739 'keyword' => array('text', $field)
1740 )
1741 );
1742 } else {
1743 $db->insert(
1744 'settings',
1745 array(
1746 'module' => array('text', 'common'),
1747 'keyword' => array('text', $field),
1748 'value' => array('text', $session_settings[$field])
1749 )
1750 );
1751 }
1752
1753 $i++;
1754 }
1755 }
1756
1757 if ($i < 4) {
1758 $message = $this->lng->txt("session_settings_not_saved");
1759 } else {
1760 $message = $this->lng->txt("settings_saved");
1761 }
1762
1764 }
1765
1771 public function getSessionSettings()
1772 {
1773 require_once('Services/Authentication/classes/class.ilSessionControl.php');
1774
1775 $db = $this->client->getDB();
1776
1777 $setting_fields = ilSessionControl::getSettingFields();
1778
1779 $query = "SELECT * FROM settings WHERE module = %s " .
1780 "AND " . $db->in('keyword', $setting_fields, false, 'text');
1781
1782 $res = $db->queryF($query, array('text'), array('common'));
1783
1784 $session_settings = array();
1785 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1786 $session_settings[$row['keyword']] = $row['value'];
1787 }
1788
1789 foreach ($setting_fields as $field) {
1790 if (!isset($session_settings[$field])) {
1791 $value = 1;
1792
1793 switch ($field) {
1794 case 'session_max_count':
1795
1797 break;
1798
1799 case 'session_min_idle':
1800
1802 break;
1803
1804 case 'session_max_idle':
1805
1807 break;
1808
1809 case 'session_max_idle_after_first_request':
1810
1812 break;
1813
1814 case 'session_allow_client_maintenance':
1815
1817 break;
1818 }
1819
1820 $session_settings[$field] = $value;
1821 }
1822 }
1823
1824 return $session_settings;
1825 }
1826
1832 public function cloneFromSource($source_id)
1833 {
1834 // Getting source and targets
1835 $source = new ilClient($source_id);
1836 $source->init();
1837 $target = $this->client;
1838
1839 // ************************************************
1840 // ** COPY FILES
1841
1842 // Cleaning up datadir
1843 if (!ilUtil::delDir($target->getDataDir())) {
1844 $this->error = "Could not delete data dir $target->getDataDir()";
1845 //return false;
1846 }
1847
1848 // Create empty datadir
1849 if (!ilUtil::makeDir($target->getDataDir())) {
1850 $this->error = "could_not_create_base_data_dir :" . $target->getDataDir();
1851 return false;
1852 }
1853
1854 // Copying datadir
1855 if (!ilUtil::rCopy($source->getDataDir(), $target->getDataDir())) {
1856 $this->error = "clone_datadircopyfail";
1857 $target->ini->write();
1858 return false;
1859 }
1860
1861 // Cleaning up Webspacedir
1862 if (!ilUtil::delDir($target->getWebspaceDir())) {
1863 $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
1864 //return false;
1865 }
1866
1867 // Create empty Webspacedir
1868 if (!ilUtil::makeDir($target->getWebspaceDir())) {
1869 $this->error = "could_not_create_base_webspace_dir :" . $target->getWebspaceDir();
1870 return false;
1871 }
1872
1873 // Copying Webspacedir
1874 if (!ilUtil::rCopy($source->getWebspaceDir(), $target->getWebspaceDir())) {
1875 $this->error = "clone_websipacedircopyfail";
1876 $target->ini->write();
1877 return false;
1878 }
1879
1880 // Restore ini file
1881 $target->ini->write();
1882
1883 // ************************************************
1884 // ** COPY DATABASE
1885
1886 $source->connect();
1887 if (!$source->db) {
1888 $this->error = "Source database connection failed.";
1889 return false;
1890 }
1891
1892 $target->connect();
1893 if (!$target->db) {
1894 $this->error = "Target database connection failed.";
1895 return false;
1896 }
1897
1898 $source->connect();
1899 $srcTables = $source->db->query("SHOW TABLES");
1900 $target->connect();
1901
1902 // drop all tables of the target db
1903 $tarTables = $target->db->query("SHOW TABLES");
1904 foreach ($tarTables->fetchAll() as $cTable) {
1905 $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
1906 }
1907
1908 foreach ($srcTables->fetchAll() as $cTable) {
1909 $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
1910 $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
1911 if (!$create) {
1912 $error = true;
1913 }
1914 $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM " . $source->getDbName() . "." . $cTable[0]);
1915 }
1916
1917 $target->db->query("UPDATE settings SET VALUE = " . $target->db->quote(0, "integer") . " WHERE keyword = " . $target->db->quote("inst_id", "text"));
1918 $target->db->query("UPDATE settings SET VALUE = " . $target->db->quote(0, "integer") . " WHERE keyword = " . $target->db->quote("nic_enabled", "text"));
1919 return true;
1920 }
1928 public function printProxyStatus($client)
1929 {
1930 require_once './Services/Http/exceptions/class.ilProxyException.php';
1931 $settings = $client->getAllSettings();
1932
1933 if ((bool) $settings['proxy_status'] == true) {
1934 try {
1935 $err_str = false;
1936 $wait_timeout = 100;
1937
1938 $fp = @fsockopen($settings['proxy_host'], $settings['proxy_port'], $err_code, $err_str, $wait_timeout);
1939
1940 if ($err_str) {
1941 throw new ilProxyException($err_str);
1942 }
1943
1944 fclose($fp);
1945
1946 ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
1947 } catch (Exception $e) {
1948 ilUtil::sendFailure($this->lng->txt('proxy_not_connectable') . ": " . $e->getMessage());
1949 }
1950 }
1951 }
1952
1953 public function saveProxySettings($proxy_settings)
1954 {
1955 $db = $this->client->getDB();
1956 $proxy_fields = array('proxy_status','proxy_host','proxy_port');
1957
1958 foreach ($proxy_fields as $field) {
1959 if (isset($proxy_settings[$field])) {
1960 $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
1961 $res = $db->queryF(
1962 $query,
1963 array('text', 'text'),
1964 array('common', $field)
1965 );
1966
1967 $row = array();
1968 while ($row = $db->fetchAssoc($res)) {
1969 break;
1970 }
1971
1972 if (is_array($row) && count($row) > 0) {
1973 $db->update(
1974 'settings',
1975 array(
1976 'value' => array('text', $proxy_settings[$field])
1977 ),
1978 array(
1979 'module' => array('text', 'common'),
1980 'keyword' => array('text', $field)
1981 )
1982 );
1983 } else {
1984 $db->insert(
1985 'settings',
1986 array(
1987 'module' => array('text', 'common'),
1988 'keyword' => array('text', $field),
1989 'value' => array('text', $proxy_settings[$field])
1990 )
1991 );
1992 }
1993 }
1994 }
1995 }
1996
2003 public function isValidClientId($a_client_id)
2004 {
2005 if (!preg_match("/^[A-Za-z0-9]+$/", $a_client_id)) {
2006 return false;
2007 }
2008 return true;
2009 }
2010
2018 protected function isDirectoryInOther($directory, $other_directory)
2019 {
2020 $other_directory = $other_directory . "/";
2021
2022 return !(strpos($directory, $other_directory) !== 0);
2023 }
2024}
$result
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
const IL_PASSWD_CRYPTED
Client Management.
Database Update class.
deleteTrailingSlash($a_path)
delete trailing slash of path variables
ilHttpRequest class
INIFile Parser.
Class ilObjSetupUser A class derived from ilObjUser for authentication purposes in the ILIAS setup.
Class for proxy related exception handling in ILIAS.
static getSettingFields()
returns the array of setting fields
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet
Class ilSetupPasswordManager.
Setup class.
checkToolsSetup($a_formdata)
check pathes to 3rd party software
checkClientContact(&$client)
check client contact data status
installDatabase()
set the database data
checkWritable()
check for writable directory
checkAccess(&$client)
check client access status
getStatus($client=0)
coumpute client status
testLatex($a_latex_url)
Check latex cgi script.
loginAsClient($a_auth_data)
process client login
getMasterPassword()
checkErrorLogSetup($error_log_path)
check error log path
saveMasterSetup($a_formdata)
saves intial settings
checkPHPVersion()
check for PHP version
testZip($a_zip_path)
Check zip program.
cloneFromSource($source_id)
Clone source client into current client.
checkPasswordSetup($a_formdata)
check setup password
isAuthenticated()
check if current user is authenticated
checkAuth()
check authentication status
checkMySQL()
Check MySQL.
checkCreatable($a_dir=".")
check for permission to create new folders in specified directory
isInstalled()
check if client's db is installed
checkDom()
Check MySQL.
checkClientProxySettings(ilClient $client)
testUnzip($a_unzip_path)
Check unzip program.
isValidClientId($a_client_id)
Is valid client id.
checkClientDatabase(ilClient $client)
storeMasterPassword(string $raw)
verifyMasterPassword(string $raw)
checkDataDirSetup($a_formdata)
check datadir path
queryPreliminaries()
preliminaries
saveProxySettings($proxy_settings)
checkClientIni(&$client)
check client ini status
unzip($a_file, $overwrite=false)
unzip file
checkClientNIC(&$client)
check client nic status
testGhostscript($a_ghostscript_path)
Check ghostscript program.
updateMasterSettings($a_formdata)
updates settings
testConvert($a_convert_path)
Check convert program.
newClient($a_client_id=0)
creates a client object in $this->client
checkClientLanguages(ilClient $client)
printProxyStatus($client)
Print proxy settings.
checkCookiesEnabled()
check cookies enabled
isAdmin()
check if current user is admin
isDirectoryInOther($directory, $other_directory)
Checks if directory is subdirectory of other directory.
checkGd()
Check MySQL.
checkClientSessionSettings(&$client, $a_as_bool=false)
check client session config status
createDatabase($a_collation="")
create client database
setClient($a_cl)
__construct(\ilSetupPasswordManager $passwordManager, $a_auth, $a_auth_type)
constructor
init()
init setup load settings from ilias.ini if exists and sets some constants
checkLogSetup($a_formdata)
check log path
checkMemoryLimit()
Check Memory Limit.
saveNewClient()
saves client.ini & updates client list in ilias.ini
getSessionSettings()
reads session settings from db
loginAsAdmin(string $raw)
Process setup admin login.
setSessionSettings($session_settings)
saves session settings to db
updateNewClient($a_old_client_id)
update client.ini & move data dirs does not work correctly at this time - DISABLED
checkXsl()
Check MySQL.
_ilSetup()
destructor
checkPreliminaries()
check all prliminaries
checkFinish(&$client)
check if client setup was finished
checkIniFileExists()
check if inifile exists
testJava($a_java_path)
Check JVM.
getError()
get Error message
$preliminaries_result
static getInstance()
Single method to reduce footprint (included files, created instances)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static escapeShellArg($a_arg)
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static is_email($a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static createDirectory($a_dir, $a_mod=0755)
create directory
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
$i
Definition: metadata.php:24
$source
Definition: metadata.php:76
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$query
$http
Definition: raiseError.php:7
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23
$message
Definition: xapiexit.php:14
$rows
Definition: xhr_table.php:10