@seydx/tr064
Advanced tools
Comparing version 0.4.1-9 to 0.4.2-0
{ | ||
"name": "@seydx/tr064", | ||
"version": "0.4.1-9", | ||
"version": "0.4.2-0", | ||
"author": "Nicolai Schmid <hey@schmid.uno>", | ||
@@ -5,0 +5,0 @@ "description": "TR-064 - UPnP/IGD for node.js", |
@@ -37,27 +37,2 @@ const async = require('async'); | ||
startTransaction(cb){ | ||
var that = this; | ||
var sessionID = this.uuid(); | ||
this._startTransaction(sessionID, function(err) { | ||
if (!err) { | ||
that._isTransaction = true; | ||
cb(null, that); | ||
} else { | ||
cb(err, null); | ||
} | ||
}); | ||
} | ||
stopTransaction(cb){ | ||
var that = this; | ||
this._stopTransaction(function(err) { | ||
if (!err) { | ||
that._isTransaction = false; | ||
cb(null, that); | ||
} else { | ||
cb(err, null); | ||
} | ||
}); | ||
} | ||
startEncryptedCommunication(){ | ||
@@ -152,31 +127,4 @@ const self=this; | ||
} | ||
_startTransaction(sessionID, cb){ | ||
var devConfig = this.services['urn:dslforum-org:service:DeviceConfig:1']; | ||
devConfig.actions.ConfigurationStarted({ NewSessionID: sessionID }, function(err) { | ||
if (!err) { | ||
cb(null); | ||
} else { | ||
cb(new Error('Transactions are not supported for this device.')); | ||
} | ||
}); | ||
} | ||
_stopTransaction(cb){ | ||
var devConfig = this.services['urn:dslforum-org:service:DeviceConfig:1']; | ||
devConfig.actions.ConfigurationFinished(function(err) { | ||
if (!err) { | ||
cb(null); | ||
} else { | ||
cb(new Error('Transactions are not supported for this device.')); | ||
} | ||
}); | ||
} | ||
uuid(a){ | ||
const self = this; | ||
return a ? ( a ^ ((Math.random() * 16) >> (a / 4))).toString(16):([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g,self.uuid); | ||
} | ||
} | ||
exports.Device = Device; |
@@ -17,2 +17,3 @@ var parseString = require('xml2js').parseString; | ||
this.timeout=config.timeout*1000||5000; | ||
this.waitForAuth = {}; | ||
this._parseSCPD(this); | ||
@@ -138,7 +139,19 @@ } | ||
const self = this; | ||
var head = ''; | ||
if (device._auth.uid) { | ||
if(!Object.keys(self.waitForAuth).length|| | ||
(serviceType == self.waitForAuth.serviceType&& | ||
action == self.waitForAuth.action&& | ||
vars == self.waitForAuth.vars&& | ||
url == self.waitForAuth.url)&& | ||
inArguments == self.waitForAuth.inArguments&& | ||
outArguments == self.waitForAuth.outArguments){ | ||
var head = ''; | ||
if (device._auth.uid) { | ||
// Content Level Authentication | ||
if (device._auth.auth) { | ||
head = '<s:Header>' + | ||
if (device._auth.auth) { | ||
self.waitForAuth = {}; | ||
head = '<s:Header>' + | ||
'<h:ClientAuth xmlns:h="http://soap-authentication.org/digest/2001/10/"' + | ||
@@ -160,5 +173,15 @@ 's:mustUnderstand="1">' + | ||
'</s:Header>'; | ||
} else { | ||
// First Auth | ||
head = ' <s:Header>' + | ||
} else { | ||
self.waitForAuth = { | ||
serviceType:serviceType, | ||
action:action, | ||
vars:vars, | ||
url:url, | ||
inArguments:inArguments, | ||
outArguments:outArguments | ||
}; | ||
// First Auth | ||
head = ' <s:Header>' + | ||
'<h:InitChallenge xmlns:h="http://soap-authentication.org/digest/2001/10/"' + | ||
@@ -174,6 +197,6 @@ 's:mustUnderstand="1">' + | ||
'</s:Header>'; | ||
} | ||
} | ||
} | ||
var body = '<?xml version="1.0" encoding="utf-8"?>' + | ||
var body = '<?xml version="1.0" encoding="utf-8"?>' + | ||
'<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s=" http://schemas.xmlsoap.org/soap/envelope/">' + | ||
@@ -188,95 +211,125 @@ head + | ||
for (var i in vars) { | ||
body += '<' + vars[i].name + '>'; | ||
body += vars[i].value; | ||
body += '</' + vars[i].name + '>'; | ||
} | ||
for (var i in vars) { | ||
body += '<' + vars[i].name + '>'; | ||
body += vars[i].value; | ||
body += '</' + vars[i].name + '>'; | ||
} | ||
body = body + '</u:' + action + '>' + '</s:Body>' + '</s:Envelope>'; | ||
body = body + '</u:' + action + '>' + '</s:Body>' + '</s:Envelope>'; | ||
var port = 0, | ||
proto = '', | ||
agentOptions = null; | ||
if (device._sslPort) { | ||
port = device._sslPort; | ||
proto = 'https://'; | ||
if (device._ca) { | ||
agentOptions = { | ||
ca: device._ca, | ||
}; | ||
var port = 0, | ||
proto = '', | ||
agentOptions = null; | ||
if (device._sslPort) { | ||
port = device._sslPort; | ||
proto = 'https://'; | ||
if (device._ca) { | ||
agentOptions = { | ||
ca: device._ca, | ||
}; | ||
} else { | ||
agentOptions = { | ||
rejectUnauthorized: false, | ||
}; // Allow selfsignd Certs | ||
} | ||
} else { | ||
agentOptions = { | ||
rejectUnauthorized: false, | ||
}; // Allow selfsignd Certs | ||
proto = 'http://'; | ||
port = device.meta.port; | ||
} | ||
} else { | ||
proto = 'http://'; | ||
port = device.meta.port; | ||
} | ||
var uri = proto + device.meta.host + ':' + port + url; | ||
var that = this; | ||
var uri = proto + device.meta.host + ':' + port + url; | ||
var that = this; | ||
request( | ||
{ | ||
method: 'POST', | ||
uri: uri, | ||
agentOptions: agentOptions, | ||
headers: { | ||
SoapAction: serviceType + '#' + action, | ||
'Content-Type': 'text/xml; charset="utf-8"', | ||
request( | ||
{ | ||
method: 'POST', | ||
uri: uri, | ||
agentOptions: agentOptions, | ||
headers: { | ||
SoapAction: serviceType + '#' + action, | ||
'Content-Type': 'text/xml; charset="utf-8"', | ||
}, | ||
body: body, | ||
timeout: self.config.timeout, | ||
}, | ||
body: body, | ||
timeout: self.config.timeout, | ||
}, | ||
function(error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
parseString( | ||
body, | ||
{ | ||
explicitArray: false, | ||
}, | ||
function(err, result) { | ||
var challange = false; | ||
var res = {}; | ||
var env = result['s:Envelope']; | ||
if (env['s:Header']) { | ||
var header = env['s:Header']; | ||
if (header['h:Challenge']) { | ||
var ch = header['h:Challenge']; | ||
challange = true; | ||
if (self.logAttempts.length) { | ||
function(error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
parseString( | ||
body, | ||
{ | ||
explicitArray: false, | ||
}, | ||
function(err, result) { | ||
var challange = false; | ||
var res = {}; | ||
var env = result['s:Envelope']; | ||
if (env['s:Header']) { | ||
var header = env['s:Header']; | ||
if (header['h:Challenge']) { | ||
var ch = header['h:Challenge']; | ||
challange = true; | ||
if (self.logAttempts.length) { | ||
for (const i in self.logAttempts) { | ||
if ((self.logAttempts[i].service == serviceType && self.logAttempts[i].action == action)) { | ||
if (self.logAttempts[i].attempts >= 1) { | ||
error = new Error('Credentials incorrect'); | ||
} else { | ||
self.logAttempts[i].attempts += 1; | ||
device._auth.des = serviceType; | ||
device._auth.sn = ch.Nonce; | ||
device._auth.realm = ch.Realm; | ||
device._auth.auth = device._calcAuthDigest( | ||
device._auth.uid, | ||
device._auth.pwd, | ||
device._auth.realm, | ||
device._auth.sn | ||
); | ||
device._auth.chCount++; | ||
that._sendSOAPActionRequest( | ||
device, | ||
url, | ||
serviceType, | ||
action, | ||
inArguments, | ||
outArguments, | ||
vars, | ||
callback | ||
); | ||
return; | ||
} | ||
} | ||
} | ||
} else { | ||
self.logAttempts.push({ service: serviceType, action: action, attempts: 1 }); | ||
device._auth.sn = ch.Nonce; | ||
device._auth.realm = ch.Realm; | ||
device._auth.auth = device._calcAuthDigest( | ||
device._auth.uid, | ||
device._auth.pwd, | ||
device._auth.realm, | ||
device._auth.sn | ||
); | ||
device._auth.chCount++; | ||
// Repeat request. | ||
that._sendSOAPActionRequest( | ||
device, | ||
url, | ||
serviceType, | ||
action, | ||
inArguments, | ||
outArguments, | ||
vars, | ||
callback | ||
); | ||
return; | ||
} | ||
} else if (header['h:NextChallenge']) { | ||
var nx = header['h:NextChallenge']; | ||
for (const i in self.logAttempts) { | ||
if ((self.logAttempts[i].service == serviceType && self.logAttempts[i].action == action)) { | ||
if (self.logAttempts[i].attempts >= 1) { | ||
error = new Error('Credentials incorrect'); | ||
} else { | ||
self.logAttempts[i].attempts += 1; | ||
device._auth.des = serviceType; | ||
device._auth.sn = ch.Nonce; | ||
device._auth.realm = ch.Realm; | ||
device._auth.auth = device._calcAuthDigest( | ||
device._auth.uid, | ||
device._auth.pwd, | ||
device._auth.realm, | ||
device._auth.sn | ||
); | ||
device._auth.chCount++; | ||
that._sendSOAPActionRequest( | ||
device, | ||
url, | ||
serviceType, | ||
action, | ||
inArguments, | ||
outArguments, | ||
vars, | ||
callback | ||
); | ||
return; | ||
} | ||
self.logAttempts[i].attempts = 0; | ||
} | ||
} | ||
} else { | ||
self.logAttempts.push({ service: serviceType, action: action, attempts: 1 }); | ||
device._auth.sn = ch.Nonce; | ||
device._auth.realm = ch.Realm; | ||
device._auth.chCount = 0; | ||
device._auth.sn = nx.Nonce; | ||
device._auth.realm = nx.Realm; | ||
device._auth.auth = device._calcAuthDigest( | ||
@@ -288,110 +341,93 @@ device._auth.uid, | ||
); | ||
device._auth.chCount++; | ||
// Repeat request. | ||
that._sendSOAPActionRequest( | ||
device, | ||
url, | ||
serviceType, | ||
action, | ||
inArguments, | ||
outArguments, | ||
vars, | ||
callback | ||
); | ||
return; | ||
} | ||
} else if (header['h:NextChallenge']) { | ||
var nx = header['h:NextChallenge']; | ||
for (const i in self.logAttempts) { | ||
if ((self.logAttempts[i].service == serviceType && self.logAttempts[i].action == action)) { | ||
self.logAttempts[i].attempts = 0; | ||
} | ||
if (env['s:Body']) { | ||
var body = env['s:Body']; | ||
if (body['u:' + action + 'Response']) { | ||
var responseVars = body['u:' + action + 'Response']; | ||
if (outArguments) { | ||
outArguments.forEach(function(arg) { | ||
res[arg] = responseVars[arg]; | ||
}); | ||
} | ||
} else if (body['s:Fault']) { | ||
var fault = body['s:Fault']; | ||
//let errorStatus = body['s:Fault'].detail.UPnPError.errorDescription; | ||
let newFault = body['s:Fault']; | ||
error = { | ||
response: response ? response.statusMessage : 'No message', | ||
responseCode: response ? response.statusCode : 'No code', | ||
tr064: newFault ? newFault.detail.UPnPError.errorDescription : 'No message', | ||
tr064code: newFault ? newFault.detail.UPnPError.errorCode : 'No code', | ||
fault: newFault ? newFault.faultstring : 'No message', | ||
faultcode: newFault ? newFault.faultcode : 'No code', | ||
serviceType: serviceType, | ||
action: action | ||
}; | ||
res = fault; | ||
} | ||
device._auth.chCount = 0; | ||
device._auth.sn = nx.Nonce; | ||
device._auth.realm = nx.Realm; | ||
device._auth.auth = device._calcAuthDigest( | ||
device._auth.uid, | ||
device._auth.pwd, | ||
device._auth.realm, | ||
device._auth.sn | ||
); | ||
} | ||
callback(error, res); | ||
} | ||
if (env['s:Body']) { | ||
var body = env['s:Body']; | ||
if (body['u:' + action + 'Response']) { | ||
var responseVars = body['u:' + action + 'Response']; | ||
if (outArguments) { | ||
outArguments.forEach(function(arg) { | ||
res[arg] = responseVars[arg]; | ||
}); | ||
} | ||
} else if (body['s:Fault']) { | ||
var fault = body['s:Fault']; | ||
//let errorStatus = body['s:Fault'].detail.UPnPError.errorDescription; | ||
let newFault = body['s:Fault']; | ||
); | ||
} else { | ||
if(response){ | ||
parseString(response.body,{explicitArray: false,}, function (err, result) { | ||
if(!err){ | ||
let env = result['s:Envelope']; | ||
if(env['s:Body']){ | ||
let newBody = env['s:Body']; | ||
if(newBody['s:Fault']){ | ||
let fault = newBody['s:Fault']; | ||
error = { | ||
error: error ? error.errno : 'No message', | ||
errorCode: error ? error.errno : 'No code', | ||
tr064: fault ? fault.detail.UPnPError.errorDescription : 'No message', | ||
tr064code: fault ? fault.detail.UPnPError.errorCode : 'No code', | ||
fault: fault ? fault.faultstring : 'No message', | ||
faultcode: fault ? fault.faultcode : 'No code', | ||
serviceType: serviceType, | ||
action: action | ||
}; | ||
} | ||
} | ||
} else { | ||
error = { | ||
response: response ? response.statusMessage : 'No message', | ||
responseCode: response ? response.statusCode : 'No code', | ||
tr064: newFault ? newFault.detail.UPnPError.errorDescription : 'No message', | ||
tr064code: newFault ? newFault.detail.UPnPError.errorCode : 'No code', | ||
fault: newFault ? newFault.faultstring : 'No message', | ||
faultcode: newFault ? newFault.faultcode : 'No code', | ||
error: error ? error.errno : 'No message', | ||
errorCode: error ? error.errno : 'No code', | ||
serviceType: serviceType, | ||
action: action | ||
}; | ||
res = fault; | ||
} | ||
} | ||
callback(error, res); | ||
}); | ||
callback(error, null); | ||
} else { | ||
error = { | ||
error: error ? error.code : 'No message', | ||
errorCode: error ? error.code : 'No code', | ||
serviceType: serviceType, | ||
action: action | ||
}; | ||
callback(error, null); | ||
} | ||
); | ||
} else { | ||
if(response){ | ||
parseString(response.body,{explicitArray: false,}, function (err, result) { | ||
if(!err){ | ||
let env = result['s:Envelope']; | ||
if(env['s:Body']){ | ||
let newBody = env['s:Body']; | ||
if(newBody['s:Fault']){ | ||
let fault = newBody['s:Fault']; | ||
error = { | ||
error: error ? error.errno : 'No message', | ||
errorCode: error ? error.errno : 'No code', | ||
tr064: fault ? fault.detail.UPnPError.errorDescription : 'No message', | ||
tr064code: fault ? fault.detail.UPnPError.errorCode : 'No code', | ||
fault: fault ? fault.faultstring : 'No message', | ||
faultcode: fault ? fault.faultcode : 'No code', | ||
serviceType: serviceType, | ||
action: action | ||
}; | ||
} | ||
} | ||
} else { | ||
error = { | ||
error: error ? error.errno : 'No message', | ||
errorCode: error ? error.errno : 'No code', | ||
serviceType: serviceType, | ||
action: action | ||
}; | ||
} | ||
}); | ||
callback(error, null); | ||
} else { | ||
error = { | ||
error: error ? error.code : 'No message', | ||
errorCode: error ? error.code : 'No code', | ||
serviceType: serviceType, | ||
action: action | ||
}; | ||
callback(error, null); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
); | ||
} else { | ||
setTimeout(function(){ | ||
self._sendSOAPActionRequest( | ||
device, | ||
url, | ||
serviceType, | ||
action, | ||
inArguments, | ||
outArguments, | ||
vars, | ||
callback | ||
); | ||
},1000); | ||
} | ||
} | ||
} | ||
exports.Service = Service; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
222802
11
706