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');
69 $GLOBALS[
'ilLog']->write(__METHOD__.
': Using deprecated call');
82 $this->header_strings[] = ($a_name.
': '.$a_value);
92 $this->header_strings = $a_header_strings;
118 public function addAuth($a_post,$a_target_mid)
122 $ilLog->write(__METHOD__.
': Add new Auth resource...');
124 $this->path_postfix =
'/sys/auths';
130 $this->
addHeader(
'Content-Type',
'application/json');
131 $this->
addHeader(
'Accept',
'application/json');
133 #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1);
135 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
136 $this->curl->setOpt(CURLOPT_POST,
true);
137 $this->curl->setOpt(CURLOPT_POSTFIELDS,$a_post);
140 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
142 $ilLog->write(__METHOD__.
': Checking HTTP status...');
143 if($info != self::HTTP_CODE_CREATED)
145 $ilLog->write(__METHOD__.
': Cannot create auth resource, did not receive HTTP 201. ');
146 $ilLog->write(__METHOD__.
': POST was: '.$a_post);
147 $ilLog->write(__METHOD__.
': HTTP code: '.$info);
150 $ilLog->write(__METHOD__.
': ... got HTTP 201 (created)');
155 $ilLog->write(__METHOD__.
': ... got hash: '.
$auth->hash);
178 $ilLog->write(__METHOD__.
': No auth hash given. Aborting.');
182 $this->path_postfix =
'/sys/auths/'.$a_hash;
188 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
190 $ilLog->write(__METHOD__.
': Checking HTTP status...');
191 if($info != self::HTTP_CODE_OK)
193 $ilLog->write(__METHOD__.
': Cannot get auth resource, did not receive HTTP 200. ');
196 $ilLog->write(__METHOD__.
': ... got HTTP 200 (ok)');
220 $this->path_postfix =
'/eventqueues';
227 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
229 $ilLog->write(__METHOD__.
': Checking HTTP status...');
230 if($info != self::HTTP_CODE_OK)
232 $ilLog->write(__METHOD__.
': Cannot get event queue, did not receive HTTP 200. ');
235 $ilLog->write(__METHOD__.
': ... got HTTP 200 (ok)');
244 #######################################################
246 #####################################################
257 $this->path_postfix =
'/sys/events/fifo';
261 $this->
addHeader(
'Content-Type',
'application/json');
262 $this->
addHeader(
'Accept',
'application/json');
266 $this->curl->setOpt(CURLOPT_POST,
true);
267 $this->curl->setOpt(CURLOPT_POSTFIELDS,
'');
272 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
273 #$ilLog->write(__METHOD__.': Checking HTTP status...');
274 if($info != self::HTTP_CODE_OK)
276 $ilLog->write(__METHOD__.
': Cannot read event fifo, did not receive HTTP 200. ');
279 #$ilLog->write(__METHOD__.': ... got HTTP 200 (ok)');
283 #$GLOBALS['ilLog']->write(__METHOD__.':------------------------------------- FIFO content'. print_r($result,true));
301 $this->path_postfix = $a_path;
305 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
309 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
310 $ilLog->write(__METHOD__.
': Checking HTTP status...');
311 if($info != self::HTTP_CODE_OK)
313 $ilLog->write(__METHOD__.
': Cannot get ressource list, did not receive HTTP 200. ');
316 $ilLog->write(__METHOD__.
': ... got HTTP 200 (ok)');
338 public function getResource($a_path, $a_econtent_id, $a_details_only =
false)
344 $ilLog->write(__METHOD__.
': Get resource with ID: '.$a_econtent_id);
348 $ilLog->write(__METHOD__.
': Get all resources ...');
351 $this->path_postfix = $a_path;
354 $this->path_postfix .= (
'/'.(int) $a_econtent_id);
358 $this->path_postfix .= (
'/details');
367 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
368 $ilLog->write(__METHOD__.
': Checking HTTP status...');
369 if($info != self::HTTP_CODE_OK)
371 $ilLog->write(__METHOD__.
': Cannot get ressource, did not receive HTTP 200. ');
374 $ilLog->write(__METHOD__.
': ... got HTTP 200 (ok)');
377 $result->setHeaders($this->curl->getResponseHeaderArray());
402 $ilLog->write(__METHOD__.
': Add new EContent...');
404 $this->path_postfix = $a_path;
410 $this->
addHeader(
'Content-Type',
'application/json');
412 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
413 $this->curl->setOpt(CURLOPT_HEADER,
true);
414 $this->curl->setOpt(CURLOPT_POST,
true);
415 $this->curl->setOpt(CURLOPT_POSTFIELDS,$a_post);
418 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
420 $ilLog->write(__METHOD__.
': Checking HTTP status...');
421 if($info != self::HTTP_CODE_CREATED)
423 $ilLog->write(__METHOD__.
': Cannot create econtent, did not receive HTTP 201. ');
426 $ilLog->write(__METHOD__.
': ... got HTTP 201 (created)');
450 $ilLog->write(__METHOD__.
': Update resource with id '.$a_econtent_id);
452 $this->path_postfix = $a_path;
456 $this->path_postfix .= (
'/'.(int) $a_econtent_id);
465 $this->
addHeader(
'Content-Type',
'application/json');
466 $this->
addHeader(
'Accept',
'application/json');
467 $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->
getHeader());
468 $this->curl->setOpt(CURLOPT_HEADER,
true);
469 $this->curl->setOpt(CURLOPT_PUT,
true);
472 $ilLog->write(__METHOD__.
': Created new tempfile: '.$tempfile);
474 $fp = fopen($tempfile,
'w');
475 fwrite($fp,$a_post_string);
478 $this->curl->setOpt(CURLOPT_UPLOAD,
true);
479 $this->curl->setOpt(CURLOPT_INFILESIZE,filesize($tempfile));
480 $fp = fopen($tempfile,
'r');
481 $this->curl->setOpt(CURLOPT_INFILE,$fp);
508 $ilLog->write(__METHOD__.
': Delete resource with id '.$a_econtent_id);
510 $this->path_postfix = $a_path;
514 $this->path_postfix .= (
'/'.(int) $a_econtent_id);
524 $this->curl->setOpt(CURLOPT_CUSTOMREQUEST,
'DELETE');
550 $ilLog->write(__METHOD__.
': Get existing memberships');
552 $this->path_postfix =
'/sys/memberships';
555 $ilLog->write(__METHOD__.
': Read membership with id: '.$a_mid);
556 $this->path_postfix .= (
'/'.(int) $a_mid);
564 $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
565 if($info != self::HTTP_CODE_OK)
567 $ilLog->write(__METHOD__.
': Cannot get memberships, did not receive HTTP 200. ');
587 #$GLOBALS['ilLog']->write(__METHOD__.': '.$this->settings->getServerURI());
591 $this->curl =
new ilCurlConnection($this->settings->getServerURI().$this->path_postfix);
593 $this->curl->setOpt(CURLOPT_HTTPHEADER,array(0 =>
'Accept: application/json'));
594 $this->curl->setOpt(CURLOPT_RETURNTRANSFER,1);
595 $this->curl->setOpt(CURLOPT_VERBOSE,1);
597 switch($this->
getServer()->getAuthType())
600 $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER,0);
601 #$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,0);
602 $this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
603 $this->curl->setOpt(CURLOPT_USERPWD,
609 $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER,1);
611 $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,2);
612 $this->curl->setOpt(CURLOPT_CAINFO,$this->settings->getCACertPath());
613 $this->curl->setOpt(CURLOPT_SSLCERT,$this->settings->getClientCertPath());
614 $this->curl->setOpt(CURLOPT_SSLKEY,$this->settings->getKeyPath());
615 $this->curl->setOpt(CURLOPT_SSLKEYPASSWD,$this->settings->getKeyPassword());
636 $res = $this->curl->exec();
658 if(!isset($a_header[
'Location']))
662 $end_path = strrpos($a_header[
'Location'],
"/");
664 if($end_path ===
false)
666 $ilLog->write(__METHOD__.
': Cannot find path seperator.');
669 $econtent_id = substr($a_header[
'Location'],$end_path + 1);
670 $ilLog->write(__METHOD__.
': Received EContentId '.$econtent_id);
671 return (
int) $econtent_id;