ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 if ($this->ini_ilias_exists)
99 {
100 if ($this->ini->readVariable("log","path") != "")
101 {
102 $log->path = $this->ini->readVariable("log","path");
103 }
104
105 if ($this->ini->readVariable("log","file") != "")
106 {
107 $log->filename = $this->ini->readVariable("log","file");
108 }
109
110 if ($this->ini->readVariable("log","enabled") != "")
111 {
112 $log->enabled = $this->ini->readVariable("log","enabled");
113 }
114 }
115 }
116
117
121 public $client;
122
123
127 public function setClient($a_cl) {
128 $this->client = $a_cl;
129 }
130
131
135 public function getClient() {
136 return $this->client;
137 }
138
144 function init()
145 {
146 // load data from setup.ini file
147 $this->ini = new ilIniFile($this->ini_file_path);
148
149 if (!$this->ini->read())
150 {
151 $this->ini->GROUPS = parse_ini_file($this->setup_defaults,true);
152 $this->error = get_class($this).": ".$this->ini->getError();
153 return false;
154 }
155
156 $this->setup_password = $this->ini->readVariable("setup","pass");
157 $this->default_client = $this->ini->readVariable("clients","default");
158
159 define("ILIAS_DATA_DIR",$this->ini->readVariable("clients","datadir"));
160 define("ILIAS_WEB_DIR",$this->ini->readVariable("clients","path"));
161
162 return true;
163 }
164
169 function saveNewClient()
170 {
171 // save client id to session
172 $_SESSION["ClientId"] = $this->client->getId();
173
174 // create client
175 if (!$this->client->create())
176 {
177 $this->error = $this->client->getError();
178 return false;
179 }
180
181 //everything okay
182 $this->ini_client_exists = true;
183
184 return true;
185 }
186
192 function updateNewClient($a_old_client_id)
193 {
194 return true;
195 //var_dump("<pre>",$this->client,"</pre>");exit;
196
197 if ($a_old_client_id != $this->client->getId())
198 {
199 // check for existing client dir
200 if (file_exists(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->client->getId()))
201 {
202 $this->raiseError($this->lng->txt("client_id_already_exists"),$this->error_obj->MESSAGE);
203 }
204
205 if (!$this->saveNewClient())
206 {
207 $this->raiseError($this->lng->txt("save_error"),$this->error_obj->MESSAGE);
208 }
209
210 ilUtil::delDir(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$a_old_client_id);
211 ilUtil::delDir(ILIAS_DATA_DIR."/".$a_old_client_id);
212 }
213
214 //everything okay
215 $this->ini_client_exists = true;
216
217 return true;
218 }
219
224 function createDatabase($a_collation = "")
225 {
226 if ($this->client->checkDatabaseExists())
227 {
228 $this->error = $this->lng->txt("database_exists");
229 return false;
230 }
231
232 $this->client->getDB()->connectHost(true);
233
234 //create database
235 $db = $this->client->getDB();
236 if (MDB2::isError($db))
237 {
238 $this->error = "connection_failed";
239 return false;
240 }
241
242 $r = $db->createDatabase($this->client->getdbName(),
243 "utf8", $a_collation);
244
245 if (MDB2::isError($r))
246 {
247 $this->error = "create_database_failed";
248 return false;
249 }
250
251 //database is created, now disconnect and reconnect
252 $db->disconnect();
253
254 $this->client->db_exists = true;
255 return true;
256 }
257
263 {
264/* if (!$this->client->checkDatabaseHost())
265 {
266 $this->error = "no_connection_to_host";
267 return false;
268 }*/
269
270 if (!$this->client->connect())
271 {
272 return false;
273 }
274
275 //take sql dump an put it in
276 if ($this->readDump($this->client->db, $this->SQL_FILE))
277 {
278 $this->client->db_installed = true;
279 return true;
280 }
281 else
282 {
283 return false;
284 }
285 }
286
287 function getline( $fp, $delim )
288 {
289 $result = "";
290 while( !feof( $fp ) )
291 {
292 $tmp = fgetc( $fp );
293 if( $tmp == $delim )
294 return $result;
295 $result .= $tmp;
296 }
297 return $result;
298 }
299
306 function readDump($db, $file)
307 {
308 // mysql (old procedure)
309 if ($db->getDBType() == "mysql")
310 {
311 $fp = fopen($file, 'r');
312
313 while(!feof($fp))
314 {
315 //$line = trim(fgets($fp, 200000));
316 $line = trim($this->getline($fp, "\n"));
317
318 if ($line != "" && substr($line,0,1)!="#"
319 && substr($line,0,1)!="-")
320 {
321 //take line per line, until last char is ";"
322 if (substr($line,-1)==";")
323 {
324 //query is complete
325 $q .= " ".substr($line,0,-1);
326 $r = $db->query($q);
327
328 if ($db->getErrorNo() > 0)
329 {
330 echo "<br />ERROR: ".$db->getError().
331 "<br />SQL: $q";
332 return false;
333 }
334 unset($q);
335 unset($line);
336 } //if
337 else
338 {
339 $q .= " ".$line;
340 } //else
341 } //if
342 } //for
343
344 fclose($fp);
345 }
346
347 #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
348 if (in_array($db->getDBType(), array("oracle", "postgres", "innodb")))
349 {
350 if(@is_dir('./setup/sql/ilDBTemplate'))
351 {
352 include_once './Services/Database/classes/class.ilArrayTableDataParser.php';
353 include_once './Services/Xml/exceptions/class.ilSaxParserException.php';
354 $reader = new tmpDirectoyIterator('./setup/sql/ilDBTemplate');
355 foreach($reader as $file)
356 {
357 eval(file_get_contents('./setup/sql/ilDBTemplate/'.$file));
358 try
359 {
360 $parser = new ilArrayTableDataParser('./setup/sql/ilDBTemplate/'.$file.'_inserts');
361 #$parser = new ilSimpleXMLTableDataParser('./setup/sql/ilDBTemplate/'.$file.'.xml');
362 $parser->startParsing();
363 #echo 'Table: '.$file.', memory: '.memory_get_peak_usage().' peak: '.memory_get_peak_usage().'<br />';flush();
364
365 }
366 catch(ilSaxParserException $e)
367 {
368 die($e);
369 }
370 }
371 }
372 else
373 {
374 include_once("./setup/sql/ilDBTemplate.php");
375 setupILIASDatabase();
376 }
377 }
378 #echo 'Start Memory: '.memory_get_usage().' peak: '.memory_get_peak_usage();
379 return true;
380 }
381
382
388 {
389 $a = @file_exists($this->INI_FILE);
390 return $a;
391 }
392
398 function checkWritable()
399 {
400 clearstatcache();
401 if (is_writable("."))
402 {
403 $arr["status"] = true;
404 //$cdir = getcwd();
405 //chdir("..");
406 $arr["comment"] = getcwd();
407 //chdir($cdir);
408 }
409 else
410 {
411 $arr["status"] = false;
412 $arr["comment"] = $this->lng->txt("pre_folder_write_error");
413 //$cdir = getcwd();
414 //chdir("..");
415 $arr["comment"] = getcwd().": ".$arr["comment"];
416 //chdir($cdir);
417 }
418
419 return $arr;
420 }
421
427 function checkCreatable($a_dir = ".")
428 {
429 clearstatcache();
430 if (@mkdir($a_dir."/crst879dldsk9d", 0774))
431 {
432 $arr["status"] = true;
433 $arr["comment"] = "";
434
435 @rmdir($a_dir."/crst879dldsk9d");
436 }
437 else
438 {
439 $arr["status"] = false;
440 //$cdir = getcwd();
441 //chdir("..");
442 $arr["comment"] = getcwd().": ".$this->lng->txt("pre_folder_create_error");
443 //chdir($cdir);
444 }
445
446 return $arr;
447 }
448
454 {
455 global $sess;
456
457 if ($sess->usesCookies)
458 {
459 $arr["status"] = true;
460 $arr["comment"] = "";
461 }
462 else
463 {
464 $arr["status"] = false;
465 $arr["comment"] = $this->lng->txt("pre_cookies_disabled");
466 }
467
468 return $arr;
469 }
470
476 {
477 $version = PHP_VERSION;
478
479 $arr["status"] = true;
480 $arr["comment"] = "PHP ".$version;
481 if (version_compare($version, '5.3.0', '<'))
482 {
483 $arr["status"] = false;
484 $arr["comment"] = "PHP ".$version.". ".$this->lng->txt("pre_php_version_too_low");
485 }
486
487 return $arr;
488 }
489
494 function checkMySQL()
495 {
496 global $ilDB;
497
498 if (function_exists("mysql_query"))
499 {
500 $arr["status"] = true;
501 $arr["comment"] = $this->lng->txt("pre_mysql_4_1_or_higher");
502 }
503 else
504 {
505 $arr["status"] = false;
506 $arr["comment"] = $this->lng->txt("pre_mysql_missing");
507 }
508
509 return $arr;
510 }
511
516 function checkAuth()
517 {
518 if ($_SESSION["auth"] === true && $_SESSION["auth_path"] == ILIAS_HTTP_PATH)
519 {
520 return true;
521 }
522
523 return false;
524 }
525
526
531 function checkDom()
532 {
533 global $ilDB;
534
535 if (class_exists("DOMDocument"))
536 {
537 $arr["status"] = true;
538 }
539 else
540 {
541 $arr["status"] = false;
542 $arr["comment"] = $this->lng->txt("pre_dom_missing");
543 }
544
545 return $arr;
546 }
547
552 function checkXsl()
553 {
554 global $ilDB;
555
556 if (class_exists("XSLTProcessor"))
557 {
558 $arr["status"] = true;
559 }
560 else
561 {
562 $arr["status"] = false;
563 $arr["comment"] = sprintf($this->lng->txt("pre_xsl_missing"),
564 "http://php.net/manual/en/book.xsl.php");
565 }
566
567 return $arr;
568 }
569
574 function checkGd()
575 {
576 global $ilDB;
577
578 if (function_exists("imagefill") && function_exists("imagecolorallocate"))
579 {
580 $arr["status"] = true;
581 }
582 else
583 {
584 $arr["status"] = false;
585 $arr["comment"] = sprintf($this->lng->txt("pre_gd_missing"),
586 "http://php.net/manual/en/book.image.php");
587 }
588
589 return $arr;
590 }
591
597 {
598 global $ilDB;
599
600 $limit = ini_get("memory_limit");
601
602 $limit_ok = true;
603 if (is_int(strpos($limit, "M")))
604 {
605 $limit_n = (int) $limit;
606 if ($limit_n < 40)
607 {
608 $limit_ok = false;
609 }
610 }
611
612 if ($limit_ok)
613 {
614 $arr["status"] = true;
615 $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_recommend");
616 }
617 else
618 {
619 $arr["status"] = false;
620 $arr["comment"] = $limit.". ".$this->lng->txt("pre_memory_limit_too_low");
621 }
622
623 return $arr;
624 }
625
626
630 protected function checkOpcacheSettings() {
631 $arr = array();
632 $load_comments = ini_get("opcache.load_comments");
633 if($load_comments == 1) {
634 $arr["status"] = true;
635 } else {
636 $arr["status"] = false;
637 $arr["comment"] = $this->lng->txt("pre_opcache_comments");
638 }
639
640 return $arr;
641 }
642
651 {
652 $a = array();
653 $a["php"] = $this->checkPHPVersion();
654// $a["mysql"] = $this->checkMySQL();
655 $a["root"] = $this->checkWritable();
656 $a["folder_create"] = $this->checkCreatable();
657 $a["cookies_enabled"] = $this->checkCookiesEnabled();
658 $a["dom"] = $this->checkDom();
659 $a["xsl"] = $this->checkXsl();
660 $a["gd"] = $this->checkGd();
661 $a["memory"] = $this->checkMemoryLimit();
662// var_dump(ini_get('opcache.enable') ); // FSX
663 if ($this->hasOpCacheEnabled()) {
664 $a["load_comments"] = $this->checkOpcacheSettings();
665 }
666
667 return $a;
668 }
669
675 {
676 $this->preliminaries_result = $this->queryPreliminaries();
677
678 foreach ($this->preliminaries_result as $val)
679 {
680 if ($val["status"] === false)
681 {
682 $this->preliminaries = false;
683 return false;
684 }
685 }
686
687 return true;
688 }
689
694 function getPassword ()
695 {
696 return $this->ini->readVariable("setup","pass");
697 }
698
704 function setPassword ($a_password)
705 {
706 $this->ini->setVariable("setup","pass",md5($a_password));
707
708 if ($this->ini->write() == false)
709 {
710 $this->error = $this->ini->getError();
711 return false;
712 }
713
714 return true;
715 }
716
722 function loginAsClient($a_auth_data)
723 {
724 global $ilDB;
725
726 if (empty($a_auth_data["client_id"]))
727 {
728 $this->error = "no_client_id";
729 return false;
730 }
731
732 if (empty($a_auth_data["username"]))
733 {
734 $this->error = "no_username";
735 return false;
736 }
737
738 if (empty($a_auth_data["password"]))
739 {
740 $this->error = "no_password";
741 return false;
742 }
743
744 if (!$this->newClient($a_auth_data["client_id"]))
745 {
746 $this->error = "unknown_client_id";
747 unset($this->client);
748 return false;
749 }
750
751 if (!$this->client->db_exists)
752 {
753 $this->error = "no_db_connect_consult_admin";
754 unset($this->client);
755 return false;
756 }
757
758 $s1 = $this->client->db->query("SELECT value from settings WHERE keyword = ".
759 $this->client->db->quote('system_role_id','text'));
760 $r1 = $this->client->db->fetchAssoc($s1);
761 $system_role_id = $r1["value"];
762
763 $add_usrfields = '';
764 if($this->client->db->tableColumnExists('usr_data', 'passwd_enc_type'))
765 {
766 $add_usrfields .= ' , usr_data.passwd_enc_type, usr_data.passwd_salt ';
767 }
768 $q = "SELECT usr_data.usr_id, usr_data.passwd $add_usrfields " .
769 "FROM usr_data " .
770 "LEFT JOIN rbac_ua ON rbac_ua.usr_id=usr_data.usr_id " .
771 "WHERE rbac_ua.rol_id = " . $this->client->db->quote((int)$system_role_id, 'integer') . " " .
772 "AND usr_data.login=" . $this->client->db->quote($a_auth_data["username"], 'text');
773 $r = $this->client->db->query($q);
774 if(!$this->client->db->numRows($r))
775 {
776 $this->error = 'login_invalid';
777 return false;
778 }
779
780 $data = $this->client->db->fetchAssoc($r);
781
782 global $ilClientIniFile;
783
784 $ilClientIniFile = $this->client->ini;
785
786 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
787 $crypt_type = ilUserPasswordManager::getInstance()->getEncoderName();
788 if(strlen($add_usrfields) && ilUserPasswordManager::getInstance()->isEncodingTypeSupported($crypt_type))
789 {
790 require_once 'setup/classes/class.ilObjSetupUser.php';
791 $user = new ilObjSetupUser();
792 $user->setPasswd($data['passwd'], IL_PASSWD_CRYPTED);
793 $user->setPasswordEncodingType($data['passwd_enc_type']);
794 $user->setPasswordSalt($data['passwd_salt']);
795
796 $password_valid = ilUserPasswordManager::getInstance()->verifyPassword($user, $a_auth_data['password'], false);
797 }
798 else
799 {
800 $password_valid = $data['passwd'] == md5($a_auth_data['password']);
801 }
802
803 if($password_valid)
804 {
805 // all checks passed -> user valid
806 $_SESSION['auth'] = true;
807 $_SESSION['auth_path'] = ILIAS_HTTP_PATH;
808 $_SESSION['access_mode'] = 'client';
809 $_SESSION['ClientId'] = $this->client->getId();
810 return true;
811 }
812 else
813 {
814 $this->error = 'login_invalid';
815 return false;
816 }
817 }
818
824 function loginAsAdmin($a_password)
825 {
826 $a_password = md5($a_password);
827
828 if ($this->ini->readVariable("setup","pass") == $a_password)
829 {
830 $_SESSION["auth"] = true;
831 $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
832 $_SESSION["access_mode"] = "admin";
833 return true;
834 }
835
836 return false;
837 }
838
844 function newClient($a_client_id = 0)
845 {
846 if (!$this->isInstalled())
847 {
848 return false;
849 }
850
851 $this->client = new ilClient($a_client_id, $this->db_connections);
852
853 if (!$this->client->init())
854 {
855//echo "<br>noclientinit";
856 $this->error = get_class($this).": ".$this->client->getError();
857 $_SESSION["ClientId"] = "";
858 return false;
859 }
860
861 $_SESSION["ClientId"] = $a_client_id;
862
863 return true;
864 }
865
871 function getStatus ($client = 0)
872 {
873 if (!is_object($client))
874 {
875 if ($this->ini_client_exists)
876 {
878 }
879 else
880 {
881 $client = new ilClient(0, $this->db_connections);
882 }
883 }
884
885 $status = array();
886 $status["ini"] = $this->checkClientIni($client); // check this one
887 $status["db"] = $this->checkClientDatabase($client);
888 if ($status["db"]["status"] === false and $status["db"]["update"] !== true)
889 {
890 //$status["sess"]["status"] = false;
891 //$status["sess"]["comment"] = $status["db"]["comment"];
892 $status["lang"]["status"] = false;
893 $status["lang"]["comment"] = $status["db"]["comment"];
894 $status["contact"]["status"] = false;
895 $status["contact"]["comment"] = $status["db"]["comment"];
896
897 $status["proxy"]["status"] = false;
898 $status["proxy"]["comment"] = $status["db"]["comment"];
899
900 $status["nic"]["status"] = false;
901 $status["nic"]["comment"] = $status["db"]["comment"];
902 }
903 else
904 {
905 //$status["sess"] = $this->checkClientSessionSettings($client);
906 $status["lang"] = $this->checkClientLanguages($client);
907 $status["contact"] = $this->checkClientContact($client);
908 $status["proxy"] = $this->checkClientProxySettings($client);
909 $status["nic"] = $this->checkClientNIC($client);
910 $status["finish"] = $this->checkFinish($client);
911 $status["access"] = $this->checkAccess($client);
912 }
913
914 //return value
915 return $status;
916 }
917
924 {
925 if ($client->getSetting("setup_ok"))
926 {
927 $arr["status"] = true;
928 //$arr["comment"] = $this->lng->txt("setup_finished");
929 }
930 else
931 {
932 $arr["status"] = false;
933 $arr["comment"] = $this->lng->txt("setup_not_finished");
934 }
935
936 return $arr;
937 }
938
945 {
946 if ($client->ini->readVariable("client","access") == "1")
947 {
948 $arr["status"] = true;
949 $arr["comment"] = $this->lng->txt("online");
950 }
951 else
952 {
953 $arr["status"] = false;
954 $arr["comment"] = $this->lng->txt("disabled");
955 }
956
957 return $arr;
958 }
959
966 {
967 if (!$arr["status"] = $client->init())
968 {
969 $arr["comment"] = $client->getError();
970 }
971 else
972 {
973 //$arr["comment"] = "dir: /".ILIAS_WEB_DIR."/".$client->getId();
974 }
975
976 return $arr;
977 }
978
985 {
986 if (!$arr["status"] = $client->db_exists)
987 {
988 $arr["comment"] = $this->lng->txt("no_database");
989 return $arr;
990 }
991
992 if (!$arr["status"] = $client->db_installed)
993 {
994 $arr["comment"] = $this->lng->txt("db_not_installed");
995 return $arr;
996 }
997
998 // TODO: move this to client class!!
999 $client->setup_ok = (bool) $client->getSetting("setup_ok");
1000
1001 //$this->lng->setDbHandler($client->db);
1002 include_once "./Services/Database/classes/class.ilDBUpdate.php";
1003 $ilDB = $client->db;
1004 $this->lng->setDbHandler($client->db);
1005 $dbupdate = new ilDBUpdate($client->db);
1006
1007 if (!$arr["status"] = $dbupdate->getDBVersionStatus())
1008 {
1009 $arr["comment"] = $this->lng->txt("db_needs_update");
1010 $arr["update"] = true;
1011 return $arr;
1012 }
1013 else if ($dbupdate->hotfixAvailable())
1014 {
1015 $arr["status"] = false;
1016 $arr["comment"] = $this->lng->txt("hotfix_available");
1017 $arr["update"] = true;
1018 return $arr;
1019 }
1020 else if ($dbupdate->customUpdatesAvailable())
1021 {
1022 $arr["status"] = false;
1023 $arr["comment"] = $this->lng->txt("custom_updates_available");
1024 $arr["update"] = true;
1025 return $arr;
1026 }
1027
1028 // check control information
1029
1030 $cset = $ilDB->query("SELECT count(*) as cnt FROM ctrl_calls");
1031 $crec = $ilDB->fetchAssoc($cset);
1032 if ($crec["cnt"] == 0)
1033 {
1034 $arr["status"] = false;
1035 $arr["comment"] = $this->lng->txt("db_control_structure_missing");
1036 $arr["update"] = true;
1037 return $arr;
1038 }
1039
1040 //$arr["comment"] = "version ".$dbupdate->getCurrentVersion();
1041 return $arr;
1042 }
1043
1049 function checkClientSessionSettings(&$client, $a_as_bool = false)
1050 {
1051 require_once('Services/Authentication/classes/class.ilSessionControl.php');
1052
1053 global $ilDB;
1054 $db = $ilDB;
1055
1057
1058 $query = "SELECT keyword, value FROM settings WHERE ".$db->in('keyword', $fields, false, 'text');
1059 $res = $db->query($query);
1060
1061 $rows = array();
1062 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
1063 {
1064 if( $row['value'] != '' )
1065 $rows[] = $row;
1066 else break;
1067 }
1068
1069 if (count($rows) != count($fields))
1070 {
1071 if($a_as_bool) return false;
1072 $arr["status"] = false;
1073 $arr["comment"] = $this->lng->txt("session_management_not_configured");
1074 }
1075 else
1076 {
1077 if($a_as_bool) return true;
1078 $arr["status"] = true;
1079 $arr["comment"] = $this->lng->txt("session_management_configured");
1080 }
1081
1082 return $arr;
1083 }
1084
1090 {
1091 global $ilDB;
1092 $db = $ilDB;
1093
1094 $fields = array('proxy_status','proxy_host','proxy_port');
1095
1096 $query = "SELECT keyword, value FROM settings WHERE ".$db->in('keyword', $fields, false, 'text');
1097 $res = $db->query($query);
1098
1099 $proxy_settings = array();
1100 $already_saved = false;
1101 while($row = $db->fetchAssoc($res))
1102 {
1103 $already_saved = true;
1104 $proxy_settings[$row['keyword']] = $row['value'];
1105 }
1106
1107 if(!$already_saved)
1108 {
1109 $arr["status"] = false;
1110 $arr["comment"] = $this->lng->txt("proxy");
1111 $arr["text"] = $this->lng->txt("proxy");
1112 }
1113 else if((bool)$proxy_settings["proxy_status"] == false)
1114 {
1115 $arr["status"] = true;
1116 $arr["comment"] = $this->lng->txt("proxy_disabled");
1117 $arr["text"] = $this->lng->txt("proxy_disabled");
1118 }
1119 else
1120 {
1121 $arr["status"] = true;
1122 $arr["comment"] = $this->lng->txt("proxy_activated_configurated");
1123 $arr["text"] = $this->lng->txt("proxy_activated_configurated");
1124
1125 }
1126 return $arr;
1127 }
1128
1135 {
1136 $installed_langs = $this->lng->getInstalledLanguages();
1137
1138 $count = count($installed_langs);
1139
1140 if ($count < 1)
1141 {
1142 $arr["status"] = false;
1143 $arr["comment"] = $this->lng->txt("lang_none_installed");
1144 }
1145 else
1146 {
1147 $arr["status"] = true;
1148 //$arr["comment"] = $count." ".$this->lng->txt("languages_installed");
1149 }
1150
1151 return $arr;
1152 }
1153
1160 {
1161 $arr["status"] = true;
1162 //$arr["comment"] = $this->lng->txt("filled_out");
1163
1164 $settings = $client->getAllSettings();
1165 $client_name = $client->getName();
1166
1167 // check required fields
1168 if (empty($settings["admin_firstname"]) or empty($settings["admin_lastname"]) or
1169 empty($settings["admin_email"]) or empty($client_name))
1170 {
1171 $arr["status"] = false;
1172 $arr["comment"] = $this->lng->txt("missing_data");
1173 }
1174
1175 // admin email
1176 if (!ilUtil::is_email($settings["admin_email"]) and $arr["status"] != false)
1177 {
1178 $arr["status"] = false;
1179 $arr["comment"] = $this->lng->txt("email_not_valid");
1180 }
1181
1182 return $arr;
1183 }
1184
1191 {
1192 $settings = $client->getAllSettings();
1193
1194 if (!isset($settings["nic_enabled"]))
1195 {
1196 $arr["status"] = false;
1197 $arr["comment"] = $this->lng->txt("nic_not_disabled");
1198 return $arr;
1199 }
1200
1201 $arr["status"] = true;
1202
1203 if ($settings["nic_enabled"] == "-1")
1204 {
1205 $arr["comment"] = $this->lng->txt("nic_reg_failed");
1206 return $arr;
1207 }
1208
1209 if (!$settings["nic_enabled"])
1210 {
1211 $arr["comment"] = $this->lng->txt("nic_reg_disabled");
1212 }
1213 else
1214 {
1215 $arr["comment"] = $this->lng->txt("nic_reg_enabled");
1216 if ($settings["inst_id"] <= 0)
1217 {
1218 $arr["status"] = false;
1219 }
1220 }
1221
1222 return $arr;
1223 }
1224
1229 function isInstalled()
1230 {
1232 }
1233
1239 {
1240 return $this->auth;
1241 }
1242
1247 function isAdmin()
1248 {
1249 return ($this->access_mode == "admin") ? true : false;
1250 }
1251
1257 function saveMasterSetup($a_formdata)
1258 {
1259 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1260
1261 if ($a_formdata["chk_datadir_path"] == 1) // mode create dir
1262 {
1263 if (!ilUtil::makeDir($datadir_path))
1264 {
1265 $this->error = "create_datadir_failed";
1266 return false;
1267 }
1268 }
1269
1270 // create webspace dir if it does not exist
1271 if (!@file_exists(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")) and !@is_dir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1272 {
1273 if (!ilUtil::makeDir(ILIAS_ABSOLUTE_PATH."/".$this->ini->readVariable("clients","path")))
1274 {
1275 $this->error = "create_webdir_failed";
1276 return false;
1277 }
1278 }
1279
1280 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1281 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1282 $log_file = substr($form_log_path,strlen($log_path)+1);
1283
1284 $this->ini->setVariable("server","http_path",ILIAS_HTTP_PATH);
1285 $this->ini->setVariable("server","absolute_path",ILIAS_ABSOLUTE_PATH);
1286 $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1287 $this->ini->setVariable("clients", "datadir", $datadir_path);
1288 $this->ini->setVariable("tools", "convert", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"])));
1289 $this->ini->setVariable("tools", "zip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"])));
1290 $this->ini->setVariable("tools", "unzip", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"])));
1291 $this->ini->setVariable("tools", "ghostscript", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"])));
1292 $this->ini->setVariable("tools", "java", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"])));
1293 $this->ini->setVariable("tools", "htmldoc", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"])));
1294 //$this->ini->setVariable("tools", "mkisofs", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"])));
1295 $this->ini->setVariable("tools", "ffmpeg", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"])));
1296 $this->ini->setVariable("tools", "latex", ilUtil::stripSlashes($a_formdata["latex_url"]));
1297 $this->ini->setVariable("tools", "vscantype", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"])));
1298 $this->ini->setVariable("tools", "scancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"])));
1299 $this->ini->setVariable("tools", "cleancommand", preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"])));
1300 $this->ini->setVariable("setup", "pass", md5($a_formdata["setup_pass"]));
1301 $this->ini->setVariable("log", "path", $log_path);
1302 $this->ini->setVariable("log", "file", $log_file);
1303 $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1304
1305 $this->ini->setVariable("https","auto_https_detect_enabled", ($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1306 $this->ini->setVariable("https","auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1307 $this->ini->setVariable("https","auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1308
1309 if (!$this->ini->write())
1310 {
1311 $this->error = get_class($this).": ".$this->ini->getError();
1312 return false;
1313 }
1314
1315 // everything is fine. so we authenticate the user and set access mode to 'admin'
1316 $_SESSION["auth"] = true;
1317 $_SESSION["auth_path"] = ILIAS_HTTP_PATH;
1318 $_SESSION["access_mode"] = "admin";
1319
1320 return true;
1321 }
1322
1328 function updateMasterSettings($a_formdata)
1329 {
1330 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1331 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1332 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1333 $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1334 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1335 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1336 //$mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1337 $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1338 $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1339 $fop_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["fop_path"]));
1340 $scan_type = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["vscanner_type"]));
1341 $scan_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["scan_command"]));
1342 $clean_command = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["clean_command"]));
1343
1344 $this->ini->setVariable("tools", "convert", $convert_path);
1345 $this->ini->setVariable("tools", "zip", $zip_path);
1346 $this->ini->setVariable("tools", "unzip", $unzip_path);
1347 $this->ini->setVariable("tools", "ghostscript", $ghostscript_path);
1348 $this->ini->setVariable("tools", "java", $java_path);
1349 $this->ini->setVariable("tools", "htmldoc", $htmldoc_path);
1350 //$this->ini->setVariable("tools", "mkisofs", $mkisofs_path);
1351 $this->ini->setVariable("tools", "ffmpeg", $ffmpeg_path);
1352 $this->ini->setVariable("tools", "latex", $latex_url);
1353 $this->ini->setVariable("tools", "fop", $fop_path);
1354 $this->ini->setVariable("tools", "vscantype", $scan_type);
1355 $this->ini->setVariable("tools", "scancommand", $scan_command);
1356 $this->ini->setVariable("tools", "cleancommand", $clean_command);
1357
1358 $form_log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1359 $log_path = substr($form_log_path,0,strrpos($form_log_path,"/"));
1360 $log_file = substr($form_log_path,strlen($log_path)+1);
1361
1362 $this->ini->setVariable("log", "path", $log_path);
1363 $this->ini->setVariable("log", "file", $log_file);
1364 $this->ini->setVariable("log", "enabled", ($a_formdata["chk_log_status"]) ? "0" : 1);
1365 $this->ini->setVariable("server","timezone",preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["time_zone"])));
1366
1367 $this->ini->setVariable("https","auto_https_detect_enabled",($a_formdata["auto_https_detect_enabled"]) ? 1 : 0);
1368 $this->ini->setVariable("https","auto_https_detect_header_name", $a_formdata["auto_https_detect_header_name"]);
1369 $this->ini->setVariable("https","auto_https_detect_header_value", $a_formdata["auto_https_detect_header_value"]);
1370
1371 if (!$this->ini->write())
1372 {
1373 $this->error = get_class($this).": ".$this->ini->getError();
1374 return false;
1375 }
1376
1377 return true;
1378 }
1379
1385 function checkToolsSetup($a_formdata)
1386 {
1387 // convert path
1388 if (!isset($a_formdata["chk_convert_path"]))
1389 {
1390 // convert backslashes to forwardslashes
1391 $convert_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["convert_path"]));
1392
1393 if (($err = $this->testConvert($convert_path)) != "")
1394 {
1395 $this->error = $err;
1396 return false;
1397 }
1398 }
1399
1400 // zip path
1401 if (!isset($a_formdata["chk_zip_path"]))
1402 {
1403 // convert backslashes to forwardslashes
1404 $zip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["zip_path"]));
1405
1406 if (empty($zip_path))
1407 {
1408 $this->error = "no_path_zip";
1409 return false;
1410 }
1411
1412 if (!$this->testZip($zip_path))
1413 {
1414 $this->error = "check_failed_zip";
1415 return false;
1416 }
1417 }
1418
1419 // unzip path
1420 if (!isset($a_formdata["chk_unzip_path"]))
1421 {
1422 // convert backslashes to forwardslashes
1423 $unzip_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["unzip_path"]));
1424
1425 if (empty($unzip_path))
1426 {
1427 $this->error = "no_path_unzip";
1428 return false;
1429 }
1430
1431 if (!$this->testUnzip($unzip_path))
1432 {
1433 $this->error = "check_failed_unzip";
1434 return false;
1435 }
1436 }
1437
1438 // ghostscript path
1439 if (!isset($a_formdata["chk_ghostscript_path"]))
1440 {
1441 // convert backslashes to forwardslashes
1442 $ghostscript_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ghostscript_path"]));
1443
1444 if (($err = $this->testGhostscript($ghostscript_path)) != "")
1445 {
1446 $this->error = $err;
1447 return false;
1448 }
1449 }
1450
1451 // java path
1452 if (!isset($a_formdata["chk_java_path"]))
1453 {
1454 // convert backslashes to forwardslashes
1455 $java_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["java_path"]));
1456
1457 if (empty($java_path))
1458 {
1459 $this->error = "no_path_java";
1460 return false;
1461 }
1462
1463 if (!$this->testJava($java_path))
1464 {
1465 $this->error = "check_failed_java";
1466 return false;
1467 }
1468 }
1469
1470 // htmldoc path
1471 if (!isset($a_formdata["chk_htmldoc_path"]))
1472 {
1473 // convert backslashes to forwardslashes
1474 $htmldoc_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["htmldoc_path"]));
1475
1476 if (empty($htmldoc_path))
1477 {
1478 $this->error = "no_path_htmldoc";
1479 return false;
1480 }
1481
1482 if (!$this->testHtmldoc($htmldoc_path))
1483 {
1484 $this->error = "check_failed_htmldoc";
1485 return false;
1486 }
1487 }
1488 /*if (!isset($a_formdata["chk_mkisofs_path"]))
1489 {
1490 // convert backslashes to forwardslashes
1491 $mkisofs_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["mkisofs_path"]));
1492
1493 if (empty($mkisofs_path))
1494 {
1495 $this->error = "no_path_mkisofs";
1496 return false;
1497 }
1498
1499 if (!$this->testHtmldoc($mkisofs_path))
1500 {
1501 $this->error = "check_failed_mkisofs";
1502 return false;
1503 }
1504 }*/
1505
1506 if (!isset($a_formdata["chk_ffmpeg_path"]))
1507 {
1508 // convert backslashes to forwardslashes
1509 $ffmpeg_path = preg_replace("/\\\\/","/",ilUtil::stripSlashes($a_formdata["ffmpeg_path"]));
1510
1511 if (empty($ffmpeg_path))
1512 {
1513 $this->error = "no_path_ffmpeg";
1514 return false;
1515 }
1516
1517 if (!$this->testFFMpeg($ffmpeg_path))
1518 {
1519 $this->error = "check_failed_ffmpeg";
1520 return false;
1521 }
1522 }
1523
1524 // latex url
1525 if (!isset($a_formdata["chk_latex_url"]))
1526 {
1527 $latex_url = ilUtil::stripSlashes($a_formdata["latex_url"]);
1528 if (empty($latex_url))
1529 {
1530 $this->error = "no_latex_url";
1531 return false;
1532 }
1533
1534 if (!$this->testLatex($latex_url))
1535 {
1536 $this->error = "check_failed_latex";
1537 return false;
1538 }
1539 }
1540
1541 return true;
1542 }
1543
1549 function checkDataDirSetup($a_formdata)
1550 {
1551 // remove trailing slash & convert backslashes to forwardslashes
1552 $datadir_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["datadir_path"])));
1553
1554 if (empty($datadir_path))
1555 {
1556 $this->error = "no_path_datadir";
1557 return false;
1558 }
1559
1560 $webspace_dir = ILIAS_ABSOLUTE_PATH . "/data";
1561
1562 // datadir may not point to webspace dir or to any place under webspace_dir
1563 if (strpos($datadir_path,$webspace_dir) !== false)
1564 {
1565 $this->error = "datadir_webspacedir_match";
1566 return false;
1567 }
1568
1569 // create dir
1570 if ($a_formdata["chk_datadir_path"] == 1)
1571 {
1572 $dir_to_create = substr(strrchr($datadir_path, "/"), 1);
1573 $dir_to_check = substr($datadir_path,0,- strlen($dir_to_create)-1);
1574
1575 if (is_writable($datadir_path))
1576 {
1577 $this->error = "dir_exists_create";
1578 return false;
1579 }
1580
1581 if (!is_writable($dir_to_check))
1582 {
1583 $this->error = "cannot_create_datadir_no_write_access";
1584 return false;
1585 }
1586 }
1587 else // check set target dir
1588 {
1589 if (!is_writable($datadir_path))
1590 {
1591 $this->error = "cannot_create_datadir_no_write_access";
1592 return false;
1593 }
1594 }
1595
1596 return true;
1597 }
1598
1604 function checkPasswordSetup($a_formdata)
1605 {
1606 if (!$a_formdata["setup_pass"])
1607 {
1608 $this->error = "no_setup_pass_given";
1609 return false;
1610 }
1611
1612 if ($a_formdata["setup_pass"] != $a_formdata["setup_pass2"])
1613 {
1614 $this->error = "pass_does_not_match";
1615 return false;
1616 }
1617
1618 return true;
1619 }
1620
1626 function checkLogSetup($a_formdata)
1627 {
1628 // log path
1629 if (!$a_formdata["chk_log_status"])
1630 {
1631 // remove trailing slash & convert backslashes to forwardslashes
1632 $log_path = preg_replace("/\\\\/","/",ilFile::deleteTrailingSlash(ilUtil::stripSlashes($a_formdata["log_path"])));
1633
1634 if (empty($log_path))
1635 {
1636 $this->error = "no_path_log";
1637 return false;
1638 }
1639
1640 if (!@touch($log_path))
1641 {
1642 $this->error = "could_not_create_logfile";
1643 return false;
1644 }
1645 }
1646
1647 return true;
1648 }
1649
1654 function getError()
1655 {
1656 if (empty($this->error))
1657 {
1658 return false;
1659 }
1660
1661 $error = $this->error;
1662 $this->error = "";
1663
1664 return $error;
1665 }
1666
1672 function _ilSetup()
1673 {
1674 //if ($this->ini->readVariable("db","type") != "")
1675 //{
1676 // $this->db->disconnect();
1677 //}
1678 return true;
1679 }
1680
1687 function testConvert($a_convert_path)
1688 {
1689 if (trim($a_convert_path) == "")
1690 {
1691 return "no_path_convert";
1692 }
1693 if (!is_file($a_convert_path))
1694 {
1695 return "check_failed_convert";
1696 }
1697
1698 return "";
1699
1700 }
1701
1708 function testGhostscript($a_ghostscript_path)
1709 {
1710 // ghostscript is optional, so empty path is ok
1711 if (trim($a_ghostscript_path) == "")
1712 {
1713 return "";
1714 }
1715 if (!is_file($a_ghostscript_path))
1716 {
1717 return "check_failed_ghostscript";
1718 }
1719
1720 return "";
1721 }
1722
1729 function testJava ($a_java_path)
1730 {
1731 // java is optional, so empty path is ok
1732 if (trim($a_java_path) == "")
1733 {
1734 return "";
1735 }
1736
1737 if (!is_file($a_java_path))
1738 {
1739 return "check_failed_java";
1740 }
1741
1742 return "";
1743/*
1744 exec($a_java_path, $out, $back);
1745
1746 unset($out);
1747
1748 return ($back != 1) ? false : true;
1749*/
1750 }
1751
1758 function testLatex($a_latex_url)
1759 {
1760 // latex is optional, so empty path is ok
1761 if (trim($a_latex_url) == "")
1762 {
1763 return "";
1764 }
1765
1766 // open the URL
1767 include_once "./setup/classes/class.ilHttpRequest.php";
1768 $http = new ilHttpRequest(ilUtil::stripSlashes($a_latex_url) . "?x_0");
1769 $result = @$http->downloadToString();
1770 if ((strpos((substr($result, 0, 5)), "PNG") !== FALSE) || (strpos((substr($result, 0, 5)), "GIF") !== FALSE))
1771 {
1772 return "";
1773 }
1774 else
1775 {
1776 return "check_failed_latex";;
1777 }
1778 }
1779
1786 function testZip ($a_zip_path)
1787 {
1788 if (trim($a_zip_path) == "")
1789 {
1790 return "no_path_zip";
1791 }
1792 if (!is_file($a_zip_path))
1793 {
1794 return "check_failed_zip";
1795 }
1796
1797 return "";
1798/*
1799 // create test file and run zip
1800 $fp = fopen(ILIAS_ABSOLUTE_PATH."/test.dat", "w");
1801
1802 fwrite($fp, "test");
1803 fclose($fp);
1804
1805 if (file_exists(ILIAS_ABSOLUTE_PATH."/test.dat"))
1806 {
1807 $curDir = getcwd();
1808 chdir(ILIAS_ABSOLUTE_PATH);
1809
1810 $zipCmd = $a_zip_path." -m zip_test_file.zip test.dat";
1811
1812 exec($zipCmd);
1813
1814 chdir($curDir);
1815
1816 }
1817
1818 // check wether zip generated test file or not
1819 if (file_exists(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip"))
1820 {
1821 unlink(ILIAS_ABSOLUTE_PATH."/zip_test_file.zip");
1822 return true;
1823 }
1824 else
1825 {
1826 unlink(ILIAS_ABSOLUTE_PATH."/test.dat");
1827 return false;
1828 }
1829*/
1830 }
1831
1832
1839 function testUnzip ($a_unzip_path)
1840 {
1841 if (trim($a_unzip_path) == "")
1842 {
1843 return "no_path_unzip";
1844 }
1845 if (!is_file($a_unzip_path))
1846 {
1847 return "check_failed_unzip";
1848 }
1849
1850 return "";
1851/*
1852 $curDir = getcwd();
1853
1854 chdir(ILIAS_ABSOLUTE_PATH);
1855
1856 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.zip"))
1857 {
1858 $unzipCmd = $a_unzip_path." unzip_test_file.zip";
1859 exec($unzipCmd);
1860 }
1861
1862 chdir($curDir);
1863
1864 // check wether unzip extracted the test file or not
1865 if (file_exists(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt"))
1866 {
1867 unlink(ILIAS_ABSOLUTE_PATH."/unzip_test_file.txt");
1868
1869 return true;
1870 }
1871 else
1872 {
1873 return false;
1874 }
1875*/
1876 }
1877
1884 function testHtmldoc($a_htmldoc_path)
1885 {
1886 // java is optional, so empty path is ok
1887 if (trim($a_htmldoc_path) == "")
1888 {
1889 return "";
1890 }
1891
1892 if (!is_file($a_htmldoc_path))
1893 {
1894 return "check_failed_htmldoc";
1895 }
1896
1897 return "";
1898
1899
1900 $curDir = getcwd();
1901
1902 chdir(ILIAS_ABSOLUTE_PATH);
1903
1904 $html = "<html><head><title></title></head><body><p>test</p></body></html>";
1905
1906 $html_file = "htmldoc_test_file.html";
1907
1908 $fp = fopen( $html_file ,"wb");
1909 fwrite($fp, $html);
1910 fclose($fp);
1911
1912 $htmldoc = $a_htmldoc_path." ";
1913 $htmldoc .= "--no-toc ";
1914 $htmldoc .= "--no-jpeg ";
1915 $htmldoc .= "--webpage ";
1916 $htmldoc .= "--outfile htmldoc_test_file.pdf ";
1917 $htmldoc .= "--bodyfont Arial ";
1918 $htmldoc .= "--charset iso-8859-15 ";
1919 $htmldoc .= "--color ";
1920 $htmldoc .= "--size A4 "; // --landscape
1921 $htmldoc .= "--format pdf ";
1922 $htmldoc .= "--footer ... ";
1923 $htmldoc .= "--header ... ";
1924 $htmldoc .= "--left 60 ";
1925 // $htmldoc .= "--right 200 ";
1926 $htmldoc .= $html_file;
1927 exec($htmldoc);
1928
1929 unlink(ILIAS_ABSOLUTE_PATH."/".$html_file);
1930
1931 chdir($curDir);
1932
1933 if (file_exists(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf"))
1934 {
1935 unlink(ILIAS_ABSOLUTE_PATH."/htmldoc_test_file.pdf");
1936 return true;
1937 }
1938 else
1939 {
1940 return false;
1941 }
1942 }
1943
1944
1951 function unzip($a_file, $overwrite = false)
1952 {
1953 //global $ilias;
1954
1955 $pathinfo = pathinfo($a_file);
1956 $dir = $pathinfo["dirname"];
1957 $file = $pathinfo["basename"];
1958
1959 // unzip
1960 $cdir = getcwd();
1961 chdir($dir);
1962 $unzip = $this->ini->readVariable("tools","unzip");
1963 $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
1964 exec($unzipcmd, $arr);
1965 $zdirs = array();
1966
1967 foreach($arr as $line)
1968 {
1969 if(is_int(strpos($line, "/")))
1970 {
1971 $zdir = substr($line, 0, strrpos($line, "/"));
1972 $nr = substr_count($zdir, "/");
1973 //echo $zdir." ".$nr."<br>";
1974 while ($zdir != "")
1975 {
1976 $nr = substr_count($zdir, "/");
1977 $zdirs[$zdir] = $nr; // collect directories
1978 //echo $dir." ".$nr."<br>";
1979 $zdir = substr($zdir, 0, strrpos($zdir, "/"));
1980 }
1981 }
1982 }
1983
1984 asort($zdirs);
1985
1986 foreach($zdirs as $zdir => $nr) // create directories
1987 {
1989 }
1990
1991 // real unzip
1992 if ($overvwrite)
1993 {
1994 $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
1995 }
1996 else
1997 {
1998 $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
1999 }
2000 exec($unzipcmd);
2001
2002 chdir($cdir);
2003 }
2004
2010 function setSessionSettings($session_settings)
2011 {
2012 require_once('Services/Authentication/classes/class.ilSessionControl.php');
2013
2014 $db = $this->client->getDB();
2015
2016 $setting_fields = ilSessionControl::getSettingFields();
2017
2018 $i = 0;
2019 foreach($setting_fields as $field)
2020 {
2021 if( isset($session_settings[$field]) )
2022 {
2023 $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
2024 $res = $db->queryF($query,
2025 array('text', 'text'), array('common', $field));
2026
2027 $row = array();
2028 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) break;
2029
2030 if( count($row) > 0 )
2031 {
2032 $db->update(
2033 'settings',
2034 array(
2035 'value' => array('text', $session_settings[$field])
2036 ),
2037 array(
2038 'module' => array('text', 'common'),
2039 'keyword' => array('text', $field)
2040 )
2041 );
2042 }
2043 else
2044 {
2045 $db->insert(
2046 'settings',
2047 array(
2048 'module' => array('text', 'common'),
2049 'keyword' => array('text', $field),
2050 'value' => array('text', $session_settings[$field])
2051 )
2052 );
2053 }
2054
2055 $i++;
2056 }
2057 }
2058
2059 if($i < 4) $message = $this->lng->txt("session_settings_not_saved");
2060 else $message = $this->lng->txt("settings_saved");
2061
2062 ilUtil::sendInfo($message);
2063 }
2064
2071 {
2072 require_once('Services/Authentication/classes/class.ilSessionControl.php');
2073
2074 $db = $this->client->getDB();
2075
2076 $setting_fields = ilSessionControl::getSettingFields();
2077
2078 $query = "SELECT * FROM settings WHERE module = %s " .
2079 "AND ".$db->in('keyword', $setting_fields, false, 'text');
2080
2081 $res = $db->queryF($query, array('text'), array('common'));
2082
2083 $session_settings = array();
2084 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
2085 {
2086 $session_settings[$row['keyword']] = $row['value'];
2087 }
2088
2089 foreach( $setting_fields as $field )
2090 {
2091 if( !isset($session_settings[$field]) )
2092 {
2093 $value = 1;
2094
2095 switch($field)
2096 {
2097 case 'session_max_count':
2098
2100 break;
2101
2102 case 'session_min_idle':
2103
2105 break;
2106
2107 case 'session_max_idle':
2108
2110 break;
2111
2112 case 'session_max_idle_after_first_request':
2113
2115 break;
2116
2117 case 'session_allow_client_maintenance':
2118
2120 break;
2121 }
2122
2123 $session_settings[$field] = $value;
2124 }
2125 }
2126
2127 return $session_settings;
2128 }
2129
2135 function cloneFromSource($source_id)
2136 {
2137 // Getting source and targets
2138 $source = new ilClient($source_id, $this->db_connections);
2139 $source->init();
2140 $target = $this->client;
2141
2142 // ************************************************
2143 // ** COPY FILES
2144
2145 // Cleaning up datadir
2146 if (! ilUtil::delDir($target->getDataDir())) {
2147 $this->error = "Could not delete data dir $target->getDataDir()";
2148 //return false;
2149 }
2150
2151 // Create empty datadir
2152 if (!ilUtil::makeDir($target->getDataDir()))
2153 {
2154 $this->error = "could_not_create_base_data_dir :".$target->getDataDir();
2155 return false;
2156 }
2157
2158 // Copying datadir
2159 if (! ilUtil::rCopy($source->getDataDir(),$target->getDataDir())) {
2160 $this->error = "clone_datadircopyfail";
2161 $target->ini->write();
2162 return false;
2163 }
2164
2165 // Cleaning up Webspacedir
2166 if (! ilUtil::delDir($target->getWebspaceDir())) {
2167 $this->error = "Could not delete webspace dir $target->getWebspaceDir()";
2168 //return false;
2169 }
2170
2171 // Create empty Webspacedir
2172 if (!ilUtil::makeDir($target->getWebspaceDir()))
2173 {
2174 $this->error = "could_not_create_base_webspace_dir :".$target->getWebspaceDir();
2175 return false;
2176 }
2177
2178 // Copying Webspacedir
2179 if (! ilUtil::rCopy($source->getWebspaceDir(),$target->getWebspaceDir())) {
2180 $this->error = "clone_websipacedircopyfail";
2181 $target->ini->write();
2182 return false;
2183 }
2184
2185 // Restore ini file
2186 $target->ini->write();
2187
2188 // ************************************************
2189 // ** COPY DATABASE
2190
2191 $source->connect();
2192 if (!$source->db)
2193 {
2194 $this->error = "Source database connection failed.";
2195 return false;
2196 }
2197
2198 $target->connect();
2199 if (!$target->db)
2200 {
2201 $this->error = "Target database connection failed.";
2202 return false;
2203 }
2204
2205 $source->connect();
2206 $srcTables = $source->db->query("SHOW TABLES");
2207 $target->connect();
2208
2209 // drop all tables of the target db
2210 $tarTables = $target->db->query("SHOW TABLES");
2211 foreach($tarTables->fetchAll() as $cTable)
2212 {
2213 $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2214 }
2215
2216 foreach($srcTables->fetchAll() as $cTable){
2217 $drop = $target->db->query("DROP TABLE IF EXISTS " . $cTable[0]);
2218 $create = $target->db->query("CREATE TABLE " . $cTable[0] . " LIKE " . $source->getDbName() . "." . $cTable[0]);
2219 if(!$create) {
2220 $error = true;
2221 }
2222 $insert = $target->db->query("INSERT INTO " . $cTable[0] . " SELECT * FROM ".$source->getDbName().".".$cTable[0]);
2223 }
2224
2225 $target->db->query("UPDATE settings SET VALUE = ".$target->db->quote(0, "integer")." WHERE keyword = ".$target->db->quote("inst_id", "text"));
2226 $target->db->query("UPDATE settings SET VALUE = ".$target->db->quote(0, "integer")." WHERE keyword = ".$target->db->quote("nic_enabled", "text"));
2227 return true;
2228 }
2236 public function printProxyStatus($client)
2237 {
2238 require_once './Services/Http/exceptions/class.ilProxyException.php';
2239 $settings = $client->getAllSettings();
2240
2241 if((bool)$settings['proxy_status'] == true)
2242 {
2243 try
2244 {
2250 require_once 'Services/PEAR/lib/Net/Socket.php';
2251
2252 $socket = new Net_Socket();
2253 $socket->setErrorHandling(PEAR_ERROR_RETURN);
2254 $response = $socket->connect($settings['proxy_host'], $settings['proxy_port']);
2255 if(!is_bool($response))
2256 {
2257 global $lng;
2258 throw new ilProxyException(strlen($response) ? $response : $lng->txt('proxy_not_connectable'));
2259 }
2260
2261 ilUtil::sendSuccess($this->lng->txt('proxy_connectable'));
2262
2263 }
2264 catch(ilProxyException $e)
2265 {
2266 ilUtil::sendFailure($this->lng->txt('proxy_pear_net_socket_error').': '.$e->getMessage());
2267 }
2268 }
2269
2270 }
2271
2272 public function saveProxySettings($proxy_settings)
2273 {
2274 $db = $this->client->getDB();
2275 $proxy_fields = array('proxy_status','proxy_host','proxy_port');
2276
2277 foreach($proxy_fields as $field)
2278 {
2279 if( isset($proxy_settings[$field]) )
2280 {
2281 $query = "SELECT keyword FROM settings WHERE module = %s AND keyword = %s";
2282 $res = $db->queryF($query,
2283 array('text', 'text'), array('common', $field));
2284
2285 $row = array();
2286 while($row = $db->fetchAssoc($res)) break;
2287
2288 if( count($row) > 0 )
2289 {
2290 $db->update(
2291 'settings',
2292 array(
2293 'value' => array('text', $proxy_settings[$field])
2294 ),
2295 array(
2296 'module' => array('text', 'common'),
2297 'keyword' => array('text', $field)
2298 )
2299 );
2300 }
2301 else
2302 {
2303 $db->insert(
2304 'settings',
2305 array(
2306 'module' => array('text', 'common'),
2307 'keyword' => array('text', $field),
2308 'value' => array('text', $proxy_settings[$field])
2309 )
2310 );
2311 }
2312 }
2313 }
2314 }
2315
2319 public function hasOpCacheEnabled() {
2320 $ini_get = ini_get('opcache.enable');
2321
2322 return ($ini_get === 1 OR $ini_get === '1' OR strtolower($ini_get) === 'on');
2323 }
2324} // END class.ilSetup
2325
2327{
2328 public function current()
2329 {
2330 return parent::getFileName();
2331 }
2332
2333 public function valid()
2334 {
2335 if(!parent::valid())
2336 {
2337 return false;
2338 }
2339 if($this->isFile() and substr(parent::getFileName(),-4) == '.xml')
2340 {
2341 return false;
2342 }
2343 if($this->isFile() and substr(parent::getFileName(),-8) != '_inserts')
2344 {
2345 return true;
2346 }
2347 parent::next();
2348 return $this->valid();
2349 }
2350
2351 public function rewind()
2352 {
2353 parent::rewind();
2354 }
2355}
2356?>
$result
print $file
const PEAR_ERROR_RETURN
#+ ERROR constants
Definition: PEAR.php:31
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
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.
Error Handling & global info handling uses PEAR error 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
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 ...
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
global $lng
Definition: privfeed.php:40
global $ilDB
const ILIAS_WEB_DIR
const ILIAS_ABSOLUTE_PATH