Example #1
0
def challenge():
    """ 問題一覧 """
    ctf = CTF.GetInformation()
    message = ''
    status = 0
    # ログイン済み
    if not Authentication.CheckLogin():
        SiteManager.SetReferer('challenges')
        return SiteManager.JumpToPage('login')
    # 問題番号取得
    cid = flask.request.args.get('id', -1, type=int)
    # 問題取得
    chall = Challenge.GetChallenge(cid)
    if chall is None:
        return SiteManager.JumpToPage('challenges')
    # 開催中か
    running = DatetimeManager.CheckDuration()
    if running == 1:
        return SiteManager.JumpToPage('challenges')
    elif running == 2 and ctf['over-open'] is False:
        return SiteManager.JumpToPage('challenges')
    # フラグ投稿
    if flask.request.method == 'POST' and 'flag' in flask.request.form:
        flag = flask.request.form['flag'].strip()
        if flag == chall['flag']:
            message = 'The flag is correct.'
            status = 1
            if running == 0:
                # 加点
                if Challenge.IsSolved(cid, flask.session['teamname']):
                    message += ' (You have already solved this challenge.)'
                    status = 2
                else:
                    Challenge.AddPoint(cid, chall, flask.session['teamname'],
                                       flask.session['username'])
            else:
                # 終了表示
                message += " (The CTF is over.)"
                status = 2
        else:
            message = 'The flag is wrong.'
            if running == 2:
                # 終了表示
                message += " (The CTF is over.)"
                status = 2
    # サイトを表示する
    return flask.render_template('challenge.tmpl',
                                 ctf=ctf,
                                 chall=chall,
                                 status=status,
                                 message=message)
Example #2
0
def token():
    """ ログイン画面 """
    ctf = CTF.GetInformation()
    config = Configure.LoadConfig()
    # ログイン済み
    if not Authentication.CheckLogin():
        SiteManager.SetReferer('token')
        return SiteManager.JumpToPage('login')
    # トークンを取得
    path = config['koh']['path']
    tokens = Token.GetTokens(path)
    # サイトを表示する
    return flask.render_template(
        'token.html',
        ctf = ctf,
        tokens = tokens
    )
Example #3
0
def challenges():
    """ 問題一覧 """
    ctf = CTF.GetInformation()
    # ログイン済み
    if not Authentication.CheckLogin():
        SiteManager.SetReferer('challenges')
        return SiteManager.JumpToPage('login')
    # 問題一覧取得
    challs = Challenge.GetAllChallenges()
    solved = Challenge.GetSolved(flask.session['teamname'])
    # 開催中か
    running = DatetimeManager.CheckDuration()
    # サイトを表示する
    return flask.render_template('challenges.html',
                                 ctf=ctf,
                                 running=running,
                                 challs=challs,
                                 solved=solved)
Example #4
0
def scoreboard():
    """ スコアボード """
    ctf = CTF.GetInformation()
    # ログイン済み
    if not Authentication.CheckLogin():
        SiteManager.SetReferer('scoreboard')
        return SiteManager.JumpToPage('login')
    # ランキング取得
    ranking = Database.Query(
        "SELECT * FROM team ORDER BY score DESC, lastlog ASC"
    )
    # ログ取得
    log = Challenge.GetRecentLog()
    # サイトを表示する
    return flask.render_template(
        'scoreboard.html',
        ctf = ctf,
        ranking = ranking,
        log = log
    )
Example #5
0
def register():
    """ 登録画面 """
    ctf = CTF.GetInformation()
    error = {'username': '', 'password': '', 'teamcode': ''}
    # ログイン済み
    if Authentication.CheckLogin():
        return SiteManager.JumpToReferer()
    # 登録試行
    if flask.request.method == 'POST':
        form = flask.request.form
        if 'user' in form and 'username' in form and 'password' in form and 'password-confirm' in form and 'country' in form:
            # ユーザー登録
            if form['password'] == form['password-confirm']:
                if ctf['team']:
                    # チームに参加
                    if 'teamcode' in form and 'teamname' in form:
                        result = Authentication.TryRegisterUser(
                            form['username'], form['password'],
                            form['teamname'], form['teamcode'],
                            form['country'])
                        error[result[0]] = result[1]
                        if result[1] == '':
                            return SiteManager.JumpToReferer()
                else:
                    # 個人で参加
                    result = Authentication.TryRegisterUser(
                        form['username'], form['password'], None, None,
                        form['country'])
                    error[result[0]] = result[1]
                    if result[1] == '':
                        return SiteManager.JumpToReferer()
            else:
                # パスワードミス
                error['password'] = '******'
        elif 'team' in form and 'teamname' in form and 'teamcode' in form and ctf[
                'team']:
            # チーム登録
            result = Authentication.TryRegisterTeam(form['teamname'],
                                                    form['teamcode'])
    # サイトを表示する
    return flask.render_template('register.html', ctf=ctf, error=error)
Example #6
0
def login():
    """ ログイン画面 """
    ctf = CTF.GetInformation()
    error = {'password': ''}
    # ログイン済み
    if Authentication.CheckLogin():
        return SiteManager.JumpToReferer()
    # ログイン試行
    if flask.request.method == 'POST':
        if 'username' in flask.request.form and 'password' in flask.request.form:
            userinfo = Authentication.TryLogin(flask.request.form['username'],
                                               flask.request.form['password'])
            if userinfo:
                flask.session['login'] = True
                flask.session['teamname'] = userinfo['teamname']
                flask.session['username'] = userinfo['username']
                return SiteManager.JumpToReferer()
            else:
                error['password'] = "******"
    # サイトを表示する
    return flask.render_template('login.html', ctf=ctf, error=error)
Example #7
0
def index():
    ctf = CTF.GetInformation()
    duration = DatetimeManager.GetDurationSet()
    login = Authentication.CheckLogin()
    # サイトを表示する
    SiteManager.SetReferer('index')
    return flask.render_template(
        'index.html',
        ctf = ctf,
        duration = duration,
        login = login
    )
Example #8
0
def logout():
    flask.session['login'] = False
    return SiteManager.JumpToPage('index')