mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Toggle username_password inputs depending on mail_useauth and clean get_smtp util (#343)
This commit is contained in:
@@ -97,8 +97,8 @@
|
|||||||
Prevent team name changes
|
Prevent team name changes
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div role="tabpanel" class="tab-pane" id="email-section">
|
<div role="tabpanel" class="tab-pane" id="email-section">
|
||||||
<ul class="nav nav-tabs" role="tablist">
|
<ul class="nav nav-tabs" role="tablist">
|
||||||
<li role="presentation" class="active">
|
<li role="presentation" class="active">
|
||||||
<a href="#mailserver" aria-controls="mailserver" role="tab" data-toggle="tab">Mail Server</a>
|
<a href="#mailserver" aria-controls="mailserver" role="tab" data-toggle="tab">Mail Server</a>
|
||||||
@@ -111,8 +111,8 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start">Mail From Address:</label>
|
<label for="start">Mail From Address:</label>
|
||||||
<input class="form-control" id='mailfrom_addr' name='mailfrom_addr' type='text'
|
<input class="form-control" id='mailfrom_addr' name='mailfrom_addr' type='text'
|
||||||
placeholder="Email address used to send email"
|
placeholder="Email address used to send email"
|
||||||
{% if mailfrom_addr is defined and mailfrom_addr != None %}value="{{ mailfrom_addr }}"{% endif %}>
|
{% if mailfrom_addr is defined and mailfrom_addr != None %}value="{{ mailfrom_addr }}"{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
@@ -121,33 +121,35 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start">Mail Server Address:</label>
|
<label for="start">Mail Server Address:</label>
|
||||||
<input class="form-control" id='mail_server' name='mail_server' type='text'
|
<input class="form-control" id='mail_server' name='mail_server' type='text'
|
||||||
placeholder="Mail Server Address"
|
placeholder="Mail Server Address"
|
||||||
{% if mail_server is defined and mail_server != None %}value="{{ mail_server }}"{% endif %}>
|
{% if mail_server is defined and mail_server != None %}value="{{ mail_server }}"{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start">Mail Server Port:</label>
|
<label for="start">Mail Server Port:</label>
|
||||||
<input class="form-control" id='mail_port' name='mail_port' type='text'
|
<input class="form-control" id='mail_port' name='mail_port' type='text'
|
||||||
placeholder="Mail Server Port"
|
placeholder="Mail Server Port"
|
||||||
{% if mail_port is defined and mail_port != None %}value="{{ mail_port }}"{% endif %}>
|
{% if mail_port is defined and mail_port != None %}value="{{ mail_port }}"{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input id="mail_useauth" name="mail_useauth" type="checkbox" {% if mail_useauth %}checked{% endif %}>
|
<input id="mail_useauth" name="mail_useauth" type="checkbox" {% if mail_useauth %}checked{% endif %}>
|
||||||
Use SMTP Authentication?
|
Specify Username and Password
|
||||||
</label>
|
</label>
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="start">Username:</label>
|
|
||||||
<input class="form-control" id='mail_username' name='mail_username' type='text'
|
|
||||||
placeholder="Username"
|
|
||||||
{% if mail_username is defined and mail_username != None %}value="{{ mail_username }}"{% endif %}>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div id="mail_username_password">
|
||||||
<label for="start">Password:</label>
|
<div class="form-group">
|
||||||
<input class="form-control" id='mail_password' name='mail_password' type='password'
|
<label for="start">Username:</label>
|
||||||
placeholder="Password"
|
<input class="form-control" id='mail_username' name='mail_username' type='text'
|
||||||
{% if mail_password is defined and mail_password != None %}value="{{ mail_password }}"{% endif %}>
|
placeholder="Username"
|
||||||
|
{% if mail_username is defined and mail_username != None %}value="{{ mail_username }}"{% endif %}>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="start">Password:</label>
|
||||||
|
<input class="form-control" id='mail_password' name='mail_password' type='password'
|
||||||
|
placeholder="Password"
|
||||||
|
{% if mail_password is defined and mail_password != None %}value="{{ mail_password }}"{% endif %}>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
@@ -167,14 +169,14 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start">Mailgun API Base URL:</label>
|
<label for="start">Mailgun API Base URL:</label>
|
||||||
<input class="form-control" id='mg_base_url' name='mg_base_url' type='text'
|
<input class="form-control" id='mg_base_url' name='mg_base_url' type='text'
|
||||||
placeholder="Mailgun API Base URL"
|
placeholder="Mailgun API Base URL"
|
||||||
{% if mg_base_url is defined and mg_base_url != None %}value="{{ mg_base_url }}"{% endif %}>
|
{% if mg_base_url is defined and mg_base_url != None %}value="{{ mg_base_url }}"{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start">Mailgun API Key:</label>
|
<label for="start">Mailgun API Key:</label>
|
||||||
<input class="form-control" id='mg_api_key' name='mg_api_key' type='text'
|
<input class="form-control" id='mg_api_key' name='mg_api_key' type='text'
|
||||||
placeholder="Mailgun API Key"
|
placeholder="Mailgun API Key"
|
||||||
{% if mg_api_key is defined and mg_api_key != None %}value="{{ mg_api_key }}"{% endif %}>
|
{% if mg_api_key is defined and mg_api_key != None %}value="{{ mg_api_key }}"{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -237,20 +239,20 @@
|
|||||||
<div class="form-group col-xs-12">
|
<div class="form-group col-xs-12">
|
||||||
<label for="start-local">Local Time:</label>
|
<label for="start-local">Local Time:</label>
|
||||||
<input class="form-control" id='start-local' type='text'
|
<input class="form-control" id='start-local' type='text'
|
||||||
placeholder="Start Date (Local Time)" readonly>
|
placeholder="Start Date (Local Time)" readonly>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-12">
|
<div class="form-group col-xs-12">
|
||||||
<label for="start-zonetime">Timezone Time:</label>
|
<label for="start-zonetime">Timezone Time:</label>
|
||||||
<input class="form-control" id='start-zonetime' type='text'
|
<input class="form-control" id='start-zonetime' type='text'
|
||||||
placeholder="Start Date (Timezone Time)" readonly>
|
placeholder="Start Date (Timezone Time)" readonly>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-12">
|
<div class="form-group col-xs-12">
|
||||||
<label for="start">UTC Timestamp:</label>
|
<label for="start">UTC Timestamp:</label>
|
||||||
<input class="form-control" id='start' name='start' type='text'
|
<input class="form-control" id='start' name='start' type='text'
|
||||||
placeholder="Start Date (UTC timestamp)"
|
placeholder="Start Date (UTC timestamp)"
|
||||||
{% if start is defined and start != None %}value="{{ start }}"{% endif %} readonly>
|
{% if start is defined and start != None %}value="{{ start }}"{% endif %} readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -259,13 +261,13 @@
|
|||||||
<div class="form-group col-xs-2">
|
<div class="form-group col-xs-2">
|
||||||
<label for="end-month">Month:</label>
|
<label for="end-month">Month:</label>
|
||||||
<input class="form-control end-date" id='end-month' name='end-month' min="1" max="12"
|
<input class="form-control end-date" id='end-month' name='end-month' min="1" max="12"
|
||||||
type='number'>
|
type='number'>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-2">
|
<div class="form-group col-xs-2">
|
||||||
<label for="end-day">Day:</label>
|
<label for="end-day">Day:</label>
|
||||||
<input class="form-control end-date" id='end-day' name='end-day' min="1" max="31"
|
<input class="form-control end-date" id='end-day' name='end-day' min="1" max="31"
|
||||||
type='number'>
|
type='number'>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-2">
|
<div class="form-group col-xs-2">
|
||||||
@@ -276,13 +278,13 @@
|
|||||||
<div class="form-group col-xs-2">
|
<div class="form-group col-xs-2">
|
||||||
<label for="end-hour">Hour:</label>
|
<label for="end-hour">Hour:</label>
|
||||||
<input class="form-control end-date" id='end-hour' name='end-hour' min="0" max="23"
|
<input class="form-control end-date" id='end-hour' name='end-hour' min="0" max="23"
|
||||||
type='number'>
|
type='number'>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-2">
|
<div class="form-group col-xs-2">
|
||||||
<label for="end-minute">Minute:</label>
|
<label for="end-minute">Minute:</label>
|
||||||
<input class="form-control end-date" id='end-minute' name='end-minute' min="0"
|
<input class="form-control end-date" id='end-minute' name='end-minute' min="0"
|
||||||
max="59" type='number'>
|
max="59" type='number'>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-4">
|
<div class="form-group col-xs-4">
|
||||||
@@ -301,20 +303,20 @@
|
|||||||
<div class="form-group col-xs-12">
|
<div class="form-group col-xs-12">
|
||||||
<label for="end-local">Local Time:</label>
|
<label for="end-local">Local Time:</label>
|
||||||
<input class="form-control" id='end-local' type='text'
|
<input class="form-control" id='end-local' type='text'
|
||||||
placeholder="End Date (Local Time)" readonly>
|
placeholder="End Date (Local Time)" readonly>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-12">
|
<div class="form-group col-xs-12">
|
||||||
<label for="end-zonetime">Timezone Time:</label>
|
<label for="end-zonetime">Timezone Time:</label>
|
||||||
<input class="form-control" id='end-zonetime' type='text'
|
<input class="form-control" id='end-zonetime' type='text'
|
||||||
placeholder="End Date (Timezone Time)" readonly>
|
placeholder="End Date (Timezone Time)" readonly>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-xs-12">
|
<div class="form-group col-xs-12">
|
||||||
<label for="end">UTC Timestamp:</label>
|
<label for="end">UTC Timestamp:</label>
|
||||||
<input class="form-control" id='end' name='end' type='text'
|
<input class="form-control" id='end' name='end' type='text'
|
||||||
placeholder="End Date (UTC timestamp)"
|
placeholder="End Date (UTC timestamp)"
|
||||||
{% if end is defined and end != None %}value="{{ end }}"{% endif %} readonly>
|
{% if end is defined and end != None %}value="{{ end }}"{% endif %} readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -606,7 +608,6 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
var hash = window.location.hash;
|
var hash = window.location.hash;
|
||||||
if (hash) {
|
if (hash) {
|
||||||
hash = hash.replace("<>[]'\"", "");
|
hash = hash.replace("<>[]'\"", "");
|
||||||
@@ -621,8 +622,7 @@
|
|||||||
var start = $('#start').val();
|
var start = $('#start').val();
|
||||||
var end = $('#end').val();
|
var end = $('#end').val();
|
||||||
var freeze = $('#freeze').val();
|
var freeze = $('#freeze').val();
|
||||||
console.log(start);
|
|
||||||
console.log(end);
|
|
||||||
if (start){
|
if (start){
|
||||||
load_timestamp('start', start);
|
load_timestamp('start', start);
|
||||||
}
|
}
|
||||||
@@ -632,6 +632,11 @@
|
|||||||
if (freeze) {
|
if (freeze) {
|
||||||
load_timestamp('freeze', freeze);
|
load_timestamp('freeze', freeze);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Toggle username and password based on stored value
|
||||||
|
$('#mail_useauth').change(function () {
|
||||||
|
$('#mail_username_password').toggle(this.checked);
|
||||||
|
}).change();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -437,11 +437,14 @@ def mailserver():
|
|||||||
|
|
||||||
|
|
||||||
def get_smtp(host, port, username=None, password=None, TLS=None, SSL=None, auth=None):
|
def get_smtp(host, port, username=None, password=None, TLS=None, SSL=None, auth=None):
|
||||||
smtp = smtplib.SMTP(host, port)
|
if SSL is None:
|
||||||
smtp.ehlo()
|
smtp = smtplib.SMTP(host, port)
|
||||||
|
else:
|
||||||
|
smtp = smtplib.SMTP_SSL(host, port)
|
||||||
|
|
||||||
if TLS:
|
if TLS:
|
||||||
smtp.starttls()
|
smtp.starttls()
|
||||||
smtp.ehlo()
|
|
||||||
if auth:
|
if auth:
|
||||||
smtp.login(username, password)
|
smtp.login(username, password)
|
||||||
return smtp
|
return smtp
|
||||||
|
|||||||
Reference in New Issue
Block a user