From 851fb93dd3d1778da12752977cfbe4fff7d65ecb Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 29 Aug 2011 10:05:36 +0200 Subject: punani: add dryrun,hard,filebased search punani is now able to search for packages via files and packages in debian-based and arch-based systems. Fix bug in punani godmode --- punani/bin/punani | 156 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 122 insertions(+), 34 deletions(-) diff --git a/punani/bin/punani b/punani/bin/punani index 7af6f0f8..f01cedb7 100755 --- a/punani/bin/punani +++ b/punani/bin/punani @@ -6,7 +6,7 @@ # -E -i spec insert a package to the target filesystem # -E -r spec remove a package # - +set -euf godmode() { if test "${nosudo-false}" != true -a `id -u` != 0; then echo "Warning: we require god mode..." >&2 @@ -15,44 +15,44 @@ godmode() { fi } -if pacman --version 2>/dev/null | fgrep -q Pacman; then - system="${system+$system, }arch-like" -fi +# return the 'system' variable +# currently be: +# arch-like +# debian-like +guess_system() +{ + if [ -f "/etc/arch-release" ] ;then + system="${system+$system, }arch-like" + fi + if [ -f "/etc/lsb-release" -o -f "/etc/debian_version" ] ;then + system="${system+$system, }debian-like" + fi -case "$system" in - (*arch-like*) - punani_Engineer_insert() { - pacman -Sy "$1" - } - punani_Engineer_remove() { - pacman -Rcs "$1" - } - ;; - (*) - email='krebs@syntax-fehler.de' - irc_host='irc.freenode.org' - irc_channel='#tincspasm' - cat>&2<&2< Date: Mon, 29 Aug 2011 12:38:56 +0200 Subject: punani: fix help/hard conflict, system function handle_system is now the function which does the right thing for all distro specific stuff --- punani/bin/punani | 239 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 152 insertions(+), 87 deletions(-) diff --git a/punani/bin/punani b/punani/bin/punani index f01cedb7..f9244c53 100755 --- a/punani/bin/punani +++ b/punani/bin/punani @@ -9,7 +9,7 @@ set -euf godmode() { if test "${nosudo-false}" != true -a `id -u` != 0; then - echo "Warning: we require god mode..." >&2 + echo "!! we require god mode..." >&2 exec sudo "$0" "$@" exit 23 # go to hell fi @@ -43,7 +43,142 @@ arch_aur_helper() echo "!! To be Implemented" return 1 } +handle_system () { + case "$system" in + (*arch-like*) + # dryrun + # TODO dryrun not dry enough for aur helper + if [ "${dryrun-}" ];then + pacman () { echo "pacman $@" ; } + pkgfile () { echo "pkgfile $@"; } + yaourt () { echo "yaourt $@" ; } + fi + + # get dependencies : + # we need pkgfile + if ! [ `which pkgfile` ] ; then + pacman -S --noconfirm pkgtools + pkgfile -u + fi + punani_Scientist_update() { + pacman -Sy + pkgtool -u + } + + punani_Engineer_insert() { + # punani under archlinux first tries to load the packages with the given file name + # it needs pkgfile for that + # + # when trying harder it tries to load the package with the given name directly via yaourt + echo "** trying to find package with given file" + if pacman -Sy `pkgfile $1`; then + echo "++ finished" + exit 0 + else + echo "!! nothing found in base repos" + if [ "${hard-}" ] ; then + echo "** trying harder" + echo "** trying yaourt directly with given package" + mgr=`arch_aur_helper` + if $mgr -S $1 ;then + echo "++ finished" + exit 0 + else + echo "!! giving up...i am sorry" + exit 1 + fi + echo + else + echo "?? When in doubt try $0 -h -Ei $1 " + fi + fi + } + punani_Engineer_remove() { + pacman -Rcs "`pacman -Ql | grep $1$ | awk '{print $1}'`" + if [ "${hard-}" ] ; then + echo "** trying harder" + echo "** directly delete given package name" + pacman -Rcs "$1" + fi + } + ;; + (*debian-like*) + if [ "${dryrun-}" ]; then + apt-file () { echo $@; } + apt-get () { echo $@; } + fi + [ `which apt-file` ] || apt-get install --yes apt-file && apt-file update + punani_Scientist_update() { + apt-get update + apt-file update + } + punani_Scientist_search() { + apt-file search $1 && exit 0 + if [ "${hard-}" ] ; then + apt-cache search $1 + fi + } + punani_Engineer_insert() { + if apt-get install `apt-file search $1`;then + echo "++ finished" + else + if [ "${hard-}" ] ; then + echo "** trying harder" + apt-get install $1 + fi + fi + } + punani_Engineer_remove() { + apt-get remove --purge "`apt-file search $1`" + if [ "${hard-}" ] ; then + echo "** trying harder" + echo "** directly delete given package name" + apt-get remove --purge "$1" + fi + } + ;; + (*) + email='krebs@syntax-fehler.de' + irc_host='irc.freenode.org' + irc_channel='#tincspasm' + cat>&2<&2 exit 23;; - esac - ;; + esac;; + (Scientist) + case $OPT in + (s) command="${ns}_${role}_search";; + (y) command="${ns}_${role}_update";; + (*) + echo 'Error 1: You are made of stupid!' >&2 + exit 23;; + esac ;; (undefined) case $OPT in (E) role=Engineer;; + (S) role=Scientist;; (*) exit 23;; esac @@ -82,96 +226,17 @@ punani $@ case $role in (Engineer) godmode $@;; + (Scientist) + case $command in + (*_update) godmode $@;; + esac;; esac shift `echo $OPTIND-1 | bc` guess_system -case "$system" in - (*arch-like*) - # get dependencies : - # we need pkgfile - if [ "${dryrun-}" ];then - pacman () { echo "pacman $@" ; } - pkgfile () { echo "pkgfile $@"; } - yaourt () { echo "yaourt $@" ; } - fi - if ! [ `which pkgfile` ] ; then - pacman -S --noconfirm pkgtools - pkgfile -u - fi - punani_Scientist_update() { - pacman -Sy - pkgtool -u - } - - punani_Engineer_insert() { - # punani under archlinux first tries to load the packages with the given file name - # it needs pkgfile for that - # - # when trying harder it tries to load the package with the given name directly via yaourt - echo "** trying to find package with given file" - if pacman -Sy `pkgfile $1`; then - echo "++ finished" - exit 0 - else - echo "!! nothing found in base repos" - if [ "${hard-}" ] ; then - echo "** trying harder" - echo "** trying yaourt directly with given package" - mgr=`arch_aur_helper` - if $mgr -S $1 ;then - echo "++ finished" - exit 0 - else - echo "!! giving up...i am sorry" - exit 1 - fi - echo - else - echo "?? When in doubt try $0 -Ei --hard $1 " - fi - fi - } - punani_Engineer_remove() { - pacman -Rcs "`pacman -Ql | grep $1$ | awk '{print $1}'`" - if [ "${hard-}" ] ; then - echo "trying harder" - echo "** directly delete given package name" - pacman -Rcs "$1" - fi - } - ;; - (*debian-like*) - if [ "${dryrun-}" ]; then - apt-file () { echo $@; } - apt-get () { echo $@; } - fi - [ `which apt-file` ] || apt-get install --yes apt-file && apt-file update - punani_Scientist_update() { - apt-get update - apt-file update - } - - ;; - (*) - email='krebs@syntax-fehler.de' - irc_host='irc.freenode.org' - irc_channel='#tincspasm' - cat>&2< Date: Mon, 29 Aug 2011 13:30:51 +0200 Subject: fix dpfhack_display now as submodule --- .gitmodules | 3 +++ oncology/dpfhack_display | 1 + submodules/github/makefu/dpfhack_display | 1 + 3 files changed, 5 insertions(+) create mode 120000 oncology/dpfhack_display create mode 160000 submodules/github/makefu/dpfhack_display diff --git a/.gitmodules b/.gitmodules index ed0cb4ed..3677b710 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "submodules/github/tautologistics/node-htmlparser"] path = submodules/github/tautologistics/node-htmlparser url = https://github.com/tautologistics/node-htmlparser +[submodule "submodules/github/makefu/dpfhack_display"] + path = submodules/github/makefu/dpfhack_display + url = https://github.com/makefu/dpfhack_pearl diff --git a/oncology/dpfhack_display b/oncology/dpfhack_display new file mode 120000 index 00000000..9666b7bc --- /dev/null +++ b/oncology/dpfhack_display @@ -0,0 +1 @@ +../submodules/github/makefu/dpfhack_display \ No newline at end of file diff --git a/submodules/github/makefu/dpfhack_display b/submodules/github/makefu/dpfhack_display new file mode 160000 index 00000000..c66acd31 --- /dev/null +++ b/submodules/github/makefu/dpfhack_display @@ -0,0 +1 @@ +Subproject commit c66acd31125dc18bc2638569d6ba081f21bcef50 -- cgit v1.2.3 From cd4f8b3394e02bcb7d86d53d1b98b4b4b868b78b Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 29 Aug 2011 13:46:45 +0200 Subject: punani/doc: initial commit releases covers a way to guess the release of the distro --- punani/doc/releases | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 punani/doc/releases diff --git a/punani/doc/releases b/punani/doc/releases new file mode 100644 index 00000000..3b372d56 --- /dev/null +++ b/punani/doc/releases @@ -0,0 +1,35 @@ +# release files (guess the os distribution) +# from http://linuxmafia.com/faq/Admin/release-files.html +Annvix: /etc/annvix-release +Arch Linux: /etc/arch-release +Arklinux: /etc/arklinux-release +Aurox Linux: /etc/aurox-release +BlackCat: /etc/blackcat-release +Cobalt: /etc/cobalt-release +Conectiva: /etc/conectiva-release +Debian: /etc/debian_version, /etc/debian_release (rare) +Fedora Core: /etc/fedora-release +Gentoo Linux: /etc/gentoo-release +Immunix: /etc/immunix-release +Knoppix: knoppix_version +Linux-From-Scratch: /etc/lfs-release +Linux-PPC: /etc/linuxppc-release +Mandrake: /etc/mandrake-release +Mandriva/Mandrake Linux: /etc/mandriva-release, /etc/mandrake-release, /etc/mandakelinux-release +MkLinux: /etc/mklinux-release +Novell Linux Desktop: /etc/nld-release +PLD Linux: /etc/pld-release +Red Hat: /etc/redhat-release, /etc/redhat_version (rare) +Slackware: /etc/slackware-version, /etc/slackware-release (rare) +SME Server (Formerly E-Smith): /etc/e-smith-release +Solaris SPARC: /etc/release +Sun JDS: /etc/sun-release +SUSE Linux: /etc/SuSE-release, /etc/novell-release +SUSE Linux ES9: /etc/sles-release +Tiny Sofa: /etc/tinysofa-release +TurboLinux: /etc/turbolinux-release +Ubuntu Linux: /etc/lsb-release +UltraPenguin: /etc/ultrapenguin-release +UnitedLinux: /etc/UnitedLinux-release (covers SUSE SLES8) +VA-Linux/RH-VALE: /etc/va-release +Yellow Dog: /etc/yellowdog-release -- cgit v1.2.3 From 568fbd7fa5541182bbbc33560863ec9c3ff01d48 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 6 Sep 2011 21:20:37 +0200 Subject: cholerab/reaktor: add privileged functions description privileged functions might be implemented via asymmetric encryption this is described in the privileged_function text file --- cholerab/reaktor/priviliged_functions | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cholerab/reaktor/priviliged_functions diff --git a/cholerab/reaktor/priviliged_functions b/cholerab/reaktor/priviliged_functions new file mode 100644 index 00000000..a673267e --- /dev/null +++ b/cholerab/reaktor/priviliged_functions @@ -0,0 +1,24 @@ +Use Case 1: Request update on Host +================================= + +< user> bot: update +< bot> /whois user +< bot> /msg user [CHALLENGE] +< user> /msg bot [CHALLENGE-RESPONSE] +< bot> updating... +< bot> now on rev XXXXX + +Command Flow +---------------- +The bot has a locally stored list of [trusted] hosts along with their public +key, preferably from the tinc/retiolum directory. + +The bot encrypts a 1K Byte long message with the public key of the host +retrieved by the /whois command. + +This challenge is sent to the user requesting the command via private message. +The user then decrpyts the message with its own private key and sends the +decrpyted message to the bot. + +The bot then executes the requested command if the challenge is answered +correctly -- cgit v1.2.3 From 89d92c55e7ddc0aec61ae8210592410f37f73502 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 12 Sep 2011 14:54:35 +0200 Subject: punani: fix parsing bug, add fallback helper --- punani/bin/punani | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/punani/bin/punani b/punani/bin/punani index f9244c53..1dd72542 100755 --- a/punani/bin/punani +++ b/punani/bin/punani @@ -31,7 +31,8 @@ guess_system() } arch_aur_helper() { - manager="yaourt clyde packer bauerbill tupac pacaur paktahn pbfetch aurget aurora cower powaur" + # pacman is the last fallback helper + manager="yaourt clyde packer bauerbill tupac pacaur paktahn pbfetch aurget aurora cower powaur pacman" for i in $manager;do mgr=`which $i` if [ "$mgr" ] ;then @@ -39,8 +40,7 @@ arch_aur_helper() return 0 fi done - echo "!! no aur helper found" - echo "!! To be Implemented" + echo "!! no helper found, this should never happen(tm)." return 1 } handle_system () { @@ -64,6 +64,14 @@ handle_system () { pacman -Sy pkgtool -u } + punani_Scientist_search() { + pkgfile $1 + if [ "${hard-}" ] ; then + mgr=`arch_aur_helper` + $mgr -Ss $1 + fi + + } punani_Engineer_insert() { # punani under archlinux first tries to load the packages with the given file name @@ -71,7 +79,7 @@ handle_system () { # # when trying harder it tries to load the package with the given name directly via yaourt echo "** trying to find package with given file" - if pacman -Sy `pkgfile $1`; then + if pacman -S `pkgfile $1` 2>/dev/null; then echo "++ finished" exit 0 else @@ -182,7 +190,7 @@ EOF punani (){ ns=punani role=undefined - while getopts 'dfhvSopEir' OPT; do + while getopts 'dfhvSsopEir' OPT; do case $OPT in (f) force=true; continue;; (h) hard=true; continue;; @@ -237,7 +245,6 @@ guess_system handle_system -command="${ns}_Engineer_insert" for name; do "$command" "$name" done -- cgit v1.2.3 From 81ab02668cc37c6e540fbfbc23a32828901b4660 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 12 Sep 2011 15:01:01 +0200 Subject: punani: deobfuscate source, handle multiple parms --- punani/bin/punani | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/punani/bin/punani b/punani/bin/punani index 1dd72542..7278e38a 100755 --- a/punani/bin/punani +++ b/punani/bin/punani @@ -90,10 +90,10 @@ handle_system () { mgr=`arch_aur_helper` if $mgr -S $1 ;then echo "++ finished" - exit 0 + return 0 else echo "!! giving up...i am sorry" - exit 1 + return 1 fi echo else @@ -241,10 +241,10 @@ case $role in esac shift `echo $OPTIND-1 | bc` -guess_system - +guess_system handle_system -for name; do - "$command" "$name" + +for name in "$@"; do + "$command" "$name" || echo "!! could not install $name" done -- cgit v1.2.3 From a9ee98ec26277014fd0f55ff414a71ece5c749aa Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 12 Sep 2011 15:04:25 +0200 Subject: punani/doc/release: add Angstrom linux detection --- punani/doc/releases | 3 +++ 1 file changed, 3 insertions(+) diff --git a/punani/doc/releases b/punani/doc/releases index 3b372d56..98c4ea82 100644 --- a/punani/doc/releases +++ b/punani/doc/releases @@ -33,3 +33,6 @@ UltraPenguin: /etc/ultrapenguin-release UnitedLinux: /etc/UnitedLinux-release (covers SUSE SLES8) VA-Linux/RH-VALE: /etc/va-release Yellow Dog: /etc/yellowdog-release + +# own collection +Angstrom: /etc/angstrom-version -- cgit v1.2.3 From 53107008a4e5640b3325fdebc56040e734527b3d Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 12 Sep 2011 15:29:50 +0200 Subject: retiolum/bin: get-tinc-dir returns the config dir of tinc supportet are currently all Linux/SunOS/Darwin as well as CYGWIN and MING --- retiolum/bin/get-tinc-dir | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 retiolum/bin/get-tinc-dir diff --git a/retiolum/bin/get-tinc-dir b/retiolum/bin/get-tinc-dir new file mode 100755 index 00000000..3f48b2cd --- /dev/null +++ b/retiolum/bin/get-tinc-dir @@ -0,0 +1,9 @@ +#!/bin/ksh +case `uname -a` in + Linux*|CYGWIN*|MING*) echo "/etc/tinc" + ;; + SunOS*|Darwin*) echo "/usr/local/etc/tinc" + ;; + *) echo "/etc/tinc" + ;; +esac -- cgit v1.2.3 From d095d11eb534695dc3eaadf3ac2d92b3f02828bd Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 12 Sep 2011 17:35:26 +0200 Subject: //Reaktor: redirect output to syslog --- Reaktor/index | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Reaktor/index b/Reaktor/index index ac647ca3..05827373 100755 --- a/Reaktor/index +++ b/Reaktor/index @@ -4,4 +4,11 @@ set -euf # cd //Reaktor cd $(dirname $(readlink -f $0)) +# redirect stdout [and stderr] to syslog +stdout=`mktemp -u` +mkfifo $stdout +trap "rm -vf $stdout" EXIT INT +exec 1<>$stdout 2>&1 +logger -t Reaktor -f $stdout & + exec IRC/index -- cgit v1.2.3 From b1519a3ddf17455639189ffb79cb51ddce60e45b Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 12 Sep 2011 17:51:47 +0200 Subject: //Reaktor/daemon: initial commit --- Reaktor/README.md | 6 +++--- Reaktor/daemon | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100755 Reaktor/daemon diff --git a/Reaktor/README.md b/Reaktor/README.md index 05af8ef5..a8f7d160 100644 --- a/Reaktor/README.md +++ b/Reaktor/README.md @@ -11,8 +11,8 @@ ## 3. marry Reaktor with /sbin/init ## 3a. /etc/inittab-like foo - echo 10:2345:respawn:/bin/su Reaktor -c /krebs/Reaktor/index >>/etc/inittab - # or 10:2345:respawn:/usr/bin/sudo -u Reaktor /krebs/Reaktor/index + echo 10:2345:respawn:/bin/su Reaktor -c /krebs/Reaktor/daemon >>/etc/inittab + # or 10:2345:respawn:/usr/bin/sudo -u Reaktor /krebs/Reaktor/daemon # if Reaktor's shell is /bin/false or similar # [check with e.g getent passwd Reaktor] telinit q @@ -24,6 +24,6 @@ author "The Ministerium" stop on runlevel [016] respawn - exec /usr/bin/sudo -u Reaktor /krebs/Reaktor/index + exec /usr/bin/sudo -u Reaktor /krebs/Reaktor/daemon EOF start Reaktor diff --git a/Reaktor/daemon b/Reaktor/daemon new file mode 100755 index 00000000..ae2b49f9 --- /dev/null +++ b/Reaktor/daemon @@ -0,0 +1,12 @@ +#! /bin/sh +# +# //Reaktor/daemon +# +# Start Reaktor as daemon w/o leaving an useless shell around. +# +set -euf + +# cd //Reaktor +cd $(dirname $(readlink -f $0)) + +./index & -- cgit v1.2.3 From 7448f050bd456c5eef2fbb5492c608d6760ea218 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 12 Sep 2011 19:29:36 +0200 Subject: Revert "//Reaktor/daemon: initial commit" This reverts commit b1519a3ddf17455639189ffb79cb51ddce60e45b. --- Reaktor/README.md | 6 +++--- Reaktor/daemon | 12 ------------ 2 files changed, 3 insertions(+), 15 deletions(-) delete mode 100755 Reaktor/daemon diff --git a/Reaktor/README.md b/Reaktor/README.md index a8f7d160..05af8ef5 100644 --- a/Reaktor/README.md +++ b/Reaktor/README.md @@ -11,8 +11,8 @@ ## 3. marry Reaktor with /sbin/init ## 3a. /etc/inittab-like foo - echo 10:2345:respawn:/bin/su Reaktor -c /krebs/Reaktor/daemon >>/etc/inittab - # or 10:2345:respawn:/usr/bin/sudo -u Reaktor /krebs/Reaktor/daemon + echo 10:2345:respawn:/bin/su Reaktor -c /krebs/Reaktor/index >>/etc/inittab + # or 10:2345:respawn:/usr/bin/sudo -u Reaktor /krebs/Reaktor/index # if Reaktor's shell is /bin/false or similar # [check with e.g getent passwd Reaktor] telinit q @@ -24,6 +24,6 @@ author "The Ministerium" stop on runlevel [016] respawn - exec /usr/bin/sudo -u Reaktor /krebs/Reaktor/daemon + exec /usr/bin/sudo -u Reaktor /krebs/Reaktor/index EOF start Reaktor diff --git a/Reaktor/daemon b/Reaktor/daemon deleted file mode 100755 index ae2b49f9..00000000 --- a/Reaktor/daemon +++ /dev/null @@ -1,12 +0,0 @@ -#! /bin/sh -# -# //Reaktor/daemon -# -# Start Reaktor as daemon w/o leaving an useless shell around. -# -set -euf - -# cd //Reaktor -cd $(dirname $(readlink -f $0)) - -./index & -- cgit v1.2.3 From 3aa12f6bcaf0ed4d7e55d686e8a0a4dc45301c36 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 13 Sep 2011 17:04:45 +0200 Subject: //Reaktor/IRC: replace irclib with own async bot Unfortunately irclib failed to detect stale connections. Asyboy comes to the rescue (maybe).^_^->deal with it...^_^ --- Reaktor/IRC/asybot.py | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++ Reaktor/IRC/bot.py | 34 ---------- Reaktor/IRC/bot2.py | 130 -------------------------------------- Reaktor/IRC/content | 1 - Reaktor/IRC/index | 2 +- Reaktor/IRC/install | 28 --------- Reaktor/README.md | 11 ++-- Reaktor/install | 6 -- 8 files changed, 174 insertions(+), 207 deletions(-) create mode 100755 Reaktor/IRC/asybot.py delete mode 100755 Reaktor/IRC/bot.py delete mode 100755 Reaktor/IRC/bot2.py delete mode 100644 Reaktor/IRC/content delete mode 100755 Reaktor/IRC/install delete mode 100755 Reaktor/install diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py new file mode 100755 index 00000000..6e9df1d9 --- /dev/null +++ b/Reaktor/IRC/asybot.py @@ -0,0 +1,169 @@ +#! /usr/bin/env python +# +# //Reaktor/IRC/asybot.py +# + +from __future__ import print_function + +def is_executable(x): + import os + return os.path.exists(x) and os.access(x, os.X_OK) + +from asynchat import async_chat as asychat +from asyncore import loop +from socket import AF_INET, SOCK_STREAM +from signal import SIGALRM, signal, alarm +from datetime import datetime as date, timedelta +from sys import exit +from re import split, search +class asybot(asychat): + def __init__(self, server, port, nickname, targets, **kwargs): + asychat.__init__(self) + self.server = server + self.port = port + self.nickname = nickname + self.targets = targets + self.username = kwargs['username'] if 'username' in kwargs else nickname + self.hostname = kwargs['hostname'] if 'hostname' in kwargs else nickname + self.ircname = kwargs['ircname'] if 'ircname' in kwargs else nickname + self.realname = kwargs['realname'] if 'realname' in kwargs else nickname + self.data = '' + self.set_terminator('\r\n') + self.create_socket(AF_INET, SOCK_STREAM) + self.connect((self.server, self.port)) + self.alarm_timeout = 300 + self.kill_timeout = 360 + self.last_activity = date.now() + signal(SIGALRM, lambda signum, frame: self.alarm_handler()) + alarm(self.alarm_timeout) + loop() + + def alarm_handler(self): + delta = date.now() - self.last_activity + if delta > timedelta(seconds=self.kill_timeout): + print('kill alarm %s' % delta) + exit() + else: + print('alarm %s' % delta) + self.push('PING :asybot') + alarm(self.alarm_timeout) + + def collect_incoming_data(self, data): + self.data += data + + def found_terminator(self): + print('< %s' % self.data) + self.last_activity = date.now() + + message = self.data + self.data = '' + + _, prefix, command, params, rest, _ = \ + split('^(?::(\S+)\s)?(\S+)((?:\s[^:]\S*)*)(?:\s:(.*))?$', message) + params = params.split(' ')[1:] + #print([prefix, command, params, rest]) + + if command == 'PING': + self.push('PONG :%s' % rest) + + elif command == 'PRIVMSG': + self.on_privmsg(prefix, command, params, rest) + + # reset alarm + alarm(self.alarm_timeout) + + def push(self, message): + print('> %s' % message) + asychat.push(self, message + self.get_terminator()) + + def handle_connect(self): + self.push('NICK %s' % self.nickname) + self.push('USER %s %s %s :%s' % + (self.username, self.hostname, self.server, self.realname)) + self.push('JOIN %s' % ','.join(self.targets)) + + def on_privmsg(self, prefix, command, params, rest): + def PRIVMSG(text): + self.push('PRIVMSG %s :%s' % (','.join(params), text)) + + def ME(text): + PRIVMSG('ACTION ' + text + '') + + _from = prefix.split('!', 1)[0] + + try: + _, _handle, _command, _argument, _ = split( + '^(\w+|\*):\s*(\w+)(?:\s+(.*))?$', rest) + except ValueError, error: + if search(self.nickname, rest): + PRIVMSG('I\'m so famous') + return # ignore + + if _handle == self.nickname or _handle == '*': + + from os.path import realpath, dirname, join + from subprocess import Popen as popen, PIPE + + Reaktor_dir = dirname(realpath(dirname(__file__))) + public_commands = join(Reaktor_dir, 'public_commands') + command = join(public_commands, _command) + + if is_executable(command): + + env = {} + if _argument != None: + env['argument'] = _argument + + try: + p = popen([command], stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) + except OSError, error: + ME('is made of stupid') + print('OSError@%s: %s' % (command, error)) + return + + stdout, stderr = [ x[:len(x)-1] for x in + [ x.split('\n') for x in p.communicate()]] + code = p.returncode + pid = p.pid + + print('command: %s -> %s' % (command, code)) + [print('%s stdout: %s' % (pid, x)) for x in stdout] + [print('%s stderr: %s' % (pid, x)) for x in stderr] + + if code == 0: + [PRIVMSG(x) for x in stdout] + [PRIVMSG(x) for x in stderr] + else: + ME('mimimi') + + else: + if _handle != '*': + PRIVMSG(_from + ': you are made of stupid') + +# retrieve the value of a [singleton] variable from a tinc.conf(5)-like file +def getconf1(x, path): + from re import findall + pattern = '(?:^|\n)\s*' + x + '\s*=\s*(.*\w)\s*(?:\n|$)' + y = findall(pattern, open(path, 'r').read()) + if len(y) < 1: + raise AttributeError("len(getconf1('%s', '%s') < 1)" % (x, path)) + if len(y) > 1: + y = ' '.join(y) + raise AttributeError("len(getconf1('%s', '%s') > 1)\n ====> %s" + % (x, path, y)) + return y[0] + +if __name__ == "__main__": + from os import environ as env + name = getconf1('Name', '/etc/tinc/retiolum/tinc.conf') + hostname = '%s.retiolum' % name + nick = str(env.get('nick', name)) + host = str(env.get('host', 'supernode')) + port = int(env.get('port', 6667)) + target = str(env.get('target', '#retiolum')) + print('====> irc://%s@%s:%s/%s' % (nick, host, port, target)) + + from getpass import getuser + asybot(host, port, nick, [target], username=getuser(), + ircname='//Reaktor running at %s' % hostname, + hostname=hostname) diff --git a/Reaktor/IRC/bot.py b/Reaktor/IRC/bot.py deleted file mode 100755 index af974f4e..00000000 --- a/Reaktor/IRC/bot.py +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env python2 - -from irclib import IRC, ServerConnectionError, is_channel -from sys import exit -from os import environ as env - -host = str(env.get('host', 'irc.freenode.org')) -port = int(env.get('port', 6667)) -nick = str(env.get('nick', 'crabspasm')) -channel = str(env.get('channel', '#tincspasm')) -print '====> irc://%s@%s:%s/%s' % (nick, host, port, channel) - -irc = IRC() -try: - client = irc.server().connect(host, port, nick) -except ServerConnectionError, error: - print error - exit - -def on_connect(connection, event): - connection.join(channel) - print 'Es passiert...' - -def on_join(connection, event): - connection.privmsg(channel, 'lol') - -def on_disconnect(connection, event): - exit - -client.add_global_handler('welcome', on_connect) -client.add_global_handler('join', on_join) -client.add_global_handler('disconnect', on_disconnect) - -irc.process_forever() diff --git a/Reaktor/IRC/bot2.py b/Reaktor/IRC/bot2.py deleted file mode 100755 index 326dd8f5..00000000 --- a/Reaktor/IRC/bot2.py +++ /dev/null @@ -1,130 +0,0 @@ -#! /usr/bin/env python -# -# //Reaktor/IRC/bot2.py -# - -from __future__ import print_function -from irclib import SimpleIRCClient, ServerConnectionError, is_channel -from sys import exit -from os import environ as env -import re - -class IRCBot(SimpleIRCClient): - def __init__(self, target): - SimpleIRCClient.__init__(self) - self.target = target - - def on_pubmsg(self, connection, event): - - def PRIVMSG(target, text): - self.connection.privmsg(target, text) - - def ME(target, text): - PRIVMSG(target, 'ACTION ' + text + '') - - def is_executable(x): - import os - return os.path.exists(x) and os.access(x, os.X_OK) - - _nickname = connection.get_nickname() - _source = event.source() - _from = _source.split('!', 1)[0] - _target = event.target() - - try: - _, _handle, _command, _argument, _ = re.split( - '^(\w+|\*):\s*(\w+)(?:\s+(.*))?$', event.arguments()[0]) - except ValueError, error: - if re.search(_nickname, event.arguments()[0]): - PRIVMSG(self.target, 'I\'m so famous') - return # ignore - - if _handle == _nickname or _handle == '*': - - from os.path import realpath, dirname, join - from subprocess import Popen as popen, PIPE - - Reaktor_dir = dirname(realpath(dirname(__file__))) - public_commands = join(Reaktor_dir, 'public_commands') - command = join(public_commands, _command) - - if is_executable(command): - - env = {} - if _argument != None: - env['argument'] = _argument - - try: - p = popen([command], stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) - except OSError, error: - ME(self.target, 'is made of stupid') - print('OSError@%s: %s' % (command, error)) - return - - stdout, stderr = [ x[:len(x)-1] for x in - [ x.split('\n') for x in p.communicate()]] - code = p.returncode - pid = p.pid - - print('command: %s -> %s' % (command, code)) - [print('%s stdout: %s' % (pid, x)) for x in stdout] - [print('%s stderr: %s' % (pid, x)) for x in stderr] - - if code == 0: - [PRIVMSG(self.target, x) for x in stdout] - [PRIVMSG(_source, x) for x in stderr] - else: - ME(self.target, 'mimimi') - - else: - if _handle != '*': - PRIVMSG(self.target, _from + ': you are made of stupid') - - def on_welcome(self, connection, event): - print('I\'m welcome! :D joining to %s now...' % (self.target)) - if is_channel(self.target): - connection.join(self.target) - else: - self.connection.privmsg(self.target, 'lol') - self.connection.quit('Pong timeout: 423 seconds') - - def on_join(self, connection, event): - print('Es passiert in %s' % (self.target)) - - def on_disconnect(self, connection, event): - # TODO reconnect - exit(0) - -# retrieve the value of a [singleton] variable from a tinc.conf(5)-like file -def getconf1(x, path): - from re import findall - pattern = '(?:^|\n)\s*' + x + '\s*=\s*(.*\w)\s*(?:\n|$)' - y = findall(pattern, open(path, 'r').read()) - if len(y) < 1: - raise AttributeError("len(getconf1('%s', '%s') < 1)" % (x, path)) - if len(y) > 1: - y = ' '.join(y) - raise AttributeError("len(getconf1('%s', '%s') > 1)\n ====> %s" - % (x, path, y)) - return y[0] - -def main(): - name = getconf1('Name', '/etc/tinc/retiolum/tinc.conf') - nick = str(env.get('nick', name)) - host = str(env.get('host', 'supernode')) - port = int(env.get('port', 6667)) - target = str(env.get('target', '#retiolum')) - print('====> irc://%s@%s:%s/%s' % (nick, host, port, target)) - - client = IRCBot(target) - try: - from getpass import getuser - client.connect(host, port, nick, username=getuser(), - ircname='//Reaktor running at %s.retiolum' % (name)) - except ServerConnectionError, error: - print(error) - exit(1) - client.start() - -if __name__ == "__main__": - main() diff --git a/Reaktor/IRC/content b/Reaktor/IRC/content deleted file mode 100644 index e0292376..00000000 --- a/Reaktor/IRC/content +++ /dev/null @@ -1 +0,0 @@ -python-irclib-0.4.6/ircbot.py diff --git a/Reaktor/IRC/index b/Reaktor/IRC/index index 68b6cf33..7b51632a 100755 --- a/Reaktor/IRC/index +++ b/Reaktor/IRC/index @@ -6,4 +6,4 @@ cd $(dirname $(readlink -f $0))/.. IRC/install -exec python IRC/bot2.py "$@" +exec python IRC/asybot.py "$@" diff --git a/Reaktor/IRC/install b/Reaktor/IRC/install deleted file mode 100755 index d5f7a8c1..00000000 --- a/Reaktor/IRC/install +++ /dev/null @@ -1,28 +0,0 @@ -#! /bin/sh -set -xeuf - -# cd //Reaktor/IRC -cd $(dirname $(readlink -f $0)) - -# install irclib.py -{ - PV=0.4.6 - PN=python-irclib - P=$PN-$PV - tarball=$P.tar.gz - URL=http://downloads.sourceforge.net/$PN/$tarball - SHA1SUM=c6271e44293ed51c21af0f44ce106667d3006e6f - - file=irclib.py - - if ! echo "$SHA1SUM $file" | sha1sum -c; then - temp=`mktemp` - trap "rm -f $temp" EXIT INT - - echo $P/$file > $temp - curl -LfsS $URL | tar --strip-components=1 -zxT $temp - fi - echo "$SHA1SUM $file" | sha1sum -c -} - - diff --git a/Reaktor/README.md b/Reaktor/README.md index 05af8ef5..b6ea89fc 100644 --- a/Reaktor/README.md +++ b/Reaktor/README.md @@ -2,22 +2,19 @@ ## Quickstart - ## 1. prepare Reaktor - //Reaktor/install - - ## 2. create a dedicated user + ## 1. create a dedicated user useradd Reaktor - ## 3. marry Reaktor with /sbin/init + ## 2. marry Reaktor with /sbin/init - ## 3a. /etc/inittab-like foo + ## 2a. /etc/inittab-like foo echo 10:2345:respawn:/bin/su Reaktor -c /krebs/Reaktor/index >>/etc/inittab # or 10:2345:respawn:/usr/bin/sudo -u Reaktor /krebs/Reaktor/index # if Reaktor's shell is /bin/false or similar # [check with e.g getent passwd Reaktor] telinit q - ## 3b. upstart-like foo + ## 2b. upstart-like foo cat > /etc/init/Reaktor.conf < Date: Tue, 13 Sep 2011 17:10:40 +0200 Subject: //Reaktor/IRC: remove dangling ptr to IRC/install --- Reaktor/IRC/index | 2 -- 1 file changed, 2 deletions(-) diff --git a/Reaktor/IRC/index b/Reaktor/IRC/index index 7b51632a..24982c76 100755 --- a/Reaktor/IRC/index +++ b/Reaktor/IRC/index @@ -4,6 +4,4 @@ set -xeuf # cd //Reaktor cd $(dirname $(readlink -f $0))/.. -IRC/install - exec python IRC/asybot.py "$@" -- cgit v1.2.3 From f42893411ca1f6d04c1741962826c9004a2afa6a Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 13 Sep 2011 17:23:25 +0200 Subject: //Reaktor: use debilian-compatible username --- Reaktor/README.md | 12 ++++++------ Reaktor/commands/reload | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Reaktor/README.md b/Reaktor/README.md index b6ea89fc..a581c6bd 100644 --- a/Reaktor/README.md +++ b/Reaktor/README.md @@ -3,15 +3,15 @@ ## Quickstart ## 1. create a dedicated user - useradd Reaktor + useradd reaktor ## 2. marry Reaktor with /sbin/init ## 2a. /etc/inittab-like foo - echo 10:2345:respawn:/bin/su Reaktor -c /krebs/Reaktor/index >>/etc/inittab - # or 10:2345:respawn:/usr/bin/sudo -u Reaktor /krebs/Reaktor/index - # if Reaktor's shell is /bin/false or similar - # [check with e.g getent passwd Reaktor] + echo 10:2345:respawn:/bin/su reaktor -c /krebs/Reaktor/index >>/etc/inittab + # or 10:2345:respawn:/usr/bin/sudo -u reaktor /krebs/Reaktor/index + # if reaktor's shell is /bin/false or similar + # [check with e.g getent passwd reaktor] telinit q ## 2b. upstart-like foo @@ -21,6 +21,6 @@ author "The Ministerium" stop on runlevel [016] respawn - exec /usr/bin/sudo -u Reaktor /krebs/Reaktor/index + exec /usr/bin/sudo -u reaktor /krebs/Reaktor/index EOF start Reaktor diff --git a/Reaktor/commands/reload b/Reaktor/commands/reload index 2b78b178..bfa1f041 100755 --- a/Reaktor/commands/reload +++ b/Reaktor/commands/reload @@ -1,2 +1,2 @@ #! /bin/sh -exec pkill -U Reaktor +exec pkill -U reaktor -- cgit v1.2.3 From ed66e3572fe5f75ea9f6fb900e56d986f18f0a52 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 13 Sep 2011 18:14:40 +0200 Subject: //Reaktor/IRC nickname: increment suffix Append or increment the bot's nickname suffix integer in order to connect to servers that already have users with the same nickname. --- Reaktor/IRC/asybot.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 6e9df1d9..6a37daf1 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -69,6 +69,14 @@ class asybot(asychat): elif command == 'PRIVMSG': self.on_privmsg(prefix, command, params, rest) + elif command == '433': + # ERR_NICKNAMEINUSE, retry with another name + _, nickname, int, _ = split('^.*[^0-9]([0-9]+)$', self.nickname) \ + if search('[0-9]$', self.nickname) \ + else ['', self.nickname, 0, ''] + self.nickname = nickname + str(int + 1) + self.handle_connect() + # reset alarm alarm(self.alarm_timeout) -- cgit v1.2.3 From 638e731abd026cfde963ee600b2b5c5079e8eda6 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 13 Sep 2011 18:44:13 +0200 Subject: //Reaktor/IRC: implement hammer time --- Reaktor/IRC/asybot.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 6a37daf1..1a84b9d4 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -31,29 +31,37 @@ class asybot(asychat): self.set_terminator('\r\n') self.create_socket(AF_INET, SOCK_STREAM) self.connect((self.server, self.port)) + + # When we don't receive data for alarm_timeout seconds then issue a + # PING every hammer_interval seconds until kill_timeout seconds have + # passed without a message. Any incoming message will reset alarm. self.alarm_timeout = 300 + self.hammer_interval = 10 self.kill_timeout = 360 - self.last_activity = date.now() signal(SIGALRM, lambda signum, frame: self.alarm_handler()) - alarm(self.alarm_timeout) + self.reset_alarm() + loop() + def reset_alarm(self): + self.last_activity = date.now() + alarm(self.alarm_timeout) + def alarm_handler(self): delta = date.now() - self.last_activity if delta > timedelta(seconds=self.kill_timeout): - print('kill alarm %s' % delta) - exit() + print('No data for %s. Giving up...' % delta) + exit(2) else: - print('alarm %s' % delta) - self.push('PING :asybot') - alarm(self.alarm_timeout) + print('No data for %s. PINGing server...' % delta) + self.push('PING :%s' % self.nickname) + alarm(self.hammer_interval) def collect_incoming_data(self, data): self.data += data def found_terminator(self): print('< %s' % self.data) - self.last_activity = date.now() message = self.data self.data = '' @@ -77,8 +85,7 @@ class asybot(asychat): self.nickname = nickname + str(int + 1) self.handle_connect() - # reset alarm - alarm(self.alarm_timeout) + self.reset_alarm() def push(self, message): print('> %s' % message) -- cgit v1.2.3 From d39f90f7c19b930b6b5bde0bbb716cbbbdb1d633 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 14 Sep 2011 00:48:36 +0200 Subject: Reaktor/IRC: update asybot logging facility now using python builtin logging DEBUG mode is enabled when the 'debug' environment variable is set on startup. --- Reaktor/IRC/asybot.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 1a84b9d4..9021d22f 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -3,8 +3,6 @@ # //Reaktor/IRC/asybot.py # -from __future__ import print_function - def is_executable(x): import os return os.path.exists(x) and os.access(x, os.X_OK) @@ -16,6 +14,10 @@ from signal import SIGALRM, signal, alarm from datetime import datetime as date, timedelta from sys import exit from re import split, search + +import logging +log = logging.getLogger() + class asybot(asychat): def __init__(self, server, port, nickname, targets, **kwargs): asychat.__init__(self) @@ -41,7 +43,6 @@ class asybot(asychat): signal(SIGALRM, lambda signum, frame: self.alarm_handler()) self.reset_alarm() - loop() def reset_alarm(self): self.last_activity = date.now() @@ -50,10 +51,10 @@ class asybot(asychat): def alarm_handler(self): delta = date.now() - self.last_activity if delta > timedelta(seconds=self.kill_timeout): - print('No data for %s. Giving up...' % delta) + log.error('No data for %s. Giving up...' % delta) exit(2) else: - print('No data for %s. PINGing server...' % delta) + log.error('No data for %s. PINGing server...' % delta) self.push('PING :%s' % self.nickname) alarm(self.hammer_interval) @@ -61,7 +62,7 @@ class asybot(asychat): self.data += data def found_terminator(self): - print('< %s' % self.data) + log.debug('<< %s' % self.data) message = self.data self.data = '' @@ -73,6 +74,7 @@ class asybot(asychat): if command == 'PING': self.push('PONG :%s' % rest) + log.info("Replying to servers PING with PONG :%s" %rest) elif command == 'PRIVMSG': self.on_privmsg(prefix, command, params, rest) @@ -88,7 +90,7 @@ class asybot(asychat): self.reset_alarm() def push(self, message): - print('> %s' % message) + log.debug('>> %s' % message) asychat.push(self, message + self.get_terminator()) def handle_connect(self): @@ -99,7 +101,8 @@ class asybot(asychat): def on_privmsg(self, prefix, command, params, rest): def PRIVMSG(text): - self.push('PRIVMSG %s :%s' % (','.join(params), text)) + msg = 'PRIVMSG %s :%s' % (','.join(params), text) + self.push(msg) def ME(text): PRIVMSG('ACTION ' + text + '') @@ -132,8 +135,8 @@ class asybot(asychat): try: p = popen([command], stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) except OSError, error: - ME('is made of stupid') - print('OSError@%s: %s' % (command, error)) + ME('brain damaged') + log.error('OSError@%s: %s' % (command, error)) return stdout, stderr = [ x[:len(x)-1] for x in @@ -141,9 +144,9 @@ class asybot(asychat): code = p.returncode pid = p.pid - print('command: %s -> %s' % (command, code)) - [print('%s stdout: %s' % (pid, x)) for x in stdout] - [print('%s stderr: %s' % (pid, x)) for x in stderr] + log.info('command: %s -> %s' % (command, code)) + [log.debug('%s stdout: %s' % (pid, x)) for x in stdout] + [log.debug('%s stderr: %s' % (pid, x)) for x in stderr] if code == 0: [PRIVMSG(x) for x in stdout] @@ -154,6 +157,7 @@ class asybot(asychat): else: if _handle != '*': PRIVMSG(_from + ': you are made of stupid') + # retrieve the value of a [singleton] variable from a tinc.conf(5)-like file def getconf1(x, path): @@ -170,15 +174,20 @@ def getconf1(x, path): if __name__ == "__main__": from os import environ as env + + lol = logging.DEBUG if env.get('debug',False) else logging.INFO + logging.basicConfig(level=lol) name = getconf1('Name', '/etc/tinc/retiolum/tinc.conf') hostname = '%s.retiolum' % name nick = str(env.get('nick', name)) host = str(env.get('host', 'supernode')) port = int(env.get('port', 6667)) target = str(env.get('target', '#retiolum')) - print('====> irc://%s@%s:%s/%s' % (nick, host, port, target)) + log.info('=> irc://%s@%s:%s/%s' % (nick, host, port, target)) from getpass import getuser asybot(host, port, nick, [target], username=getuser(), ircname='//Reaktor running at %s' % hostname, hostname=hostname) + + loop() -- cgit v1.2.3 From dcb9737ae58fea03b714675eb4cc8d7b6f52ccf4 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 14 Sep 2011 03:06:50 +0200 Subject: //hyper/process main.go: first steps --- hyper/process/main.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 hyper/process/main.go diff --git a/hyper/process/main.go b/hyper/process/main.go new file mode 100644 index 00000000..297be2cf --- /dev/null +++ b/hyper/process/main.go @@ -0,0 +1,52 @@ +package main + +import "fmt" +import "os" + + +func reader(file *os.File) { + var b []byte = make([]byte, 1024) + var err os.Error = nil + for err == nil { + var n int + n, err = file.Read(b) + fmt.Printf("data: %d, %s\n", n, b) + } +} + +func main() { + var name = "/usr/bin/bc" + var argv = []string{ "bc" } + var envv = []string{ "FOO=23" } + //var chroot = false + var dir = "/var/empty" + var files [3][2]*os.File + var err os.Error + + for i, _ := range files { + files[i][0], files[i][1], err = os.Pipe() + err = err + } + + var attr = &os.ProcAttr{ + Dir: dir, + Env: envv, + Files: []*os.File{ /*files[0][0] */ os.Stdin, files[1][1], files[2][1]}, + } + + var p *os.Process + + p, err = os.StartProcess(name, argv, attr) + + for _, file := range attr.Files { + file.Close() + } + + p=p + + go reader(files[1][0]) + reader(files[2][0]) + + fmt.Printf("hello, world\n") + +} -- cgit v1.2.3 From 6cb808fa910cb32a9ec786616be7b821a500e8d8 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 14 Sep 2011 03:13:20 +0200 Subject: //hyper/process Makefile: initial commit --- hyper/process/Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 hyper/process/Makefile diff --git a/hyper/process/Makefile b/hyper/process/Makefile new file mode 100644 index 00000000..7d61b28d --- /dev/null +++ b/hyper/process/Makefile @@ -0,0 +1,14 @@ + +A := 8 + +.PHONY: all clean +all: main + +clean: + rm -f main *.$A + +%.$A: %.go + $Ag $< + +%: %.$A + $Al -o $@ $< -- cgit v1.2.3 From 893054fb784cb6c2908817a27248b42c526cb3d5 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 14 Sep 2011 17:59:52 +0200 Subject: punani: fix help bug --- punani/bin/punani | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/punani/bin/punani b/punani/bin/punani index 7278e38a..91f250e1 100755 --- a/punani/bin/punani +++ b/punani/bin/punani @@ -190,7 +190,7 @@ EOF punani (){ ns=punani role=undefined - while getopts 'dfhvSsopEir' OPT; do + while getopts 'dfhvSsopEir?' OPT; do case $OPT in (f) force=true; continue;; (h) hard=true; continue;; -- cgit v1.2.3 From 044eae2d6cefd134da1804050526b343e7cb4148 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 14 Sep 2011 18:03:09 +0200 Subject: punani: add verbose function --- punani/bin/punani | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/punani/bin/punani b/punani/bin/punani index 91f250e1..d118b13c 100755 --- a/punani/bin/punani +++ b/punani/bin/punani @@ -194,7 +194,7 @@ punani (){ case $OPT in (f) force=true; continue;; (h) hard=true; continue;; - (v) verbose=true; continue;; + (v) set -x; continue;; (d) dryrun=true; continue;; (\?) help;continue ;; esac -- cgit v1.2.3 From a8ab9dbc2de0ee3aa744485255360b5e5e8b45cd Mon Sep 17 00:00:00 2001 From: root Date: Wed, 14 Sep 2011 20:36:40 +0200 Subject: Reaktor/asybot: add syslog logging feature --- Reaktor/IRC/asybot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 9021d22f..99cb2fe6 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -15,8 +15,12 @@ from datetime import datetime as date, timedelta from sys import exit from re import split, search -import logging -log = logging.getLogger() +import logging,logging.handlers +log = logging.getLogger('asybot') +hdlr = logging.handlers.SysLogHandler(facility=logging.handlers.SysLogHandler.LOG_DAEMON) +formatter = logging.Formatter( '%(filename)s: %(levelname)s: %(message)s') +hdlr.setFormatter(formatter) +log.addHandler(hdlr) class asybot(asychat): def __init__(self, server, port, nickname, targets, **kwargs): -- cgit v1.2.3 From 1e9f32bf57ab45ff1d3a61294e323b9c0cd3309b Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 14 Sep 2011 21:47:41 +0200 Subject: //hyper/process: Emergency Commit #2 --- hyper/process/Makefile | 23 +++--- hyper/process/main.go | 80 +++++++++--------- hyper/process/src/hyper/process/Makefile | 11 +++ hyper/process/src/hyper/process/process.go | 125 +++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 45 deletions(-) create mode 100644 hyper/process/src/hyper/process/Makefile create mode 100644 hyper/process/src/hyper/process/process.go diff --git a/hyper/process/Makefile b/hyper/process/Makefile index 7d61b28d..bbc1c2fb 100644 --- a/hyper/process/Makefile +++ b/hyper/process/Makefile @@ -1,14 +1,19 @@ +include $(GOROOT)/src/Make.inc -A := 8 +GCIMPORTS = -I pkg/$(GOOS)_$(GOARCH) +LDIMPORTS = -L pkg/$(GOOS)_$(GOARCH) -.PHONY: all clean -all: main +TARG=main +GOFILES=\ + main.go\ -clean: - rm -f main *.$A +include $(GOROOT)/src/Make.cmd -%.$A: %.go - $Ag $< +export GOPATH := $(PWD) +.PHONY: prepare +prepare: + #goinstall -v github.com/garyburd/twister/server + goinstall -v gorilla.googlecode.com/hg/gorilla/mux + goinstall -v $(PWD)/src/hyper/process -%: %.$A - $Al -o $@ $< +_go_.$O: prepare diff --git a/hyper/process/main.go b/hyper/process/main.go index 297be2cf..ebeeb6d6 100644 --- a/hyper/process/main.go +++ b/hyper/process/main.go @@ -1,52 +1,60 @@ package main -import "fmt" +import "json" +import "log" +import "http" +import "gorilla.googlecode.com/hg/gorilla/mux" import "os" +import "fmt" + +import "hyper/process" +var proc = map[string] *hyper.Process{} -func reader(file *os.File) { - var b []byte = make([]byte, 1024) - var err os.Error = nil - for err == nil { - var n int - n, err = file.Read(b) - fmt.Printf("data: %d, %s\n", n, b) +// TODO Retrieve Process, Write, Kill [autokill], get exit code + +func RespondJSON(res http.ResponseWriter, v interface{}) os.Error { + content, err := json.Marshal(v) + if err == nil { + log.Printf("< %s", content) + res.Header().Set("Content-Type", "application/json; charset=\"utf-8\"") + res.WriteHeader(http.StatusOK) + res.Write(content) + } else { + log.Printf("%s while json.Marshal(%s)", err, v) } + return err } -func main() { - var name = "/usr/bin/bc" - var argv = []string{ "bc" } - var envv = []string{ "FOO=23" } - //var chroot = false - var dir = "/var/empty" - var files [3][2]*os.File - var err os.Error - - for i, _ := range files { - files[i][0], files[i][1], err = os.Pipe() - err = err +func CreateProcessHandler(res http.ResponseWriter, req *http.Request) { + if p, err := hyper.NewProcess(req); err == nil { + id := p.Id() + proc[id] = p + RespondJSON(res, &map[string]string{ + "path": fmt.Sprintf("/proc/%s", id), + }) + } else { + log.Printf("%s", err) + res.WriteHeader(http.StatusInternalServerError) } +} - var attr = &os.ProcAttr{ - Dir: dir, - Env: envv, - Files: []*os.File{ /*files[0][0] */ os.Stdin, files[1][1], files[2][1]}, +func RetrieveProcess(res http.ResponseWriter, req *http.Request) { + if p := proc[mux.Vars(req)["id"]]; p != nil { + RespondJSON(res, p) + } else { + res.WriteHeader(http.StatusNotFound) } +} - var p *os.Process +func main() { - p, err = os.StartProcess(name, argv, attr) + // Gorilla + mux.HandleFunc("/proc", CreateProcessHandler).Methods("POST") + mux.HandleFunc("/proc/{id}", RetrieveProcess).Methods("GET") - for _, file := range attr.Files { - file.Close() + err := http.ListenAndServe(":8888", mux.DefaultRouter) + if err != nil { + log.Fatal("ListenAndServe: ", err.String()) } - - p=p - - go reader(files[1][0]) - reader(files[2][0]) - - fmt.Printf("hello, world\n") - } diff --git a/hyper/process/src/hyper/process/Makefile b/hyper/process/src/hyper/process/Makefile new file mode 100644 index 00000000..7ecda716 --- /dev/null +++ b/hyper/process/src/hyper/process/Makefile @@ -0,0 +1,11 @@ +include ${GOROOT}/src/Make.inc + +TARG=hyper/process + +GOFILES=\ + process.go\ + +#DEPS=\ +# gorilla.googlecode.com/hg/gorilla/context\ + +include ${GOROOT}/src/Make.pkg diff --git a/hyper/process/src/hyper/process/process.go b/hyper/process/src/hyper/process/process.go new file mode 100644 index 00000000..a52197f0 --- /dev/null +++ b/hyper/process/src/hyper/process/process.go @@ -0,0 +1,125 @@ +package hyper + +import "fmt" +import "http" +import "bytes" +import "json" +import "os" + +type Process struct { + Path string `json:"path"` + Argv []string `json:"argv"` + Envp map[string]string `json:"envp"` + //Stdin string `json:"stdin"` + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` + process *os.Process + process_stdin *os.File + process_stdout *os.File + process_stderr *os.File + id string +} + +func (p *Process) Id() string { + return p.id +} + +func NewProcess(req *http.Request) (*Process, os.Error) { + body := make([]byte, 4096) + _, err := req.Body.Read(body) + if err != nil { + return nil, err + } + + body = bytes.TrimRight(body, string([]byte{0})) + + var p Process + + if err := json.Unmarshal(body, &p); err != nil { + return nil, err + } + + p.id = gensym() + + if err := p.Start(); err != nil { + return nil, err + } + + return &p, nil +} + +func (hp *Process) Write(b []byte) { + n, err := hp.process_stdin.Write(b) + if err != nil { + fmt.Printf("Write: %s\n", err) + } else { + fmt.Printf("Wrote: %d bytes\n", n) + } +} + +func (hp *Process) Start() os.Error { + var name = hp.Path //os.Args[1] //"/usr/b" + var argv = hp.Argv //os.Args[1:] //[]string{ "bc" } + //var chroot = false + //var dir = "/var/empty" + var files [3][2]*os.File + var err os.Error + + for i, _ := range files { + files[i][0], files[i][1], err = os.Pipe() + if err != nil { + return err + } + } + + var env []string + for k, v := range hp.Envp { + env = append(env, fmt.Sprintf("%s=%s", k, v)) + } + + var attr = &os.ProcAttr{ + //Dir: dir, + Env: env, //os.Environ(), + Files: []*os.File{ files[0][0], files[1][1], files[2][1]}, + } + + //var foo, _ = json.Marshal(attr) + //fmt.Printf("%s\n", foo) + + hp.process, err = os.StartProcess(name, argv, attr) + if err != nil { + return err + } + + hp.process_stdin = files[0][1] + hp.process_stdout = files[1][0] + hp.process_stderr = files[2][0] + + for _, file := range attr.Files { + file.Close() + } + + go reader(hp.process_stdout) + go reader(hp.process_stderr) + return nil +} + +func reader(file *os.File) { + var b []byte = make([]byte, 1024) + var err os.Error = nil + for err == nil { + var n int + n, err = file.Read(b) + fmt.Printf("data: %d, %s\n", n, b) + } +} + +func gensym() string { + f, _ := os.Open("/dev/urandom") + b := make([]byte, 16) + f.Read(b) + f.Close() + uuid := fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) + return uuid +} + -- cgit v1.2.3 From cd9ad4429884c4418bac04265881c118191ade50 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 14 Sep 2011 21:58:15 +0200 Subject: //retiolum/hosts/zerg: initial commit --- retiolum/hosts/zerg | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 retiolum/hosts/zerg diff --git a/retiolum/hosts/zerg b/retiolum/hosts/zerg new file mode 100644 index 00000000..9a3d365a --- /dev/null +++ b/retiolum/hosts/zerg @@ -0,0 +1,10 @@ +Subnet = 42:448b:2bdc:d090:9f0f:a957:01a7:7254/128 +Subnet = 10.7.7.18 +-----BEGIN RSA PUBLIC KEY----- +MIIBCgKCAQEAxLkTKBXMgChxgPlMlLqqGRx/MSZos2dkXdCw7pzyO9HRwYi2Ax1j +frVG8Z6YQJAxGv4mOtSLEkSfgzgg0AgCb1o0/fniFabYgBVBMr7K5HvnoJz+ODP2 +49O7+m8t495ygOVY/qO6u4ezSbzDTqcPUjQxUHRo1Ik4/uDjvkPe+rbxC2ZTVW/Z +YnhSaWwH/GkzI9T8OCmAGetdrsXKY+h/ukVJB89qHXAs2fqWIUvujyfwN/mj5mx4 +BT28RJr2/Mx2ivb1Dq1t8iaxNx+I8q5/WVl0EfZBKkSHsXtqzg9xqwzMS37dF356 +0uq2uuysIDbFMXF3jYvFSZyxCmgXNzvN5QIDAQAB +-----END RSA PUBLIC KEY----- -- cgit v1.2.3 From 7c006192b5990176acdd546065105d53fe59b908 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 14 Sep 2011 23:41:50 +0200 Subject: tinc_setup: update install.sh to write new supernode EUcancER is the new supernode which can be used to connect to --- retiolum/scripts/tinc_setup/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/retiolum/scripts/tinc_setup/install.sh b/retiolum/scripts/tinc_setup/install.sh index 526dbe1f..547cf366 100755 --- a/retiolum/scripts/tinc_setup/install.sh +++ b/retiolum/scripts/tinc_setup/install.sh @@ -56,6 +56,7 @@ Name = $myname ConnectTo = supernode ConnectTo = kaah ConnectTo = pa_sharepoint +ConnectTo = EUcancER Device = /dev/net/tun EOF -- cgit v1.2.3 From b172e0b1314d1eaec8f72710e6b44ef3acdd859a Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 15 Sep 2011 00:14:41 +0200 Subject: //hyper/sink: initial commit --- hyper/sink/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 hyper/sink/index.js diff --git a/hyper/sink/index.js b/hyper/sink/index.js new file mode 100644 index 00000000..b556b88d --- /dev/null +++ b/hyper/sink/index.js @@ -0,0 +1,13 @@ +require('http').createServer(function (req, res) { + + req.on('data', function (data) { + require('util').puts(data); + }); + + req.on('end', function () { + res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Length': 0}); + res.end(); + }); +}).listen(1337, '127.0.0.1', function () { + console.log('Running HyperSink at http://127.0.0.1:1337/'); +}); -- cgit v1.2.3 From 668ca493744636a5fe090d431f9d36e97be7907b Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 15 Sep 2011 00:15:36 +0200 Subject: //hyper/process: route POST /proc/{id} to stdin --- hyper/process/main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hyper/process/main.go b/hyper/process/main.go index ebeeb6d6..5420f681 100644 --- a/hyper/process/main.go +++ b/hyper/process/main.go @@ -6,6 +6,7 @@ import "http" import "gorilla.googlecode.com/hg/gorilla/mux" import "os" import "fmt" +import "bytes" import "hyper/process"