Issues (2128)

plugin/sepe/ws/service.php (1 issue)

Severity
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
ini_set('log_errors_max_len', 0);
6
ini_set('soap.wsdl_cache_enabled', '0');
7
ini_set('soap.wsdl_cache_ttl', '0');
8
9
require_once '../../../main/inc/global.inc.php';
10
require_once '../../../vendor/autoload.php';
11
12
ini_set("soap.wsdl_cache_enabled", 0);
13
$libpath = api_get_path(LIBRARY_PATH);
14
require_once api_get_path(SYS_PLUGIN_PATH).'sepe/ws/Sepe.php';
15
16
require_once $libpath.'nusoap/class.nusoap_base.php';
17
require_once api_get_path(SYS_PLUGIN_PATH).'sepe/src/wsse/soap-server-wsse.php';
18
19
$ns = api_get_path(WEB_PLUGIN_PATH)."sepe/ws/ProveedorCentroTFWS.wsdl";
20
$wsdl = api_get_path(SYS_PLUGIN_PATH)."sepe/ws/ProveedorCentroTFWS.wsdl";
21
$serviceUrl = api_get_path(WEB_PLUGIN_PATH).'sepe/ws/service.php';
22
23
/**
24
 * Class CustomServer.
25
 */
26
class CustomServer extends Zend\Soap\Server
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function __construct($wsdl = null, array $options = null)
32
    {
33
        parent::__construct($wsdl, $options);
34
35
        // Response of handle will always be returned
36
        $this->setReturnResponse(true);
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
48
        $response = $this->addNamespaceToTag($response, 'RESPUESTA_DATOS_CENTRO', 'sal');
49
        $response = $this->addNamespaceToTag($response, 'RESPUESTA_OBT_LISTA_ACCIONES', 'sal');
50
        $response = $this->addNamespaceToTag($response, 'RESPUESTA_ELIMINAR_ACCION', 'sal');
51
        $response = $this->addNamespaceToTag($response, 'RESPUESTA_OBT_ACCION', 'sal');
52
53
        $response = $this->addNamespaceToTag($response, 'ACCION_FORMATIVA', 'ent');
54
        $response = $this->addNamespaceToTag($response, 'ID_ACCION', 'ent');
55
        $response = $this->addNamespaceToTag($response, 'DATOS_IDENTIFICATIVOS', 'ent');
56
57
        // Dentro de ACCION_FORMATIVA no hay ent:ID_ACCION
58
        $response = str_replace(
59
            '<ent:ACCION_FORMATIVA><ent:ID_ACCION>',
60
            '<ent:ACCION_FORMATIVA><ID_ACCION>',
61
            $response
62
        );
63
64
        $response = str_replace(
65
            '</ent:ID_ACCION><SITUACION>',
66
            '</ID_ACCION><SITUACION>',
67
            $response
68
        );
69
70
        //$response = file_get_contents('/tmp/log4.xml');
71
        header('Content-Length:'.strlen($response));
72
        echo $response;
73
        exit;
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
74
    }
75
76
    private function addNamespaceToTag($response, $tag, $namespace)
77
    {
78
        return str_replace(
79
            $tag,
80
            $namespace.":".$tag,
81
            $response
82
        );
83
    }
84
}
85
86
function authenticate($WSUser, $WSKey)
87
{
88
    $tUser = Database::get_main_table(TABLE_MAIN_USER);
89
    $tApi = Database::get_main_table(TABLE_MAIN_USER_API_KEY);
90
    $login = Database::escape_string($WSUser);
91
    $WSKey = Database::escape_string($WSKey);
92
93
    $sql = "SELECT u.user_id, u.status FROM $tUser u, $tApi a
94
            WHERE
95
                u.username='".$login."' AND
96
                u.user_id = a.user_id AND
97
                a.api_service = 'dokeos' AND
98
                a.api_key='".$WSKey."'";
99
    $result = Database::query($sql);
100
101
    if (Database::num_rows($result) > 0) {
102
        $row = Database::fetch_row($result);
103
        if ($row[1] == '4') {
104
            return true;
105
        }
106
    }
107
108
    return false;
109
}
110
111
$doc = new DOMDocument();
112
$post = file_get_contents('php://input');
113
if (!empty($post)) {
114
    $doc->loadXML($post);
115
116
    $WSUser = $doc->getElementsByTagName('Username')->item(0)->nodeValue;
117
    $WSKey = $doc->getElementsByTagName('Password')->item(0)->nodeValue;
118
119
    $s = new WSSESoapServer($doc);
120
    if (!empty($WSUser) && !empty($WSKey)) {
121
        if (authenticate($WSUser, $WSKey)) {
122
            // pointing to the current file here
123
            $options = [
124
                'soap_version' => SOAP_1_1,
125
            ];
126
            $soap = new CustomServer($wsdl, $options);
127
            $soap->setObject(new Sepe());
128
129
            if ($s->process()) {
130
                $xml = $s->saveXML();
131
                //header('Content-type: application/xml');
132
                $soap->handle($xml);
133
                exit;
134
            } else {
135
                error_log('not processed');
136
            }
137
        } else {
138
            error_log('Claves incorrectas');
139
        }
140
    } else {
141
        error_log('not processed');
142
    }
143
} else {
144
    $contents = file_get_contents($wsdl);
145
    header('Content-type: application/xml');
146
    echo $contents;
147
    exit;
148
}
149
exit;
150