X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Fphp%2FMAPS.php;h=6ccc76dfdf8339ff0cce2bf14618c205fcd16b53;hb=83737e59d30d46e80259f07dd8d528b06dd43858;hp=59936e20393b643001683ada7c567e17c138e444;hpb=3f50a70e676ff421d6e55d058d2cb2c6d0891358;p=clearscm.git diff --git a/maps/php/MAPS.php b/maps/php/MAPS.php index 59936e2..6ccc76d 100755 --- a/maps/php/MAPS.php +++ b/maps/php/MAPS.php @@ -34,9 +34,13 @@ $Types = array ( "nulllist" ); +$db; + function DBError($msg, $statement) { - $errno = mysql_errno(); - $errmsg = mysql_error(); + global $db; + + $errno = mysqli_errno($db); + $errmsg = mysqli_error($db); print "$msg
Error # $errno $errmsg"; print "
SQL Statement: $statement"; @@ -44,13 +48,23 @@ function DBError($msg, $statement) { } // DBError function OpenDB() { - $db = mysql_connect("localhost", "maps", "spam") + global $db; + + $db = mysqli_connect("127.0.0.1", "maps", "spam") or DBError("OpenDB: Unable to connect to database server", "Connect"); - mysql_select_db("MAPS") + 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; @@ -58,24 +72,28 @@ function SetContext($new_userid) { } // SetContext function Encrypt($password, $userid) { - $statement = "select encode(\"$password\",\"$userid\")"; + global $db; + + $statement = "select hex(aes_encrypt(\"$password\",\"$userid\"))"; - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError("Encrypt: Unable to execute statement", $statement); // Get return value, which should be the encoded password - $row = mysql_fetch_array($result); + $row = mysqli_fetch_array($result); return $row[0]; } // Encrypt function UserExists($userid) { + global $db; + $statement = "select userid, password from user where userid = \"$userid\""; - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError ("UserExists: Unable to execute statement", $statement); - $row = mysql_fetch_array($result); + $row = mysqli_fetch_array($result); $dbuserid = $row["userid"]; $dbpassword = $row["password"]; @@ -92,6 +110,7 @@ function Login($userid, $password) { // Check if user exists $dbpassword = UserExists($userid); + print "dbpassword = $dbpassword
"; // Return -1 if user doesn't exist if ($dbpassword == -1) { @@ -109,15 +128,15 @@ function Login($userid, $password) { } // Login function CountList ($type) { - global $userid; + global $userid, $db; $statement = "select count(*) as count from list where type=\"$type\" and userid=\"$userid\""; - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError("CountList: Unable to count list: ", $statement); // How many rows are there? - $row = mysql_fetch_array($result); + $row = mysqli_fetch_array($result); return $row["count"]; } // CountList @@ -129,10 +148,10 @@ function FindList($type, $next, $lines) { $statement = "select * from list where type=\"$type\" and userid=\"$userid\" order by sequence limit $next, $lines"; - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError ("FindList: Unable to execute query: ", $statement); - $count = mysql_num_rows($result); + $count = mysqli_num_rows($result); return array($count, $result); } // FindList @@ -142,13 +161,15 @@ function Today2SQLDatetime() { } // Today2SQLDatetime function countem($table, $condition) { + global $db; + $statement = "select count(distinct sender) as count from $table where $condition"; - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError("countem: Unable to perform query: ", $statement); // How many rows are there? - $row = mysql_fetch_array($result); + $row = mysqli_fetch_array($result); return $row["count"]; } // countem @@ -199,9 +220,9 @@ function displayquickstats() { $current_time = date("g:i:s a"); // Start quickstats - print "
"; - print "

Today's Activity

"; - print "

as of $current_time

"; + print "
"; + print "

Today's Activity

"; + print "

as of $current_time

"; $processed = $dates[$today]["processed"]; $returned = $dates[$today]["returned"]; @@ -219,20 +240,21 @@ function displayquickstats() { $nulllist_pct = $processed == 0 ? 0 : number_format ($nulllist / $processed * 100, 1, ".", ""); - $returned_link = $returned == 0 ? 0 : - "$returned"; - $whitelist_link = $whitelist == 0 ? 0 : - "$whitelist"; - $blacklist_link = $blacklist == 0 ? 0 : - "$blacklist"; - $registered_link = $registered == 0 ? 0 : - "$registered"; - $mailloop_link = $mailloop == 0 ? 0 : - "$mailloop"; - $nulllist_link = $nulllist == 0 ? 0 : - "$nulllist"; + $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 << @@ -240,37 +262,38 @@ print <<n/a - - + + + + + + - - + - - + - - + - - + - - - -
Processed
Returned$returned_link + $nulllist$nulllist_pct%
$returned $returned_pct%
Whitelist$whitelist_link + $whitelist $whitelist_pct%
Blacklist$blacklist_link + $blacklist $blacklist_pct%
Registered$registered_link + $registered n/a
Mailloop$mailloop_link + $mailloop n/a
Nulllist$nulllist_link - $nulllist_pct%
+
EOT; } // displayquickstats @@ -295,7 +318,8 @@ function NavigationBar($userid) { if (!isset ($userid) || $userid == "") { print <<Welcome to MAPS +

MAPS 2.0

+
Welcome to MAPS
+

MAPS 2.0

+
Welcome $Userid
END; + + displayquickstats(); + print <<
@@ -332,8 +360,6 @@ END; END; - displayquickstats(); - print << +

END; } // if @@ -350,16 +377,16 @@ END; } # NavigationBar function GetUserLines() { - global $userid; + global $userid, $db; $lines = 10; $statement = "select value from useropts where userid=\"$userid\" and name=\"Page\""; - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError("GetUserLines: Unable to execute query: ", $statement); - $row = mysql_fetch_array ($result); + $row = mysqli_fetch_array ($result); if (isset ($row["value"])) { $lines = $row["value"]; @@ -372,16 +399,17 @@ 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 = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError("DisplayList: Unable to execute query: ", $statement); for ($i = 0; $i < $lines; $i++) { - $row = mysql_fetch_array ($result); + $row = mysqli_fetch_array($result); - if (!isset ($row ["sequence"])) { + if (!isset ($row["sequence"])) { break; } // if @@ -390,6 +418,7 @@ function DisplayList($type, $next, $lines) { $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 @@ -406,13 +435,13 @@ function DisplayList($type, $next, $lines) { $rightclass = ($i == $lines || $sequence == $total || $sequence == $last) ? "tablebottomright" : "tablerightdata"; - print "" . $sequence . ""; - print "\n"; + print "" . $sequence . "\n"; print "" . $username . ""; print "@"; print "$domain"; print "" . $hit_count . ""; print "" . $last_hit . ""; + print "" . $retention . ""; print "" . $comments . ""; print ""; } // for @@ -435,7 +464,7 @@ END; } // MAPSHeader function ListDomains($top = 10) { - global $userid; + global $userid, $db; // Generate a list of the top 10 spammers by domain $statement = "select count(sender) as nbr, "; @@ -447,7 +476,7 @@ function ListDomains($top = 10) { $statement = $statement . "group by domain order by nbr desc"; // Do the query - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError("ListDomains: Unable to execute query: ", $statement); print <<\n"; print "" . $ranking . ""; - print "$domain"; + print "$domain"; print ""; print "$nbr"; } else { print "\n"; print "" . $ranking . ""; - print "$domain"; + print "$domain"; print ""; print "$nbr"; } // if @@ -494,26 +523,28 @@ END; } // ListDomains function Space() { - global $userid; + global $userid, $db; // Tally up space used by $userid $space = 0; $statement = "select * from email where userid = \"$userid\""; - $result = mysql_query($statement) + $result = mysqli_query($db, $statement) or DBError("Space: Unable to execute query: ", $statement); - while ($row = mysql_fetch_array ($result)) { + while ($row = mysqli_fetch_array ($result)) { $msg_space = strlen($row["userid"]) + strlen($row["sender"]) + strlen($row["subject"]) + strlen($row["timestamp"]) + strlen($row["data"]); - $space = $space + $msg_space; + $space += $msg_space; } // while + mysqli_free_result($result); + return $space; } // Space ?>