diff options
Diffstat (limited to 'Reaktor/reaktor/commands')
-rwxr-xr-x | Reaktor/reaktor/commands/badcommand | 1 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/caps | 13 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/hello | 2 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/identify | 22 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/licht_resolver | 37 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/nag | 68 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/reload | 2 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/respond | 2 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/rev | 2 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/say | 2 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/taken | 28 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/tell-on_join | 19 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/tell-on_privmsg | 17 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/uptime | 8 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/whatweb | 17 | ||||
-rwxr-xr-x | Reaktor/reaktor/commands/whois | 4 |
16 files changed, 244 insertions, 0 deletions
diff --git a/Reaktor/reaktor/commands/badcommand b/Reaktor/reaktor/commands/badcommand new file mode 100755 index 00000000..c59b4d1c --- /dev/null +++ b/Reaktor/reaktor/commands/badcommand @@ -0,0 +1 @@ +#? //retard diff --git a/Reaktor/reaktor/commands/caps b/Reaktor/reaktor/commands/caps new file mode 100755 index 00000000..ac8cc66d --- /dev/null +++ b/Reaktor/reaktor/commands/caps @@ -0,0 +1,13 @@ +#! /usr/bin/env python3 +import imp +import os + +def load_config(filename): + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [ dirname ]) + return imp.load_module(modname, file, pathname, description) + +config = load_config(os.environ['config_filename']) +print('Private: '+' '.join(filter(None,[ x.get('capname',None) for x in config.commands]))) +print('Public: '+' '.join(filter(None,[ x.get('capname',None) for x in config.public_commands]))) diff --git a/Reaktor/reaktor/commands/hello b/Reaktor/reaktor/commands/hello new file mode 100755 index 00000000..05ed79b5 --- /dev/null +++ b/Reaktor/reaktor/commands/hello @@ -0,0 +1,2 @@ +#! /bin/sh +echo "Hello${*+, $*}!" diff --git a/Reaktor/reaktor/commands/identify b/Reaktor/reaktor/commands/identify new file mode 100755 index 00000000..c2fb2c58 --- /dev/null +++ b/Reaktor/reaktor/commands/identify @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import imp +import os,sys + +def load_config(filename): + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [ dirname ]) + return imp.load_module(modname, file, pathname, description) + +config = load_config(os.environ['config_filename']) + +with open(config.admin_file) as f: + for line in f: + nick,secret = line.split() + if sys.argv[1] == secret: + print("identified you as %s!"%nick) + with open(config.auth_file,'a+') as g: + g.write(os.environ['_prefix'] +"\n") + sys.exit(0) + +print("unable to identify you, sorry") diff --git a/Reaktor/reaktor/commands/licht_resolver b/Reaktor/reaktor/commands/licht_resolver new file mode 100755 index 00000000..5bdb6510 --- /dev/null +++ b/Reaktor/reaktor/commands/licht_resolver @@ -0,0 +1,37 @@ +#! /usr/bin/python +# -*- coding: utf-8 -*- + +map = { + 'shackspace': { + 'device': { + 0: 'Licht0, Zickenzone; Fenster', + 1: 'Licht1, Sofaecke; Fenster', + 2: 'Licht2, Zickenzone; Ghetto', + 3: 'Licht3, Sofaecke; Ghetto', + 4: 'Licht4, Richtung Getränkelager', + 5: 'Licht5, Porschekonsole', + 6: 'Licht6, Tomatenecke', + 7: 'Licht7, Ghetto', + 10: 'Hauptschalter' + }, + 'state': { + 0: 'aus', + 1: 'an', + 2: 'aus in T-10s' + }, + '->': 'ist' + } +} + +from struct import unpack +import json +from os import environ as env + +location = "shackspace" + +map = map[location] +print (env["payload"]+"") +did, sid= unpack('BB', json.loads(env['payload'])) +device,state = map['device'][did], map['state'][sid] +arrow = map['->'] +print ' '.join([device, arrow, state]) diff --git a/Reaktor/reaktor/commands/nag b/Reaktor/reaktor/commands/nag new file mode 100755 index 00000000..f2141392 --- /dev/null +++ b/Reaktor/reaktor/commands/nag @@ -0,0 +1,68 @@ +#! /bin/sh +set -euf +if test -e nag.hosts.ls; then + echo "nag seems to run already... if not, then delete $workdir/nag.*, please" + exit 23 +fi + +trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT + + +# usage: git_pull_output_filter REPO_NAME +git_pull_output_filter() { + sed -n 's/^ [0-9]\+ file change/'"$1"': &/p' +} + + +if ! test -d nag.hosts; then + git clone "$hosts_repo" nag.hosts +else + (cd nag.hosts && git pull) | git_pull_output_filter hosts +fi + +if ! test -d nag.services; then + git clone "$services_repo" nag.services +else + (cd nag.services && git pull) | git_pull_output_filter services +fi + + +(cd nag.hosts && ls | sort) > nag.hosts.ls +(cd nag.services && ls | sort) > nag.services.ls + +diff -u nag.hosts.ls nag.services.ls > nag.patch || : + +missing_services=$(sed -n '1d;2d;s/^-\(.*\)/\1/p' nag.patch | tr '\n' ' ') +obsolete_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ') + +if test "${inspect_services-false}" = true; then + missing_owners=$(set +f; cd nag.services && grep '^owner:$' * | cut -d: -f1) + missing_mailtos=$(set +f; cd nag.services && grep '^mailto:$' * | cut -d: -f1) +fi + +nag_missing_services='missing services' +nag_obsolete_services='obsolete services' +nag_missing_owners='services with missing owner entry' +nag_missing_mailtos='services with missing mailto entry' + +# +# output +# +did_nag=false +for i in \ + missing_services \ + obsolete_services \ + missing_owners \ + missing_mailtos +do + eval "offenders=\${$i-}; nag_msg=\$nag_$i" + if test -n "$offenders"; then + echo $nag_msg: $offenders + did_nag=true + fi +done + +# if asked directly, answer if there is nothing to nag about +if test $did_nag = false -a -n "${_from:-}";then + echo "nothing to nag about" +fi diff --git a/Reaktor/reaktor/commands/reload b/Reaktor/reaktor/commands/reload new file mode 100755 index 00000000..bfa1f041 --- /dev/null +++ b/Reaktor/reaktor/commands/reload @@ -0,0 +1,2 @@ +#! /bin/sh +exec pkill -U reaktor diff --git a/Reaktor/reaktor/commands/respond b/Reaktor/reaktor/commands/respond new file mode 100755 index 00000000..e23dc3ef --- /dev/null +++ b/Reaktor/reaktor/commands/respond @@ -0,0 +1,2 @@ +#!/bin/sh +printf '%s\n' "${_from}: $*" diff --git a/Reaktor/reaktor/commands/rev b/Reaktor/reaktor/commands/rev new file mode 100755 index 00000000..a8681ab9 --- /dev/null +++ b/Reaktor/reaktor/commands/rev @@ -0,0 +1,2 @@ +#! /bin/sh +git log -1 --format="%h by %an, %ar" diff --git a/Reaktor/reaktor/commands/say b/Reaktor/reaktor/commands/say new file mode 100755 index 00000000..8b83c056 --- /dev/null +++ b/Reaktor/reaktor/commands/say @@ -0,0 +1,2 @@ +#!/bin/sh +printf '%s\n' "$*" diff --git a/Reaktor/reaktor/commands/taken b/Reaktor/reaktor/commands/taken new file mode 100755 index 00000000..b8beba68 --- /dev/null +++ b/Reaktor/reaktor/commands/taken @@ -0,0 +1,28 @@ +#!/bin/sh +#!/bin/bash + +# domainavailable +# Fast, domain name checker to use from the shell +# Use globs for real fun: +# domainavailable blah{1..3}.{com,net,org,co.uk} +# Inspired by foca / giles: +# http://gilesbowkett.blogspot.com/2009/02/simple-bash-domain-availability.html + +for d in $@; +do +if host "$d" | grep "NXDOMAIN" >&/dev/null; then + w=$(whois "$d") + if ! test "$?" -eq 0 ;then + echo "$d - whois not available" + elif echo "$w" | grep -Ei "(No match|NOT FOUND|Status: free)" >&/dev/null; then + echo "$d available"; + elif echo "$w"| grep -Ei "(Status: invalid)" >&/dev/null ;then + echo "$d invalid" + else + echo "$d taken"; + fi +else + echo "$d taken"; +fi +done +exit 0 diff --git a/Reaktor/reaktor/commands/tell-on_join b/Reaktor/reaktor/commands/tell-on_join new file mode 100755 index 00000000..2dbff41a --- /dev/null +++ b/Reaktor/reaktor/commands/tell-on_join @@ -0,0 +1,19 @@ +#! /bin/sh +set -euf + +# require flock from util-linux +if test "${FLOCK-}" != "$state_file"; then + exec env FLOCK="$state_file" flock "$state_file" "$0" "$@" +fi + +to="$_from" + +# print messages +sed -n '/^'"$to"' /{ + s/^\([^ ]\+\) \([^ ]\+\) <\([^>]\+\)> \(.*\)/\1: \4 2-- \2, \3/p +}' "$state_file" + +# delete messages +sed -i '/^'"$to"' /{ + d +}' "$state_file" diff --git a/Reaktor/reaktor/commands/tell-on_privmsg b/Reaktor/reaktor/commands/tell-on_privmsg new file mode 100755 index 00000000..5d0aff41 --- /dev/null +++ b/Reaktor/reaktor/commands/tell-on_privmsg @@ -0,0 +1,17 @@ +#! /bin/sh +set -euf + +# require flock from util-linux +if test "${FLOCK-}" != "$state_file"; then + exec env FLOCK="$state_file" flock "$state_file" "$0" "$@" +fi + +from="$_prefix" +to="$1"; shift +msg="$*" +date=$(date) + +# TODO tell now, if already joined +printf '%s %s <%s> %s\n' "$to" "$from" "$date" "$msg" >> "$state_file" + +echo 'Consider it noted.' # that's what lambdabot says... diff --git a/Reaktor/reaktor/commands/uptime b/Reaktor/reaktor/commands/uptime new file mode 100755 index 00000000..7ff64168 --- /dev/null +++ b/Reaktor/reaktor/commands/uptime @@ -0,0 +1,8 @@ +#! /bin/sh +# +# //Reactor/commands/uptime - IRC-optimized uptime output +# +uptime | sed ' + s/^\(.*\) up \(.*\) days\?, *\(.*\), *\(.*\) users\?, *load average: \(.*\)$/\1; \2d \3; \4u; \5/;t + s/^\(.*\) up *\(.*\), *\(.*\) users\?, *load average: \(.*\)$/\1; 0d \2; \3u; \4/;t +' diff --git a/Reaktor/reaktor/commands/whatweb b/Reaktor/reaktor/commands/whatweb new file mode 100755 index 00000000..36711efa --- /dev/null +++ b/Reaktor/reaktor/commands/whatweb @@ -0,0 +1,17 @@ +#!/bin/sh +#wrapper for WhatWeb +set -eu + +# whatweb is in path? +whatweb=whatweb +if ! type -p whatweb >/dev/null 2>&1 ;then + here=$(dirname `readlink -f $0`) + whatweb="$here/../repos/whatweb/whatweb" + if ! test -e "$whatweb" then + echo "!! cannot find usable whatweb installation in path or basedir ($whatweb)" + exit 1 + fi +fi + +[ -z "${1:-}" ] && echo "!! no host given" && exit 1 +exec $whatweb_bin --user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0" -a 3 "$1" 2>&1 diff --git a/Reaktor/reaktor/commands/whois b/Reaktor/reaktor/commands/whois new file mode 100755 index 00000000..b0733891 --- /dev/null +++ b/Reaktor/reaktor/commands/whois @@ -0,0 +1,4 @@ +#!/bin/sh +(! type whois >/dev/null 2>/dev/null) && echo "whois does not exist" && exit 0 + +whois "${1?usage: $0 domain}" | sed -e '/^$/d' -e '/^%/d' -e '/^Nserver/d' -e 's/^\[.*/---/' -e '/^Changed/d' -e '/^Status/d' -e '/^Type/d' -e '/^PostalCode/d' -e '/^Phone/d' -e '/^Fax/d' -e '/Last update of WHOIS database/Q' -e '/ID:/d' |