mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 05:54:19 +01:00
* Extracting key checking logic to make it more extensible * Add missing keys __init__ file * Adding logging access and errors to Dockerfile * Use template inheritance for page.html (#198) * Fix exception on cofirmation screen (#202) When a user attempts to confirm an e-mail address, an exception is thrown because the db session is closed prior to logging. The line db.session.close() has to move after the logging, otherwise the team parameters from the orm object are discarded and an exception is thrown. Closing the session after logging, fixes the issue. * Adding custom key types for challenges * Separating out admin.py, adding challenge types * Don't let truncate affect edit modal * File uploads no longer refresh page (#207) Closes (#180) * Fixing missing import * Fixing mistake in flag JSON response * Removing compare_digest to support Python 2.7.6 * Fixing inconsistencies in standard challenge modal * Passing submission input over to template js * Handling cases where data can't be found in the DOM better * Don't refresh modal if it's just a refresh operation * Fixing solving challenges while scoreboard is public Induce a redirect to make user login * Adding missing js file and fixing migration * Fixing some visual glitches and streamlining challenge creation
62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
from flask import current_app as app, render_template, request, redirect, jsonify, url_for, Blueprint
|
|
from CTFd.utils import admins_only, is_admin, unix_time, get_config, \
|
|
set_config, sendmail, rmdir, create_image, delete_image, run_image, container_status, container_ports, \
|
|
container_stop, container_start, get_themes, cache, upload_file
|
|
from CTFd.models import db, Teams, Solves, Awards, Containers, Challenges, WrongKeys, Keys, Tags, Files, Tracking, Pages, Config, DatabaseError
|
|
|
|
admin_pages = Blueprint('admin_pages', __name__)
|
|
|
|
@admin_pages.route('/admin/css', methods=['GET', 'POST'])
|
|
@admins_only
|
|
def admin_css():
|
|
if request.method == 'POST':
|
|
css = request.form['css']
|
|
css = set_config('css', css)
|
|
with app.app_context():
|
|
cache.clear()
|
|
return '1'
|
|
return '0'
|
|
|
|
|
|
@admin_pages.route('/admin/pages', defaults={'route': None}, methods=['GET', 'POST'])
|
|
@admin_pages.route('/admin/pages/<route>', methods=['GET', 'POST'])
|
|
@admins_only
|
|
def admin_pages_view(route):
|
|
if request.method == 'GET' and request.args.get('mode') == 'create':
|
|
return render_template('admin/editor.html')
|
|
if route and request.method == 'GET':
|
|
page = Pages.query.filter_by(route=route).first()
|
|
return render_template('admin/editor.html', page=page)
|
|
if route and request.method == 'POST':
|
|
page = Pages.query.filter_by(route=route).first()
|
|
errors = []
|
|
html = request.form['html']
|
|
route = request.form['route']
|
|
if not route:
|
|
errors.append('Missing URL route')
|
|
if errors:
|
|
page = Pages(html, '')
|
|
return render_template('/admin/editor.html', page=page)
|
|
if page:
|
|
page.route = route
|
|
page.html = html
|
|
db.session.commit()
|
|
db.session.close()
|
|
return redirect(url_for('admin_pages.admin_pages_view'))
|
|
page = Pages(route, html)
|
|
db.session.add(page)
|
|
db.session.commit()
|
|
db.session.close()
|
|
return redirect(url_for('admin_pages.admin_pages_view'))
|
|
pages = Pages.query.all()
|
|
return render_template('admin/pages.html', routes=pages, css=get_config('css'))
|
|
|
|
|
|
@admin_pages.route('/admin/page/<pageroute>/delete', methods=['POST'])
|
|
@admins_only
|
|
def delete_page(pageroute):
|
|
page = Pages.query.filter_by(route=pageroute).first_or_404()
|
|
db.session.delete(page)
|
|
db.session.commit()
|
|
db.session.close()
|
|
return '1' |