diff options
author | lassulus <lassulus@lassul.us> | 2018-09-18 19:01:36 +0200 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2018-09-18 19:01:36 +0200 |
commit | 2dfb816ddadb34e5b11676ef18c3c2f9079c8146 (patch) | |
tree | 59658869371ec5ac11fcd749cf270e1be655d1f5 /UDP/index | |
parent | 00b26ca0bb45d0fb7989a3ddf506bd8230363a14 (diff) |
throw away dead code
Diffstat (limited to 'UDP/index')
-rwxr-xr-x | UDP/index | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/UDP/index b/UDP/index deleted file mode 100755 index ffe3d6b..0000000 --- a/UDP/index +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/python - -import asyncore, socket -import logging,subprocess -import re -import json -log = logging.getLogger('ubot') - -def enable_syslog(logger): - import logging.handlers as handlers - from logging import Formatter - hdlr = handlers.SysLogHandler( - facility=handlers.SysLogHandler.LOG_DAEMON) - formatter = Formatter( - '%(filename)s: %(levelname)s: %(message)s') - 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") - - """ UDP Bot """ - 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_addr = bind_addr - - def datagramReceived(self,datagram,addr): - self.data = datagram - log.debug('<< %s' % self.data) - if self.find_pattern(): - self.start_action() - - def find_pattern(self): - """ returns true if own pattern is found""" - log.debug("Pattern is %s" %self.pattern) - ret = re.search(self.pattern,self.data) - if ret: - log.info("Match \"%s\" with pattern \"%s\"" % ((ret.string.strip()),self.pattern)) - else: - log.info("No Match") - return ret - - - def start_action(self): - """ runs all the defined actions""" - log.debug("Actions: %s" % str(self.action)) - 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) - for i in load_conf("%s/config" %HERE): - reactor.listenMulticast(i["port"], ubot(**i)) - reactor.run() |