Skip to content

Commit 7ce4f3f

Browse files
committed
enable both Firmware Upgrade and Vendor Configuration
1 parent d8da720 commit 7ce4f3f

File tree

3 files changed

+24
-34
lines changed

3 files changed

+24
-34
lines changed

src/http/cwmp/index.coffee

+7-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ request = (url, req, res) ->
6969
console.dir [ req.headers, req.body ]
7070

7171
res.name = 'cwmp:Download'
72-
res.fileType = '3 Vendor Configuration File'
73-
res.fileSize = file.sts.length
74-
res.url = "#{ url }file.sts"
72+
73+
res.fileType = switch file.ext
74+
when '.rbi' then '1 Firmware Upgrade Image'
75+
when '.sts' then '3 Vendor Configuration File'
76+
77+
res.fileSize = file.data.length
78+
res.url = "#{ url }#{file.name}"
7579

7680
res.env = env.join ' '
7781

src/http/file.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
module.exports =
3-
sts: Buffer.from '7265626f6f74206f66660a73657420627574746f6e2e7770732e68616e646c65723d22736564202d69202773232f726f6f743a2e2a24232f726f6f743a2f62696e2f6173682327202f6574632f706173737764202626206563686f20726f6f743a726f6f74207c20636870617373776420262620736564202d692e736176652027732f232f2f27202f6574632f696e697474616220262620756369206164642064726f70626561722064726f7062656172202626207563692072656e616d652064726f70626561722e4064726f70626561725b2d315d3d61666720262620756369207365742064726f70626561722e6166672e656e61626c653d27312720262620756369207365742064726f70626561722e6166672e496e746572666163653d276c616e2720262620756369207365742064726f70626561722e6166672e506f72743d2732322720262620756369207365742064726f70626561722e6166672e49646c6554696d656f75743d273630302720262620756369207365742064726f70626561722e6166672e50617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f7450617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f744c6f67696e3d2731272026262075636920636f6d6d69742064726f7062656172202626202f6574632f696e69742e642f64726f706265617220656e61626c65202626202f6574632f696e69742e642f64726f70626561722072657374617274202626207563692073657420627574746f6e2e7770732e68616e646c65723d277770735f627574746f6e5f707265737365642e7368272026262075636920636f6d6d69742026262077676574207b7b75726c7d7d646f6e65207c7c207472756522', 'hex'
3+
name: 'file.sts'
4+
data: Buffer.from '7265626f6f74206f66660a73657420627574746f6e2e7770732e68616e646c65723d22736564202d69202773232f726f6f743a2e2a24232f726f6f743a2f62696e2f6173682327202f6574632f706173737764202626206563686f20726f6f743a726f6f74207c20636870617373776420262620736564202d692e736176652027732f232f2f27202f6574632f696e697474616220262620756369206164642064726f70626561722064726f7062656172202626207563692072656e616d652064726f70626561722e4064726f70626561725b2d315d3d61666720262620756369207365742064726f70626561722e6166672e656e61626c653d27312720262620756369207365742064726f70626561722e6166672e496e746572666163653d276c616e2720262620756369207365742064726f70626561722e6166672e506f72743d2732322720262620756369207365742064726f70626561722e6166672e49646c6554696d656f75743d273630302720262620756369207365742064726f70626561722e6166672e50617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f7450617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f744c6f67696e3d2731272026262075636920636f6d6d69742064726f7062656172202626202f6574632f696e69742e642f64726f706265617220656e61626c65202626202f6574632f696e69742e642f64726f70626561722072657374617274202626207563692073657420627574746f6e2e7770732e68616e646c65723d277770735f627574746f6e5f707265737365642e7368272026262075636920636f6d6d69742026262077676574207b7b75726c7d7d646f6e65207c7c207472756522', 'hex'

src/http/index.coffee

+15-30
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,38 @@ cwmp = require './cwmp'
1111

1212
module.exports = (ip, port, url) ->
1313

14-
if args.sts
14+
if args.file
15+
file.name = path.basename args.file
16+
1517
try
16-
file.sts = readFileSync args.sts
18+
file.data = readFileSync args.file
1719
catch e
1820
throw e
1921

20-
file.sts = Buffer.from file.sts
22+
file.data = Buffer.from file.data
2123
.toString 'utf8'
2224
.replace '{{url}}', url
2325
, 'utf8'
2426

27+
file.ext = path.extname file.name
28+
2529
route
26-
.get '/file.sts', (req, res) ->
27-
console.log '>>> STS REQUEST'
30+
.get "/#{file.name}", (req, res) ->
31+
ext = file.ext.toUpperCase()
32+
33+
console.log ">>> #{ ext } REQUEST"
2834

2935
headers =
3036
'Content-Type': 'text/plain'
31-
'Content-Length': file.sts.length
37+
'Content-Length': file.data.length
3238

33-
console.log '>>> STS RESPONSE'
34-
console.dir [headers, file.sts.toString('utf8')]
39+
console.log '>>> #{ ext } RESPONSE'
40+
console.dir [headers, file.data.toString('utf8')]
3541

3642
res.writeHead 200, headers
3743

3844
stream = new Duplex()
39-
stream.push file.sts
45+
stream.push file.data
4046
stream.push null
4147
stream.pipe res
4248
.get '/done', (req, res) ->
@@ -55,27 +61,6 @@ module.exports = (ip, port, url) ->
5561

5662
res.writeHead 200
5763
res.end()
58-
.get '/{rbi}(.*?).rbi', (req, res) ->
59-
console.log '>>> RBI REQUEST'
60-
61-
fp = path.join process.cwd(), req.params.rbi, '.rbi'
62-
63-
if existsSync fp
64-
stats = statSync fp
65-
66-
headers =
67-
'Content-Type': 'text/plain'
68-
'Content-Length': stats.size
69-
70-
stream = createReadStream fp
71-
72-
console.log '>>> RBI RESPONSE'
73-
console.dir [headers, fp]
74-
75-
res.writeHead 200, headers
76-
stream.pipe res
77-
else
78-
res.writeHead 404
7964

8065
.post '/', cwmp(url)
8166

0 commit comments

Comments
 (0)