soapserver.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Handling of SOAP queries
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. // Important note: if some required includes are missing, this might result
  25. // in the error "looks like we got no XML document"...
  26. require_once('../approot.inc.php');
  27. require_once(APPROOT.'/application/application.inc.php');
  28. require_once(APPROOT.'/application/startup.inc.php');
  29. // this file is generated dynamically with location = here
  30. $sWsdlUri = utils::GetAbsoluteUrlAppRoot().'webservices/itop.wsdl.php';
  31. if (isset($_REQUEST['service_category']) && (!empty($_REQUEST['service_category'])))
  32. {
  33. $sWsdlUri .= "?service_category=".$_REQUEST['service_category'];
  34. }
  35. ini_set("soap.wsdl_cache_enabled","0");
  36. $aSOAPMapping = SOAPMapping::GetMapping();
  37. $oSoapServer = new SoapServer
  38. (
  39. $sWsdlUri,
  40. array(
  41. 'classmap' => $aSOAPMapping
  42. )
  43. );
  44. // $oSoapServer->setPersistence(SOAP_PERSISTENCE_SESSION);
  45. if (isset($_REQUEST['service_category']) && (!empty($_REQUEST['service_category'])))
  46. {
  47. $sServiceClass = $_REQUEST['service_category'];
  48. if (!class_exists($sServiceClass))
  49. {
  50. // not a valid class name (not a PHP class at all)
  51. throw new SoapFault("iTop SOAP server", "Invalid argument service_category: '$sServiceClass' is not a PHP class");
  52. }
  53. elseif (!is_subclass_of($sServiceClass, 'WebServicesBase'))
  54. {
  55. // not a valid class name (not deriving from WebServicesBase)
  56. throw new SoapFault("iTop SOAP server", "Invalid argument service_category: '$sServiceClass' is not derived from WebServicesBase");
  57. }
  58. else
  59. {
  60. $oSoapServer->setClass($sServiceClass, null);
  61. }
  62. }
  63. else
  64. {
  65. $oSoapServer->setClass('BasicServices', null);
  66. }
  67. if ($_SERVER["REQUEST_METHOD"] == "POST")
  68. {
  69. CMDBObject::SetTrackOrigin('webservice-soap');
  70. $oSoapServer->handle();
  71. }
  72. else
  73. {
  74. echo "This SOAP server can handle the following functions: ";
  75. $aFunctions = $oSoapServer->getFunctions();
  76. echo "<ul>\n";
  77. foreach($aFunctions as $sFunc)
  78. {
  79. if ($sFunc == 'GetWSDLContents') continue;
  80. echo "<li>$sFunc</li>\n";
  81. }
  82. echo "</ul>\n";
  83. echo "<p>Here the <a href=\"$sWsdlUri\">WSDL file</a><p>";
  84. echo "You may also want to try the following service categories: ";
  85. echo "<ul>\n";
  86. foreach(get_declared_classes() as $sPHPClass)
  87. {
  88. if (is_subclass_of($sPHPClass, 'WebServicesBase'))
  89. {
  90. $sServiceCategory = $sPHPClass;
  91. $sSoapServerUri = utils::GetAbsoluteUrlAppRoot().'webservices/soapserver.php';
  92. $sSoapServerUri .= "?service_category=$sServiceCategory";
  93. echo "<li><a href=\"$sSoapServerUri\">$sServiceCategory</a></li>\n";
  94. }
  95. }
  96. echo "</ul>\n";
  97. }
  98. ?>