Major updates paving the road support ACS methods
This commit is contained in:
1 parent
3ce097359c
commit
462e9e3afd
3 files changed
+202
-186
No files matched your search
+33
-32
@@ -21,7 +21,7 @@ applyConfigurations = (currentRequest, taskList) ->
|
|||||||
runTask(currentRequest, task, {})
|
runTask(currentRequest, task, {})
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
res = tr069.response(currentRequest.sessionId, {}, {})
|
res = tr069.response(null, {}, {})
|
||||||
writeResponse(currentRequest, res)
|
writeResponse(currentRequest, res)
|
||||||
|
|
||||||
|
|
||||||
@@ -91,14 +91,15 @@ updateDevice = (currentRequest, actions, callback) ->
|
|||||||
callback() if callback?
|
callback() if callback?
|
||||||
|
|
||||||
|
|
||||||
runTask = (currentRequest, task, cwmpRequest) ->
|
runTask = (currentRequest, task, methodResponse) ->
|
||||||
cwmpResponse = {}
|
cwmpResponse = {}
|
||||||
actions = tasks.task(task, cwmpRequest, cwmpResponse)
|
actions = tasks.task(task, methodResponse, cwmpResponse)
|
||||||
|
|
||||||
updateDevice(currentRequest, actions)
|
updateDevice(currentRequest, actions)
|
||||||
|
|
||||||
if Object.keys(cwmpResponse).length > 0
|
if Object.keys(cwmpResponse).length > 0
|
||||||
db.updateTask(task, (err) ->
|
db.updateTask(task, (err) ->
|
||||||
res = tr069.response(currentRequest.sessionId, cwmpResponse, {task : String(task._id)})
|
res = tr069.response(task._id, cwmpResponse)
|
||||||
writeResponse(currentRequest, res)
|
writeResponse(currentRequest, res)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@@ -107,7 +108,7 @@ runTask = (currentRequest, task, cwmpRequest) ->
|
|||||||
db.memcached.del(String(task._id))
|
db.memcached.del(String(task._id))
|
||||||
db.tasksCollection.remove({'_id' : mongodb.ObjectID(String(task._id))}, {safe: true}, (err, removed) ->
|
db.tasksCollection.remove({'_id' : mongodb.ObjectID(String(task._id))}, {safe: true}, (err, removed) ->
|
||||||
util.log("#{currentRequest.deviceId}: Completed task #{task.name}(#{task._id})")
|
util.log("#{currentRequest.deviceId}: Completed task #{task.name}(#{task._id})")
|
||||||
cookies = {task : null}
|
cookies = {}
|
||||||
nextTask(currentRequest, cookies)
|
nextTask(currentRequest, cookies)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -115,7 +116,6 @@ runTask = (currentRequest, task, cwmpRequest) ->
|
|||||||
nextTask = (currentRequest, cookies) ->
|
nextTask = (currentRequest, cookies) ->
|
||||||
cur = db.tasksCollection.find({'device' : currentRequest.deviceId}).sort(['timestamp']).limit(1)
|
cur = db.tasksCollection.find({'device' : currentRequest.deviceId}).sort(['timestamp']).limit(1)
|
||||||
cur.nextObject( (err, task) ->
|
cur.nextObject( (err, task) ->
|
||||||
cwmpRequest = {}
|
|
||||||
cwmpResponse = {}
|
cwmpResponse = {}
|
||||||
|
|
||||||
if not task
|
if not task
|
||||||
@@ -136,22 +136,22 @@ nextTask = (currentRequest, cookies) ->
|
|||||||
)
|
)
|
||||||
else
|
else
|
||||||
# no discrepancy, return empty response
|
# no discrepancy, return empty response
|
||||||
res = tr069.response(currentRequest.sessionId, cwmpResponse, cookies)
|
res = tr069.response(null, cwmpResponse, cookies)
|
||||||
writeResponse(currentRequest, res)
|
writeResponse(currentRequest, res)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
# no discrepancy, return empty response
|
# no discrepancy, return empty response
|
||||||
res = tr069.response(currentRequest.sessionId, cwmpResponse, cookies)
|
res = tr069.response(null, cwmpResponse, cookies)
|
||||||
writeResponse(currentRequest, res)
|
writeResponse(currentRequest, res)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
else if task.fault?
|
else if task.fault?
|
||||||
# last task was faulty. Do nothing until until task is deleted
|
# last task was faulty. Do nothing until until task is deleted
|
||||||
res = tr069.response(currentRequest.sessionId, cwmpResponse, cookies)
|
res = tr069.response(null, cwmpResponse, cookies)
|
||||||
writeResponse(currentRequest, res)
|
writeResponse(currentRequest, res)
|
||||||
else
|
else
|
||||||
util.log("#{currentRequest.deviceId}: Started task #{task.name}(#{task._id})")
|
util.log("#{currentRequest.deviceId}: Started task #{task.name}(#{task._id})")
|
||||||
runTask(currentRequest, task, cwmpRequest)
|
runTask(currentRequest, task, {})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -209,11 +209,10 @@ else
|
|||||||
cwmpRequest = tr069.request(httpRequest)
|
cwmpRequest = tr069.request(httpRequest)
|
||||||
|
|
||||||
# get deviceId either from inform xml or cookie
|
# get deviceId either from inform xml or cookie
|
||||||
if cwmpRequest.deviceId?
|
if cwmpRequest.methodRequest? and cwmpRequest.methodRequest.type is 'Inform'
|
||||||
currentRequest.deviceId = common.getDeviceId(cwmpRequest.deviceId)
|
cookies.deviceId = currentRequest.deviceId = common.getDeviceId(cwmpRequest.methodRequest.deviceId)
|
||||||
cookies.DeviceId = currentRequest.deviceId
|
|
||||||
else
|
else
|
||||||
currentRequest.deviceId = cwmpRequest.cookies.DeviceId
|
currentRequest.deviceId = cwmpRequest.cookies.deviceId
|
||||||
|
|
||||||
if config.DEBUG_DEVICES[currentRequest.deviceId]
|
if config.DEBUG_DEVICES[currentRequest.deviceId]
|
||||||
dump = "# REQUEST #{new Date(Date.now())}\n" + JSON.stringify(httpRequest.headers) + "\n#{httpRequest.getBody()}\n\n"
|
dump = "# REQUEST #{new Date(Date.now())}\n" + JSON.stringify(httpRequest.headers) + "\n#{httpRequest.getBody()}\n\n"
|
||||||
@@ -221,38 +220,40 @@ else
|
|||||||
throw new Error(err) if err
|
throw new Error(err) if err
|
||||||
)
|
)
|
||||||
|
|
||||||
if cwmpRequest.inform
|
if cwmpRequest.methodRequest?
|
||||||
cwmpResponse.inform = true
|
if cwmpRequest.methodRequest.type == 'Inform'
|
||||||
cookies.ID = currentRequest.sessionId = cwmpRequest.sessionId
|
cwmpResponse.methodResponse = {type : 'InformResponse'}
|
||||||
|
|
||||||
if config.LOG_INFORMS
|
if config.LOG_INFORMS
|
||||||
util.log("#{currentRequest.deviceId}: Inform (#{cwmpRequest.eventCodes}); retry count #{cwmpRequest.retryCount}")
|
util.log("#{currentRequest.deviceId}: Inform (#{cwmpRequest.methodRequest.event}); retry count #{cwmpRequest.methodRequest.retryCount}")
|
||||||
|
|
||||||
updateDevice(currentRequest, {'inform' : true, 'parameterValues' : cwmpRequest.informParameterValues}, (err) ->
|
updateDevice(currentRequest, {'inform' : true, 'parameterValues' : cwmpRequest.methodRequest.parameterList}, (err) ->
|
||||||
res = tr069.response(currentRequest.sessionId, cwmpResponse, cookies)
|
res = tr069.response(cwmpRequest.id, cwmpResponse, cookies)
|
||||||
writeResponse(currentRequest, res)
|
writeResponse(currentRequest, res)
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
currentRequest.sessionId = cwmpRequest.cookies.ID
|
|
||||||
taskId = cwmpRequest.cookies.task
|
|
||||||
|
|
||||||
if not taskId
|
|
||||||
nextTask(currentRequest, cookies)
|
|
||||||
else
|
else
|
||||||
|
throw Error('ACS method not supported')
|
||||||
|
else if cwmpRequest.methodResponse?
|
||||||
|
taskId = cwmpRequest.id
|
||||||
|
|
||||||
db.getTask(taskId, (task) ->
|
db.getTask(taskId, (task) ->
|
||||||
if not task
|
if not task
|
||||||
nextTask(currentRequest, cookies)
|
nextTask(currentRequest, cookies)
|
||||||
|
else
|
||||||
|
runTask(currentRequest, task, cwmpRequest.methodResponse)
|
||||||
|
)
|
||||||
else if cwmpRequest.fault?
|
else if cwmpRequest.fault?
|
||||||
util.log("#{currentRequest.deviceId}: Fault response for task #{task._id}")
|
taskId = cwmpRequest.id
|
||||||
db.tasksCollection.update({_id : mongodb.ObjectID(String(task._id))}, {$set : {fault : cwmpRequest.fault}}, (err) ->
|
util.log("#{currentRequest.deviceId}: Fault response for task #{taskId}")
|
||||||
|
db.tasksCollection.update({_id : mongodb.ObjectID(taskId)}, {$set : {fault : cwmpRequest.fault}}, (err) ->
|
||||||
# Faulty task. No more work to do until task is deleted.
|
# Faulty task. No more work to do until task is deleted.
|
||||||
res = tr069.response(currentRequest.sessionId, cwmpResponse, cookies)
|
res = tr069.response(null, cwmpResponse, cookies)
|
||||||
writeResponse(currentRequest, res)
|
writeResponse(currentRequest, res)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
runTask(currentRequest, task, cwmpRequest)
|
# cpe sent empty response. start sending acs requests
|
||||||
)
|
nextTask(currentRequest, cookies)
|
||||||
|
|
||||||
|
|
||||||
server.listen config.ACS_PORT, config.ACS_INTERFACE
|
server.listen config.ACS_PORT, config.ACS_INTERFACE
|
||||||
#console.log "Server listening on port #{config.ACS_PORT}"
|
#console.log "Server listening on port #{config.ACS_PORT}"
|
||||||
+32
-20
@@ -1,13 +1,13 @@
|
|||||||
common = require './common'
|
common = require './common'
|
||||||
BATCH_SIZE = 16
|
BATCH_SIZE = 16
|
||||||
|
|
||||||
this.init = (task, cwmpRequest, cwmpResponse) ->
|
this.init = (task, methodResponse, cwmpResponse) ->
|
||||||
ret = {}
|
ret = {}
|
||||||
if not task.subtask?
|
if not task.subtask?
|
||||||
task.subtask = {'name' : 'getParameterNames', 'parameterPath' : '', 'nextLevel' : false}
|
task.subtask = {'name' : 'getParameterNames', 'parameterPath' : '', 'nextLevel' : false}
|
||||||
|
|
||||||
if task.subtask.name == 'getParameterNames'
|
if task.subtask.name == 'getParameterNames'
|
||||||
common.extend(ret, this.getParameterNames(task.subtask, cwmpRequest, cwmpResponse))
|
common.extend(ret, this.getParameterNames(task.subtask, methodResponse, cwmpResponse))
|
||||||
if ret.parameterNames? # task finished
|
if ret.parameterNames? # task finished
|
||||||
parameterNames = []
|
parameterNames = []
|
||||||
for p in ret.parameterNames
|
for p in ret.parameterNames
|
||||||
@@ -16,37 +16,44 @@ this.init = (task, cwmpRequest, cwmpResponse) ->
|
|||||||
task.subtask = {'name' : 'getParameterValues', 'parameterNames' : parameterNames}
|
task.subtask = {'name' : 'getParameterValues', 'parameterNames' : parameterNames}
|
||||||
|
|
||||||
if task.subtask.name == 'getParameterValues'
|
if task.subtask.name == 'getParameterValues'
|
||||||
common.extend(ret, this.getParameterValues(task.subtask, cwmpRequest, cwmpResponse))
|
common.extend(ret, this.getParameterValues(task.subtask, methodResponse, cwmpResponse))
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
this.getParameterNames = (task, cwmpRequest, cwmpResponse) ->
|
this.getParameterNames = (task, methodResponse, cwmpResponse) ->
|
||||||
if cwmpRequest.getParameterNamesResponse?
|
if methodResponse.type is 'GetParameterNamesResponse'
|
||||||
return {'parameterNames' : cwmpRequest.getParameterNamesResponse}
|
return {'parameterNames' : methodResponse.parameterList}
|
||||||
else
|
else
|
||||||
cwmpResponse.getParameterNames = [task.parameterPath, if task.nextLevel? task.nextLevel else false]
|
cwmpResponse.methodRequest = {
|
||||||
|
type : 'GetParameterNames',
|
||||||
|
parameterPath : task.parameterPath,
|
||||||
|
nextLevel : if task.nextLevel? then task.nextLevel else false
|
||||||
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
this.getParameterValues = (task, cwmpRequest, cwmpResponse) ->
|
this.getParameterValues = (task, methodResponse, cwmpResponse) ->
|
||||||
if not task.currentIndex?
|
if not task.currentIndex?
|
||||||
task.currentIndex = 0
|
task.currentIndex = 0
|
||||||
else if cwmpRequest.getParameterValuesResponse?
|
else if methodResponse.parameterList?
|
||||||
task.currentIndex = task.nextIndex
|
task.currentIndex = task.nextIndex
|
||||||
|
|
||||||
task.nextIndex = Math.min(task.currentIndex + BATCH_SIZE, task.parameterNames.length)
|
task.nextIndex = Math.min(task.currentIndex + BATCH_SIZE, task.parameterNames.length)
|
||||||
names = task.parameterNames.slice(task.currentIndex, task.nextIndex)
|
names = task.parameterNames.slice(task.currentIndex, task.nextIndex)
|
||||||
|
|
||||||
if names.length > 0
|
if names.length > 0
|
||||||
cwmpResponse.getParameterValues = names
|
cwmpResponse.methodRequest = {
|
||||||
|
type : 'GetParameterValues',
|
||||||
|
parameterNames : names
|
||||||
|
}
|
||||||
|
|
||||||
if cwmpRequest.getParameterValuesResponse
|
if methodResponse.type is 'GetParameterValuesResponse'
|
||||||
return {'parameterValues' : cwmpRequest.getParameterValuesResponse}
|
return {'parameterValues' : methodResponse.parameterList}
|
||||||
return
|
return
|
||||||
|
|
||||||
this.setParameterValues = (task, cwmpRequest, cwmpResponse) ->
|
this.setParameterValues = (task, methodResponse, cwmpResponse) ->
|
||||||
if not task.currentIndex?
|
if not task.currentIndex?
|
||||||
task.currentIndex = 0
|
task.currentIndex = 0
|
||||||
else if cwmpRequest.setParameterValuesResponse?
|
else if methodResponse.type is 'SetParameterValuesResponse'
|
||||||
prevValues = task.parameterValues.slice(task.currentIndex, task.nextIndex)
|
prevValues = task.parameterValues.slice(task.currentIndex, task.nextIndex)
|
||||||
task.currentIndex = task.nextIndex
|
task.currentIndex = task.nextIndex
|
||||||
|
|
||||||
@@ -54,15 +61,20 @@ this.setParameterValues = (task, cwmpRequest, cwmpResponse) ->
|
|||||||
values = task.parameterValues.slice(task.currentIndex, task.nextIndex)
|
values = task.parameterValues.slice(task.currentIndex, task.nextIndex)
|
||||||
|
|
||||||
if values.length > 0
|
if values.length > 0
|
||||||
cwmpResponse.setParameterValues = values
|
cwmpResponse.methodRequest = {
|
||||||
|
type : 'SetParameterValues',
|
||||||
|
parameterList : values
|
||||||
|
}
|
||||||
|
|
||||||
if prevValues?
|
if prevValues?
|
||||||
return {'parameterValues' : prevValues}
|
return {'parameterValues' : prevValues}
|
||||||
return
|
return
|
||||||
|
|
||||||
this.reboot = (task, cwmpRequest, cwmpResponse) ->
|
this.reboot = (task, methodResponse, cwmpResponse) ->
|
||||||
if not cwmpRequest.reboot
|
if methodResponse.type isnt 'RebootResponse'
|
||||||
cwmpResponse.reboot = 'reboot'
|
cwmpResponse.methodRequest = {
|
||||||
|
type : 'Reboot'
|
||||||
|
}
|
||||||
|
|
||||||
exports.task = (task, cwmpRequest, cwmpResponse) ->
|
exports.task = (task, methodResponse, cwmpResponse) ->
|
||||||
return this[task.name](task, cwmpRequest, cwmpResponse)
|
return this[task.name](task, methodResponse, cwmpResponse)
|
||||||
+137
-134
@@ -10,16 +10,13 @@ NAMESPACES = {
|
|||||||
'cwmp' : 'urn:dslforum-org:cwmp-1-0',
|
'cwmp' : 'urn:dslforum-org:cwmp-1-0',
|
||||||
}
|
}
|
||||||
|
|
||||||
trim = (str) ->
|
|
||||||
str.replace /^\s+|\s+$/g, ''
|
|
||||||
|
|
||||||
|
|
||||||
cookiesToObj = (cookieLine) ->
|
cookiesToObj = (cookieLine) ->
|
||||||
cookies = {}
|
cookies = {}
|
||||||
for c in trim(cookieLine).split ','
|
for c in cookieLine.trim().split ','
|
||||||
nv = c.split '='
|
nv = c.split '='
|
||||||
continue if nv.length < 2
|
continue if nv.length < 2
|
||||||
cookies[trim(nv[0])] = trim(nv[1])
|
cookies[nv[0].trim()] = nv[1].trim()
|
||||||
return cookies
|
return cookies
|
||||||
|
|
||||||
|
|
||||||
@@ -30,108 +27,105 @@ cookiesToStr = (obj) ->
|
|||||||
return l# + 'path=/'
|
return l# + 'path=/'
|
||||||
|
|
||||||
|
|
||||||
sessionId = (xml) ->
|
event = (xml) ->
|
||||||
e = xml.get('//soap-env:Envelope/soap-env:Header/cwmp:ID', NAMESPACES)
|
e.text().trim() for e in xml.find('EventStruct/EventCode', NAMESPACES)
|
||||||
if e?
|
|
||||||
return trim(e.text())
|
|
||||||
return undefined
|
|
||||||
|
|
||||||
|
|
||||||
deviceId = (xml) ->
|
parameterInfoList = (xml) ->
|
||||||
e = xml.get('//soap-env:Envelope/soap-env:Body/cwmp:Inform/DeviceId', NAMESPACES)
|
infoList = []
|
||||||
if e?
|
for e in xml.find('ParameterInfoStruct', NAMESPACES)
|
||||||
id = {}
|
name = e.get('Name').text().trim()
|
||||||
for n in e.find('//child::*')
|
|
||||||
id[n.name()] = trim(n.text())
|
|
||||||
return id
|
|
||||||
return undefined
|
|
||||||
|
|
||||||
|
|
||||||
eventCodes = (xml) ->
|
|
||||||
(trim(e.text()) for e in xml.find('//soap-env:Envelope/soap-env:Body/cwmp:Inform/Event/EventStruct/EventCode', NAMESPACES))
|
|
||||||
|
|
||||||
|
|
||||||
retryCount = (xml) ->
|
|
||||||
e = xml.get('//soap-env:Envelope/soap-env:Body/cwmp:Inform/RetryCount', NAMESPACES)
|
|
||||||
if e
|
|
||||||
return JSON.parse(e.text())
|
|
||||||
return undefined
|
|
||||||
|
|
||||||
|
|
||||||
informParameterValues = (xml) ->
|
|
||||||
if not xml.get( '//soap-env:Envelope/soap-env:Body/cwmp:Inform/ParameterList', NAMESPACES)
|
|
||||||
return undefined
|
|
||||||
|
|
||||||
values = []
|
|
||||||
for e in xml.find('//soap-env:Envelope/soap-env:Body/cwmp:Inform/ParameterList/ParameterValueStruct', NAMESPACES)
|
|
||||||
valueType = trim(e.get('Value').attr('type').value())
|
|
||||||
name = trim(e.get('Name').text())
|
|
||||||
switch valueType
|
|
||||||
when 'xsd:boolean'
|
|
||||||
value = Boolean(JSON.parse(e.get('Value').text()))
|
|
||||||
when 'xsd:unsignedInt'
|
|
||||||
value = JSON.parse(e.get('Value').text())
|
|
||||||
else
|
|
||||||
value = trim(e.get('Value').text())
|
|
||||||
|
|
||||||
values.push([name, value])
|
|
||||||
return values
|
|
||||||
|
|
||||||
|
|
||||||
getParameterNamesResponse = (xml) ->
|
|
||||||
if not xml.get('//soap-env:Envelope/soap-env:Body/cwmp:GetParameterNamesResponse', NAMESPACES)
|
|
||||||
return undefined
|
|
||||||
|
|
||||||
response = []
|
|
||||||
for e in xml.find('//soap-env:Envelope/soap-env:Body/cwmp:GetParameterNamesResponse/ParameterList/ParameterInfoStruct', NAMESPACES)
|
|
||||||
name = trim(e.get('Name').text())
|
|
||||||
writable = Boolean(JSON.parse(e.get('Writable').text()))
|
writable = Boolean(JSON.parse(e.get('Writable').text()))
|
||||||
response.push([name, writable])
|
infoList.push([name, writable])
|
||||||
return response
|
return infoList
|
||||||
|
|
||||||
|
|
||||||
getParameterValuesResponse = (xml) ->
|
parameterValueList = (xml) ->
|
||||||
if not xml.get( '//soap-env:Envelope/soap-env:Body/cwmp:GetParameterValuesResponse', NAMESPACES)
|
valueList = []
|
||||||
return undefined
|
for e in xml.find('ParameterValueStruct', NAMESPACES)
|
||||||
|
valueType = e.get('Value').attr('type').value().trim()
|
||||||
values = []
|
name = e.get('Name').text().trim()
|
||||||
for e in xml.find('//soap-env:Envelope/soap-env:Body/cwmp:GetParameterValuesResponse/ParameterList/ParameterValueStruct', NAMESPACES)
|
value = e.get('Value').text().trim()
|
||||||
valueType = trim(e.get('Value').attr('type').value())
|
|
||||||
name = trim(e.get('Name').text())
|
|
||||||
switch valueType
|
switch valueType
|
||||||
when 'xsd:boolean'
|
when 'xsd:boolean'
|
||||||
value = Boolean(JSON.parse(e.get('Value').text()))
|
value = Boolean(JSON.parse(value))
|
||||||
when 'xsd:unsignedInt'
|
when 'xsd:unsignedInt'
|
||||||
value = JSON.parse(e.get('Value').text())
|
value = JSON.parse(value)
|
||||||
|
valueList.push([name, value])
|
||||||
|
return valueList
|
||||||
|
|
||||||
|
|
||||||
|
cpeGetParameterNames = (xml, methodRequest) ->
|
||||||
|
el = xml.node('cwmp:GetParameterNames')
|
||||||
|
el.node('cwmp:ParameterPath').text(methodRequest.parameterPath)
|
||||||
|
el.node('cwmp:NextLevel').text(+methodRequest.nextLevel)
|
||||||
|
|
||||||
|
|
||||||
|
cpeGetParameterNamesResponse = (xml) ->
|
||||||
|
{parameterList : parameterInfoList(xml.get('ParameterList'))}
|
||||||
|
|
||||||
|
|
||||||
|
cpeGetParameterValues = (xml, methodRequest) ->
|
||||||
|
el = xml.node('cwmp:GetParameterValues').node('cwmp:ParameterNames')
|
||||||
|
for p in methodRequest.parameterNames
|
||||||
|
el.node('xsd:string').text(p)
|
||||||
|
|
||||||
|
|
||||||
|
cpeGetParameterValuesResponse = (xml) ->
|
||||||
|
{parameterList : parameterValueList(xml.get('ParameterList'))}
|
||||||
|
|
||||||
|
|
||||||
|
cpeSetParameterValues = (xml, methodRequest) ->
|
||||||
|
el = xml.node('cwmp:SetParameterValues')
|
||||||
|
paramList = el.node('ParameterList')
|
||||||
|
for i in methodRequest.parameterList
|
||||||
|
pvs = paramList.node('ParameterValueStruct')
|
||||||
|
pvs.node('Name').text(i[0])
|
||||||
|
pvs.node('Value').text(i[1])
|
||||||
|
# Huawei CPEs need this element present otherwise won't respond
|
||||||
|
el.node('ParameterKey').text(if methodRequest.parameterKey? then methodRequest.parameterKey else '')
|
||||||
|
|
||||||
|
|
||||||
|
cpeSetParameterValuesResponse = (xml) ->
|
||||||
|
{status : JSON.parse(xml.get('Status').text())}
|
||||||
|
|
||||||
|
|
||||||
|
traverseXml = (xml) ->
|
||||||
|
obj = {}
|
||||||
|
for n in xml.childNodes()
|
||||||
|
if n.type() == 'element'
|
||||||
|
obj[n.name()] = traverseXml(n)
|
||||||
|
|
||||||
|
if Object.keys(obj).length == 0
|
||||||
|
xml.text()
|
||||||
else
|
else
|
||||||
value = trim(e.get('Value').text())
|
obj
|
||||||
|
|
||||||
values.push([name, value])
|
|
||||||
return values
|
|
||||||
|
|
||||||
|
|
||||||
setParameterValuesResponse = (xml) ->
|
|
||||||
e = xml.get('//soap-env:Envelope/soap-env:Body/cwmp:SetParameterValuesResponse/Status', NAMESPACES)
|
|
||||||
if e
|
|
||||||
return JSON.parse(e.text())
|
|
||||||
return undefined
|
|
||||||
|
|
||||||
fault = (xml) ->
|
fault = (xml) ->
|
||||||
f = xml.get('//soap-env:Envelope/soap-env:Body/soap-env:Fault', NAMESPACES)
|
return traverseXml(xml)
|
||||||
if f
|
|
||||||
traverse = (el) ->
|
|
||||||
children = el.childNodes()
|
|
||||||
obj = {}
|
|
||||||
for n in el.childNodes()
|
|
||||||
if n.type() == 'element'
|
|
||||||
obj[n.name()] = traverse(n)
|
|
||||||
if Object.keys(obj).length == 0
|
|
||||||
return el.text()
|
|
||||||
else
|
|
||||||
return obj
|
|
||||||
|
|
||||||
return traverse(f)
|
|
||||||
return undefined
|
acsInform = (xml) ->
|
||||||
|
{
|
||||||
|
parameterList : parameterValueList(xml.get('ParameterList')),
|
||||||
|
deviceId : traverseXml(xml.get('DeviceId')),
|
||||||
|
event : event(xml.get('Event')),
|
||||||
|
retryCount : JSON.parse(xml.get('RetryCount').text())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
acsInformResponse = (xml) ->
|
||||||
|
xml.node('cwmp:InformResponse').node('MaxEnvelopes').text(1)
|
||||||
|
|
||||||
|
|
||||||
|
cpeReboot = (xml, methodRequest) ->
|
||||||
|
el = xml.node('cwmp:Reboot')
|
||||||
|
# Huawei CPEs need this element present otherwise won't respond
|
||||||
|
el.node('CommandKey').text(if methodRequest.commandKey then methodRequest.commandKey else '')
|
||||||
|
|
||||||
|
|
||||||
|
cpeRebootResponse = (xml) ->
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
exports.request = (httpRequest) ->
|
exports.request = (httpRequest) ->
|
||||||
@@ -147,21 +141,36 @@ exports.request = (httpRequest) ->
|
|||||||
# some devices send invalid utf8 characters
|
# some devices send invalid utf8 characters
|
||||||
xml = libxmljs.parseXml httpRequest.getBody('binary')
|
xml = libxmljs.parseXml httpRequest.getBody('binary')
|
||||||
|
|
||||||
cwmpRequest.sessionId = sessionId xml
|
cwmpRequest.id = xml.get('//soap-env:Envelope/soap-env:Header/cwmp:ID', NAMESPACES).text()
|
||||||
cwmpRequest.inform = true if xml.get('//soap-env:Envelope/soap-env:Body/cwmp:Inform', NAMESPACES)
|
|
||||||
cwmpRequest.informParameterValues = informParameterValues xml
|
methodElement = xml.get('/soap-env:Envelope/soap-env:Body/cwmp:*', NAMESPACES)
|
||||||
cwmpRequest.reboot = true if xml.get('//soap-env:Envelope/soap-env:Body/cwmp:RebootResponse', NAMESPACES)
|
if methodElement?
|
||||||
cwmpRequest.deviceId = deviceId xml
|
switch methodElement.name()
|
||||||
cwmpRequest.eventCodes = eventCodes xml
|
when 'Inform'
|
||||||
cwmpRequest.retryCount = retryCount xml
|
cwmpRequest.methodRequest = acsInform(methodElement)
|
||||||
cwmpRequest.getParameterNamesResponse = getParameterNamesResponse xml
|
cwmpRequest.methodRequest.type = 'Inform'
|
||||||
cwmpRequest.getParameterValuesResponse = getParameterValuesResponse xml
|
when 'GetParameterNamesResponse'
|
||||||
cwmpRequest.setParameterValuesResponse = setParameterValuesResponse xml
|
cwmpRequest.methodResponse = cpeGetParameterNamesResponse(methodElement)
|
||||||
cwmpRequest.fault = fault xml
|
cwmpRequest.methodResponse.type = 'GetParameterNamesResponse'
|
||||||
|
when 'GetParameterValuesResponse'
|
||||||
|
cwmpRequest.methodResponse = cpeGetParameterValuesResponse(methodElement)
|
||||||
|
cwmpRequest.methodResponse.type = 'GetParameterValuesResponse'
|
||||||
|
when 'SetParameterValuesResponse'
|
||||||
|
cwmpRequest.methodResponse = cpeSetParameterValuesResponse(methodElement)
|
||||||
|
cwmpRequest.methodResponse.type = 'SetParameterValuesResponse'
|
||||||
|
when 'RebootResponse'
|
||||||
|
cwmpRequest.methodResponse = cpeRebootResponse(methodElement)
|
||||||
|
cwmpRequest.methodResponse.type = 'RebootResponse'
|
||||||
|
else
|
||||||
|
throw Error('8000 Method not supported')
|
||||||
|
else
|
||||||
|
faultElement = xml.get('/soap-env:Envelope/soap-env:Body/soap-env:Fault', NAMESPACES)
|
||||||
|
cwmpRequest.fault = fault(faultElement)
|
||||||
|
|
||||||
return cwmpRequest
|
return cwmpRequest
|
||||||
|
|
||||||
|
|
||||||
exports.response = (sessionId, cwmpResponse, cookies = null) ->
|
exports.response = (id, cwmpResponse, cookies = null) ->
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type' : 'text/xml; charset="utf-8"',
|
'Content-Type' : 'text/xml; charset="utf-8"',
|
||||||
'Server' : SERVER_NAME,
|
'Server' : SERVER_NAME,
|
||||||
@@ -183,35 +192,29 @@ exports.response = (sessionId, cwmpResponse, cookies = null) ->
|
|||||||
env.defineNamespace prefix, url
|
env.defineNamespace prefix, url
|
||||||
|
|
||||||
header = env.node('soap-env:Header')
|
header = env.node('soap-env:Header')
|
||||||
header.node('cwmp:ID').attr({'soap-env:mustUnderstand' : 1}).text(sessionId)
|
header.node('cwmp:ID').attr({'soap-env:mustUnderstand' : 1}).text(id)
|
||||||
#header.node('cwmp:NoMoreRequests').text(0) # depracated
|
|
||||||
body = env.node('soap-env:Body')
|
body = env.node('soap-env:Body')
|
||||||
|
|
||||||
if cwmpResponse.inform
|
if cwmpResponse.methodResponse?
|
||||||
body.node('cwmp:InformResponse').node('MaxEnvelopes').text(1)
|
switch cwmpResponse.methodResponse.type
|
||||||
|
when 'InformResponse'
|
||||||
if cwmpResponse.getParameterNames?
|
acsInformResponse(body)
|
||||||
getParameterNames = body.node('cwmp:GetParameterNames')
|
else
|
||||||
getParameterNames.node('cwmp:ParameterPath').text(cwmpResponse.getParameterNames[0])
|
throw Error("Unknown method response type #{cwmpResponse.methodResponse.type}")
|
||||||
getParameterNames.node('cwmp:NextLevel').text(+cwmpResponse.getParameterNames[1])
|
else if cwmpResponse.methodRequest?
|
||||||
|
switch cwmpResponse.methodRequest.type
|
||||||
if cwmpResponse.getParameterValues?
|
when 'GetParameterNames'
|
||||||
parameterNames = body.node('cwmp:GetParameterValues').node('cwmp:ParameterNames')
|
cpeGetParameterNames(body, cwmpResponse.methodRequest)
|
||||||
for p in cwmpResponse.getParameterValues
|
when 'GetParameterValues'
|
||||||
parameterNames.node('xsd:string').text(p)
|
cpeGetParameterValues(body, cwmpResponse.methodRequest)
|
||||||
|
when 'SetParameterValues'
|
||||||
if cwmpResponse.setParameterValues?
|
cpeSetParameterValues(body, cwmpResponse.methodRequest)
|
||||||
setParameterValuesNode = body.node('cwmp:SetParameterValues')
|
when 'Reboot'
|
||||||
parameterList = setParameterValuesNode.node('ParameterList')
|
cpeReboot(body, cwmpResponse.methodRequest)
|
||||||
for i in cwmpResponse.setParameterValues
|
else
|
||||||
pvs = parameterList.node('ParameterValueStruct')
|
throw Error("Unknown method request #{cwmpResponse.methodRequest.type}")
|
||||||
pvs.node('Name').text(i[0])
|
else
|
||||||
pvs.node('Value').text(i[1])
|
throw Error('Invalid response arguments')
|
||||||
setParameterValuesNode.node('ParameterKey')
|
|
||||||
|
|
||||||
if cwmpResponse.reboot?
|
|
||||||
body.node('cwmp:Reboot').node('CommandKey').text(cwmpResponse.reboot)
|
|
||||||
|
|
||||||
|
|
||||||
data = xml.toString()
|
data = xml.toString()
|
||||||
headers['Content-Length'] = data.length
|
headers['Content-Length'] = data.length
|
||||||
|
|||||||
Reference in new issue
Block a user