3 # Copyright 2015-2017 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
4 # send me your changes. credit author(s). do not publish. share alike.
5 # to be done: find a suitable licence text.
20 dbconnstring = "host=127.0.0.1 port=5432 dbname=flagbot user=flagbot password=flagbotpw"
22 def login(force = False):
24 if force == True or team is None:
25 team = ictf.iCTF().login('ctf@w0y.at','ZmtphWHFUDwRWk6m')
26 print("login(): logged in.")
30 print("submitFlag(): starting...")
37 dbconn = psycopg2.connect(dbconnstring)
38 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
39 cur.execute("SELECT * from flags where status = 0 or status = 4 order by random() limit 400")
40 print("submitFlag(): submitting " + str(cur.rowcount) + " flags...")
41 flist = [x['flag'] for x in cur.fetchall()]
42 result = team.submit_flag(flist)
43 resultlist = list(zip(flist,result))
45 for res in resultlist:
49 if "notactive" in result:
50 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), "
51 "status = %s, srvresponse = %s WHERE flag = %s",
54 elif "incorrect" in result:
55 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), "
56 "status = %s, srvresponse = %s WHERE flag = %s",
59 elif "correct" in result:
60 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), "
61 "status = %s, srvresponse = %s WHERE flag = %s",
64 elif "already" in result:
65 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), "
66 "status = %s, srvresponse = %s WHERE flag = %s",
73 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), "
74 "status = %s, srvresponse = %s WHERE flag = %s",
78 except psycopg2.DatabaseError as e:
80 traceback.print_exc(file=sys.stdout)
82 except Exception as e:
84 traceback.print_exc(file=sys.stdout)
88 except AttributeError as e:
90 # print('Error %s' % e)
91 # traceback.print_exc(file=sys.stdout)
93 except psycopg2.DatabaseError as e:
95 traceback.print_exc(file=sys.stdout)
97 print("submitFlag(): ended.")
102 print("*** starting ...")
106 if __name__ == "__main__":
107 def signal_handler(signal, frame):
108 print('SIG received. exitting!')
110 signal.signal(signal.SIGINT, signal_handler)