forked from ornfelt/azerothcore_lua_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoap.js
More file actions
53 lines (51 loc) · 1.43 KB
/
soap.js
File metadata and controls
53 lines (51 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const config = require('./config.js')
function Soap(command){
var http = require('http')
return new Promise((resolve, reject)=>{
const req = http.request({
port: config.soapPort,
method: "POST",
hostname: config.soapHostname,
auth: config.soapAuth,
headers: { 'Content-Type': 'application/xml' }
}, res=>{
res.on('data', async d => {
xml2js = require('xml2js');
const xml = await xml2js.parseStringPromise(d.toString());
const body = xml["SOAP-ENV:Envelope"]["SOAP-ENV:Body"][0];
const fault = body["SOAP-ENV:Fault"];
if(fault){
resolve({
faultCode : fault[0]["faultcode"][0],
faultString: fault[0]["faultstring"][0],
});
return;
}
const response = body["ns1:executeCommandResponse"];
if(response){
resolve({
result: response[0]["result"][0]
});
return;
}
console.log(d.toString());
})
});
req.write(
'<SOAP-ENV:Envelope' +
' xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"' +
' xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"' +
' xmlns:xsd="http://www.w3.org/1999/XMLSchema"' +
' xmlns:ns1="urn:AC">' +
'<SOAP-ENV:Body>' +
'<ns1:executeCommand>' +
'<command>'+command+'</command>' +
'</ns1:executeCommand>' +
'</SOAP-ENV:Body>' +
'</SOAP-ENV:Envelope>'
);
req.end();
});
}
module.exports = { Soap };