var WebSocketServer = require('websocket').server;
var http = require('http');
var argv = require('yargs')
	.alias('e', 'exec')
    .default('port', 8080)
    .alias('p', 'password')
    .describe('p', 'Set a specific password to the WebSocket server')
	.demand(['e'])
	.argv;

var controllers = require('./lib/connectionCtrl.js');
var utils = require('./lib/utils.js');

var PORT = argv.port;

if (argv.password === undefined) console.log("\033[31m\nWARNING: It is recommended to set a password and use encrypted connections with sensible data.\n \x1b[0m")

var server = http.createServer(function(request, response) {
    console.log((new Date()) + ' Received request for ' + request.url);
    response.writeHead(404);
    response.end();
});

server.listen(PORT, function() {
    utils.log('Server is listening on port ' + PORT);
});

wsServer = new WebSocketServer({
    httpServer: server,
    autoAcceptConnections: false
});

wsServer.on('request', function(request) {
    controllers.onRequest(request, argv);
});
@@ -176,16 +176,310 @@
 sword')%0A
+    .alias('ssl', 'https')%0A    .boolean('ssl')%0A    .describe('ssl', 'Add https support')%0A    .describe('ssl-key', 'Route to SSL key')%0A    .describe('ssl-cert', 'Route to SSL certificate')%0A    .describe('port', 'Set the port to listen')%0A    .describe('e', 'Set the command you want to execute')%0A
     .des
@@ -540,17 +540,20 @@
 erver')%0A
-%09
+    
 .demand(
@@ -559,16 +559,84 @@
 (%5B'e'%5D)%0A
+    .implies('ssl', 'ssl-cert')%0A    .implies('ssl-cert', 'ssl-key')%0A
 %09.argv;%0A

ADD https flags and flags improvement