ILIAS  release_8 Revision v8.24
class.ilSoapAdministration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27include_once './webservice/soap/lib/nusoap.php';
28include_once("./Services/Authentication/classes/class.ilAuthUtils.php"); // to get auth mode constants
29
31{
32 public const NUSOAP = 1;
33 public const PHP5 = 2;
34
35 protected bool $soap_check = true;
36 protected string $message = '';
37 protected string $message_code = '';
38
42 public int $error_method;
43
44 public function __construct(bool $use_nusoap = true)
45 {
46 if (
47 defined('IL_SOAPMODE') &&
48 defined('IL_SOAPMODE_NUSOAP') &&
50 ) {
51 $this->error_method = self::NUSOAP;
52 } else {
53 $this->error_method = self::PHP5;
54 }
55
57 }
58
59 protected function checkSession(string $sid): bool
60 {
61 global $DIC;
62
63 $ilUser = $DIC->user();
64
65 [$sid, $client] = $this->explodeSid($sid);
66
67 if ($sid === '') {
68 $this->setMessage('No session id given');
69 $this->setMessageCode('Client');
70 return false;
71 }
72 if (!$client) {
73 $this->setMessage('No client given');
74 $this->setMessageCode('Client');
75 return false;
76 }
77
78 if (!$GLOBALS['DIC']['ilAuthSession']->isAuthenticated()) {
79 $this->setMessage('Session invalid');
80 $this->setMessageCode('Client');
81 return false;
82 }
83
84 if ($ilUser->hasToAcceptTermsOfService()) {
85 $this->setMessage('User agreement no accepted.');
86 $this->setMessageCode('Server');
87 return false;
88 }
89
90 if ($this->soap_check) {
91 $set = new ilSetting();
92 $this->setMessage('SOAP is not enabled in ILIAS administration for this client');
93 $this->setMessageCode('Server');
94 return ((int) $set->get("soap_user_administration", '0')) === 1;
95 }
96
97 return true;
98 }
99
100 protected function explodeSid(string $sid): array
101 {
102 $exploded = explode('::', $sid);
103
104 return is_array($exploded) ? $exploded : array('sid' => '', 'client' => '');
105 }
106
107 protected function setMessage(string $a_str): void
108 {
109 $this->message = $a_str;
110 }
111
112 public function getMessage(): string
113 {
114 return $this->message;
115 }
116
117 public function appendMessage(string $a_str): void
118 {
119 $this->message .= isset($this->message) ? ' ' : '';
120 $this->message .= $a_str;
121 }
122
123 public function setMessageCode(string $a_code): void
124 {
125 $this->message_code = $a_code;
126 }
127
128 public function getMessageCode(): string
129 {
130 return $this->message_code;
131 }
132
133 protected function initAuth(string $sid): void
134 {
135 global $DIC;
136
137 [$sid, $client] = $this->explodeSid($sid);
138
139 if (session_status() === PHP_SESSION_ACTIVE && $sid === session_id()) {
140 return;
141 }
142
143 if (session_status() === PHP_SESSION_ACTIVE) {
144 session_destroy();
145 }
146
147 session_id($sid);
148 }
149
150 protected function initIlias(): void
151 {
153 try {
154 require_once("Services/Init/classes/class.ilInitialisation.php");
156 } catch (Exception $e) {
157 }
158 }
159 }
160
161 public function reInitUser(): void
162 {
164 try {
165 require_once("Services/Init/classes/class.ilInitialisation.php");
167 } catch (Exception $e) {
168 }
169 }
170 }
171
172 protected function initAuthenticationObject(): void
173 {
174 include_once './Services/Authentication/classes/class.ilAuthFactory.php';
176 }
177
183 protected function raiseError(string $a_message, $a_code)
184 {
185 switch ($this->error_method) {
186 case self::NUSOAP:
187 return new soap_fault($a_code, '', $a_message);
188 case self::PHP5:
189 return new SoapFault($a_code, $a_message);
190 }
191 return null;
192 }
193
194 public function isFault($object): bool
195 {
196 switch ($this->error_method) {
197 case self::NUSOAP:
198 return $object instanceof soap_fault;
199 case self::PHP5:
200 return $object instanceof SoapFault;
201 }
202 return true;
203 }
204
208 protected function checkObjectAccess(
209 int $ref_id,
210 array $expected_type,
211 string $permission,
212 bool $returnObject = false
213 ) {
214 global $DIC;
215
216 $rbacsystem = $DIC->rbac()->system();
217
218 if (!ilObject::_exists($ref_id, true)) {
219 return $this->raiseError(
220 'No object for id.',
221 'CLIENT_OBJECT_NOT_FOUND'
222 );
223 }
224
225 if (ilObject::_isInTrash($ref_id)) {
226 return $this->raiseError(
227 'Object is already trashed.',
228 'CLIENT_OBJECT_DELETED'
229 );
230 }
231
233 if (!in_array($type, $expected_type, true)) {
234 return $this->raiseError(
235 "Wrong type $type for id. Expected: " . implode(",", $expected_type),
236 'CLIENT_OBJECT_WRONG_TYPE'
237 );
238 }
239 if (!$rbacsystem->checkAccess($permission, $ref_id, $type)) {
240 return $this->raiseError(
241 'Missing permission $permission for type $type.',
242 'CLIENT_OBJECT_WRONG_PERMISSION'
243 );
244 }
245 if ($returnObject) {
246 try {
248 } catch (ilObjectNotFoundException $e) {
249 return $this->raiseError('No valid ref_id given', 'Client');
250 }
251 }
252 return $type;
253 }
254
255 public function getInstallationInfoXML(): string
256 {
257 $this->initIlias();
258 if (!defined("ILIAS_WEB_DIR")) {
259 define('ILIAS_WEB_DIR', dirname(__DIR__, 3) . "/data/");
260 }
261
262 $clientdirs = glob(ILIAS_WEB_DIR . "/*", GLOB_ONLYDIR);
263 require_once("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
264 $writer = new ilSoapInstallationInfoXMLWriter();
265 $writer->start();
266 if (is_array($clientdirs)) {
267 foreach ($clientdirs as $clientdir) {
268 $writer->addClient($clientdir);
269 }
270 }
271 $writer->end();
272 return $writer->getXML();
273 }
274
278 public function getClientInfoXML(string $clientid)
279 {
280 $this->initIlias();
281 if (!defined("ILIAS_WEB_DIR")) {
282 define('ILIAS_WEB_DIR', dirname(__DIR__, 3) . "/data/");
283 }
284 $clientdir = ILIAS_WEB_DIR . "/" . $clientid;
285
286 require_once("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
287 $writer = new ilSoapInstallationInfoXMLWriter();
288 $writer->start();
289 if (!$writer->addClient($clientdir)) {
290 return $this->raiseError(
291 'Client ID ' . $clientid . 'does not exist!',
292 'Client'
293 );
294 }
295 $writer->end();
296 return $writer->getXML();
297 }
298}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static setContext(int $a_context)
set context
const CONTEXT_SOAP
SOAP based authentication.
static getType()
Get context type.
const CONTEXT_SOAP
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _isInTrash(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
soap server Base class for all SOAP registered methods.
raiseError(string $a_message, $a_code)
__construct(bool $use_nusoap=true)
int $error_method
Defines type of error handling (PHP5 || NUSOAP)
checkObjectAccess(int $ref_id, array $expected_type, string $permission, bool $returnObject=false)
check access for ref id: expected type, permission, return object instance if returnobject is true
Backward compatibility.
Definition: nusoap.php:1111
const ILIAS_WEB_DIR
Definition: constants.php:45
$client
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$ref_id
Definition: ltiauth.php:67
$type
const IL_SOAPMODE
Definition: server.php:19
const IL_SOAPMODE_NUSOAP
Definition: server.php:15