34 include_once(
'Services/WebServices/ECS/classes/class.ilECSSetting.php');
35 include_once(
'Services/WebServices/ECS/classes/class.ilECSResult.php');
36 include_once(
'Services/WebServices/Curl/classes/class.ilCurlConnection.php');
70 $this->logger = $DIC->logger()->wsrv();
74 $this->logger->warning(
'Using deprecated call.');
87 $this->header_strings[] = ($a_name .
': ' . $a_value);
97 $this->header_strings = $a_header_strings;
123 public function addAuth($a_post, $a_target_mid)
127 $ilLog = $DIC[
'ilLog'];
129 $ilLog->write(__METHOD__ .
': Add new Auth resource...');
131 $this->path_postfix =
'/sys/auths';
136 $this->
addHeader(
'Content-Type',
'application/json');
137 $this->
addHeader(
'Accept',
'application/json');
139 #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1); 141 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
142 $this->curl->setOpt(CURLOPT_POST,
true);
143 $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
146 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
148 $ilLog->write(__METHOD__ .
': Checking HTTP status...');
149 if ($info != self::HTTP_CODE_CREATED) {
150 $ilLog->write(__METHOD__ .
': Cannot create auth resource, did not receive HTTP 201. ');
151 $ilLog->write(__METHOD__ .
': POST was: ' . $a_post);
152 $ilLog->write(__METHOD__ .
': HTTP code: ' . $info);
155 $ilLog->write(__METHOD__ .
': ... got HTTP 201 (created)');
156 $ilLog->write(__METHOD__ .
': POST was: ' . $a_post);
161 $ilLog->write(__METHOD__ .
': ... got hash: ' .
$auth->hash);
176 public function getAuth($a_hash, $a_details_only =
false)
180 $ilLog = $DIC[
'ilLog'];
182 if (!strlen($a_hash)) {
183 $ilLog->write(__METHOD__ .
': No auth hash given. Aborting.');
187 $this->path_postfix =
'/sys/auths/' . $a_hash;
189 if ($a_details_only) {
190 $this->path_postfix .= (
'/details');
197 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
199 $ilLog->write(__METHOD__ .
': Checking HTTP status...');
200 if ($info != self::HTTP_CODE_OK) {
201 $ilLog->write(__METHOD__ .
': Cannot get auth resource, did not receive HTTP 200. ');
204 $ilLog->write(__METHOD__ .
': ... got HTTP 200 (ok)');
208 if ($a_details_only) {
209 include_once
'./Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
211 $details->loadFromJson($ecs_result->getResult());
235 $ilLog = $DIC[
'ilLog'];
237 $this->path_postfix =
'/eventqueues';
243 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
245 $ilLog->write(__METHOD__ .
': Checking HTTP status...');
246 if ($info != self::HTTP_CODE_OK) {
247 $ilLog->write(__METHOD__ .
': Cannot get event queue, did not receive HTTP 200. ');
250 $ilLog->write(__METHOD__ .
': ... got HTTP 200 (ok)');
257 ####################################################### 259 ##################################################### 270 $ilLog = $DIC[
'ilLog'];
272 $this->path_postfix =
'/sys/events/fifo';
276 $this->
addHeader(
'Content-Type',
'application/json');
277 $this->
addHeader(
'Accept',
'application/json');
280 $this->curl->setOpt(CURLOPT_POST,
true);
281 $this->curl->setOpt(CURLOPT_POSTFIELDS,
'');
286 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
287 #$ilLog->write(__METHOD__.': Checking HTTP status...'); 288 if ($info != self::HTTP_CODE_OK) {
289 $ilLog->write(__METHOD__ .
': Cannot read event fifo, did not receive HTTP 200. ');
292 #$ilLog->write(__METHOD__.': ... got HTTP 200 (ok)'); 296 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.':------------------------------------- FIFO content'. print_r($result,true)); 302 $this->curl->close();
314 $ilLog = $DIC[
'ilLog'];
316 $this->path_postfix = $a_path;
320 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
324 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
325 $ilLog->write(__METHOD__ .
': Checking HTTP status...');
326 if ($info != self::HTTP_CODE_OK) {
327 $ilLog->write(__METHOD__ .
': Cannot get ressource list, did not receive HTTP 200. ');
330 $ilLog->write(__METHOD__ .
': ... got HTTP 200 (ok)');
350 public function getResource($a_path, $a_econtent_id, $a_details_only =
false)
354 $ilLog = $DIC[
'ilLog'];
356 if ($a_econtent_id) {
357 $ilLog->write(__METHOD__ .
': Get resource with ID: ' . $a_econtent_id);
359 $ilLog->write(__METHOD__ .
': Get all resources ...');
362 $this->path_postfix = $a_path;
363 if ($a_econtent_id) {
364 $this->path_postfix .= (
'/' . (int) $a_econtent_id);
366 if ($a_details_only) {
367 $this->path_postfix .= (
'/details');
375 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
376 $ilLog->write(__METHOD__ .
': Checking HTTP status...');
377 if ($info != self::HTTP_CODE_OK) {
378 $ilLog->write(__METHOD__ .
': Cannot get ressource, did not receive HTTP 200. ');
381 $ilLog->write(__METHOD__ .
': ... got HTTP 200 (ok)');
384 $result->setHeaders($this->curl->getResponseHeaderArray());
407 $ilLog = $DIC[
'ilLog'];
409 $ilLog->write(__METHOD__ .
': Add new EContent...');
411 $this->path_postfix = $a_path;
416 $this->
addHeader(
'Content-Type',
'application/json');
418 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
419 $this->curl->setOpt(CURLOPT_HEADER,
true);
420 $this->curl->setOpt(CURLOPT_POST,
true);
421 $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post);
424 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
426 $ilLog->write(__METHOD__ .
': Checking HTTP status...');
427 if ($info != self::HTTP_CODE_CREATED) {
428 $ilLog->write(__METHOD__ .
': Cannot create econtent, did not receive HTTP 201. ');
431 $ilLog->write(__METHOD__ .
': ... got HTTP 201 (created)');
433 $eid = self::_fetchEContentIdFromHeader($this->curl->getResponseHeaderArray());
453 $ilLog = $DIC[
'ilLog'];
455 $ilLog->write(__METHOD__ .
': Update resource with id ' . $a_econtent_id);
457 $this->path_postfix = $a_path;
459 if ($a_econtent_id) {
460 $this->path_postfix .= (
'/' . (int) $a_econtent_id);
466 $this->
addHeader(
'Content-Type',
'application/json');
467 $this->
addHeader(
'Accept',
'application/json');
468 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
469 $this->curl->setOpt(CURLOPT_HEADER,
true);
470 $this->curl->setOpt(CURLOPT_PUT,
true);
473 $ilLog->write(__METHOD__ .
': Created new tempfile: ' . $tempfile);
475 $fp = fopen($tempfile,
'w');
476 fwrite($fp, $a_post_string);
479 $this->curl->setOpt(CURLOPT_UPLOAD,
true);
480 $this->curl->setOpt(CURLOPT_INFILESIZE, filesize($tempfile));
481 $fp = fopen($tempfile,
'r');
482 $this->curl->setOpt(CURLOPT_INFILE, $fp);
507 $ilLog = $DIC[
'ilLog'];
509 $ilLog->write(__METHOD__ .
': Delete resource with id ' . $a_econtent_id);
511 $this->path_postfix = $a_path;
513 if ($a_econtent_id) {
514 $this->path_postfix .= (
'/' . (int) $a_econtent_id);
521 $this->curl->setOpt(CURLOPT_CUSTOMREQUEST,
'DELETE');
544 $ilLog = $DIC[
'ilLog'];
546 $ilLog->write(__METHOD__ .
': Get existing memberships');
548 $this->path_postfix =
'/sys/memberships';
550 $ilLog->write(__METHOD__ .
': Read membership with id: ' . $a_mid);
551 $this->path_postfix .= (
'/' . (int) $a_mid);
557 $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 =>
'X-EcsQueryStrings: sender=true'));
560 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
561 if ($info != self::HTTP_CODE_OK) {
562 $ilLog->write(__METHOD__ .
': Cannot get memberships, did not receive HTTP 200. ');
582 $this->curl->
init(
true);
583 $this->curl->setOpt(CURLOPT_HTTPHEADER, array(0 =>
'Accept: application/json'));
584 $this->curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
585 $this->curl->setOpt(CURLOPT_TIMEOUT_MS, 2000);
588 $this->curl->setOpt(CURLOPT_VERBOSE, 1);
591 switch ($this->
getServer()->getAuthType()) {
593 $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
594 #$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,0); 595 $this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
603 $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
605 $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
606 $this->curl->setOpt(CURLOPT_CAINFO, $this->
settings->getCACertPath());
607 $this->curl->setOpt(CURLOPT_SSLCERT, $this->
settings->getClientCertPath());
608 $this->curl->setOpt(CURLOPT_SSLKEY, $this->
settings->getKeyPath());
609 $this->curl->setOpt(CURLOPT_SSLKEYPASSWD, $this->
settings->getKeyPassword());
627 $res = $this->curl->exec();
647 $ilLog = $DIC[
'ilLog'];
648 $location_parts = [];
649 foreach ($a_header as $header => $value) {
650 if (strcasecmp(
'Location', $header) == 0) {
651 $location_parts = explode(
'/', $value);
655 if (!$location_parts) {
656 $ilLog->write(__METHOD__ .
': Cannot find location headers.');
659 if (count($location_parts) == 1) {
660 $ilLog->write(__METHOD__ .
': Cannot find path seperator.');
663 $econtent_id = end($location_parts);
664 $ilLog->write(__METHOD__ .
': Received EContentId ' . $econtent_id);
665 return (
int) $econtent_id;
const RESULT_TYPE_URL_LIST
addResource($a_path, $a_post)
Add resource.
__construct(ilECSSetting $settings=null)
Constructor.
getAuth($a_hash, $a_details_only=false)
get auth resource
deleteResource($a_path, $a_econtent_id)
Delete resource.
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
init(bool $set_proxy=true)
Init curl connection.
foreach($_POST as $key=> $value) $res
addAuth($a_post, $a_target_mid)
Add auth resource.
getMemberships($a_mid=0)
public
setHeader($a_header_strings)
static _fetchEContentIdFromHeader($a_header)
fetch new econtent id from location header
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
updateResource($a_path, $a_econtent_id, $a_post_string)
update resource
getResource($a_path, $a_econtent_id, $a_details_only=false)
Get resources from ECS server.
getServer()
Get current server setting.
addHeader($a_name, $a_value)
Add Header.
readEventFifo($a_delete=false)
Read event fifo.
prepareConnection()
prepare connection
const HTTP_CODE_NOT_FOUND
getEventQueues()
get event queue