ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  var $sauth = null;
51 
52  /*
53  * Defines type of error handling (PHP5 || NUSOAP)
54  * @var object
55  */
56  var $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 
70  {
71  $this->error_method = NUSOAP;
72  }
73  else
74  {
75  $this->error_method = PHP5;
76  }
77  #echo ("SOAP: using soap mode ".IL_SOAPMODE == IL_SOAPMODE_NUSOAP ? "NUSOAP": "PHP5");
79  }
80 
81  // PROTECTED
82  function __checkSession($sid)
83  {
87  global $ilUser;
88 
89  list($sid,$client) = $this->__explodeSid($sid);
90 
91  if(!strlen($sid))
92  {
93  $this->__setMessage('No session id given');
94  $this->__setMessageCode('Client');
95  return false;
96  }
97  if(!$client)
98  {
99  $this->__setMessage('No client given');
100  $this->__setMessageCode('Client');
101  return false;
102  }
103 
104  if(!$GLOBALS['DIC']['ilAuthSession']->isAuthenticated())
105  {
106  $this->__setMessage('Session invalid');
107  $this->__setMessageCode('Client');
108  return false;
109  }
110 
111  if($ilUser->hasToAcceptTermsOfService())
112  {
113  $this->__setMessage('User agreement no accepted.');
114  $this->__setMessageCode('Server');
115  return false;
116  }
117 
118  if($this->soap_check)
119  {
120  $set = new ilSetting();
121  $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
122  $this->__setMessageCode('Server');
123  return ($set->get("soap_user_administration") == 1);
124  }
125 
126  return true;
127  }
128 
136  public function initErrorWriter()
137  {
138  include_once('./Services/Init/classes/class.ilErrorHandling.php');
139 
140  set_error_handler(array('ilErrorHandling','_ilErrorWriter'),E_ALL);
141  }
142 
143 
144  function __explodeSid($sid)
145  {
146  $exploded = explode('::',$sid);
147 
148  return is_array($exploded) ? $exploded : array('sid' => '','client' => '');
149  }
150 
151 
152  function __setMessage($a_str)
153  {
154  $this->message = $a_str;
155  }
156  function __getMessage()
157  {
158  return $this->message;
159  }
160  function __appendMessage($a_str)
161  {
162  $this->message .= isset($this->message) ? ' ' : '';
163  $this->message .= $a_str;
164  }
165 
166  public function __setMessageCode($a_code)
167  {
168  $this->message_code = $a_code;
169  }
170 
171  public function __getMessageCode()
172  {
173  return $this->message_code;
174  }
175 
180  public function initAuth($sid)
181  {
182  list($sid,$client) = $this->__explodeSid($sid);
183  define('CLIENT_ID',$client);
184  $_COOKIE['ilClientId'] = $client;
185  $_COOKIE['PHPSESSID'] = $sid;
186  }
187 
188  public function initIlias()
189  {
191  {
192  try
193  {
194  require_once("Services/Init/classes/class.ilInitialisation.php");
196  }
197  catch(Exception $e)
198  {
199  // #10608
200  // no need to do anything here, see __checkSession() below
201  }
202  }
203  }
204 
205 
206  function __initAuthenticationObject($a_auth_mode = AUTH_LOCAL)
207  {
208  include_once './Services/Authentication/classes/class.ilAuthFactory.php';
210  }
211 
212 
213  function __raiseError($a_message,$a_code)
214  {
215  #echo $a_message, $a_code;
216  switch($this->error_method)
217  {
218  case NUSOAP:
219  return new soap_fault($a_code,'',$a_message);
220  case PHP5:
221  return new SoapFault($a_code, $a_message);
222  }
223  }
224 
232  function getNIC($sid)
233  {
234  $this->initAuth($sid);
235  $this->initIlias();
236 
237  if(!$this->__checkSession($sid))
238  {
239  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
240  }
241 
242  global $rbacsystem, $rbacreview, $ilLog, $rbacadmin,$ilSetting, $ilClientIniFile;
243 
244  if (!is_object($ilClientIniFile)) {
245  return $this->__raiseError("Client ini is not initialized","Server");
246  }
247  $auth_modes = ilAuthUtils::_getActiveAuthModes();
248  $auth_mode_default = strtoupper(ilAuthUtils::_getAuthModeName(array_shift($auth_modes)));
249  $auth_mode_names = array();
250  foreach ($auth_modes as $mode) {
251  $auth_mode_names[] = strtoupper(ilAuthUtils::_getAuthModeName($mode));
252  }
253 
254  include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
255  include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php';
256 
257  // create advanced meta data record xml
258  $record_ids = array();
260  foreach($record_types as $type_info) {
261  $type = $type_info['obj_type'];
263  foreach ($records as $record){
264  $record_ids [] = $record->getRecordId();
265  }
266  }
267  $record_ids = array_unique($record_ids);
268  $advmwriter = new ilAdvancedMDRecordXMLWriter($record_ids);
269  $advmwriter->write();
270 
271  // create user defined fields record xml, simulate empty user records
272  include_once ("./Services/User/classes/class.ilUserXMLWriter.php");
273  $udfWriter = new ilUserXMLWriter();
274  $users = array();
275  $udfWriter->setObjects($users);
276  $udfWriter->start();
277 
278  // todo: get information from client id, read from ini file specificied
279  $client_details[] = array ("installation_id" => IL_INST_ID,
280  "installation_version" => ILIAS_VERSION,
281  "installation_url" => ILIAS_HTTP_PATH,
282  "installation_description" => $ilClientIniFile->readVariable("client","description"),
283  "installation_language_default" => $ilClientIniFile->readVariable("language","default"),
284  "installation_session_expire" => $ilClientIniFile->readVariable("session","expire"),
285  "installation_php_postmaxsize" => $this->return_bytes(ini_get("post_max_size")),
286  "authentication_methods" => join(",", $auth_mode_names),
287  "authentication_default_method" => $auth_mode_default,
288  "installation_udf_xml" => $udfWriter ->getXML(),
289  "installation_advmd_xml" => $advmwriter->xmlDumpMem(false)
290 
291  );
292 
293  // store into xml result set
294  include_once './webservice/soap/classes/class.ilXMLResultSet.php';
295 
296 
297  $xmlResult = new ilXMLResultSet();
298  $xmlResult->addArray($client_details, true);
299 
300  // create writer and return xml
301  include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
302  $xmlResultWriter = new ilXMLResultSetWriter($xmlResult);
303  $xmlResultWriter->start();
304  return $xmlResultWriter->getXML();
305  }
306 
311  public static function return_bytes($val) {
312  $val = trim($val);
313  $last = strtolower($val{strlen($val)-1});
314  switch($last) {
315  // The 'G' modifier is available since PHP 5.1.0
316  case 'g':
317  $val *= 1024;
318  case 'm':
319  $val *= 1024;
320  case 'k':
321  $val *= 1024;
322  }
323  return $val;
324  }
325 
326  public function isFault($object) {
327  switch($this->error_method)
328  {
329  case NUSOAP:
330  return $object instanceof soap_fault;
331  case PHP5:
332  return $object instanceof SoapFault;
333  }
334  return true;
335  }
336 
346  public function checkObjectAccess($ref_id, $expected_type, $permission, $returnObject = false) {
347  global $rbacsystem;
348  if(!is_numeric($ref_id))
349  {
350  return $this->__raiseError('No valid id given.',
351  'Client');
352  }
353  if (!ilObject::_exists($ref_id, true)) {
354  return $this->__raiseError('No object for id.',
355  'CLIENT_OBJECT_NOT_FOUND');
356  }
357 
359  return $this->__raiseError('Object is already trashed.',
360  'CLIENT_OBJECT_DELETED');
361  }
362 
364  if ((is_array($expected_type) && !in_array($type, $expected_type))
365  ||
366  (!is_array($expected_type) && $type != $expected_type)
367  )
368  {
369  return $this->__raiseError("Wrong type $type for id. Expected: ".(is_array($expected_type) ? join (",",$expected_type) : $expected_type), 'CLIENT_OBJECT_WRONG_TYPE');
370  }
371 
372  if (!$rbacsystem->checkAccess($permission, $ref_id, $type))
373  {
374  return $this->__raiseError('Missing permission $permission for type $type.', 'CLIENT_OBJECT_WRONG_PERMISSION');
375  }
376 
377  if ($returnObject) {
379  }
380 
381  return $type;
382  }
383 
384  public function getInstallationInfoXML()
385  {
386  include_once "Services/Context/classes/class.ilContext.php";
388 
389  require_once("Services/Init/classes/class.ilInitialisation.php");
391 
392  $clientdirs = glob(ILIAS_WEB_DIR."/*",GLOB_ONLYDIR);
393  require_once ("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
394  $writer = new ilSoapInstallationInfoXMLWriter ();
395  $writer->start();
396  if (is_array($clientdirs))
397  {
398  foreach ($clientdirs as $clientdir)
399  {
400  if (is_object($clientInfo= $this->getClientInfo($init, $clientdir)))
401  {
402  $writer->addClient ($clientInfo);
403  }
404  }
405  }
406  $writer->end();
407 
408  return $writer->getXML();
409  }
410 
411  public function getClientInfoXML($clientid)
412  {
413  include_once "Services/Context/classes/class.ilContext.php";
415 
416  require_once("Services/Init/classes/class.ilInitialisation.php");
418 
419  $clientdir = ILIAS_WEB_DIR."/".$clientid;
420  require_once ("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
421  $writer = new ilSoapInstallationInfoXMLWriter ();
422  $writer->setExportAdvancedMetaDataDefinitions (true);
423  $writer->setExportUDFDefinitions (true);
424  $writer->start();
425  if (is_object($client = $this->getClientInfo($init, $clientdir)))
426  {
427  $writer->addClient($client);
428  }
429  else
430  return $this->__raiseError("Client ID $clientid does not exist!", 'Client');
431  $writer->end();
432  return $writer->getXML();
433  }
434 
435  private function getClientInfo ($init, $client_dir)
436  {
437  global $ilDB;
438  $ini_file = "./".$client_dir."/client.ini.php";
439 
440  // get settings from ini file
441  require_once("./Services/Init/classes/class.ilIniFile.php");
442 
443  $ilClientIniFile = new ilIniFile($ini_file);
444  $ilClientIniFile->read();
445  if ($ilClientIniFile->ERROR != "")
446  {
447  return false;
448  }
449  $client_id = $ilClientIniFile->readVariable('client','name');
450  if ($ilClientIniFile->variableExists('client', 'expose'))
451  {
452  $client_expose = $ilClientIniFile->readVariable('client','expose');
453  if ($client_expose == "0")
454  return false;
455  }
456 
457  // build dsn of database connection and connect
458  require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
459  $ilDB = ilDBWrapperFactory::getWrapper($ilClientIniFile->readVariable("db","type"),
460  $ilClientIniFile->readVariable("db","inactive_mysqli"));
461  $ilDB->initFromIniFile($ilClientIniFile);
462  if ($ilDB->connect(true))
463  {
464  $GLOBALS['ilDB'] = $ilDB;
465 
466  require_once("Services/Administration/classes/class.ilSetting.php");
467  $settings = new ilSetting();
468  $GLOBALS["ilSetting"] = $settings;
469  // workaround to determine http path of client
470  define ("IL_INST_ID", $settings->get("inst_id",0));
471  $settings->access = $ilClientIniFile->readVariable("client", "access");
472  $settings->description = $ilClientIniFile->readVariable("client","description");
473  $settings->session = min((int) ini_get("session.gc_maxlifetime"), (int) $ilClientIniFile->readVariable("session","expire"));
474  $settings->language = $ilClientIniFile->readVariable("language","default");
475  $settings->clientid = basename($client_dir); //pathinfo($client_dir, PATHINFO_FILENAME);
476  $settings->default_show_users_online = $settings->get("show_users_online");
477  $settings->default_hits_per_page = $settings->get("hits_per_page");
478  $skin = $ilClientIniFile->readVariable("layout","skin");
479  $style = $ilClientIniFile->readVariable("layout","style");
480  $settings->default_skin_style = $skin.":".$style;
481  return $settings;
482  }
483  return null;
484  }
485 
486 
487 }
488 ?>
const IL_SOAPMODE_NUSOAP
Definition: server.php:15
ILIAS Setting Class.
$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
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
initErrorWriter()
Overwrite error handler.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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
static _getAuthModeName($a_auth_key)
__construct($use_nusoap=true)
Constructor.
$client
static initILIAS()
ilias initialisation
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
Create styles array
The data for the language used.
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.
$ref_id
Definition: sahs_server.php:39
global $ilSetting
Definition: privfeed.php:17
initAuth($sid)
Init authentication.
global $ilDB
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
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.
const IL_SOAPMODE
Definition: server.php:19