def get_challenges():
        if not is_admin():
            if not ctftime():
                if view_after_ctf():
                    pass
                else:
                    return []
        if challenges_visible() and (ctf_started() or is_admin()):
            chals = db.session.query(Challenges.id, Challenges.name,
                                     Challenges.category).filter(
                                         or_(Challenges.state != 'hidden',
                                             Challenges.state is None)).all()
            jchals = []
            for x in chals:
                jchals.append({
                    'id': x.id,
                    'name': x.name,
                    'category': x.category
                })

            # Sort into groups
            categories = set(map(lambda x: x['category'], jchals))
            jchals = [
                j for c in categories for j in jchals if j['category'] == c
            ]
            return jchals
        return []
예제 #2
0
파일: __init__.py 프로젝트: shareef12/CTFd
    def during_ctf_time_only_wrapper(*args, **kwargs):
        if ctftime() or current_user.is_admin():
            return f(*args, **kwargs)
        else:
            if ctf_ended():
                error = '{} has ended'.format(config.ctf_name())
                abort(403, description=error)

            if ctf_started() is False:
                error = '{} has not started yet'.format(config.ctf_name())
                abort(403, description=error)
예제 #3
0
def test_ctf_started():
    """
    Tests that the ctf_started function returns the correct value
    :return:
    """
    app = create_ctfd()
    with app.app_context():
        assert ctf_started() is True

        set_config("start", "1507089600"
                   )  # Wednesday, October 4, 2017 12:00:00 AM GMT-04:00 DST
        set_config(
            "end",
            "1507262400")  # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST

        with freeze_time("2017-10-3"):
            ctf_started()
            assert ctf_started() is False

        with freeze_time("2017-10-5"):
            assert ctf_started() is True

        with freeze_time("2017-10-7"):
            assert ctf_started() is True
    destroy_ctfd(app)
예제 #4
0
 def during_ctf_time_only_wrapper(*args, **kwargs):
     if ctftime() or current_user.is_admin():
         return f(*args, **kwargs)
     else:
         if ctf_ended():
             if view_after_ctf():
                 return f(*args, **kwargs)
             else:
                 error = '{} 已经结束'.format(config.ctf_name())
                 abort(403, description=error)
         if ctf_started() is False:
             error = '{} 尚未开始'.format(config.ctf_name())
             abort(403, description=error)
예제 #5
0
def listing():
    infos = get_infos()
    errors = get_errors()

    if ctf_started() is False:
        errors.append(f"{config.ctf_name()} has not started yet")

    if ctf_paused() is True:
        infos.append(f"{config.ctf_name()} is paused")

    if ctf_ended() is True:
        infos.append(f"{config.ctf_name()} has ended")

    return render_template("challenges.html", infos=infos, errors=errors)
예제 #6
0
def listing():
    infos = get_infos()
    errors = get_errors()

    if ctf_started() is False:
        errors.append(f"{config.ctf_name()} ещё не начался")

    if ctf_paused() is True:
        infos.append(f"{config.ctf_name()} приостановлен")

    if ctf_ended() is True:
        infos.append(f"{config.ctf_name()} закончился")

    return render_template("challenges.html", infos=infos, errors=errors)
예제 #7
0
파일: challenges.py 프로젝트: csnp/njit-ctf
def listing():
    if (Configs.challenge_visibility == ChallengeVisibilityTypes.PUBLIC
            and authed() is False):
        pass
    else:
        if is_teams_mode() and get_current_team() is None:
            return redirect(url_for("teams.private", next=request.full_path))

    infos = get_infos()
    errors = get_errors()

    if ctf_started() is False:
        errors.append(f"{Configs.ctf_name} has not started yet")

    if ctf_paused() is True:
        infos.append(f"{Configs.ctf_name} is paused")

    if ctf_ended() is True:
        infos.append(f"{Configs.ctf_name} has ended")

    return render_template("challenges.html", infos=infos, errors=errors)
예제 #8
0
def test_ctf_started():
    """
    Tests that the ctf_started function returns the correct value
    :return:
    """
    app = create_ctfd()
    with app.app_context():
        assert ctf_started() is True

        with ctftime.init():

            with ctftime.not_started():
                ctf_started()
                assert ctf_started() is False

            with ctftime.started():
                assert ctf_started() is True

            with ctftime.ended():
                assert ctf_started() is True
    destroy_ctfd(app)