def edit_ipv6(self): ''' Add ipv6 addresses to a box (sorta edits the box object) ''' form = Form(box_uuid="Select a box", ipv6="Please provide a list of IPv6 addresses") if form.validate(self.request.arguments): errors = [] box = Box.by_uuid(self.get_argument('box_uuid')) if box is not None: ips_string = self.get_argument('ipv6').replace('\n', ',').lower() ips = filter(lambda char: char in "1234567890abcdef:,", ips_string).split(",") for ip in filter(lambda ip: 0 < len(ip), ips): try: box = Box.by_ip_address(ip) if box is None: addr = IpAddress(box_id=box.id, v6=ip) dbsession.add(addr) else: errors.append( "%s has already been assigned to %s." % ( ip, box.name, )) except ValueError: errors.append("'%s' is not a valid IPv6 address" % str(ip[:39])) dbsession.flush() else: errors.append("Box does not exist") self.render("admin/view/game_objects.html", errors=errors) else: self.render("admin/view/game_objects.html", errors=form.errors)
def __mkipv4__(box, address): print(INFO + "IPv4 address '%s' now belongs to %s" % (address, box.name,)) ip = IpAddress( v4=unicode(address), ) box.ip_addresses.append(ip) dbsession.add(ip) dbsession.add(box) dbsession.flush() return ip
def __mkipv6__(box, address): print(INFO + "IPv6 address %s belongs to %s" % ( address, str(bold + box.name + W), )) ip = IpAddress(v6=unicode(address), ) box.ip_addresses.append(ip) dbsession.add(ip) dbsession.add(box) dbsession.flush() return ip
def del_ip(self): ''' Delete an ip address object ''' ip = IpAddress.by_address(self.get_argument('ip', '')) if ip is not None: logging.info("Deleted IP address: '%s'" % str(ip)) dbsession.delete(ip) dbsession.flush() self.redirect("/admin/view/game_objects") else: logging.info("IP address (%r) does not exist in database" % self.get_argument('ip', '')) self.render("admin/view/game_objects.html", errors=["IP does not exist in database"])
def vote(): ipaddr = IpAddress.query.get(request.remote_addr) if not ipaddr: ipaddr = IpAddress(request) db.session.add(ipaddr) db.session.commit() if not ipaddr.correct: print "INCORRECT IP " + request.remote_addr return redirect('/') votes_list = Vote.query.filter_by(ip=request.remote_addr).all() # Использованные id для этого IP used_ids = {vote.win_id for vote in votes_list} | \ {vote.lose_id for vote in votes_list} win_id = request.form["win_id"] lose_id = request.form["lose_id"] if (int(win_id) in used_ids) or (int(lose_id) in used_ids): return redirect('/anti-bot') win = User.query.get(win_id) lose = User.query.get(lose_id) if (not win) or (not lose): # Id out of range return redirect('/') win_elo, win_times = win.elo, win.times lose_elo, lose_times = lose.elo, lose.times #print "WIN Id%s, rate=%s, %s times" % (win_id, win_elo, win_times) #print "LOSE Id%s, rate=%s, %s times" % (lose_id, lose_elo, lose_times) win_elo = elo(1, float(win_elo), float(lose_elo), int(win_times)) lose_elo = elo(0, float(lose_elo), float(win_elo), int(lose_times)) win.elo = win_elo win.times += 1 lose.elo = lose_elo lose.times += 1 vote = Vote(request, win_id, lose_id) db.session.add(vote) db.session.commit() #print "WIN new rate=%f" % (win_elo) #print "LOSE new rate=%f" % (lose_elo) return redirect('/')
def del_ip(self): ''' Delete an ip address object ''' ip = IpAddress.by_address(self.get_argument('ip', '')) if ip is not None: logging.info("Deleted IP address: '%s'" % str(ip)) dbsession.delete(ip) dbsession.flush() self.redirect("/admin/view/game_objects") else: logging.info("IP address (%r) does not exist in database" % self.get_argument('ip', '') ) self.render("admin/view/game_objects.html", errors=["IP does not exist in database"] )