diff --git a/HELP.md b/HELP.md index a13fe3ab..bb6b2484 100644 --- a/HELP.md +++ b/HELP.md @@ -76,6 +76,7 @@ Cloud Commander supports command line parameters: | `--progress` | show progress of file operations | `--open` | open web browser when server started | `--one-panel-mode` | set one panel mode + `--config-dialog` | enable config dialog | `--no-server` | do not start server | `--no-auth` | disable authorization | `--no-online` | load scripts from local server @@ -83,6 +84,7 @@ Cloud Commander supports command line parameters: | `--no-minify` | disable minification | `--no-progress` | do not show progress of file operations | `--no-one-panel-mode` | unset one panel mode +| `--no-config-dialog` | disable config dialog If no parameters given Cloud Commander reads information from `~/.cloudcmd.json` and use port from it (`8000` default). if port variables `PORT` or `VCAP_APP_PORT` isn't exist. diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 56c29259..8fadc07e 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -32,6 +32,7 @@ var Info = require('../package'), 'open', 'minify', 'progress', + 'config-dialog', 'one-panel-mode' ], default: { @@ -47,6 +48,7 @@ var Info = require('../package'), prefix : config('prefix') || '', progress : config('progress'), + 'config-dialog': defaultTrue(config('configDialog')), 'one-panel-mode': config('onePanelMode'), }, alias: { @@ -85,6 +87,7 @@ if (args.version) { config('prefix', args.prefix); config('root', args.root); config('onePanelMode', args['one-panel-mode']); + config('configDialog', args['config-dialog']); readConfig(args.config); @@ -107,6 +110,13 @@ if (args.version) { }); } +function defaultTrue(value) { + if (typeof value === 'undefined') + return true; + + return value; +} + function validateRoot(root) { var validate = require('../lib/server/validate'); validate.root(root, console.log); diff --git a/json/config.json b/json/config.json index 7d6ab83c..230cce4a 100644 --- a/json/config.json +++ b/json/config.json @@ -20,5 +20,6 @@ "root": "/", "prefix": "", "progress": true, - "onePanelMode": false + "onePanelMode": false, + "configDialog": true } diff --git a/json/help.json b/json/help.json index 3ec49264..e4448886 100644 --- a/json/help.json +++ b/json/help.json @@ -14,6 +14,7 @@ "--minify ": "enable minification", "--progress ": "show progress of file operations", "--one-panel-mode ": "set one panel mode", + "--config-dialog ": "enable config dialog", "--open ": "open web browser when server started", "--no-server ": "do not start server", "--no-auth ": "disable authorization", @@ -21,5 +22,6 @@ "--no-open ": "do not open web browser when server started", "--no-minify ": "disable minification", "--no-progress ": "do not show progress of file operations", - "--no-one-panel-mode ": "unset one panel mode" + "--no-one-panel-mode ": "unset one panel mode", + "--no-config-dialog ": "disable config dialog" } diff --git a/lib/client/config.js b/lib/client/config.js index a3393a18..d1247577 100644 --- a/lib/client/config.js +++ b/lib/client/config.js @@ -293,7 +293,16 @@ var CloudCmd, Util, DOM, io; } } - init(); + DOM.Files.get('config', function(error, config) { + if (error) + return Dialog.alert(TITLE, error); + + if (!config.configDialog) + return; + + init(); + }); } })(CloudCmd, Util, DOM); + diff --git a/lib/server/config.js b/lib/server/config.js index 5d8105b7..f4239a95 100644 --- a/lib/server/config.js +++ b/lib/server/config.js @@ -48,11 +48,10 @@ module.exports = manage; module.exports.save = save; module.exports.middle = middle; module.exports.listen = function(socket, authCheck) { - if (!socket) - throw Error('socket could not be empty!'); + check(socket, authCheck); - if (authCheck && typeof authCheck !== 'function') - throw Error('authCheck should be function!'); + if (!manage('configDialog')) + return middle; listen(socket, authCheck); @@ -115,6 +114,8 @@ function connection(socket) { } function middle(req, res, next) { + var noConfigDialog = !manage('configDialog'); + if (req.url !== apiURL + '/config') { next(); } else { @@ -124,6 +125,11 @@ function middle(req, res, next) { break; case 'PATCH': + if (noConfigDialog) + return res + .status(404) + .send('Config is disabled'); + patch(req, res, next); break; @@ -190,3 +196,11 @@ function cryptoPass(json) { json.password = criton(json.password, algo); } +function check(socket, authCheck) { + if (!socket) + throw Error('socket could not be empty!'); + + if (authCheck && typeof authCheck !== 'function') + throw Error('authCheck should be function!'); +} + diff --git a/lib/server/route.js b/lib/server/route.js index 6c38035f..92bac8c0 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -48,6 +48,8 @@ var DIR = __dirname + '/../../', }).join(':'); module.exports = function(req, res, next) { + check(req, res, next); + readFiles(function() { route(req, res, next); }); @@ -62,6 +64,7 @@ function indexProcessing(options) { right = '', keysPanel = '