示例#1
0
def admin_chals():
    if request.method == 'POST':
        chals = Challenges.query.add_columns(
            'id', 'type', 'name', 'value', 'description', 'category', 'hidden',
            'max_attempts').order_by(Challenges.value).all()

        json_data = {'game': []}
        for x in chals:
            type_class = CHALLENGE_CLASSES.get(x.type)
            type_name = type_class.name if type_class else None

            json_data['game'].append({
                'id': x.id,
                'name': x.name,
                'value': x.value,
                'description': x.description,
                'category': x.category,
                'hidden': x.hidden,
                'max_attempts': x.max_attempts,
                'type': x.type,
                'type_name': type_name,
                'type_data': {
                    'id': type_class.id,
                    'name': type_class.name,
                    'templates': type_class.templates,
                    'scripts': type_class.scripts,
                }
            })

        db.session.close()
        return jsonify(json_data)
    else:
        challenges = Challenges.query.all()
        return render_template('admin/challenges.html', challenges=challenges)
示例#2
0
def get_chal_class(class_id):
    """
    Utility function used to get the corresponding class from a class ID.

    :param class_id: String representing the class ID
    :return: Challenge class
    """
    cls = CHALLENGE_CLASSES.get(class_id)
    if cls is None:
        raise KeyError
    return cls
示例#3
0
    def get(self):
        response = {}

        for class_id in CHALLENGE_CLASSES:
            challenge_class = CHALLENGE_CLASSES.get(class_id)
            response[challenge_class.id] = {
                "id": challenge_class.id,
                "name": challenge_class.name,
                "templates": challenge_class.templates,
                "scripts": challenge_class.scripts,
            }
        return {"success": True, "data": response}
示例#4
0
    def get(self):
        response = {}

        for class_id in CHALLENGE_CLASSES:
            challenge_class = CHALLENGE_CLASSES.get(class_id)
            response[challenge_class.id] = {
                'id': challenge_class.id,
                'name': challenge_class.name,
                'templates': challenge_class.templates,
                'scripts': challenge_class.scripts,
            }
        return {'success': True, 'data': response}
示例#5
0
def admin_chal_types():
    data = {}
    for class_id in CHALLENGE_CLASSES:
        challenge_class = CHALLENGE_CLASSES.get(class_id)
        data[challenge_class.id] = {
            'id': challenge_class.id,
            'name': challenge_class.name,
            'templates': challenge_class.templates,
            'scripts': challenge_class.scripts,
        }

    return jsonify(data)
示例#6
0
文件: challenges.py 项目: satan1a/Oak
def admin_chals():
    if request.method == 'POST':
        chals = Challenges.query.order_by(Challenges.value).all()

        json_data = {'game': []}
        for chal in chals:
            tags = [
                tag.tag for tag in Tags.query.add_columns('tag').filter_by(
                    chal=chal.id).all()
            ]
            files = [
                str(f.location)
                for f in Files.query.filter_by(chal=chal.id).all()
            ]
            hints = []
            for hint in Hints.query.filter_by(chal=chal.id).all():
                hints.append({
                    'id': hint.id,
                    'cost': hint.cost,
                    'hint': hint.hint
                })

            type_class = CHALLENGE_CLASSES.get(chal.type)
            type_name = type_class.name if type_class else None

            json_data['game'].append({
                'id': chal.id,
                'name': chal.name,
                'value': chal.value,
                'description': chal.description,
                'category': chal.category,
                'files': files,
                'tags': tags,
                'hints': hints,
                'hidden': chal.hidden,
                'max_attempts': chal.max_attempts,
                'type': chal.type,
                'type_name': type_name,
                'type_data': {
                    'id': type_class.id,
                    'name': type_class.name,
                    'templates': type_class.templates,
                    'scripts': type_class.scripts,
                }
            })

        db.session.close()
        return jsonify(json_data)
    else:
        challenges = Challenges.query.all()
        return render_template('admin/challenges.html', challenges=challenges)
示例#7
0
def admin_chals(page):
    page = abs(int(page))
    results_per_page = 10
    page_start = results_per_page * (page - 1)
    page_end = results_per_page * (page - 1) + results_per_page

    if request.method == 'POST':
        chals = Challenges.query.order_by(Challenges.id.desc()).slice(page_start, page_end).all()
        json_data = {'game': []}
        for chal in chals:
            tags = [tag.tag for tag in Tags.query.add_columns('tag').filter_by(chal=chal.id).all()]
            files = [str(f.location) for f in Files.query.filter_by(chal=chal.id).all()]
            hints = []
            for hint in Hints.query.filter_by(chal=chal.id).all():
                hints.append({'id': hint.id, 'cost': hint.cost, 'hint': hint.hint})

            type_class = CHALLENGE_CLASSES.get(chal.type)
            type_name = type_class.name if type_class else None

            json_data['game'].append({
                'id': chal.id,
                'name': chal.name,
                'value': chal.value,
                'description': chal.description,
                'category': chal.category,
                'files': files,
                'tags': tags,
                'hints': hints,
                'hidden': chal.hidden,
                'max_attempts': chal.max_attempts,
                'type': chal.type,
                'type_name': type_name,
                'type_data': {
                    'id': type_class.id,
                    'name': type_class.name,
                    'templates': type_class.templates,
                    'scripts': type_class.scripts,
                }
            })

        db.session.close()
        return jsonify(json_data)
    else:
        count = Challenges.query.count()
        challenges = Challenges.query.order_by(Challenges.id.desc()).slice(page_start, page_end).all()
        pages = int(count / results_per_page) + (count % results_per_page > 0)
        return render_template('admin/challenges.html', challenges=challenges, challenge_pages=pages, curr_page=page)
def admin_chals():
    if request.method == 'POST':
        chals = Challenges.query.add_columns(
            'id', 'type', 'name', 'value', 'description', 'category', 'hidden',
            'max_attempts').order_by(Challenges.value).all()

        teams_with_points = db.session.query(Solves.teamid).join(Teams).filter(
            Teams.banned == False).group_by(Solves.teamid).count()

        json_data = {'game': []}
        for x in chals:
            solve_count = Solves.query.join(Teams,
                                            Solves.teamid == Teams.id).filter(
                                                Solves.chalid == x[1],
                                                Teams.banned == False).count()
            if teams_with_points > 0:
                percentage = (float(solve_count) / float(teams_with_points))
            else:
                percentage = 0.0

            type_class = CHALLENGE_CLASSES.get(x.type)
            type_name = type_class.name if type_class else None

            json_data['game'].append({
                'id': x.id,
                'name': x.name,
                'value': x.value,
                'description': x.description,
                'category': x.category,
                'hidden': x.hidden,
                'max_attempts': x.max_attempts,
                'type': x.type,
                'type_name': type_name,
                'percentage_solved': percentage,
                'type_data': {
                    'id': type_class.id,
                    'name': type_class.name,
                    'templates': type_class.templates,
                    'scripts': type_class.scripts,
                }
            })

        db.session.close()
        return jsonify(json_data)
    else:
        return render_template('admin/chals.html')
示例#9
0
def admin_chals():
    if request.method == 'POST':
        chals = Challenges.query.add_columns('id', 'type', 'name', 'value', 'description', 'category', 'hidden', 'max_attempts').order_by(Challenges.value).all()

        teams_with_points = db.session.query(Solves.teamid).join(Teams).filter(
            Teams.banned == False).group_by(Solves.teamid).count()

        json_data = {'game': []}
        for x in chals:
            solve_count = Solves.query.join(Teams, Solves.teamid == Teams.id).filter(
                Solves.chalid == x[1], Teams.banned == False).count()
            if teams_with_points > 0:
                percentage = (float(solve_count) / float(teams_with_points))
            else:
                percentage = 0.0

            type_class = CHALLENGE_CLASSES.get(x.type)
            type_name = type_class.name if type_class else None

            json_data['game'].append({
                'id': x.id,
                'name': x.name,
                'value': x.value,
                'description': x.description,
                'category': x.category,
                'hidden': x.hidden,
                'max_attempts': x.max_attempts,
                'type': x.type,
                'type_name': type_name,
                'percentage_solved': percentage
            })

        db.session.close()
        return jsonify(json_data)
    else:
        return render_template('admin/chals.html')
示例#10
0
def admin_chal_types():
    data = {}
    for class_id in CHALLENGE_CLASSES:
        data[class_id] = CHALLENGE_CLASSES.get(class_id).name

    return jsonify(data)
示例#11
0
def admin_chal_types():
    data = {}
    for class_id in CHALLENGE_CLASSES:
        data[class_id] = CHALLENGE_CLASSES.get(class_id).name

    return jsonify(data)