diff --git a/lib/custom-commands.coffee b/lib/custom-commands.coffee index 3790940..711dea7 100644 --- a/lib/custom-commands.coffee +++ b/lib/custom-commands.coffee @@ -15,22 +15,31 @@ # along with GenieACS. If not, see . ### +path = require 'path' config = require './config' common = require './common' +FILES = {} +getFile = (filename) -> + if filename not of FILES + FILES[filename] = require(path.resolve(config.get('CONFIG_DIR'), "custom_commands/#{filename}")) + + return FILES[filename] + + exports.execute = (deviceId, command, callback) -> args = command.split(/\s+/) f = args.shift() c = args.shift() - file = require "../config/custom_commands/#{f}" + file = getFile(f) file[c](deviceId, args.join(' '), callback) exports.getFileCommands = (filename) -> commands = [] - f = require("../config/custom_commands/#{filename}") + f = getFile(filename) for k,v of f commands.push(k) return commands