mirror of https://github.com/JohnHammond/CTFd.git
Closes #21
parent
eced601485
commit
d09d0a9678
|
@ -62,6 +62,8 @@ def init_admin(app):
|
|||
view_challenges_unregistered = 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))
|
||||
|
||||
db_start = Config.query.filter_by(key='start').first()
|
||||
|
@ -84,6 +86,14 @@ def init_admin(app):
|
|||
db.session.commit()
|
||||
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')
|
||||
if not do_api_key:
|
||||
set_config('do_api_key', None)
|
||||
|
@ -107,8 +117,9 @@ def init_admin(app):
|
|||
db.session.commit()
|
||||
db.session.close()
|
||||
|
||||
return render_template('admin/config.html', start=start, end=end, view_challenges_unregistered=view_challenges_unregistered,
|
||||
prevent_registration=prevent_registration, do_api_key=do_api_key)
|
||||
return render_template('admin/config.html', ctf_name=ctf_name, start=start, end=end,
|
||||
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/<route>', methods=['GET', 'POST'])
|
||||
|
|
|
@ -8,7 +8,7 @@ SESSION_COOKIE_HTTPONLY = True
|
|||
HOST = ".ctfd.io"
|
||||
UPLOAD_FOLDER = os.path.normpath('static/uploads')
|
||||
|
||||
##### EMAIL #####
|
||||
##### EMAIL (if not using Mailgun) #####
|
||||
CTF_NAME = ''
|
||||
MAIL_SERVER = ''
|
||||
MAIL_PORT = 0
|
||||
|
|
|
@ -13,6 +13,7 @@ import datetime
|
|||
import hashlib
|
||||
import digitalocean
|
||||
import shutil
|
||||
import requests
|
||||
|
||||
|
||||
def init_utils(app):
|
||||
|
@ -147,18 +148,31 @@ def set_config(key, value):
|
|||
|
||||
|
||||
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 False
|
||||
|
||||
|
||||
def sendmail(addr, text):
|
||||
try:
|
||||
msg = Message("Message from {0}".format(app.config['CTF_NAME']), sender = app.config['ADMINS'][0], recipients = [addr])
|
||||
msg.body = text
|
||||
mail.send(msg)
|
||||
return True
|
||||
except:
|
||||
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:
|
||||
msg = Message("Message from {0}".format(get_config('ctf_name')), sender=app.config['ADMINS'][0], recipients=[addr])
|
||||
msg.body = text
|
||||
mail.send(msg)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@ def init_views(app):
|
|||
|
||||
if not is_setup():
|
||||
if request.method == 'POST':
|
||||
ctf_name = request.form['ctf_name']
|
||||
ctf_name = Config('ctf_name', ctf_name)
|
||||
|
||||
## Admin user
|
||||
name = request.form['name']
|
||||
email = request.form['email']
|
||||
|
@ -71,6 +74,7 @@ def init_views(app):
|
|||
|
||||
setup = Config('setup', True)
|
||||
|
||||
db.session.add(ctf_name)
|
||||
db.session.add(admin)
|
||||
db.session.add(page)
|
||||
db.session.add(start)
|
||||
|
|
|
@ -8,4 +8,5 @@ passlib==1.6.2
|
|||
bcrypt
|
||||
six==1.8.0
|
||||
itsdangerous
|
||||
python-digitalocean
|
||||
python-digitalocean
|
||||
requests
|
||||
|
|
|
@ -7,6 +7,16 @@
|
|||
<form method="POST">
|
||||
<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">
|
||||
<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 %}>
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
</div>
|
||||
|
||||
<form method="POST">
|
||||
<strong>CTF Name</strong>
|
||||
<input class="radius" type='text' name='ctf_name' placeholder='CTF Name'><br/>
|
||||
|
||||
<strong>Username</strong>
|
||||
<input class="radius" type='text' name='name' placeholder='Name'><br/>
|
||||
|
||||
|
|
Loading…
Reference in New Issue