From 851eac604babf8de64c48e720527bd7122063a66 Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:04:18 +0100 Subject: [PATCH 1/8] Add Sentry SqlalchemyIntegration and AioHttpIntegration --- server.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 79133514..66c03f69 100644 --- a/server.py +++ b/server.py @@ -9,6 +9,9 @@ from flask_admin import Admin from flask_cors import cross_origin from flask_login import current_user from sentry_sdk.integrations.flask import FlaskIntegration +from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration +from sentry_sdk.integrations.aiohttp import AioHttpIntegration + from app import paddle_utils from app.admin_model import SLModelView, SLAdminIndexView @@ -48,7 +51,14 @@ from app.oauth.base import oauth_bp if SENTRY_DSN: LOG.d("enable sentry") - sentry_sdk.init(dsn=SENTRY_DSN, integrations=[FlaskIntegration()]) + sentry_sdk.init( + dsn=SENTRY_DSN, + integrations=[ + FlaskIntegration(), + SqlalchemyIntegration(), + AioHttpIntegration(), + ], + ) # the app is served behin nginx which uses http and not https os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" From 2a05e320e175282567550aee87416d820d6dbffc Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:05:34 +0100 Subject: [PATCH 2/8] remove beta on send email button --- app/dashboard/templates/dashboard/index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index f1e972e9..b4b0a81b 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -158,10 +158,9 @@ {% endif %} class="btn btn-sm btn-outline-primary" data-toggle="tooltip" - title="Send email from alias" + title="Not only an alias can receive emails, it can send emails too" > Send Email     - Beta {% endif %} From be1b689463be8ac24fe42156911be996968ff0fa Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:08:37 +0100 Subject: [PATCH 3/8] Fix dns query could throw different kinds of exceptions --- app/dns_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dns_utils.py b/app/dns_utils.py index 0110b343..56431843 100644 --- a/app/dns_utils.py +++ b/app/dns_utils.py @@ -7,7 +7,7 @@ def get_mx_domains(hostname) -> [(int, str)]: """ try: answers = dns.resolver.query(hostname, "MX") - except dns.resolver.NoAnswer: + except Exception: return [] ret = [] From 0327f755a16c52f71558e0e53dbb96d026cb76b4 Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:10:27 +0100 Subject: [PATCH 4/8] accept both GET and POST for / --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 66c03f69..a9f29264 100644 --- a/server.py +++ b/server.py @@ -195,7 +195,7 @@ def register_blueprints(app: Flask): def set_index_page(app): - @app.route("/") + @app.route("/", methods=["GET", "POST"]) def index(): if current_user.is_authenticated: return redirect(url_for("dashboard.index")) From 970421957683ce7bedbfe9fcddd48eb8ddce84fd Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:12:03 +0100 Subject: [PATCH 5/8] Fix product tour wording --- app/dashboard/templates/dashboard/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index b4b0a81b..b270dc66 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -152,8 +152,8 @@ {% if alias_info.show_intro_test_send_email %} data-intro="Not only alias can receive emails, it can send emails too!

You can add a new contact to for your alias here.

- To send an email to your contact, SimpleLogin will create a special email address:
- sending an email to this email address will forward your email to your contact" + To send an email to your contact, SimpleLogin will create a special email address.

+ Sending an email to this email address will forward the email to your contact" data-step="4" {% endif %} class="btn btn-sm btn-outline-primary" From fc985d64d9e66b5b6ca35e45e32bd563492d233f Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:15:08 +0100 Subject: [PATCH 6/8] Use catch-all for all dns query --- app/dns_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/dns_utils.py b/app/dns_utils.py index 56431843..cb0f1799 100644 --- a/app/dns_utils.py +++ b/app/dns_utils.py @@ -28,7 +28,7 @@ def get_spf_domain(hostname) -> [str]: """return all domains listed in *include:*""" try: answers = dns.resolver.query(hostname, "TXT") - except dns.resolver.NoAnswer: + except Exception: return [] ret = [] @@ -49,7 +49,7 @@ def get_spf_domain(hostname) -> [str]: def get_txt_record(hostname) -> [str]: try: answers = dns.resolver.query(hostname, "TXT") - except dns.resolver.NoAnswer: + except Exception: return [] ret = [] @@ -67,7 +67,7 @@ def get_dkim_record(hostname) -> str: """query the dkim._domainkey.{hostname} record and returns its value""" try: answers = dns.resolver.query(f"dkim._domainkey.{hostname}", "TXT") - except dns.resolver.NoAnswer: + except Exception: return "" ret = [] From 3edd5f0b82cbc1ca59738e376aa8a8f59bfab636 Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:21:54 +0100 Subject: [PATCH 7/8] Show something when there's no DNS record --- app/dashboard/templates/dashboard/domain_detail/dns.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/dashboard/templates/dashboard/domain_detail/dns.html b/app/dashboard/templates/dashboard/domain_detail/dns.html index a6a78dc5..6207a708 100644 --- a/app/dashboard/templates/dashboard/domain_detail/dns.html +++ b/app/dashboard/templates/dashboard/domain_detail/dns.html @@ -56,6 +56,9 @@
Your DNS is not correctly set. The MX record we obtain is:
+ {% if not mx_errors %} + (Empty) + {% endif %} {% for r in mx_errors %} {{ r }}
{% endfor %} @@ -112,6 +115,10 @@
Your DNS is not correctly set. The TXT record we obtain is:
+ {% if not spf_errors %} + (Empty) + {% endif %} + {% for r in spf_errors %} {{ r }}
{% endfor %} From ab3fe8a6267b5aee4ea7da35801c52a24f7e46bc Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 2 Jan 2020 22:22:09 +0100 Subject: [PATCH 8/8] Flash errors when MX, SPF or DKIM fail --- app/dashboard/views/domain_detail.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/dashboard/views/domain_detail.py b/app/dashboard/views/domain_detail.py index c0557c26..88bcf98b 100644 --- a/app/dashboard/views/domain_detail.py +++ b/app/dashboard/views/domain_detail.py @@ -34,6 +34,7 @@ def domain_detail_dns(custom_domain_id): mx_domains = get_mx_domains(custom_domain.domain) if sorted(mx_domains) != sorted(EMAIL_SERVERS_WITH_PRIORITY): + flash("The MX record is not correctly set", "warning") mx_ok = False # build mx_errors to show to user mx_errors = [ @@ -63,7 +64,10 @@ def domain_detail_dns(custom_domain_id): ) ) else: - flash(f"{EMAIL_DOMAIN} is not included in your SPF record.", "warning") + flash( + f"SPF: {EMAIL_DOMAIN} is not included in your SPF record.", + "warning", + ) spf_ok = False spf_errors = get_txt_record(custom_domain.domain) @@ -81,6 +85,7 @@ def domain_detail_dns(custom_domain_id): ) ) else: + flash("DKIM: the TXT record is not correctly set", "warning") dkim_ok = False dkim_errors = get_txt_record(f"dkim._domainkey.{custom_domain.domain}")