", "", $srcip); $srcip = str_replace(" ", "", $srcip); // make input safe $srcip = escapeshellarg($srcip); /* execute spamdb command */ if ($action == "whitelist") { exec("/usr/local/sbin/spamdb -d {$srcip} -T"); exec("/usr/local/sbin/spamdb -d {$srcip} -t"); delete_from_blacklist($srcip); mwexec("/sbin/pfctl -q -t blacklist -T replace -f /var/db/blacklist.txt"); exec("echo spamdb -a {$srcip} > /tmp/tmp"); exec("/usr/local/sbin/spamdb -a {$srcip}"); } elseif ($action == "delete") { exec("/usr/local/sbin/spamdb -d {$srcip}"); exec("/usr/local/sbin/spamdb -d {$srcip} -T"); exec("/usr/local/sbin/spamdb -d {$srcip} -t"); delete_from_blacklist($srcip); mwexec("/sbin/pfctl -q -t spamd -T delete $srcip"); mwexec("/sbin/pfctl -q -t blacklist -T replace -f /var/db/blacklist.txt"); } elseif ($action == "trapped") { exec("/usr/local/sbin/spamdb -d {$srcip}"); exec("/usr/local/sbin/spamdb -d {$srcip}"); exec("/usr/local/sbin/spamdb -d -t {$srcip}"); exec("/usr/local/sbin/spamdb -a -t {$srcip}"); } elseif ($action == "spamtrap") { exec("/usr/local/sbin/spamdb -a -T {$spamtrapemailarg}"); } /* signal a reload for real time effect. */ mwexec("/usr/bin/killall -HUP spamlogd"); exit; } if ($_GET['getstatus'] != "") { $status = exec("/usr/local/sbin/spamdb | /usr/bin/grep " . escapeshellarg($_GET['getstatus'])); if (stristr($status, "WHITE") == true) { echo "WHITE"; } elseif (stristr($status, "TRAPPED") == true) { echo "TRAPPED"; } elseif (stristr($status, "GREY") == true) { echo "GREY"; } elseif (stristr($status, "SPAMTRAP") == true) { echo "SPAMTRAP"; } else { echo "NOT FOUND"; } exit; } /* spam trap e-mail address */ if ($spamtrapemail != "") { $status = exec("/usr/local/sbin/spamdb -T -a {$spamtrapemailarg}"); mwexec("/usr/bin/killall -HUP spamlogd"); if ($status) { echo $status; } else { echo htmlentities($spamtrapemail) . " added to spam trap database."; } exit; } /* whitelist e-mail address */ if ($_GET['whitelist'] != "") { $status = exec("/usr/local/sbin/spamdb -a {$spamtrapemail}"); mwexec("/usr/bin/killall -HUP spamlogd"); if ($status) { echo $status; } else { echo htmlentities($spamtrapemail) . " added to whitelist database."; } exit; } function delete_from_blacklist($srcip) { $blacklist = explode("\n", file_get_contents("/var/db/blacklist.txt")); $fd = fopen("/var/db/blacklist.txt", "w"); foreach ($blacklist as $bl) { if ($bl != "") { if (!stristr($bl, $srcip)) { fwrite($fd, "{$bl}\n"); } } } fclose($fd); mwexec("/sbin/pfctl -q -t spamd -T delete {$srcip}"); mwexec("/sbin/pfctl -q -t blacklist -T replace -f /var/db/blacklist.txt"); } function delete_from_whitelist($srcip) { $whitelist = explode("\n", file_get_contents("/var/db/whitelist.txt")); $fd = fopen("/var/db/whitelist.txt", "w"); foreach($whitelist as $wl) { if ($wl != "") { if (!stristr($wl, $srcip)) { fwrite($fd, "{$wl}\n"); } } } fclose($fd); mwexec("/sbin/pfctl -q -t spamd -T delete $srcip"); mwexec("/sbin/pfctl -q -t whitelist -T replace -f /var/db/whitelist.txt"); } $pgtitle = "SpamD: Database"; include("head.inc"); if (file_exists("/var/db/whitelist.txt")) { $whitelist_items = shell_exec("/bin/cat /var/db/whitelist.txt | /usr/bin/wc -l"); } else { $whitelist_items = 0; } if (file_exists("/var/db/blacklist.txt")) { $blacklist_items = shell_exec("/bin/cat /var/db/blacklist.txt | /usr/bin/wc -l"); } else { $blacklist_items = 0; } // Get an overall count of the database $spamdb_items = shell_exec("/usr/local/sbin/spamdb | /usr/bin/wc -l"); // Get blacklist and whitelist count from database $spamdb_white = shell_exec("/usr/local/sbin/spamdb | /usr/bin/grep WHITE | /usr/bin/wc -l"); $spamdb_black = shell_exec("/usr/local/sbin/spamdb | /usr/bin/grep BLACK | /usr/bin/wc -l"); $spamdb_grey = shell_exec("/usr/local/sbin/spamdb | /usr/bin/grep GREY | /usr/bin/wc -l"); // Now count the user contributed whitelist and blacklist count $whitelist_items = $whitelist_items + $spamdb_white; $blacklist_items = $blacklist_items + $spamdb_black; ?>

Filter by test:  Inverse filter (NOT): />
Limit:
 
* Add spam trap E-mail address:

" . date("H:i:s", $dt); } if ($filter) { if ($not) { $fd = fopen("/tmp/spamdb", "w"); $cmd = "/usr/local/sbin/spamdb | /usr/bin/grep -v " . escapeshellarg($filter) . " | /usr/bin/tail -n {$limit}"; fwrite($fd, $cmd); fclose($fd); exec($cmd, $pkgdb); if (file_exists("/var/db/blacklist.txt")) { $cmd = "/bin/cat /var/db/blacklist.txt | /usr/bin/grep -v \"" . escapeshellarg($filter) . "\" "; exec($cmd, $pkgdba); foreach($pkgdba as $pkg) { $pkgdb[] = "TRAPPED|{$pkg}|1149324397"; } } } else { $cmd = "/usr/local/sbin/spamdb | /usr/bin/grep " . escapeshellarg($filter) . " | /usr/bin/tail -n {$limit}"; exec($cmd, $pkgdb); if (file_exists("/var/db/blacklist.txt")) { $cmd = "/bin/cat /var/db/blacklist.txt | /usr/bin/grep " . escapeshellarg($filter); exec($cmd, $pkgdba); foreach ($pkgdba as $pkg) { $pkgdb[] = "TRAPPED|{$pkg}|1149324397"; } echo ""; } } } else { exec("/usr/local/sbin/spamdb | /usr/bin/tail -n {$limit}", $pkgdb); } $rows = 0; $lastseenip = ""; $srcip = "|"; foreach ($pkgdb as $pkgdb_row) { if($rows > $limit) { break; } $dontdisplay = false; if (!$pkgdb_row) { continue; } $pkgdb_split = explode("|", $pkgdb_row); /* For TRAPPED entries the format is: type|ip|expire where type will be TRAPPED, IP will be the IP address blacklisted due to hitting a spamtrap, and expire will be when the IP is due to be removed from the blacklist. For GREY entries, the format is: type|source IP|helo|from|to|first|pass|expire|block|pass For WHITE entries, the format is: type|source IP|||first|pass|expire|block|pass */ switch($pkgdb_split[0]) { case "SPAMTRAP": $recordtype = htmlentities($pkgdb_split[0]); $srcip = ""; $fromaddress = htmlentities($pkgdb_split[1]); $toaddress = ""; $first = ""; $pass = ""; $expire = ""; $attempts = htmlentities($pkgdb_split[8]); break; case "TRAPPED": $recordtype = htmlentities($pkgdb_split[0]); $srcip = htmlentities($pkgdb_split[1]); $fromaddress = ""; $toaddress = ""; $first = ""; $pass = ""; $expire = formatspamddatetime($pkgdb_split[2]); $attempts = ""; break; case "GREY": $recordtype = htmlentities($pkgdb_split[0]); $srcip = htmlentities($pkgdb_split[1]); $fromaddress = htmlentities($pkgdb_split[3]); $toaddress = htmlentities($pkgdb_split[4]); $first = formatspamddatetime($pkgdb_split[5]); $pass = formatspamddatetime($pkgdb_split[6]); $expire = formatspamddatetime($pkgdb_split[7]); $attempts = htmlentities($pkgdb_split[8]); break; case "WHITE": $recordtype = htmlentities($pkgdb_split[0]); $srcip = htmlentities($pkgdb_split[1]); $fromaddress = ""; $toaddress = ""; $first = formatspamddatetime($pkgdb_split[4]); $pass = formatspamddatetime($pkgdb_split[5]); $expire = formatspamddatetime($pkgdb_split[6]); $attempts = htmlentities($pkgdb_split[8]); break; } if ($srcip == "" and $fromaddress == "" and $toaddress == "") { continue; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $rows++; } ?>
Type IP From To First Pass Expire Attempts
{$recordtype}{$srcip}{$fromaddress}{$toaddress}" . $first . "" . $pass . "" . $expire . "{$attempts}"; $rowtext = "\"Add "; $rowtext .= "\"Blacklist\" "; $rowtext .= "\"Delete\""; $rowtext .= "\"Spamtrap\" "; echo $rowtext; echo "

" . $rows . " rows returned.

"; ?>

* NOTE: adding an e-mail address to the spamtrap automatically traps any server trying to send e-mail to this address.


Note: Clicking on the action icons will invoke a AJAX query and the page will not refresh. Click refresh in your browser if you wish to view the changes in status.

Database totals:

"; echo "{$blacklist_items} total items in the blacklist.
"; echo "{$spamdb_grey} total items in the greylist.
"; echo "{$spamdb_items} total items in the SpamDB.
"; ?>