diff --git a/lib/client/konsole.js b/lib/client/konsole.js index 25db8efd..0fdf8f73 100644 --- a/lib/client/konsole.js +++ b/lib/client/konsole.js @@ -50,7 +50,19 @@ function create(callback) { var prefix = getPrefix(); - Console(Element, prefix, function() { + Console(Element, prefix, function(spawn) { + spawn.on('auth', function() { + Dialog.alert(TITLE, 'Wrong credentials!'); + }); + + DOM.Files.get('config', function(error, config) { + if (error) + return Dialog.alert(TITLE, error); + + if (config.auth) + spawn.emit('auth', config.username, config.password); + }); + Util.exec(callback); }); diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 98f06a3b..db96e8a3 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -94,13 +94,26 @@ return cloudcmd(prefix, p.socket); }; + function authCheck(socket, success) { + if (!config('auth')) + return success(); + + socket.on('auth', function(name, pass) { + name === config('username') && + pass === config('password') ? + + success() : socket.emit('auth'); + }); + } + function listen(prefix, socket) { var size = cloudfunc.MAX_SIZE, pref = getPrefix(prefix); webconsole({ socket: socket, - prefix: pref + '/console' + prefix: pref + '/console', + authCheck: authCheck }); edward.listen(socket, {