3
# Copyright (c) 2010, 2011, The OpenDKIM Project. All rights reserved.
5
# Script to generate some HTML-ized statistics for OpenDKIM
11
# Command to perform a MySQL query and output HTML
12
MYSQL_CMD="mysql -s -N"
15
DB=${OPENDKIM_DB:-opendkim}
18
USER=${OPENDKIM_USER:-opendkim}
20
# Database user's password
21
PASSWORD=${OPENDKIM_PASSWORD:-password}
23
# Where to write the report
24
REALOUTPUT=${OPENDKIM_OUTPUT:-/var/www/docs/opendkim/graphs.html}
25
OUTPUT=${REALOUTPUT}.$$
26
GRAPHDIR=`dirname $REALOUTPUT`
29
DOMAINS=${OPENDKIM_DOMAINS:-"gmail.com,yahoo.com,paypal.com"}
32
### NO user-serviceable parts beyond this point
35
MYSQL="$MYSQL_CMD --user=$USER --password=$PASSWORD --database=$DB"
39
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
43
OpenDKIM Statistics Report (Part II)
50
echo "<h1>OpenDKIM Statistics Report (Part II) generated at `date` </h1>" >> $OUTPUT
51
echo "<hr>" >> $OUTPUT
52
echo "<ul>" >> $OUTPUT
53
for i in $(echo $DOMAINS | awk -F, '{for (c = 1; c <= NF; c++) print $c;}')
55
echo '<li> <a href="'#$i'">'$i'</a>' >> $OUTPUT
57
echo '<li> <a href="#unsigned">unsigned</a>' >> $OUTPUT
58
echo "</ul>" >> $OUTPUT
59
echo "<hr>" >> $OUTPUT
61
for i in $(echo $DOMAINS | awk -F, '{for (c = 1; c <= NF; c++) print $c;}')
63
echo '<a name="'$i'"></a>' >> $OUTPUT
64
echo "<p> $i: </p>" >> $OUTPUT
65
$MYSQL --execute="SELECT t1.x, t1.y, COUNT(*)/10 FROM (SELECT COUNT(*) AS x, SUM(spam) AS y FROM messages JOIN reporters ON reporters.id = messages.reporter JOIN signatures ON signatures.message = messages.id JOIN domains ON domains.id = signatures.domain WHERE enabled = 1 AND NOT spam = -1 AND domains.name = '"$i"' GROUP BY DATE(msgtime)) AS t1 GROUP BY t1.x, t1.y" > /tmp/ogg.data.$$
66
cat > /tmp/ogg.script.$$ << EOF
75
set terminal png size 800,600
77
echo set title \"$i received-spam scatter plot\" >> /tmp/ogg.script.$$
78
echo set output '"'/tmp/ogg.png.$$'"' >> /tmp/ogg.script.$$
79
echo plot '"'/tmp/ogg.data.$$'"' using 1:2:3 notitle with circles >> /tmp/ogg.script.$$
80
gnuplot /tmp/ogg.script.$$ | fgrep -v "empty y"
81
rm -f /tmp/ogg.script.$$ -f /tmp/ogg.data.$$
82
mv /tmp/ogg.png.$$ $GRAPHDIR/$i.png
83
echo '<img src="'$i.png'">' >> $OUTPUT
87
echo '<a name="unsigned"></a>' >> $OUTPUT
88
echo "<p> unsigned mail: </p>" >> $OUTPUT
89
$MYSQL --execute="SELECT t1.msgs, t1.spam, COUNT(*) FROM (SELECT COUNT(*) AS msgs, SUM(spam) AS spam FROM messages JOIN reporters ON reporters.id = messages.reporter WHERE enabled = 1 AND NOT EXISTS (SELECT * FROM signatures WHERE signatures.message = messages.id AND signatures.pass = 1) AND NOT spam = -1 GROUP BY DATE(msgtime)) AS t1 GROUP BY t1.msgs, t1.spam" > /tmp/ogg.data.$$
90
cat > /tmp/ogg.script.$$ << EOF
99
set terminal png size 800,600
101
echo set title \"unsigned mail received-spam scatter plot\" >> /tmp/ogg.script.$$
102
echo set output '"'/tmp/ogg.png.$$'"' >> /tmp/ogg.script.$$
103
echo plot '"'/tmp/ogg.data.$$'"' using 1:2:3 notitle with circles >> /tmp/ogg.script.$$
104
gnuplot /tmp/ogg.script.$$ | fgrep -v "empty y"
105
rm -f /tmp/ogg.script.$$ -f /tmp/ogg.data.$$
106
mv /tmp/ogg.png.$$ $GRAPHDIR/unsigned.png
107
echo '<img src="unsigned.png">' >> $OUTPUT
111
echo "<hr>" >> $OUTPUT
112
echo '<font size="-1"> <i> $Id: opendkim-gengraphs,v 1.26 2010/10/27 06:18:45 cm-msk Exp $ </i> </font>' >> $OUTPUT
113
cat >> $OUTPUT << EOF
119
mv $OUTPUT $REALOUTPUT