var utils = require('./utils.js');
var spawn = require('child_process').spawn;

exports.onRequest = function(request, argv) {
	var connection = request.accept('', request.origin);
	var authorized = false;
	
	var path = utils.getProcessPath(argv);

	connection.process = {};
	
    connection.on('message', function(message) {
        if (message.type === 'utf8') {
        	if (!authorized) {
        		if (message.utf8Data === '1234') {
        			authorized = true;
        			
        			console.log("Client authorized successfully");

        			connection.process = spawn(path.cmd, path.argvs);

					connection.process.stdout.on('data', function(data) {
						connection.sendUTF(data);
					});

					connection.process.stdout.on('error', function(data) {
						connection.sendUTF(data);
					});
        		}
        		else {
        			console.log("Client tried to authorize with " + message.utf8Data);
        		}
        	} else {
        		console.log("Data received from authorized user");
        	}
        }
    });
}
@@ -77,203 +77,684 @@
 n;%0A%0A
-exports.onRequest = function(request, argv) %7B%0A%09var connection = request.accept('', request.origin);%0A%09var authorized = false;%0A%09%0A%09var path = utils.getProcessPath(argv);%0A%0A%09connection.process = %7B%7D;%0A%09
+%0Avar initProcess = function(connection, path) %7B%0A    connection.process = spawn(path.cmd, path.argvs);%0A%0A    connection.process.stdout.on('data', function(data) %7B%0A        connection.sendUTF(data);%0A    %7D);%0A%0A    connection.process.stdout.on('error', function(data) %7B%0A        connection.sendUTF(data);%0A    %7D);%0A%7D%0A%0Aexports.onRequest = function(request, argv) %7B%0A%09var connection = request.accept('', request.origin);%0A    connection.process = %7B%7D;%0A%0A%09var authorized = false;%0A    if (argv.password === undefined) %7B%0A        authorized = true;%0A        var path = utils.getProcessPath(argv);%0A        initProcess(connection, path);%0A        console.log(%22Client authorized successfully%22);%0A    %7D%0A
 %0A   
@@ -903,16 +903,22 @@
 a ==
-= '1234'
+ argv.password
 ) %7B%0A
@@ -959,20 +959,16 @@
     
-%09%09%09%0A
         
 %09%09%09c
@@ -967,320 +967,157 @@
     
-%09%09%09console.log(%22Client authorized successfully%22);%0A%0A        %09%09%09connection.process = spawn(path.cmd, path.
+    var path = utils.getProcessPath(
 argv
-s
 );%0A
-%0A%09%09%09%09%09connection.process.stdout.on('data', function(data) %7B%0A%09%09%09%09%09%09connection.sendUTF(data);%0A%09%09%09%09%09%7D);%0A%0A%09%09%09%09%09connection.process.stdout.on('error', function(data) %7B%0A%09%09%09%09%09%09connection.sendUTF(data);%0A%09%09%09%09%09%7D
+                    initProcess(connection, path);%0A        %09%09%09console.log(%22Client authorized successfully%22
 );%0A 
@@ -1218,24 +1218,88 @@
 .utf8Data);%0A
+                    console.log(%22Correct is %22 + argv.password);%0A
         %09%09%7D%0A
@@ -1343,16 +1343,41 @@
 og(%22Data
+ %22 + message.utf8Data + %22
  receive

ADD password authentification