2 ////////////////////////////////////////////////////////////////////////////////
5 // Revision: $Revision: 1.1 $
6 // Description: Main PHP module to MAPS
7 // Author: Andrew@DeFaria.com
8 // Created: Fri Nov 29 14:17:21 2002
9 // Modified: $Date: 2013/06/12 14:05:48 $
12 // (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
14 ////////////////////////////////////////////////////////////////////////////////
16 if (isset($_REQUEST["userid"])) {
17 $userid = $_REQUEST["userid"];
21 if (!isset($userid)) {
22 // No userid, see if we have a cookie for it
23 $userid=$_COOKIE["MAPSUser"];
39 function DBError($msg, $statement) {
42 $errno = mysqli_errno($db);
43 $errmsg = mysqli_error($db);
44 print "$msg<br>Error # $errno $errmsg";
45 print "<br>SQL Statement: $statement";
53 $db = mysqli_connect("127.0.0.1", "maps", "spam")
54 or DBError("OpenDB: Unable to connect to database server", "Connect");
56 mysqli_select_db($db, "MAPS")
57 or DBError("OpenDB: Unable to select MAPS database", "adefaria_maps");
68 function SetContext($new_userid) {
71 $userid = $new_userid;
74 function Encrypt($password, $userid) {
77 $statement = "select hex(aes_encrypt(\"$password\",\"$userid\"))";
79 $result = mysqli_query($db, $statement)
80 or DBError("Encrypt: Unable to execute statement", $statement);
82 // Get return value, which should be the encoded password
83 $row = mysqli_fetch_array($result);
88 function UserExists($userid) {
91 $statement = "select userid, password from user where userid = \"$userid\"";
93 $result = mysqli_query($db, $statement)
94 or DBError ("UserExists: Unable to execute statement", $statement);
96 $row = mysqli_fetch_array($result);
98 $dbuserid = $row["userid"];
99 $dbpassword = $row["password"];
101 if ($dbuserid != $userid) {
108 function Login($userid, $password) {
109 $password = Encrypt($password, $userid);
111 // Check if user exists
112 $dbpassword = UserExists($userid);
114 // Return -1 if user doesn't exist
115 if ($dbpassword == -1) {
119 // Return -2 if password does not match
120 if ($password != $dbpassword) {
123 setcookie("MAPSUser", $userid, time()+60*60*24*30, "/maps");
129 function CountList ($type) {
132 $statement = "select count(*) as count from list where type=\"$type\" and userid=\"$userid\"";
134 $result = mysqli_query($db, $statement)
135 or DBError("CountList: Unable to count list: ", $statement);
137 // How many rows are there?
138 $row = mysqli_fetch_array($result);
140 return $row["count"];
143 function FindList($type, $next, $lines) {
148 $statement = "select * from list where type=\"$type\" and userid=\"$userid\" order by sequence limit $next, $lines";
150 $result = mysqli_query($db, $statement)
151 or DBError ("FindList: Unable to execute query: ", $statement);
153 $count = mysqli_num_rows($result);
155 return array($count, $result);
158 function Today2SQLDatetime() {
159 return date ("Y-m-d H:i:s");
160 } // Today2SQLDatetime
162 function countem($table, $condition) {
165 $statement = "select count(distinct sender) as count from $table where $condition";
167 $result = mysqli_query($db, $statement)
168 or DBError("countem: Unable to perform query: ", $statement);
170 // How many rows are there?
171 $row = mysqli_fetch_array($result);
173 return $row["count"];
176 function countlog($condition="") {
179 if ($condition != "") {
180 return countem("log", "userid=\"$userid\" and " . $condition);
182 return countem("log", "userid=\"$userid\"");
186 function SubtractDays($date, $nbr_days) {
190 function GetStats($nbr_days, $date = "") {
194 $date = Today2SQLDatetime();
197 while ($nbr_days > 0) {
198 $ymd = substr($date, 0, 10);
199 $sod = $ymd . " 00:00:00";
200 $eod = $ymd . " 23:59:59";
202 foreach ($Types as $type) {
203 $condition = "type=\"$type\" and (timestamp > \"$sod\" and timestamp < \"$eod\")";
204 $stats[$type] = countlog($condition);
207 $dates[$ymd] = &$stats;
209 $date = SubtractDays($date, 1);
216 function displayquickstats() {
217 $today = substr (Today2SQLDatetime(), 0, 10);
218 $dates = getquickstats($today);
219 $current_time = date("g:i:s a");
222 print "<div class=\"quickstats\">";
223 print "<h4 align=\"center\" class=\"todaysactivity\">Today's Activity</h4>";
224 print "<p align=\"center\"><b>as of $current_time</b></p>";
226 $processed = $dates[$today]["processed"];
227 $returned = $dates[$today]["returned"];
228 $returned_pct = $processed == 0 ? 0 :
229 number_format ($returned / $processed * 100, 1, ".", "");
230 $whitelist = $dates[$today]["whitelist"];
231 $whitelist_pct = $processed == 0 ? 0 :
232 number_format ($whitelist / $processed * 100, 1, ".", "");
233 $blacklist = $dates[$today]["blacklist"];
234 $blacklist_pct = $processed == 0 ? 0 :
235 number_format ($blacklist / $processed * 100, 1, ".", "");
236 $registered = $dates[$today]["registered"];
237 $mailloop = $dates[$today]["mailloop"];
238 $nulllist = $dates[$today]["nulllist"];
239 $nulllist_pct = $processed == 0 ? 0 :
240 number_format ($nulllist / $processed * 100, 1, ".", "");
242 $returned_link = $returned == 0 ? '' :
243 "<a href=\"/maps/bin/detail.cgi?type=returned;date=$today\">";
244 $whitelist_link = $whitelist == 0 ? '' :
245 "<a href=\"/maps/bin/detail.cgi?type=whitelist;date=$today\">";
246 $blacklist_link = $blacklist == 0 ? '' :
247 "<a href=\"/maps/bin/detail.cgi?type=blacklist;date=$today\">";
248 $registered_link = $registered == 0 ? '' :
249 "<a href=\"/maps/bin/detail.cgi?type=registered;date=$today\">";
250 $mailloop_link = $mailloop == 0 ? '' :
251 "<a href=\"/maps/bin/detail.cgi?type=mailloop;date=$today>\"";
252 $nulllist_link = $nulllist == 0 ? '' :
253 "<a href=\"/maps/bin/detail.cgi?type=nulllist;date=$today\">";
256 <div id="quickstats">
257 <table cellpadding="2" border="0" align="center" cellspacing="0">
259 <td align="left" class="smalllabel">Processed</td>
260 <td align="right" class="smallnumber">$processed</td>
261 <td align="right" class="smallnumber">n/a</td>
264 <td class="smalllabel">${nulllist_link}Nulllist</a></td>
265 <td class="smallnumber">$nulllist</td>
266 <td class="smallnumber">$nulllist_pct%</td>
269 <td class="smalllabel">${returned_link}Returned</a></td>
270 <td class=smallnumber>$returned</td>
271 <td class="smallnumber">$returned_pct%</td>
274 <td class="smalllabel">${whitelist_link}Whitelist</a></td>
275 <td class="smallnumber">$whitelist</td>
276 <td class="smallnumber">$whitelist_pct%</td>
279 <td class="smalllabel">${blacklist_link}Blacklist</a></td>
280 <td class="smallnumber">$blacklist</td>
281 <td class="smallnumber">$blacklist_pct%</td>
284 <td class="smalllabel">${registered_link}Registered</a></td>
285 <td class="smallnumber">$registered</td>
286 <td class="smallnumber">n/a</td>
289 <td class="smalllabel">${mailloop_link}Mailloop</a></td>
290 <td class="smallnumber">$mailloop</td>
291 <td class="smallnumber">n/a</td>
297 } // displayquickstats
299 function getquickstats($date) {
302 $dates = GetStats(1, $date);
304 foreach ($Types as $type) {
305 if (isset ($dates[$date]["processed"])) {
306 $dates[$date]["processed"] += $dates[$date][$type];
308 $dates[$date]["processed"] = $dates[$date][$type];
315 function NavigationBar($userid) {
316 print "<div id=leftbar>";
318 if (!isset ($userid) || $userid == "") {
320 <h2 align='center'><font style="color: white">MAPS 2.0</font></h2>
321 <div class="username">Welcome to MAPS</div>
323 <a href="/maps/doc/">What is MAPS?</a><br>
324 <a href="/maps/doc/SPAM.php">What is SPAM?</a><br>
325 <a href="/maps/doc/Requirements.php">Requirements</a><br>
326 <a href="/maps/SignupForm.html">Signup</a><br>
327 <a href="/maps/doc/Using.php">Using MAPS</a><br>
328 <a href="/maps/doc/">Help</a><br>
332 $Userid = ucfirst($userid);
334 <h2 align='center'><font style="color: white">MAPS 2.0</font></h2>
335 <div class="username">Welcome $Userid</div>
337 <a href="/maps/">Home</a><br>
338 <a href="/maps/bin/stats.cgi">Statistics</a><br>
339 <a href="/maps/bin/editprofile.cgi">Profile</a><br>
340 <a href="/maps/php/Reports.php">Reports</a><br>
341 <a href="/maps/php/list.php?type=white">White</a><br>
342 <a href="/maps/php/list.php?type=black">Black</a><br>
343 <a href="/maps/php/list.php?type=null">Null</a><br>
344 <a href="/maps/doc/">Help</a><br>
345 <a href="/maps/adm/">Admin</a><br>
346 <a href="/maps/?logout=yes">Logout</a>
354 <form method="get" action="/maps/bin/search.cgi" name="search">
355 Search Sender/Subject
356 <input type="text" class="searchfield" id="searchfield" name="str"
357 size="20" maxlength="255" value="" onclick="document.search.str.value='';">
364 <form "method"=post action="javascript://" name="address"
365 onsubmit="checkaddress(this);">
367 <input type="text" class="searchfield" id="searchfield" name="email"
368 size="20" maxlength="255" value="" onclick="document.address.email.value = '';">
378 function GetUserLines() {
383 $statement = "select value from useropts where userid=\"$userid\" and name=\"Page\"";
385 $result = mysqli_query($db, $statement)
386 or DBError("GetUserLines: Unable to execute query: ", $statement);
388 $row = mysqli_fetch_array ($result);
390 if (isset ($row["value"])) {
391 $lines = $row["value"];
397 function DisplayList($type, $next, $lines) {
403 $statement = "select * from list where userid=\"$userid\" and type=\"$type\" order by sequence limit $next, $lines";
405 $result = mysqli_query($db, $statement)
406 or DBError("DisplayList: Unable to execute query: ", $statement);
408 for ($i = 0; $i < $lines; $i++) {
409 $row = mysqli_fetch_array($result);
411 if (!isset ($row["sequence"])) {
415 $sequence = $row["sequence"];
416 $username = $row["pattern"] == "" ? " " : $row["pattern"];
417 $domain = $row["domain"] == "" ? " " : $row["domain"];
418 $hit_count = $row["hit_count"] == "" ? " " : $row["hit_count"];
419 $last_hit = $row["last_hit"] == "" ? " " : $row["last_hit"];
420 $retention = $row["retention"] == "" ? " " : $row["retention"];
421 $comments = $row["comment"] == "" ? " " : $row["comment"];
423 // Remove time from last hit
424 $last_hit = substr($last_hit, 0, (strlen($last_hit) - strpos($last_hit, " ")) + 1);
427 $last_hit = substr ($last_hit, 5, 2) . "/" .
428 substr ($last_hit, 8, 2) . "/" .
429 substr ($last_hit, 0, 4);
430 $leftclass = ($i == $lines || $sequence == $total || $sequence == $last) ?
431 "tablebottomleft" : "tableleftdata";
432 $dataclass = ($i == $lines || $sequence == $total || $sequence == $last) ?
433 "tablebottomdata" : "tabledata";
434 $rightclass = ($i == $lines || $sequence == $total || $sequence == $last) ?
435 "tablebottomright" : "tablerightdata";
437 print "<td class=$leftclass align=right>" . $sequence . "<input type=checkbox name=action" . $sequence . " value=on></td>\n";
438 print "<td class=$dataclass align=right>" . $username . "</td>";
439 print "<td class=$dataclass align=center>@</td>";
440 print "<td class=$dataclass align=left><a href=\"http://$domain\" target=_blank>$domain</a></td>";
441 print "<td class=$dataclass align=right>" . $hit_count . "</td>";
442 print "<td class=$dataclass align=center>" . $last_hit . "</td>";
443 print "<td class=$dataclass align=right>" . $retention . "</td>";
444 print "<td class=$rightclass align=left>" . $comments . "</td>";
449 function MAPSHeader() {
451 <meta name="author" content="Andrew DeFaria <Andre@DeFaria.com>">
452 <meta name="MAPS" "Mail Authorization and Permission System">
453 <meta name="keywords" content="Eliminate SPAM, Permission based email, SPAM filtering system">
454 <meta http-equiv=Refresh content="900">
455 <link rel="icon" href="/maps/MAPS.png" type="image/png">
456 <link rel="SHORTCUT ICON" href="/maps/favicon.ico">
457 <link rel="stylesheet" type="text/css" href="/maps/css/MAPSStyle.css"/>
458 <script language="JavaScript1.2" src="/maps/JavaScript/MAPSUtils.js"
459 type="text/javascript"></script>
460 <script language="JavaScript1.2" src="/maps/JavaScript/CheckAddress.js"
461 type="text/javascript"></script>
465 function ListDomains($top = 10) {
468 // Generate a list of the top 10 spammers by domain
469 $statement = "select count(sender) as nbr, ";
470 // Must extract domain from sender...
471 $statement = $statement . "substring(sender, locate(\"@\",sender, 1)+1) as domain ";
472 // From email for the current userid...
473 $statement = $statement . "from email where userid=\"$userid\" ";
474 // Group things by domain but order them descending on nbr...
475 $statement = $statement . "group by domain order by nbr desc";
478 $result = mysqli_query($db, $statement)
479 or DBError("ListDomains: Unable to execute query: ", $statement);
481 print "<div id=highlightrow>";
483 <table border="0" cellspacing="0" cellpadding="4" align="center" name="domainlist">
485 <th class="tableleftend"> </th>
486 <th class="tableheader">Domain</th>
487 <th class="tablerightend">Returns</th>
492 for ($i = 0; $i < $top; $i++) {
493 $row = mysqli_fetch_array($result);
494 $domain = $row["domain"];
500 print "<td align=center class=tableleftdata>" . $ranking . "<input type=checkbox name=action" . $i . " value=on></td>\n";
501 print "<td class=tabledata><a href=\"http://$domain\">$domain</as></td>";
502 print "<input type=hidden name=email$i value=\"@$domain\">";
503 print "<td align=center class=tablerightdata>$nbr</td>";
505 print "<td align=center class=tablebottomleft>" . $ranking . "<input type=checkbox name=action" . $i . " value=on></td>\n";
506 print "<td class=tablebottomdata><a href=\"http://$domain\">$domain</a></td>";
507 print "<input type=hidden name=email$i value=\"@$domain\">";
508 print "<td align=center class=tablebottomright>$nbr</td>";
515 <td align=center colspan=4><input type="submit" name="action" value="Nulllist" onclick="return CheckAtLeast1Checked (document.domains);" /><input type="submit" name="action" value="Reset" onclick="return ClearAll (document.domains);" />
526 // Tally up space used by $userid
529 $statement = "select * from email where userid = \"$userid\"";
531 $result = mysqli_query($db, $statement)
532 or DBError("Space: Unable to execute query: ", $statement);
534 while ($row = mysqli_fetch_array ($result)) {
536 strlen($row["userid"]) +
537 strlen($row["sender"]) +
538 strlen($row["subject"]) +
539 strlen($row["timestamp"]) +
540 strlen($row["data"]);
541 $space += $msg_space;
544 mysqli_free_result($result);