From 4e84815375b79e4913863d589dd528f1b70e6da0 Mon Sep 17 00:00:00 2001 From: doanguyen Date: Sun, 5 Jan 2020 19:45:29 +0100 Subject: [PATCH 1/8] let debug configurable --- app/config.py | 2 ++ server.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/config.py b/app/config.py index ae2082ee..11608748 100644 --- a/app/config.py +++ b/app/config.py @@ -30,6 +30,8 @@ COLOR_LOG = "COLOR_LOG" in os.environ # Allow user to have 1 year of premium: set the expiration_date to 1 year more PROMO_CODE = "SIMPLEISBETTER" +# Debug mode +DEBUG = os.environ['DEBUG'] # Server url URL = os.environ["URL"] print(">>> URL:", URL) diff --git a/server.py b/server.py index 08d95c42..5425b926 100644 --- a/server.py +++ b/server.py @@ -18,6 +18,7 @@ from app.admin_model import SLModelView, SLAdminIndexView from app.api.base import api_bp from app.auth.base import auth_bp from app.config import ( + DEBUG, DB_URI, FLASK_SECRET, SENTRY_DSN, @@ -67,6 +68,8 @@ os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" def create_app() -> Flask: app = Flask(__name__) app.url_map.strict_slashes = False + app.debug = DEBUG + os.environ["FLASK_DEBUG"] = DEBUG app.config["SQLALCHEMY_DATABASE_URI"] = DB_URI app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False @@ -422,8 +425,6 @@ window.location.href = "/"; if __name__ == "__main__": app = create_app() - app.debug = True - # enable flask toolbar # app.config["DEBUG_TB_PROFILER_ENABLED"] = True # app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False @@ -444,6 +445,6 @@ if __name__ == "__main__": context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) context.load_cert_chain("local_data/cert.pem", "local_data/key.pem") - app.run(debug=True, host="0.0.0.0", port=7777, ssl_context=context) + app.run(host="0.0.0.0", port=7777, ssl_context=context) else: - app.run(debug=True, host="0.0.0.0", port=7777) + app.run(host="0.0.0.0", port=7777) From 5af974fc5d4681e92319c58e00867008890c32f9 Mon Sep 17 00:00:00 2001 From: doanguyen Date: Sun, 5 Jan 2020 22:49:48 +0100 Subject: [PATCH 2/8] alias log dashboard --- app/config.py | 4 +- .../templates/dashboard/alias_log.html | 93 ++++++++++++++++++- app/dashboard/views/alias_log.py | 9 ++ 3 files changed, 103 insertions(+), 3 deletions(-) diff --git a/app/config.py b/app/config.py index 11608748..6da3176c 100644 --- a/app/config.py +++ b/app/config.py @@ -31,7 +31,7 @@ COLOR_LOG = "COLOR_LOG" in os.environ PROMO_CODE = "SIMPLEISBETTER" # Debug mode -DEBUG = os.environ['DEBUG'] +DEBUG = os.environ["DEBUG"] # Server url URL = os.environ["URL"] print(">>> URL:", URL) @@ -45,7 +45,7 @@ SUPPORT_EMAIL = os.environ["SUPPORT_EMAIL"] ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL") MAX_NB_EMAIL_FREE_PLAN = int(os.environ["MAX_NB_EMAIL_FREE_PLAN"]) # allow to override postfix server locally -POSTFIX_SERVER = os.environ.get("POSTFIX_SERVER", "1.1.1.1") +POSTFIX_SERVER = os.environ.get("POSTFIX_SERVER", "0.0.0.0") # list of (priority, email server) EMAIL_SERVERS_WITH_PRIORITY = eval( diff --git a/app/dashboard/templates/dashboard/alias_log.html b/app/dashboard/templates/dashboard/alias_log.html index 59c40d06..2382d3c1 100644 --- a/app/dashboard/templates/dashboard/alias_log.html +++ b/app/dashboard/templates/dashboard/alias_log.html @@ -1,7 +1,68 @@ {% extends 'default.html' %} {% set active_page = "dashboard" %} +{% block head %} + +{% endblock %} {% block title %} Alias Activity {% endblock %} @@ -12,7 +73,37 @@ {{ alias }} - +
+
+
+ + {{ total }} + Email Handled +
+
+
+
+ + {{ email_forwarded }} + Email Forwarded +
+
+
+
+ + {{ email_replied }} + Email Replied +
+
+
+
+ + {{ email_forwarded }} + Email Blocked +
+
+
+

Activities

{% for log in logs %}
diff --git a/app/dashboard/views/alias_log.py b/app/dashboard/views/alias_log.py index d7ec6388..afc790f2 100644 --- a/app/dashboard/views/alias_log.py +++ b/app/dashboard/views/alias_log.py @@ -38,6 +38,15 @@ def alias_log(alias, page_id): return redirect(url_for("dashboard.index")) logs = get_alias_log(gen_email, page_id) + base = ( + db.session.query(ForwardEmail, ForwardEmailLog) + .filter(ForwardEmail.id == ForwardEmailLog.forward_id) + .filter(ForwardEmail.gen_email_id == gen_email.id) + ) + total = base.count() + email_forwarded = base.filter(ForwardEmailLog.is_reply == False).count() + email_replied = base.filter(ForwardEmailLog.is_reply == True).count() + email_blocked = base.filter(ForwardEmailLog.blocked == True).count() last_page = ( len(logs) < _LIMIT ) # lightweight pagination without counting all objects From 5ffdc45c8703d010c77d92edb4a9247a236626de Mon Sep 17 00:00:00 2001 From: doanguyen Date: Sun, 5 Jan 2020 22:53:00 +0100 Subject: [PATCH 3/8] fix DEBUG flag is not default in os environment --- app/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config.py b/app/config.py index 6da3176c..ace7ae05 100644 --- a/app/config.py +++ b/app/config.py @@ -31,7 +31,7 @@ COLOR_LOG = "COLOR_LOG" in os.environ PROMO_CODE = "SIMPLEISBETTER" # Debug mode -DEBUG = os.environ["DEBUG"] +DEBUG = os.environ["DEBUG"] if "DEBUG" in os.environ else False # Server url URL = os.environ["URL"] print(">>> URL:", URL) From 783aba12757dc3b00d6386390627d255d10d08e9 Mon Sep 17 00:00:00 2001 From: doanguyen Date: Sun, 5 Jan 2020 22:58:40 +0100 Subject: [PATCH 4/8] flask debug must be string, not bool, int. What a joke --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 5425b926..16ff725a 100644 --- a/server.py +++ b/server.py @@ -69,7 +69,7 @@ def create_app() -> Flask: app = Flask(__name__) app.url_map.strict_slashes = False app.debug = DEBUG - os.environ["FLASK_DEBUG"] = DEBUG + os.environ["FLASK_DEBUG"] = str(DEBUG) app.config["SQLALCHEMY_DATABASE_URI"] = DB_URI app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False From 8f1c56baf989fcc60dcca4216adc4db6f7416d5c Mon Sep 17 00:00:00 2001 From: doanguyen Date: Sun, 5 Jan 2020 23:03:56 +0100 Subject: [PATCH 5/8] forget to push this local configuration --- app/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config.py b/app/config.py index ace7ae05..3473ce8d 100644 --- a/app/config.py +++ b/app/config.py @@ -45,7 +45,7 @@ SUPPORT_EMAIL = os.environ["SUPPORT_EMAIL"] ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL") MAX_NB_EMAIL_FREE_PLAN = int(os.environ["MAX_NB_EMAIL_FREE_PLAN"]) # allow to override postfix server locally -POSTFIX_SERVER = os.environ.get("POSTFIX_SERVER", "0.0.0.0") +POSTFIX_SERVER = os.environ.get("POSTFIX_SERVER", "1.1.1.1") # list of (priority, email server) EMAIL_SERVERS_WITH_PRIORITY = eval( From 6a99fd30c4cd14c089f9468b97e670142fc098af Mon Sep 17 00:00:00 2001 From: doanguyen Date: Mon, 6 Jan 2020 23:58:24 +0100 Subject: [PATCH 6/8] fix some minor bugs --- app/dashboard/templates/dashboard/alias_log.html | 2 +- app/dashboard/views/alias_log.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dashboard/templates/dashboard/alias_log.html b/app/dashboard/templates/dashboard/alias_log.html index 2382d3c1..130a37b5 100644 --- a/app/dashboard/templates/dashboard/alias_log.html +++ b/app/dashboard/templates/dashboard/alias_log.html @@ -98,7 +98,7 @@
- {{ email_forwarded }} + {{ email_blocked }} Email Blocked
diff --git a/app/dashboard/views/alias_log.py b/app/dashboard/views/alias_log.py index afc790f2..12221ded 100644 --- a/app/dashboard/views/alias_log.py +++ b/app/dashboard/views/alias_log.py @@ -44,7 +44,7 @@ def alias_log(alias, page_id): .filter(ForwardEmail.gen_email_id == gen_email.id) ) total = base.count() - email_forwarded = base.filter(ForwardEmailLog.is_reply == False).count() + email_forwarded = base.filter(ForwardEmailLog.is_reply == False).filter(ForwardEmailLog.blocked==False).count() email_replied = base.filter(ForwardEmailLog.is_reply == True).count() email_blocked = base.filter(ForwardEmailLog.blocked == True).count() last_page = ( From d804a28c071a204ca3640e7f99aca4a57f858469 Mon Sep 17 00:00:00 2001 From: doanguyen Date: Tue, 7 Jan 2020 00:02:12 +0100 Subject: [PATCH 7/8] fix the format, again --- app/dashboard/views/alias_log.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/dashboard/views/alias_log.py b/app/dashboard/views/alias_log.py index 12221ded..6878b130 100644 --- a/app/dashboard/views/alias_log.py +++ b/app/dashboard/views/alias_log.py @@ -44,7 +44,11 @@ def alias_log(alias, page_id): .filter(ForwardEmail.gen_email_id == gen_email.id) ) total = base.count() - email_forwarded = base.filter(ForwardEmailLog.is_reply == False).filter(ForwardEmailLog.blocked==False).count() + email_forwarded = ( + base.filter(ForwardEmailLog.is_reply == False) + .filter(ForwardEmailLog.blocked == False) + .count() + ) email_replied = base.filter(ForwardEmailLog.is_reply == True).count() email_blocked = base.filter(ForwardEmailLog.blocked == True).count() last_page = ( From c49bc87baef0d09555abf52c8503253acf170584 Mon Sep 17 00:00:00 2001 From: doanguyen Date: Tue, 7 Jan 2020 22:29:37 +0100 Subject: [PATCH 8/8] rollback the debug flag --- server.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 16ff725a..e51272c2 100644 --- a/server.py +++ b/server.py @@ -68,8 +68,6 @@ os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" def create_app() -> Flask: app = Flask(__name__) app.url_map.strict_slashes = False - app.debug = DEBUG - os.environ["FLASK_DEBUG"] = str(DEBUG) app.config["SQLALCHEMY_DATABASE_URI"] = DB_URI app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False @@ -445,6 +443,6 @@ if __name__ == "__main__": context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) context.load_cert_chain("local_data/cert.pem", "local_data/key.pem") - app.run(host="0.0.0.0", port=7777, ssl_context=context) + app.run(debug=True, host="0.0.0.0", port=7777, ssl_context=context) else: - app.run(host="0.0.0.0", port=7777) + app.run(debug=True, host="0.0.0.0", port=7777)