From 887e2927480303014992427ec1bb1a4d023c0785 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 15:30:08 +0200 Subject: [PATCH 01/15] Add changes for mailgraph webserver --- conf/nginx-primaryonly.conf | 10 ++++++++++ setup/web.sh | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/conf/nginx-primaryonly.conf b/conf/nginx-primaryonly.conf index d8d912ca..be6588e2 100644 --- a/conf/nginx-primaryonly.conf +++ b/conf/nginx-primaryonly.conf @@ -64,4 +64,14 @@ rewrite ^/.well-known/carddav /cloud/remote.php/carddav/ redirect; rewrite ^/.well-known/caldav /cloud/remote.php/caldav/ redirect; + location ~ ^/mailgraph/.*\.cgi { + root /usr/share/mailgraph; + include /etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/share/mailgraph/mailgraph.$ + fastcgi_pass unix:/var/run/fcgiwrap.socket; + + auth_basic "box"; + auth_basic_user_file /etc/nginx/htpasswd; + } + # ADDITIONAL DIRECTIVES HERE diff --git a/setup/web.sh b/setup/web.sh index ed37e5e3..6cb1a30b 100755 --- a/setup/web.sh +++ b/setup/web.sh @@ -19,7 +19,7 @@ fi echo "Installing Nginx (web server)..." -apt_install nginx php-cli php-fpm +apt_install nginx php-cli php-fpm fcgiwrap mailgraph rm -f /etc/nginx/sites-enabled/default From 69a50ed9541712b39939a28d9a2d0336a6fb80ac Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 15:39:19 +0200 Subject: [PATCH 02/15] fix error in nginx configuration --- conf/nginx-primaryonly.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx-primaryonly.conf b/conf/nginx-primaryonly.conf index be6588e2..2eeacc6f 100644 --- a/conf/nginx-primaryonly.conf +++ b/conf/nginx-primaryonly.conf @@ -67,7 +67,7 @@ location ~ ^/mailgraph/.*\.cgi { root /usr/share/mailgraph; include /etc/nginx/fastcgi_params; - fastcgi_param SCRIPT_FILENAME /usr/share/mailgraph/mailgraph.$ + fastcgi_param SCRIPT_FILENAME /usr/share/mailgraph/mailgraph.cgi fastcgi_pass unix:/var/run/fcgiwrap.socket; auth_basic "box"; From 8180707cc63ef234f094fc240bbd6f8d2cbcf102 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 15:43:30 +0200 Subject: [PATCH 03/15] add missing semicolon to nginx conf --- conf/nginx-primaryonly.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/nginx-primaryonly.conf b/conf/nginx-primaryonly.conf index 2eeacc6f..552cf28a 100644 --- a/conf/nginx-primaryonly.conf +++ b/conf/nginx-primaryonly.conf @@ -67,7 +67,7 @@ location ~ ^/mailgraph/.*\.cgi { root /usr/share/mailgraph; include /etc/nginx/fastcgi_params; - fastcgi_param SCRIPT_FILENAME /usr/share/mailgraph/mailgraph.cgi + fastcgi_param SCRIPT_FILENAME /usr/share/mailgraph/mailgraph.cgi; fastcgi_pass unix:/var/run/fcgiwrap.socket; auth_basic "box"; From 5615031ef8a040a1fc0a90d65da562cfb6fca787 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 17:23:58 +0200 Subject: [PATCH 04/15] initial work to integrate with control panel --- management/templates/index.html | 1 + management/templates/mailgraph.html | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 management/templates/mailgraph.html diff --git a/management/templates/index.html b/management/templates/index.html index 2c0d5a9a..31fe5916 100644 --- a/management/templates/index.html +++ b/management/templates/index.html @@ -102,6 +102,7 @@
  • Instructions
  • Users
  • Aliases
  • +
  • Reports
  • Contacts/Calendar
  • diff --git a/management/templates/mailgraph.html b/management/templates/mailgraph.html new file mode 100644 index 00000000..9d495b0c --- /dev/null +++ b/management/templates/mailgraph.html @@ -0,0 +1,32 @@ +

    Mail statistics

    + + +

    Last Day

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    + +

    Last Week

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    + +

    Last Month

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    + +

    Last Year

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    + +
    + +

    Mailgraph 1.14 by David Schweikert +(built on Tobi Oetiker's RRDtool)

    From fefb5ebc3342cf8a07520091b4fbd7f0da4cdfb6 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 20:16:39 +0200 Subject: [PATCH 05/15] more work on control panel integration --- management/daemon.py | 14 ++++++++++++ management/templates/index.html | 2 +- management/templates/mailgraph.html | 34 ++++++++++++++--------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index 572b6b4a..918370ef 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -520,6 +520,20 @@ def privacy_status_set(): utils.write_settings(config, env) return "OK" +# Mailgraph + +@app.route('/mailgraph/image.cgi') +@authorized_personnel_only +def mailgraph(): + if request.query_string: + return utils.shell( + "check_output", + ["/usr/share/mailgraph/mailgraph.cgi"], + env={"QUERY_STRING": request.query_string} + ) + return '' + + # MUNIN @app.route('/munin/') diff --git a/management/templates/index.html b/management/templates/index.html index 31fe5916..9f8b8652 100644 --- a/management/templates/index.html +++ b/management/templates/index.html @@ -102,7 +102,7 @@
  • Instructions
  • Users
  • Aliases
  • -
  • Reports
  • +
  • Mailgraph
  • Contacts/Calendar
  • diff --git a/management/templates/mailgraph.html b/management/templates/mailgraph.html index 9d495b0c..8b1ad893 100644 --- a/management/templates/mailgraph.html +++ b/management/templates/mailgraph.html @@ -1,4 +1,4 @@ -

    Mail statistics

    +

    Mail statistics

    -

    Last Day

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    Last Day

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    -

    Last Week

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    Last Week

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    -

    Last Month

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    Last Month

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    -

    Last Year

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    Last Year

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph


    From fd239db7c1e2ae92bb9bcdfec5c8b65cec373723 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 20:22:08 +0200 Subject: [PATCH 06/15] integrate template --- management/templates/index.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/management/templates/index.html b/management/templates/index.html index 9f8b8652..26d25e4a 100644 --- a/management/templates/index.html +++ b/management/templates/index.html @@ -152,6 +152,10 @@ {% include "sync-guide.html" %} +
    + {% include "mailgraph.html" %} +
    +
    {% include "web.html" %}
    From d41cdb844cb6965aa2958b5627b8e88d149ff2de Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 20:31:24 +0200 Subject: [PATCH 07/15] remove nginx config for Mailgraph --- conf/nginx-primaryonly.conf | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/conf/nginx-primaryonly.conf b/conf/nginx-primaryonly.conf index 552cf28a..d8d912ca 100644 --- a/conf/nginx-primaryonly.conf +++ b/conf/nginx-primaryonly.conf @@ -64,14 +64,4 @@ rewrite ^/.well-known/carddav /cloud/remote.php/carddav/ redirect; rewrite ^/.well-known/caldav /cloud/remote.php/caldav/ redirect; - location ~ ^/mailgraph/.*\.cgi { - root /usr/share/mailgraph; - include /etc/nginx/fastcgi_params; - fastcgi_param SCRIPT_FILENAME /usr/share/mailgraph/mailgraph.cgi; - fastcgi_pass unix:/var/run/fcgiwrap.socket; - - auth_basic "box"; - auth_basic_user_file /etc/nginx/htpasswd; - } - # ADDITIONAL DIRECTIVES HERE From 5ffa71999ac42001fcc825a717a53741f54c32ea Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 20:47:54 +0200 Subject: [PATCH 08/15] work on the daemon for mailgraph --- management/daemon.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index 918370ef..54b1a565 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -526,12 +526,21 @@ def privacy_status_set(): @authorized_personnel_only def mailgraph(): if request.query_string: - return utils.shell( + print("QUERY_STRING=%s" % request.query_string) + + code, bin_out = utils.shell( "check_output", ["/usr/share/mailgraph/mailgraph.cgi"], - env={"QUERY_STRING": request.query_string} + env={"QUERY_STRING": request.query_string}, + return_bytes=True ) - return '' + + if code != 0: + return ('Error generating mailgraph image: %s' % request.query_string, 500) + + return make_response(bin_out) + + return ('Mailgraph: no image requested', 500) # MUNIN From 89677584132d62c0d1152335459887202be599f5 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 23:18:44 +0200 Subject: [PATCH 09/15] Only load mailgraph images when the page is viewed --- management/templates/mailgraph.html | 32 ++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/management/templates/mailgraph.html b/management/templates/mailgraph.html index 8b1ad893..fc96f9b1 100644 --- a/management/templates/mailgraph.html +++ b/management/templates/mailgraph.html @@ -7,26 +7,34 @@

    Last Day

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Week

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Month

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Year

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph


    Mailgraph 1.14 by David Schweikert (built on Tobi Oetiker's RRDtool)

    + + From 5b5087c9dd1bdf35c35b35c411be4bbf550dfd15 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sat, 2 Mar 2019 23:33:45 +0200 Subject: [PATCH 10/15] fix query params for mailgraph images --- management/templates/mailgraph.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/management/templates/mailgraph.html b/management/templates/mailgraph.html index fc96f9b1..086aa9cc 100644 --- a/management/templates/mailgraph.html +++ b/management/templates/mailgraph.html @@ -7,24 +7,24 @@

    Last Day

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Week

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Month

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Year

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph


    From dce4058705714f30c4e8271d26315da75d6a14e3 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sun, 3 Mar 2019 00:34:41 +0200 Subject: [PATCH 11/15] process images returned from mailgraph --- management/daemon.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index 54b1a565..b53c3c40 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -522,23 +522,29 @@ def privacy_status_set(): # Mailgraph -@app.route('/mailgraph/image.cgi') +@app.route('/mailgraph/image.cgi', methods=['GET']) @authorized_personnel_only def mailgraph(): if request.query_string: - print("QUERY_STRING=%s" % request.query_string) + app.logger.error("QUERY_STRING=%s" % request.query_string) code, bin_out = utils.shell( "check_output", ["/usr/share/mailgraph/mailgraph.cgi"], env={"QUERY_STRING": request.query_string}, - return_bytes=True + return_bytes=True, + trap=True ) if code != 0: return ('Error generating mailgraph image: %s' % request.query_string, 500) - return make_response(bin_out) + headers, image_bytes = bin_out.split(b'\n\n', 1) + response = make_response(image_bytes) + for line in headers.splitlines(): + name, value = line.decode("utf8").split(':', 1) + response.headers[name] = value + return response return ('Mailgraph: no image requested', 500) From 6883a60f5d024437a3a8b8a60688a5d73844a91e Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sun, 3 Mar 2019 19:15:59 +0200 Subject: [PATCH 12/15] load images as base64 --- management/daemon.py | 9 +++----- management/templates/mailgraph.html | 33 +++++++++++++++++------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index b53c3c40..7e0d4936 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -521,7 +521,7 @@ def privacy_status_set(): return "OK" # Mailgraph - +import base64 @app.route('/mailgraph/image.cgi', methods=['GET']) @authorized_personnel_only def mailgraph(): @@ -540,11 +540,8 @@ def mailgraph(): return ('Error generating mailgraph image: %s' % request.query_string, 500) headers, image_bytes = bin_out.split(b'\n\n', 1) - response = make_response(image_bytes) - for line in headers.splitlines(): - name, value = line.decode("utf8").split(':', 1) - response.headers[name] = value - return response + + return base64.b64encode(image_bytes) return ('Mailgraph: no image requested', 500) diff --git a/management/templates/mailgraph.html b/management/templates/mailgraph.html index 086aa9cc..25428509 100644 --- a/management/templates/mailgraph.html +++ b/management/templates/mailgraph.html @@ -7,24 +7,24 @@

    Last Day

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Week

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Month

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph

    Last Year

    -

    mailgraph

    -

    mailgraph

    -

    mailgraph

    +

    mailgraph

    +

    mailgraph

    +

    mailgraph


    @@ -34,7 +34,14 @@ From e29e3a5cba43ac3094dd0b776dc1cfd78b5c26ae Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sun, 3 Mar 2019 19:23:58 +0200 Subject: [PATCH 13/15] fix QUERY_STRING to only have the image request --- management/daemon.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index 7e0d4936..b3f5689c 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -526,12 +526,16 @@ import base64 @authorized_personnel_only def mailgraph(): if request.query_string: - app.logger.error("QUERY_STRING=%s" % request.query_string) + query = request.query_string + if '&' in query: + query = query.split('&')[0] + + app.logger.error("QUERY_STRING=%s" % query) code, bin_out = utils.shell( "check_output", ["/usr/share/mailgraph/mailgraph.cgi"], - env={"QUERY_STRING": request.query_string}, + env={"QUERY_STRING": query}, return_bytes=True, trap=True ) From 7600e727c118e92c0338bb32c2908addc2e06445 Mon Sep 17 00:00:00 2001 From: John Supplee Date: Sun, 3 Mar 2019 21:15:16 +0200 Subject: [PATCH 14/15] debugging of image display --- management/daemon.py | 10 ++++++---- management/templates/mailgraph.html | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index b3f5689c..9925245d 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -1,5 +1,7 @@ import os, os.path, re, json, time import subprocess +import base64 +import sys from functools import wraps @@ -521,16 +523,16 @@ def privacy_status_set(): return "OK" # Mailgraph -import base64 + @app.route('/mailgraph/image.cgi', methods=['GET']) @authorized_personnel_only def mailgraph(): if request.query_string: - query = request.query_string + query = request.query_string.decode('utf-8', 'ignore') if '&' in query: query = query.split('&')[0] - app.logger.error("QUERY_STRING=%s" % query) + print("QUERY_STRING=%s" % query, file=sys.stderr) code, bin_out = utils.shell( "check_output", @@ -541,7 +543,7 @@ def mailgraph(): ) if code != 0: - return ('Error generating mailgraph image: %s' % request.query_string, 500) + return ('Error generating mailgraph image: %s' % query, 500) headers, image_bytes = bin_out.split(b'\n\n', 1) diff --git a/management/templates/mailgraph.html b/management/templates/mailgraph.html index 25428509..22d76088 100644 --- a/management/templates/mailgraph.html +++ b/management/templates/mailgraph.html @@ -34,8 +34,9 @@