aboutsummaryrefslogtreecommitdiffstats
path: root/UDP/index
diff options
context:
space:
mode:
authorroot <root@krebs>2011-09-25 02:53:05 +0200
committerroot <root@krebs>2011-09-25 02:53:05 +0200
commit18e0376ffd9dee51f554f422b8e83bcfaa0ab218 (patch)
treee5cda395701b7b89d5a4d930f50e6302c14880ea /UDP/index
parent821f9a450a9140f1ef63fb317a564d0251bc967e (diff)
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
Diffstat (limited to 'UDP/index')
-rwxr-xr-xUDP/index33
1 files changed, 28 insertions, 5 deletions
diff --git a/UDP/index b/UDP/index
index b7a2150..3e0bbd1 100755
--- a/UDP/index
+++ b/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()