mirror of
https://github.com/simple-login/app.git
synced 2024-11-18 06:31:27 +08:00
remove the copy button, use CNAME for DKIM
This commit is contained in:
parent
625def2367
commit
6a42673229
3 changed files with 53 additions and 32 deletions
|
@ -28,19 +28,21 @@
|
|||
</div>
|
||||
|
||||
<div class="mb-2">Add the following MX DNS record to your domain. <br>
|
||||
Please note that there's a point (<em>.</em>) at the end target addresses. <br>
|
||||
Please note that there's a point (<em>.</em>) at the end target addresses.
|
||||
This is to make sure the <i>absolute</i> address is used.
|
||||
<br>
|
||||
Also some domain registrars (Namecheap, CloudFlare, etc) might use <em>@</em> for the root domain.
|
||||
</div>
|
||||
|
||||
{% for priority, email_server in EMAIL_SERVERS_WITH_PRIORITY %}
|
||||
<div class="mb-3 p-3" style="background-color: #eee">
|
||||
Domain: <em>{{ custom_domain.domain }}</em> or <em>@</em> <br>
|
||||
Record: MX <br>
|
||||
Domain: {{ custom_domain.domain }} or @ <br>
|
||||
Priority: {{ priority }} <br>
|
||||
Target: <em>{{ email_server }}</em>
|
||||
<button class="ml-4 clipboard btn btn-sm btn-outline-success" data-clipboard-action="copy"
|
||||
data-clipboard-text="{{ email_server }}">
|
||||
Copy <i class="fe fe-clipboard"></i>
|
||||
</button>
|
||||
Target: <em data-toggle="tooltip"
|
||||
title="Click to copy"
|
||||
class="clipboard"
|
||||
data-clipboard-text="{{ email_server }}">{{ email_server }}</em>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
|
@ -93,18 +95,18 @@
|
|||
Setting up SPF is highly recommended to reduce the chance your emails ending up in the recipient's Spam folder.
|
||||
</div>
|
||||
|
||||
<div class="mb-2">Add the following TXT DNS record to your domain</div>
|
||||
<div class="mb-2">Add the following TXT DNS record to your domain.</div>
|
||||
|
||||
<div class="mb-2 p-3" style="background-color: #eee">
|
||||
Domain: <em>{{ custom_domain.domain }}</em> or <em>@</em> <br>
|
||||
Record: TXT <br>
|
||||
Domain: {{ custom_domain.domain }} or @ <br>
|
||||
Value:
|
||||
<em>
|
||||
<em data-toggle="tooltip"
|
||||
title="Click to copy"
|
||||
class="clipboard"
|
||||
data-clipboard-text="{{ spf_record }}">
|
||||
{{ spf_record }}
|
||||
</em>
|
||||
<button class="ml-4 clipboard btn btn-sm btn-outline-success" data-clipboard-action="copy"
|
||||
data-clipboard-text="{{ spf_record }}">
|
||||
Copy <i class="fe fe-clipboard"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form method="post" action="#spf-form">
|
||||
|
@ -158,18 +160,21 @@
|
|||
Setting up DKIM is highly recommended to reduce the chance your emails ending up in the recipient's Spam folder.
|
||||
</div>
|
||||
|
||||
<div class="mb-2">Add the following TXT DNS record to your domain</div>
|
||||
<div class="mb-2">Add the following CNAME DNS record to your domain.</div>
|
||||
|
||||
<div class="mb-2 p-3" style="background-color: #eee">
|
||||
Domain: <em>dkim._domainkey.{{ custom_domain.domain }}</em> <br>
|
||||
Record: CNAME <br>
|
||||
Domain: <em data-toggle="tooltip"
|
||||
title="Click to copy"
|
||||
class="clipboard"
|
||||
data-clipboard-text="dkim._domainkey.">dkim._domainkey.</em>{{ custom_domain.domain }} <br>
|
||||
Value:
|
||||
<em style="overflow-wrap: break-word">
|
||||
{{ dkim_record }}
|
||||
<em data-toggle="tooltip"
|
||||
title="Click to copy"
|
||||
class="clipboard"
|
||||
data-clipboard-text="{{ dkim_cname }}" style="overflow-wrap: break-word">
|
||||
{{ dkim_cname }}
|
||||
</em>
|
||||
<button class="ml-4 clipboard btn btn-sm btn-outline-success" data-clipboard-action="copy"
|
||||
data-clipboard-text="{{ dkim_record }}">
|
||||
Copy <i class="fe fe-clipboard"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form method="post" action="#dkim-form">
|
||||
|
@ -189,7 +194,7 @@
|
|||
<div class="text-danger mt-4">
|
||||
Your DNS is not correctly set.
|
||||
{% if dkim_errors %}
|
||||
The TXT record we obtain for
|
||||
The CNAME record we obtain for
|
||||
<em>dkim._domainkey.{{ custom_domain.domain }}</em> is:
|
||||
|
||||
<div class="mb-3 p-3" style="background-color: #eee">
|
||||
|
|
|
@ -8,6 +8,7 @@ from app.dns_utils import (
|
|||
get_spf_domain,
|
||||
get_dkim_record,
|
||||
get_txt_record,
|
||||
get_cname_record,
|
||||
)
|
||||
from app.extensions import db
|
||||
from app.models import CustomDomain, Alias
|
||||
|
@ -21,6 +22,11 @@ def domain_detail_dns(custom_domain_id):
|
|||
flash("You cannot see this page", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
spf_record = f"v=spf1 include:{EMAIL_DOMAIN} -all"
|
||||
|
||||
# hardcode the DKIM selector here
|
||||
dkim_cname = f"dkim._domainkey.{EMAIL_DOMAIN}"
|
||||
|
||||
mx_ok = spf_ok = dkim_ok = True
|
||||
mx_errors = spf_errors = dkim_errors = []
|
||||
|
||||
|
@ -67,9 +73,8 @@ def domain_detail_dns(custom_domain_id):
|
|||
spf_errors = get_txt_record(custom_domain.domain)
|
||||
|
||||
elif request.form.get("form-name") == "check-dkim":
|
||||
dkim_record = get_dkim_record(custom_domain.domain)
|
||||
correct_dkim_record = f"v=DKIM1; k=rsa; p={DKIM_DNS_VALUE}"
|
||||
if dkim_record == correct_dkim_record:
|
||||
dkim_record = get_cname_record(custom_domain.domain)
|
||||
if dkim_record == dkim_cname:
|
||||
flash("The DKIM is setup correctly.", "success")
|
||||
custom_domain.dkim_verified = True
|
||||
db.session.commit()
|
||||
|
@ -80,13 +85,9 @@ def domain_detail_dns(custom_domain_id):
|
|||
)
|
||||
)
|
||||
else:
|
||||
flash("DKIM: the TXT record is not correctly set", "warning")
|
||||
flash("DKIM: the CNAME record is not correctly set", "warning")
|
||||
dkim_ok = False
|
||||
dkim_errors = get_txt_record(f"dkim._domainkey.{custom_domain.domain}")
|
||||
|
||||
spf_record = f"v=spf1 include:{EMAIL_DOMAIN} -all"
|
||||
|
||||
dkim_record = f"v=DKIM1; k=rsa; p={DKIM_DNS_VALUE}"
|
||||
dkim_errors = [dkim_record or "[Empty]"]
|
||||
|
||||
return render_template(
|
||||
"dashboard/domain_detail/dns.html",
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from typing import Optional
|
||||
|
||||
import dns.resolver
|
||||
|
||||
|
||||
|
@ -10,6 +12,19 @@ def _get_dns_resolver():
|
|||
return my_resolver
|
||||
|
||||
|
||||
def get_cname_record(hostname) -> Optional[str]:
|
||||
"""Return the CNAME record if exists for a domain"""
|
||||
try:
|
||||
answers = _get_dns_resolver().query(hostname, "CNAME")
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
for a in answers:
|
||||
return a
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_mx_domains(hostname) -> [(int, str)]:
|
||||
"""return list of (priority, domain name).
|
||||
domain name ends with a "." at the end.
|
||||
|
|
Loading…
Reference in a new issue