From 33e453d7679ed3b35dafb6e57d3f1d988f661b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:04:00 +0000 Subject: [PATCH 01/24] fixed blegh --- templates/register.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/register.html b/templates/register.html index 778cd50..bdf1900 100644 --- a/templates/register.html +++ b/templates/register.html @@ -65,7 +65,7 @@
- +
  • Create new Team
  • @@ -110,13 +110,13 @@ $(function(){ $("#create-team #team_name").prop('required', true); $("#create-team #team_affiliation").prop('required', true); $("#join-team #team_key").prop('required', false); - $("#join-team #join_team").attr('val', "0"); + $("#join_team-input").attr('val', "0"); }); $("#join-team-btn").on('click', function(){ $("#create-team #team_name").prop('required', false); $("#create-team #team_affiliation").prop('required', false); $("#join-team #team_key").prop('required', true); - $("#join-team #join_team").attr('val', "1"); + $("#join_team-input").attr('val', "1"); }); $("#country").change(function(e) { From 29de7d1a21805fee9b344ace6377a979bbad1380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:11:09 +0000 Subject: [PATCH 02/24] uuuuuuuuuuuuuuuuuuuugh --- app.py | 5 ++++- templates/register.html | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 9a62232..8625439 100644 --- a/app.py +++ b/app.py @@ -183,8 +183,11 @@ def register(): team = Team.get(Team.key == team_key) except Team.DoesNotExist: flash("Couldn't find this team, check your team key.") - return rener_template("register.html") + return render_template("register.html") else: + if not team_name or len(team_name) > 100: + flash("Missing team name") + return render_template("register.html") if not team_affiliation or len(team_affiliation) > 100: team_affiliation = "No affiliation" try: diff --git a/templates/register.html b/templates/register.html index bdf1900..7b39cc2 100644 --- a/templates/register.html +++ b/templates/register.html @@ -110,13 +110,13 @@ $(function(){ $("#create-team #team_name").prop('required', true); $("#create-team #team_affiliation").prop('required', true); $("#join-team #team_key").prop('required', false); - $("#join_team-input").attr('val', "0"); + $("#join_team-input").val("0"); }); $("#join-team-btn").on('click', function(){ $("#create-team #team_name").prop('required', false); $("#create-team #team_affiliation").prop('required', false); $("#join-team #team_key").prop('required', true); - $("#join_team-input").attr('val', "1"); + $("#join_team-input").val("1"); }); $("#country").change(function(e) { From d2fb5d84f6f46aec02cf38e7b83cb0043fd5161f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:16:47 +0000 Subject: [PATCH 03/24] fixed login --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 8625439..97602bc 100644 --- a/app.py +++ b/app.py @@ -221,7 +221,7 @@ def register(): def logout(): session.pop("user_id") flash("You've successfully logged out.") - return redirect(url_for('root')) + return redirect(url_for('login')) # Things that require a team From d1c0ebb244d69b9e02845613a60431f3a3285463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:21:50 +0000 Subject: [PATCH 04/24] added members to team page --- templates/team.html | 74 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/templates/team.html b/templates/team.html index 8197416..e8fd64f 100644 --- a/templates/team.html +++ b/templates/team.html @@ -80,6 +80,80 @@
+ +
+
+
Score Calculation
+
+ {% if team_solves.count() %} +
Solved problems
+
+
+ + + + + + {% for solve in team_solves %} + + + + + + {% endfor %} + +
NameCategoryTimeValue
{{ solve.challenge.name }}{{ solve.challenge.category }}{{ solve.time }}{{ solve.challenge.points }}
+
+
+ {% else %} +

No problems have been solved.

+ {% endif %} + {% if team_adjustments.count() %} +
Score adjustments
+
+
+ + + + + + {% for adj in team_adjustments %} + + + + + {% endfor %} + +
ReasonValue
{{ adj.reason }}{{ adj.value }}
+
+
+ {% else %} +

No score adjustments have been made.

+ {% endif %} +
+
+
+
+
+
Members
+
+
+
+ + + + + + {% for member in team.members %} + + {% endfor %} + +
Username
{{ member.username }}
+
+
+
+
+
Score Calculation
From a340cc30bb7c5d66b866de68a1f704f3f0e9e115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:22:59 +0000 Subject: [PATCH 05/24] whoops --- templates/team.html | 54 ++------------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/templates/team.html b/templates/team.html index e8fd64f..f1acc16 100644 --- a/templates/team.html +++ b/templates/team.html @@ -81,58 +81,6 @@
-
-
-
Score Calculation
-
- {% if team_solves.count() %} -
Solved problems
-
-
- - - - - - {% for solve in team_solves %} - - - - - - {% endfor %} - -
NameCategoryTimeValue
{{ solve.challenge.name }}{{ solve.challenge.category }}{{ solve.time }}{{ solve.challenge.points }}
-
-
- {% else %} -

No problems have been solved.

- {% endif %} - {% if team_adjustments.count() %} -
Score adjustments
-
-
- - - - - - {% for adj in team_adjustments %} - - - - - {% endfor %} - -
ReasonValue
{{ adj.reason }}{{ adj.value }}
-
-
- {% else %} -

No score adjustments have been made.

- {% endif %} -
-
-
Members
@@ -145,7 +93,9 @@ {% for member in team.members %} + {{ member.username }} + {% endfor %} From 2ce77b953a4acce7e560b83d8afb2027e0e837e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:24:35 +0000 Subject: [PATCH 06/24] add eligibility status --- templates/team.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/templates/team.html b/templates/team.html index f1acc16..ff7b90a 100644 --- a/templates/team.html +++ b/templates/team.html @@ -89,12 +89,16 @@
- + + + + {% for member in team.members %} + {% endfor %} From 0af15dff4b541e22d7d5772e3f7dcfec27365157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:25:13 +0000 Subject: [PATCH 07/24] wrong text --- templates/team.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/team.html b/templates/team.html index ff7b90a..5cb4bcc 100644 --- a/templates/team.html +++ b/templates/team.html @@ -98,7 +98,7 @@ {% for member in team.members %} - + {% endfor %} From 66c93f1b42fe8b22aeb7db5fd2f36ba97b9427e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Thu, 14 Jul 2016 19:28:14 +0000 Subject: [PATCH 08/24] fixed team naming thing --- app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 97602bc..eea39c5 100644 --- a/app.py +++ b/app.py @@ -185,7 +185,7 @@ def register(): flash("Couldn't find this team, check your team key.") return render_template("register.html") else: - if not team_name or len(team_name) > 100: + if not team_name or len(team_name) > 50: flash("Missing team name") return render_template("register.html") if not team_affiliation or len(team_affiliation) > 100: @@ -405,7 +405,7 @@ def team_dashboard(): if not affiliation or len(affiliation) > 100: affiliation = "No affiliation" - if g.team_name != team_name: + if g.team.name != team_name: try: team = Team.get(Team.name == team_name) flash("This team name is already in use!") From 76cfcbec49857ae01abb060285efb9cfcf547143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 20:37:03 +0000 Subject: [PATCH 09/24] added production settings --- app.py | 7 +++++-- config.py | 16 ++++++++++++++++ database.py | 7 ++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index eea39c5..0da1981 100644 --- a/app.py +++ b/app.py @@ -17,7 +17,10 @@ import socket app.secret_key = config.secret.key import logging -logging.basicConfig(level=logging.DEBUG) +if config.production: + logging.basicConfig(level=logging.INFO) +else: + logging.basicConfig(level=logging.DEBUG) @app.before_request def make_info_available(): @@ -561,7 +564,7 @@ def debug_app(): def before_request(): g.connected = True db.connect() - g.redis = redis.StrictRedis() + g.redis = redis.StrictRedis(host=config.redis.host, port=config.redis.port, db=config.redis.db) @app.teardown_request def teardown_request(exc): diff --git a/config.py b/config.py index 2f355ed..bc51309 100644 --- a/config.py +++ b/config.py @@ -1,6 +1,8 @@ import os from datetime import datetime +production = os.getenv("PRODUCTION", None) is not None + ctf_name = "IceCTF" #IRC Channel ctf_chat_channel = "#IceCTF" @@ -49,3 +51,17 @@ from collections import namedtuple with open("secrets") as f: _secret = yaml.load(f) secret = namedtuple('SecretsDict', _secret.keys())(**_secret) + +_redis = { + 'host': 'localhost', + 'port': 6379, + 'db': 0 +} + +if production: + with open("database") as f: + _database = yaml.load(f) + database = namedtuple('DatabaseDict', _database.keys())(**_database) + _redis['db'] = 1 + +redis = namedtuple('RedisDict', _redis.keys())(**_redis) diff --git a/database.py b/database.py index a5948b6..387e8d9 100644 --- a/database.py +++ b/database.py @@ -1,6 +1,11 @@ from peewee import * import bcrypt -db = SqliteDatabase("dev.db") +import config +if config.production: + db = PostgresqlDatabase(config.database.database, user=config.database.user, password=config.database.password) +else: + db = SqliteDatabase("dev.db") + class BaseModel(Model): class Meta: From 8385bd3d0c11ff2cad7b7a9ca898a127262a1096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 21:14:53 +0000 Subject: [PATCH 10/24] fixed redirect --- app.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app.py b/app.py index 0da1981..e438d2f 100644 --- a/app.py +++ b/app.py @@ -33,6 +33,8 @@ def make_info_available(): except User.DoesNotExist: session.pop("user_id") return render_template("login.html") + else: + g.logged_in = False @app.context_processor def scoreboard_variables(): @@ -59,6 +61,8 @@ app.register_blueprint(admin.admin) @app.route('/') def root(): + if g.logged_in: + return redirect(url_for('team_dashboard')) return redirect(url_for('register')) @app.route('/chat/') From 2dbe921da91d7f7eca03ebe5c21225d1229af444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 21:18:14 +0000 Subject: [PATCH 11/24] whoops --- app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.py b/app.py index e438d2f..079b960 100644 --- a/app.py +++ b/app.py @@ -30,7 +30,9 @@ def make_info_available(): g.user_restricts = g.user.restricts.split(",") g.team = g.user.team g.team_restricts = g.team.restricts.split(",") + g.logged_in = True except User.DoesNotExist: + g.logged_in = False session.pop("user_id") return render_template("login.html") else: From b284dbb5cb0f02e172b9a3f99b5097322affb5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 21:23:19 +0000 Subject: [PATCH 12/24] in case of errors --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 079b960..8cc940f 100644 --- a/app.py +++ b/app.py @@ -25,12 +25,12 @@ else: @app.before_request def make_info_available(): if "user_id" in session: + g.logged_in = True try: g.user = User.get(User.id == session["user_id"]) g.user_restricts = g.user.restricts.split(",") g.team = g.user.team g.team_restricts = g.team.restricts.split(",") - g.logged_in = True except User.DoesNotExist: g.logged_in = False session.pop("user_id") From f16b41f808fd3694f1837bbad273027ebc051061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 21:43:17 +0000 Subject: [PATCH 13/24] database to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3bbc5a7..8ea2130 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ dump.rdb /problems __pycache__ /secrets +/database venv From 4d840a055b195510712b72cdff7ea2160b850a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 21:55:09 +0000 Subject: [PATCH 14/24] moved connected --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 8cc940f..de7231f 100644 --- a/app.py +++ b/app.py @@ -568,9 +568,9 @@ def debug_app(): @app.before_request def before_request(): - g.connected = True db.connect() g.redis = redis.StrictRedis(host=config.redis.host, port=config.redis.port, db=config.redis.db) + g.connected = True @app.teardown_request def teardown_request(exc): From 4f606e4608c8f5dd2d1169e681e0d094692271d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 21:55:29 +0000 Subject: [PATCH 15/24] psycopg2 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 7b904ef..7f0d385 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ redis pyyaml oath pycountry +psycopg2 From 132c8f886aa3398a817435e1e43b5453106e9de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 22:07:02 +0000 Subject: [PATCH 16/24] running times --- config.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.py b/config.py index bc51309..13f56f8 100644 --- a/config.py +++ b/config.py @@ -34,6 +34,10 @@ custom_stylesheet = "css/main.css" competition_begin = datetime(1970, 1, 1, 0, 0) competition_end = datetime(2018, 1, 1, 0, 0) +if production: + competition_begin = datetime(2016, 8, 12, hour=16, minute=0, second=0) + competition_end = datetime(2016, 8, 26, hour=16, minute=0, second=0) + # Are you using a resume server? resumes = False # If yes, where's it hosted? Otherwise, just put None. From f79234b974160cb6274f9970c31291f74d4e0933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 15 Jul 2016 22:09:56 +0000 Subject: [PATCH 17/24] moved status --- templates/base.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/base.html b/templates/base.html index 73338fe..5eca4f1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -63,6 +63,10 @@
chat
Chat
+
  • +
    build
    +
    Status
    +
  • {% endif %} {% if logged_in %}
  • @@ -70,10 +74,7 @@
    Tickets
  • {% endif %} -
  • -
    build
    -
    Status
    -
  • +
    {% if logged_in %} From 8ee487e0abbbe9fbf8105ccbc5839662f1c6a1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Sat, 16 Jul 2016 14:41:24 +0000 Subject: [PATCH 18/24] team must exist before user --- ctftool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctftool b/ctftool index fd1ba18..4876e9b 100755 --- a/ctftool +++ b/ctftool @@ -17,7 +17,7 @@ import yaml import argparse import logging -tables = [User, Team, UserAccess, Challenge, ChallengeSolve, ChallengeFailure, NewsItem, TroubleTicket, TicketComment, Notification, ScoreAdjustment, AdminUser] +tables = [Team, User, UserAccess, Challenge, ChallengeSolve, ChallengeFailure, NewsItem, TroubleTicket, TicketComment, Notification, ScoreAdjustment, AdminUser] def create_tables(args): check = True From cc85afb1e4901b1e11d754bea67f3a1776020df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Sat, 16 Jul 2016 14:59:46 +0000 Subject: [PATCH 19/24] change popup text --- templates/user.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/user.html b/templates/user.html index 5f77620..dd8d055 100644 --- a/templates/user.html +++ b/templates/user.html @@ -124,7 +124,7 @@

    First off, please check the email you signed up with. You must confirm your account to solve problems. If needed, you can change your Email or resend confirmation on this page.

    -

    We recommend you read the Rules and FAQ. Then, do some Practice to warm up for the competition, join the Chat to meet your fellow competitors and ask questions. The competition will begin soon enough, but in the meanwhile, explore the site!

    +

    The competition hasn't started yet, but while you wait, we recommend you read the Rules and FAQ. Then, do some practice to warm up for the competition, join the Chat to meet your fellow competitors and ask questions. The competition will begin soon enough, but in the meanwhile, explore the site!

    {% endblock %} From 82d7168aaac64e3260251d4e2f6e8dceaf5f9c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Sat, 16 Jul 2016 16:09:05 +0000 Subject: [PATCH 23/24] added google analytics and changed link --- templates/base.html | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/templates/base.html b/templates/base.html index f29f7bb..49d486b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -65,7 +65,7 @@ {% endif %} {% if logged_in %} -
  • +
  • chat
    Chat
  • @@ -152,5 +152,17 @@ {% block postscript %} {% endblock %} + {% if config.production %} + + {% endif %} From e8ecccc7d02e171ffab1fa45c89d948d5bca8b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Sat, 16 Jul 2016 17:04:12 +0000 Subject: [PATCH 24/24] y u do this --- utils/email.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/email.py b/utils/email.py index ac9151d..ee62672 100644 --- a/utils/email.py +++ b/utils/email.py @@ -9,7 +9,7 @@ def send_confirmation_email(team_email, confirmation_key): send_email(team_email, "Welcome to {}!".format(config.ctf_name), """Hello, and thanks for registering for {}! Before you can start solving problems, you must confirm your email by clicking the link below: -http://098f6bcd46.icec.tf/confirm_email/{} +http://play.icec.tf/confirm_email/{} Once you've done that, your account will be enabled, and you will be able to access the challenges. If you have any trouble, feel free to contact an organizer! @@ -23,7 +23,7 @@ def is_valid_email(email): def send_password_reset_email(team_email, password_reset_token): send_email(team_email, "{} Password Reset".format(config.ctf_name), """To reset your password click the link below and enter a new password. This link will expire in 24 hours. -http://098f6bcd46.icec.tf/reset_password/{} +http://play.icec.tf/reset_password/{} If you didn't request this email, then you can disregard it. """.format(password_reset_token))
    Username
    UsernameEligibility Status
    {{ member.username }}{{ member.eligible() }}
    {{ member.username }}{{ member.eligible() }}{{ "Eligible" if member.eligible() else "Ineligibile" }}