forked from technion/maia_mailguard
/
stats.php
280 lines (260 loc) · 11.1 KB
/
stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
/*
* $Id: stats.php 1439 2009-11-17 23:31:04Z dmorton $
*
* MAIA MAILGUARD LICENSE v.1.0
*
* Copyright 2004 by Robert LeBlanc <rjl@renaissoft.com>
* David Morton <mortonda@dgrmm.net>
* All rights reserved.
*
* PREAMBLE
*
* This License is designed for users of Maia Mailguard
* ("the Software") who wish to support the Maia Mailguard project by
* leaving "Maia Mailguard" branding information in the HTML output
* of the pages generated by the Software, and providing links back
* to the Maia Mailguard home page. Users who wish to remove this
* branding information should contact the copyright owner to obtain
* a Rebranding License.
*
* DEFINITION OF TERMS
*
* The "Software" refers to Maia Mailguard, including all of the
* associated PHP, Perl, and SQL scripts, documentation files, graphic
* icons and logo images.
*
* GRANT OF LICENSE
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgment:
*
* "This product includes software developed by Robert LeBlanc
* <rjl@renaissoft.com>."
*
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. At least one of the following branding conventions must be used:
*
* a. The Maia Mailguard logo appears in the page-top banner of
* all HTML output pages in an unmodified form, and links
* directly to the Maia Mailguard home page; or
*
* b. The "Powered by Maia Mailguard" graphic appears in the HTML
* output of all gateway pages that lead to this software,
* linking directly to the Maia Mailguard home page; or
*
* c. A separate Rebranding License is obtained from the copyright
* owner, exempting the Licensee from 4(a) and 4(b), subject to
* the additional conditions laid out in that license document.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
require_once ("core.php");
require_once ("maia_db.php");
require_once ("authcheck.php");
require_once ("display.php");
$display_language = get_display_language($euid);
require_once ("./locale/$display_language/db.php");
require_once ("./locale/$display_language/display.php");
require_once ("./locale/$display_language/stats.php");
require_once ("smarty.php");
if (isset($_GET["id"])) {
$id = trim($_GET["id"]);
if (($id != 0) && (!is_an_administrator($uid))) {
$id = $euid;
}
} else {
$id = $euid;
}
$smarty->assign("user_id", $id);
$select = "SELECT currency_label, enable_false_negative_management, " .
"enable_virus_scanning, enable_spam_filtering, " .
"enable_bad_header_checking, enable_banned_files_checking, enable_charts " .
"FROM maia_config WHERE id = 0";
$sth = $dbh->prepare($select);
$res = $sth->execute();
if (PEAR::isError($sth)) {
die($sth->getMessage());
}
if ($row = $res->fetchrow()) {
$currency_label = $row["currency_label"];
$enable_false_negative_management = ($row["enable_false_negative_management"] == 'Y');
$enable_virus_scanning = ($row["enable_virus_scanning"] == 'Y');
$enable_spam_filtering = ($row["enable_spam_filtering"] == 'Y');
$enable_bad_header_checking = ($row["enable_bad_header_checking"] == 'Y');
$enable_banned_files_checking = ($row["enable_banned_files_checking"] == 'Y');
$enable_charts = ($row["enable_charts"] == 'Y');
}
$sth->free();
if ($enable_charts) {
$select = "SELECT charts FROM maia_users WHERE id=?";
$sth = $dbh->prepare($select);
$res = $sth->execute($euid);
if (PEAR::isError($sth)) {
die($sth->getMessage());
}
if ($row = $res->fetchrow()) {
$enable_charts = ($row["charts"] == 'Y');
}
$sth->free();
}
update_mail_stats($id, "suspected_ham");
update_mail_stats($id, "suspected_spam");
$showmail = ok_to_impersonate($euid, $uid);
if ($id > 0) {
$header = sprintf($lang['header_user'], get_user_name($id));
} else {
$header = $lang['header_systemwide'];
}
$smarty->assign("header", $header);
$smarty->assign("currency_label", $currency_label);
$smarty->assign("is_a_visitor", false);
$smarty->assign("msid", $msid);
$smarty->assign("sid", $sid);
$smarty->assign("enable_virus_scanning", $enable_virus_scanning);
$smarty->assign("enable_spam_filtering", $enable_spam_filtering);
$smarty->assign("enable_charts", $enable_charts);
// $smarty->assign("showmail", $showmail);
list($ppv_pct, $npv_pct, $sensitivity_pct, $specificity_pct, $efficiency_pct, $fp_pct, $fn_pct) = get_filter_stats($id);
$smarty->assign("ppv_pct", $ppv_pct);
$smarty->assign("npv_pct", $npv_pct);
$smarty->assign("sensitivity_pct", $sensitivity_pct);
$smarty->assign("specificity_pct", $specificity_pct);
$smarty->assign("eff_pct", $efficiency_pct);
$smarty->assign("fp_pct", $fp_pct);
$smarty->assign("fn_pct", $fn_pct);
$data = array();
if ($enable_spam_filtering && $enable_false_negative_management) {
$data['suspected_ham'] = get_item_row($id, 'suspected_ham');
}
$data['ham'] = get_item_row($id, 'ham');
if ($enable_spam_filtering) {
$data['fp'] = get_item_row($id, "fp");
$data['suspected_spam'] = get_item_row($id, "suspected_spam");
$data['spam'] = get_item_row($id, "spam");
if ($enable_false_negative_management) {
$data['fn'] = get_item_row($id, "fn");
}
}
$data['wl'] = get_item_row($id, "wl");
$data['bl'] = get_item_row($id, "bl");
if ($enable_virus_scanning) {
$data['virus'] = get_item_row($id, "virus");
}
if ($enable_banned_files_checking) {
$data['banned_file'] = get_item_row($id, "banned_file");
}
if ($enable_bad_header_checking) {
$data['bad_header'] = get_item_row($id, "bad_header");
}
$data['oversized'] = get_item_row($id, "oversized");
$links = array( 'suspected_ham' => "ham",
'suspected_spam' => "spam",
'virus' => "virus",
'banned_file' => "attachment",
'bad_header' => "header",
'ham' => false, // these false values are here to
'bl' => false, // prevent smarty from issueing
'fp' => false, // warnings for undefined indices.
'spam' => false, // I wish smarty would be smarter about this. :(
'fn' => false,
'wl' => false,
'oversized' => false
);
$smarty->assign('links', $links);
$smarty->assign('data', $data);
$smarty->display("stats.tpl");
/*
* get_item_row(): Produces a row of statistics about mail items
* of the specified type received by the specified
* user, or all users if $user_id == 0.
*/
function get_item_row($user_id, $type)
{
global $dbh;
global $lang;
$bandwidth_cost = get_config_value("bandwidth_cost");
$items = count_items($user_id, $type);
if ($items > 0) {
$ret = array();
$ret['items'] = $items;
$total_mail = count_total_mail($user_id);
if ($total_mail > 0) {
$ret['pct'] = sprintf("%.1f%%", 100 * $items / $total_mail);
} else {
$ret['pct'] = "0.0%";
}
$item_size = total_item_size($user_id, $type);
$item_days = count_item_days($user_id, $type);
if ($item_days > 0) {
if ($item_days >= 1) {
$ret['rate'] = sprintf("%.1f", $items / $item_days);
$bandwidth_per_day = $item_size / $item_days;
} else {
$ret['rate'] = $items;
$bandwidth_per_day = $item_size;
}
} else {
$ret['rate'] = "-";
$bandwidth_per_day = 0;
}
if ($type == "ham" || $type == "spam" || $type == "suspected_spam" || $type == "suspected_ham" || $type == "fp" || $type == "fn") {
$ret['minscore'] = sprintf("%.3f", lowest_item_score($user_id, $type));
$ret['maxscore'] = sprintf("%.3f", highest_item_score($user_id, $type));
$ret['avgscore'] = sprintf("%.3f", total_item_score($user_id, $type) / $items);
} else {
$ret['minscore'] = "-";
$ret['maxscore'] = "-";
$ret['avgscore'] = "-";
}
$ret['minsize'] = sprintf("%.1f", smallest_item_size($user_id, $type) / KILOBYTE);
$ret['maxsize'] = sprintf("%.1f", largest_item_size($user_id, $type) / KILOBYTE);
$ret['avgsize'] = sprintf("%.1f", $item_size / $items / KILOBYTE);
if ($bandwidth_per_day > 0) {
$ret['bandwidth'] = sprintf("%.2f", $bandwidth_per_day / MEGABYTE);
} else {
$ret['bandwidth'] = "-";
}
$ret['cost'] = sprintf("%.3f", $bandwidth_cost * $bandwidth_per_day / GIGABYTE);
} else {
$ret = array(
'items' => "-",
'rate' => "-",
'minscore' => "-",
'maxscore' => "-",
'avgscore' => "-",
'minsize' => "-",
'maxsize' => "-",
'avgsize' => "-",
'bandwidth' => "-",
'cost' => "-",
'pct' => "-"
);
}
return $ret;
}
?>