1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-12-24 07:37:04 +00:00

Merge branch 'mailgraph' into extended

This commit is contained in:
John Supplee 2019-03-09 11:11:13 +02:00
commit d2d8586f21
4 changed files with 87 additions and 1 deletions

View File

@ -1,5 +1,7 @@
import os, os.path, re, json, time import os, os.path, re, json, time
import subprocess import subprocess
import base64
import sys
from functools import wraps from functools import wraps
@ -594,6 +596,37 @@ def default_quota_set():
return "OK" 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 # MUNIN
@app.route('/munin/') @app.route('/munin/')

View File

@ -102,6 +102,7 @@
<li><a href="#mail-guide" onclick="return show_panel(this);">Instructions</a></li> <li><a href="#mail-guide" onclick="return show_panel(this);">Instructions</a></li>
<li><a href="#users" onclick="return show_panel(this);">Users</a></li> <li><a href="#users" onclick="return show_panel(this);">Users</a></li>
<li><a href="#aliases" onclick="return show_panel(this);">Aliases</a></li> <li><a href="#aliases" onclick="return show_panel(this);">Aliases</a></li>
<li><a href="#mailgraph" onclick="return show_panel(this);">Mailgraph</a></li>
</ul> </ul>
</li> </li>
<li><a href="#sync_guide" onclick="return show_panel(this);">Contacts/Calendar</a></li> <li><a href="#sync_guide" onclick="return show_panel(this);">Contacts/Calendar</a></li>
@ -151,6 +152,10 @@
{% include "sync-guide.html" %} {% include "sync-guide.html" %}
</div> </div>
<div id="panel_mailgraph" class="admin_panel">
{% include "mailgraph.html" %}
</div>
<div id="panel_web" class="admin_panel"> <div id="panel_web" class="admin_panel">
{% include "web.html" %} {% include "web.html" %}
</div> </div>

View File

@ -0,0 +1,48 @@
<h2>Mail statistics</h2>
<ul id="jump">
<li><a href="#G0">Day</a>&nbsp;</li>
<li><a href="#G1">Week</a>&nbsp;</li>
<li><a href="#G2">Month</a>&nbsp;</li>
<li><a href="#G3">Year</a>&nbsp;</li>
</ul>
<h3 id="G0">Last Day</h3>
<p><img src="" data-src="/mailgraph/image.cgi?0-n" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?0-e" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?0-g" alt="mailgraph"/></p>
<h3 id="G1">Last Week</h3>
<p><img src="" data-src="/mailgraph/image.cgi?1-n" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?1-e" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?1-g" alt="mailgraph"/></p>
<h3 id="G2">Last Month</h3>
<p><img src="" data-src="/mailgraph/image.cgi?2-n" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?2-e" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?2-g" alt="mailgraph"/></p>
<h3 id="G3">Last Year</h3>
<p><img src="" data-src="/mailgraph/image.cgi?3-n" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?3-e" alt="mailgraph"/></p>
<p><img src="" data-src="/mailgraph/image.cgi?3-g" alt="mailgraph"/></p>
<hr/>
<p><a href="http://mailgraph.schweikert.ch/">Mailgraph</a> 1.14 by <a href="http://david.schweikert.ch/">David Schweikert</a>
(built on Tobi Oetiker's <a href="http://oss.oetiker.ch/rrdtool/">RRDtool</a>)</p>
<script type="text/javascript">
function show_mailgraph() {
$('[data-src]').each(function() {
var that = this;
api(
$(that).attr('data-src'),
'GET',
'',
function(data) {
$(that).attr('src', 'data:image/gif;base64,' + data);
}
);
});
}
</script>

View File

@ -19,7 +19,7 @@ fi
echo "Installing Nginx (web server)..." 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 rm -f /etc/nginx/sites-enabled/default