soapserver.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/itop.wsdl.php';
  31. if (isset($_REQUEST['service_category']) && (!empty($_REQUEST['service_category'])))
  32. {
  33. $sWsdlUri .= "soapserver.php?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. $oSoapServer->handle();
  70. }
  71. else
  72. {
  73. echo "This SOAP server can handle the following functions: ";
  74. $aFunctions = $oSoapServer->getFunctions();
  75. echo "<ul>\n";
  76. foreach($aFunctions as $sFunc)
  77. {
  78. if ($sFunc == 'GetWSDLContents') continue;
  79. echo "<li>$sFunc</li>\n";
  80. }
  81. echo "</ul>\n";
  82. echo "<p>Here the <a href=\"$sWsdlUri\">WSDL file</a><p>";
  83. echo "You may also want to try the following service categories: ";
  84. echo "<ul>\n";
  85. foreach(get_declared_classes() as $sPHPClass)
  86. {
  87. if (is_subclass_of($sPHPClass, 'WebServicesBase'))
  88. {
  89. $sServiceCategory = $sPHPClass;
  90. $sSoapServerUri = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../webservices/soapserver.php';
  91. $sSoapServerUri .= "?service_category=$sServiceCategory";
  92. echo "<li><a href=\"$sSoapServerUri\">$sServiceCategory</a></li>\n";
  93. }
  94. }
  95. echo "</ul>\n";
  96. }
  97. ?>