def email_receiver(cmd,msg): T = Tester() T.newtest(testname=cmd) # Save the received email mesasge in the database messageid = T.insert_email_message(tester.EMAIL_TAG_USER_SENT,str(msg)) args = {"messageid":messageid,"cmd":cmd} # Depending on the command, institute the next step... if cmd=="bouncer": T.insert_task(tester.TASK_COMPOSE_SIMPLE_RESPONSE, args) T.commit() elif cmd=="register": T.insert_task(tester.TASK_REGISTER_FROM_EMAIL, args) T.commit() else: # Log invalid command logging.info("Invalid command: {} Message {}".format(cmd,messageid))
def periodic(): from tester import Tester import argparse parser = argparse.ArgumentParser(description="database maintenance") parser.add_argument("--debug", action="store_true") parser.add_argument("--list", help="List all of the tasks", action="store_true") args = parser.parse_args() W = Tester() # get a database connection c = W.conn.cursor() if args.list: c.execute("select workqueueid,testid,created,completed from workqueue") for line in c: print(line) exit(0) # Run the queue until there is nothing left to run while True: c.execute("select workqueueid,testid,task,args from workqueue where isnull(completed)") count = 0 for (workqueueid, testid, task, task_args_str) in c.fetchall(): count += 1 T = Tester(testid=testid) task_args = json.loads(task_args_str) if args.debug or debug: print("task_args=", task_args) task_args["state"] = "WORKING" logging.info("testid={} task={} task_args={}".format(testid, task, task_args)) if eval(task + "(T,task_args)"): c.execute("update workqueue set completed=now() where workqueueid=%s", (workqueueid,)) W.commit() if count == 0: break
if len(args.name)!=1: print("Error: One name must be provided") exit(1) name = args.name[0] print("DBDNS DEMO") T = Tester() T.newtest(testname="dig") print("dig -t {} {}".format(args.t,name)) print("TestID: {}".format(T.testid)) response = dbdns.query(T,name,args.t) for part in range(len(response.answer)): print("ANSWER PART {}:".format(part)) for i in range(len(response.answer[part])): print("RR {}: {} {}".format(i,response.answer[part][i],type(response.answer[part][i]))) T.commit() print("\n\n\nReplay:") response = dbdns.query(T,name,args.t,replay=True) for part in range(len(response.answer)): print("ANSWER PART {}:".format(part)) for i in range(len(b.answer[part])): print("RR {}: {} {}".format(i, response.answer[part][i], type(response.answer[part][i]))) if args.mxdemo: print("MX hosts for dnspython.org:") print("") print("Traditional dnspython MX resolution:") a = dns.resolver.query("dnspython.org","MX")