diff --git a/management/daemon.py b/management/daemon.py index 4812b824..1b232d89 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 @@ -594,6 +596,37 @@ def default_quota_set(): return "OK" + +# Mailgraph + +@app.route('/mailgraph/image.cgi', methods=['GET']) +@authorized_personnel_only +def mailgraph(): + if request.query_string: + query = request.query_string.decode('utf-8', 'ignore') + if '&' in query: + query = query.split('&')[0] + + print("QUERY_STRING=%s" % query, file=sys.stderr) + + code, bin_out = utils.shell( + "check_output", + ["/usr/share/mailgraph/mailgraph.cgi"], + env={"QUERY_STRING": query}, + return_bytes=True, + trap=True + ) + + if code != 0: + return ('Error generating mailgraph image: %s' % query, 500) + + headers, image_bytes = bin_out.split(b'\n\n', 1) + + return base64.b64encode(image_bytes) + + return ('Mailgraph: no image requested', 500) + + # MUNIN @app.route('/munin/') diff --git a/management/templates/index.html b/management/templates/index.html index 2c0d5a9a..26d25e4a 100644 --- a/management/templates/index.html +++ b/management/templates/index.html @@ -102,6 +102,7 @@
  • Instructions
  • Users
  • Aliases
  • +
  • Mailgraph
  • Contacts/Calendar
  • @@ -151,6 +152,10 @@ {% include "sync-guide.html" %} +
    + {% include "mailgraph.html" %} +
    +
    {% include "web.html" %}
    diff --git a/management/templates/mailgraph.html b/management/templates/mailgraph.html new file mode 100644 index 00000000..91577512 --- /dev/null +++ b/management/templates/mailgraph.html @@ -0,0 +1,48 @@ +

    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)

    + + diff --git a/setup/web.sh b/setup/web.sh index ad7ad310..bd839153 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