"""
CTF API Configuration File

Note this is just a python script. It does config things.
"""

import api
import datetime
import os

import api.app

""" FLASK """

api.app.session_cookie_domain = None # don't set this value if you want this to work on any domain
api.app.session_cookie_path = "/"
api.app.session_cookie_name = "flask"

# KEEP THIS SECRET
with open(".secret_key", "a+b") as f:
    secret_key = f.read()
    if not secret_key:
        secret_key = os.urandom(64)
        f.write(secret_key)
        f.flush()
    api.app.secret_key = secret_key
    f.close()

""" SECURITY """

api.common.allowed_protocols = ["https", "http"]
api.common.allowed_ports = [80, 8080]

""" MONGO """

api.common.mongo_db_name = "stuyctf"
api.common.mongo_addr = "127.0.0.1"
api.common.mongo_port = 27017

""" TESTING """

testing_mongo_db_name = "ctf_test"
testing_mongo_addr = "127.0.0.1"
testing_mongo_port = 27017

""" CTF SETTINGS """

enable_teachers = True

competition_name = "stuyCTF"
competition_urls = ["stuyctf.me"]

# Max users on any given team
api.team.max_team_users = 5

# Teams to display on scoreboard graph
api.stats.top_teams = 10

# start and end times!
class EST(datetime.tzinfo):
    def __init__(self, utc_offset):
        self.utc_offset = utc_offset

    def utcoffset(self, dt):
      return datetime.timedelta(hours=-self.utc_offset)

    def dst(self, dt):
        return datetime.timedelta(0)

start_time = datetime.datetime(2015, 4, 11, 10, 0, 0, tzinfo=EST(4))
end_time = datetime.datetime(2017, 4, 20, 22, 00, 00, tzinfo=EST(4))

# Root directory of all problem graders
api.problem.grader_base_path = "./graders"

""" SHELL SERVER """

enable_shell = False

shell_host = "127.0.0.1"
shell_username = "vagrant"
shell_password = "vagrant"
shell_port = 22

shell_user_prefixes  = list("abcdefghijklmnopqrstuvwxyz")
shell_password_length = 4
shell_free_acounts = 10
shell_max_accounts = 9999

shell_user_creation = "sudo useradd -m {username} -p {password}"

""" EMAIL (SMTP) """

api.utilities.enable_email = True
api.utilities.smtp_url = "smtp.sendgrid.net"
api.utilities.email_username = "dqiu"
api.utilities.email_password = "stuyctf"
api.utilities.from_addr = "contact@stuyctf.me"
api.utilities.from_name = "stuyCTF Team"

""" CAPTCHA """
enable_captcha = False
captcha_url = "https://www.google.com/recaptcha/api/siteverify"
reCAPTCHA_private_key = ""


""" AUTOGENERATED PROBLEMS """

api.autogen.seed = "0413688f8ef14e96b0afe25e2f662fef"

""" LOGGING """

# Will be emailed any severe internal exceptions!
# Requires email block to be setup.
api.logger.admin_emails = ["ben@example.com", "joe@example.com"]
api.logger.critical_error_timeout = 600
