From 4ff483f4a721b488acaaf30557d1d6168022c42c Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 12 Aug 2011 15:20:37 +0200 Subject: knut: initial commit knut is the notification toolchain for krebs --- cholerab/knut/README | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 cholerab/knut/README (limited to 'cholerab/knut') diff --git a/cholerab/knut/README b/cholerab/knut/README new file mode 100644 index 00000000..51b90307 --- /dev/null +++ b/cholerab/knut/README @@ -0,0 +1,2 @@ +KNUT - Krebs Notification Utility Toolchain +=========================================== -- cgit v1.2.3 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 ++++++++++++++++++++++++++++++++++ cholerab/knut/plugs/ttycnser/bin/login | 4 +++ cholerab/knut/plugs/ttycnser/bin/write | 4 +++ cholerab/knut/plugs/ttycnser/index | 1 + cholerab/knut/src/io/slurp.js | 38 ++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100755 cholerab/knut/index.js create mode 100755 cholerab/knut/plugs/ttycnser/bin/login create mode 100755 cholerab/knut/plugs/ttycnser/bin/write create mode 120000 cholerab/knut/plugs/ttycnser/index create mode 100644 cholerab/knut/src/io/slurp.js (limited to 'cholerab/knut') 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); +}); diff --git a/cholerab/knut/plugs/ttycnser/bin/login b/cholerab/knut/plugs/ttycnser/bin/login new file mode 100755 index 00000000..bf88d6f9 --- /dev/null +++ b/cholerab/knut/plugs/ttycnser/bin/login @@ -0,0 +1,4 @@ +#! /bin/sh +set -euf +pipe="/tmp/krebscode.painload.cholerab.ttycnser.${LOGNAME}" +ln -snf "`tty`" "$pipe" diff --git a/cholerab/knut/plugs/ttycnser/bin/write b/cholerab/knut/plugs/ttycnser/bin/write new file mode 100755 index 00000000..f358407a --- /dev/null +++ b/cholerab/knut/plugs/ttycnser/bin/write @@ -0,0 +1,4 @@ +#! /bin/sh +set -euf +pipe="/tmp/krebscode.painload.cholerab.ttycnser.${LOGNAME}" +echo -n "7>>>> ${params}8" > "${pipe}" diff --git a/cholerab/knut/plugs/ttycnser/index b/cholerab/knut/plugs/ttycnser/index new file mode 120000 index 00000000..2d949688 --- /dev/null +++ b/cholerab/knut/plugs/ttycnser/index @@ -0,0 +1 @@ +bin/write \ No newline at end of file diff --git a/cholerab/knut/src/io/slurp.js b/cholerab/knut/src/io/slurp.js new file mode 100644 index 00000000..70319743 --- /dev/null +++ b/cholerab/knut/src/io/slurp.js @@ -0,0 +1,38 @@ +module.exports = (function () { + + function join_buffers (buffers, length) { + var buffer = new Buffer(length); + var targetStart = 0; + buffers.forEach(function (x) { + x.copy(buffer, targetStart); + targetStart += x.length; + }); + return buffer; + }; + + function finish_it (req, buffers, length, callback) { + req.content = join_buffers(buffers, length); + return callback(req.content); + }; + + function nop () {}; + + return function (req, callback) { + if (req.hasOwnProperty('content')) { + return callback(req.content); + }; + var content = []; + var length = 0; + var end_handler = finish_it; + req.on('data', function (data) { + content.push(data); + length += data.length; + }); + [ 'end', 'close' ].forEach(function (event) { + req.on(event, function () { + finish_it(req, content, length, callback); + end_handler = nop; + }); + }); + }; +})(); -- cgit v1.2.3 From 323da3f815a8a97c48e7f7c2cd6c49a3a7c60070 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 13 Aug 2011 15:40:17 +0200 Subject: cholerab knut cnot: add command line client --- cholerab/knut/clients/cnot/index | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 cholerab/knut/clients/cnot/index (limited to 'cholerab/knut') diff --git a/cholerab/knut/clients/cnot/index b/cholerab/knut/clients/cnot/index new file mode 100755 index 00000000..a9e4972d --- /dev/null +++ b/cholerab/knut/clients/cnot/index @@ -0,0 +1,14 @@ +#! /bin/sh +# +# +# +set -euf + +host="$1"; shift +port=42101 + +params="$*" + +exec curl -vsS -X PUT --data-binary @- "http://$host:$port" < Date: Sat, 13 Aug 2011 15:40:52 +0200 Subject: cholerab knut Makefile: add install target --- cholerab/knut/Makefile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cholerab/knut/Makefile (limited to 'cholerab/knut') diff --git a/cholerab/knut/Makefile b/cholerab/knut/Makefile new file mode 100644 index 00000000..69144a40 --- /dev/null +++ b/cholerab/knut/Makefile @@ -0,0 +1,21 @@ + + +.PHONY: all install + +all: + echo 'Error 1: You are made of stupid!' >&2 + exit 23 + +install: \ + ../../bin/cnot \ + ../../bin/clive-knut \ + ../../bin/ttycnser-login + +../../bin/cnot: clients/cnot/index + ln -vsnf ../cholerab/knut/$< $@ + +../../bin/clive-knut: index.js + ln -vsnf ../cholerab/knut/$< $@ + +../../bin/ttycnser-login: plugs/ttycnser/bin/login + ln -vsnf ../cholerab/knut/$< $@ -- cgit v1.2.3 From 541620dc51862d588a2bdfea9b84dbf9bf21bf73 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 13 Aug 2011 15:42:28 +0200 Subject: cholerab cnot: add documentation --- cholerab/knut/clients/cnot/index | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cholerab/knut') diff --git a/cholerab/knut/clients/cnot/index b/cholerab/knut/clients/cnot/index index a9e4972d..d17329f4 100755 --- a/cholerab/knut/clients/cnot/index +++ b/cholerab/knut/clients/cnot/index @@ -1,6 +1,8 @@ #! /bin/sh # +# cnot - cholerab live command line notification client, bitch! # +# usage: cnot hostname message... # set -euf -- cgit v1.2.3 From c36f72a019abcd22fca3dc550e1a239c1d161f1f Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 13 Aug 2011 15:49:43 +0200 Subject: cholerab cnot: be verbose on demand only --- cholerab/knut/clients/cnot/index | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'cholerab/knut') diff --git a/cholerab/knut/clients/cnot/index b/cholerab/knut/clients/cnot/index index d17329f4..f276dd25 100755 --- a/cholerab/knut/clients/cnot/index +++ b/cholerab/knut/clients/cnot/index @@ -2,7 +2,7 @@ # # cnot - cholerab live command line notification client, bitch! # -# usage: cnot hostname message... +# usage: [verbose=yes] cnot hostname [message...] # set -euf @@ -11,6 +11,12 @@ port=42101 params="$*" -exec curl -vsS -X PUT --data-binary @- "http://$host:$port" < Date: Sat, 13 Aug 2011 22:16:22 +0200 Subject: knut/plugs/pynot: initial commit notification via lib-notify and python --- cholerab/knut/plugs/pynot/index | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 cholerab/knut/plugs/pynot/index (limited to 'cholerab/knut') diff --git a/cholerab/knut/plugs/pynot/index b/cholerab/knut/plugs/pynot/index new file mode 100755 index 00000000..04e9c90c --- /dev/null +++ b/cholerab/knut/plugs/pynot/index @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import pynotify,os,sys + +imageURI = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0]) + '/../../../bling/krebs_plain_negate_nobg.png')) +try: + TITLE=os.environ.get('method','clive') + ':' + os.environ.get('id','-1') + MESSAGE=os.environ.get('params','No Message') +except: + print("Error 1: You are made of stupid!") + exit(23) + +pynotify.init("Notif App",) +print imageURI +n = pynotify.Notification(TITLE, MESSAGE,imageURI) +n.set_timeout(20000) +n.show() -- cgit v1.2.3 From 13092c905de4f43c429edb004fd080fcb2ee5cbd Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 13 Aug 2011 22:21:04 +0200 Subject: knut/Makefile: add dependency install --- cholerab/knut/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'cholerab/knut') diff --git a/cholerab/knut/Makefile b/cholerab/knut/Makefile index 69144a40..ee422fd9 100644 --- a/cholerab/knut/Makefile +++ b/cholerab/knut/Makefile @@ -10,6 +10,7 @@ install: \ ../../bin/cnot \ ../../bin/clive-knut \ ../../bin/ttycnser-login + ../../punani/bin/punani -Ei python python-notify ../../bin/cnot: clients/cnot/index ln -vsnf ../cholerab/knut/$< $@ -- cgit v1.2.3 From 84f25017f61d87c592bcc4519bee56e49fe66083 Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 14 Aug 2011 22:03:11 +0200 Subject: pidgin_speak: initial commit --- cholerab/knut/Makefile | 2 +- cholerab/knut/clients/pidgin_speak/speak.py | 31 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 cholerab/knut/clients/pidgin_speak/speak.py (limited to 'cholerab/knut') diff --git a/cholerab/knut/Makefile b/cholerab/knut/Makefile index ee422fd9..bb2aa905 100644 --- a/cholerab/knut/Makefile +++ b/cholerab/knut/Makefile @@ -10,7 +10,7 @@ install: \ ../../bin/cnot \ ../../bin/clive-knut \ ../../bin/ttycnser-login - ../../punani/bin/punani -Ei python python-notify + ../../punani/bin/punani -Ei python python-notify dbus-python ../../bin/cnot: clients/cnot/index ln -vsnf ../cholerab/knut/$< $@ diff --git a/cholerab/knut/clients/pidgin_speak/speak.py b/cholerab/knut/clients/pidgin_speak/speak.py new file mode 100755 index 00000000..aeaa417f --- /dev/null +++ b/cholerab/knut/clients/pidgin_speak/speak.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +import string +CNOT="../cnot/index %s %s" +host="pornocauster" +def speakOwn(account, receiver,message): + speak(account,receiver,message,"",""); +def speak(account, sender, message, conversation, flags): + bus = dbus.SessionBus() + obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") + purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") + import subprocess + message = message.replace("'",'"') + print message + #cmd = "espeak -v de '%s'" % message + cmd = CNOT % (host,message) + subprocess.call(cmd,shell=True) +import dbus, gobject + +from dbus.mainloop.glib import DBusGMainLoop +dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) +bus = dbus.SessionBus() + +bus.add_signal_receiver(speak, + dbus_interface="im.pidgin.purple.PurpleInterface", + signal_name="ReceivedImMsg") + +bus.add_signal_receiver(speakOwn, + dbus_interface="im.pidgin.purple.PurpleInterface", + signal_name="SentImMsg") +loop = gobject.MainLoop() +loop.run() -- 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') 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') 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') 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 From 74e325f2c44361230aa133a61fb35cd3e596a63c Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 28 Aug 2011 17:25:18 +0200 Subject: cholerab cnot: bail out on bad response With this commit the curl_flags environmental variable is used to override the default flags to curl (which are -fsS ATM). --- cholerab/knut/clients/cnot/index | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cholerab/knut') diff --git a/cholerab/knut/clients/cnot/index b/cholerab/knut/clients/cnot/index index f276dd25..fcbef73e 100755 --- a/cholerab/knut/clients/cnot/index +++ b/cholerab/knut/clients/cnot/index @@ -11,7 +11,7 @@ port=42101 params="$*" -flags=-sS +flags=${curl_flags--fsS} if test "${verbose-no}" != no; then flags="${flags+$flags }-v" -- cgit v1.2.3