예제 #1
0
파일: user.py 프로젝트: Warchant/innoctf
"""

import bcrypt, re, urllib.parse, urllib.request, flask, json

import api

from api.common import check, validate, safe_fail
from api.common import WebException, InternalException
from api.annotations import log_action
from voluptuous import Required, Length, Schema

_check_email_format = lambda email: re.match(r".+@.+\..{2,}", email) is not None

user_schema = Schema({
    Required('email'): check(
        ("Email must be between 5 and 50 characters.", [str, Length(min=5, max=50)]),
        ("Your email does not look like an email address.", [_check_email_format])
    ),
    Required('firstname'): check(
        ("First Name must be between 1 and 50 characters.", [str, Length(min=1, max=50)])
    ),
    Required('lastname'): check(
        ("Last Name must be between 1 and 50 characters.", [str, Length(min=1, max=50)])
    ),
    Required('country'): check(
        ("Please select a country", [str, Length(min=2, max=2)])
    ),
    Required('username'): check(
        ("Usernames must be between 3 and 20 characters.", [str, Length(min=3, max=20)]),
        ("This username already exists.", [
            lambda name: safe_fail(get_user, name=name) is None])
    ),
예제 #2
0
import json

import api
import pymongo
import spur
from api.common import (check, InternalException, safe_fail, validate,
                        WebException)
from voluptuous import Length, Required, Schema

server_schema = Schema(
    {
        Required("name"):
        check(("Name must be a reasonable string.",
               [str, Length(min=1, max=128)])),
        Required("host"):
        check(
            ("Host must be a reasonable string", [str,
                                                  Length(min=1, max=128)])),
        Required("port"):
        check(("You have to supply a valid integer for your port.", [int]),
              ("Your port number must be in the valid range 1-65535.",
               [lambda x: 1 <= int(x) and int(x) <= 65535])),
        Required("username"):
        check(("Username must be a reasonable string",
               [str, Length(min=1, max=128)])),
        Required("password"):
        check(("Username must be a reasonable string",
               [str, Length(min=1, max=128)])),
        Required("protocol"):
        check(("Protocol must be either HTTP or HTTPS",
               [lambda x: x in ['HTTP', 'HTTPS']]))
예제 #3
0
    if len(whitelist) == 0:
        return True

    for email_domain in whitelist:
        if re.match(r".*?@{}$".format(email_domain), email) is not None:
            return True

    return False


user_schema = Schema(
    {
        Required('email'):
        check(
            ("Email must be between 5 and 50 characters.",
             [str, Length(min=5, max=50)]),
            ("Your email does not look like an email address.",
             [_check_email_format]),
        ),
        Required('firstname'):
        check(("First Name must be between 1 and 50 characters.",
               [str, Length(min=1, max=50)])),
        Required('lastname'):
        check(("Last Name must be between 1 and 50 characters.",
               [str, Length(min=1, max=50)])),
        Required('username'):
        check(("Usernames must be between 3 and 20 characters.",
               [str, Length(min=3, max=20)]),
              ("Usernames must be alphanumeric.", [_check_username]),
              ("This username already exists.",
               [lambda name: safe_fail(get_user, name=name) is None]),
              ("This username conflicts with an existing team.",
예제 #4
0
    if len(whitelist) == 0:
        return True

    for email_domain in whitelist:
        if re.match(r".*?@{}$".format(email_domain), email) is not None:
            return True

    return False


user_schema = Schema(
    {
        Required('email'):
        check(
            ("Email must be between 5 and 50 characters.",
             [str, Length(min=5, max=50)]),
            ("Your email does not look like an email address.",
             [_check_email_format]),
        ),
        Required('firstname'):
        check(("First Name must be between 1 and 50 characters.",
               [str, Length(min=1, max=50)])),
        Required('lastname'):
        check(("Last Name must be between 1 and 50 characters.",
               [str, Length(min=1, max=50)])),
        Required('country'):
        check(("Please select a country", [str, Length(min=2, max=2)])),
        Required('username'):
        check(
            ("Usernames must be between 3 and 20 characters.",
             [str, Length(min=3, max=20)]),
            ("Usernames must be alphanumeric.", [_check_username]),
예제 #5
0
import pymongo

import api

from datetime import datetime
from api.common import validate, check, safe_fail, InternalException, SevereInternalException, WebException
from voluptuous import Schema, Length, Required, Range
from bson import json_util
from os.path import join, isfile

from api.annotations import log_action

grader_base_path = "./graders"

submission_schema = Schema({
    Required("tid"): check(
        ("This does not look like a valid tid.", [str, Length(max=100)])),
    Required("pid"): check(
        ("This does not look like a valid pid.", [str, Length(max=100)])),
    Required("key"): check(
        ("This does not look like a valid key.", [str, Length(max=100)]))
})

problem_schema = Schema({
    Required("name"): check(
        ("The problem's display name must be a string.", [str])),
    Required("score"): check(
        ("Score must be a positive integer.", [int, Range(min=0)])),
    Required("category"): check(
        ("Category must be a string.", [str])),
    Required("grader"): check(
        ("The grader path must be a string.", [str])),
예제 #6
0
import api

from flask import request, session

from voluptuous import Schema, Required, Length, Range

from api.common import safe_fail, get_conn, WebSuccess, WebError, InternalException, check, validate, join_kwargs
from api.annotations import require_login

submission_schema = Schema({
    Required('question'): check(
        ('Question number must be positive', [int, Range(min=1)]),
    ),
    Required('answer'): check(
        ('Answer must be between 3 and 50 characters', [str, Length(min=3, max=50)]),
    ),
})

def has_solved(qid, uid=None):
    if not uid:
        if 'uid' not in session:
            raise InternalException('Need uid to see if solved')
        uid = session['uid']

    with get_conn() as cursor:
        query = 'SELECT 1 FROM `submissions` WHERE `correct` = 1 AND `qid` = %s AND `uid` = %s LIMIT 1;'

        cursor.execute(query, (qid, uid))

        return bool(len(cursor.fetchall()))
예제 #7
0
""" Module for handling groups of teams """

import api

from voluptuous import Required, Length, Schema
from api.common import check, validate, safe_fail, WebException, InternalException, SevereInternalException

from api.annotations import log_action

register_group_schema = Schema(
    {Required("group-name"): check(("Class name must be between 3 and 50 characters.", [str, Length(min=3, max=100)]))},
    extra=True,
)

join_group_schema = Schema(
    {Required("group-name"): check(("Class name must be between 3 and 50 characters.", [str, Length(min=3, max=100)]))},
    extra=True,
)

leave_group_schema = Schema(
    {Required("group-name"): check(("Class name must be between 3 and 50 characters.", [str, Length(min=3, max=100)]))},
    extra=True,
)

delete_group_schema = Schema(
    {Required("group-name"): check(("Class name must be between 3 and 50 characters.", [str, Length(min=3, max=100)]))},
    extra=True,
)


def is_owner_of_group(gid):
예제 #8
0
        settings = api.config.get_settings()
        whitelist = settings["email_filter"]

    #Nothing to check against!
    if len(whitelist) == 0:
        return True

    for email_domain in whitelist:
        if re.match(r".*?@{}$".format(email_domain), email) is not None:
            return True

    return False

user_schema = Schema({
    Required('email'): check(
        ("Email must be between 5 and 50 characters.", [str, Length(min=5, max=50)]),
        ("Your email does not look like an email address.", [_check_email_format]),
    ),
    Required('firstname'): check(
        ("First Name must be between 1 and 50 characters.", [str, Length(min=1, max=50)])
    ),
    Required('lastname'): check(
        ("Last Name must be between 1 and 50 characters.", [str, Length(min=1, max=50)])
    ),
    Required('country'): check(
        ("Please select a country", [str, Length(min=2, max=2)])
    ),
    Required('username'): check(
        ("Usernames must be between 3 and 20 characters.", [str, Length(min=3, max=20)]),
        ("Usernames must be alphanumeric.", [_check_username]),
        ("This username already exists.", [
            lambda name: safe_fail(get_user, name=name) is None]),
예제 #9
0
""" Module for handling problem feedback """

from datetime import datetime

import api
import pymongo
from api.annotations import log_action
from api.common import (check, InternalException, safe_fail,
                        SevereInternalException, validate, WebException)
from voluptuous import Length, Required, Schema

feedback_schema = Schema({
    Required("liked"):
    check(("liked must be a boolean", [lambda x: type(x) == bool])),
    "comment":
    check(("The comment must be no more than 500 characters",
           [str, Length(max=500)])),
    "timeSpent":
    check(("Time spend must be a number", [int])),
    "source":
    check(("The source must be no more than 500 characters",
           [str, Length(max=10)]))
})


def get_problem_feedback(pid=None, tid=None, uid=None):
    """
    Retrieve feedback for a given problem, team, or user

    Args:
        pid: the problem id
예제 #10
0
파일: group.py 프로젝트: tiffanyb/picoCTF
from flask import Flask, request, session, send_from_directory, render_template
from flask import Blueprint
import api, json

from api.common import WebSuccess, WebError
from api.annotations import api_wrapper, require_login, require_teacher, require_admin, check_csrf
from api.annotations import block_before_competition, block_after_competition
from api.annotations import log_action

from voluptuous import Required, Length, Schema
from api.common import check, validate, safe_fail, WebException

register_group_schema = Schema(
    {Required("group-name"): check(("Class name must be between 3 and 50 characters.", [str, Length(min=3, max=100)]))},
    extra=True,
)

join_group_schema = Schema(
    {
        Required("group-name"): check(
            ("Class name must be between 3 and 50 characters.", [str, Length(min=3, max=100)])
        ),
        Required("group-owner"): check(
            ("The team name must be between 3 and 40 characters.", [str, Length(min=3, max=40)])
        ),
    },
    extra=True,
)

leave_group_schema = Schema(
    {
예제 #11
0
파일: email.py 프로젝트: zaratec/picoCTF
from api.common import (
    check,
    InternalException,
    safe_fail,
    validate,
    WebException
)
from flask_mail import Message
from voluptuous import Length, Required, Schema

mail = None


password_reset_request_schema = Schema({
    Required('username'): check(
        ("Usernames must be between 3 and 20 characters.", [str, Length(min=3, max=20)]),
    )
})

password_reset_schema = Schema({
    Required("token"): check(
        ("This does not look like a valid token.", [str, Length(max=100)])
    ),
    Required('password'): check(
        ("Passwords must be between 3 and 20 characters.", [str, Length(min=3, max=20)])
    )
})

def reset_password(token_value, password, confirm_password):
    """
    Perform the password update operation.
예제 #12
0
import json

import api
import pymongo
import spur
from api.common import (check, InternalException, safe_fail, validate,
                        WebException)
from voluptuous import Length, Required, Schema

server_schema = Schema(
    {
        Required("name"):
        check(
            ("Name must be a reasonable string.", [str,
                                                   Length(min=1, max=128)])),
        Required("host"):
        check(
            ("Host must be a reasonable string", [str,
                                                  Length(min=1, max=128)])),
        Required("port"):
        check(("You have to supply a valid integer for your port.", [int]),
              ("Your port number must be in the valid range 1-65535.",
               [lambda x: 1 <= int(x) and int(x) <= 65535])),
        Required("username"):
        check(("Username must be a reasonable string",
               [str, Length(min=1, max=128)])),
        Required("password"):
        check(("Username must be a reasonable string",
               [str, Length(min=1, max=128)])),
        Required("protocol"):
        check(("Protocol must be either HTTP or HTTPS",
예제 #13
0
import api
import bcrypt
import pymysql

from voluptuous import Schema, Required, Length
from flask import request, session

from api.common import safe_fail, get_conn, InternalException, WebException, check, validate, join_kwargs

login_schema = Schema({
    Required('username'): check(
        ('Usernames must be between 3 and 50 characters', [str, Length(min=3, max=50)]),
    ),
    Required('password'): check(
        ('Passwords must be between 3 and 50 characters', [str, Length(min=3, max=50)]),
    ),
})

def is_logged_in():
    return 'uid' in session

def logout():
    session.permanent = False
    session.clear()

def get_user_scores(uid=None):
    if not uid:
        if 'uid' not in session:
            raise InternalException('Need uid to get scores')
        uid = session['uid']
예제 #14
0
""" Module for handling groups of teams """

import api

from api.annotations import log_action
from api.common import check, validate, safe_fail, InternalException

from voluptuous import Required, Length, Schema

group_settings_schema = Schema({
    Required("email_filter"): check(
        ("Email filter must be a list of emails.", [lambda emails: type(emails) == list])),
    Required("hidden"): check(
        ("Hidden property of a group is a boolean.", [lambda hidden: type(hidden) == bool]))})

def get_roles_in_group(gid, tid=None, uid=None):
    """
    Determine what role the team plays in a group.

    Args:
        gid: the group id
        tid: the team id
        uid: optional uid
    """

    group = get_group(gid=gid)

    if uid is not None:
        user = api.user.get_user(uid=uid)
        team = api.user.get_team(uid=user["uid"])
예제 #15
0
import json

import api
from api.annotations import (api_wrapper, block_after_competition,
                             block_before_competition, check_csrf, log_action,
                             require_admin, require_login, require_teacher)
from api.common import (check, safe_fail, validate, WebError, WebException,
                        WebSuccess)
from flask import (Blueprint, Flask, render_template, request,
                   send_from_directory, session)
from voluptuous import Length, Required, Schema

register_group_schema = Schema(
    {
        Required("group-name"):
        check(("Class name must be between 3 and 50 characters.",
               [str, Length(min=3, max=100)]), )
    },
    extra=True)

join_group_schema = Schema(
    {
        Required("group-name"):
        check(("Class name must be between 3 and 50 characters.",
               [str, Length(min=3, max=100)]), ),
        Required("group-owner"):
        check(("The team name must be between 3 and 40 characters.",
               [str, Length(min=3, max=40)]), )
    },
    extra=True)

leave_group_schema = Schema(
예제 #16
0
import api
import pymongo
import spur
import json

from api.common import validate, check, WebException, InternalException, safe_fail
from voluptuous import Schema, Required, Length

server_schema = Schema({
    Required("name"): check(
        ("Name must be a reasonable string.", [str, Length(min=1, max=128)])),
    Required("host"): check(
        ("Host must be a reasonable string", [str, Length(min=1, max=128)])),
    Required("port"): check(
        ("You have to supply a valid integer for your port.", [int]),
        ("Your port number must be in the valid range 1-65535.", [lambda x: 1 <= int(x) and int(x) <= 65535])),
    Required("username"): check(
        ("Username must be a reasonable string", [str, Length(min=1, max=128)])),
    Required("password"): check(
        ("Username must be a reasonable string", [str, Length(min=1, max=128)])),
    Required("protocol"): check(
        ("Protocol must be either HTTP or HTTPS", [lambda x: x in ['HTTP', 'HTTPS']]))
}, extra=True)

def get_connection(host, port, username, password):
    """
    Attempts to connect to the given server and
    returns a connection.
    """

    try:
예제 #17
0
from copy import copy, deepcopy
from datetime import datetime
from os.path import isfile, join
from random import randint

import api
import pymongo
from api.annotations import log_action
from api.common import (check, InternalException, safe_fail,
                        SevereInternalException, validate, WebException)
from bson import json_util
from voluptuous import Length, Range, Required, Schema, ALLOW_EXTRA

submission_schema = Schema({
    Required("tid"):
    check(("This does not look like a valid tid.", [str, Length(max=100)])),
    Required("pid"):
    check(("This does not look like a valid pid.", [str, Length(max=100)])),
    Required("key"):
    check(("This does not look like a valid key.", [str, Length(max=100)]))
})

problem_schema = Schema(
    {
        Required("name"):
        check(("The problem's display name must be a string.", [str])),
        Required("sanitized_name"):
        check(("The problems's sanitized name must be a string.", [str])),
        Required("score"):
        check(("Score must be a positive integer.", [int, Range(min=0)])),
        Required("author"):
예제 #18
0
import pymongo
import api

from datetime import datetime

from voluptuous import Schema, Required, Length
from api.common import validate, check, safe_fail, InternalException, SevereInternalException, WebException

from api.annotations import log_action

feedback_schema = Schema({
    Required("metrics"): check(
        ("metrics must include difficulty, enjoyment, and educational-value", [
            lambda metrics: "difficulty" in metrics,
            lambda metrics: "enjoyment" in metrics,
            lambda metrics: "educational-value" in metrics
        ])
    ),
    "comment": check(
        ("The comment must be no more than 500 characters", [str, Length(max=500)])
    ),
    "timeSpent": check(("Time spend must be a number", [int])),
    "source": check(
        ("The source must be no more than 10 characters", [str, Length(max=10)])
    )
})

def get_problem_feedback(pid=None, tid=None, uid=None):
    """
    Retrieve feedback for a given problem, team, or user
예제 #19
0
import imp
import pymongo

import api

from os.path import join
from datetime import datetime
from voluptuous import Schema, Required, Range
from api.common import check, InternalException, SevereInternalException, validate, safe_fail, WebException

from api.annotations import log_action

processor_base_path = "./processors"

achievement_schema = Schema({
    Required("name"): check(
        ("The achievement's display name must be a string.", [str])),
    Required("score"): check(
        ("Score must be a positive integer.", [int, Range(min=0)])),
    Required("event"): check(
        ("Type must be a string.", [str])),
    Required("description"): check(
        ("The description must be a string.", [str])),
    Required("processor"): check(
        ("The processor path must be a string.", [str])),
    Required("hidden"): check(
        ("An achievement's hidden state is either True or False.", [
            lambda hidden: type(hidden) == bool])),
    Required("image"): check(
        ("An achievement's image path must be a string.", [str])),
    Required("smallimage"): check(
        ("An achievement's smallimage path must be a string.", [str])),
예제 #20
0
import api
import pymongo
import spur
import json

from api.common import validate, check, WebException
from voluptuous import Schema, Required

server_schema = Schema({
    Required("host"): check(
        ("Host must be a string", [str])),
    Required("port"): check(
        ("Port must be a string", [str])),
    Required("username"): check(
        ("Username must be a string", [str])),
    Required("password"): check(
        ("Username must be a string", [str])),
    Required("protocol"): check(
        ("Protocol must be either HTTP or HTTPS", [lambda x: x in ['HTTP', 'HTTPS']]))
}, extra=True)

def get_connection(host, port, username, password):
    """
    Attempts to connect to the given server and
    returns a connection.
    """

    try:
        shell = spur.SshShell(
            hostname=host,
            username=username,
예제 #21
0
import pymongo

import api

from random import randint
from copy import copy, deepcopy
from datetime import datetime
from api.common import validate, check, safe_fail, InternalException, SevereInternalException, WebException
from voluptuous import Schema, Length, Required, Range
from bson import json_util
from os.path import join, isfile

from api.annotations import log_action

submission_schema = Schema({
    Required("tid"): check(
        ("This does not look like a valid tid.", [str, Length(max=100)])),
    Required("pid"): check(
        ("This does not look like a valid pid.", [str, Length(max=100)])),
    Required("key"): check(
        ("This does not look like a valid key.", [str, Length(max=100)]))
})

problem_schema = Schema({
    Required("name"): check(
        ("The problem's display name must be a string.", [str])),
    Required("sanitized_name"): check(
        ("The problems's sanitized name must be a string.", [str])),
    Required("score"): check(
        ("Score must be a positive integer.", [int, Range(min=0)])),
    Required("author"): check(
        ("Author must be a string.", [str])),
예제 #22
0
enable_email = False
use_sendgrid = True
smtp_url = ''
email_username = ''
email_password = ''
sendgrid_username = ''
sendgrid_password = ''
from_addr = ''
from_name = ''

sg = None

password_reset_request_schema = Schema({
    Required('username'):
    check(("Usernames must be between 3 and 20 characters.",
           [str, Length(min=3, max=20)]), )
})

password_reset_schema = Schema({
    Required("token"):
    check(("This does not look like a valid token.", [str,
                                                      Length(max=100)])),
    Required('password'):
    check(("Passwords must be between 3 and 20 characters.",
           [str, Length(min=3, max=20)]))
})


def setup_sendgrid():
    sg = sendgrid.SendGridClient(sendgrid_username,
                                 sendgrid_password,
예제 #23
0
import api

from api.common import safe_fail, WebException, InternalException, SevereInternalException

from api.annotations import log_action
from api.common import check, validate, safe_fail
from voluptuous import Required, Length, Schema

new_team_schema = Schema(
    {
        Required("team_name"):
        check(
            ("The team name must be between 3 and 40 characters.",
             [str, Length(min=3, max=40)]),
            ("A team with that name already exists.",
             [lambda name: safe_fail(api.team.get_team, name=name) is None]),
            ("A username with that name already exists.",
             [lambda name: safe_fail(api.user.get_user, name=name) is None]),
        ),
        Required("team_password"):
        check(("Passwords must be between 3 and 20 characters.",
               [str, Length(min=3, max=20)]))
    },
    extra=True)

join_team_schema = Schema(
    {
        Required("team_name"):
        check(("The team name must be between 3 and 40 characters.",
               [str, Length(min=3, max=40)]), ),
        Required("team_password"):
예제 #24
0
""" Module for handling problem feedback """

import pymongo
import api

from datetime import datetime

from voluptuous import Schema, Required, Length
from api.common import validate, check, safe_fail, InternalException, SevereInternalException, WebException

from api.annotations import log_action

feedback_schema = Schema({
    Required("liked"): check(
        ("liked must be a boolean", [lambda x: type(x) == bool])
    ),
    "comment": check(
        ("The comment must be no more than 500 characters", [str, Length(max=500)])
    ),
    "timeSpent": check(("Time spend must be a number", [int])),
    "source": check(
        ("The source must be no more than 500 characters", [str, Length(max=10)])
    )
})

def get_problem_feedback(pid=None, tid=None, uid=None):
    """
    Retrieve feedback for a given problem, team, or user

    Args:
        pid: the problem id
예제 #25
0
""" Module for handling groups of teams """

import api

from voluptuous import Required, Length, Schema
from api.common import check, validate, safe_fail, WebException, InternalException, SevereInternalException

from api.annotations import log_action

register_group_schema = Schema(
    {
        Required("group-name"):
        check(("Class name must be between 3 and 50 characters.",
               [str, Length(min=3, max=100)]))
    },
    extra=True)

join_group_schema = Schema(
    {
        Required("group-name"):
        check(("Class name must be between 3 and 50 characters.",
               [str, Length(min=3, max=100)]), )
    },
    extra=True)

leave_group_schema = Schema(
    {
        Required("group-name"):
        check(("Class name must be between 3 and 50 characters.",
               [str, Length(min=3, max=100)]), )
    },
예제 #26
0
""" Module for email related functionality. """

from datetime import datetime

import api
from api.common import (check, InternalException, safe_fail, validate,
                        WebException)
from flask_mail import Message
from voluptuous import Length, Required, Schema

mail = None

password_reset_request_schema = Schema({
    Required('username'):
    check(("Usernames must be between 3 and 20 characters.",
           [str, Length(min=3, max=20)]),)
})

password_reset_schema = Schema({
    Required("token"):
    check(("This does not look like a valid token.", [str, Length(max=100)])),
    Required('password'):
    check(("Passwords must be between 3 and 20 characters.",
           [str, Length(min=3, max=20)]))
})


def reset_password(token_value, password, confirm_password):
    """
    Perform the password update operation.
예제 #27
0
import api

from api.common import check, validate, safe_fail, WebException
from voluptuous import Required, Length, Schema
from datetime import datetime

enable_email = False
smtp_url = ''
email_username = ''
email_password = ''
from_addr = ''
from_name = ''

password_reset_request_schema = Schema({
    Required('username'): check(
        ("Usernames must be between 3 and 20 characters.", [str, Length(min=3, max=20)]),
    )
})

password_reset_schema = Schema({
    Required("token"): check(
        ("This does not look like a valid token.", [str, Length(max=100)])
    ),
    Required('password'): check(
        ("Passwords must be between 3 and 20 characters.", [str, Length(min=3, max=20)])
    )
})

def send_email(recipient, subject, body):
    """
    Send an email with the given body text and subject to the given recipient.
예제 #28
0
import imp
import pymongo

import api

from datetime import datetime
from api.common import validate, check, safe_fail, InternalException, SevereInternalException, WebException
from voluptuous import Schema, Length, Required, Range
from bson import json_util
from os.path import join, isfile

from api.annotations import log_action

writeup_schema = Schema({
    Required("wid"): check(
        ("This does not look like a valid wid.", [str, Length(max=100)])),
    Required("uid"): check(
        ("This does not look like a valid uid.", [str, Length(max=100)])),
    Required("tid"): check(
        ("This does not look like a valid tid.", [str, Length(max=100)])),
    Required("pid"): check(
        ("This does not look like a valid pid.", [str, Length(max=100)])),
    Required("title"): check(
        ("The writeup title must be a string.", [str])),
    Required("url"): check(
        ("The writeup URL must be a string.", [str])),
})

vote_schema = Schema({
    Required("wid"): check(
        ("This does not look like a valid wid.", [str, Length(max=100)])),
예제 #29
0
"""

import bcrypt, re, urllib, flask

import api

from api.common import check, validate, safe_fail
from api.common import WebException, InternalException
from api.annotations import log_action
from voluptuous import Required, Length, Schema

_check_email_format = lambda email: re.match(r"[A-Za-z0-9\._%+-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,4}", email) is not None

user_schema = Schema({
    Required('email'): check(
        ("Email must be between 5 and 50 characters.", [str, Length(min=5, max=50)]),
        ("Your email does not look like an email address.", [_check_email_format])
    ),
    Required('firstname'): check(
        ("First Name must be between 1 and 50 characters.", [str, Length(min=1, max=50)])
    ),
    Required('lastname'): check(
        ("Last Name must be between 1 and 50 characters.", [str, Length(min=1, max=50)])
    ),
    Required('country'): check(
        ("Please select a country", [str, Length(min=2, max=2)])
    ),
    Required('username'): check(
        ("Usernames must be between 3 and 20 characters.", [str, Length(min=3, max=20)]),
        ("This username already exists.", [
            lambda name: safe_fail(get_user, name=name) is None])
    ),
예제 #30
0
"""

import api

from api.common import safe_fail, WebException, InternalException, SevereInternalException

from api.annotations import log_action
from api.common import check, validate, safe_fail
from voluptuous import Required, Length, Schema

new_team_schema = Schema(
    {
        Required("team_name"): check(
            ("The team name must be between 3 and 40 characters.", [str, Length(min=3, max=40)]),
            ("A team with that name already exists.", [lambda name: safe_fail(api.team.get_team, name=name) is None]),
            (
                "A username with that name already exists.",
                [lambda name: safe_fail(api.user.get_user, name=name) is None],
            ),
        ),
        Required("team_password"): check(
            ("Passwords must be between 3 and 20 characters.", [str, Length(min=3, max=20)])
        ),
    },
    extra=True,
)

join_team_schema = Schema(
    {
        Required("team_name"): check(
            ("The team name must be between 3 and 40 characters.", [str, Length(min=3, max=40)])
        ),
예제 #31
0
import pymongo

import api

from datetime import datetime
from api.common import validate, check, safe_fail, InternalException, SevereInternalException, WebException
from voluptuous import Schema, Length, Required, Range
from bson import json_util
from os.path import join, isfile

from api.annotations import log_action

grader_base_path = "./graders"

submission_schema = Schema({
    Required("tid"): check(
        ("This does not look like a valid tid.", [str, Length(max=100)])),
    Required("pid"): check(
        ("This does not look like a valid pid.", [str, Length(max=100)])),
    Required("key"): check(
        ("This does not look like a valid key.", [str, Length(max=100)]))
})

problem_schema = Schema({
    Required("name"): check(
        ("The problem's display name must be a string.", [str])),
    Required("score"): check(
        ("Score must be a positive integer.", [int, Range(min=0)])),
    Required("category"): check(
        ("Category must be a string.", [str])),
    Required("grader"): check(
        ("The grader path must be a string.", [str])),
import pymongo
import api

from datetime import datetime

from voluptuous import Schema, Required, Length
from api.common import validate, check, safe_fail, InternalException, SevereInternalException, WebException

from api.annotations import log_action

feedback_schema = Schema({
    Required("metrics"): check(
        ("metrics must include difficulty, enjoyment, and educational-value", [
            lambda metrics: "difficulty" in metrics,
            lambda metrics: "enjoyment" in metrics,
            lambda metrics: "educational-value" in metrics
        ])
    ),
    "comment": check(
        ("The comment must be no more than 500 characters", [str, Length(max=500)])
    ),
    "timeSpent": check(("Time spend must be a number", [int])),
    "source": check(
        ("The source must be no more than 500 characters", [str, Length(max=10)])
    )
})

def get_problem_feedback(pid=None, tid=None, uid=None):
    """
    Retrieve feedback for a given problem, team, or user
예제 #33
0
""" Module for handling groups of teams """

import api
from api.annotations import log_action
from api.common import check, InternalException, safe_fail, validate
from voluptuous import Length, Required, Schema

group_settings_schema = Schema({
    Required("email_filter"):
    check(("Email filter must be a list of emails.",
           [lambda emails: type(emails) == list])),
    Required("hidden"):
    check(("Hidden property of a group is a boolean.",
           [lambda hidden: type(hidden) == bool]))
})


def get_roles_in_group(gid, tid=None, uid=None):
    """
    Determine what role the team plays in a group.

    Args:
        gid: the group id
        tid: the team id
        uid: optional uid
    """

    group = get_group(gid=gid)

    if uid is not None:
        user = api.user.get_user(uid=uid)
예제 #34
0
""" Module for handling groups of teams """

import api
from api.annotations import log_action
from api.common import check, InternalException, safe_fail, validate
from voluptuous import Length, Required, Schema

group_settings_schema = Schema({
    Required("email_filter"):
    check(("Email filter must be a list of emails.",
           [lambda emails: type(emails) == list])),
    Required("hidden"):
    check(("Hidden property of a group is a boolean.",
           [lambda hidden: type(hidden) == bool]))
})


def get_roles_in_group(gid, tid=None, uid=None):
    """
    Determine what role the team plays in a group.

    Args:
        gid: the group id
        tid: the team id
        uid: optional uid
    """

    group = get_group(gid=gid)

    if uid is not None:
        user = api.user.get_user(uid=uid)
예제 #35
0
import json

import api
from api.annotations import (api_wrapper, block_after_competition,
                             block_before_competition, check_csrf, log_action,
                             require_admin, require_login, require_teacher)
from api.common import (check, safe_fail, validate, WebError, WebException,
                        WebSuccess)
from flask import (Blueprint, Flask, render_template, request,
                   send_from_directory, session)
from voluptuous import Length, Required, Schema

register_group_schema = Schema(
    {
        Required("group-name"):
        check(("Classroom name must be between 3 and 50 characters.",
               [str, Length(min=3, max=100)]),)
    },
    extra=True)

join_group_schema = Schema(
    {
        Required("group-name"):
        check(("Classroom name must be between 3 and 50 characters.",
               [str, Length(min=3, max=100)]),),
        Required("group-owner"):
        check(("The teacher name must be between 3 and 40 characters.",
               [str, Length(min=3, max=40)]),)
    },
    extra=True)

leave_group_schema = Schema(
예제 #36
0
파일: team.py 프로젝트: royragsdale/picoCTF
API functions relating to team management.
"""

import api
from api.annotations import log_action
from api.common import (check, InternalException, safe_fail,
                        SevereInternalException, validate, WebException)
from voluptuous import Length, Required, Schema

new_team_schema = Schema(
    {
        Required("team_name"):
        check(
            ("The team name must be between 3 and 40 characters.",
             [str, Length(min=3, max=40)]),
            ("This team name conflicts with an existing user name.",
             [lambda name: safe_fail(api.user.get_user, name=name) is None]),
            ("A team with that name already exists.",
             [lambda name: safe_fail(api.team.get_team, name=name) is None]),
        ),
        Required("team_password"):
        check(("Passwords must be between 3 and 20 characters.",
               [str, Length(min=3, max=20)]))
    },
    extra=True)

join_team_schema = Schema(
    {
        Required("team_name"):
        check(
            ("The team name must be between 3 and 40 characters.",
               [str, Length(min=3, max=40)]),