From 62be5c21f9fa17f7452acf8064800911faae051d Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 9 Dec 2013 22:17:22 +0100 Subject: make http_head both look similar when using either wget or curl --- ship/lib/network | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ship/lib/network b/ship/lib/network index 29eefdbe..90d7ec4f 100644 --- a/ship/lib/network +++ b/ship/lib/network @@ -10,7 +10,7 @@ which_get_loader(){ echo "wget -O-" fi else - echo "curl" + echo "curl -s" fi return 0 } @@ -21,19 +21,19 @@ which_head_loader(){ warn "Please install curl or wget" return 1 else - echo "wget -O- --spider" + echo "wget -O- --spider -S -q" fi else - echo "curl -I" + echo "curl -I -s" fi return 0 } http_get(){ - eval "$(which_get_loader)" "${1?please provide url}" + eval "$(which_get_loader)" "${1?please provide url}" 2>&1 } http_head(){ - eval "$(which_head_loader)" "${1?please provide url}" + eval "$(which_head_loader)" "${1?please provide url}" 2>&1 } which_telnet(){ -- cgit v1.2.3 From 893c529590c68c0d0c1fdd1e39f442023f434404 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 11 Dec 2013 00:55:30 +0100 Subject: add @strict macro, fix @info for code not under version control (private code) --- ship/build | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ship/build b/ship/build index 5863e325..2051a7db 100755 --- a/ship/build +++ b/ship/build @@ -40,12 +40,22 @@ EOF fi } +## usage: #@strict -> build_strict_mode \1 +build_strict_mode() { cat< build_info \1 -build_info() { cat</dev/null || true) +cat<> "$buildcache" } + + ### ### main invocation ### -- cgit v1.2.3 From 9c5150a71affdd436a524f4f96c2c001f18ef09f Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 11 Dec 2013 01:17:30 +0100 Subject: build - because : is the new true --- ship/build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ship/build b/ship/build index 2051a7db..f7dcf3c2 100755 --- a/ship/build +++ b/ship/build @@ -44,13 +44,13 @@ EOF build_strict_mode() { cat< build_info \1 -build_info() { - gitinfo=$(git describe --always --dirty --abbrev=0 2>/dev/null || true) +build_info() { + gitinfo=$(git describe --always --dirty --abbrev=0 2>/dev/null || :) cat< Date: Wed, 11 Dec 2013 11:39:46 +0100 Subject: RIP vvs.de --- .graveyard/util/bin/vvs.de | 61 ++++++++++++++++++++++++++++++++++++++++++++++ util/bin/vvs.de | 61 ---------------------------------------------- 2 files changed, 61 insertions(+), 61 deletions(-) create mode 100755 .graveyard/util/bin/vvs.de delete mode 100755 util/bin/vvs.de diff --git a/.graveyard/util/bin/vvs.de b/.graveyard/util/bin/vvs.de new file mode 100755 index 00000000..3b7ccf93 --- /dev/null +++ b/.graveyard/util/bin/vvs.de @@ -0,0 +1,61 @@ +#! /bin/sh +# +# NAME +# vvs.de - web scraper for VVS departure information +# +# SYNOPSIS +# vvs.de ORIGIN DESTINATION [HH [MM]] +# +# EXAMPLES +# $ vvs.de Hauptbahnhof Renningen 13 37 +# +# CAVEATS +# Acceptable operands have to be found by trial and error. +# +# BUGS +# Probably bit rot.^_^ +# +# SEE ALSO +# mobile.vvs.de +# +# COPYRIGHT +# All departure information is copyrighted by Verkehrs- und +# Tarifverbund Stuttgart GmbH. The original copyright statement can +# be obtained online at http://www.vvs.de/impressum . +# +# The following code is your fault. +# +set -euf + +#
+ #s/itdDateDay=/&${3-$itdDateDay}/ + #s/itdDateMonth=/&${4-$itdDateMonth}/ + #s/itdDateYear=/&${5-$itdDateYear}/ + +vvs_tmp=/tmp/vvs.tmp +curl -Ss http://www.vvs.de/fahrplan/ | +sed -rn "//,//{ + s.*.*\1=\2;T + /itdTripDateTimeDepArr=arr/b + s/(name_origin=).*/\1${1-$name_origin}/ + s/(name_destination=).*/\1${2-$name_destination}/ + ${3+s/(itdTimeHour=).*/\1${3-$itdTimeHour}/} + ${4+s/(itdTimeMinute=).*/\1${4-$itdTimeMinute}/} + p +}" | tr '\n' '&' | sed 's/&$//' >"$vvs_tmp" + + +#while read line ; do +# test -z "$line" || echo "$line" +#done >"$vvs_tmp" + +echo from: ${1-$name_origin} +echo \ \ to: ${2-$name_destination} +echo '-------------------------------------' +w3m -cols 9423 -post "$vvs_tmp" \ + -dump http://www.vvs.de/./efaanyfield/anyfield.php | +sed -rn " + s/^ +[0-9]+ +([0-9]+:[0-9]+) +([0-9]+:[0-9]+) +([A-Z0-9 ,]+) .*$/\1 \2 \3/p +" | tr -d , + +#### diff --git a/util/bin/vvs.de b/util/bin/vvs.de deleted file mode 100755 index 3b7ccf93..00000000 --- a/util/bin/vvs.de +++ /dev/null @@ -1,61 +0,0 @@ -#! /bin/sh -# -# NAME -# vvs.de - web scraper for VVS departure information -# -# SYNOPSIS -# vvs.de ORIGIN DESTINATION [HH [MM]] -# -# EXAMPLES -# $ vvs.de Hauptbahnhof Renningen 13 37 -# -# CAVEATS -# Acceptable operands have to be found by trial and error. -# -# BUGS -# Probably bit rot.^_^ -# -# SEE ALSO -# mobile.vvs.de -# -# COPYRIGHT -# All departure information is copyrighted by Verkehrs- und -# Tarifverbund Stuttgart GmbH. The original copyright statement can -# be obtained online at http://www.vvs.de/impressum . -# -# The following code is your fault. -# -set -euf - -# - #s/itdDateDay=/&${3-$itdDateDay}/ - #s/itdDateMonth=/&${4-$itdDateMonth}/ - #s/itdDateYear=/&${5-$itdDateYear}/ - -vvs_tmp=/tmp/vvs.tmp -curl -Ss http://www.vvs.de/fahrplan/ | -sed -rn "//,//{ - s.*.*\1=\2;T - /itdTripDateTimeDepArr=arr/b - s/(name_origin=).*/\1${1-$name_origin}/ - s/(name_destination=).*/\1${2-$name_destination}/ - ${3+s/(itdTimeHour=).*/\1${3-$itdTimeHour}/} - ${4+s/(itdTimeMinute=).*/\1${4-$itdTimeMinute}/} - p -}" | tr '\n' '&' | sed 's/&$//' >"$vvs_tmp" - - -#while read line ; do -# test -z "$line" || echo "$line" -#done >"$vvs_tmp" - -echo from: ${1-$name_origin} -echo \ \ to: ${2-$name_destination} -echo '-------------------------------------' -w3m -cols 9423 -post "$vvs_tmp" \ - -dump http://www.vvs.de/./efaanyfield/anyfield.php | -sed -rn " - s/^ +[0-9]+ +([0-9]+:[0-9]+) +([0-9]+:[0-9]+) +([A-Z0-9 ,]+) .*$/\1 \2 \3/p -" | tr -d , - -#### -- cgit v1.2.3 From 719ac6102fdd5c8aa557a30a4a3c965825b2b2fa Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Dec 2013 11:41:14 +0100 Subject: RIP mobile vvs and smoke tests --- .graveyard/util/bin/mobile.vvs.de | 167 +++++++++++++++++++++++++++++ .graveyard/util/t/mobile.vvs.de/smoke-test | 5 + .graveyard/util/t/vvs.de/smoke-test | 11 ++ util/bin/mobile.vvs.de | 167 ----------------------------- util/t/mobile.vvs.de/smoke-test | 5 - util/t/vvs.de/smoke-test | 11 -- 6 files changed, 183 insertions(+), 183 deletions(-) create mode 100755 .graveyard/util/bin/mobile.vvs.de create mode 100755 .graveyard/util/t/mobile.vvs.de/smoke-test create mode 100755 .graveyard/util/t/vvs.de/smoke-test delete mode 100755 util/bin/mobile.vvs.de delete mode 100755 util/t/mobile.vvs.de/smoke-test delete mode 100755 util/t/vvs.de/smoke-test diff --git a/.graveyard/util/bin/mobile.vvs.de b/.graveyard/util/bin/mobile.vvs.de new file mode 100755 index 00000000..fdc4cca2 --- /dev/null +++ b/.graveyard/util/bin/mobile.vvs.de @@ -0,0 +1,167 @@ +#! /bin/sh +# +# NAME +# mobile.vvs.de - web scraper for VVS departure information +# +# SYNOPSIS +# mobile.vvs.de ORIGIN [HH [MM [YYmmdd]]] +# +# DESCRIPTION +# The mobile.vvs.de utility fetches departure information from the +# Internet and prints the results to standard output. +# +# OPERANDS +# ORIGIN The point of departure. +# +# HH, MM, YYmmdd +# The time and date of departure. Defaults to the current +# time and date. +# +# STDIN +# Not used. +# +# INPUT FILES +# None. +# +# ENVIRONMENT VARIABLES +# The following environment variables affect the execution of mobile.vvs.de: +# +# limit Limits the number of entries to be fetched. +# +# origin, H, M, Ymd +# Provide defaults operands. If origin is set, then ORIGIN +# becomes optional. The order of the operands doesn't change +# by these variables. These variables are overridden by the +# operands. +# +# ASYNCHRONOUS EVENTS +# Defaults. +# +# STDOUT +# The first line has the format: +# +# "\e[4m%s:%s %s\e[m\n", H, M, origin_real_name +# +# where H and M are the corresponding provided or default operands. +# origin_real_name is the real name of the point of departure. +# +# The subsequent lines specify the departing means of transport. +# Each line has the format: +# +# "%s %s → %s\n", time_of_departure, line_number, destination +# +# where time_of_departure is self-evident, and line_number and +# destination identify the route and direction. +# +# STDERR +# Not used. +# +# OUTPUT FILES +# None. +# +# EXTENDED DESCRIPTION +# None. +# +# EXIT STATUS +# 0 A departure board could be fetched. +# +# 1 ORIGIN doesn't specify an acceptable point of departure. +# +# EXAMPLES +# 1. Get the top three current departures at Stuttgart, Hauptbahnhof: +# +# $ limit=3 mobile.vvs.de hauptbahnhof +# +# FUTURE DIRECTIONS +# None. +# +# BUGS +# The format of STDOUT suffers from bit rot. +# +# SEE ALSO +# vvs.de +# +# COPYRIGHT +# All departure information is copyrighted by Verkehrs- und +# Tarifverbund Stuttgart GmbH. The original copyright statement can +# be obtained online at http://www.vvs.de/impressum . +# +# The following code is your fault. +# +set -euf + +ltrim() { + sed "s/^[${1-$symbols}]*//" +} + +POST() { + ## TODO url-encode, trim + tr '\n' '&' | sed 's/&$//' | + w3m -config /dev/null -cols 256 -post /dev/stdin -dump "${1-$URI}" +} + +limit=${limit-10} +origin="${1-$origin}" +H="${2-${H-`date +%H`}}" +M="${3-${M-`date +%M`}}" +Ymd="${4-${Ymd-`date +%Y%m%d`}}" + +URI='http://mobil.vvs.de/mobile/XSLT_DM_REQUEST' + +echo " +sessionID=0 +requestID=0 +language=de +locationServerActive=1 +useRealtime=1 +anySigWhenPerfectNoOtherMatches=1 +limit=$limit +deleteAssignedStops_dm=1 +mode=direct +convertCrossingsITKernel2LocationServer=1 +convertStopsPTKernel2LocationServer=1 +convertAddressesITKernel2LocationServer=1 +convertPOIsITKernel2LocationServer=1 +itdLPxx_dest= +useAllStops=1 +maxAssignedStops=1 +itOptionsActive=1 +trITMOTvalue100=5 +ptOptionsActive=1 +useProxFootSearch=0 +w_regPrefAm=1 +w_objPrefAl=2 +w_objPrefAl=12 +itdLPxx_script=true +place_dm= +placeState_dm=empty +nameState_dm=empty +nameInfo_dm=invalid +typeInfo_dm=invalid +placeInfo_dm=invalid +reducedAnyWithoutAddressObjFilter_dm=103 +reducedAnyPostcodeObjFilter_dm=64 +reducedAnyTooManyObjFilter_dm=2 +anyObjFilter_dm=126 +type_dm=any +name_dm=$origin +itdTimeHour=`echo $H | ltrim 0` +itdTimeMinute=`echo $M | ltrim 0` +itdDate=$Ymd +" | POST "$URI" | sed -rn ' + s/^Von:[^[:alpha:]]+(.*)$/'$H:$M' \1/p + /Haltestelle/,/^ *$/{ + /Haltestelle|^ *$/!{ + s/[[:space:]]*\[info\][[:space:]]*$// + p + } + } +' | { + read REPLY + echo "$REPLY" + while read time dev no dest ; do + printf "$time %3s → %s\n" $no "$dest" + done +} + +#### diff --git a/.graveyard/util/t/mobile.vvs.de/smoke-test b/.graveyard/util/t/mobile.vvs.de/smoke-test new file mode 100755 index 00000000..0b9e7960 --- /dev/null +++ b/.graveyard/util/t/mobile.vvs.de/smoke-test @@ -0,0 +1,5 @@ +#! /bin/sh +set -euf +mobile.vvs.de hauptbahnhof | + sed -n 'p;q' | + grep -q '\[4m[0-9][0-9]:[0-9][0-9] Stuttgart, Hauptbahnhof\[m' diff --git a/.graveyard/util/t/vvs.de/smoke-test b/.graveyard/util/t/vvs.de/smoke-test new file mode 100755 index 00000000..451270fe --- /dev/null +++ b/.graveyard/util/t/vvs.de/smoke-test @@ -0,0 +1,11 @@ +#! /bin/sh +set -euf + +vvs.de Hauptbahnhof Renningen 13 37 | { + read from && test "x$from" = 'xfrom: Hauptbahnhof' + read to && test "x$to" = 'xto: Renningen' + read sep && test "x$sep" = 'x-------------------------------------' + while read line; do + echo "$line" | grep -q '^[0-9][0-9]:[0-9][0-9] [0-9][0-9]:[0-9][0-9] ' + done +} diff --git a/util/bin/mobile.vvs.de b/util/bin/mobile.vvs.de deleted file mode 100755 index fdc4cca2..00000000 --- a/util/bin/mobile.vvs.de +++ /dev/null @@ -1,167 +0,0 @@ -#! /bin/sh -# -# NAME -# mobile.vvs.de - web scraper for VVS departure information -# -# SYNOPSIS -# mobile.vvs.de ORIGIN [HH [MM [YYmmdd]]] -# -# DESCRIPTION -# The mobile.vvs.de utility fetches departure information from the -# Internet and prints the results to standard output. -# -# OPERANDS -# ORIGIN The point of departure. -# -# HH, MM, YYmmdd -# The time and date of departure. Defaults to the current -# time and date. -# -# STDIN -# Not used. -# -# INPUT FILES -# None. -# -# ENVIRONMENT VARIABLES -# The following environment variables affect the execution of mobile.vvs.de: -# -# limit Limits the number of entries to be fetched. -# -# origin, H, M, Ymd -# Provide defaults operands. If origin is set, then ORIGIN -# becomes optional. The order of the operands doesn't change -# by these variables. These variables are overridden by the -# operands. -# -# ASYNCHRONOUS EVENTS -# Defaults. -# -# STDOUT -# The first line has the format: -# -# "\e[4m%s:%s %s\e[m\n", H, M, origin_real_name -# -# where H and M are the corresponding provided or default operands. -# origin_real_name is the real name of the point of departure. -# -# The subsequent lines specify the departing means of transport. -# Each line has the format: -# -# "%s %s → %s\n", time_of_departure, line_number, destination -# -# where time_of_departure is self-evident, and line_number and -# destination identify the route and direction. -# -# STDERR -# Not used. -# -# OUTPUT FILES -# None. -# -# EXTENDED DESCRIPTION -# None. -# -# EXIT STATUS -# 0 A departure board could be fetched. -# -# 1 ORIGIN doesn't specify an acceptable point of departure. -# -# EXAMPLES -# 1. Get the top three current departures at Stuttgart, Hauptbahnhof: -# -# $ limit=3 mobile.vvs.de hauptbahnhof -# -# FUTURE DIRECTIONS -# None. -# -# BUGS -# The format of STDOUT suffers from bit rot. -# -# SEE ALSO -# vvs.de -# -# COPYRIGHT -# All departure information is copyrighted by Verkehrs- und -# Tarifverbund Stuttgart GmbH. The original copyright statement can -# be obtained online at http://www.vvs.de/impressum . -# -# The following code is your fault. -# -set -euf - -ltrim() { - sed "s/^[${1-$symbols}]*//" -} - -POST() { - ## TODO url-encode, trim - tr '\n' '&' | sed 's/&$//' | - w3m -config /dev/null -cols 256 -post /dev/stdin -dump "${1-$URI}" -} - -limit=${limit-10} -origin="${1-$origin}" -H="${2-${H-`date +%H`}}" -M="${3-${M-`date +%M`}}" -Ymd="${4-${Ymd-`date +%Y%m%d`}}" - -URI='http://mobil.vvs.de/mobile/XSLT_DM_REQUEST' - -echo " -sessionID=0 -requestID=0 -language=de -locationServerActive=1 -useRealtime=1 -anySigWhenPerfectNoOtherMatches=1 -limit=$limit -deleteAssignedStops_dm=1 -mode=direct -convertCrossingsITKernel2LocationServer=1 -convertStopsPTKernel2LocationServer=1 -convertAddressesITKernel2LocationServer=1 -convertPOIsITKernel2LocationServer=1 -itdLPxx_dest= -useAllStops=1 -maxAssignedStops=1 -itOptionsActive=1 -trITMOTvalue100=5 -ptOptionsActive=1 -useProxFootSearch=0 -w_regPrefAm=1 -w_objPrefAl=2 -w_objPrefAl=12 -itdLPxx_script=true -place_dm= -placeState_dm=empty -nameState_dm=empty -nameInfo_dm=invalid -typeInfo_dm=invalid -placeInfo_dm=invalid -reducedAnyWithoutAddressObjFilter_dm=103 -reducedAnyPostcodeObjFilter_dm=64 -reducedAnyTooManyObjFilter_dm=2 -anyObjFilter_dm=126 -type_dm=any -name_dm=$origin -itdTimeHour=`echo $H | ltrim 0` -itdTimeMinute=`echo $M | ltrim 0` -itdDate=$Ymd -" | POST "$URI" | sed -rn ' - s/^Von:[^[:alpha:]]+(.*)$/'$H:$M' \1/p - /Haltestelle/,/^ *$/{ - /Haltestelle|^ *$/!{ - s/[[:space:]]*\[info\][[:space:]]*$// - p - } - } -' | { - read REPLY - echo "$REPLY" - while read time dev no dest ; do - printf "$time %3s → %s\n" $no "$dest" - done -} - -#### diff --git a/util/t/mobile.vvs.de/smoke-test b/util/t/mobile.vvs.de/smoke-test deleted file mode 100755 index 0b9e7960..00000000 --- a/util/t/mobile.vvs.de/smoke-test +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/sh -set -euf -mobile.vvs.de hauptbahnhof | - sed -n 'p;q' | - grep -q '\[4m[0-9][0-9]:[0-9][0-9] Stuttgart, Hauptbahnhof\[m' diff --git a/util/t/vvs.de/smoke-test b/util/t/vvs.de/smoke-test deleted file mode 100755 index 451270fe..00000000 --- a/util/t/vvs.de/smoke-test +++ /dev/null @@ -1,11 +0,0 @@ -#! /bin/sh -set -euf - -vvs.de Hauptbahnhof Renningen 13 37 | { - read from && test "x$from" = 'xfrom: Hauptbahnhof' - read to && test "x$to" = 'xto: Renningen' - read sep && test "x$sep" = 'x-------------------------------------' - while read line; do - echo "$line" | grep -q '^[0-9][0-9]:[0-9][0-9] [0-9][0-9]:[0-9][0-9] ' - done -} -- cgit v1.2.3 From 2c4426db77bfb4531d50418add76c98940c5181f Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 14 Dec 2013 15:24:04 +0100 Subject: krebsplug from irc_nick: Lost_Prophet --- retiolum/hosts/krebsplugad1f45ec | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 retiolum/hosts/krebsplugad1f45ec diff --git a/retiolum/hosts/krebsplugad1f45ec b/retiolum/hosts/krebsplugad1f45ec new file mode 100644 index 00000000..150b7c5b --- /dev/null +++ b/retiolum/hosts/krebsplugad1f45ec @@ -0,0 +1,11 @@ +Subnet = 10.243.169.22 +Subnet = 42:e495:04bf:720d:6b87:3501:c288:b6bf + +-----BEGIN RSA PUBLIC KEY----- +MIIBCgKCAQEAyL6QFFwsJt1B6r0l4x0LrjFllfu8wwnQetUD/z9Rp7l6eaxbSV7i +SeUbQ2H50cjFvP0HuQp37i15c5B66BJJBRJ5aTTQusi8YGzYxENA/fZp4M13QRAp +0zZhed3zvebQFxJFTWepzxY2bqemF0GLsPTRWSRQ1O8PGSPL8nt8wh0zdQivPLbI +Odm8RK2akhvUf0MLtkJfwwee9W0JNBEcPet4v8ViTZKaQznh1wQo7BAMvY8i9pCQ +XsUGfUKpkGG6AcntLTIKiJqpqX5K03yaLA7QoeH3nhFeZdOdmbEaAvNVh8GeTn90 +SuTaBgvxHTLUs60Cf2K4DtXwFG9K6GaNXwIDAQAB +-----END RSA PUBLIC KEY----- -- cgit v1.2.3 From 8e7f6b0c15db735fd289b304cb9fa5337f53c4fc Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 16 Dec 2013 16:23:12 +0100 Subject: Reaktor/IRC: use config.json (and python3ize) --- Reaktor/IRC/asybot.py | 82 ++++++++++++++--------------------------- Reaktor/IRC/getconf.py | 20 ++++++++++ Reaktor/IRC/index | 2 +- Reaktor/IRC/translate_colors.py | 2 +- Reaktor/config.json | 27 ++++++++++++++ 5 files changed, 76 insertions(+), 57 deletions(-) create mode 100644 Reaktor/IRC/getconf.py create mode 100644 Reaktor/config.json diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 2cb533ea..7fcc2ea6 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -18,37 +18,42 @@ from sys import exit from re import split, search from textwrap import TextWrapper import logging,logging.handlers +from getconf import make_getconf +getconf = make_getconf('config.json') 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) +logging.basicConfig(level = logging.DEBUG if getconf('main.debug') else logging.INFO) # s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g -- removes color codes class asybot(asychat): - def __init__(self, server, port, nickname, targets, **kwargs): + def __init__(self): 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.server = getconf('irc.server') + self.port = getconf('irc.port') + self.channels = getconf('irc.channels') + self.realname = getconf('irc.nickname') + self.nickname = getconf('irc.nickname') + self.username = getconf('irc.nickname') + self.hostname = getconf('irc.nickname') + self.ircname = getconf('irc.nickname') self.data = '' - self.set_terminator('\r\n') + self.set_terminator('\r\n'.encode(encoding='UTF-8')) self.create_socket(AF_INET, SOCK_STREAM) self.connect((self.server, self.port)) self.wrapper = TextWrapper(subsequent_indent=" ",width=400) + log.info('=> irc://%s@%s:%s/%s' % (self.nickname, self.server, self.port, self.channels)) + # 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.alarm_timeout = getconf('irc.alarm_timeout') + self.hammer_interval = getconf('irc.hammer_interval') self.kill_timeout = 360 signal(SIGALRM, lambda signum, frame: self.alarm_handler()) self.reset_alarm() @@ -69,7 +74,7 @@ class asybot(asychat): alarm(self.hammer_interval) def collect_incoming_data(self, data): - self.data += data + self.data += data.decode(encoding='UTF-8') def found_terminator(self): log.debug('<< %s' % self.data) @@ -100,18 +105,19 @@ class asybot(asychat): self.reset_alarm() def push(self, message): - log.debug('>> %s' % message) - asychat.push(self, message + self.get_terminator()) + msg = (message + self.get_terminator().decode(encoding='UTF-8')).encode(encoding='UTF-8') + log.debug('>> %s' % msg) + asychat.push(self, msg) 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)) + self.push('JOIN %s' % ','.join(self.channels)) def on_privmsg(self, prefix, command, params, rest): def PRIVMSG(text): - for line in self.wrapper.wrap(text): + for line in self.wrapper.wrap(text.decode(encoding='UTF-8')): msg = 'PRIVMSG %s :%s' % (','.join(params), line) log.info(msg) self.push(msg) @@ -125,7 +131,7 @@ class asybot(asychat): try: _, _handle, _command, _argument, _ = split( '^(\w+|\*):\s*(\w+)(?:\s+(.*))?$', rest) - except ValueError, error: + except (ValueError, Exception): if search(self.nickname, rest): PRIVMSG('I\'m so famous') return # ignore @@ -149,12 +155,12 @@ class asybot(asychat): args = shlex.split(_argument) try: p = popen([command] + args,bufsize=1, stdout=PIPE, stderr=PIPE, env=env) - except OSError, error: + except (OSError, Exception): ME('brain damaged') log.error('OSError@%s: %s' % (command, error)) return pid = p.pid - for line in iter(p.stdout.readline,""): + for line in iter(p.stdout.readline, ''.encode(encoding='UTF-8')): PRIVMSG(translate_colors(line)) log.debug('%s stdout: %s' % (pid, line)) p.wait() @@ -169,41 +175,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): - 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 - - lol = logging.DEBUG if env.get('debug',False) else logging.INFO - logging.basicConfig(level=lol) - try: - name = getconf1('Name', '/etc/tinc/retiolum/tinc.conf') - hostname = '%s.retiolum' % name - except: - name = gethostname() - hostname = 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')) - 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) - + asybot() loop() diff --git a/Reaktor/IRC/getconf.py b/Reaktor/IRC/getconf.py new file mode 100644 index 00000000..5fdd1cdb --- /dev/null +++ b/Reaktor/IRC/getconf.py @@ -0,0 +1,20 @@ +#getconf = make_getconf("dateiname.json") +#getconf(key) -> value +#oder error + +import json + +def make_getconf(filename): + def getconf(prop): + prop_split = prop.split('.') + string = '' + file = open(filename) + for line in file.readlines(): + string+=line + parsed = json.loads(string) + tmp = parsed + for pr in prop_split: + tmp = tmp[pr] + + return tmp + return getconf diff --git a/Reaktor/IRC/index b/Reaktor/IRC/index index cc2652fe..2dc803a1 100755 --- a/Reaktor/IRC/index +++ b/Reaktor/IRC/index @@ -3,4 +3,4 @@ set -xeuf # cd //Reaktor cd $(dirname $(readlink -f $0))/.. -host=irc.freenode.net target='#krebs' python IRC/asybot.py "$@" +exec IRC/asybot.py "$@" diff --git a/Reaktor/IRC/translate_colors.py b/Reaktor/IRC/translate_colors.py index bd716618..3ea34be6 100644 --- a/Reaktor/IRC/translate_colors.py +++ b/Reaktor/IRC/translate_colors.py @@ -23,7 +23,7 @@ COLOR_MAP = { } def translate_colors (line): for color,replace in COLOR_MAP.items(): - line = line.replace(color,replace) + line = line.replace(color.encode(encoding='UTF-8'),replace.encode(encoding='UTF-8')) return line if __name__ == "__main__": diff --git a/Reaktor/config.json b/Reaktor/config.json new file mode 100644 index 00000000..0b032c60 --- /dev/null +++ b/Reaktor/config.json @@ -0,0 +1,27 @@ +{ + "main": { + "debug": true, + "name": "asybot" + }, + "irc": { + "alarm_timeout": 300, + "hammer_interval": 10, + "kill_timeout": 360, + "nickname": "asybot", + "server": "irc.freenode.org", + "port": 6667, + "channels": [ + "#krebs" + ], + "commands": [ + { "pattern": "^{main.name}:\\s*caps\\s*$", "argv": [ "command/caps" ] }, + { "pattern": "^{main.name}:\\s*hello\\s*$", "argv": [ "command/hello" ] }, + { "pattern": "^{main.name}:\\s*reload\\s*$", "argv": [ "command/reload" ] }, + { "pattern": "^{main.name}:\\s*retard\\s*$", "argv": [ "command/retard" ] }, + { "pattern": "^{main.name}:\\s*rev\\s*$", "argv": [ "command/rev" ] }, + { "pattern": "^{main.name}:\\s*uptime\\s*$", "argv": [ "command/uptime" ] }, + { "pattern": "{main.name}", "argv": [ "command/say", "I'm famous" ] } + ] + } +} + -- cgit v1.2.3 From 5f6ded8bcbc4700b4547c4d1285e71e270908b2f Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 16 Dec 2013 16:28:38 +0100 Subject: Reaktor/IRC: encode harder --- Reaktor/IRC/asybot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 7fcc2ea6..9a183413 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -133,7 +133,7 @@ class asybot(asychat): '^(\w+|\*):\s*(\w+)(?:\s+(.*))?$', rest) except (ValueError, Exception): if search(self.nickname, rest): - PRIVMSG('I\'m so famous') + PRIVMSG('I\'m so famous'.encode(encoding='UTF-8')) return # ignore if _handle == self.nickname or _handle == '*': -- cgit v1.2.3 From 884fb902e9936993e13fe87f46fcd0e1fc052499 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 16 Dec 2013 18:19:49 +0100 Subject: Reaktor/IRC: use command patterns --- Reaktor/IRC/asybot.py | 87 +++++++++++++++++++-------------------------- Reaktor/TODO | 9 +++++ Reaktor/commands/badcommand | 1 + Reaktor/commands/caps | 1 + Reaktor/commands/retard | 1 - Reaktor/commands/say | 2 ++ Reaktor/config.json | 15 ++++---- 7 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 Reaktor/TODO create mode 100755 Reaktor/commands/badcommand delete mode 100755 Reaktor/commands/retard create mode 100755 Reaktor/commands/say diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 9a183413..ceebe844 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -15,7 +15,7 @@ from datetime import datetime as date, timedelta import shlex from time import sleep from sys import exit -from re import split, search +from re import split, search, match from textwrap import TextWrapper import logging,logging.handlers from getconf import make_getconf @@ -85,7 +85,6 @@ class asybot(asychat): _, 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) @@ -124,57 +123,45 @@ class asybot(asychat): sleep(1) def ME(text): - PRIVMSG('ACTION ' + text + '') + PRIVMSG(('ACTION ' + text + '').encode(encoding='UTF-8')) - _from = prefix.split('!', 1)[0] + for command in getconf('irc.commands'): + y = match(command['pattern'], rest) + if y: + self.execute_command(command, y, PRIVMSG, ME) + def execute_command(self, command, match, PRIVMSG, ME): + from os.path import realpath, dirname, join + from subprocess import Popen as popen, PIPE + from time import time + + #TODO: allow only commands below ./commands/ + exe = join(dirname(realpath(dirname(__file__))), command['argv'][0]) + myargv = [exe] + command['argv'][1:] + + env = {} + start = time() try: - _, _handle, _command, _argument, _ = split( - '^(\w+|\*):\s*(\w+)(?:\s+(.*))?$', rest) - except (ValueError, Exception): - if search(self.nickname, rest): - PRIVMSG('I\'m so famous'.encode(encoding='UTF-8')) - return # ignore - - if _handle == self.nickname or _handle == '*': - - from os.path import realpath, dirname, join - from subprocess import Popen as popen, PIPE - from time import time - Reaktor_dir = dirname(realpath(dirname(__file__))) - public_commands = join(Reaktor_dir, 'public_commands') - command = join(public_commands, _command) - - if is_executable(command): - - env = {} - args = [] - start = time() - if _argument != None: - env['argument'] = _argument - args = shlex.split(_argument) - try: - p = popen([command] + args,bufsize=1, stdout=PIPE, stderr=PIPE, env=env) - except (OSError, Exception): - ME('brain damaged') - log.error('OSError@%s: %s' % (command, error)) - return - pid = p.pid - for line in iter(p.stdout.readline, ''.encode(encoding='UTF-8')): - PRIVMSG(translate_colors(line)) - log.debug('%s stdout: %s' % (pid, line)) - p.wait() - elapsed = time() - start - code = p.returncode - log.info('command: %s -> %s in %d seconds' % (command, code,elapsed)) - [log.debug('%s stderr: %s' % (pid, x)) for x in p.stderr.readlines()] - - if code != 0: - ME('mimimi') - - else: - if _handle != '*': - PRIVMSG(_from + ': you are made of stupid') + p = popen(myargv, bufsize=1, stdout=PIPE, stderr=PIPE, env=env) + except (OSError, Exception) as error: + ME('brain damaged') + log.error('OSError@%s: %s' % (myargv, error)) + return + pid = p.pid + for line in iter(p.stdout.readline, ''.encode(encoding='UTF-8')): + try: + PRIVMSG(translate_colors(line)) + except Exception as error: + log.error('no send: %s' % error) + log.debug('%s stdout: %s' % (pid, line)) + p.wait() + elapsed = time() - start + code = p.returncode + log.info('command: %s -> %s in %d seconds' % (myargv, code, elapsed)) + [log.debug('%s stderr: %s' % (pid, x)) for x in p.stderr.readlines()] + + if code != 0: + ME('mimimi') if __name__ == "__main__": asybot() diff --git a/Reaktor/TODO b/Reaktor/TODO new file mode 100644 index 00000000..ba9c4b6e --- /dev/null +++ b/Reaktor/TODO @@ -0,0 +1,9 @@ +{ "pattern": "^(?:asybot|\\*):.*", "argv": [ "commands/say", "{{from.nickname}}: you are made of stupid" ], only_match: true } + +getconf: check syntax and semantics on load +getconf: reload inotify + +apropros caps: commands need access to config + +commands need access to from (eg as env var): + _from = prefix.split('!', 1)[0] diff --git a/Reaktor/commands/badcommand b/Reaktor/commands/badcommand new file mode 100755 index 00000000..c59b4d1c --- /dev/null +++ b/Reaktor/commands/badcommand @@ -0,0 +1 @@ +#? //retard diff --git a/Reaktor/commands/caps b/Reaktor/commands/caps index bc3d7ba2..caa1fe06 100755 --- a/Reaktor/commands/caps +++ b/Reaktor/commands/caps @@ -1,4 +1,5 @@ #! /bin/sh +exec echo 'TODO: need access to config.json' set -euf cd public_commands echo `ls` diff --git a/Reaktor/commands/retard b/Reaktor/commands/retard deleted file mode 100755 index c59b4d1c..00000000 --- a/Reaktor/commands/retard +++ /dev/null @@ -1 +0,0 @@ -#? //retard diff --git a/Reaktor/commands/say b/Reaktor/commands/say new file mode 100755 index 00000000..8b83c056 --- /dev/null +++ b/Reaktor/commands/say @@ -0,0 +1,2 @@ +#!/bin/sh +printf '%s\n' "$*" diff --git a/Reaktor/config.json b/Reaktor/config.json index 0b032c60..7b84c55e 100644 --- a/Reaktor/config.json +++ b/Reaktor/config.json @@ -14,13 +14,14 @@ "#krebs" ], "commands": [ - { "pattern": "^{main.name}:\\s*caps\\s*$", "argv": [ "command/caps" ] }, - { "pattern": "^{main.name}:\\s*hello\\s*$", "argv": [ "command/hello" ] }, - { "pattern": "^{main.name}:\\s*reload\\s*$", "argv": [ "command/reload" ] }, - { "pattern": "^{main.name}:\\s*retard\\s*$", "argv": [ "command/retard" ] }, - { "pattern": "^{main.name}:\\s*rev\\s*$", "argv": [ "command/rev" ] }, - { "pattern": "^{main.name}:\\s*uptime\\s*$", "argv": [ "command/uptime" ] }, - { "pattern": "{main.name}", "argv": [ "command/say", "I'm famous" ] } + { "pattern": "^(?:asybot|\\*):\\s*caps\\s*$", "argv": [ "commands/caps" ] }, + { "pattern": "^(?:asybot|\\*):\\s*hello\\s*$", "argv": [ "commands/hello" ] }, + { "pattern": "^(?:asybot|\\*):\\s*reload\\s*$", "argv": [ "commands/reload" ] }, + { "pattern": "^(?:asybot|\\*):\\s*badcommand\\s*$", "argv": [ "commands/badcommand" ] }, + { "pattern": "^(?:asybot|\\*):\\s*rev\\s*$", "argv": [ "commands/rev" ] }, + { "pattern": "^(?:asybot|\\*):\\s*uptime\\s*$", "argv": [ "commands/uptime" ] }, + { "pattern": "^(?:asybot|\\*):\\s*nocommand\\s*$", "argv": [ "commands/nocommand" ] }, + { "pattern": "^.*\\basybot(?:\\b[^:].*)?$", "argv": [ "commands/say", "I'm famous" ] } ] } } -- cgit v1.2.3 From abf03f260a3d4b3b1b62c98ede3014b724658e1c Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 16 Dec 2013 18:27:20 +0100 Subject: Reaktor/IRC: update TODO --- Reaktor/TODO | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Reaktor/TODO b/Reaktor/TODO index ba9c4b6e..6dbc2f8d 100644 --- a/Reaktor/TODO +++ b/Reaktor/TODO @@ -7,3 +7,5 @@ apropros caps: commands need access to config commands need access to from (eg as env var): _from = prefix.split('!', 1)[0] + +provide arguments to commands -- cgit v1.2.3