From 236a0241baf155a2424c6cc0bb181caa0cb1dc95 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Sun, 9 Mar 2014 19:59:34 +0300 Subject: [PATCH] Better file structure and naming --- .npmignore | 22 +++++++------------ README.md | 14 ++++++------ bin/{genieacs-files => genieacs-cwmp} | 6 ++--- bin/{genieacs-acs => genieacs-fs} | 6 ++--- bin/{genieacs-api => genieacs-nbi} | 6 ++--- httpscert.crt => config/httpscert-sample.crt | 0 httpscert.key => config/httpscert-sample.key | 0 .../api-functions.coffee | 0 auth.coffee => lib/auth.coffee | 0 common.coffee => lib/common.coffee | 0 config.coffee => lib/config.coffee | 9 ++++---- .../custom-commands.coffee | 0 acs.coffee => lib/cwmp.coffee | 22 +++++++++---------- db.coffee => lib/db.coffee | 0 files.coffee => lib/fs.coffee | 0 mongo-query.coffee => lib/mongo-query.coffee | 0 api.coffee => lib/nbi.coffee | 0 normalize.coffee => lib/normalize.coffee | 0 parameters.coffee => lib/parameters.coffee | 0 presets.coffee => lib/presets.coffee | 0 query.coffee => lib/query.coffee | 0 tr-069.coffee => lib/soap.coffee | 2 +- tasks.coffee => lib/tasks.coffee | 0 package.json | 4 ++-- test/methods.coffee | 2 +- 25 files changed, 44 insertions(+), 49 deletions(-) rename bin/{genieacs-files => genieacs-cwmp} (66%) rename bin/{genieacs-acs => genieacs-fs} (67%) rename bin/{genieacs-api => genieacs-nbi} (67%) rename httpscert.crt => config/httpscert-sample.crt (100%) rename httpscert.key => config/httpscert-sample.key (100%) rename api-functions.coffee => lib/api-functions.coffee (100%) rename auth.coffee => lib/auth.coffee (100%) rename common.coffee => lib/common.coffee (100%) rename config.coffee => lib/config.coffee (84%) rename custom-commands.coffee => lib/custom-commands.coffee (100%) rename acs.coffee => lib/cwmp.coffee (96%) rename db.coffee => lib/db.coffee (100%) rename files.coffee => lib/fs.coffee (100%) rename mongo-query.coffee => lib/mongo-query.coffee (100%) rename api.coffee => lib/nbi.coffee (100%) rename normalize.coffee => lib/normalize.coffee (100%) rename parameters.coffee => lib/parameters.coffee (100%) rename presets.coffee => lib/presets.coffee (100%) rename query.coffee => lib/query.coffee (100%) rename tr-069.coffee => lib/soap.coffee (99%) rename tasks.coffee => lib/tasks.coffee (100%) diff --git a/.npmignore b/.npmignore index 4c8ba05..28a805c 100644 --- a/.npmignore +++ b/.npmignore @@ -1,20 +1,14 @@ -* -!*.js +*~ +.npmignore -config/*.js +config/* !config/*-sample.* +!config/custom_commands -!tools/* +debug/* +!debug/.gitkeep + +lib/*.coffee tools/*.coffee - -!test/* test/*.coffee -!bin/genieacs-acs -!bin/genieacs-api -!bin/genieacs-files - -!httpscert.key -!httpscert.crt - -*~ diff --git a/README.md b/README.md index ecbe5c5..941d7e8 100644 --- a/README.md +++ b/README.md @@ -30,23 +30,23 @@ Alternatively, you can use git to get the latest development version (not recomm Finally, run the following in GNU Screen session or something similar: - genieacs-acs + genieacs-cwmp This is the service that the CPEs will communicate with. It listens to port 7547 by default (see config/config.json). Configure the ACS URL of your devices accordingly. - genieacs-api + genieacs-nbi -This is the API module. It exposes the API on port 7557 by default. This is needed for the GUI front end to communicate with. +This is the northbound interface module. It exposes a REST API on port 7557 by default. This is needed for the GUI front end to communicate with. - genieacs-files + genieacs-fs This is the file server from which the CPEs will download firmware images and other types of files. You can use stream redirection to output to log files: - genieacs-acs >> /var/log/genieacs-acs.log 2>> /var/log/genieacs-acs-err.log - genieacs-api >> /var/log/genieacs-api.log 2>> /var/log/genieacs-api-err.log - genieacs-files >> /var/log/genieacs-files.log 2>> /var/log/genieacs-files-err.log + genieacs-cwmp >> /var/log/genieacs-cwmp.log 2>> /var/log/genieacs-cwmp-err.log + genieacs-nbi >> /var/log/genieacs-nbi.log 2>> /var/log/genieacs-nbi-err.log + genieacs-fs >> /var/log/genieacs-fs.log 2>> /var/log/genieacs-fs-err.log For further details about installation and configuration, refer to the [wiki section](https://github.com/zaidka/genieacs/wiki). diff --git a/bin/genieacs-files b/bin/genieacs-cwmp similarity index 66% rename from bin/genieacs-files rename to bin/genieacs-cwmp index c94adeb..a135c9e 100755 --- a/bin/genieacs-files +++ b/bin/genieacs-cwmp @@ -2,9 +2,9 @@ var path = require('path'); var fs = require('fs'); -var dir = path.join(path.dirname(fs.realpathSync(__filename)), '../'); -process.title = 'genieacs-files'; +var dir = path.join(path.dirname(fs.realpathSync(__filename)), '../lib/'); +process.title = 'genieacs-cwmp'; process.chdir(dir); -require(path.join(dir, './files')); +require(path.join(dir, './cwmp')); diff --git a/bin/genieacs-acs b/bin/genieacs-fs similarity index 67% rename from bin/genieacs-acs rename to bin/genieacs-fs index ab19d1f..67d4571 100755 --- a/bin/genieacs-acs +++ b/bin/genieacs-fs @@ -2,9 +2,9 @@ var path = require('path'); var fs = require('fs'); -var dir = path.join(path.dirname(fs.realpathSync(__filename)), '../'); -process.title = 'genieacs-acs'; +var dir = path.join(path.dirname(fs.realpathSync(__filename)), '../lib/'); +process.title = 'genieacs-fs'; process.chdir(dir); -require(path.join(dir, './acs')); +require(path.join(dir, './fs')); diff --git a/bin/genieacs-api b/bin/genieacs-nbi similarity index 67% rename from bin/genieacs-api rename to bin/genieacs-nbi index 044d3ce..6bf4f72 100755 --- a/bin/genieacs-api +++ b/bin/genieacs-nbi @@ -2,9 +2,9 @@ var path = require('path'); var fs = require('fs'); -var dir = path.join(path.dirname(fs.realpathSync(__filename)), '../'); -process.title = 'genieacs-api'; +var dir = path.join(path.dirname(fs.realpathSync(__filename)), '../lib/'); +process.title = 'genieacs-nbi'; process.chdir(dir); -require(path.join(dir, './api')); +require(path.join(dir, './nbi')); diff --git a/httpscert.crt b/config/httpscert-sample.crt similarity index 100% rename from httpscert.crt rename to config/httpscert-sample.crt diff --git a/httpscert.key b/config/httpscert-sample.key similarity index 100% rename from httpscert.key rename to config/httpscert-sample.key diff --git a/api-functions.coffee b/lib/api-functions.coffee similarity index 100% rename from api-functions.coffee rename to lib/api-functions.coffee diff --git a/auth.coffee b/lib/auth.coffee similarity index 100% rename from auth.coffee rename to lib/auth.coffee diff --git a/common.coffee b/lib/common.coffee similarity index 100% rename from common.coffee rename to lib/common.coffee diff --git a/config.coffee b/lib/config.coffee similarity index 84% rename from config.coffee rename to lib/config.coffee index 1fa24b9..fdd646e 100644 --- a/config.coffee +++ b/lib/config.coffee @@ -30,14 +30,15 @@ exports.MONGODB_OPTIONS = { } # load configuration -c = require('./config/config') +c = require('../config/config') for k, v of c exports[k] = v # load parameter configurations -exports.PARAMETERS = require('./config/parameters') +exports.PARAMETERS = require('../config/parameters') # load authentication scripts -exports.auth = require('./config/auth') +exports.auth = require('../config/auth') + +exports.CUSTOM_COMMANDS = require('../config/custom_commands') -exports.CUSTOM_COMMANDS = require('./config/custom_commands') diff --git a/custom-commands.coffee b/lib/custom-commands.coffee similarity index 100% rename from custom-commands.coffee rename to lib/custom-commands.coffee diff --git a/acs.coffee b/lib/cwmp.coffee similarity index 96% rename from acs.coffee rename to lib/cwmp.coffee index c28d8c7..0668967 100644 --- a/acs.coffee +++ b/lib/cwmp.coffee @@ -3,7 +3,7 @@ common = require './common' util = require 'util' http = require 'http' https = require 'https' -tr069 = require './tr-069' +soap = require './soap' tasks = require './tasks' normalize = require('./normalize').normalize db = require './db' @@ -150,7 +150,7 @@ inform = (currentRequest, cwmpRequest) -> updateAndRespond = () -> updateDevice(currentRequest, actions, (err) -> throw err if err - res = tr069.response(cwmpRequest.id, {methodResponse : {type : 'InformResponse'}}, {deviceId : currentRequest.deviceId}) + res = soap.response(cwmpRequest.id, {methodResponse : {type : 'InformResponse'}}, {deviceId : currentRequest.deviceId}) writeResponse(currentRequest, res) ) @@ -245,7 +245,7 @@ runTask = (currentRequest, task, methodResponse) -> f = () -> db.redisClient.setex(String(task._id), config.CACHE_DURATION, JSON.stringify(task), (err) -> throw err if err - res = tr069.response(task._id, cwmpResponse) + res = soap.response(task._id, cwmpResponse) writeResponse(currentRequest, res) ) @@ -293,7 +293,7 @@ assertPresets = (currentRequest) -> presetsHash = res[1] if devicePresetsHash? and devicePresetsHash == presetsHash # no discrepancy, return empty response - res = tr069.response(null, {}) + res = soap.response(null, {}) writeResponse(currentRequest, res) else db.getPresetsObjectsAliases((allPresets, allObjects, allAliases) -> @@ -334,7 +334,7 @@ assertPresets = (currentRequest) -> runTask(currentRequest, task, {}) ) else - res = tr069.response(null, {}, {}) + res = soap.response(null, {}, {}) writeResponse(currentRequest, res) ) ) @@ -392,7 +392,7 @@ listener = (httpRequest, httpResponse) -> httpRequest.addListener 'end', () -> cwmpResponse = {} - cwmpRequest = tr069.request(httpRequest) + cwmpRequest = soap.request(httpRequest) currentRequest = { httpRequest : httpRequest @@ -417,12 +417,12 @@ listener = (httpRequest, httpResponse) -> # do nothing util.log("#{currentRequest.deviceId}: Transfer complete") cwmpResponse.methodResponse = {type : 'TransferCompleteResponse'} - res = tr069.response(cwmpRequest.id, cwmpResponse, cookies) + res = soap.response(cwmpRequest.id, cwmpResponse, cookies) writeResponse(currentRequest, res) else if cwmpRequest.methodRequest.type is 'RequestDownload' requestDownloadResponse = () -> cwmpResponse.methodResponse = {type : 'RequestDownloadResponse'} - res = tr069.response(cwmpRequest.id, cwmpResponse, cookies) + res = soap.response(cwmpRequest.id, cwmpResponse, cookies) writeResponse(currentRequest, res) fileType = cwmpRequest.methodRequest.fileType util.log("#{currentRequest.deviceId}: RequestDownload (#{fileType})") @@ -480,7 +480,7 @@ listener = (httpRequest, httpResponse) -> taskId = cwmpRequest.id if not taskId # Fault not related to a task. return empty response. - res = tr069.response(null, {}, {}) + res = soap.response(null, {}, {}) writeResponse(currentRequest, res) return @@ -516,8 +516,8 @@ if cluster.isMaster cluster.fork() else options = { - key: fs.readFileSync('httpscert.key'), - cert: fs.readFileSync('httpscert.crt') + key: fs.readFileSync('../config/httpscert.key'), + cert: fs.readFileSync('../config/httpscert.crt') } httpServer = http.createServer(listener) diff --git a/db.coffee b/lib/db.coffee similarity index 100% rename from db.coffee rename to lib/db.coffee diff --git a/files.coffee b/lib/fs.coffee similarity index 100% rename from files.coffee rename to lib/fs.coffee diff --git a/mongo-query.coffee b/lib/mongo-query.coffee similarity index 100% rename from mongo-query.coffee rename to lib/mongo-query.coffee diff --git a/api.coffee b/lib/nbi.coffee similarity index 100% rename from api.coffee rename to lib/nbi.coffee diff --git a/normalize.coffee b/lib/normalize.coffee similarity index 100% rename from normalize.coffee rename to lib/normalize.coffee diff --git a/parameters.coffee b/lib/parameters.coffee similarity index 100% rename from parameters.coffee rename to lib/parameters.coffee diff --git a/presets.coffee b/lib/presets.coffee similarity index 100% rename from presets.coffee rename to lib/presets.coffee diff --git a/query.coffee b/lib/query.coffee similarity index 100% rename from query.coffee rename to lib/query.coffee diff --git a/tr-069.coffee b/lib/soap.coffee similarity index 99% rename from tr-069.coffee rename to lib/soap.coffee index aaace1c..2566166 100644 --- a/tr-069.coffee +++ b/lib/soap.coffee @@ -1,6 +1,6 @@ libxmljs = require 'libxmljs' -SERVER_NAME = "GenieACS/#{require('./package.json').version}" +SERVER_NAME = "GenieACS/#{require('../package.json').version}" NAMESPACES = { 'soap-enc' : 'http://schemas.xmlsoap.org/soap/encoding/', diff --git a/tasks.coffee b/lib/tasks.coffee similarity index 100% rename from tasks.coffee rename to lib/tasks.coffee diff --git a/package.json b/package.json index 79923a6..5bb9170 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ }, "scripts": { "prepublish": "npm run compile", - "compile": "coffee -cb *.coffee test/*.coffee tools/*.coffee", - "configure": "cp ./config/config-sample.json ./config/config.json; cp ./config/parameters-sample.json ./config/parameters.json; cp ./config/custom_commands-sample.json ./config/custom_commands.json; cp ./config/auth-sample.js ./config/auth.js", + "compile": "coffee -cb lib/*.coffee test/*.coffee tools/*.coffee", + "configure": "cp ./config/config-sample.json ./config/config.json; cp ./config/parameters-sample.json ./config/parameters.json; cp ./config/custom_commands-sample.json ./config/custom_commands.json; cp ./config/auth-sample.js ./config/auth.js; cp ./config/httpscert-sample.key ./config/httpscert.key; cp ./config/httpscert-sample.crt ./config/httpscert.crt", "install": "npm run configure", "test": "node test" } diff --git a/test/methods.coffee b/test/methods.coffee index 3ac8c97..1e12a10 100644 --- a/test/methods.coffee +++ b/test/methods.coffee @@ -1,4 +1,4 @@ -common = require '../common' +common = require '../lib/common' NAMESPACES = { 'soap-enc' : 'http://schemas.xmlsoap.org/soap/encoding/',