def set_flag(key, value): """Set a flag in the datastore's value.""" flag = Flags.all().filter("flag_key =", key).get() if flag: # Flag already exists, update it flag.value = value else: # Flag doesn't exist, create it flag = Flags(flag_key=key, value=value) # Great we're done, save it flag.put()
def register(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] phone = flask.request.form['phone'] if email is not None and password is not None and phone is not None: user = User(email, password, phone) db.session.add(user) db.session.commit() flags = Flags(user.id, False, False, False) pi = Pi(user.id, datetime.utcnow()) db.session.add(flags) db.session.add(pi) db.session.commit() flask_login.login_user(user) return redirect('dashboard') else: print('Error creating user: '******'register.html')
def init_team_flag(mathobj, themath): #themath = models.math.query.first() #global round_cont #round_cont+=1 #获取当前最大的轮数 round_cont = db.session.query(func.max( Flags.rounds)).scalar() #Round.query.fields(Round.rounds).first() if round_cont: round_cont = round_cont + 1 else: round_cont = 1 #flag_list=[] for i in mathobj: text = '%s %s check False' % (i.teamname, i.db_containers.typename) #记录 check_rezult 状态 if i.db_containers.check_stat == 1: # Round(attackteamid,rounds,containerid,text,score=0) db.session.add( Round(0, round_cont - 1, i.id, text, -themath.checkscore)) # db.session.commit() #初始化新的一轮 check_rezult i.db_containers.check_stat = 0 i.db_containers.attack_stat = 0 i.update_checkstat() i.update_attackstat() #i.session.commit() flag = Flags(i.id, make_flag_str(i.container_name), round_cont) #flag_list.append(flag) db.session.add(flag) db.session.commit() try: i.freshflag(flag.flag) #logger.info('%s Flag fresed : %s'%(i.teamname,flag.flag)) except: i.db_containers.check_stat = 1 i.update_checkstat() #i.session.commit() logger.warning('Round %d flag fresh %s error' % (round_cont, i.teamname)) t = threading.Thread(target=errorfresh, args=( i, flag.flag, )) t.setDaemon(True) t.start() #db.session.add_all(flag_list) #db.session.commit() countscore(round_cont - 1, mathobj, themath.checkscore, themath.atacckscore) return round_cont
def init_team_flag(teams): global round_cont round_cont += 1 flag_list = [] for i in teams: flag = Flags(i.id, make_flag_str(i.teamcontainer), round_cont) flag_list.append(flag) print(i.teamcontainer, i.token, flag.flag) print(service_checker(i.id, round_cont - 1)) try: freshflag2(i.teamcontainer, flag.flag) except Exception as e: print('Round %d flag fresh error' % round_cont, e) count_score(round_cont - 1) db.session.add_all(flag_list) db.session.commit() print('Round {} updated.'.format(round_cont))
def init_team_flag(mathobj): global timespan themath = math.query.first() #匹配比赛信息,控制刷新时间在比赛进行时 if themath: timespan = themath.flagflash * 60 if (datetime.datetime.now() - themath.endtime).total_seconds() > 0 or ( datetime.datetime.now() - themath.starttime).total_seconds() < 0: print('=== Time up ===') print('[+]starttime', themath.starttime) print('[+]the time', datetime.datetime.now()) print('[+]endtime', themath.endtime) print((datetime.datetime.now() - themath.endtime).total_seconds()) print((datetime.datetime.now() - themath.starttime).total_seconds()) #return False else: print('=== No math infomation ===') #return False #global round_cont #round_cont+=1 #获取当前最大的轮数 round_cont = db.session.query(func.max( Flags.rounds)).scalar() #Round.query.fields(Round.rounds).first() if round_cont: round_cont = round_cont + 1 else: round_cont = 1 flag_list = [] for i in mathobj: text = '%s %s check False' % (i.teamname, i.db_containers.typename) #记录 check_rezult 状态 if i.db_containers.check_stat == 1: # Round(attackteamid,rounds,containerid,text,score=0) db.session.add( Round(0, round_cont - 1, i.id, text, themath.checkscore)) # db.session.commit() #初始化新的一轮 check_rezult i.db_containers.check_stat = 0 flag = Flags(i.id, make_flag_str(i.container_name), round_cont) flag_list.append(flag) try: i.freshflag(flag.flag) except: i.db_containers.check_stat = 1 print('Round %d flag fresh %s error' % (round_cont, i.teamname)) t = threading.Thread(target=errorfresh, args=( i, flag.flag, )) t.setDaemon(True) t.start() db.session.add_all(flag_list) db.session.commit() countscore(round_cont - 1, mathobj, themath.checkscore, themath.atacckscore) time.sleep(timespan) return round_cont
def get_flag(key): """Get a flag's value from the datastore.""" flag = Flags.all().filter("flag_key =", key).get() if flag: return flag.value