Пример #1
0
    def edit_boxes(self):
        '''
        Edit existing boxes in the database, and log the changes
        '''
        try:
            box = Box.by_uuid(self.get_argument('uuid', ''))
            if box is None:
                raise ValidationError("Box does not exist")
            # Name
            name = self.get_argument('name', '')
            if name != box.name:
                if Box.by_name(name) is None:
                    logging.info("Updated box name %s -> %s" % (
                        box.name,
                        name,
                    ))
                    box.name = name
                else:
                    raise ValidationError("Box name already exists")
            # Corporation
            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:
                raise ValidationError("Corporation does not exist")
            # Description
            description = self.get_argument('description', '')
            if description != box._description:
                logging.info("Updated %s's description %s -> %s" % (
                    box.name,
                    box.description,
                    description,
                ))
                box.description = description
            # Difficulty
            difficulty = self.get_argument('difficulty', '')
            if difficulty != box.difficulty:
                logging.info("Updated %s's difficulty %s -> %s" % (
                    box.name,
                    box.difficulty,
                    difficulty,
                ))
                box.difficulty = difficulty
            # Avatar
            if 'avatar' in self.request.files:
                box.avatar = self.request.files['avatar'][0]['body']

            self.dbsession.add(box)
            self.dbsession.commit()
            self.redirect("/admin/view/game_objects")
        except ValidationError as error:
            self.render("admin/view/game_objects.html", errors=[
                str(error),
            ])
Пример #2
0
def create_box(corp=None):
    if corp is None:
        corp = create_corp()
    game_level = GameLevel.all()[0]
    box = Box(corporation_id=corp.id, game_level_id=game_level.id)
    box.name = "TestBox"
    box.description = "Some description"
    box.difficuly = "Easy"
    corp.boxes.append(box)
    dbsession.add(box)
    dbsession.commit()
    return box, corp
Пример #3
0
def create_box(corp=None):
    if corp is None:
        corp = create_corp()
    game_level = GameLevel.all()[0]
    box = Box(corporation_id=corp.id, game_level_id=game_level.id)
    box.name = "TestBox"
    box.description = "Some description"
    box.difficuly = "Easy"
    corp.boxes.append(box)
    dbsession.add(box)
    dbsession.commit()
    return box, corp
Пример #4
0
 def create_box(self):
     ''' Create a box object '''
     try:
         game_level = self.get_argument('game_level', '')
         corp_uuid = self.get_argument('corporation_uuid', '')
         if Box.by_name(self.get_argument('name', '')) is not None:
             raise ValidationError("Box name already exists")
         elif Corporation.by_uuid(corp_uuid) is None:
             raise ValidationError("Corporation does not exist")
         elif GameLevel.by_number(game_level) is None:
             raise ValidationError("Game level does not exist")
         else:
             corp = Corporation.by_uuid(corp_uuid)
             level = GameLevel.by_number(game_level)
             box = Box(corporation_id=corp.id, game_level_id=level.id)
             box.name = self.get_argument('name', '')
             box.description = self.get_argument('description', '')
             box.autoformat = self.get_argument('autoformat', '') == 'true'
             box.difficulty = self.get_argument('difficulty', '')
             self.dbsession.add(box)
             self.dbsession.commit()
             if hasattr(self.request,
                        'files') and 'avatar' in self.request.files:
                 box.avatar = self.request.files['avatar'][0]['body']
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render('admin/create/box.html', errors=[
             str(error),
         ])
Пример #5
0
    def edit_boxes(self):
        '''
        Edit existing boxes in the database, and log the changes
        '''
        try:
            box = Box.by_uuid(self.get_argument('uuid', ''))
            if box is None:
                raise ValidationError("Box does not exist")
            # Name
            name = self.get_argument('name', '')
            if name != box.name:
                if Box.by_name(name) is None:
                    logging.info("Updated box name %s -> %s" % (
                        box.name, name,
                    ))
                    box.name = name
                else:
                    raise ValidationError("Box name already exists")
            # Corporation
            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:
                raise ValidationError("Corporation does not exist")
            # Description
            description = self.get_argument('description', '')
            if description != box._description:
                logging.info("Updated %s's description %s -> %s" % (
                    box.name, box.description, description,
                ))
                box.description = description
            # Difficulty
            difficulty = self.get_argument('difficulty', '')
            if difficulty != box.difficulty:
                logging.info("Updated %s's difficulty %s -> %s" % (
                    box.name, box.difficulty, difficulty,
                ))
                box.difficulty = difficulty
            # Avatar
            if 'avatar' in self.request.files:
                box.avatar = self.request.files['avatar'][0]['body']

            self.dbsession.add(box)
            self.dbsession.commit()
            self.redirect("/admin/view/game_objects")
        except ValidationError as error:
            self.render("admin/view/game_objects.html", errors=[str(error), ])
Пример #6
0
 def to_dict(self):
     """ Returns public data as a dict """
     box = Box.by_id(self.box_id)
     if self.lock_id:
         lock_uuid = Flag.by_id(self.lock_id).uuid
     else:
         lock_uuid = ""
     case_sensitive = self.case_sensitive
     if case_sensitive != 0:
         case_sensitive = 1
     return {
         "name": self.name,
         "uuid": self.uuid,
         "description": self.description,
         "capture_message": self.capture_message,
         "value": self.value,
         "original_value": self.original_value,
         "box": box.uuid,
         "token": self.token,
         "lock_uuid": lock_uuid,
         "case-sensitive": case_sensitive,
         "flagtype": self.type,
         "choices": self.choices(),
         "order": self.order,
     }
Пример #7
0
 def get(self, *args, **kwargs):
     """
     Renders the box details page.
     """
     uuid = self.get_argument("uuid", "")
     box = Box.by_uuid(uuid)
     if box is not None:
         user = self.get_current_user()
         level = GameLevel.by_id(box.game_level_id)
         if (
             user.team
             and level.type != "none"
             and level not in user.team.game_levels
         ):
             self.redirect("/403")
         elif box.locked:
             self.render(
                 "missions/status.html",
                 errors=None,
                 info=["This box is currently locked by the Admin."],
             )
         else:
             self.render(
                 "missions/box.html",
                 box=box,
                 user=user,
                 team=user.team,
                 errors=[],
                 success=[],
                 info=[],
             )
     else:
         self.render("public/404.html")
 def edit_flags(self):
     """ Edit existing flags in the database """
     try:
         flag = Flag.by_uuid(self.get_argument("uuid", ""))
         if flag is None:
             raise ValidationError("Flag does not exist")
         # Name
         name = self.get_argument("name", "")
         if flag._name != name:
             logging.info("Updated flag name %s -> %s" % (flag._name, name))
             flag.name = name
         token = self.get_argument("token", "")
         if flag.token != token:
             flag.token = token
         # Description
         description = self.get_argument("description", "")
         if flag._description != description:
             logging.info("Updated %s's description %s -> %s" %
                          (flag.name, flag._description, description))
             flag.description = description
         # Value
         flag.value = self.get_argument("value", "")
         flag.original_value = self.get_argument("value", "")
         flag.capture_message = self.get_argument("capture_message", "")
         flag.case_sensitive = self.get_argument("case-sensitive", 1)
         # Type
         flag_type = self.get_argument("flag_type", None)
         if flag_type and flag_type != flag.type:
             logging.info("Updated %s's type %s -> %s" %
                          (flag.name, flag.type, flag_type))
             flag.type = flag_type
         # Dependency Lock
         lock = Flag.by_uuid(self.get_argument("lock_uuid", ""))
         if lock:
             flag.lock_id = lock.id
         else:
             flag.lock_id = None
         box = Box.by_uuid(self.get_argument("box_uuid", ""))
         if box is not None and flag not in box.flags:
             logging.info("Updated %s's box %d -> %d" %
                          (flag.name, flag.box_id, box.id))
             flag.box_id = box.id
             for fl in box.flags:
                 fl.order
                 self.dbsession.add(fl)
             flag.order = len(box.flags) + 1  # place flag at end
             for hint in flag.hints:
                 hint.box_id = box.id
                 self.dbsession.add(hint)
         elif box is None:
             raise ValidationError("Box does not exist")
         self.dbsession.add(flag)
         self.dbsession.commit()
         if flag.type == FLAG_CHOICE:
             self.edit_choices(flag, self.request.arguments)
         self.redirect("/admin/view/game_objects#%s" % box.uuid)
     except ValidationError as error:
         self.render("admin/view/game_objects.html",
                     success=None,
                     errors=["%s" % error])
Пример #9
0
 def get(self, *args, **kwargs):
     ''' Send file to user if their team owns it '''
     uuid = self.get_argument('uuid', '')
     box = Box.by_uuid(uuid)
     if box is not None and box.source_code is not None:
         user = self.get_current_user()
         if box.source_code in user.team.purchased_source_code:
             root = self.application.settings['source_code_market_dir']
             src_file = open(root + '/' + box.source_code.uuid, 'r')
             src_data = b64decode(src_file.read())
             src_file.close()
             content_type = guess_type(box.source_code.file_name)[0]
             if content_type is None: content_type = 'unknown/data'
             self.set_header('Content-Type', content_type)
             self.set_header('Content-Length', len(src_data))
             fname = filter(lambda char: char in self.goodchars,
                            box.source_code.file_name)
             self.set_header('Content-Disposition',
                             'attachment; filename=%s' % fname)
             self.write(src_data)
             self.finish()
         else:
             self.render('public/404.html')
     else:
         self.render('public/404.html')
Пример #10
0
 def get(self, *args, **kwargs):
     fuuid = self.get_argument("flag", None)
     buuid = self.get_argument("box", None)
     try:
         reward = int(self.get_argument("reward", 0))
     except ValueError:
         reward = 0
     user = self.get_current_user()
     box = Box.by_uuid(buuid)
     flag = Flag.by_uuid(fuuid)
     if box is not None and box.is_complete(user):
         if self.config.story_mode and len(box.capture_message) > 0:
             self.add_content_policy("script", "'unsafe-eval'")
             self.render("missions/captured.html",
                         box=box,
                         flag=None,
                         reward=reward)
             return
     elif flag is not None and flag in user.team.flags:
         if self.config.story_mode and len(flag.capture_message) > 0:
             self.add_content_policy("script", "'unsafe-eval'")
             self.render("missions/captured.html",
                         box=None,
                         flag=flag,
                         reward=reward)
             return
     self.render("public/404.html")
Пример #11
0
 def edit_hint(self):
     """ Edit a hint object """
     try:
         hint = Hint.by_uuid(self.get_argument("uuid", ""))
         if hint is None:
             raise ValidationError("Hint does not exist")
         logging.debug("Edit hint object with uuid of %s" % hint.uuid)
         price = self.get_argument("price", "")
         if hint.price != price:
             hint.price = price
         description = self.get_argument("description", "")
         hint.description = description
         flag = Flag.by_uuid(self.get_argument("hint-flag_uuid", ""))
         if flag:
             flag_id = flag.id
         else:
             flag_id = None
         hint.flag_id = flag_id
         box = Box.by_id(flag.box_id)
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect("/admin/view/game_objects#%s" % box.uuid)
     except ValidationError as error:
         self.render("admin/view/game_objects.html",
                     success=None,
                     errors=[str(error)])
Пример #12
0
    def _mkflag(self, flag_type, is_file=False):
        """ Creates the flag in the database """
        box = Box.by_uuid(self.get_argument("box_uuid", ""))
        if box is None:
            raise ValidationError("Box does not exist")
        if is_file:
            if not hasattr(self.request,
                           "files") or not "flag" in self.request.files:
                raise ValidationError("No file in request")
            token = self.request.files["flag"][0]["body"]
        else:
            token = self.get_argument("token", "")
        name = self.get_argument("flag_name", "")
        description = self.get_argument("description", "")
        reward = self.get_argument("reward", "")
        flag = Flag.create_flag(flag_type, box, name, token, description,
                                reward)
        flag.capture_message = self.get_argument("capture_message", "")
        flag.case_sensitive = self.get_argument("case-sensitive", 1)
        flag.order = len(box.flags) + 1
        lock = Flag.by_uuid(self.get_argument("lock_uuid", ""))
        if lock:
            flag.lock_id = lock.id
        else:
            flag.lock_id = None
        self.add_attachments(flag)
        self.dbsession.add(flag)
        self.dbsession.commit()

        choices = self.get_arguments("addmore[]", strip=True)
        if choices is not None:
            for item in choices:
                FlagChoice.create_choice(flag, item)

        self.redirect("/admin/view/game_objects#%s" % box.uuid)
Пример #13
0
 def team_skills(self):
     ''' Returns team details in JSON form '''
     uuid = self.get_argument('uuid', '')
     if uuid == '':
         user = self.get_current_user()
         if user:
             team = user.team
     else:
         team = Team.by_uuid(uuid)
     if team is not None:
         categories = Category.all()
         catlist = {}
         for cat in categories:
             catbox = Box.by_category(cat.id)
             if (len(catbox) > 0):
                 catlist[int(cat.id)] = 0
         for flag in team.flags:
             box = flag.box
             if box and box.category_id is not None:
                 catlist[int(box.category_id)] += 1
         skillvalues = []
         for val in catlist:
             skillvalues.append(catlist[val])
         self.write(str(skillvalues))
     else:
         self.write({'error': 'Team does not exist'})
     self.finish()
Пример #14
0
 def get(self, *args, **kwargs):
     ''' Send file to user if their team owns it '''
     uuid = self.get_argument('uuid', '')
     box = Box.by_uuid(uuid)
     if box is not None and box.source_code is not None:
         user = self.get_current_user()
         if box.source_code in user.team.purchased_source_code:
             root = self.application.settings['source_code_market_dir']
             src_file = open(root + '/' + box.source_code.uuid, 'r')
             src_data = b64decode(src_file.read())
             src_file.close()
             content_type = guess_type(box.source_code.file_name)[0]
             if content_type is None: content_type = 'unknown/data'
             self.set_header('Content-Type', content_type)
             self.set_header('Content-Length', len(src_data))
             fname = filter(lambda char: char in self.goodchars, box.source_code.file_name)
             self.set_header('Content-Disposition',
                 'attachment; filename=%s' % fname
             )
             self.write(src_data)
             self.finish()
         else:
             self.render('public/404.html')
     else:
         self.render('public/404.html')
Пример #15
0
 def render_page(self, errors=None):
     """ Addes extra params to render() """
     user = self.get_current_user()
     boxes = [box for box in Box.all() if box.source_code is not None]
     self.render(
         "upgrades/source_code_market.html", user=user, boxes=boxes, errors=errors
     )
Пример #16
0
 def get(self, *args, **kwargs):
     """ Send file to user if their team owns it """
     uuid = self.get_argument("uuid", "")
     box = Box.by_uuid(uuid)
     if box is not None and box.source_code is not None:
         user = self.get_current_user()
         if box.source_code in user.team.purchased_source_code:
             content_type = guess_type(box.source_code.file_name)[0]
             if content_type is None:
                 content_type = "unknown/data"
             self.set_header("Content-Type", content_type)
             self.set_header("Content-Length", len(box.source_code.data))
             fname = "".join(
                 [
                     char
                     for char in box.source_code.file_name
                     if char in self.goodchars
                 ]
             )
             self.set_header(
                 "Content-Disposition", "attachment; filename=%s" % fname
             )
             self.write(box.source_code.data)
             self.finish()
         else:
             self.render("public/404.html")
     else:
         self.render("public/404.html")
Пример #17
0
 def render_page(self, errors=None):
     ''' Addes extra params to render() '''
     user = self.get_current_user()
     boxes = filter(lambda box: box.source_code is not None, Box.all())
     self.render('upgrades/source_code_market.html',
         user=user, boxes=boxes, errors=errors
     )
 def _mkflag(self, flag_type, is_file=False):
     ''' Creates the flag in the database '''
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is None:
         raise ValidationError('Box does not exist')
     if is_file:
         if not hasattr(self.request,
                        'files') or not 'flag' in self.request.files:
             raise ValidationError('No file in request')
         token = self.request.files['flag'][0]['body']
     else:
         token = self.get_argument('token', '')
     name = self.get_argument('flag_name', '')
     description = self.get_argument('description', '')
     reward = self.get_argument('reward', '')
     flag = Flag.create_flag(flag_type, box, name, token, description,
                             reward)
     flag.capture_message = self.get_argument('capture_message', '')
     flag.case_sensitive = self.get_argument('case-sensitive', 1)
     lock = Flag.by_uuid(self.get_argument('lock_uuid', ''))
     if lock:
         flag.lock_id = lock.id
     else:
         flag.lock_id = None
     self.add_attachments(flag)
     self.dbsession.add(flag)
     self.dbsession.commit()
     choices = self.get_arguments('addmore[]', strip=True)
     if choices is not None:
         for item in choices:
             FlagChoice.create_choice(flag, item)
     self.redirect("/admin/view/game_objects#%s" % box.uuid)
Пример #19
0
 def get(self, *args, **kwargs):
     """
     Renders the box details page.
     """
     uuid = self.get_argument("uuid", "")
     box = Box.by_uuid(uuid)
     if box is not None:
         user = self.get_current_user()
         if box.locked:
             self.render(
                 "missions/status.html",
                 errors=None,
                 info=["This box is currently locked by the Admin."],
             )
         else:
             self.render(
                 "missions/box.html",
                 box=box,
                 user=user,
                 team=user.team,
                 errors=[],
                 success=[],
                 info=[],
             )
     else:
         self.render("public/404.html")
Пример #20
0
 def _mkflag(self, flag_type, is_file=False):
     ''' Creates the flag in the database '''
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is None:
         raise ValidationError('Box does not exist')
     if is_file:
         if not hasattr(self.request, 'files') or not 'flag' in self.request.files:
             raise ValidationError('No file in request')
         token = self.request.files['flag'][0]['body']
     else:
         token = self.get_argument('token', '')
     name = self.get_argument('flag_name', '')
     description = self.get_argument('description', '')
     reward = self.get_argument('reward', '')
     flag = Flag.create_flag(
         flag_type, box, name, token, description, reward)
     flag.capture_message = self.get_argument('capture_message', '')
     flag.case_sensitive = self.get_argument('case-sensitive', 1)
     lock = Flag.by_uuid(self.get_argument('lock_uuid', ''))
     if lock:
         flag.lock_id = lock.id
     else:
         flag.lock_id = None
     self.add_attachments(flag)
     self.dbsession.add(flag)
     self.dbsession.commit()
     choices = self.get_arguments('addmore[]', strip=True)
     if choices is not None:
         for item in choices:
             FlagChoice.create_choice(flag, item)
     self.redirect("/admin/view/game_objects#%s" % box.uuid)
Пример #21
0
def get_new_avatar(dir, forceteam=False):
    avatar = default_avatar(dir)
    avatars = filter_avatars(dir)
    if len(avatars) == 0:
        return avatar
    if dir == "team" or forceteam:
        from models.Team import Team

        cmplist = Team.all()
    elif dir == "user":
        from models.User import User

        cmplist = User.all()
    else:
        from models.Box import Box

        cmplist = Box.all()
    dblist = []
    for item in cmplist:
        if item._avatar:
            dblist.append(item._avatar)
    for image in avatars:
        if not image in dblist:
            return image
    return avatars[randint(0, len(avatars) - 1)]
Пример #22
0
 def get(self, *args, **kwargs):
     """
     Renders the box details page.
     """
     uuid = self.get_argument("uuid", "")
     box = Box.by_uuid(uuid)
     if box is not None:
         user = self.get_current_user()
         if self.application.settings["game_started"] or user.is_admin():
             self.render(
                 "missions/box.html",
                 box=box,
                 user=user,
                 team=user.team,
                 errors=[],
                 success=[],
                 info=[],
             )
         else:
             self.render(
                 "missions/status.html",
                 errors=None,
                 info=["The game has not started yet"],
             )
     else:
         self.render("public/404.html")
Пример #23
0
 def render_page(self, errors=None):
     ''' Addes extra params to render() '''
     user = self.get_current_user()
     boxes = filter(lambda box: box.source_code is not None, Box.all())
     self.render('upgrades/source_code_market.html',
                 user=user,
                 boxes=boxes,
                 errors=errors)
Пример #24
0
 def lock_box(self):
     uuid = self.get_argument("uuid", "")
     box = Box.by_uuid(uuid)
     if box is not None:
         box.locked = False if box.locked else True
         self.dbsession.add(box)
         self.dbsession.commit()
     self.redirect("/admin/view/game_objects#%s" % str(uuid))
 def render_page(self, flag, errors=[]):
     ''' Wrapper to .render() to avoid duplicate code '''
     user = self.get_current_user()
     box = Box.by_id(flag.box_id)
     self.render('missions/box.html',
                 box=box,
                 team=user.team,
                 errors=errors)
Пример #26
0
 def render_page(self, flag, errors=[]):
     ''' Wrapper to .render() to avoid duplicate code '''
     user = self.get_current_user()
     box = Box.by_id(flag.box_id)
     self.render('missions/box.html',
                 box=box,
                 team=user.team,
                 errors=errors)
Пример #27
0
 def create_box(self):
     ''' Create a box object '''
     try:
         game_level = self.get_argument('game_level', '')
         corp_uuid = self.get_argument('corporation_uuid', '')
         if Box.by_name(self.get_argument('name', '')) is not None:
             raise ValidationError("Box name already exists")
         elif Corporation.by_uuid(corp_uuid) is None:
             raise ValidationError("Corporation does not exist")
         elif GameLevel.by_number(game_level) is None:
             raise ValidationError("Game level does not exist")
         else:
             corp = Corporation.by_uuid(corp_uuid)
             level = GameLevel.by_number(game_level)
             box = Box(corporation_id=corp.id, game_level_id=level.id)
             box.name = self.get_argument('name', '')
             box.description = self.get_argument('description', '')
             box.autoformat = self.get_argument('autoformat', '') == 'true'
             box.difficulty = self.get_argument('difficulty', '')
             self.dbsession.add(box)
             self.dbsession.commit()
             if hasattr(self.request, 'files') and 'avatar' in self.request.files:
                 box.avatar = self.request.files['avatar'][0]['body']
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render('admin/create/box.html', errors=[str(error), ])
Пример #28
0
 def delete_source_code(self):
     ''' Delete source code file '''
     uuid = self.get_argument('box_uuid', '')
     box = Box.by_uuid(uuid)
     if box is not None and box.source_code is not None:
         box.source_code.delete_data()
         self.dbsession.delete(box.source_code)
         self.dbsession.commit()
     else:
         raise ValidationError("Box/source code does not exist")
     self.render('admin/upgrades/source_code_market.html', errors=None)
Пример #29
0
 def post(self, *args, **kwargs):
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is not None and box.source_code is not None:
         user = self.get_current_user()
         if box.source_code.price <= user.team.money:
             self.purchase_code(box)
             self.redirect("/source_code_market")
         else:
             self.render_page(["You cannot afford to purchase this code"])
     else:
         self.render_page(["Box does not exist"])
Пример #30
0
 def post(self, *args, **kwargs):
     box = Box.by_uuid(self.get_argument("box_uuid", ""))
     if box is not None and box.source_code is not None:
         user = self.get_current_user()
         if box.source_code.price <= user.team.money:
             self.purchase_code(box)
             self.redirect("/source_code_market")
         else:
             self.render_page(["You cannot afford to purchase this code"])
     else:
         self.render_page(["Box does not exist"])
Пример #31
0
 def get(self, *args, **kwargs):
     ''' Download a Box's garbage file '''
     box = Box.by_uuid(self.get_argument('uuid', ''))
     if box is not None:
         data = box.get_garbage_cfg()
         self.set_header('Content-Type', 'text/plain')
         self.set_header(
             "Content-disposition", "attachment; filename=%s.garbage" %
             (filter(lambda char: char in printable[:-38], box.name), ))
         self.set_header('Content-Length', len(data))
         self.write(data)
Пример #32
0
 def del_box(self):
     ''' Delete a box '''
     box = Box.by_uuid(self.get_argument('uuid', ''))
     if box is not None:
         logging.info("Delete box: %s" % box.name)
         self.dbsession.delete(box)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     else:
         self.render('admin/view/game_objects.html',
                     errors=["Box does not exist in database."])
Пример #33
0
 def delete_source_code(self):
     """ Delete source code file """
     uuid = self.get_argument("box_uuid", "")
     box = Box.by_uuid(uuid)
     if box is not None and box.source_code is not None:
         box.source_code.delete_data()
         self.dbsession.delete(box.source_code)
         self.dbsession.commit()
     else:
         raise ValidationError("Box/source code does not exist")
     self.render("admin/upgrades/source_code_market.html", errors=None)
Пример #34
0
 def get(self, *args, **kwargs):
     ''' Download a Box's garbage file '''
     box = Box.by_uuid(self.get_argument('uuid', ''))
     if box is not None:
         data = box.get_garbage_cfg()
         self.set_header('Content-Type', 'text/plain')
         self.set_header(
             "Content-disposition", "attachment; filename=%s.garbage" % (
                 filter(lambda char: char in printable[:-38], box.name),
             ))
         self.set_header('Content-Length', len(data))
         self.write(data)
Пример #35
0
 def to_dict(self):
     """ Returns public data as a dict """
     box = Box.by_id(self.box_id)
     return {
         "name": self.name,
         "uuid": self.uuid,
         "description": self.description,
         "capture_message": self.capture_message,
         "value": self.value,
         "box": box.uuid,
         "token": self.token,
     }
Пример #36
0
 def to_dict(self):
     ''' Returns public data as a dict '''
     box = Box.by_id(self.box_id)
     return {
         'name': self.name,
         'uuid': self.uuid,
         'description': self.description,
         'capture_message': self.capture_message,
         'value': self.value,
         'box': box.uuid,
         'token': self.token,
     }
Пример #37
0
 def to_dict(self):
     ''' Returns public data as a dict '''
     box = Box.by_id(self.box_id)
     return {
         'name': self.name,
         'uuid': self.uuid,
         'description': self.description,
         'capture_message': self.capture_message,
         'value': self.value,
         'box': box.uuid,
         'token': self.token,
     }
Пример #38
0
 def get(self, *args, **kwargs):
     """ Download a Box's garbage file """
     box = Box.by_uuid(self.get_argument("uuid", ""))
     if box is not None:
         data = box.get_garbage_cfg()
         self.set_header("Content-Type", "text/plain")
         self.set_header(
             "Content-disposition",
             "attachment; filename=%s.garbage" % (filter(lambda char: char in printable[:-38], box.name),),
         )
         self.set_header("Content-Length", len(data))
         self.write(data)
Пример #39
0
 def del_box(self):
     ''' Delete  a box '''
     box = Box.by_uuid(self.get_argument('uuid', ''))
     if box is not None:
         logging.info("Delete box: %s" % box.name)
         self.dbsession.delete(box)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     else:
         self.render('admin/view/game_objects.html',
             errors=["Box does not exist in database."]
         )
Пример #40
0
 def add_source_code(self):
     box = Box.by_uuid(self.get_argument("box_uuid", ""))
     if box is not None:
         file_count = len(self.request.files["source_archive"])
         if not "source_archive" in self.request.files and 0 < file_count:
             raise ValidationError("No file data")
         else:
             price = self.get_argument("price", "")
             self.create_source_code(box, price)
             self.render("admin/upgrades/source_code_market.html", errors=None)
     else:
         raise ValidationError("The selected box does not exist")
Пример #41
0
 def add_source_code(self):
     box = Box.by_uuid(self.get_argument("box_uuid", ""))
     if box is not None:
         file_count = len(self.request.files["source_archive"])
         if "source_archive" not in self.request.files and 0 < file_count:
             raise ValidationError("No file data")
         else:
             price = self.get_argument("price", "")
             self.create_source_code(box, price)
             self.render("admin/upgrades/source_code_market.html", errors=None)
     else:
         raise ValidationError("The selected box does not exist")
Пример #42
0
 def add_source_code(self):
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is not None:
         file_count = len(self.request.files['source_archive'])
         if not 'source_archive' in self.request.files and 0 < file_count:
             raise ValidationError("No file data")
         else:
             price = self.get_argument('price', '')
             self.create_source_code(box, price)
             self.render('admin/upgrades/source_code_market.html',
                         errors=None)
     else:
         raise ValidationError("The selected box does not exist")
Пример #43
0
 def del_box(self):
     """ Delete a box """
     box = Box.by_uuid(self.get_argument("uuid", ""))
     if box is not None:
         logging.info("Delete box: %s" % box.name)
         self.dbsession.delete(box)
         self.dbsession.commit()
         self.redirect("/admin/view/game_objects")
     else:
         self.render(
             "admin/view/game_objects.html",
             errors=["Box does not exist in database."],
         )
Пример #44
0
 def get(self, *args, **kwargs):
     """ Download a Box's garbage file """
     box = Box.by_uuid(self.get_argument("uuid", ""))
     if box is not None:
         data = box.get_garbage_cfg()
         self.set_header("Content-Type", "text/plain")
         self.set_header(
             "Content-disposition",
             "attachment; filename=%s.garbage"
             % "".join(list(filter(lambda char: char in printable[:-38], box.name))),
         )
         self.set_header("Content-Length", len(data))
         self.write(data)
Пример #45
0
 def add_source_code(self):
     box = Box.by_uuid(self.get_argument('box_uuid'), '')
     if box is not None:
         file_count = len(self.request.files['source_archive'])
         if not 'source_archive' in self.request.files and 0 < file_count:
             raise ValidationError("No file data")
         else:
             price = self.get_argument('price', '')
             self.create_source_code(box, price)
             self.render('admin/upgrades/source_code_market.html',
                         errors=None)
     else:
         raise ValidationError("The selected box does not exist")
Пример #46
0
 def to_dict(self):
     flag = Flag.by_id(self.flag_id)
     if flag:
         flag_uuid = flag.uuid
     else:
         flag_uuid = ""
     return {
         'price': str(self.price),
         'description': self.description,
         'flag_uuid': flag_uuid,
         'uuid': self.uuid,
         'flaglist': Box.flaglist(self.box_id)
     }
Пример #47
0
 def to_dict(self):
     flag = Flag.by_id(self.flag_id)
     if flag:
         flag_uuid = flag.uuid
     else:
         flag_uuid = ""
     return {
         'price': str(self.price),
         'description': self.description,
         'flag_uuid': flag_uuid,
         'uuid': self.uuid,
         'flaglist': Box.flaglist(self.box_id)
     }
Пример #48
0
 def create_hint(self):
     ''' Add hint to database '''
     try:
         box = Box.by_uuid(self.get_argument('box_uuid', ''))
         if box is None:
             raise ValidationError("Box does not exist")
         hint = Hint(box_id=box.id)
         hint.price = self.get_argument('price', '')
         hint.description = self.get_argument('description', '')
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render('admin/create/hint.html', errors=[str(error), ])
Пример #49
0
 def box_level(self):
     ''' Changes a boxs level '''
     errors = []
     box = Box.by_uuid(self.get_argument('box_uuid'))
     level = GameLevel.by_uuid(self.get_argument('level_uuid'))
     if box is not None and level is not None:
         box.game_level_id = level.id
         self.dbsession.add(box)
         self.dbsession.commit()
     elif box is None:
         errors.append("Box does not exist")
     elif level is None:
         errors.append("GameLevel does not exist")
     self.render("admin/view/game_levels.html", errors=errors)
Пример #50
0
 def get(self, *args, **kwargs):
     '''
     Renders the box details page.
     '''
     uuid = self.get_argument('uuid', '')
     box = Box.by_uuid(uuid)
     if box is not None:
         user = self.get_current_user()
         self.render('missions/box.html',
                     box=box,
                     team=user.team,
                     errors=[])
     else:
         self.render('public/404.html')
Пример #51
0
 def edit_flags(self):
     ''' Edit existing flags in the database '''
     try:
         flag = Flag.by_uuid(self.get_argument('uuid', ''))
         if flag is None:
             raise ValidationError("Flag does not exist")
         # Name
         name = self.get_argument('name', '')
         if flag.name != name:
             logging.info("Updated flag name %s -> %s" % (
                 flag.name, name,
             ))
             flag.name = name
         token = self.get_argument('token', '')
         if flag.token != token:
             flag.token = token
         # Description
         description = self.get_argument('description', '')
         if flag._description != description:
             logging.info("Updated %s's description %s -> %s" % (
                 flag.name, flag._description, description,
             ))
             flag.description = description
         # Value
         flag.value = self.get_argument('value', '')
         flag.original_value = self.get_argument('value', '')
         flag.capture_message = self.get_argument('capture_message', '')
         flag.case_sensitive = self.get_argument('case-sensitive', 1)
         # Dependency Lock
         lock = Flag.by_uuid(self.get_argument('lock_uuid', ''))
         if lock:
             flag.lock_id = lock.id
         else:
             flag.lock_id = None
         box = Box.by_uuid(self.get_argument('box_uuid', ''))
         if box is not None and flag not in box.flags:
             logging.info("Updated %s's box %d -> %d" % (
                 flag.name, flag.box_id, box.id
             ))
             flag.box_id = box.id
         elif box is None:
             raise ValidationError("Box does not exist")
         self.dbsession.add(flag)
         self.dbsession.commit()
         if flag.type == FLAG_CHOICE:
             self.edit_choices(flag, self.request.arguments)
         self.redirect("/admin/view/game_objects#%s" % box.uuid)
     except ValidationError as error:
         self.render("admin/view/game_objects.html", errors=["%s" % error])
Пример #52
0
 def create_hint(self):
     ''' Add hint to database '''
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is not None:
         try:
             hint = Hint(box_id=box.id)
             hint.price = self.get_argument('price', '')
             hint.description = self.get_argument('description', '')
             self.dbsession.add(hint)
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
         except ValueError as error:
             self.render('admin/create/hint.html', errors=["%s" % error])
     else:
         self.render('admin/create/hint.html', errors=["Box does not exist"])
Пример #53
0
 def edit_flags(self):
     ''' Super ugly code, yes - Edit existing flags in the database '''
     flag = Flag.by_uuid(self.get_argument('uuid', ''))
     if flag is not None:
         try:
             name = self.get_argument('name', '')
             if flag.name != name:
                 if Flag.by_name(name) is None:
                     logging.info("Updated flag name %s -> %s" %
                         (flag.name, name,)
                     )
                     flag.name = name
                 else:
                     raise ValueError("Flag name already exists")
             token = self.get_argument('token', '')
             if flag.token != token:
                 if Flag.by_token(token) is None:
                     logging.info("Updated %s's token %s -> %s" %
                         (flag.name, flag.token, token)
                     )
                     flag.token = token
                 else:
                     raise ValueError("Token is not unique")
             description = self.get_argument('description', '')
             if flag._description != description:
                 logging.info("Updated %s's description %s -> %s" %
                     (flag.name, flag._description, description,)
                 )
                 flag.description = description
             flag.value = self.get_argument('value', '')
             flag.capture_message = self.get_argument('capture_message', '')
             box = Box.by_uuid(self.get_argument('box_uuid', ''))
             if box is not None and flag not in box.flags:
                 logging.info("Updated %s's box %d -> %d" %
                     (flag.name, flag.box_id, box.id)
                 )
                 flag.box_id = box.id
             elif box is None:
                 raise ValueError("Box does not exist")
             self.dbsession.add(flag)
             self.dbsession.commit()
             self.redirect("/admin/view/game_objects")
         except ValueError as error:
             self.render("admin/view/game_objects.html", errors=["%s" % error])
     else:
         self.render("admin/view/game_objects.html",
             errors=["Flag does not exist"]
         )
Пример #54
0
 def _mkflag(self, flag_type, is_file=False):
     name = self.get_argument('flag_name', '')
     if is_file:
         if not 'flag' in self.request.files:
             raise ValueError('No file in request')
         token = self.request.files['flag'][0]['body']
     else:
         token = self.get_argument('token', '')
     description = self.get_argument('description', '')
     reward = int(self.get_argument('reward', ''))
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is None:
         raise ValueError('Box does not exist')
     flag = Flag.create_flag(flag_type, box, name, token, description, reward)
     flag.capture_message = self.get_argument('capture_message', '')
     self.dbsession.add(flag)
     self.dbsession.commit()
     self.redirect('/admin/view/game_objects')
Пример #55
0
 def delete_source_code(self):
     ''' Delete source code file '''
     uuid = self.get_argument('box_uuid', '')
     box = Box.by_uuid(uuid)
     if box is not None and box.source_code is not None:
         source_code_uuid = box.source_code.uuid
         self.dbsession.delete(box.source_code)
         self.dbsession.commit()
         root = self.application.settings['source_code_market_dir']
         source_code_path = root + '/' + source_code_uuid
         logging.info("Delete souce code market file: %s (box: %s)" %
             (source_code_path, box.name,)
         )
         if os.path.exists(source_code_path):
             os.unlink(source_code_path)
         errors = None
     else:
         errors = ["Box does not exist, or contains no source code"]
     self.render('admin/upgrades/source_code_market.html', errors=errors)
Пример #56
0
 def _make_box(self, level_number):
     ''' Creates a box in the database '''
     corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
     level = GameLevel.by_number(level_number)
     box = Box(corporation_id=corp.id, game_level_id=level.id)
     box.name = self.get_argument('name', '')
     box.description = self.get_argument('description', '')
     box.autoformat = self.get_argument('autoformat', '') == 'true'
     box.difficulty = self.get_argument('difficulty', '')
     self.dbsession.add(box)
     self.dbsession.commit()
     if 'avatar' in self.request.files:
         box.avatar = self.request.files['avatar'][0]['body']
     return box
Пример #57
0
 def edit_ip(self):
     ''' Add ip addresses to a box (sorta edits the box object) '''
     try:
         box = Box.by_uuid(self.get_argument('box_uuid', ''))
         if box is None:
             raise ValidationError("Box does not exist")
         ip_addr = self.get_argument('ip_address', '')
         if IpAddress.by_address(ip_addr) is None:
             ip = IpAddress(box_id=box.id, address=ip_addr)
             if self.get_argument('visable', '').lower() != 'true':
                 ip.visable = False
             box.ip_addresses.append(ip)
             self.dbsession.add(ip)
             self.dbsession.add(box)
             self.dbsession.commit()
             self.redirect("/admin/view/game_objects#%s" % box.uuid)
         else:
             raise ValidationError("IP address is already in use")
     except ValidationError as error:
         self.render("admin/view/game_objects.html", errors=[str(error), ])
Пример #58
0
 def get(self, *args, **kwargs):
     '''
     Renders the box details page.
     '''
     uuid = self.get_argument('uuid', '')
     box = Box.by_uuid(uuid)
     if box is not None:
         user = self.get_current_user()
         if self.application.settings['game_started'] or user.is_admin():
             self.render('missions/box.html',
                         box=box,
                         user=user,
                         team=user.team,
                         errors=[],
                         success=[],
                         info=[])
         else:
             self.render('missions/status.html', errors=None, info=["The game has not started yet"])
     else:
         self.render('public/404.html')
Пример #59
0
 def create_box(self):
     ''' Create a box object '''
     try:
         lvl = self.get_argument('game_level', '')
         game_level = abs(int(lvl)) if lvl.isdigit() else 0
         corp_uuid = self.get_argument('corporation_uuid', '')
         if Box.by_name(self.get_argument('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:
             box = self._make_box(game_level)
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
     except ValueError as error:
         self.render('admin/create/box.html', errors=["%s" % error])
Пример #60
0
 def edit_ip(self):
     ''' Add ip addresses to a box (sorta edits the box object) '''
     errors = []
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is not None:
         addr = self.get_argument('ip_address', '')
         if IpAddress.by_address(addr) is None:
             try:
                 ip = IpAddress(box_id=box.id, address=addr)
                 box.ip_addresses.append(ip)
                 self.dbsession.add(ip)
                 self.dbsession.add(box)
                 self.dbsession.commit()
             except Exception as error:
                 errors.append(str(error))
         else:
             errors.append("IP address is already in use")
     else:
         errors.append("Box does not exist")
     self.render("admin/view/game_objects.html", errors=errors)