summaryrefslogtreecommitdiffstats
path: root/elchos/root-image/krebs/etc/Reaktor
diff options
context:
space:
mode:
Diffstat (limited to 'elchos/root-image/krebs/etc/Reaktor')
-rw-r--r--elchos/root-image/krebs/etc/Reaktor/admin.lst0
-rw-r--r--elchos/root-image/krebs/etc/Reaktor/auth.lst0
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/ftpget58
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/identify22
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/io25
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/ips2
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/list_downloads8
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/onion3
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/reboot3
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/refresh_shares4
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/shares2
-rwxr-xr-xelchos/root-image/krebs/etc/Reaktor/commands/update-search3
-rw-r--r--elchos/root-image/krebs/etc/Reaktor/config.py60
13 files changed, 190 insertions, 0 deletions
diff --git a/elchos/root-image/krebs/etc/Reaktor/admin.lst b/elchos/root-image/krebs/etc/Reaktor/admin.lst
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/admin.lst
diff --git a/elchos/root-image/krebs/etc/Reaktor/auth.lst b/elchos/root-image/krebs/etc/Reaktor/auth.lst
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/auth.lst
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/ftpget b/elchos/root-image/krebs/etc/Reaktor/commands/ftpget
new file mode 100755
index 00000000..74e76f8e
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/ftpget
@@ -0,0 +1,58 @@
+#!/bin/sh
+# usage: $0 [-d] uri sharename[/subdirs]
+exec 2>&1
+set -euf
+ncdc_user=hooker
+usage(){
+ cat <<EOF
+usage: $0 [-d] uri share[/subdirs]
+ -d -- uri is a directory to be mirrored
+ share -- vag[0-n]
+
+EOF
+}
+examples(){
+ cat <<EOF
+examples: ftpget -d http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/0.8 vag0/firefox_releases
+ -> 0.8 directory is stored to /media/vag0/firefox_releases
+
+ ftpget -d http://speedtest.qsc.de/10MB.qsc vag0/
+ -> 10MB.qsc is stored to /media/vag0/10MB.qsc
+EOF
+}
+if test "${1:--h}" == '-h' -o "${1:-}" == '--help';then
+ usage
+ examples
+ exit 0
+fi
+if test ${1:-} == '-d' ;then
+ is_dir=true
+ shift
+fi
+
+target="${1:-}"
+if !( echo "$target" | egrep -q '^(ftps*://|https*://)' );then
+ exit 23
+fi
+
+share=$( printf "%s" "${2?provide share name}" |head -1 | sed 's#\.\./##')
+sharepath=/media/${share%%/*}
+realshare="/media/$share"
+test ! -e "$sharepath" && echo "$sharepath does not exist!" && exit 23
+
+sudo -u $ncdc_user /usr/bin/mkdir -p "$realshare"
+
+if test -z ${is_dir:-};then
+ cmd="lftpget \"$target\""
+else
+ cmd="lftp -e \"mirror;exit\" $target"
+fi
+
+ if ! sudo -u $ncdc_user /usr/bin/tmux has-session -t dl >/dev/null 2>&1 ;then
+ sudo -u $ncdc_user /usr/bin/tmux new-session -s dl -d -c "$realshare" "$cmd"
+ else
+ sudo -u $ncdc_user /usr/bin/tmux new-window -t dl -c "$realshare" "$cmd"
+ fi
+#sudo -u $ncdc_user /usr/bin/tmux new-window -t dl
+#cd "$realshare" ;sudo -u hooker /usr/bin/lftpget "$target"
+echo "download started, check with 'list_downloads'"
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/identify b/elchos/root-image/krebs/etc/Reaktor/commands/identify
new file mode 100755
index 00000000..c2fb2c58
--- /dev/null
+++ b/elchos/root-image/krebs/etc/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/elchos/root-image/krebs/etc/Reaktor/commands/io b/elchos/root-image/krebs/etc/Reaktor/commands/io
new file mode 100755
index 00000000..eb04ae9b
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/io
@@ -0,0 +1,25 @@
+#!/usr/bin/zsh
+printf '%-10s %-7s %-7s %-7s %-7s\n' IFACE rxkB/s txkB/s rxTotal txTotal
+sar -n DEV 1 3 | grep Average: | grep -v IFACE | grep -v ' lo ' | while read line;do
+ dev=$(echo $line | awk '{print $2}')
+ rxkb=$(echo $line | awk '{print $5}')
+ txkb=$(echo $line | awk '{print $6}')
+ total_bytes_r=$(cat /proc/net/dev | grep ${dev}: | awk '{print $2}')
+ total_bytes_t=$(cat /proc/net/dev | grep ${dev}: | awk '{print $10}')
+
+ printf '%-10s %-7s %-7s %-7s %-7s\n' $dev $rxkb $txkb $((total_bytes_r / (1024*1024))) $((total_bytes_t / (1024*1024)))
+done
+printf "%-10s %-7s %-7s\n" "DSK" "rxkB/s" "txkB/s"
+sar -p -d 1 3 | grep Average: | grep -v ' DEV ' |while read line;
+do
+ dsk=$(echo $line | awk '{print $2}')
+ rd_sec=$(echo $line | awk '{print $4}')
+ wr_sec=$(echo $line | awk '{print $5}')
+ if echo $dsk | egrep -q '(sd|hd|vd)';then
+ # TODO for some reason 0.00 can only be interpreted correctly as arithmetic
+ # expession by zsh
+ #
+ # rd is counted in blocks (which is 512 bytes)
+ printf "%-10s %-7.2f %-7.2f\n" "/dev/$dsk" "$((rd_sec*2))" "$((wr_sec*2))"
+ fi
+done
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/ips b/elchos/root-image/krebs/etc/Reaktor/commands/ips
new file mode 100755
index 00000000..17c39658
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/ips
@@ -0,0 +1,2 @@
+#!/bin/sh
+ip addr | grep 'inet ' | awk '{print $2}' | grep -v 127.0.0.1 | grep .
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/list_downloads b/elchos/root-image/krebs/etc/Reaktor/commands/list_downloads
new file mode 100755
index 00000000..f53067d8
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/list_downloads
@@ -0,0 +1,8 @@
+#!/bin/sh
+ncdc_user=hooker
+count=$(sudo -u $ncdc_user /usr/bin/tmux list-windows -t dl 2>/dev/null| wc -l)
+
+test $count -eq 0 && echo "no downloads running" && exit 0
+for i in $(seq 0 $(($count-1)));do
+ sudo -u $ncdc_user /usr/bin/tmux capture-pane -t dl:$i -p | grep -v '^$' | tail -n 1
+done
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/onion b/elchos/root-image/krebs/etc/Reaktor/commands/onion
new file mode 100755
index 00000000..1a202991
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/onion
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+sudo -u tor /krebs/bin/tor-get-hidden-service.sh || echo "no hidden service configured"
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/reboot b/elchos/root-image/krebs/etc/Reaktor/commands/reboot
new file mode 100755
index 00000000..a264831a
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/reboot
@@ -0,0 +1,3 @@
+#!/bin/sh
+echo "system is going down"
+sudo /usr/bin/reboot
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/refresh_shares b/elchos/root-image/krebs/etc/Reaktor/commands/refresh_shares
new file mode 100755
index 00000000..1005998b
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/refresh_shares
@@ -0,0 +1,4 @@
+#!/bin/sh
+ncdc_user=hooker
+sudo /krebs/bin/refresh-shares.ship 2>&1
+sudo -u $ncdc_user /krebs/bin/update-search.sh 2>&1
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/shares b/elchos/root-image/krebs/etc/Reaktor/commands/shares
new file mode 100755
index 00000000..1601d584
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/shares
@@ -0,0 +1,2 @@
+#!/bin/sh
+df -h | grep '/media/'
diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/update-search b/elchos/root-image/krebs/etc/Reaktor/commands/update-search
new file mode 100755
index 00000000..1db1c1b2
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/commands/update-search
@@ -0,0 +1,3 @@
+#!/bin/sh
+ncdc_user=hooker
+sudo -u $ncdc_user /krebs/bin/update-search.sh
diff --git a/elchos/root-image/krebs/etc/Reaktor/config.py b/elchos/root-image/krebs/etc/Reaktor/config.py
new file mode 100644
index 00000000..5e07b659
--- /dev/null
+++ b/elchos/root-image/krebs/etc/Reaktor/config.py
@@ -0,0 +1,60 @@
+import socket
+
+debug = False
+
+name = socket.gethostname()
+
+irc_alarm_timeout = 300
+irc_hammer_interval = 10
+irc_kill_timeout = 360
+irc_nickname = name
+#irc_server = 'elchirc.nsupdate.info'
+irc_server = 'irc.freenode.net'
+irc_restart_timeout = 5
+irc_port = 6667
+irc_channels = [
+ '#filehooker'
+]
+
+admin_file='admin.lst'
+auth_file='auth.lst'
+
+def default_command(cmd):
+ return {
+ 'capname': cmd,
+ 'pattern': '^(?:' + name + '|\\*):\\s*' + cmd + '\\s*(?:\\s+(?P<args>.*))?$',
+ 'argv': [ 'commands/' + cmd ] }
+
+public_commands = [
+ default_command('caps'),
+ default_command('hello'),
+ default_command('search'),
+ default_command('list_downloads'),
+ default_command('badcommand'),
+ default_command('rev'),
+ default_command('io'),
+ default_command('ips'),
+ default_command('uptime'),
+ default_command('shares'),
+ default_command('onion'),
+ default_command('nocommand'),
+ # command not found
+ { 'pattern': '^(?:' + name + '|\\*):.*',
+ 'argv': [ 'commands/respond','You are made of stupid!'] },
+ # "highlight"
+ { 'pattern': '.*\\b' + name + '\\b.*',
+ 'argv': [ 'commands/say', 'I\'m famous' ] },
+ # identify via direct connect
+ { 'capname': 'identify',
+ 'pattern': 'identify' + '\\s*(?:\\s+(?P<args>.*))?$',
+ 'argv' : [ 'commands/identify' ]}
+
+]
+
+commands = [
+ default_command('reload'),
+ default_command('update-search'),
+ default_command('refresh_shares'),
+ default_command('ftpget'),
+ default_command('reboot')
+]