From b50c069f0f824f47234d29d8784489a31c0b5d40 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 13 Aug 2011 14:56:27 +0200 Subject: cholerab knut: initial commit --- cholerab/knut/index.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 cholerab/knut/index.js (limited to 'cholerab/knut/index.js') diff --git a/cholerab/knut/index.js b/cholerab/knut/index.js new file mode 100755 index 00000000..e7278678 --- /dev/null +++ b/cholerab/knut/index.js @@ -0,0 +1,63 @@ +#! /usr/bin/env node + +var host = '0.0.0.0'; +var port = 42101; + +var pipe = '/tmp/krebscode.painload.cholerab.ttycnser.' + process.env.LOGNAME; + +var fs = require('fs'); +var http = require('http'); +var slurp = require('./src/io/slurp'); +var spawn = require('child_process').spawn; + +var plugs = process.argv.slice(2); + +http.createServer(function (req, res) { + return slurp(req, function (data) { + try { + var message = JSON.parse(data); + } catch (exn) { + console.error(exn.stack); + }; + if (message) { + plugs.forEach(function (plug) { + + var env = JSON.parse(JSON.stringify(process.env)); + Object.keys(message).forEach(function (key) { + env[key] = message[key]; + }); + + var child = spawn(__dirname + '/plugs/' + plug + '/index', [], { + env: env + }); + + child.stdout.on('data', function (data) { + console.log(plug, 'stdout:', data.toString()); + }); + + child.stderr.on('data', function (data) { + console.log(plug, 'stderr:', data.toString()); + }); + + child.on('exit', function (code) { + console.log(plug, 'exit:', code); + if (code === 0) { + res.writeHead(200, { 'Content-Length': 0 }); + res.end(); + } else { + res.writeHead(500, { 'Content-Length': 0 }); + res.end(); + }; + }); + + }); + } else { + res.writeHead(400, 'You are made of stupid!', { + 'Content-Length': 0 + }); + res.end(); + }; + }); +}).listen(port, host, function () { + console.log('Serving HTTP on', host, 'port', port); +}); -- cgit v1.2.3 From 51af2699a3005346a453782393fa7ddbd7c13282 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 24 Aug 2011 20:52:53 +0200 Subject: cholerab knut: make host and port configurable usage: [host=HOST] [port=PORT] node knut --- cholerab/knut/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cholerab/knut/index.js') diff --git a/cholerab/knut/index.js b/cholerab/knut/index.js index e7278678..0ec6abae 100755 --- a/cholerab/knut/index.js +++ b/cholerab/knut/index.js @@ -1,7 +1,7 @@ #! /usr/bin/env node -var host = '0.0.0.0'; -var port = 42101; +var host = process.env.host || '0.0.0.0'; +var port = Number(process.env.port) || 42101; var pipe = '/tmp/krebscode.painload.cholerab.ttycnser.' + process.env.LOGNAME; -- cgit v1.2.3 From e9bead5873d628de50d53f6c280691830ca11b30 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 24 Aug 2011 22:25:16 +0200 Subject: knut: default to localhost Your Security Architect will thank you^_- --- cholerab/knut/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cholerab/knut/index.js') diff --git a/cholerab/knut/index.js b/cholerab/knut/index.js index 0ec6abae..9c536006 100755 --- a/cholerab/knut/index.js +++ b/cholerab/knut/index.js @@ -1,6 +1,6 @@ #! /usr/bin/env node -var host = process.env.host || '0.0.0.0'; +var host = process.env.host || '127.0.0.1'; var port = Number(process.env.port) || 42101; var pipe = '/tmp/krebscode.painload.cholerab.ttycnser.' + process.env.LOGNAME; -- cgit v1.2.3 From d75d0a901dc562cb3df818dbebd8cced601c9217 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 28 Aug 2011 17:23:45 +0200 Subject: =?UTF-8?q?knut:=20add=20Error=20#1=20=E2=88=A7=20Pro-Tip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cholerab/knut/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cholerab/knut/index.js') diff --git a/cholerab/knut/index.js b/cholerab/knut/index.js index 9c536006..b8951f1d 100755 --- a/cholerab/knut/index.js +++ b/cholerab/knut/index.js @@ -12,6 +12,16 @@ var spawn = require('child_process').spawn; var plugs = process.argv.slice(2); +if (plugs.length === 0) { + console.error('Error 1: You are made of stupid!' + + '\nPro-Tip: ' + + require('path').basename(process.argv[1]) + ' PLUG' + + ' # PLUG ∈ {' + + require('fs').readdirSync(__dirname + '/plugs').join(',') + + '}^n, n ≥ 1'); + process.exit(23); +}; + http.createServer(function (req, res) { return slurp(req, function (data) { try { -- cgit v1.2.3