Skip to content

Commit c8031b3

Browse files
authoredNov 20, 2018
2.0.0 (CTFd#741)
* Fix user and admin panel user/team graphs * Closes CTFd#682 * Unify login and logout under specific functions * Closes CTFd#659 * Rename Challenges.hidden to Challenges.state * Start to clean up API and front end integration starting with profile updating * Slightly cleaner code * Clean API to respond with success, data, and status codes * Simpler COUNTRIES_LIST and update profile to use COUNTRIES_LIST * Lookup country code in users page. Update front end calls to get API data properly * Fix some API endpoints and fix JS to process new responses * Update config.py to support new values * Closes CTFd#635 * Update some code to handle user types, add email domain whitelisting * Write a logging wrapper * Use logging wrapper for submissions * Close CTFd#656 * Break up config.html to make it easier to maintain * Fix logging, domain_whitelist, and config * Improving views.py, starting to add Announcements * Starting announcements front end * Make it easier to see large images, clean up some more REST API differences * Closes CTFd#668 * Update Proxyfix config to REVERSE_PROXY * Add announcements front end * Move creation/edit modals into seperate files. Start moving user updating into their admin profile pages. * Update font-awesome to 5.4.1 * Switch to user-edit icon * Update the update_check function to send up more anonymous data for statistics purposes. * Start work on CTFd#640 * Add the user action modals and update API to fix responses * Fix admin teams page * Add challenge requirements * Implement anonymous locked challenges * Team editting from admin panel * Switch from simple cache to filesystem cache * Implements a Cache backed server side session (CTFd#658) and fixes Users editting endpoint * Add our messaging for docs * Closes CTFd#700 * Remove invalid import * Move challenge enditting around a whole lot and probably break a bunch of things * Show challenge names in prerequisites instead of challenge IDs * Closes CTFd#661 * Change user templates to use url_for * Remove extra function * Rewrite admin panel to use url_for * Fix events to work under subdirectories * Start cleaning up config panel * Fix filesystem uploader; deprecate view_challenges_unregistered, view_scoreboard_if_authed, prevent_registration, view_after_ctf; implement new visibility decorators * Remove workshop mode, fix some glitches with the new visibility settings * Fix ctf_logo on core theme * Fix setup errors * Removing default from get_config b/c of memoization issues and getting some tests working * Relax email regex validation rule (CTFd#693) * Update to pycodestyle and fix new lint errors * Add a ctf_id to update_check * Change challenge plugin layout. Rename mailgun configs to be more descriptive (Closes CTFd#702) * Detect if people try to set routes with '/' to simplify CTFd#690 * Closes CTFd#690 * Clean up some code * Clean up challenge submit to rate limit * Fix js version compatability issue * Close some TODOs * Hide challenges if not authenticated * Make set_config reset the cache for those config values * Return 404 on empty challenges for /api/v1/<challenge_id>/solves * Fix setting boolean configs * Properly change account config settings * Move datetimes to isoformat (Closes CTFd#703) * Remove all .isoformat() calls because it isn't UTC aware (ends in Z). Switch to isoformat function & filter * Make /v1/submissions endpoint work for admin submission creation * Make oauth_id unique for Users and Teams * Move challenge submission endpoint and implement mark solved. Fix some isoformat issues. * Only show team's missing challenges if in team mode * Adding support for Hints & Unlocks * Update challenge submission url * Fix encoding functions in Python3 * Fix hexencode in Python3 * Added functional tests for challenges API for non-admin users (CTFd#705) * Set hint default type to be standard * Fix some JS issues. Closes CTFd#704 * Implement session.regenerate on top of the CachingSessionInterface * Challenge challenge attempt responses from numbers to strings * Fix password updating for UserSchema * Remove leftover challenge submission code * Remove old migrations :(, resolve challenge requirements not loading correctly, move migration functions * Added functional tests for challenges/hints/admin API (CTFd#710) * Fix helpers and re-add JSONLite * Install MySQL 5.7 * Try more mysql * Update password for mysql * Fixing issuse in Users.get_solves * Add new import/export code * Switch to CTFdSerializer for Python 3 * Re-implement import exports and add a very flaky test * Redesign submissions API response * Get export to roundtrip in tests * Int score b/c Decimal is not JSON serializeable * Remove unused route methods * Fix POST /api/v1/configs and start adding admin tests * Add user_id and team_id to top/10 * Fix admin creating Teams * Fix Team website validation * Change admins_only to reply with a 403 if the request is JSON * Organize admin tests and fix authed_only to return 403 on unauthed * Adding check_account_visibility, check_score_visibility for /api/v1/teams/<team_id>/(solves|awards|fails) * Fix teams/me endpoints again * Fix users/me endpoints to return 403 if unauthed * Fix Python 3 config API * Add fetch and promise polyfills. (CTFd#712) * Add exec to docker-entrypoint.sh (CTFd#713) * Display import_ctf Exceptions via repr (CTFd#651) - Wraps exceptions on `/admin/import` returned to users in a `repr()`, making debugging easier. * Add error messages to the admin panel, fix schemas for users, start working on UI for imports/exports * Make unauthed challenge submission attempt return 403 instead of 302, Fix user deletion, fix associated tests, remove TODOs * Remove old means of creating solves * Remove most of the content from teams.js and users.js * Remove extra code from /challenges.js * Fix POST'ing & PATCH'ing pages * Make (users|teams)/fails return only count to users. Fix public score graphs to factor in awards * Fix admin side scoregraphs. Fix Awardschemas for admins * Add requirements to db migration * Adding some team decorators * Fix require_team_mode decorator * Make verified emails decorator return 403 on JSON requests * Redo initial revision * Add SQLiteJSON back * Adding ratelimit to /redirect and removing POST from /oauth * Fix PATCH tags * Actually fix PATCH tags * Simplify 500.html * Added tests for challenges, awards, files, flags, hints ... (CTFd#723) * Added tests for challenges, awards, files, flags, hints, notifications, pages, submissions, tags * Fix user data validation functions, Fix hidden challenges and include test * Add a locked state to attempt * OAuth teams get verified, use logging functions in redirect route * Removing extra print call * Update requirements.txt * Fix possible AttributeError * Start work on CTFd#716 * Closes CTFd#717 * Fix issue patching teams * Rename .j2 to .html, implement preview for challenges if admin * Move admin/challenge.html to admin/challenges/challenge.html * Remove old modals * Add Reset CTF button (CTFd#639) * Add Reset link to config.html * Delete Tracking * files handler should return a 404 on files it cant find * Denote official teams (CTFd#729), make scoregraph fill to zero * Remove old javascript files, make some challenge elements refresh by reloading * Fix team editting modals to work more reliably * Fix rendering of CTF paused * Remove hide_scores funtion and roll it into scores visibility * Log to stdout/stderr by default (CTFd#719) * Fix user searching * Remove searching for users/teams by country * Add badges to admin team and user pages, implement user banning (CTFd#643) * Remove shell.py, clean up admin team.html, add tests for banned users, teams * Start cleaning up dynamic_challenges to meet new challenge type plugin format * Remove POST method from teams.public * Add credentials: 'same-origin' to all fetch calls (CTFd#734) * Add challenge preview, add challenge deletion, fix file deletions when deleting challenges * Fix imports UI (CTFd#735) * Show prerequisites before adding a blank one (CTFd#738), Refresh all challenges after a submission (CTFd#739) * Admins can see hidden challenges * Fix some UI elements, fix loading location hash, set version to be 2.0.0 * Clean up some challenge plugin pages * Add default for flag type * Fix Python3 bytes/str issues * Add in MLC urls and support user mode for oauth * Fix seeing user graphs when scores are hidden, clean up setup.html, add links to MLC oauth * Add state parameter support * Use URLSafeTimedSerializer wrapper for sending token based emails * setting APPLICATION_ROOT from env var (CTFd#732) * Rearrange config.py and update README * Updating README
1 parent 41933cc commit c8031b3

File tree

378 files changed

+25711
-13485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

378 files changed

+25711
-13485
lines changed
 

‎.travis.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@ language: python
22
services:
33
- mysql
44
- postgresql
5+
addons:
6+
apt:
7+
sources:
8+
- mysql-5.7-trusty
9+
packages:
10+
- mysql-server
11+
- mysql-client
512
env:
6-
- TESTING_DATABASE_URL='mysql+pymysql://root@localhost/ctfd'
13+
- TESTING_DATABASE_URL='mysql+pymysql://root:password@localhost/ctfd'
714
- TESTING_DATABASE_URL='sqlite://'
815
- TESTING_DATABASE_URL='postgres://postgres@localhost/ctfd'
916
python:
1017
- 2.7
1118
- 3.6
19+
before_install:
20+
- sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('password') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
21+
- sudo mysql_upgrade -u root -ppassword
22+
- sudo service mysql restart
1223
install:
1324
- pip install -r development.txt
1425
before_script:
1526
- psql -c 'create database ctfd;' -U postgres
1627
script:
17-
- pep8 --ignore E501,E712 CTFd/ tests/
28+
- pycodestyle --ignore E501,E712,E402 CTFd/ tests/
1829
- nosetests -v -d --with-randomly
1930
after_success:
2031
- codecov

‎CTFd/__init__.py

+54-45
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@
33

44
from distutils.version import StrictVersion
55
from flask import Flask
6+
from werkzeug.contrib.fixers import ProxyFix
67
from jinja2 import FileSystemLoader
78
from jinja2.sandbox import SandboxedEnvironment
89
from sqlalchemy.engine.url import make_url
910
from sqlalchemy_utils import database_exists, create_database
1011
from six.moves import input
1112

12-
from CTFd.utils import cache, migrate, migrate_upgrade, migrate_stamp, update_check
1313
from CTFd import utils
14+
from CTFd.utils.migrations import migrations, migrate, upgrade, stamp, create_database
15+
from CTFd.utils.sessions import CachingSessionInterface
16+
from CTFd.utils.updates import update_check
17+
from CTFd.utils.initialization import init_request_processors, init_template_filters, init_template_globals
18+
from CTFd.utils.events import socketio
19+
from CTFd.plugins import init_plugins
1420

1521
# Hack to support Unicode in Python 2 properly
1622
if sys.version_info[0] < 3:
1723
reload(sys)
1824
sys.setdefaultencoding("utf-8")
1925

20-
__version__ = '1.2.0'
26+
__version__ = '2.0.0'
2127

2228

2329
class CTFdFlask(Flask):
2430
def __init__(self, *args, **kwargs):
2531
"""Overriden Jinja constructor setting a custom jinja_environment"""
2632
self.jinja_environment = SandboxedBaseEnvironment
33+
self.jinja_environment.cache = None
34+
self.session_interface = CachingSessionInterface(key_prefix='session')
2735
Flask.__init__(self, *args, **kwargs)
2836

2937
def create_jinja_environment(self):
@@ -78,7 +86,7 @@ def confirm_upgrade():
7886

7987

8088
def run_upgrade():
81-
migrate_upgrade()
89+
upgrade()
8290
utils.set_config('ctf_version', __version__)
8391

8492

@@ -90,21 +98,9 @@ def create_app(config='CTFd.config.Config'):
9098
theme_loader = ThemeLoader(os.path.join(app.root_path, 'themes'), followlinks=True)
9199
app.jinja_loader = theme_loader
92100

93-
from CTFd.models import db, Teams, Solves, Challenges, WrongKeys, Keys, Tags, Files, Tracking
101+
from CTFd.models import db, Teams, Solves, Challenges, Fails, Flags, Tags, Files, Tracking
94102

95-
url = make_url(app.config['SQLALCHEMY_DATABASE_URI'])
96-
if url.drivername == 'postgres':
97-
url.drivername = 'postgresql'
98-
99-
if url.drivername.startswith('mysql'):
100-
url.query['charset'] = 'utf8mb4'
101-
102-
# Creates database if the database database does not exist
103-
if not database_exists(url):
104-
if url.drivername.startswith('mysql'):
105-
create_database(url, encoding='utf8mb4')
106-
else:
107-
create_database(url)
103+
url = create_database()
108104

109105
# This allows any changes to the SQLALCHEMY_DATABASE_URI to get pushed back in
110106
# This is mostly so we can force MySQL's charset
@@ -114,32 +110,37 @@ def create_app(config='CTFd.config.Config'):
114110
db.init_app(app)
115111

116112
# Register Flask-Migrate
117-
migrate.init_app(app, db)
113+
migrations.init_app(app, db)
118114

119115
# Alembic sqlite support is lacking so we should just create_all anyway
120116
if url.drivername.startswith('sqlite'):
121117
db.create_all()
118+
stamp()
122119
else:
123-
if len(db.engine.table_names()) == 0:
124-
# This creates tables instead of db.create_all()
125-
# Allows migrations to happen properly
126-
migrate_upgrade()
127-
elif 'alembic_version' not in db.engine.table_names():
128-
# There is no alembic_version because CTFd is from before it had migrations
129-
# Stamp it to the base migration
130-
if confirm_upgrade():
131-
migrate_stamp(revision='cb3cfcc47e2f')
132-
run_upgrade()
133-
else:
134-
exit()
120+
# This creates tables instead of db.create_all()
121+
# Allows migrations to happen properly
122+
upgrade()
123+
124+
from CTFd.models import ma
125+
126+
ma.init_app(app)
135127

136128
app.db = db
137129
app.VERSION = __version__
138130

131+
from CTFd.cache import cache
132+
139133
cache.init_app(app)
140134
app.cache = cache
141135

142-
update_check(force=True)
136+
# If you have multiple workers you must have a shared cache
137+
socketio.init_app(
138+
app,
139+
message_queue=app.config.get('CACHE_REDIS_URL')
140+
)
141+
142+
if app.config.get('REVERSE_PROXY'):
143+
app.wsgi_app = ProxyFix(app.wsgi_app)
143144

144145
version = utils.get_config('ctf_version')
145146

@@ -156,31 +157,39 @@ def create_app(config='CTFd.config.Config'):
156157
if not utils.get_config('ctf_theme'):
157158
utils.set_config('ctf_theme', 'core')
158159

160+
update_check(force=True)
161+
162+
init_request_processors(app)
163+
init_template_filters(app)
164+
init_template_globals(app)
165+
166+
# Importing here allows tests to use sensible names (e.g. api instead of api_bp)
159167
from CTFd.views import views
168+
from CTFd.teams import teams
169+
from CTFd.users import users
160170
from CTFd.challenges import challenges
161171
from CTFd.scoreboard import scoreboard
162172
from CTFd.auth import auth
163-
from CTFd.admin import admin, admin_statistics, admin_challenges, admin_pages, admin_scoreboard, admin_keys, admin_teams
164-
from CTFd.utils import init_utils, init_errors, init_logs
165-
166-
init_utils(app)
167-
init_errors(app)
168-
init_logs(app)
173+
from CTFd.admin import admin
174+
from CTFd.api import api
175+
from CTFd.events import events
176+
from CTFd.errors import page_not_found, forbidden, general_error, gateway_error
169177

170178
app.register_blueprint(views)
179+
app.register_blueprint(teams)
180+
app.register_blueprint(users)
171181
app.register_blueprint(challenges)
172182
app.register_blueprint(scoreboard)
173183
app.register_blueprint(auth)
184+
app.register_blueprint(api)
185+
app.register_blueprint(events)
174186

175187
app.register_blueprint(admin)
176-
app.register_blueprint(admin_statistics)
177-
app.register_blueprint(admin_challenges)
178-
app.register_blueprint(admin_teams)
179-
app.register_blueprint(admin_scoreboard)
180-
app.register_blueprint(admin_keys)
181-
app.register_blueprint(admin_pages)
182-
183-
from CTFd.plugins import init_plugins
188+
189+
app.register_error_handler(404, page_not_found)
190+
app.register_error_handler(403, forbidden)
191+
app.register_error_handler(500, general_error)
192+
app.register_error_handler(502, gateway_error)
184193

185194
init_plugins(app)
186195

0 commit comments

Comments
 (0)
Please sign in to comment.