From 14636218a1ca18cf66c507d39c6784a6b28f7528 Mon Sep 17 00:00:00 2001 From: krebs Date: Sat, 24 Sep 2011 20:33:21 -0400 Subject: punani: bugfix --- icecrab/icecast2 | 19 ------------------- icecrab/icecast2.conf | 19 +++++++++++++++++++ punani/bin/punani | 3 ++- 3 files changed, 21 insertions(+), 20 deletions(-) delete mode 100644 icecrab/icecast2 create mode 100644 icecrab/icecast2.conf diff --git a/icecrab/icecast2 b/icecrab/icecast2 deleted file mode 100644 index 3a2521ff..00000000 --- a/icecrab/icecast2 +++ /dev/null @@ -1,19 +0,0 @@ -# Defaults for icecast2 initscript -# sourced by /etc/init.d/icecast2 -# installed at /etc/default/icecast2 by the maintainer scripts - -# -# This is a POSIX shell fragment -# - -# Full path to the server configuration file -CONFIGFILE="/etc/icecast2/icecast.xml" - -# Name or ID of the user and group the daemon should run under -USERID=icecast2 -GROUPID=icecast - -# Edit /etc/icecast2/icecast.xml and change at least the passwords. -# Change this to true when done to enable the init.d script -ENABLE=true - diff --git a/icecrab/icecast2.conf b/icecrab/icecast2.conf new file mode 100644 index 00000000..3a2521ff --- /dev/null +++ b/icecrab/icecast2.conf @@ -0,0 +1,19 @@ +# Defaults for icecast2 initscript +# sourced by /etc/init.d/icecast2 +# installed at /etc/default/icecast2 by the maintainer scripts + +# +# This is a POSIX shell fragment +# + +# Full path to the server configuration file +CONFIGFILE="/etc/icecast2/icecast.xml" + +# Name or ID of the user and group the daemon should run under +USERID=icecast2 +GROUPID=icecast + +# Edit /etc/icecast2/icecast.xml and change at least the passwords. +# Change this to true when done to enable the init.d script +ENABLE=true + diff --git a/punani/bin/punani b/punani/bin/punani index 34d5bcbf..954eca43 100755 --- a/punani/bin/punani +++ b/punani/bin/punani @@ -115,7 +115,7 @@ handle_system () { # apt-file () { echo $@; } # apt-get () { echo $@; } #fi - if [ `which apt-file` ]; then + if ! which apt-file; then echo "installing dependencies: apt-file" apt-get install --yes apt-file echo "update the apt-file tool" @@ -133,6 +133,7 @@ handle_system () { fi } punani_Engineer_insert() { + echo "trying to install $1" if apt-get install `apt-file search -l -x /$1\$`;then echo "++ finished" else -- cgit v1.2.3 From a30932e4c793ceb2c813986bd84e8f99d1dc84a5 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 25 Sep 2011 02:53:05 +0200 Subject: Reaktor/UDP: working release Reaktor/UDP is customizable via a single json config parsed at the very beginning, starting a number of asynchronous UDP listeners. See Readme for more info --- Reaktor/UDP/README | 7 ++++--- Reaktor/UDP/config | 15 +++++++++++++++ Reaktor/UDP/index | 33 ++++++++++++++++++++++++++++----- Reaktor/commands/licht_resolver | 37 +++++++++++++++++++++++++++++++++++++ Reaktor/udp_commands/licht_resolver | 1 + 5 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 Reaktor/UDP/config create mode 100755 Reaktor/commands/licht_resolver create mode 120000 Reaktor/udp_commands/licht_resolver diff --git a/Reaktor/UDP/README b/Reaktor/UDP/README index ad7117fe..587c8046 100644 --- a/Reaktor/UDP/README +++ b/Reaktor/UDP/README @@ -5,6 +5,7 @@ From 2011-09-16: { "port": 1337, "pattern": "XXYY", + "comment" : "does the right thing", "action" : { "POST": { "url" : "xyz", @@ -15,10 +16,9 @@ From 2011-09-16: ] ## Head definition { - "bind" : "127.0.0.1", + "bind_addr" : "127.0.0.1", "port" : 1234, "pattern" : "XXZZ", - "terminator" : "\r\n" "action" : { }, } bind is an optional entry which lets the user define a bind address for the server. @@ -35,6 +35,7 @@ terminator is optional which lets the user define the EOM terminator. Process is taken from //hyper/process/test/bc.json - rev:a7fd3f stdout/stderr are optional and if left away data will be written to real stdout/stderr +in the process in envp => "payload" will be allocated for the given payload from the network "PROCESS" : { { @@ -43,7 +44,7 @@ stdout/stderr are optional and if left away data will be written to real stdout/ "bc" ], "envp": { - "was": "geht" + "was": "geht", }, "stdout": "uri:///path/to/somewhere", "stderr": "uri:///path/to/somewhere" diff --git a/Reaktor/UDP/config b/Reaktor/UDP/config new file mode 100644 index 00000000..34f0d0bc --- /dev/null +++ b/Reaktor/UDP/config @@ -0,0 +1,15 @@ +[ + { + "comment" : "listener for licht.shack", + "bind_addr" : "0.0.0.0", + "port" : 2342, + "pattern" : "", + "action" : { + "PROCESS" : { + "path" : "/krebs/Reaktor/UDP/licht_resolver", + "argv" : [ ], + "envp" : { } + } + } + } +] diff --git a/Reaktor/UDP/index b/Reaktor/UDP/index index b7a21508..3e0bbd15 100755 --- a/Reaktor/UDP/index +++ b/Reaktor/UDP/index @@ -1,9 +1,10 @@ #!/usr/bin/python import asyncore, socket -import logging +import logging,subprocess import re import sys +import json log = logging.getLogger('ubot') def enable_syslog(logger): @@ -19,7 +20,7 @@ def enable_syslog(logger): class ubot(asyncore.dispatcher): """ UDP Bot """ - def __init__(self, port,pattern,action,bind_addr="",): + def __init__(self, port,pattern,action,comment="",bind_addr="",): asyncore.dispatcher.__init__(self) self.bind_addr = bind_addr self.port = port @@ -64,13 +65,35 @@ class ubot(asyncore.dispatcher): def start_action(self): """ runs all the defined actions""" log.debug("Actions: %s" % str(self.action)) - log.error("not yet implemented") - sys.exit(23) + self.start_process() + self.start_post() + + def start_process(self): + try: + act = self.action["PROCESS"] + proc = [] + proc.append(act["path"]) + proc.extend(act["argv"]) + + env = act["envp"] + env["payload"] = json.dumps(self.data) + log.info("Starting Process: %s (env: %s)" % (proc,env)) + subprocess.Popen(proc,env=env) + except Exception as e: + log.error(e) + def start_post(self): + pass + +def load_conf(conf_file): + return json.load(open(conf_file)) + if __name__ == "__main__": import os #enable_syslog(log) + HERE = os.path.dirname(os.path.realpath(__file__)) lol = logging.DEBUG if os.environ.get('debug',False) else logging.INFO logging.basicConfig(level=lol) - ubot(1337,r'abc',{}) + for i in load_conf("%s/config" %HERE): + ubot(**i) asyncore.loop() diff --git a/Reaktor/commands/licht_resolver b/Reaktor/commands/licht_resolver new file mode 100755 index 00000000..5bdb6510 --- /dev/null +++ b/Reaktor/commands/licht_resolver @@ -0,0 +1,37 @@ +#! /usr/bin/python +# -*- coding: utf-8 -*- + +map = { + 'shackspace': { + 'device': { + 0: 'Licht0, Zickenzone; Fenster', + 1: 'Licht1, Sofaecke; Fenster', + 2: 'Licht2, Zickenzone; Ghetto', + 3: 'Licht3, Sofaecke; Ghetto', + 4: 'Licht4, Richtung Getränkelager', + 5: 'Licht5, Porschekonsole', + 6: 'Licht6, Tomatenecke', + 7: 'Licht7, Ghetto', + 10: 'Hauptschalter' + }, + 'state': { + 0: 'aus', + 1: 'an', + 2: 'aus in T-10s' + }, + '->': 'ist' + } +} + +from struct import unpack +import json +from os import environ as env + +location = "shackspace" + +map = map[location] +print (env["payload"]+"") +did, sid= unpack('BB', json.loads(env['payload'])) +device,state = map['device'][did], map['state'][sid] +arrow = map['->'] +print ' '.join([device, arrow, state]) diff --git a/Reaktor/udp_commands/licht_resolver b/Reaktor/udp_commands/licht_resolver new file mode 120000 index 00000000..0d8b0956 --- /dev/null +++ b/Reaktor/udp_commands/licht_resolver @@ -0,0 +1 @@ +../commands/licht_resolver \ No newline at end of file -- cgit v1.2.3 From f183a3cc4ef59668c24d4268df9690f88092b0f4 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 25 Sep 2011 02:55:34 +0200 Subject: Reaktor/UDP: fix bug in config update Path to actual script --- Reaktor/UDP/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Reaktor/UDP/config b/Reaktor/UDP/config index 34f0d0bc..623c721c 100644 --- a/Reaktor/UDP/config +++ b/Reaktor/UDP/config @@ -6,7 +6,7 @@ "pattern" : "", "action" : { "PROCESS" : { - "path" : "/krebs/Reaktor/UDP/licht_resolver", + "path" : "/krebs/Reaktor/udp_commands/licht_resolver", "argv" : [ ], "envp" : { } } -- cgit v1.2.3 From 1ca5b6d9500ee081e5797138e6194a06d159a8f0 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 26 Sep 2011 17:06:45 +0200 Subject: ukrepl: fix +space bug the python 'print' is retarded and always adds a space to a given character if newline is suppressed, using sys.stdout.write instead --- crypto/bin/ukrepl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto/bin/ukrepl b/crypto/bin/ukrepl index b3b25db9..2dfaabc4 100755 --- a/crypto/bin/ukrepl +++ b/crypto/bin/ukrepl @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python2 # -*- coding: utf-8 -*- import sys @@ -98,4 +98,7 @@ for line in sys.stdin: else: print "unknown mode %c" % mode helpme() - print char, + try: + sys.stdout.write(char) + except: + sys.stdout.write(char.encode("utf-8")) -- cgit v1.2.3 From 592331580802ace9e96f3e4369bc9019f8e484b9 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 26 Sep 2011 22:42:44 +0200 Subject: UDP/Reaktor: now using twisted because asyncore sucks eselballs --- Reaktor/UDP/index | 53 ++++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/Reaktor/UDP/index b/Reaktor/UDP/index index 3e0bbd15..ffe3d6b1 100755 --- a/Reaktor/UDP/index +++ b/Reaktor/UDP/index @@ -3,7 +3,6 @@ import asyncore, socket import logging,subprocess import re -import sys import json log = logging.getLogger('ubot') @@ -17,37 +16,33 @@ def enable_syslog(logger): hdlr.setFormatter(formatter) logger.addHandler(hdlr) +from twisted.internet.protocol import DatagramProtocol +from twisted.internet import reactor +from twisted.application.internet import MulticastServer +from socket import SOL_SOCKET,SO_BROADCAST +class ubot(DatagramProtocol): +# def startProtocol(self): +# log.info("Starting Listener for Multicast") +# self.transport.joinGroup("255.255.255.255") -class ubot(asyncore.dispatcher): """ UDP Bot """ - def __init__(self, port,pattern,action,comment="",bind_addr="",): - asyncore.dispatcher.__init__(self) - self.bind_addr = bind_addr - self.port = port + def startProtocol(self): + log.info("starting Protocol at host (%s)" % self.bind_addr) + #self.transport. + if self.bind_addr != "255.255.255.255": + self.transport.joinGroup(self.bind_addr) + else: + self.transport.socket.setsockopt(SOL_SOCKET,SO_BROADCAST,True) + def __init__(self, pattern,action,bind_addr,**kwargs): + #DatagramProtocol.__init__(self) self.data = '' self.pattern = pattern self.action = action - self.bind_socket() - - def bind_socket(self): - """ - if the socket is already bound we want to reuse this socket anyway - """ - self.create_socket(socket.AF_INET,socket.SOCK_DGRAM) - self.set_reuse_addr() - self.socket.setsockopt( - socket.SOL_SOCKET,socket.SO_BROADCAST,1) - log.info("Binding Socket at %s:%d" - %(self.bind_addr,self.port)) - self.bind( (self.bind_addr,self.port) ) - - def handle_connect(self): - log.info("Server Started") + self.bind_addr = bind_addr - def handle_read(self): - self.data,addr = self.recvfrom(2048) + def datagramReceived(self,datagram,addr): + self.data = datagram log.debug('<< %s' % self.data) - if self.find_pattern(): self.start_action() @@ -60,8 +55,8 @@ class ubot(asyncore.dispatcher): else: log.info("No Match") return ret - - + + def start_action(self): """ runs all the defined actions""" log.debug("Actions: %s" % str(self.action)) @@ -95,5 +90,5 @@ if __name__ == "__main__": lol = logging.DEBUG if os.environ.get('debug',False) else logging.INFO logging.basicConfig(level=lol) for i in load_conf("%s/config" %HERE): - ubot(**i) - asyncore.loop() + reactor.listenMulticast(i["port"], ubot(**i)) + reactor.run() -- cgit v1.2.3