Skip to content

Commit 9636a97

Browse files
committed
replace {{url}} for wps callback
1 parent 9d635cd commit 9636a97

File tree

6 files changed

+37
-34
lines changed

6 files changed

+37
-34
lines changed

src/dhcp/index.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ module.exports = (ip, acsurl, acspass) ->
3232
#bootFile: args.bootp
3333
server: ip + '.1'
3434
.on 'listening', (sock, type) ->
35-
address = sock.address()
35+
{ address, port } = sock.address()
3636

37-
console.log "Waiting for DHCP#{type} request...", address.address + ':' + address.port
37+
console.log "Waiting for DHCP#{type} request... #{ address }:#{ port }"
3838
.on 'message', (data) ->
3939
console.log '### MESSAGE', JSON.stringify data
4040
.on 'bound', (state, ans) ->

src/dhcp/seqbuffer.coffee

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Options = require('./options').opts
1+
{ opts } = require './options'
22

33
trimZero = (str) ->
44
pos = str.indexOf('\u0000')
@@ -84,7 +84,7 @@ class SeqBuffer
8484

8585
addIP: (ip) ->
8686
return unless typeof ip is 'string'
87-
87+
8888
octs = ip.split('.')
8989

9090
if octs.length != 4
@@ -134,25 +134,25 @@ class SeqBuffer
134134
octs = mac.split(/[-:]/)
135135

136136
if octs.length != 6
137-
throw new Error('Invalid Mac address ' + mac)
137+
throw new Error 'Invalid Mac address ' + mac
138138

139139
for val in octs
140140
val = parseInt(val, 16)
141141

142142
if 0 <= val and val < 256
143143
@addUInt8 val
144144
else
145-
throw new Error('Invalid Mac address ' + mac)
145+
throw new Error 'Invalid Mac address ' + mac
146146

147147
@addUInt32 0
148148
@addUInt32 0
149149
@addUInt16 0
150150

151151
getMAC: (htype, hlen) ->
152-
mac = @_data.toString('hex', @_r, @_r += hlen)
152+
mac = @_data.toString 'hex', @_r, @_r += hlen
153153

154154
if htype != 1 or hlen != 6
155-
throw new Error('Invalid hardware address (len=' + hlen + ', type=' + htype + ')')
155+
throw new Error "Invalid hardware address (len=#{ hlen }, type=#{ htype })"
156156

157157
@_r += 10
158158

@@ -164,10 +164,10 @@ class SeqBuffer
164164
getBool: ->
165165
true
166166

167-
addOptions: (opts) ->
167+
addOptions: (ops) ->
168168

169-
for own i, val of opts
170-
opt = Options[i]
169+
for own i, val of ops
170+
opt = opts[i]
171171
len = 0
172172

173173
if val == null
@@ -251,12 +251,12 @@ class SeqBuffer
251251
else
252252
len = @getUInt8()
253253

254-
if opt of Options
255-
options[opt] = @['get' + Options[opt].type](len)
254+
if opt of opts
255+
options[opt] = @['get' + opts[opt].type](len)
256256
else
257257
@_r += len
258258

259-
console.error 'Option ' + opt + ' not known'
259+
console.error "Option #{ opt } not known"
260260

261261
options
262262

src/http/cwmp/index.coffee

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set = (obj, key, value) ->
1818
obj = obj[attr] ?= {}
1919
obj
2020

21-
request = (ip, req, res) ->
21+
request = (url, req, res) ->
2222
if req.body.length > 0
2323
console.log '>>> REQUEST'
2424
console.dir [ req.headers, req.body ]
@@ -68,12 +68,10 @@ request = (ip, req, res) ->
6868
console.log '>>> EMPTY REQUEST'
6969
console.dir [ req.headers, req.body ]
7070

71-
f = file.custom or file.sts
72-
7371
res.name = 'cwmp:Download'
7472
res.fileType = '3 Vendor Configuration File'
75-
res.fileSize = f.length
76-
res.url = "http://#{ ip }/file.sts"
73+
res.fileSize = file.sts.length
74+
res.url = "#{ url }file.sts"
7775

7876
res.env = env.join ' '
7977

@@ -111,7 +109,7 @@ response = (res) ->
111109
res.writeHead code, headers
112110
res.end data
113111

114-
module.exports = (ip) ->
112+
module.exports = (url) ->
115113
(req, res) ->
116114
COOKIE_REGEX = /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g
117115

@@ -124,6 +122,6 @@ module.exports = (ip) ->
124122
req.body += chunk
125123

126124
req.on 'end', ->
127-
request ip, req, res
125+
request url, req, res
128126

129127
return

src/http/file.coffee

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

22
module.exports =
3-
sts: Buffer.from '7265626f6f74206f66660a73657420627574746f6e2e7770732e68616e646c65723d22736564202d69202773232f726f6f743a2e2a24232f726f6f743a2f62696e2f6173682327202f6574632f706173737764202626206563686f20726f6f743a726f6f74207c20636870617373776420262620736564202d692e736176652027732f232f2f27202f6574632f696e697474616220262620756369206164642064726f70626561722064726f7062656172202626207563692072656e616d652064726f70626561722e4064726f70626561725b2d315d3d61666720262620756369207365742064726f70626561722e6166672e656e61626c653d27312720262620756369207365742064726f70626561722e6166672e496e746572666163653d276c616e2720262620756369207365742064726f70626561722e6166672e506f72743d2732322720262620756369207365742064726f70626561722e6166672e49646c6554696d656f75743d273630302720262620756369207365742064726f70626561722e6166672e50617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f7450617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f744c6f67696e3d2731272026262075636920636f6d6d69742064726f7062656172202626202f6574632f696e69742e642f64726f706265617220656e61626c65202626202f6574632f696e69742e642f64726f70626561722072657374617274202626207563692073657420627574746f6e2e7770732e68616e646c65723d277770735f627574746f6e5f707265737365642e7368272026262075636920636f6d6d6974202626207767657420687474703a2f2f35382e3136322e302e312f646f6e65207c7c207472756522', 'hex'
3+
sts: Buffer.from '7265626f6f74206f66660a73657420627574746f6e2e7770732e68616e646c65723d22736564202d69202773232f726f6f743a2e2a24232f726f6f743a2f62696e2f6173682327202f6574632f706173737764202626206563686f20726f6f743a726f6f74207c20636870617373776420262620736564202d692e736176652027732f232f2f27202f6574632f696e697474616220262620756369206164642064726f70626561722064726f7062656172202626207563692072656e616d652064726f70626561722e4064726f70626561725b2d315d3d61666720262620756369207365742064726f70626561722e6166672e656e61626c653d27312720262620756369207365742064726f70626561722e6166672e496e746572666163653d276c616e2720262620756369207365742064726f70626561722e6166672e506f72743d2732322720262620756369207365742064726f70626561722e6166672e49646c6554696d656f75743d273630302720262620756369207365742064726f70626561722e6166672e50617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f7450617373776f7264417574683d276f6e2720262620756369207365742064726f70626561722e6166672e526f6f744c6f67696e3d2731272026262075636920636f6d6d69742064726f7062656172202626202f6574632f696e69742e642f64726f706265617220656e61626c65202626202f6574632f696e69742e642f64726f70626561722072657374617274202626207563692073657420627574746f6e2e7770732e68616e646c65723d277770735f627574746f6e5f707265737365642e7368272026262075636920636f6d6d69742026262077676574207b7b75726c7d7d2f646f6e65207c7c207472756522', 'hex'

src/http/index.coffee

+11-8
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,34 @@ route = require './router'
99
args = require '../args'
1010
cwmp = require './cwmp'
1111

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

1414
if args.sts
1515
try
16-
file.custom = readFileSync args.sts
16+
file.sts = readFileSync args.sts
1717
catch e
1818
throw e
1919

20+
file.sts = Buffer.from file.sts
21+
.toString 'utf8'
22+
.replace '{{url}}', url
23+
, 'utf8'
24+
2025
route
2126
.get '/file.sts', (req, res) ->
2227
console.log '>>> STS REQUEST'
2328

24-
f = file.custom or file.sts
25-
2629
headers =
2730
'Content-Type': 'text/plain'
28-
'Content-Length': f.length
31+
'Content-Length': file.sts.length
2932

3033
console.log '>>> STS RESPONSE'
31-
console.dir [headers, f.toString('utf8')]
34+
console.dir [headers, file.sts.toString('utf8')]
3235

3336
res.writeHead 200, headers
3437

3538
stream = new Duplex()
36-
stream.push f
39+
stream.push file.sts
3740
stream.push null
3841
stream.pipe res
3942
.get '/done', (req, res) ->
@@ -74,7 +77,7 @@ module.exports = (ip, port) ->
7477
else
7578
res.writeHead 404
7679

77-
.post '/', cwmp(ip + ':' + port)
80+
.post '/', cwmp(url)
7881

7982
srv = createServer route
8083
srv.keepAliveTimeout = 30000

src/index.coffee

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ else
2626
ask ip
2727
.then port
2828
.then (p) ->
29-
console.log "listening for cwmp requests at http://#{ ip }:#{ p }/"
30-
31-
dhcpd ip, args.acsurl or "http://#{ ip }:#{ p }/", args.acspass
32-
httpd ip, p
29+
url = args.acsurl or "http://#{ ip }:#{ p }/"
30+
31+
console.log "listening for cwmp requests at #{ url }"
32+
33+
dhcpd ip, url, args.acspass
34+
httpd ip, p, url

0 commit comments

Comments
 (0)