ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapAdministration.php
Go to the documentation of this file.
1 <?php
2  /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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  /*
44  * object which handles php's authentication
45  * @var object
46  */
47  var $sauth = null;
48 
49  /*
50  * Defines type of error handling (PHP5 || NUSOAP)
51  * @var object
52  */
53  var $error_method = null;
54 
55 
56  function ilSoapAdministration($use_nusoap = true)
57  {
58  define('USER_FOLDER_ID',7);
59  define('NUSOAP',1);
60  define('PHP5',2);
61 
62  if(IL_SOAPMODE == IL_SOAPMODE_NUSOAP)
63  {
64  $this->error_method = NUSOAP;
65  }
66  else
67  {
68  $this->error_method = PHP5;
69  }
70  #echo ("SOAP: using soap mode ".IL_SOAPMODE == IL_SOAPMODE_NUSOAP ? "NUSOAP": "PHP5");
72 
73  }
74 
75  // PROTECTED
76  function __checkSession($sid)
77  {
78  //return true;
79  list($sid,$client) = $this->__explodeSid($sid);
80  $this->sauth->setClient($client);
81  $this->sauth->setSid($sid);
82 
83  if(!$this->sauth->validateSession())
84  {
85  return false;
86  }
87  return true;
88  }
89 
97  public function initErrorWriter()
98  {
99  include_once('classes/class.ilErrorHandling.php');
100 
101  set_error_handler(array('ilErrorHandling','_ilErrorWriter'),E_ALL);
102  }
103 
104 
105  function __explodeSid($sid)
106  {
107  $exploded = explode('::',$sid);
108 
109  return is_array($exploded) ? $exploded : array('sid' => '','client' => '');
110  }
111 
112 
113  function __setMessage($a_str)
114  {
115  $this->message = $a_str;
116  }
117  function __getMessage()
118  {
119  return $this->message;
120  }
121  function __appendMessage($a_str)
122  {
123  $this->message .= isset($this->message) ? ' ' : '';
124  $this->message .= $a_str;
125  }
126 
127 
128  function __initAuthenticationObject($a_auth_mode = AUTH_LOCAL)
129  {
130  switch($a_auth_mode)
131  {
132  case AUTH_CAS:
133  include_once './webservice/soap/classes/class.ilSoapAuthenticationCAS.php';
134  return $this->sauth = new ilSoapAuthenticationCAS();
135  case AUTH_LDAP:
136  include_once './webservice/soap/classes/class.ilSoapAuthenticationLDAP.php';
137  return $this->sauth = new ilSoapAuthenticationLDAP();
138 
139  default:
140  include_once './webservice/soap/classes/class.ilSoapAuthentication.php';
141  return $this->sauth = new ilSoapAuthentication();
142  }
143  }
144 
145 
146  function __raiseError($a_message,$a_code)
147  {
148  #echo $a_message, $a_code;
149  switch($this->error_method)
150  {
151  case NUSOAP:
152  return new soap_fault($a_code,'',$a_message);
153  case PHP5:
154  return new SoapFault($a_code, $a_message);
155  }
156  }
157 
165  function getNIC($sid) {
166  if(!$this->__checkSession($sid))
167  {
168  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
169  }
170  // Include main header
171 
172  include_once './include/inc.header.php';
173  global $rbacsystem, $rbacreview, $ilLog, $rbacadmin,$ilSetting, $ilClientIniFile;
174 
175  if (!is_object($ilClientIniFile)) {
176  return $this->__raiseError("Client ini is not initialized","Server");
177  }
178 
179  $auth_modes = ilAuthUtils::_getActiveAuthModes();
180  $auth_mode_default = strtoupper(ilAuthUtils::_getAuthModeName(array_shift($auth_modes)));
181  $auth_mode_names = array();
182  foreach ($auth_modes as $mode) {
183  $auth_mode_names[] = strtoupper(ilAuthUtils::_getAuthModeName($mode));
184  }
185 
186  include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
187  include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php';
188 
189  // create advanced meta data record xml
190  $record_ids = array();
192  foreach($record_types as $type) {
194  foreach ($records as $record){
195  $record_ids [] = $record->getRecordId();
196  }
197  }
198  $record_ids = array_unique($record_ids);
199  $advmwriter = new ilAdvancedMDRecordXMLWriter($record_ids);
200  $advmwriter->write();
201 
202  // create user defined fields record xml, simulate empty user records
203  include_once ("./Services/User/classes/class.ilUserXMLWriter.php");
204  $udfWriter = new ilUserXMLWriter();
205  $users = array();
206  $udfWriter->setObjects($users);
207  $udfWriter->start();
208 
209  // todo: get information from client id, read from ini file specificied
210  $client_details[] = array ("installation_id" => IL_INST_ID,
211  "installation_version" => ILIAS_VERSION,
212  "installation_url" => ILIAS_HTTP_PATH,
213  "installation_description" => $ilClientIniFile->readVariable("client","description"),
214  "installation_language_default" => $ilClientIniFile->readVariable("language","default"),
215  "installation_session_expire" => $ilClientIniFile->readVariable("session","expire"),
216  "installation_php_postmaxsize" => $this->return_bytes(ini_get("post_max_size")),
217  "authentication_methods" => join(",", $auth_mode_names),
218  "authentication_default_method" => $auth_mode_default,
219  "installation_udf_xml" => $udfWriter ->getXML(),
220  "installation_advmd_xml" => $advmwriter->xmlDumpMem(false)
221 
222  );
223 
224  // store into xml result set
225  include_once './webservice/soap/classes/class.ilXMLResultSet.php';
226 
227 
228  $xmlResult = new ilXMLResultSet();
229  $xmlResult->addArray($client_details, true);
230 
231  // create writer and return xml
232  include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
233  $xmlResultWriter = new ilXMLResultSetWriter($xmlResult);
234  $xmlResultWriter->start();
235  return $xmlResultWriter->getXML();
236  }
237 
242  public static function return_bytes($val) {
243  $val = trim($val);
244  $last = strtolower($val{strlen($val)-1});
245  switch($last) {
246  // The 'G' modifier is available since PHP 5.1.0
247  case 'g':
248  $val *= 1024;
249  case 'm':
250  $val *= 1024;
251  case 'k':
252  $val *= 1024;
253  }
254  return $val;
255  }
256 
257  public function isFault($object) {
258  switch($this->error_method)
259  {
260  case NUSOAP:
261  return $object instanceof soap_fault;
262  case PHP5:
263  return $object instanceof SoapFault;
264  }
265  return true;
266  }
267 
277  public function checkObjectAccess($ref_id, $expected_type, $permission, $returnObject = false) {
278  global $rbacsystem;
279  if(!is_numeric($ref_id))
280  {
281  return $this->__raiseError('No valid id given.',
282  'Client');
283  }
284  if (!ilObject::_exists($ref_id, true)) {
285  return $this->__raiseError('No object for id.',
286  'CLIENT_OBJECT_NOT_FOUND');
287  }
288 
290  return $this->__raiseError('Object is already trashed.',
291  'CLIENT_OBJECT_DELETED');
292  }
293 
295  if ((is_array($expected_type) && !in_array($type, $expected_type))
296  ||
297  (!is_array($expected_type) && $type != $expected_type)
298  )
299  {
300  return $this->__raiseError("Wrong type $type for id. Expected: ".(is_array($expected_type) ? join (",",$expected_type) : $expected_type), 'CLIENT_OBJECT_WRONG_TYPE');
301  }
302 
303  if (!$rbacsystem->checkAccess($permission, $ref_id, $type))
304  {
305  return $this->__raiseError('Missing permission $permission for type $type.', 'CLIENT_OBJECT_WRONG_PERMISSION');
306  }
307 
308  if ($returnObject) {
310  }
311 
312  return $type;
313  }
314 
315  public function getInstallationInfoXML()
316  {
317  require_once("Services/Init/classes/class.ilInitialisation.php");
318 
319  $init = new ilInitialisation();
320  $init->requireCommonIncludes();
321  $init->initIliasIniFile();
322 
323  $ilias = & new ILIAS();
324  $GLOBALS['ilias'] =& $ilias;
325 
326 
327  $settings = array();
328  $clientdirs = glob(ILIAS_WEB_DIR."/*",GLOB_ONLYDIR);
329  require_once ("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
330  $writer = new ilSoapInstallationInfoXMLWriter ();
331  $writer->start();
332  if (is_array($clientdirs))
333  {
334  foreach ($clientdirs as $clientdir)
335  {
336  if (is_object($clientInfo= $this->getClientInfo($init, $clientdir)))
337  {
338  $writer->addClient ($clientInfo);
339  }
340  }
341  }
342  $writer->end();
343 
344  return $writer->getXML();
345  }
346 
347  public function getClientInfoXML($clientid)
348  {
349  require_once("Services/Init/classes/class.ilInitialisation.php");
350 
351  $init = new ilInitialisation();
352  $init->requireCommonIncludes();
353  $init->initIliasIniFile();
354 
355  $ilias = & new ILIAS();
356  $GLOBALS['ilias'] =& $ilias;
357 
358 
359  $settings = array();
360  $clientdir = ILIAS_WEB_DIR."/".$clientid;
361  require_once ("webservice/soap/classes/class.ilSoapInstallationInfoXMLWriter.php");
362  $writer = new ilSoapInstallationInfoXMLWriter ();
363  $writer->setExportAdvancedMetaDataDefinitions (true);
364  $writer->setExportUDFDefinitions (true);
365  $writer->start();
366  if (is_object($client = $this->getClientInfo($init, $clientdir)))
367  {
368  $writer->addClient($client);
369  }
370  else
371  return $this->__raiseError("Client ID $clientid does not exist!", 'Client');
372  $writer->end();
373  return $writer->getXML();
374  }
375 
376  private function getClientInfo ($init, $client_dir)
377  {
378  global $ilDB;
379  $ini_file = "./".$client_dir."/client.ini.php";
380 
381  // get settings from ini file
382  require_once("classes/class.ilIniFile.php");
383 
384  $ilClientIniFile = new ilIniFile($ini_file);
385  $ilClientIniFile->read();
386  if ($ilClientIniFile->ERROR != "")
387  {
388  return false;
389  }
390  $client_id = $ilClientIniFile->readVariable('client','name');
391  if ($ilClientIniFile->variableExists('client', 'expose'))
392  {
393  $client_expose = $ilClientIniFile->readVariable('client','expose');
394  if ($client_expose == "0")
395  return false;
396  }
397 
398  // build dsn of database connection and connect
399  $dsn = $ilClientIniFile->readVariable("db","type")."://".$ilClientIniFile->readVariable("db", "user").
400  ":".$ilClientIniFile->readVariable("db", "pass").
401  "@".$ilClientIniFile->readVariable("db", "host").
402  "/".$ilClientIniFile->readVariable("db", "name");
403 
404 
405  require_once "classes/class.ilDBx.php";
406  $ilDB = new ilDBx($dsn);
407  $GLOBALS['ilDB'] = $ilDB;
408 
409  require_once("Services/Administration/classes/class.ilSetting.php");
410  $settings = new ilSetting();
411  $GLOBALS["ilSetting"] = $settings;
412  // workaround to determine http path of client
413  define ("IL_INST_ID", $settings->get("inst_id",0));
414  $settings->access = $ilClientIniFile->readVariable("client", "access");
415  $settings->description = $ilClientIniFile->readVariable("client","description");
416  $settings->session = min((int) ini_get("session.gc_maxlifetime"), (int) $ilClientIniFile->readVariable("session","expire"));
417  $settings->language = $ilClientIniFile->readVariable("language","default");
418  $settings->clientid = basename($client_dir); //pathinfo($client_dir, PATHINFO_FILENAME);
419  $settings->default_show_users_online = $settings->get("show_users_online");
420  $settings->default_hits_per_page = $settings->get("hits_per_page");
421  $skin = $ilClientIniFile->readVariable("layout","skin");
422  $style = $ilClientIniFile->readVariable("layout","style");
423  $settings->default_skin_style = $skin.":".$style;
424  return $settings;
425  }
426 
427 
428 }
429 ?>