def create_box(self): ''' Create a box object ''' form = Form( box_name="Enter a box name", description="Enter a description", difficulty="Select a difficulty", corporation_uuid="Please select a corporation", game_level="Please select a game level", ) if form.validate(self.request.arguments): try: game_level = int(self.get_argument('game_level')) corp_uuid = self.get_argument('corporation_uuid') if Box.by_name(self.get_argument('box_name')) is not None: self.render("admin/create/box.html", errors=["Box name already exists"] ) elif Corporation.by_uuid(corp_uuid) is None: self.render("admin/create/box.html", errors=["Corporation does not exist"] ) elif GameLevel.by_number(game_level) is None: self.render("admin/create/box.html", errors=["Game level does not exist"] ) else: self.__mkbox__() self.redirect('/admin/view/game_objects') except ValueError: self.render('admin/view/create.html', errors=["Invalid level number"] ) else: self.render("admin/create/box.html", errors=form.errors)
def create_box(self): ''' Create a box object ''' form = Form( box_name="Enter a box name", description="Enter a description", difficulty="Select a difficulty", corporation_uuid="Please select a corporation", game_level="Please select a game level", ) if form.validate(self.request.arguments): try: game_level = int(self.get_argument('game_level')) corp_uuid = self.get_argument('corporation_uuid') if Box.by_name(self.get_argument('box_name')) is not None: self.render("admin/create/box.html", errors=["Box name already exists"]) elif Corporation.by_uuid(corp_uuid) is None: self.render("admin/create/box.html", errors=["Corporation does not exist"]) elif GameLevel.by_number(game_level) is None: self.render("admin/create/box.html", errors=["Game level does not exist"]) else: self.__mkbox__() self.redirect('/admin/view/game_objects') except ValueError: self.render('admin/view/create.html', errors=["Invalid level number"]) else: self.render("admin/create/box.html", errors=form.errors)
def edit_boxes(self): ''' Edit existing boxes in the database ''' form = Form( uuid="Object not selected", name="Missing box name", corporation_uuid="Please select a corporation", description="Please enter a description", difficulty="Please enter a difficulty", ) if form.validate(self.request.arguments): box = Box.by_uuid(self.get_argument('uuid')) if box is not None: errors = [] if self.get_argument('name') != box.name: if Box.by_name(self.get_argument('name')) is None: logging.info("Updated box name %s -> %s" % ( box.name, self.get_argument('name'), )) box.name = unicode(self.get_argument('name')) else: errors.append("Box name already exists") corp = Corporation.by_uuid( self.get_argument('corporation_uuid')) if corp is not None and corp.id != box.corporation_id: logging.info("Updated %s's corporation %s -> %s" % ( box.name, box.corporation_id, corp.id, )) box.corporation_id = corp.id elif corp is None: errors.append("Corporation does not exist") if self.get_argument('description') != box.description: logging.info("Updated %s's description %s -> %s" % ( box.name, box.description, self.get_argument('description'), )) box.description = unicode(self.get_argument('description')) if self.get_argument('difficulty') != box.difficulty: logging.info("Updated %s's difficulty %s -> %s" % ( box.name, box.difficulty, self.get_argument('difficulty'), )) box.difficulty = unicode(self.get_argument('difficulty')) dbsession.add(box) dbsession.flush() self.render("admin/view/game_objects.html", errors=errors) else: self.render("admin/view/game_objects.html", errors=["Box does not exist"]) else: self.render("admin/view/game_objects.html", errors=form.errors)
def create_box(name, corporation, difficulty, game_level, description, ipv4_addresses=[], ipv6_addresses=[], avatar=None): if Box.by_name(name) is not None: logging.info("Box with name '%s' already exists, skipping" % (name)) return Box.by_name(name) logging.info("Create Box: %s" % name) if isinstance(game_level, int): game_level = GameLevel.by_number(game_level) box = Box( name=unicode(name[:16]), corporation_id=corporation.id, difficulty=unicode(difficulty[:16]), game_level_id=game_level.id, _description=unicode(description[:1024]), ) dbsession.add(box) dbsession.flush() if avatar is not None and os.path.exists(avatar): set_avatar(box, avatar) for ip_address in ipv4_addresses: __mkipv4__(box, ip_address) for ip_address in ipv6_addresses: __mkipv6__(box, ip_address) return box
def edit_boxes(self): ''' Edit existing boxes in the database ''' form = Form( uuid="Object not selected", name="Missing box name", corporation_uuid="Please select a corporation", description="Please enter a description", difficulty="Please enter a difficulty", ) if form.validate(self.request.arguments): box = Box.by_uuid(self.get_argument('uuid')) if box is not None: errors = [] if self.get_argument('name') != box.name: if Box.by_name(self.get_argument('name')) is None: logging.info("Updated box name %s -> %s" % (box.name, self.get_argument('name'),) ) box.name = unicode(self.get_argument('name')) else: errors.append("Box name already exists") corp = Corporation.by_uuid(self.get_argument('corporation_uuid')) if corp is not None and corp.id != box.corporation_id: logging.info("Updated %s's corporation %s -> %s" % (box.name, box.corporation_id, corp.id,)) box.corporation_id = corp.id elif corp is None: errors.append("Corporation does not exist") if self.get_argument('description') != box.description: logging.info("Updated %s's description %s -> %s" % (box.name, box.description, self.get_argument('description'),) ) box.description = unicode(self.get_argument('description')) if self.get_argument('difficulty') != box.difficulty: logging.info("Updated %s's difficulty %s -> %s" % (box.name, box.difficulty, self.get_argument('difficulty'),) ) box.difficulty = unicode(self.get_argument('difficulty')) dbsession.add(box) dbsession.flush() self.render("admin/view/game_objects.html", errors=errors) else: self.render("admin/view/game_objects.html", errors=["Box does not exist"] ) else: self.render("admin/view/game_objects.html", errors=form.errors)
def interrogation_response(self, msg): """ Steps 3 and 4; validate repsonses """ logging.debug("Received interrogate response, validating ...") response_xid = msg["response_xid"] user = User.by_handle(msg["handle"]) box = Box.by_name(msg["box_name"]) if self.config.whitelist_box_ips and self.remote_ip not in box.ips: self.send_error("Invalid remote IP for this box") elif user is None or user.is_admin(): self.send_error("User does not exist") elif box is None: self.send_error("Box does not exist") elif not self.is_valid_xid(box, response_xid): self.send_error("Invalid xid response") else: self.team_name = user.team.name self.team_uuid = user.team.uuid self.box_uuid = box.uuid self.box_name = box.name self.add_to_botnet(user)
def interrogation_response(self, msg): """ Steps 3 and 4; validate repsonses """ logging.debug("Recieved interrogate response, validating ...") response_xid = msg["rxid"] user = User.by_handle(msg["handle"]) box = Box.by_name(msg["box_name"]) if self.config.whitelist_box_ips and self.remote_ip not in box.ips: self.send_error("Invalid remote IP for this box") elif user is None or user.has_permission(ADMIN_PERMISSION): self.send_error("User does not exist") elif box is None: self.send_error("Box does not exist") elif not self.is_valid_xid(box, response_xid): self.send_error("Invalid xid response") else: self.team_name = user.team.name self.team_uuid = user.team.uuid self.box_uuid = box.uuid self.box_name = box.name self.add_to_botnet()
def interrogation_response(self, msg): ''' Steps 3 and 4; validate repsonses ''' logging.debug("Received interrogate response, validating ...") response_xid = msg['response_xid'] user = User.by_handle(msg['handle']) box = Box.by_name(msg['box_name']) if self.config.whitelist_box_ips and self.remote_ip not in box.ips: self.send_error("Invalid remote IP for this box") elif user is None or user.is_admin(): self.send_error("User does not exist") elif box is None: self.send_error("Box does not exist") elif not self.is_valid_xid(box, response_xid): self.send_error("Invalid xid response") else: self.team_name = user.team.name self.team_uuid = user.team.uuid self.box_uuid = box.uuid self.box_name = box.name self.add_to_botnet(user)
def interrogation_response(self, msg): ''' Steps 3 and 4; validate repsonses ''' logging.debug("Recieved interrogate response, validating ...") response_xid = msg['rxid'] user = User.by_handle(msg['handle']) box = Box.by_name(msg['box_name']) if self.config.whitelist_box_ips and self.remote_ip not in box.ips: self.send_error("Invalid remote IP for this box") elif user is None or user.has_permission(ADMIN_PERMISSION): self.send_error("User does not exist") elif box is None: self.send_error("Box does not exist") elif not self.is_valid_xid(box, response_xid): self.send_error("Invalid xid response") else: self.team_name = user.team.name self.team_uuid = user.team.uuid self.box_uuid = box.uuid self.box_name = box.name self.add_to_botnet()