diff options
author | root <root@filebitch> | 2011-08-16 19:10:17 +0200 |
---|---|---|
committer | root <root@filebitch> | 2011-08-16 19:10:17 +0200 |
commit | 460982f036bdc4815ea5e9447392bdb049ff2a87 (patch) | |
tree | b27e2e3cb28b8b4ecbb3e9ba2004966241262c85 /cholerab/knut | |
parent | 9a9ff1d97fa5072109a4381484f5daf5a4bfb0c1 (diff) | |
parent | 84f25017f61d87c592bcc4519bee56e49fe66083 (diff) |
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'cholerab/knut')
-rw-r--r-- | cholerab/knut/Makefile | 22 | ||||
-rwxr-xr-x | cholerab/knut/clients/cnot/index | 22 | ||||
-rwxr-xr-x | cholerab/knut/clients/pidgin_speak/speak.py | 31 | ||||
-rwxr-xr-x | cholerab/knut/index.js | 63 | ||||
-rwxr-xr-x | cholerab/knut/plugs/pynot/index | 17 | ||||
-rwxr-xr-x | cholerab/knut/plugs/ttycnser/bin/login | 4 | ||||
-rwxr-xr-x | cholerab/knut/plugs/ttycnser/bin/write | 4 | ||||
l--------- | cholerab/knut/plugs/ttycnser/index | 1 | ||||
-rw-r--r-- | cholerab/knut/src/io/slurp.js | 38 |
9 files changed, 202 insertions, 0 deletions
diff --git a/cholerab/knut/Makefile b/cholerab/knut/Makefile new file mode 100644 index 00000000..bb2aa905 --- /dev/null +++ b/cholerab/knut/Makefile @@ -0,0 +1,22 @@ + + +.PHONY: all install + +all: + echo 'Error 1: You are made of stupid!' >&2 + exit 23 + +install: \ + ../../bin/cnot \ + ../../bin/clive-knut \ + ../../bin/ttycnser-login + ../../punani/bin/punani -Ei python python-notify dbus-python + +../../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/$< $@ diff --git a/cholerab/knut/clients/cnot/index b/cholerab/knut/clients/cnot/index new file mode 100755 index 00000000..f276dd25 --- /dev/null +++ b/cholerab/knut/clients/cnot/index @@ -0,0 +1,22 @@ +#! /bin/sh +# +# cnot - cholerab live command line notification client, bitch! +# +# usage: [verbose=yes] cnot hostname [message...] +# +set -euf + +host="$1"; shift +port=42101 + +params="$*" + +flags=-sS + +if test "${verbose-no}" != no; then + flags="${flags+$flags }-v" +fi + +exec curl $flags -X PUT --data-binary @- "http://$host:$port" <<EOF +{"method":"clive","params":"$params","id":null} +EOF 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() 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/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() 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[2;1H[2K[33;1m>>>> ${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; + }); + }); + }; +})(); |