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"];
37 function DBError($msg, $statement) {
38 $errno = mysql_errno();
39 $errmsg = mysql_error();
40 print "$msg<br>Error # $errno $errmsg";
41 print "<br>SQL Statement: $statement";
47 $db = mysql_connect("localhost", "mapsadmin", "mapsadmin")
48 or DBError("OpenDB: Unable to connect to database server", "Connect");
50 mysql_select_db("MAPS")
51 or DBError("OpenDB: Unable to select MAPS database", "adefaria_maps");
54 function SetContext($new_userid) {
57 $userid = $new_userid;
60 function Encrypt($password, $userid) {
61 $statement = "select encode(\"$password\",\"$userid\")";
63 $result = mysql_query($statement)
64 or DBError("Encrypt: Unable to execute statement", $statement);
66 // Get return value, which should be the encoded password
67 $row = mysql_fetch_array($result);
72 function UserExists($userid) {
73 $statement = "select userid, password from user where userid = \"$userid\"";
75 $result = mysql_query($statement)
76 or DBError ("UserExists: Unable to execute statement", $statement);
78 $row = mysql_fetch_array($result);
80 $dbuserid = $row["userid"];
81 $dbpassword = $row["password"];
83 if ($dbuserid != $userid) {
90 function Login($userid, $password) {
91 $password = Encrypt($password, $userid);
93 // Check if user exists
94 $dbpassword = UserExists($userid);
96 // Return -1 if user doesn't exist
97 if ($dbpassword == -1) {
101 // Return -2 if password does not match
102 if ($password != $dbpassword) {
105 setcookie("MAPSUser", $userid, time()+60*60*24*30, "/maps");
111 function CountList ($type) {
114 $statement = "select count(*) as count from list where type=\"$type\" and userid=\"$userid\"";
116 $result = mysql_query($statement)
117 or DBError("CountList: Unable to count list: ", $statement);
119 // How many rows are there?
120 $row = mysql_fetch_array($result);
122 return $row["count"];
125 function FindList($type, $next, $lines) {
130 $statement = "select * from list where type=\"$type\" and userid=\"$userid\" order by sequence limit $next, $lines";
132 $result = mysql_query($statement)
133 or DBError ("FindList: Unable to execute query: ", $statement);
135 $count = mysql_num_rows($result);
137 return array($count, $result);
140 function Today2SQLDatetime() {
141 return date ("Y-m-d H:i:s");
142 } // Today2SQLDatetime
144 function countem($table, $condition) {
145 $statement = "select count(distinct sender) as count from $table where $condition";
147 $result = mysql_query($statement)
148 or DBError("countem: Unable to perform query: ", $statement);
150 // How many rows are there?
151 $row = mysql_fetch_array($result);
153 return $row["count"];
156 function countlog($condition="") {
159 if ($condition != "") {
160 return countem("log", "userid=\"$userid\" and " . $condition);
162 return countem("log", "userid=\"$userid\"");
166 function SubtractDays($date, $nbr_days) {
170 function GetStats($nbr_days, $date = "") {
174 $date = Today2SQLDatetime();
177 while ($nbr_days > 0) {
178 $ymd = substr($date, 0, 10);
179 $sod = $ymd . " 00:00:00";
180 $eod = $ymd . " 23:59:59";
182 foreach ($Types as $type) {
183 $condition = "type=\"$type\" and (timestamp > \"$sod\" and timestamp < \"$eod\")";
184 $stats[$type] = countlog($condition);
187 $dates[$ymd] = &$stats;
189 $date = SubtractDays($date, 1);
196 function displayquickstats() {
197 $today = substr (Today2SQLDatetime(), 0, 10);
198 $dates = getquickstats($today);
199 $current_time = date("g:i a");
202 print "<div class=quickstats>";
203 print "<h4 align=center class=header>Today's Activity</h4>";
204 print "<p align=center><b>as of $current_time</b></p>";
206 $processed = $dates[$today]["processed"];
207 $returned = $dates[$today]["returned"];
208 $returned_pct = $processed == 0 ? 0 :
209 number_format ($returned / $processed * 100, 1, ".", "");
210 $whitelist = $dates[$today]["whitelist"];
211 $whitelist_pct = $processed == 0 ? 0 :
212 number_format ($whitelist / $processed * 100, 1, ".", "");
213 $blacklist = $dates[$today]["blacklist"];
214 $blacklist_pct = $processed == 0 ? 0 :
215 number_format ($blacklist / $processed * 100, 1, ".", "");
216 $registered = $dates[$today]["registered"];
217 $mailloop = $dates[$today]["mailloop"];
218 $nulllist = $dates[$today]["nulllist"];
219 $nulllist_pct = $processed == 0 ? 0 :
220 number_format ($nulllist / $processed * 100, 1, ".", "");
222 $returned_link = $returned == 0 ? 0 :
223 "<a href=/maps/bin/detail.cgi?type=returned;date=$today>$returned</a>";
224 $whitelist_link = $whitelist == 0 ? 0 :
225 "<a href=/maps/bin/detail.cgi?type=whitelist;date=$today>$whitelist</a>";
226 $blacklist_link = $blacklist == 0 ? 0 :
227 "<a href=/maps/bin/detail.cgi?type=blacklist;date=$today>$blacklist</a>";
228 $registered_link = $registered == 0 ? 0 :
229 "<a href=/maps/bin/detail.cgi?type=registered;date=$today>$registered</a>";
230 $mailloop_link = $mailloop == 0 ? 0 :
231 "<a href=/maps/bin/detail.cgi?type=mailloop;date=$today>$mailloop</a>";
232 $nulllist_link = $nulllist == 0 ? 0 :
233 "<a href=/maps/bin/detail.cgi?type=nulllist;date=$today>$nulllist</a>";
236 <table cellpadding="2" border="0" align="center" cellspacing="0">
238 <td align="right" class="smalllabel">Processed</td>
239 <td align="right" class="smallnumber">$processed</td>
240 <td align="right" class="smallnumber">n/a</td>
243 <td class="smalllabel">Returned</td>
244 <td class=smallnumber>$returned_link
245 <td class="smallnumber">$returned_pct%</td>
248 <td class="smalllabel">Whitelist</td>
249 <td class="smallnumber">$whitelist_link
250 <td class="smallnumber">$whitelist_pct%</td>
253 <td class="smalllabel">Blacklist</td>
254 <td class="smallnumber">$blacklist_link
255 <td class="smallnumber">$blacklist_pct%</td>
258 <td class="smalllabel">Registered</td>
259 <td class="smallnumber">$registered_link
260 <td class="smallnumber">n/a</td>
263 <td class="smalllabel">Mailloop</td>
264 <td class="smallnumber">$mailloop_link
265 <td class="smallnumber">n/a</td>
268 <td class="smalllabel">Nulllist</td>
269 <td class="smallnumber">$nulllist_link
270 <td class="smallnumber">$nulllist_pct%</td>
275 } // displayquickstats
277 function getquickstats($date) {
280 $dates = GetStats(1, $date);
282 foreach ($Types as $type) {
283 if (isset ($dates[$date]["processed"])) {
284 $dates[$date]["processed"] += $dates[$date][$type];
286 $dates[$date]["processed"] = $dates[$date][$type];
293 function NavigationBar($userid) {
294 print "<div id=leftbar>";
296 if (!isset ($userid) || $userid == "") {
298 <div class="username">Welcome to MAPS</div>
300 <a href="/maps/doc/">What is MAPS?</a><br>
301 <a href="/maps/doc/SPAM.php">What is SPAM?</a><br>
302 <a href="/maps/doc/Requirements.php">Requirements</a><br>
303 <a href="/maps/SignupForm.html">Signup</a><br>
304 <a href="/maps/doc/Using.php">Using MAPS</a><br>
305 <a href="/maps/doc/">Help</a><br>
309 $Userid = ucfirst($userid);
311 <div class="username">Welcome $Userid</div>
313 <a href="/maps/">MAPS Home</a><br>
314 <a href="/maps/bin/stats.cgi">Statistics</a><br>
315 <a href="/maps/bin/editprofile.cgi">Edit Profile</a><br>
316 <a href="/maps/php/Reports.php">Reports</a><br>
317 <a href="/maps/php/list.php?type=white">White List</a><br>
318 <a href="/maps/php/list.php?type=black">Black List</a><br>
319 <a href="/maps/php/list.php?type=null">Null List</a><br>
320 <a href="/maps/doc/">Help</a><br>
321 <a href="/maps/adm/">MAPS Admin</a><br>
322 <a href="/maps/?logout=yes">Logout</a>
327 <form method="get" action="/maps/bin/search.cgi" name="search">
328 Search Sender/Subject
329 <input type="text" class="searchfield" id="searchfield" name="str"
330 size="20" maxlength="255" value="" onclick="document.search.str.value='';">
339 <form "method"=post action="javascript://" name="address"
340 onsubmit="checkaddress(this);">
342 <input type="text" class="searchfield" id="searchfield" name="email"
343 size="20" maxlength="255" value="" onclick="document.address.email.value = '';">
352 function GetUserLines() {
357 $statement = "select value from useropts where userid=\"$userid\" and name=\"Page\"";
359 $result = mysql_query($statement)
360 or DBError("GetUserLines: Unable to execute query: ", $statement);
362 $row = mysql_fetch_array ($result);
364 if (isset ($row["value"])) {
365 $lines = $row["value"];
371 function DisplayList($type, $next, $lines) {
376 $statement = "select * from list where userid=\"$userid\" and type=\"$type\" order by sequence limit $next, $lines";
378 $result = mysql_query($statement)
379 or DBError("DisplayList: Unable to execute query: ", $statement);
381 for ($i = 0; $i < $lines; $i++) {
382 $row = mysql_fetch_array ($result);
384 if (!isset ($row ["sequence"])) {
388 $sequence = $row["sequence"];
389 $username = $row["pattern"] == "" ? " " : $row["pattern"];
390 $domain = $row["domain"] == "" ? " " : $row["domain"];
391 $hit_count = $row["hit_count"] == "" ? " " : $row["hit_count"];
392 $last_hit = $row["last_hit"] == "" ? " " : $row["last_hit"];
393 $comments = $row["comment"] == "" ? " " : $row["comment"];
395 // Remove time from last hit
396 $last_hit = substr($last_hit, 0, (strlen($last_hit) - strpos($last_hit, " ")) + 1);
399 $last_hit = substr ($last_hit, 5, 2) . "/" .
400 substr ($last_hit, 8, 2) . "/" .
401 substr ($last_hit, 0, 4);
402 $leftclass = ($i == $lines || $sequence == $total || $sequence == $last) ?
403 "tablebottomleft" : "tableleftdata";
404 $dataclass = ($i == $lines || $sequence == $total || $sequence == $last) ?
405 "tablebottomdata" : "tabledata";
406 $rightclass = ($i == $lines || $sequence == $total || $sequence == $last) ?
407 "tablebottomright" : "tablerightdata";
409 print "<td class=$leftclass align=center>" . $sequence . "</td>";
410 print "<td class=$dataclass align=center><input type=checkbox name=action" . $sequence . " value=on></td>\n";
411 print "<td class=$dataclass align=right>" . $username . "</td>";
412 print "<td class=$dataclass align=center>@</td>";
413 print "<td class=$dataclass align=left><a href=\"http://$domain\" target=_blank>$domain</a></td>";
414 print "<td class=$dataclass align=right>" . $hit_count . "</td>";
415 print "<td class=$dataclass align=center>" . $last_hit . "</td>";
416 print "<td class=$rightclass align=left>" . $comments . "</td>";
421 function MAPSHeader() {
423 <meta name="author" content="Andrew DeFaria <Andre@DeFaria.com>">
424 <meta name="MAPS" "Mail Authorization and Permission System">
425 <meta name="keywords" content="Eliminate SPAM, Permission based email, SPAM filtering system">
426 <meta http-equiv=Refresh content="900">
427 <link rel="icon" href="/maps/MAPS.png" type="image/png">
428 <link rel="SHORTCUT ICON" href="/maps/favicon.ico">
429 <link rel="stylesheet" type="text/css" href="/maps/css/MAPSStyle.css"/>
430 <script language="JavaScript1.2" src="/maps/JavaScript/MAPSUtils.js"
431 type="text/javascript"></script>
432 <script language="JavaScript1.2" src="/maps/JavaScript/CheckAddress.js"
433 type="text/javascript"></script>
437 function ListDomains($top = 10) {
440 // Generate a list of the top 10 spammers by domain
441 $statement = "select count(sender) as nbr, ";
442 // Must extract domain from sender...
443 $statement = $statement . "substring(sender, locate(\"@\",sender, 1)+1) as domain ";
444 // From email for the current userid...
445 $statement = $statement . "from email where userid=\"$userid\" ";
446 // Group things by domain but order them descending on nbr...
447 $statement = $statement . "group by domain order by nbr desc";
450 $result = mysql_query($statement)
451 or DBError("ListDomains: Unable to execute query: ", $statement);
454 <table border="0" cellspacing="0" cellpadding="4" align="center" name="domainlist">
456 <th class="tableleftend">Mark</th>
457 <th class="tableheader">Ranking</th>
458 <th class="tableheader">Domain</th>
459 <th class="tablerightend">Returns</th>
464 for ($i = 0; $i < $top; $i++) {
465 $row = mysql_fetch_array ($result);
466 $domain = $row["domain"];
472 print "<td class=tableleftdata align=center><input type=checkbox name=action" . $i . " value=on></td>\n";
473 print "<td align=center class=tabledata>" . $ranking . "</td>";
474 print "<td class=tabledata>$domain</td>";
475 print "<input type=hidden name=email$i value=\"@$domain\">";
476 print "<td align=center class=tablerightdata>$nbr</td>";
478 print "<td class=tablebottomleft align=center><input type=checkbox name=action" . $i . " value=on></td>\n";
479 print "<td align=center class=tablebottomdata>" . $ranking . "</td>";
480 print "<td class=tablebottomdata>$domain</td>";
481 print "<input type=hidden name=email$i value=\"@$domain\">";
482 print "<td align=center class=tablebottomright>$nbr</td>";
489 <td align=center colspan=4><input type="submit" name="action" value="Nulllist Marked" onclick="return CheckAtLeast1Checked (document.domains);" /><input type="submit" name="action" value="Reset Marks" onclick="return ClearAll (document.domains);" />
499 // Tally up space used by $userid
502 $statement = "select * from email where userid = \"$userid\"";
504 $result = mysql_query($statement)
505 or DBError("Space: Unable to execute query: ", $statement);
507 while ($row = mysql_fetch_array ($result)) {
509 strlen($row["userid"]) +
510 strlen($row["sender"]) +
511 strlen($row["subject"]) +
512 strlen($row["timestamp"]) +
513 strlen($row["data"]);
514 $space = $space + $msg_space;