$next = True; break; } } } } } // RBL check if (!$next) { $sites = $wpdb->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='rbld'"); if ($sites) { foreach ($sites as $site) { $regex = $site->regex; $str = $comment->comment_content; $str .= ' ' . $comment->comment_url; if ($domains = wpbl_get_domain($str)) { foreach ($domains as $domain) { $rblhost = $domain . "." . $regex; $resolved = gethostbyname($rblhost); if ($resolved != $rblhost) { $s_result = array(); $s_result['record'] = $comment; $s_result['reason'] = 'RBL DOMAIN'; $s_result['pattern'] = $domain; $s_results[] = $s_result; $next = True; break; } } } }
function blacklist($commentID) { global $wpbl_options, $wpbl_comment, $tableblacklist, $approved; $wpbl_comment = get_commentdata($commentID, 1, false); // first check the comment status based on WP core moderation $stat = wp_get_comment_status($commentID); if ($stat == 'deleted') { // no need to proceed since there is no comment return; } else { if ($stat == 'unapproved') { $held = True; } else { $held = False; } } // are we supposed to delete comments held by the core? if ($held && in_array('deletecore', $wpbl_options)) { mail_and_del($commentID, "Mail held for moderation outside WPBlacklist"); return; } else { if ($held && !in_array('checkcore', $wpbl_options)) { // comment held for moderation but option to check against blacklist not specified return; } } // IP check $sites = $GLOBALS['wpdb']->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='ip'"); if ($sites) { foreach ($sites as $site) { $regex = "/^{$site->regex}/"; if (preg_match($regex, $wpbl_comment['comment_author_IP'])) { $held = True; if (in_array('deleteip', $wpbl_options)) { $approved = 'deleted'; mail_and_del($commentID, "Author IP: {$wpbl_comment['comment_author_IP']} matched {$regex}"); return; } break; } } } // RBL check if (!$held || in_array('deleterbl', $wpbl_options)) { $sites = $GLOBALS['wpdb']->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='rbl'"); if ($sites) { foreach ($sites as $site) { $regex = $site->regex; if (preg_match("/([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)/", $wpbl_comment['comment_author_IP'], $matches)) { $rblhost = $matches[4] . "." . $matches[3] . "." . $matches[2] . "." . $matches[1] . "." . $regex; $resolved = gethostbyname($rblhost); if ($resolved != $rblhost) { $held = True; if (in_array('deleterbl', $wpbl_options)) { mail_and_del($commentID, "Author IP: {$wpbl_comment['comment_author_IP']} blacklisted by RBL {$regex}"); return; } break; } } } } $sites = $GLOBALS['wpdb']->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='rbld'"); if ($sites) { foreach ($sites as $site) { $regex = $site->regex; $str = $wpbl_comment['comment_content']; $str .= ' ' . $wpbl_comment['comment_url']; if ($domains = wpbl_get_domain($str)) { foreach ($domains as $domain) { $rblhost = $domain . "." . $regex; $resolved = gethostbyname($rblhost); if ($resolved != $rblhost) { $held = True; if (in_array('deleterbl', $wpbl_options)) { mail_and_del($commentID, "URL({$domain}) in a Comment text contained blacklisted by RBL {$regex}"); return; } break; } } } } } } // expression check if (!$held || in_array('deletemail', $wpbl_options) || in_array('deleteurl', $wpbl_options) || in_array('delcommurl', $wpbl_options)) { $sites = $GLOBALS['wpdb']->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='url'"); if ($sites) { foreach ($sites as $site) { $regex = "/{$site->regex}/i"; // echo "Regex: $regex <br />"; if (preg_match($regex, $wpbl_comment['comment_author_url'])) { $held = True; if (in_array('deleteurl', $wpbl_options)) { $approved = 'deleted'; mail_and_del($commentID, "Author URL: {$wpbl_comment['comment_author_url']} matched {$regex}"); return; } break; } if (preg_match($regex, $wpbl_comment['comment_author_email'])) { $held = True; if (in_array('deletemail', $wpbl_options)) { mail_and_del($commentID, "Author e-mail: {$wpbl_comment['comment_author_email']} matched {$regex}"); return; } break; } if (preg_match($regex, $wpbl_comment['comment_content'])) { $held = True; if (in_array('delcommurl', $wpbl_options)) { $approved = 'deleted'; mail_and_del($commentID, "Comment text contained {$regex}"); return; } break; } } } } if ($wpbl_comment['comment_type'] == 'trackback' && (!$held || in_array('deltbsp', $wpbl_options))) { // Let's check the remote site require_once XOOPS_ROOT_PATH . '/class/snoopy.php'; $snoopy = new Snoopy(); if ($snoopy->fetch($wpbl_comment['comment_author_url'])) { $orig_contents = $snoopy->results; } if (!strpos($orig_contents, wp_siteurl())) { $held = True; if (in_array('deltbsp', $wpbl_options)) { $approved = 'deleted'; mail_and_del($commentID, "TrackBack URL does not contain my site URL"); return; } } } if ($held) { $approved = 0; wp_set_comment_status($commentID, 'hold'); } else { $approved = 1; wp_set_comment_status($commentID, 'approve'); } // the following is essential not to break other plugins return $commentID; }