load images as base64

This commit is contained in:
John Supplee 2019-03-03 19:15:59 +02:00
parent dce4058705
commit 6883a60f5d
2 changed files with 23 additions and 19 deletions

View File

@ -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)

View File

@ -7,24 +7,24 @@
</ul>
<h3 id="G0">Last Day</h3>
<p><img src="" data-src="/admin/mailgraph/image.cgi?0-n" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?0-e" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?0-g" alt="mailgraph"/></p>
<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="/admin/mailgraph/image.cgi?1-n" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?1-e" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?1-g" alt="mailgraph"/></p>
<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="/admin/mailgraph/image.cgi?2-n" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?2-e" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?2-g" alt="mailgraph"/></p>
<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="/admin/mailgraph/image.cgi?3-n" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?3-e" alt="mailgraph"/></p>
<p><img src="" data-src="/admin/mailgraph/image.cgi?3-g" alt="mailgraph"/></p>
<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/>
@ -34,7 +34,14 @@
<script type="text/javascript">
function show_mailgraph() {
$('[data-src]').each(function() {
$(this).attr('src', $(this).attr('data-src'));
api(
$(this).attr('data-src'),
'GET',
'',
function(data) {
$(this).attr('src', 'data:image/gif;base64,' + data);
}
);
});
}
</script>