ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSoapAdministration.php
Go to the documentation of this file.
1<?php
2 /*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2009 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
24
35include_once './webservice/soap/lib/nusoap.php';
36include_once("./Services/Authentication/classes/class.ilAuthUtils.php"); // to get auth mode constants
37
38define('SOAP_CLIENT_ERROR', 1);
39define('SOAP_SERVER_ERROR', 2);
40
42{
43 protected $soap_check = true;
44
45
46 /*
47 * object which handles php's authentication
48 * @var object
49 */
50 public $sauth = null;
51
52 /*
53 * Defines type of error handling (PHP5 || NUSOAP)
54 * @var object
55 */
56 public $error_method = null;
57
58
63 public function __construct($use_nusoap = true)
64 {
65 define('USER_FOLDER_ID', 7);
66 define('NUSOAP', 1);
67 define('PHP5', 2);
68
69 if (
70 defined('IL_SOAPMODE') && defined('IL_SOAPMODE_NUSOAP') &&
72 ) {
73 $this->error_method = NUSOAP;
74 } else {
75 $this->error_method = PHP5;
76 }
77
79 }
80
81 // PROTECTED
82 public function __checkSession($sid)
83 {
87 global $ilUser;
88
89 list($sid, $client) = $this->__explodeSid($sid);
90
91 if (!strlen($sid)) {
92 $this->__setMessage('No session id given');
93 $this->__setMessageCode('Client');
94 return false;
95 }
96 if (!$client) {
97 $this->__setMessage('No client given');
98 $this->__setMessageCode('Client');
99 return false;
100 }
101
102 if (!$GLOBALS['DIC']['ilAuthSession']->isAuthenticated()) {
103 $this->__setMessage('Session invalid');
104 $this->__setMessageCode('Client');
105 return false;
106 }
107
108 if ($ilUser->hasToAcceptTermsOfService()) {
109 $this->__setMessage('User agreement no accepted.');
110 $this->__setMessageCode('Server');
111 return false;
112 }
113
114 if ($this->soap_check) {
115 $set = new ilSetting();
116 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
117 $this->__setMessageCode('Server');
118 return ($set->get("soap_user_administration") == 1);
119 }
120
121 return true;
122 }
123
131 public function initErrorWriter()
132 {
133 include_once('./Services/Init/classes/class.ilErrorHandling.php');
134
135 set_error_handler(array('ilErrorHandling','_ilErrorWriter'), E_ALL);
136 }
137
138
139 public function __explodeSid($sid)
140 {
141 $exploded = explode('::', $sid);
142
143 return is_array($exploded) ? $exploded : array('sid' => '','client' => '');
144 }
145
146
147 public function __setMessage($a_str)
148 {
149 $this->message = $a_str;
150 }
151 public function __getMessage()
152 {
153 return $this->message;
154 }
155 public function __appendMessage($a_str)
156 {
157 $this->message .= isset($this->message) ? ' ' : '';
158 $this->message .= $a_str;
159 }
160
161 public function __setMessageCode($a_code)
162 {
163 $this->message_code = $a_code;
164 }
165
166 public function __getMessageCode()
167 {
168 return $this->message_code;
169 }
170
175 public function initAuth($sid)
176 {
177 list($sid, $client) = $this->__explodeSid($sid);
178 define('CLIENT_ID', $client);
179 $_COOKIE['ilClientId'] = $client;
180 $_COOKIE['PHPSESSID'] = $sid;
181 }
182
183 public function initIlias()
184 {
186 try {
187 require_once("Services/Init/classes/class.ilInitialisation.php");
189 } catch (Exception $e) {
190 // #10608
191 // no need to do anything here, see __checkSession() below
192 }
193 }
194 }
195
196
197 public function __initAuthenticationObject($a_auth_mode = AUTH_LOCAL)
198 {
199 include_once './Services/Authentication/classes/class.ilAuthFactory.php';
201 }
202
203
204 public function __raiseError($a_message, $a_code)
205 {
206 #echo $a_message, $a_code;
207 switch ($this->error_method) {
208 case NUSOAP:
209 return new soap_fault($a_code, '', $a_message);
210 case PHP5:
211 return new SoapFault($a_code, $a_message);
212 }
213 }
214
222 public function getNIC($sid)
223 {
224 $this->initAuth($sid);
225 $this->initIlias();
226
227 if (!$this->__checkSession($sid)) {
228 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
229 }
230
231 global $rbacsystem, $rbacreview, $ilLog, $rbacadmin,$ilSetting, $ilClientIniFile;
232
233 if (!is_object($ilClientIniFile)) {
234 return $this->__raiseError("Client ini is not initialized", "Server");
235 }
236 $auth_modes = ilAuthUtils::_getActiveAuthModes();
237 $auth_mode_default = strtoupper(ilAuthUtils::_getAuthModeName(array_shift($auth_modes)));
238 $auth_mode_names = array();
239 foreach ($auth_modes as $mode) {
240 $auth_mode_names[] = strtoupper(ilAuthUtils::_getAuthModeName($mode));
241 }
242
243 include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
244 include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php';
245
246 // create advanced meta data record xml
247 $record_ids = array();
249 foreach ($record_types as $type_info) {
250 $type = $type_info['obj_type'];
252 foreach ($records as $record) {
253 $record_ids [] = $record->getRecordId();
254 }
255 }
256 $record_ids = array_unique($record_ids);
257 $advmwriter = new ilAdvancedMDRecordXMLWriter($record_ids);
258 $advmwriter->write();
259
260 // create user defined fields record xml, simulate empty user records
261 include_once("./Services/User/classes/class.ilUserXMLWriter.php");
262 $udfWriter = new ilUserXMLWriter();
263 $users = array();
264 $udfWriter->setObjects($users);
265 $udfWriter->start();
266
267 // todo: get information from client id, read from ini file specificied
268 $client_details[] = array("installation_id" => IL_INST_ID,
269 "installation_version" => ILIAS_VERSION,
270 "installation_url" => ILIAS_HTTP_PATH,
271 "installation_description" => $ilClientIniFile->readVariable("client", "description"),
272 "installation_language_default" => $ilClientIniFile->readVariable("language", "default"),
273 "installation_session_expire" => $ilClientIniFile->readVariable("session", "expire"),
274 "installation_php_postmaxsize" => $this->return_bytes(ini_get("post_max_size")),
275 "authentication_methods" => join(",", $auth_mode_names),
276 "authentication_default_method" => $auth_mode_default,
277 "installation_udf_xml" => $udfWriter ->getXML(),
278 "installation_advmd_xml" => $advmwriter->xmlDumpMem(false)
279
280 );
281
282 // store into xml result set
283 include_once './webservice/soap/classes/class.ilXMLResultSet.php';
284
285
286 $xmlResult = new ilXMLResultSet();
287 $xmlResult->addArray($client_details, true);
288
289 // create writer and return xml
290 include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
291 $xmlResultWriter = new ilXMLResultSetWriter($xmlResult);
292 $xmlResultWriter->start();
293 return $xmlResultWriter->getXML();
294 }
295
300 public static function return_bytes($val)
301 {
302 $val = trim($val);
303 $last = strtolower($val{strlen($val)-1});
304 switch ($last) {
305 // The 'G' modifier is available since PHP 5.1.0
306 case 'g':
307 $val *= 1024;
308 // no break
309 case 'm':
310 $val *= 1024;
311 // no break
312 case 'k':
313 $val *= 1024;
314 }
315 return $val;
316 }
317
318 public function isFault($object)
319 {
320 switch ($this->error_method) {
321 case NUSOAP:
322 return $object instanceof soap_fault;
323 case PHP5:
324 return $object instanceof SoapFault;
325 }
326 return true;
327 }
328
338 public function checkObjectAccess($ref_id, $expected_type, $permission, $returnObject = false)
339 {
340 global $rbacsystem;
341 if (!is_numeric($ref_id)) {
342 return $this->__raiseError(
343 'No valid id given.',
344 'Client'
345 );
346 }
347 if (!ilObject::_exists($ref_id, true)) {
348 return $this->__raiseError(
349 'No object for id.',
350 'CLIENT_OBJECT_NOT_FOUND'
351 );
352 }
353
354 if (ilObject::_isInTrash($ref_id)) {
355 return $this->__raiseError(
356 'Object is already trashed.',
357 'CLIENT_OBJECT_DELETED'
358 );
359 }
360
362 if ((is_array($expected_type) && !in_array($type, $expected_type))
363 ||
364 (!is_array($expected_type) && $type != $expected_type)
365 ) {
366 return $this->__raiseError("Wrong type $type for id. Expected: " . (is_array($expected_type) ? join(",", $expected_type) : $expected_type), 'CLIENT_OBJECT_WRONG_TYPE');
367 }
368
369 if (!$rbacsystem->checkAccess($permission, $ref_id, $type)) {
370 return $this->__raiseError('Missing permission $permission for type $type.', 'CLIENT_OBJECT_WRONG_PERMISSION');
371 }
372
373 if ($returnObject) {
375 }
376
377 return $type;
378 }
379
380 public function getInstallationInfoXML()
381 {
382 include_once "Services/Context/classes/class.ilContext.php";
384
385 require_once("Services/Init/classes/class.ilInitialisation.php");
387
388 $clientdirs = glob(ILIAS_WEB_DIR . "/*", GLOB_ONLYDIR);
389 require_once("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
390 $writer = new ilSoapInstallationInfoXMLWriter();
391 $writer->start();
392 if (is_array($clientdirs)) {
393 foreach ($clientdirs as $clientdir) {
394 if (is_object($clientInfo= $this->getClientInfo(null, $clientdir))) {
395 $writer->addClient($clientInfo);
396 }
397 }
398 }
399 $writer->end();
400
401 return $writer->getXML();
402 }
403
404 public function getClientInfoXML($clientid)
405 {
406 include_once "Services/Context/classes/class.ilContext.php";
408
409 require_once("Services/Init/classes/class.ilInitialisation.php");
411
412 $clientdir = ILIAS_WEB_DIR . "/" . $clientid;
413 require_once("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
414 $writer = new ilSoapInstallationInfoXMLWriter();
415 $writer->setExportAdvancedMetaDataDefinitions(true);
416 $writer->setExportUDFDefinitions(true);
417 $writer->start();
418 if (is_object($client = $this->getClientInfo(null, $clientdir))) {
419 $writer->addClient($client);
420 } else {
421 return $this->__raiseError("Client ID $clientid does not exist!", 'Client');
422 }
423 $writer->end();
424 return $writer->getXML();
425 }
426
427 private function getClientInfo($init, $client_dir)
428 {
429 global $DIC;
430
431 $ini_file = "./" . $client_dir . "/client.ini.php";
432
433 // get settings from ini file
434 require_once("./Services/Init/classes/class.ilIniFile.php");
435
436 $ilClientIniFile = new ilIniFile($ini_file);
437 $ilClientIniFile->read();
438 if ($ilClientIniFile->ERROR != "") {
439 return false;
440 }
441 $client_id = $ilClientIniFile->readVariable('client', 'name');
442 if ($ilClientIniFile->variableExists('client', 'expose')) {
443 $client_expose = $ilClientIniFile->readVariable('client', 'expose');
444 if ($client_expose == "0") {
445 return false;
446 }
447 }
448
449 // build dsn of database connection and connect
450 require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
451 $ilDB = ilDBWrapperFactory::getWrapper(
452 $ilClientIniFile->readVariable("db", "type"),
453 $ilClientIniFile->readVariable("db", "inactive_mysqli")
454 );
455 $ilDB->initFromIniFile($ilClientIniFile);
456 if ($ilDB->connect(true)) {
457 unset($DIC['ilDB']);
458 $DIC['ilDB'] = $ilDB;
459
460 require_once("Services/Administration/classes/class.ilSetting.php");
461
462 $settings = new ilSetting();
463 unset($DIC["ilSetting"]);
464 $DIC["ilSetting"] = $settings;
465 // workaround to determine http path of client
466 define("IL_INST_ID", $settings->get("inst_id", 0));
467 $settings->access = $ilClientIniFile->readVariable("client", "access");
468 $settings->description = $ilClientIniFile->readVariable("client", "description");
469 $settings->session = min((int) ini_get("session.gc_maxlifetime"), (int) $ilClientIniFile->readVariable("session", "expire"));
470 $settings->language = $ilClientIniFile->readVariable("language", "default");
471 $settings->clientid = basename($client_dir); //pathinfo($client_dir, PATHINFO_FILENAME);
472 $settings->default_show_users_online = $settings->get("show_users_online");
473 $settings->default_hits_per_page = $settings->get("hits_per_page");
474 $skin = $ilClientIniFile->readVariable("layout", "skin");
475 $style = $ilClientIniFile->readVariable("layout", "style");
476 $settings->default_skin_style = $skin . ":" . $style;
477 return $settings;
478 }
479 return null;
480 }
481}
$_COOKIE['client_id']
Definition: server.php:9
$users
Definition: authpage.php:44
$client
Definition: resume.php:9
An exception for terminatinating execution or to throw for unit testing.
const AUTH_LOCAL
static _getActivatedRecordsByObjectType($a_obj_type, $a_sub_type="", $a_only_optional=false)
Get activated records by object type.
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
static setContext($a_context)
set context
static _getActiveAuthModes()
static _getAuthModeName($a_auth_key)
const CONTEXT_SOAP_WITHOUT_CLIENT
static init($a_type)
Init context by type.
static getType()
Get context type.
const CONTEXT_SOAP
INIFile Parser.
static initILIAS()
ilias initialisation
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static getTypeByRefId($a_ref_id, $stop_on_error=true)
get object type by reference id
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _isInTrash($a_ref_id)
checks wether object is in trash
ILIAS Setting Class.
initAuth($sid)
Init authentication.
__initAuthenticationObject($a_auth_mode=AUTH_LOCAL)
__raiseError($a_message, $a_code)
__construct($use_nusoap=true)
Constructor.
checkObjectAccess($ref_id, $expected_type, $permission, $returnObject=false)
check access for ref id: expected type, permission, return object instance if returnobject is true
initErrorWriter()
Overwrite error handler.
static return_bytes($val)
calculate bytes from K,M,G modifiers e.g: 8M = 8 * 1024 * 1024 bytes
getNIC($sid)
get client information from current as xml result set
XML writer class.
XML Writer for XMLResultSet.
soap_fault class, allows for creation of faults mainly used for returning faults from deployed functi...
Definition: nusoap.php:669
$style
Definition: example_012.php:70
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$client_id
const ILIAS_VERSION
catch(Exception $e) $message
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
global $ilSetting
Definition: privfeed.php:17
$type
global $DIC
Definition: saml.php:7
$records
Definition: simple_test.php:22
global $ilDB
$ilUser
Definition: imgupload.php:18
const IL_SOAPMODE
Definition: server.php:19
const IL_SOAPMODE_NUSOAP
Definition: server.php:15