18 declare(strict_types=1);
78 $this->db = $DIC->database();
79 $this->log = $DIC->logger()->wsrv();
80 $this->objDataCache = $DIC[
'ilObjDataCache'];
81 $this->tree = $DIC->repositoryTree();
83 $this->server_id = $a_server_id;
94 return self::$instances[$a_server_id] ?? (self::$instances[$a_server_id] =
new ilECSSetting($a_server_id));
102 return self::DEFAULT_AUTH_MODE;
119 $this->title = $a_title;
136 $this->auth_type = $a_auth_type;
152 $this->auth_user = $a_user;
168 $this->auth_pass = $a_pass;
193 $this->active = $status;
209 $this->server = $a_server;
227 case self::PROTOCOL_HTTP:
231 case self::PROTOCOL_HTTPS:
236 if (strpos($this->
getServer(),
'/') !==
false) {
238 foreach ((array) explode(
'/', $this->
getServer()) as
$key => $part) {
241 $uri .=
':' . $this->
getPort();
246 $uri = substr($uri, 0, -1);
249 $uri .= (
':' . $this->
getPort());
260 $this->protocol = $a_prot;
276 $this->port = $a_port;
289 $this->client_cert_path = $a_path;
307 $this->ca_cert_path = $a_ca;
333 $this->key_path = $a_path;
351 $this->key_password = $a_pass;
360 $this->import_id = $a_id;
376 $this->cert_serial_number = $a_cert_serial;
400 $this->global_role = $a_role_id;
408 $this->duration = $a_duration;
416 return $this->duration ?: self::DEFAULT_DURATION;
432 return implode(
',', $this->user_recipients);
443 $this->user_recipients = $a_logins;
459 return implode(
',', $this->econtent_recipients);
469 $this->econtent_recipients = $a_logins;
485 return implode(
',', $this->approval_recipients);
493 $this->approval_recipients = $a_rcp;
508 if ($this->
getAuthType() === self::AUTH_CERTIFICATE) {
510 return self::ERROR_REQUIRED;
514 return self::ERROR_EXTRACT_SERIAL;
517 return self::ERROR_CERT_EXPIRED;
523 return self::ERROR_REQUIRED;
530 return self::ERROR_REQUIRED;
534 return self::ERROR_INVALID_IMPORT_ID;
547 if ($this->objDataCache->lookupType($this->objDataCache->lookupObjId($this->getImportId())) !==
'cat') {
550 if ($this->tree->isDeleted($this->getImportId())) {
561 $this->server_id = $this->db->nextId(
'ecs_server');
562 $this->db->manipulate(
563 'INSERT INTO ecs_server (server_id,active,title,protocol,server,port,auth_type,client_cert_path,ca_cert_path,' .
564 'key_path,key_password,cert_serial,import_id,global_role,econtent_rcp,user_rcp,approval_rcp,duration,auth_user,auth_pass) ' .
566 $this->db->quote($this->getServerId(),
'integer') .
', ' .
567 $this->db->quote((
int) $this->isEnabled(),
'integer') .
', ' .
568 $this->db->quote($this->getTitle(),
'text') .
', ' .
569 $this->db->quote($this->getProtocol(),
'integer') .
', ' .
570 $this->db->quote($this->getServer(),
'text') .
', ' .
571 $this->db->quote($this->getPort(),
'integer') .
', ' .
572 $this->db->quote($this->getAuthType(),
'integer') .
', ' .
573 $this->db->quote($this->getClientCertPath(),
'text') .
', ' .
574 $this->db->quote($this->getCACertPath(),
'text') .
', ' .
575 $this->db->quote($this->getKeyPath(),
'text') .
', ' .
576 $this->db->quote($this->getKeyPassword(),
'text') .
', ' .
577 $this->db->quote($this->getCertSerialNumber(),
'text') .
', ' .
578 $this->db->quote($this->getImportId(),
'integer') .
', ' .
579 $this->db->quote($this->getGlobalRole(),
'integer') .
', ' .
580 $this->db->quote($this->getEContentRecipientsAsString(),
'text') .
', ' .
581 $this->db->quote($this->getUserRecipientsAsString(),
'text') .
', ' .
582 $this->db->quote($this->getApprovalRecipientsAsString(),
'text') .
', ' .
583 $this->db->quote($this->getDuration(),
'integer') .
', ' .
584 $this->db->quote($this->getAuthUser(),
'text') .
', ' .
585 $this->db->quote($this->getAuthPass(),
'text') .
' ' .
595 $this->db->manipulate(
596 'UPDATE ecs_server SET ' .
597 'server_id = ' . $this->db->quote($this->getServerId(),
'integer') .
', ' .
598 'active = ' . $this->db->quote((
int) $this->isEnabled(),
'integer') .
', ' .
599 'title = ' . $this->db->quote($this->getTitle(),
'text') .
', ' .
600 'protocol = ' . $this->db->quote($this->getProtocol(),
'integer') .
', ' .
601 'server = ' . $this->db->quote($this->getServer(),
'text') .
', ' .
602 'port = ' . $this->db->quote($this->getPort(),
'integer') .
', ' .
603 'auth_type = ' . $this->db->quote($this->getAuthType(),
'integer') .
', ' .
604 'client_cert_path = ' . $this->db->quote($this->getClientCertPath(),
'text') .
', ' .
605 'ca_cert_path = ' . $this->db->quote($this->getCACertPath(),
'text') .
', ' .
606 'key_path = ' . $this->db->quote($this->getKeyPath(),
'text') .
', ' .
607 'key_password = ' . $this->db->quote($this->getKeyPassword(),
'text') .
', ' .
608 'cert_serial = ' . $this->db->quote($this->getCertSerialNumber(),
'text') .
', ' .
609 'import_id = ' . $this->db->quote($this->getImportId(),
'integer') .
', ' .
610 'global_role = ' . $this->db->quote($this->getGlobalRole(),
'integer') .
', ' .
611 'econtent_rcp = ' . $this->db->quote($this->getEContentRecipientsAsString(),
'text') .
', ' .
612 'user_rcp = ' . $this->db->quote($this->getUserRecipientsAsString(),
'text') .
', ' .
613 'approval_rcp = ' . $this->db->quote($this->getApprovalRecipientsAsString(),
'text') .
', ' .
614 'duration = ' . $this->db->quote($this->getDuration(),
'integer') .
', ' .
615 'auth_user = ' . $this->db->quote($this->getAuthUser(),
'text') .
', ' .
616 'auth_pass = ' . $this->db->quote($this->getAuthPass(),
'text') .
', ' .
617 'auth_type = ' . $this->db->quote($this->getAuthType(),
'integer') .
' ' .
618 'WHERE server_id = ' . $this->db->quote($this->getServerId(),
'integer')
625 public function delete():
bool 639 $query =
'DELETE FROM ecs_events' .
640 ' WHERE server_id = ' . $this->db->quote($this->
getServerId(),
'integer');
641 $this->db->manipulate(
$query);
651 $this->db->manipulate(
652 'DELETE FROM ecs_server ' .
653 'WHERE server_id = ' . $this->db->quote($this->getServerId(),
'integer')
656 $this->server_id = 0;
666 if ($this->
getAuthType() !== self::AUTH_CERTIFICATE) {
670 if ((function_exists(
'openssl_x509_parse') &&
672 $cert && isset($cert[
'validTo_time_t'])) && $cert[
'validTo_time_t']) {
686 if (function_exists(
'openssl_x509_parse') && ($cert = openssl_x509_parse(
'file://' . $this->
getClientCertPath())) && $cert && isset($cert[
'serialNumber']) && $cert[
'serialNumber']) {
688 $this->log->debug(
'Searial number is: ' . $cert[
'serialNumber']);
697 foreach ($lines as $line) {
698 if (strpos($line,
'Serial Number:') !==
false) {
700 $serial_line = explode(
':', $line);
701 $serial = trim($serial_line[1]);
705 if ($found && isset($serial)) {
721 $query =
'SELECT * FROM ecs_server ' .
722 'WHERE server_id = ' . $this->db->quote($this->
getServerId(),
'integer');
728 $this->
setPort((
int) $row[
'port']);
735 if ($row[
'cert_serial']) {
739 $this->econtent_recipients = explode(
',', $row[
'econtent_rcp']);
740 $this->approval_recipients = explode(
',', $row[
'approval_rcp']);
741 $this->user_recipients = explode(
',', $row[
'user_rcp']);
755 $this->server_id = 0;
setEContentRecipients(array $a_logins)
set EContent recipients
setServer(string $a_server)
set server
static getInstanceByServerId(int $a_server_id)
Get singleton instance.
setKeyPassword(string $a_pass)
set key password
getKeyPassword()
get key password
const ERROR_INVALID_IMPORT_ID
getCACertPath()
get ca cert path
setAuthUser($a_user)
Set apache auth user.
setDuration(int $a_duration)
set Duration
getServerId()
Get current server id.
static ecsConfigured()
Checks if an ecs server is configured.
getAuthType()
Get auth type.
getServerURI()
get complete server uri
getEContentRecipientsAsString()
get EContent recipients as string
setAuthPass($a_pass)
Set Apache auth password.
static getInstance()
Get the singelton instance of this ilECSExportManager.
getApprovalRecipientsAsString()
get approval recipients as string
setKeyPath(string $a_path)
set key path
static getInstance()
Get singleton instance.
__clone()
Overwritten clone method Reset all connection settings.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
getClientCertPath()
get certificate path
getAuthPass()
Get auth password.
getImportId()
get import id
getEContentRecipients()
get Econtent recipients
setCACertPath(string $a_ca)
set ca cert path
setTitle(string $a_title)
Set title.
setPort(int $a_port)
set port
fetchCertificateExpiration()
Fetch validity (expired date)
setAuthType($a_auth_type)
Set auth type.
getProtocol()
get protocol
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
validate()
Validate settings.
array $approval_recipients
string $cert_serial_number
setProtocol(int $a_prot)
set protocol
static getInstance()
Get the singleton instance of this ilECSImportManager.
static deleteByServerId($a_server_id)
setEnabledStatus(bool $status)
en/disable ecs functionality
getUserRecipientsAsString()
Get new user recipients.
setUserRecipients(array $a_logins)
set user recipients
getCertSerialNumber()
get cert serial number
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
Reads ECS events and stores them in the database.
setImportId(int $a_id)
set import id Object of category, that store new remote courses
getAuthUser()
Get apache auth user.
ilObjectDataCache $objDataCache
checkImportId()
check import id
array $econtent_recipients
setGlobalRole(int $a_role_id)
set default global role
getGlobalRole()
get global role
const ERROR_EXTRACT_SERIAL
getDuration()
get duration
static lookupAuthMode()
Lookup auth mode.
setClientCertPath($a_path)
fetchSerialID()
Fetch serial ID from cert.
__construct($a_server_id=0)
Singleton contructor.
setApprovalRecipients(array $a_rcp)
set approval recipients
getApprovalRecipients()
get approval recipients
getUserRecipients()
Get new user recipients.
setCertSerialNumber(string $a_cert_serial)
set cert serial number
static deleteByServerId($a_server_id)