mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-19 06:54:20 +01:00
Closes #21
This commit is contained in:
@@ -62,6 +62,8 @@ def init_admin(app):
|
|||||||
view_challenges_unregistered = None
|
view_challenges_unregistered = None
|
||||||
prevent_registration = None
|
prevent_registration = None
|
||||||
|
|
||||||
|
ctf_name = set_config("ctf_name", request.form.get('ctf_name', None))
|
||||||
|
mg_api_key = set_config("mg_api_key", request.form.get('mg_api_key', None))
|
||||||
do_api_key = set_config("do_api_key", request.form.get('do_api_key', None))
|
do_api_key = set_config("do_api_key", request.form.get('do_api_key', None))
|
||||||
|
|
||||||
db_start = Config.query.filter_by(key='start').first()
|
db_start = Config.query.filter_by(key='start').first()
|
||||||
@@ -84,6 +86,14 @@ def init_admin(app):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect('/admin/config')
|
return redirect('/admin/config')
|
||||||
|
|
||||||
|
ctf_name = get_config('ctf_name')
|
||||||
|
if not ctf_name:
|
||||||
|
set_config('do_api_key', None)
|
||||||
|
|
||||||
|
mg_api_key = get_config('do_api_key')
|
||||||
|
if not mg_api_key:
|
||||||
|
set_config('do_api_key', None)
|
||||||
|
|
||||||
do_api_key = get_config('do_api_key')
|
do_api_key = get_config('do_api_key')
|
||||||
if not do_api_key:
|
if not do_api_key:
|
||||||
set_config('do_api_key', None)
|
set_config('do_api_key', None)
|
||||||
@@ -107,8 +117,9 @@ def init_admin(app):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
db.session.close()
|
db.session.close()
|
||||||
|
|
||||||
return render_template('admin/config.html', start=start, end=end, view_challenges_unregistered=view_challenges_unregistered,
|
return render_template('admin/config.html', ctf_name=ctf_name, start=start, end=end,
|
||||||
prevent_registration=prevent_registration, do_api_key=do_api_key)
|
view_challenges_unregistered=view_challenges_unregistered,
|
||||||
|
prevent_registration=prevent_registration, do_api_key=do_api_key, mg_api_key=mg_api_key)
|
||||||
|
|
||||||
@app.route('/admin/pages', defaults={'route': None}, methods=['GET', 'POST'])
|
@app.route('/admin/pages', defaults={'route': None}, methods=['GET', 'POST'])
|
||||||
@app.route('/admin/pages/<route>', methods=['GET', 'POST'])
|
@app.route('/admin/pages/<route>', methods=['GET', 'POST'])
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ SESSION_COOKIE_HTTPONLY = True
|
|||||||
HOST = ".ctfd.io"
|
HOST = ".ctfd.io"
|
||||||
UPLOAD_FOLDER = os.path.normpath('static/uploads')
|
UPLOAD_FOLDER = os.path.normpath('static/uploads')
|
||||||
|
|
||||||
##### EMAIL #####
|
##### EMAIL (if not using Mailgun) #####
|
||||||
CTF_NAME = ''
|
CTF_NAME = ''
|
||||||
MAIL_SERVER = ''
|
MAIL_SERVER = ''
|
||||||
MAIL_PORT = 0
|
MAIL_PORT = 0
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import datetime
|
|||||||
import hashlib
|
import hashlib
|
||||||
import digitalocean
|
import digitalocean
|
||||||
import shutil
|
import shutil
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def init_utils(app):
|
def init_utils(app):
|
||||||
@@ -147,19 +148,32 @@ def set_config(key, value):
|
|||||||
|
|
||||||
|
|
||||||
def mailserver():
|
def mailserver():
|
||||||
if app.config['MAIL_SERVER'] and app.config['MAIL_PORT'] and app.config['ADMINS']:
|
if get_config('mg_api_key') or (app.config['MAIL_SERVER'] and app.config['MAIL_PORT'] and app.config['ADMINS']):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def sendmail(addr, text):
|
def sendmail(addr, text):
|
||||||
|
if get_config('mg_api_key'):
|
||||||
|
ctf_name = get_config('ctf_name')
|
||||||
|
mg_api_key = get_config('mg_api_key')
|
||||||
|
return requests.post(
|
||||||
|
"https://api.mailgun.net/v2/mail"+app.config['HOST']+"/messages",
|
||||||
|
auth=("api", mg_api_key),
|
||||||
|
data={"from": "{} Admin <noreply@ctfd.io>".format(ctf_name),
|
||||||
|
"to": [addr],
|
||||||
|
"subject": "Message from {0}".format(ctf_name),
|
||||||
|
"text": text})
|
||||||
|
elif app.config['MAIL_SERVER'] and app.config['MAIL_PORT'] and app.config['ADMINS']:
|
||||||
try:
|
try:
|
||||||
msg = Message("Message from {0}".format(app.config['CTF_NAME']), sender = app.config['ADMINS'][0], recipients = [addr])
|
msg = Message("Message from {0}".format(get_config('ctf_name')), sender=app.config['ADMINS'][0], recipients=[addr])
|
||||||
msg.body = text
|
msg.body = text
|
||||||
mail.send(msg)
|
mail.send(msg)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def rmdir(dir):
|
def rmdir(dir):
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ def init_views(app):
|
|||||||
|
|
||||||
if not is_setup():
|
if not is_setup():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
ctf_name = request.form['ctf_name']
|
||||||
|
ctf_name = Config('ctf_name', ctf_name)
|
||||||
|
|
||||||
## Admin user
|
## Admin user
|
||||||
name = request.form['name']
|
name = request.form['name']
|
||||||
email = request.form['email']
|
email = request.form['email']
|
||||||
@@ -71,6 +74,7 @@ def init_views(app):
|
|||||||
|
|
||||||
setup = Config('setup', True)
|
setup = Config('setup', True)
|
||||||
|
|
||||||
|
db.session.add(ctf_name)
|
||||||
db.session.add(admin)
|
db.session.add(admin)
|
||||||
db.session.add(page)
|
db.session.add(page)
|
||||||
db.session.add(start)
|
db.session.add(start)
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ bcrypt
|
|||||||
six==1.8.0
|
six==1.8.0
|
||||||
itsdangerous
|
itsdangerous
|
||||||
python-digitalocean
|
python-digitalocean
|
||||||
|
requests
|
||||||
|
|||||||
@@ -7,6 +7,16 @@
|
|||||||
<form method="POST">
|
<form method="POST">
|
||||||
<input name='nonce' type='hidden' value="{{ nonce }}">
|
<input name='nonce' type='hidden' value="{{ nonce }}">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<label for="start">CTF Name:</label>
|
||||||
|
<input id='ctf_name' name='ctf_name' type='text' placeholder="CTF Name" {% if ctf_name is defined and ctf_name != None %}value="{{ ctf_name }}"{% endif %}>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<label for="start">Mailgun API Key:</label>
|
||||||
|
<input id='mg_api_key' name='mg_api_key' type='text' placeholder="Mailgun API Key" {% if mg_api_key is defined and mg_api_key != None %}value="{{ mg_api_key }}"{% endif %}>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label for="start">Digital Ocean API Key:</label>
|
<label for="start">Digital Ocean API Key:</label>
|
||||||
<input id='do_api_key' name='do_api_key' type='text' placeholder="Digital Ocean API Key" {% if do_api_key is defined and do_api_key != None %}value="{{ do_api_key }}"{% endif %}>
|
<input id='do_api_key' name='do_api_key' type='text' placeholder="Digital Ocean API Key" {% if do_api_key is defined and do_api_key != None %}value="{{ do_api_key }}"{% endif %}>
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
|
<strong>CTF Name</strong>
|
||||||
|
<input class="radius" type='text' name='ctf_name' placeholder='CTF Name'><br/>
|
||||||
|
|
||||||
<strong>Username</strong>
|
<strong>Username</strong>
|
||||||
<input class="radius" type='text' name='name' placeholder='Name'><br/>
|
<input class="radius" type='text' name='name' placeholder='Name'><br/>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user