diff --git a/CTFd/auth.py b/CTFd/auth.py
index 02ddfade..9f265e4f 100644
--- a/CTFd/auth.py
+++ b/CTFd/auth.py
@@ -1,5 +1,5 @@
from flask import render_template, request, redirect, abort, jsonify, url_for, session, Blueprint
-from CTFd.utils import sha512, is_safe_url, authed, mailserver, sendmail, can_register, get_config, verify_email
+from CTFd.utils import sha512, is_safe_url, authed, can_send_mail, sendmail, can_register, get_config, verify_email
from CTFd.models import db, Teams
from itsdangerous import TimedSerializer, BadTimeSignature, Signer, BadSignature
@@ -121,10 +121,10 @@ def register():
session['admin'] = team.admin
session['nonce'] = sha512(os.urandom(10))
- if mailserver() and get_config('verify_emails'):
+ if can_send_mail() and get_config('verify_emails'):
verify_email(team.email)
else:
- if mailserver():
+ if can_send_mail():
sendmail(request.form['email'], "You've successfully registered for {}".format(get_config('ctf_name')))
db.session.close()
diff --git a/CTFd/config.py b/CTFd/config.py
index 31a5770f..c7a36291 100644
--- a/CTFd/config.py
+++ b/CTFd/config.py
@@ -18,6 +18,7 @@ SESSION_FILE_DIR = "/tmp/flask_session"
SESSION_COOKIE_HTTPONLY = True
PERMANENT_SESSION_LIFETIME = 604800 # 7 days in seconds
HOST = ".ctfd.io"
+MAILFROM_ADDR = "noreply@ctfd.io"
UPLOAD_FOLDER = os.path.normpath('static/uploads')
TEMPLATES_AUTO_RELOAD = True
TRUSTED_PROXIES = [
diff --git a/CTFd/templates/original/admin/teams.html b/CTFd/templates/original/admin/teams.html
index d665b2dc..568a29a7 100644
--- a/CTFd/templates/original/admin/teams.html
+++ b/CTFd/templates/original/admin/teams.html
@@ -139,7 +139,7 @@ input[type="checkbox"] { margin: 0px !important; position: relative; top: 5px; }
- {% if mailserver() %}{% endif %}
+ {% if can_send_mail() %}{% endif %}
|
@@ -199,7 +199,7 @@ $('#update-user').click(function(e){
row.find('.team-affiliation').text( $.grep(user_data, function(e){ return e.name == 'affiliation'; })[0]['value'] );
row.find('.team-country').text( $.grep(user_data, function(e){ return e.name == 'country'; })[0]['value'] );
- $('#user').modal();
+ $('#user').modal('hide');
}
else{
$('#results').append($('p').text( data['data'][i] ))
@@ -224,7 +224,7 @@ $('#send-user-email').click(function(e){
var email_data = $('#email-user form').serializeArray();
$.post($('#email-user form').attr('action'), $('#email-user form').serialize(), function(data){
if (data == "1"){
- $('#email-user').modal();
+ $('#email-user').modal('hide');
}
else{
$('#email-user-errors').append("Failed to send email");
diff --git a/CTFd/utils.py b/CTFd/utils.py
index fc85e8b5..74ab1cad 100644
--- a/CTFd/utils.py
+++ b/CTFd/utils.py
@@ -92,7 +92,7 @@ def init_utils(app):
app.jinja_env.filters['long2ip'] = long2ip
app.jinja_env.globals.update(pages=pages)
app.jinja_env.globals.update(can_register=can_register)
- app.jinja_env.globals.update(mailserver=mailserver)
+ app.jinja_env.globals.update(can_send_mail=can_send_mail)
app.jinja_env.globals.update(ctf_name=ctf_name)
app.jinja_env.globals.update(ctf_theme=ctf_theme)
app.jinja_env.globals.update(can_create_container=can_create_container)
@@ -315,10 +315,19 @@ def set_config(key, value):
return config
-def mailserver():
+def can_send_mail():
+ return mailgun() or mailserver()
+
+
+def mailgun():
if app.config.get('MAILGUN_API_KEY') and app.config.get('MAILGUN_BASE_URL'):
return True
- if (get_config('mg_api_key') and get_config('mg_base_url')) or (get_config('mail_server') and get_config('mail_port')):
+ if (get_config('mg_api_key') and get_config('mg_base_url')):
+ return True
+ return False
+
+def mailserver():
+ if (get_config('mail_server') and get_config('mail_port')):
return True
return False
@@ -334,14 +343,15 @@ def get_smtp(host, port, username=None, password=None, TLS=None, SSL=None):
def sendmail(addr, text):
- if mailserver():
+ if mailgun():
ctf_name = get_config('ctf_name')
mg_api_key = get_config('mg_api_key') or app.config.get('MAILGUN_API_KEY')
mg_base_url = get_config('mg_base_url') or app.config.get('MAILGUN_BASE_URL')
+ mailfrom_addr = get_config('mailfrom_addr') or app.config.get('MAILFROM_ADDR')
r = requests.post(
mg_base_url + '/messages',
auth=("api", mg_api_key),
- data={"from": "{} Admin <{}>".format(ctf_name, 'noreply@ctfd.io'),
+ data={"from": "{} Admin <{}>".format(ctf_name, mailfrom_addr),
"to": [addr],
"subject": "Message from {0}".format(ctf_name),
"text": text})
@@ -349,7 +359,7 @@ def sendmail(addr, text):
return True
else:
return False
- elif get_config('mail_server') and get_config('mail_port'):
+ elif mailserver():
data = {
'host': get_config('mail_server'),
'port': int(get_config('mail_port'))
@@ -529,4 +539,4 @@ def container_ports(name, verbose=False):
ports = [int(re.sub('[A-Za-z/]+', '', port)) for port in ports_asked]
return ports
except subprocess.CalledProcessError:
- return []
\ No newline at end of file
+ return []
diff --git a/serve.py b/serve.py
index aabe4ba4..8bf07bc2 100644
--- a/serve.py
+++ b/serve.py
@@ -1,3 +1,3 @@
from CTFd import create_app
app = create_app()
-app.run(debug=True, host="0.0.0.0", port=4000)
+app.run(debug=True, threaded=True, host="0.0.0.0", port=4000)