service.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.webservices
  5. */
  6. ini_set('log_errors_max_len', 0);
  7. ini_set('soap.wsdl_cache_enabled', '0');
  8. ini_set('soap.wsdl_cache_ttl', '0');
  9. require_once '../../../main/inc/global.inc.php';
  10. require_once '../../../vendor/autoload.php';
  11. ini_set("soap.wsdl_cache_enabled", 0);
  12. $libpath = api_get_path(LIBRARY_PATH);
  13. require_once api_get_path(SYS_PLUGIN_PATH).'sepe/ws/Sepe.php';
  14. require_once $libpath.'nusoap/class.nusoap_base.php';
  15. require_once api_get_path(SYS_PLUGIN_PATH).'sepe/src/wsse/soap-server-wsse.php';
  16. //require_once api_get_path(SYS_PLUGIN_PATH).'sepe/src/wsse/soap-wsse.php';
  17. $ns = api_get_path(WEB_PLUGIN_PATH)."sepe/ws/ProveedorCentroTFWS.wsdl";
  18. $wsdl = api_get_path(SYS_PLUGIN_PATH)."sepe/ws/ProveedorCentroTFWS.wsdl";
  19. $serviceUrl = api_get_path(WEB_PLUGIN_PATH).'sepe/ws/service.php';
  20. class CustomServer extends Zend\Soap\Server
  21. {
  22. /**
  23. * @inheritdoc
  24. **/
  25. public function __construct($wsdl = null, array $options = null)
  26. {
  27. parent::__construct($wsdl, $options);
  28. // Response of handle will always be returned
  29. $this->setReturnResponse(true);
  30. }
  31. private function addNamespaceToTag($response, $tag, $namespace)
  32. {
  33. return str_replace(
  34. $tag,
  35. $namespace.":".$tag,
  36. $response
  37. );
  38. }
  39. public function handle($request = null)
  40. {
  41. $response = parent::handle($request);
  42. $response = str_replace(
  43. 'xmlns:ns1="http://impl.ws.application.proveedorcentro.meyss.spee.es"',
  44. 'xmlns:ns1="http://impl.ws.application.proveedorcentro.meyss.spee.es" xmlns:impl="http://impl.ws.application.proveedorcentro.meyss.spee.es" xmlns:sal="http://salida.bean.domain.common.proveedorcentro.meyss.spee.es" xmlns:ent="http://entsal.bean.domain.common.proveedorcentro.meyss.spee.es" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"',
  45. $response
  46. );
  47. $response = $this->addNamespaceToTag($response, 'RESPUESTA_DATOS_CENTRO', 'sal');
  48. $response = $this->addNamespaceToTag($response, 'RESPUESTA_OBT_LISTA_ACCIONES', 'sal');
  49. $response = $this->addNamespaceToTag($response, 'RESPUESTA_ELIMINAR_ACCION', 'sal');
  50. $response = $this->addNamespaceToTag($response, 'RESPUESTA_OBT_ACCION', 'sal');
  51. $response = $this->addNamespaceToTag($response, 'ACCION_FORMATIVA', 'ent');
  52. $response = $this->addNamespaceToTag($response, 'ID_ACCION', 'ent');
  53. $response = $this->addNamespaceToTag($response, 'DATOS_IDENTIFICATIVOS', 'ent');
  54. // Dentro de ACCION_FORMATIVA no hay ent:ID_ACCION
  55. $response = str_replace(
  56. '<ent:ACCION_FORMATIVA><ent:ID_ACCION>',
  57. '<ent:ACCION_FORMATIVA><ID_ACCION>',
  58. $response
  59. );
  60. $response = str_replace(
  61. '</ent:ID_ACCION><SITUACION>',
  62. '</ID_ACCION><SITUACION>',
  63. $response
  64. );
  65. //$response = file_get_contents('/tmp/log4.xml');
  66. header('Content-Length:'.strlen($response));
  67. echo $response;
  68. exit;
  69. }
  70. }
  71. function authenticate($WSUser,$WSKey)
  72. {
  73. $tUser = Database::get_main_table(TABLE_MAIN_USER);
  74. $tApi = Database::get_main_table(TABLE_MAIN_USER_API_KEY);
  75. $login = Database::escape_string($WSUser);
  76. $sql = "SELECT u.user_id, u.status FROM $tUser u, $tApi a WHERE u.username='".$login."' and u.user_id = a.user_id AND a.api_service = 'dokeos' and a.api_key='".$WSKey."'";
  77. $result = Database::query($sql);
  78. if (Database::num_rows($result) > 0) {
  79. $row = Database::fetch_row($result);
  80. if ($row[1] == '4') { //UserManager::is_admin($row[0])) {
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. } else {
  86. return false;
  87. }
  88. }
  89. $doc = new DOMDocument();
  90. $post = file_get_contents('php://input');
  91. if (!empty($post)) {
  92. $doc->loadXML($post);
  93. $WSUser = $doc->getElementsByTagName('Username')->item(0)->nodeValue;
  94. $WSKey = $doc->getElementsByTagName('Password')->item(0)->nodeValue;
  95. $s = new WSSESoapServer($doc);
  96. if (!empty($WSUser) && !empty($WSKey)) {
  97. if (authenticate($WSUser,$WSKey)) {
  98. // pointing to the current file here
  99. $options = array(
  100. 'soap_version' => SOAP_1_1
  101. );
  102. $soap = new CustomServer($wsdl, $options);
  103. $soap->setObject(new Sepe());
  104. if ($s->process()) {
  105. $xml = $s->saveXML();
  106. //header('Content-type: application/xml');
  107. $soap->handle($xml);
  108. exit;
  109. } else {
  110. error_log('not processed');
  111. }
  112. } else {
  113. error_log('Claves incorrectas');
  114. }
  115. } else {
  116. error_log('not processed');
  117. }
  118. } else {
  119. $contents = file_get_contents($wsdl);
  120. header('Content-type: application/xml');
  121. echo $contents;
  122. exit;
  123. }
  124. exit;