From c3c008ff720f90281aea91bbd1539403bbca4fa1 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 9 Nov 2016 15:57:44 +0200 Subject: [PATCH] feature(cloudcmd) add ability to disable console with "--no-console" (#65) --- HELP.md | 5 ++++- bin/cloudcmd.js | 3 +++ json/config.json | 4 +++- json/help.json | 4 +++- lib/client/key.js | 2 -- lib/client/konsole.js | 10 +++++++++- lib/cloudcmd.js | 12 ++++++------ lib/server/route.js | 9 +++++++-- man/cloudcmd.1 | 2 ++ package.json | 1 + test/before.js | 4 ++++ test/console.js | 37 +++++++++++++++++++++++++++++++++++++ 12 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 test/console.js diff --git a/HELP.md b/HELP.md index 03fc0401..379479f6 100644 --- a/HELP.md +++ b/HELP.md @@ -77,6 +77,7 @@ Cloud Commander supports command line parameters: | `--open` | open web browser when server started | `--one-panel-mode` | set one panel mode `--config-dialog` | enable config dialog + `--console` | enable console | `--no-server` | do not start server | `--no-auth` | disable authorization | `--no-online` | load scripts from local server @@ -85,6 +86,7 @@ Cloud Commander supports command line parameters: | `--no-progress` | do not show progress of file operations | `--no-one-panel-mode` | unset one panel mode | `--no-config-dialog` | disable config dialog +| `--no-console` | disable console 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. @@ -233,7 +235,8 @@ Here is description of options: "prefix" : "", /* url prefix */ "progress" : true, /* show progress of file operations */ "onePanelMode" : false, /* set one panel mode */ - "configDialog" : true /* enable config dialog */ + "configDialog" : true, /* enable config dialog */ + "console" : true /* enable console */ } ``` diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 8fadc07e..0403e36b 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -32,6 +32,7 @@ var Info = require('../package'), 'open', 'minify', 'progress', + 'console', 'config-dialog', 'one-panel-mode' ], @@ -47,6 +48,7 @@ var Info = require('../package'), root : config('root') || '/', prefix : config('prefix') || '', progress : config('progress'), + console : defaultTrue(config('console')), 'config-dialog': defaultTrue(config('configDialog')), 'one-panel-mode': config('onePanelMode'), @@ -84,6 +86,7 @@ if (args.version) { config('minify', args.minify); config('username', args.username); config('progress', args.progress); + config('console', args.console); config('prefix', args.prefix); config('root', args.root); config('onePanelMode', args['one-panel-mode']); diff --git a/json/config.json b/json/config.json index 230cce4a..9f1bdb94 100644 --- a/json/config.json +++ b/json/config.json @@ -21,5 +21,7 @@ "prefix": "", "progress": true, "onePanelMode": false, - "configDialog": true + "configDialog": true, + "console": true } + diff --git a/json/help.json b/json/help.json index e4448886..eb61533e 100644 --- a/json/help.json +++ b/json/help.json @@ -15,6 +15,7 @@ "--progress ": "show progress of file operations", "--one-panel-mode ": "set one panel mode", "--config-dialog ": "enable config dialog", + "--console ": "enable console", "--open ": "open web browser when server started", "--no-server ": "do not start server", "--no-auth ": "disable authorization", @@ -23,5 +24,6 @@ "--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" + "--no-config-dialog ": "disable config dialog", + "--no-console ": "disable console" } diff --git a/lib/client/key.js b/lib/client/key.js index e51c4bbe..0c86f3c8 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -333,13 +333,11 @@ var CloudCmd, Util, DOM; break; case Key.TRA: - DOM.Images.show.load('top'); CloudCmd.Konsole.show(); event.preventDefault(); break; case KEY.BRACKET_CLOSE: - DOM.Images.show.load('top'); CloudCmd.Konsole.show(); event.preventDefault(); break; diff --git a/lib/client/konsole.js b/lib/client/konsole.js index 0627826e..5e0d9482 100644 --- a/lib/client/konsole.js +++ b/lib/client/konsole.js @@ -110,7 +110,15 @@ Util.time(Name + ' load'); } - init(); + DOM.Files.get('config', function(error, config) { + if (error) + return Dialog.alert(TITLE, error); + + if (!config.console) + return; + + init(); + }); } })(CloudCmd, Util, DOM); diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 38bea7c2..e4f56180 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -108,12 +108,6 @@ function listen(prefix, socket) { config.listen(socket, authCheck); - webconsole({ - prefix: prefix + '/console', - socket: socket, - authCheck: authCheck - }); - edward.listen(socket, { size: size, root: root, @@ -152,6 +146,12 @@ function listen(prefix, socket) { prefix: prefix + '/ishtar', authCheck: authCheck }); + + config('console') && webconsole({ + prefix: prefix + '/console', + socket: socket, + authCheck: authCheck + }); } function cloudcmd(prefix) { diff --git a/lib/server/route.js b/lib/server/route.js index 92bac8c0..fea34365 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -64,7 +64,8 @@ function indexProcessing(options) { right = '', keysPanel = '
{ server.close(); }; + const socket = io.listen(server); + app.use(cloudcmd({ + socket, config: assign(defaultConfig(), config) })); diff --git a/test/console.js b/test/console.js new file mode 100644 index 00000000..712d4ae9 --- /dev/null +++ b/test/console.js @@ -0,0 +1,37 @@ +'use strict'; + +const test = require('tape'); +const io = require('socket.io-client'); + +const before = require('./before'); + +test('cloudcmd: console: enabled', (t) => { + const config = {console: true}; + + before(config, (port, after) => { + const socket = io(`http://localhost:${port}/console`) + + socket.once('data', (data) => { + socket.close(); + t.equal(data, 'client #1 console connected\n', 'should emit data event'); + after(); + t.end(); + }); + }); +}); + +test('cloudcmd: console: disabled', (t) => { + const config = {console: false}; + + before(config, (port, after) => { + const socket = io(`http://localhost:${port}/console`); + + socket.on('error', (error) => { + t.equal(error, 'Invalid namespace', 'should emit error'); + socket.close(); + after(); + t.end(); + }); + }); +}); +