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