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