Implemented HTTPS support
This commit is contained in:
1 parent
85fc5edc8d
commit
20fa79c0a3
4 files changed
+66
-22
No files matched your search
+32
-22
@@ -2,12 +2,14 @@ config = require './config'
|
|||||||
common = require './common'
|
common = require './common'
|
||||||
util = require 'util'
|
util = require 'util'
|
||||||
http = require 'http'
|
http = require 'http'
|
||||||
|
https = require 'https'
|
||||||
tr069 = require './tr-069'
|
tr069 = require './tr-069'
|
||||||
tasks = require './tasks'
|
tasks = require './tasks'
|
||||||
sanitize = require('./sanitize').sanitize
|
sanitize = require('./sanitize').sanitize
|
||||||
db = require './db'
|
db = require './db'
|
||||||
presets = require './presets'
|
presets = require './presets'
|
||||||
mongodb = require 'mongodb'
|
mongodb = require 'mongodb'
|
||||||
|
fs = require 'fs'
|
||||||
|
|
||||||
|
|
||||||
applyConfigurations = (currentRequest, taskList) ->
|
applyConfigurations = (currentRequest, taskList) ->
|
||||||
@@ -106,7 +108,7 @@ runTask = (currentRequest, task, methodResponse) ->
|
|||||||
nextTask(currentRequest)
|
nextTask(currentRequest)
|
||||||
)
|
)
|
||||||
when tasks.STATUS_FAULT
|
when tasks.STATUS_FAULT
|
||||||
util.log("#{currentRequest.deviceId}: Fault response for task #{taskId}")
|
util.log("#{currentRequest.deviceId}: Fault response for task #{task._id}")
|
||||||
db.saveTask(task, (err) ->
|
db.saveTask(task, (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(null, cwmpResponse)
|
res = tr069.response(null, cwmpResponse)
|
||||||
@@ -166,26 +168,7 @@ nextTask = (currentRequest) ->
|
|||||||
runTask(currentRequest, task, {})
|
runTask(currentRequest, task, {})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
listener = (httpRequest, httpResponse) ->
|
||||||
cluster = require 'cluster'
|
|
||||||
numCPUs = require('os').cpus().length
|
|
||||||
|
|
||||||
if cluster.isMaster
|
|
||||||
cluster.on('listening', (worker, address) ->
|
|
||||||
util.log("Worker #{worker.process.pid} listening to #{address.address}:#{address.port}")
|
|
||||||
)
|
|
||||||
|
|
||||||
cluster.on('exit', (worker, code, signal) ->
|
|
||||||
util.log("Worker #{worker.process.pid} died (#{worker.process.exitCode})")
|
|
||||||
setTimeout(()->
|
|
||||||
cluster.fork()
|
|
||||||
, config.WORKER_RESPAWN_TIME)
|
|
||||||
)
|
|
||||||
|
|
||||||
for i in [1 .. numCPUs]
|
|
||||||
cluster.fork()
|
|
||||||
else
|
|
||||||
server = http.createServer (httpRequest, httpResponse) ->
|
|
||||||
if httpRequest.method != 'POST'
|
if httpRequest.method != 'POST'
|
||||||
#console.log '>>> 405 Method Not Allowed'
|
#console.log '>>> 405 Method Not Allowed'
|
||||||
httpResponse.writeHead 405, {'Allow': 'POST'}
|
httpResponse.writeHead 405, {'Allow': 'POST'}
|
||||||
@@ -274,5 +257,32 @@ else
|
|||||||
nextTask(currentRequest)
|
nextTask(currentRequest)
|
||||||
|
|
||||||
|
|
||||||
server.listen config.ACS_PORT, config.ACS_INTERFACE
|
cluster = require 'cluster'
|
||||||
|
numCPUs = require('os').cpus().length
|
||||||
|
|
||||||
|
if cluster.isMaster
|
||||||
|
cluster.on('listening', (worker, address) ->
|
||||||
|
util.log("Worker #{worker.process.pid} listening to #{address.address}:#{address.port}")
|
||||||
|
)
|
||||||
|
|
||||||
|
cluster.on('exit', (worker, code, signal) ->
|
||||||
|
util.log("Worker #{worker.process.pid} died (#{worker.process.exitCode})")
|
||||||
|
setTimeout(()->
|
||||||
|
cluster.fork()
|
||||||
|
, config.WORKER_RESPAWN_TIME)
|
||||||
|
)
|
||||||
|
|
||||||
|
for i in [1 .. numCPUs]
|
||||||
|
cluster.fork()
|
||||||
|
else
|
||||||
|
options = {
|
||||||
|
key: fs.readFileSync('httpscert.key'),
|
||||||
|
cert: fs.readFileSync('httpscert.crt')
|
||||||
|
}
|
||||||
|
|
||||||
|
httpServer = http.createServer(listener)
|
||||||
|
httpsServer = https.createServer(options, listener)
|
||||||
|
|
||||||
|
httpServer.listen(config.ACS_PORT, config.ACS_INTERFACE)
|
||||||
|
httpsServer.listen(config.ACS_HTTPS_PORT, config.ACS_HTTPS_INTERFACE)
|
||||||
#console.log "Server listening on port #{config.ACS_PORT}"
|
#console.log "Server listening on port #{config.ACS_PORT}"
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
exports.DATABASE_NAME = 'genie'
|
exports.DATABASE_NAME = 'genie'
|
||||||
exports.ACS_PORT = 7547 # CWMP port as assigned by IANA
|
exports.ACS_PORT = 7547 # CWMP port as assigned by IANA
|
||||||
|
exports.ACS_HTTPS_PORT = 7548
|
||||||
exports.ACS_INTERFACE = '0.0.0.0'
|
exports.ACS_INTERFACE = '0.0.0.0'
|
||||||
|
exports.ACS_HTTPS_INTERFACE = '0.0.0.0'
|
||||||
exports.API_PORT = 7557
|
exports.API_PORT = 7557
|
||||||
exports.API_INTERFACE = '0.0.0.0'
|
exports.API_INTERFACE = '0.0.0.0'
|
||||||
exports.FILES_PORT = 7567
|
exports.FILES_PORT = 7567
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICqTCCAhICCQDSrolRw1qPBzANBgkqhkiG9w0BAQUFADCBmDELMAkGA1UEBhMC
|
||||||
|
SVExFTATBgNVBAgMDFN1bGF5bWFuaXlhaDEVMBMGA1UEBwwMU3VsYXltYW5peWFo
|
||||||
|
MQ8wDQYDVQQKDAZGYW5vb3MxEzARBgNVBAsMClRlY2hub2xvZ3kxDjAMBgNVBAMM
|
||||||
|
BWdlbmllMSUwIwYJKoZIhvcNAQkBFhZ6YWlkLmFiZHVsbGFAZmFub29zLmlxMB4X
|
||||||
|
DTEzMDIxNzEyNTYzN1oXDTE0MDIxNzEyNTYzN1owgZgxCzAJBgNVBAYTAklRMRUw
|
||||||
|
EwYDVQQIDAxTdWxheW1hbml5YWgxFTATBgNVBAcMDFN1bGF5bWFuaXlhaDEPMA0G
|
||||||
|
A1UECgwGRmFub29zMRMwEQYDVQQLDApUZWNobm9sb2d5MQ4wDAYDVQQDDAVnZW5p
|
||||||
|
ZTElMCMGCSqGSIb3DQEJARYWemFpZC5hYmR1bGxhQGZhbm9vcy5pcTCBnzANBgkq
|
||||||
|
hkiG9w0BAQEFAAOBjQAwgYkCgYEAxtHC3jlOoVsZQ9I8Wgd+8NkEaRfc01lRIAzj
|
||||||
|
eWuUO/xNY54EUDHecRxwolHtoGkkZAp4kKR3uUVdAo9uXmNT2CeeZ5lfRoa8WmgG
|
||||||
|
Yd6PExsdc4ZeKcw20XrKtQICqmU6rGlLERMFX97ejQh3eUmqwbzNaXiURxcKGdeK
|
||||||
|
2C/NxoUCAwEAATANBgkqhkiG9w0BAQUFAAOBgQAYFw6dy/z74ahnA5QpuJOjjTrt
|
||||||
|
AJaL9iuL1xS6TFfzne9UMIT+fFJsgSy6xx3TGkvbZJTnCzJN7I2uqmAhMoGFy7Ea
|
||||||
|
svCCkj8U5qkjqgwwi7IbwQ7fXxTVdPqUlkIdNB2YLDELksxCX+ZzGQPiFB8WrSoO
|
||||||
|
OBvB+hhPFpgp3aO2AQ==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIICXgIBAAKBgQDG0cLeOU6hWxlD0jxaB37w2QRpF9zTWVEgDON5a5Q7/E1jngRQ
|
||||||
|
Md5xHHCiUe2gaSRkCniQpHe5RV0Cj25eY1PYJ55nmV9GhrxaaAZh3o8TGx1zhl4p
|
||||||
|
zDbResq1AgKqZTqsaUsREwVf3t6NCHd5SarBvM1peJRHFwoZ14rYL83GhQIDAQAB
|
||||||
|
AoGAR4NpuW8ZhlZzNv7m8Gcj1NPqjzajGm5VDNc19xWoAw+UcpGC8amOXlcheHFJ
|
||||||
|
rNpE2asehMBzw/NcKjCXPWIy5LnGmttJMN2EbT2h/+uxBIM5IUc+joF744xF4C0t
|
||||||
|
5zrtqQYJxC7sBLX2vf7nY6iuovUM7fHEwACyV3Rpw3zdZf0CQQDiqW+ugLKcfS/c
|
||||||
|
6hkGTxeYWF4gUJTf3ke3au8nyMmUhyBwOuP4kpO72mK8bMLtjZRk3g6YChA4qH41
|
||||||
|
nfXUXIh7AkEA4I2/zj4GDjjspDR+/tX0iUHQk1Rm2CRmRXXFJV1f688OLODCcOFK
|
||||||
|
Ms/+qnbe41wXo1NUxCqVrnPwEh3MVl88/wJBANUTpXqtX7s+8ETECTxmE+9Se0Hz
|
||||||
|
ntCJXG/v5d1Ho0Cueu8mXXMrEBiTpygtMl4xL2RXX+7L3w30T5lF4nh9eIsCQQDY
|
||||||
|
DmsbdL/81TaTc9MxPQlxOzsFVrMxiixA7uTGY8ZULD/2XDeZxprOsyPUPlWMquIv
|
||||||
|
ipFHwbWNSg4WUEd4X2BfAkEAytze+0mCd0WCsKbKwfTQnmJ3bK7JQywtC03llWyA
|
||||||
|
Om3Vl61Syaa7M2hl5rLvitZMvU1Wd0s8raOXN8RUuRXZBw==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
Reference in new issue
Block a user