ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilECSSetting.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
34{
35 const DEFAULT_AUTH_MODE = 'ldap';
36
37 const ERROR_EXTRACT_SERIAL = 'ecs_error_extract_serial';
38 const ERROR_REQUIRED = 'fill_out_all_required_fields';
39 const ERROR_INVALID_IMPORT_ID = 'ecs_check_import_id';
40 const ERROR_CERT_EXPIRED = 'ecs_certificate_expired';
41
43 const AUTH_APACHE = 2;
44
46
47
48 const PROTOCOL_HTTP = 0;
49 const PROTOCOL_HTTPS = 1;
50
51 protected static $instances = null;
52
53
54 private $server_id = 0;
55 private $active = false;
56 private $title = '';
58 private $server;
59 private $protocol;
60 private $port;
63 private $key_path;
65 private $polling;
66 private $import_id;
67 private $cert_serial;
68 private $global_role;
69 private $duration;
70
71 private $auth_user = '';
72 private $auth_pass = '';
73
74 private $user_recipients = array();
75 private $econtent_recipients = array();
76 private $approval_recipients = array();
77
83 private function __construct($a_server_id = 0)
84 {
85 $this->server_id = $a_server_id;
86 $this->read();
87 }
88
97 public static function _getInstance()
98 {
99 $GLOBALS['DIC']->logger()->wsrv()->warning('Using deprecated call');
100 $GLOBALS['DIC']->logger()->wsrv()->logStack(ilLogLevel::WARNING);
101 return self::getInstanceByServerId(null);
102 }
103
109 public static function getInstanceByServerId($a_server_id)
110 {
111 if (self::$instances[$a_server_id]) {
112 return self::$instances[$a_server_id];
113 }
114 return self::$instances[$a_server_id] = new ilECSSetting($a_server_id);
115 }
116
120 public static function lookupAuthMode()
121 {
123 }
124
129 public function setTitle($a_title)
130 {
131 $this->title = $a_title;
132 }
133
138 public function getTitle()
139 {
140 return $this->title;
141 }
142
147 public function setAuthType($a_auth_type)
148 {
149 $this->auth_type = $a_auth_type;
150 }
151
156 public function getAuthType()
157 {
158 return $this->auth_type;
159 }
160
165 public function setAuthUser($a_user)
166 {
167 $this->auth_user = $a_user;
168 }
169
174 public function getAuthUser()
175 {
176 return $this->auth_user;
177 }
178
183 public function setAuthPass($a_pass)
184 {
185 $this->auth_pass = $a_pass;
186 }
187
192 public function getAuthPass()
193 {
194 return $this->auth_pass;
195 }
196
201 public function getServerId()
202 {
203 return (int) $this->server_id;
204 }
205
213 public function setEnabledStatus($a_status)
214 {
215 $this->active = $a_status;
216 }
217
224 public function isEnabled()
225 {
226 return $this->active;
227 }
228
236 public function setServer($a_server)
237 {
238 $this->server = $a_server;
239 }
240
248 public function getServer()
249 {
250 return $this->server;
251 }
252
259 public function getServerURI()
260 {
261 switch ($this->getProtocol()) {
263 $uri = 'http://';
264 break;
265
267 $uri = 'https://';
268 break;
269 }
270
271 if (stristr($this->getServer(), '/')) {
272 $counter = 0;
273 foreach ((array) explode('/', $this->getServer()) as $key => $part) {
274 $uri .= $part;
275 if (!$counter) {
276 $uri .= ':' . $this->getPort();
277 }
278 $uri .= '/';
279 ++$counter;
280 }
281 $uri = substr($uri, 0, -1);
282 } else {
283 $uri .= $this->getServer();
284 $uri .= (':' . $this->getPort());
285 }
286
287 return $uri;
288 }
289
297 public function setProtocol($a_prot)
298 {
299 $this->protocol = $a_prot;
300 }
301
308 public function getProtocol()
309 {
310 return $this->protocol;
311 }
312
320 public function setPort($a_port)
321 {
322 $this->port = $a_port;
323 }
324
332 public function getPort()
333 {
334 return $this->port;
335 }
336
344 public function setPollingTime($a_time)
345 {
346 $this->polling = $a_time;
347 }
348
355 public function getPollingTime()
356 {
357 return $this->polling;
358 }
359
366 public function getPollingTimeSeconds()
367 {
368 return (int) ($this->polling % 60);
369 }
370
377 public function getPollingTimeMinutes()
378 {
379 return (int) ($this->polling / 60);
380 }
381
390 public function setPollingTimeMS($a_min, $a_sec)
391 {
392 $this->setPollingTime(60 * $a_min + $a_sec);
393 }
394
402 public function setClientCertPath($a_path)
403 {
404 $this->client_cert_path = $a_path;
405 }
406
412 public function getClientCertPath()
413 {
415 }
416
424 public function setCACertPath($a_ca)
425 {
426 $this->ca_cert_path = $a_ca;
427 }
428
435 public function getCACertPath()
436 {
437 return $this->ca_cert_path;
438 }
439
446 public function getKeyPath()
447 {
448 return $this->key_path;
449 }
450
458 public function setKeyPath($a_path)
459 {
460 $this->key_path = $a_path;
461 }
462
469 public function getKeyPassword()
470 {
471 return $this->key_password;
472 }
473
481 public function setKeyPassword($a_pass)
482 {
483 $this->key_password = $a_pass;
484 }
485
493 public function setImportId($a_id)
494 {
495 $this->import_id = $a_id;
496 }
497
503 public function getImportId()
504 {
505 return $this->import_id;
506 }
507
515 public function setCertSerialNumber($a_cert_serial)
516 {
517 $this->cert_serial_number = $a_cert_serial;
518 }
519
526 public function getCertSerialNumber()
527 {
528 return $this->cert_serial_number;
529 }
530
537 public function getGlobalRole()
538 {
539 return $this->global_role;
540 }
541
549 public function setGlobalRole($a_role_id)
550 {
551 $this->global_role = $a_role_id;
552 }
553
561 public function setDuration($a_duration)
562 {
563 $this->duration = $a_duration;
564 }
565
572 public function getDuration()
573 {
574 return $this->duration ? $this->duration : self::DEFAULT_DURATION;
575 }
576
583 public function getUserRecipients()
584 {
585 return explode(',', (string) $this->user_recipients);
586 }
587
595 {
596 return $this->user_recipients ? $this->user_recipients : '';
597 }
598
606 public function setUserRecipients($a_logins)
607 {
608 $this->user_recipients = $a_logins;
609 }
610
617 public function getEContentRecipients()
618 {
619 return explode(',', $this->econtent_recipients);
620 }
621
629 {
630 return $this->econtent_recipients ? $this->econtent_recipients : '';
631 }
632
640 public function setEContentRecipients($a_logins)
641 {
642 $this->econtent_recipients = $a_logins;
643 }
644
651 public function getApprovalRecipients()
652 {
653 return explode(',', $this->approval_recipients);
654 }
655
664 {
665 return $this->approval_recipients ? $this->approval_recipients : '';
666 }
667
674 public function setApprovalRecipients($a_rcp)
675 {
676 $this->approval_recipients = $a_rcp;
677 }
678
687 public function validate()
688 {
689 if (!$this->isEnabled()) {
690 return '';
691 }
692
693 // Cert based authentication
694 if ($this->getAuthType() == self::AUTH_CERTIFICATE) {
695 if (!$this->getClientCertPath() or !$this->getCACertPath() or !$this->getKeyPath() or !$this->getKeyPassword()) {
697 }
698 // Check import id
699 if (!$this->fetchSerialID()) {
701 }
702 if (!$this->fetchCertificateExpiration()) {
704 }
705 }
706 // Apache auth
707 if ($this->getAuthType() == self::AUTH_APACHE) {
708 if (!$this->getAuthUser() or !$this->getAuthPass()) {
710 }
711 }
712
713 // required fields
714 if (!$this->getServer() or !$this->getPort() or !$this->getPollingTime() or !$this->getImportId()
715 or !$this->getGlobalRole() or !$this->getDuration()) {
717 }
718
719 if (!$this->checkImportId()) {
721 }
722 return '';
723 }
724
731 public function checkImportId()
732 {
733 global $ilObjDataCache,$tree;
734
735 if (!$this->getImportId()) {
736 return false;
737 }
738 if ($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->getImportId())) != 'cat') {
739 return false;
740 }
741 if ($tree->isDeleted($this->getImportId())) {
742 return false;
743 }
744 return true;
745 }
746
753 public function save()
754 {
755 global $ilDB;
756
757 $this->server_id = $ilDB->nextId('ecs_server');
758 $ilDB->manipulate(
759 $q = 'INSERT INTO ecs_server (server_id,active,title,protocol,server,port,auth_type,client_cert_path,ca_cert_path,' .
760 'key_path,key_password,cert_serial,polling_time,import_id,global_role,econtent_rcp,user_rcp,approval_rcp,duration,auth_user,auth_pass) ' .
761 'VALUES (' .
762 $ilDB->quote($this->getServerId(), 'integer') . ', ' .
763 $ilDB->quote((int) $this->isEnabled(), 'integer') . ', ' .
764 $ilDB->quote($this->getTitle(), 'text') . ', ' .
765 $ilDB->quote((int) $this->getProtocol(), 'integer') . ', ' .
766 $ilDB->quote($this->getServer(), 'text') . ', ' .
767 $ilDB->quote($this->getPort(), 'integer') . ', ' .
768 $ilDB->quote($this->getAuthType(), 'integer') . ', ' .
769 $ilDB->quote($this->getClientCertPath(), 'text') . ', ' .
770 $ilDB->quote($this->getCACertPath(), 'text') . ', ' .
771 $ilDB->quote($this->getKeyPath(), 'text') . ', ' .
772 $ilDB->quote($this->getKeyPassword(), 'text') . ', ' .
773 $ilDB->quote($this->getCertSerialNumber(), 'text') . ', ' .
774 $ilDB->quote($this->getPollingTime(), 'integer') . ', ' .
775 $ilDB->quote($this->getImportId(), 'integer') . ', ' .
776 $ilDB->quote($this->getGlobalRole(), 'integer') . ', ' .
777 $ilDB->quote($this->getEContentRecipientsAsString(), 'text') . ', ' .
778 $ilDB->quote($this->getUserRecipientsAsString(), 'text') . ', ' .
779 $ilDB->quote($this->getApprovalRecipientsAsString(), 'text') . ', ' .
780 $ilDB->quote($this->getDuration(), 'integer') . ', ' .
781 $ilDB->quote($this->getAuthUser(), 'text') . ', ' .
782 $ilDB->quote($this->getAuthPass(), 'text') . ' ' .
783 ')'
784 );
785 }
786
790 public function update()
791 {
792 global $ilDB;
793
794 $ilDB->manipulate(
795 'UPDATE ecs_server SET ' .
796 'server_id = ' . $ilDB->quote($this->getServerId(), 'integer') . ', ' .
797 'active = ' . $ilDB->quote((int) $this->isEnabled(), 'integer') . ', ' .
798 'title = ' . $ilDB->quote($this->getTitle(), 'text') . ', ' .
799 'protocol = ' . $ilDB->quote((int) $this->getProtocol(), 'integer') . ', ' .
800 'server = ' . $ilDB->quote($this->getServer(), 'text') . ', ' .
801 'port = ' . $ilDB->quote($this->getPort(), 'integer') . ', ' .
802 'auth_type = ' . $ilDB->quote($this->getAuthType(), 'integer') . ', ' .
803 'client_cert_path = ' . $ilDB->quote($this->getClientCertPath(), 'text') . ', ' .
804 'ca_cert_path = ' . $ilDB->quote($this->getCACertPath(), 'text') . ', ' .
805 'key_path = ' . $ilDB->quote($this->getKeyPath(), 'text') . ', ' .
806 'key_password = ' . $ilDB->quote($this->getKeyPassword(), 'text') . ', ' .
807 'cert_serial = ' . $ilDB->quote($this->getCertSerialNumber(), 'text') . ', ' .
808 'polling_time = ' . $ilDB->quote($this->getPollingTime(), 'integer') . ', ' .
809 'import_id = ' . $ilDB->quote($this->getImportId(), 'integer') . ', ' .
810 'global_role = ' . $ilDB->quote($this->getGlobalRole(), 'integer') . ', ' .
811 'econtent_rcp = ' . $ilDB->quote($this->getEContentRecipientsAsString(), 'text') . ', ' .
812 'user_rcp = ' . $ilDB->quote($this->getUserRecipientsAsString(), 'text') . ', ' .
813 'approval_rcp = ' . $ilDB->quote($this->getApprovalRecipientsAsString(), 'text') . ', ' .
814 'duration = ' . $ilDB->quote($this->getDuration(), 'integer') . ', ' .
815 'auth_user = ' . $ilDB->quote($this->getAuthUser(), 'text') . ', ' .
816 'auth_pass = ' . $ilDB->quote($this->getAuthPass(), 'text') . ', ' .
817 'auth_type = ' . $ilDB->quote($this->getAuthType(), 'integer') . ' ' .
818 'WHERE server_id = ' . $ilDB->quote($this->getServerId(), 'integer')
819 );
820 }
821
825 public function delete()
826 {
827 global $ilDB;
828
829 // --- cascading delete
830
831 include_once 'Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
833
834 include_once 'Services/WebServices/ECS/classes/class.ilECSCommunityCache.php';
836
837 include_once 'Services/WebServices/ECS/classes/class.ilECSDataMappingSetting.php';
839
840 include_once 'Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php';
842
843 include_once 'Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
845
846 include_once 'Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
848
849 include_once 'Services/WebServices/ECS/classes/class.ilECSExport.php';
851
852 // resetting server id to flag items in imported list
853 include_once 'Services/WebServices/ECS/classes/class.ilECSImport.php';
855
856 $ilDB->manipulate(
857 'DELETE FROM ecs_server ' .
858 'WHERE server_id = ' . $ilDB->quote($this->getServerId(), 'integer')
859 );
860
861 $this->server_id = null;
862 return true;
863 }
864
865
871 {
872 if ($this->getAuthType() != self::AUTH_CERTIFICATE) {
873 return null;
874 }
875
876 if (function_exists('openssl_x509_parse') and $cert = openssl_x509_parse('file://' . $this->getClientCertPath())) {
877 if (isset($cert['validTo_time_t']) and $cert['validTo_time_t']) {
878 $dt = new ilDateTime($cert['validTo_time_t'], IL_CAL_UNIX);
879
880 $GLOBALS['DIC']->logger()->wsrv()->debug('Certificate expires at: ' . ilDatePresentation::formatDate($dt));
881 return $dt;
882 }
883 }
884 return null;
885 }
886
893 private function fetchSerialID()
894 {
895 if (function_exists('openssl_x509_parse') and $cert = openssl_x509_parse('file://' . $this->getClientCertPath())) {
896 if (isset($cert['serialNumber']) and $cert['serialNumber']) {
897 $this->setCertSerialNumber($cert['serialNumber']);
898 $GLOBALS['DIC']->logger()->wsrv()->debug('Searial number is: ' . $cert['serialNumber']);
899 return true;
900 }
901 }
902
903 if (!file_exists($this->getClientCertPath()) or !is_readable($this->getClientCertPath())) {
904 return false;
905 }
906 $lines = file($this->getClientCertPath());
907 $found = false;
908 foreach ($lines as $line) {
909 if (strpos($line, 'Serial Number:') !== false) {
910 $found = true;
911 $serial_line = explode(':', $line);
912 $serial = (int) trim($serial_line[1]);
913 break;
914 }
915 }
916 if ($found) {
917 $this->setCertSerialNumber($serial);
918 return true;
919 } else {
920 return false;
921 }
922 }
923
929 private function read()
930 {
931 global $ilDB;
932
933 if (!$this->getServerId()) {
934 return false;
935 }
936
937 $query = 'SELECT * FROM ecs_server ' .
938 'WHERE server_id = ' . $ilDB->quote($this->getServerId(), 'integer');
939 $res = $ilDB->query($query);
940 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
941 $this->setServer($row['server']);
942 $this->setTitle($row['title']);
943 $this->setProtocol($row['protocol']);
944 $this->setPort($row['port']);
945 $this->setClientCertPath($row['client_cert_path']);
946 $this->setCACertPath($row['ca_cert_path']);
947 $this->setKeyPath($row['key_path']);
948 $this->setKeyPassword($row['key_password']);
949 $this->setPollingTime($row['polling_time']);
950 $this->setImportId($row['import_id']);
951 $this->setEnabledStatus((int) $row['active']);
952 $this->setCertSerialNumber($row['cert_serial']);
953 $this->setGlobalRole($row['global_role']);
954 $this->econtent_recipients = $row['econtent_rcp'];
955 $this->approval_recipients = $row['approval_rcp'];
956 $this->user_recipients = $row['user_rcp'];
957 $this->setDuration($row['duration']);
958 $this->setAuthUser($row['auth_user']);
959 $this->setAuthPass($row['auth_pass']);
960 $this->setAuthType($row['auth_type']);
961 }
962 }
963
968 public function __clone()
969 {
970 $this->server_id = 0;
971 $this->setTitle($this->getTitle() . ' (Copy)');
972 $this->setEnabledStatus(false);
973 $this->setServer('');
974 $this->setProtocol(self::PROTOCOL_HTTPS);
975 $this->setPort(0);
976 $this->setClientCertPath('');
977 $this->setKeyPath('');
978 $this->setKeyPassword('');
979 $this->setCACertPath('');
980 $this->setCertSerialNumber('');
981 $this->setAuthType(self::AUTH_CERTIFICATE);
982 $this->setAuthUser('');
983 $this->setAuthPass('');
984 }
985}
An exception for terminatinating execution or to throw for unit testing.
const AUTH_APACHE
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
@classDescription Date and time handling
static deleteByServerId($a_server_id)
static deleteByServerId($a_server_id)
static deleteByServerId($a_server_id)
static deleteByServerId($a_server_id)
static resetServerId($a_server_id)
checkImportId()
check import id
setAuthPass($a_pass)
Set Apache auth password.
setAuthType($a_auth_type)
Set auth type.
getAuthType()
Get auth type.
getServerId()
Get current server id.
getApprovalRecipientsAsString()
get approval recipients as string
static _getInstance()
singleton getInstance
getPollingTimeMinutes()
get polling time minutes
getApprovalRecipients()
get approval recipients
isEnabled()
is enabled
fetchSerialID()
Fetch serial ID from cert.
getKeyPath()
get key path
setTitle($a_title)
Set title.
setDuration($a_duration)
set Duration
setCertSerialNumber($a_cert_serial)
set cert serial number
save()
save settings
getAuthUser()
Get apache auth user.
setProtocol($a_prot)
set protocol
getAuthPass()
Get auth password.
getUserRecipientsAsString()
Get new user recipients.
__construct($a_server_id=0)
Singleton contructor.
getCertSerialNumber()
get cert serial number
setPollingTime($a_time)
set polling time
getPollingTimeSeconds()
get polling time seconds (<60)
getKeyPassword()
get key password
setAuthUser($a_user)
Set apache auth user.
update()
Update setting.
setPort($a_port)
set port
getDuration()
get duration
getCACertPath()
get ca cert path
fetchCertificateExpiration()
Fetch validity (expired date)
getServer()
get server
setApprovalRecipients($a_rcp)
set approval recipients
getTitle()
Get title.
getUserRecipients()
Get new user recipients.
setServer($a_server)
set server
getPollingTime()
get polling time
setPollingTimeMS($a_min, $a_sec)
Set polling time.
getServerURI()
get complete server uri
setUserRecipients($a_logins)
set user recipients
read()
Read settings.
setEContentRecipients($a_logins)
set EContent recipients
setClientCertPath($a_path)
set
setEnabledStatus($a_status)
en/disable ecs functionality
setCACertPath($a_ca)
set ca cert path
static lookupAuthMode()
Lookup auth mode.
setKeyPath($a_path)
set key path
getClientCertPath()
get certificate path
getEContentRecipientsAsString()
get EContent recipients as string
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
getEContentRecipients()
get Econtent recipients
validate()
Validate settings.
getGlobalRole()
get global role
getProtocol()
get protocol
setGlobalRole($a_role_id)
set default global role
const ERROR_INVALID_IMPORT_ID
__clone()
Overwritten clone method Reset all connection settings.
setKeyPassword($a_pass)
set key password
setImportId($a_id)
set import id Object of category, that store new remote courses
getImportId()
get import id
$counter
$key
Definition: croninfo.php:18
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$query
foreach($_POST as $key=> $value) $res
global $ilDB