Error # $errno $errmsg"; print "
SQL Statement: $statement"; exit($errno); } // DBError function OpenDB() { global $db; $db = mysqli_connect("127.0.0.1", "maps", "spam") or DBError("OpenDB: Unable to connect to database server", "Connect"); mysqli_select_db($db, "MAPS") or DBError("OpenDB: Unable to select MAPS database", "adefaria_maps"); } // OpenDB function CloseDB() { global $db; if (isset ($db)) { mysqli_close($db); } // if } // CloseDB function SetContext($new_userid) { global $userid; $userid = $new_userid; } // SetContext function Encrypt($password, $userid) { global $db; $statement = "select hex(aes_encrypt(\"$password\",\"$userid\"))"; $result = mysqli_query($db, $statement) or DBError("Encrypt: Unable to execute statement", $statement); // Get return value, which should be the encoded password $row = mysqli_fetch_array($result); return $row[0]; } // Encrypt function UserExists($userid) { global $db; $statement = "select userid, password from user where userid = \"$userid\""; $result = mysqli_query($db, $statement) or DBError ("UserExists: Unable to execute statement", $statement); $row = mysqli_fetch_array($result); $dbuserid = $row["userid"]; $dbpassword = $row["password"]; if ($dbuserid != $userid) { return -1; } else { return $dbpassword; } # if } // UserExists function Login($userid, $password) { $password = Encrypt($password, $userid); // Check if user exists $dbpassword = UserExists($userid); // Return -1 if user doesn't exist if ($dbpassword == -1) { return -1; } // if // Return -2 if password does not match if ($password != $dbpassword) { return -2; } else { setcookie("MAPSUser", $userid, time()+60*60*24*30, "/maps"); SetContext($userid); return 0; } // if } // Login function CountList ($type) { global $userid, $db; $statement = "select count(*) as count from list where type=\"$type\" and userid=\"$userid\""; $result = mysqli_query($db, $statement) or DBError("CountList: Unable to count list: ", $statement); // How many rows are there? $row = mysqli_fetch_array($result); return $row["count"]; } // CountList function FindList($type, $next, $lines) { global $db; global $userid; global $lines; $statement = "select * from list where type=\"$type\" and userid=\"$userid\" order by sequence limit $next, $lines"; $result = mysqli_query($db, $statement) or DBError ("FindList: Unable to execute query: ", $statement); $count = mysqli_num_rows($result); return array($count, $result); } // FindList function Today2SQLDatetime() { return date ("Y-m-d H:i:s"); } // Today2SQLDatetime function countem($table, $condition) { global $db; $statement = "select count(distinct sender) as count from $table where $condition"; $result = mysqli_query($db, $statement) or DBError("countem: Unable to perform query: ", $statement); // How many rows are there? $row = mysqli_fetch_array($result); return $row["count"]; } // countem function countlog($condition="") { global $userid; if ($condition != "") { return countem("log", "userid=\"$userid\" and " . $condition); } else { return countem("log", "userid=\"$userid\""); } // if } // countlog function SubtractDays($date, $nbr_days) { } // SubtractDays function GetStats($nbr_days, $date = "") { global $Types; if ($date == "") { $date = Today2SQLDatetime(); } // if while ($nbr_days > 0) { $ymd = substr($date, 0, 10); $sod = $ymd . " 00:00:00"; $eod = $ymd . " 23:59:59"; foreach ($Types as $type) { $condition = "type=\"$type\" and (timestamp > \"$sod\" and timestamp < \"$eod\")"; $stats[$type] = countlog($condition); } # foreach $dates[$ymd] = &$stats; $date = SubtractDays($date, 1); $nbr_days--; } # while return $dates; } # GetStats function displayquickstats() { $today = substr (Today2SQLDatetime(), 0, 10); $dates = getquickstats($today); $current_time = date("g:i:s a"); // Start quickstats print "
"; print "

Today's Activity

"; print "

as of $current_time

"; $processed = $dates[$today]["processed"]; $returned = $dates[$today]["returned"]; $returned_pct = $processed == 0 ? 0 : number_format ($returned / $processed * 100, 1, ".", ""); $whitelist = $dates[$today]["whitelist"]; $whitelist_pct = $processed == 0 ? 0 : number_format ($whitelist / $processed * 100, 1, ".", ""); $blacklist = $dates[$today]["blacklist"]; $blacklist_pct = $processed == 0 ? 0 : number_format ($blacklist / $processed * 100, 1, ".", ""); $registered = $dates[$today]["registered"]; $mailloop = $dates[$today]["mailloop"]; $nulllist = $dates[$today]["nulllist"]; $nulllist_pct = $processed == 0 ? 0 : number_format ($nulllist / $processed * 100, 1, ".", ""); $returned_link = $returned == 0 ? '' : ""; $whitelist_link = $whitelist == 0 ? '' : ""; $blacklist_link = $blacklist == 0 ? '' : ""; $registered_link = $registered == 0 ? '' : ""; $mailloop_link = $mailloop == 0 ? '' : "\""; $nulllist_link = $nulllist == 0 ? '' : ""; print <<
Processed $processed n/a
${nulllist_link}Nulllist $nulllist $nulllist_pct%
${returned_link}Returned $returned $returned_pct%
${whitelist_link}Whitelist $whitelist $whitelist_pct%
${blacklist_link}Blacklist $blacklist $blacklist_pct%
${registered_link}Registered $registered n/a
${mailloop_link}Mailloop $mailloop n/a
EOT; } // displayquickstats function getquickstats($date) { global $Types; $dates = GetStats(1, $date); foreach ($Types as $type) { if (isset ($dates[$date]["processed"])) { $dates[$date]["processed"] += $dates[$date][$type]; } else { $dates[$date]["processed"] = $dates[$date][$type]; } // if } # foreach return $dates; } // getquickstats function NavigationBar($userid) { print "
"; if (!isset ($userid) || $userid == "") { print <<MAPS 2.0
Welcome to MAPS
END; } else { $Userid = ucfirst($userid); print <<MAPS 2.0
Welcome $Userid
END; displayquickstats(); print <<
Search Sender/Subject
END; print <<
Check Email Address

END; } // if print ""; } # NavigationBar function GetUserLines() { global $userid, $db; $lines = 10; $statement = "select value from useropts where userid=\"$userid\" and name=\"Page\""; $result = mysqli_query($db, $statement) or DBError("GetUserLines: Unable to execute query: ", $statement); $row = mysqli_fetch_array ($result); if (isset ($row["value"])) { $lines = $row["value"]; } // if return $lines; } // GetUserLines function DisplayList($type, $next, $lines) { global $userid; global $total; global $last; global $db; $statement = "select * from list where userid=\"$userid\" and type=\"$type\" order by sequence limit $next, $lines"; $result = mysqli_query($db, $statement) or DBError("DisplayList: Unable to execute query: ", $statement); for ($i = 0; $i < $lines; $i++) { $row = mysqli_fetch_array($result); if (!isset ($row["sequence"])) { break; } // if $sequence = $row["sequence"]; $username = $row["pattern"] == "" ? " " : $row["pattern"]; $domain = $row["domain"] == "" ? " " : $row["domain"]; $hit_count = $row["hit_count"] == "" ? " " : $row["hit_count"]; $last_hit = $row["last_hit"] == "" ? " " : $row["last_hit"]; $retention = $row["retention"] == "" ? " " : $row["retention"]; $comments = $row["comment"] == "" ? " " : $row["comment"]; // Remove time from last hit $last_hit = substr($last_hit, 0, (strlen($last_hit) - strpos($last_hit, " ")) + 1); // Reformat last_hit $last_hit = substr ($last_hit, 5, 2) . "/" . substr ($last_hit, 8, 2) . "/" . substr ($last_hit, 0, 4); $leftclass = ($i == $lines || $sequence == $total || $sequence == $last) ? "tablebottomleft" : "tableleftdata"; $dataclass = ($i == $lines || $sequence == $total || $sequence == $last) ? "tablebottomdata" : "tabledata"; $rightclass = ($i == $lines || $sequence == $total || $sequence == $last) ? "tablebottomright" : "tablerightdata"; print "" . $sequence . "\n"; print "" . $username . ""; print "@"; print "$domain"; print "" . $hit_count . ""; print "" . $last_hit . ""; print "" . $retention . ""; print "" . $comments . ""; print ""; } // for } // DisplayList function MAPSHeader() { print << END; } // MAPSHeader function ListDomains($top = 10) { global $userid, $db; // Generate a list of the top 10 spammers by domain $statement = "select count(sender) as nbr, "; // Must extract domain from sender... $statement = $statement . "substring(sender, locate(\"@\",sender, 1)+1) as domain "; // From email for the current userid... $statement = $statement . "from email where userid=\"$userid\" "; // Group things by domain but order them descending on nbr... $statement = $statement . "group by domain order by nbr desc"; // Do the query $result = mysqli_query($db, $statement) or DBError("ListDomains: Unable to execute query: ", $statement); print "
"; print <<   Domain Returns END; // Get results for ($i = 0; $i < $top; $i++) { $row = mysqli_fetch_array($result); $domain = $row["domain"]; $nbr = $row["nbr"]; print ""; $ranking = $i + 1; if ($i < $top - 1) { print "" . $ranking . "\n"; print "$domain"; print ""; print "$nbr"; } else { print "" . $ranking . "\n"; print "$domain"; print ""; print "$nbr"; } // if print ""; } // for print << END; } // ListDomains function Space() { global $userid, $db; // Tally up space used by $userid $space = 0; $statement = "select * from email where userid = \"$userid\""; $result = mysqli_query($db, $statement) or DBError("Space: Unable to execute query: ", $statement); while ($row = mysqli_fetch_array ($result)) { $msg_space = strlen($row["userid"]) + strlen($row["sender"]) + strlen($row["subject"]) + strlen($row["timestamp"]) + strlen($row["data"]); $space += $msg_space; } // while mysqli_free_result($result); return $space; } // Space ?>