function filter_this(&$cmt_object)
 {
     $this->ID = $cmt_object->ID;
     $this->snowball_by($cmt_object, "IP", "AND `comments`.`comment_author_IP` = '" . $cmt_object->author_ip . "'", 1, 1);
     if (!empty($cmt_object->author_url['domain'])) {
         $my_url = $cmt_object->author_url['domain'];
         global $sk2_blacklist;
         if ($grey_rows = $sk2_blacklist->match_entries('domain_grey', $my_url, true, 80)) {
             $my_url = $cmt_object->author_url['url'];
         }
         if (count($cmt_object->content_links)) {
             $this->snowball_by($cmt_object, "URL", "AND `comments`.`comment_author_url` LIKE '%" . sk2_escape_string($my_url) . "%'", 1, 0.02);
         } else {
             $this->snowball_by($cmt_object, "URL", "AND `comments`.`comment_author_url` LIKE '%" . sk2_escape_string($my_url) . "%'", 1.5, 1);
         }
     }
     if (!empty($cmt_object->author_email)) {
         $this->snowball_by($cmt_object, "email", "AND `comments`.`comment_author_email` = '" . sk2_escape_string($cmt_object->author_email) . "'", 0.5, 2);
     }
 }
 function match_entries($match_type, $match_value, $strict = true, $min_score = 0, $limit = 0)
 {
     global $wpdb;
     if ($strict) {
         $sql_match = "= '" . sk2_escape_string($match_value) . "'";
     } else {
         $sql_match = "LIKE '%" . sk2_escape_string($match_value) . "%'";
     }
     switch ($match_type) {
         case 'url':
         case 'url_black':
         case 'url_white':
             if ($match_type == 'url_black') {
                 $query_where = "(`value` " . strtolower($sql_match) . " AND (`type` = 'domain_black')) OR (`id` IN(";
                 $query_where_regex = "`type` = 'regex_black'";
             } elseif ($match_type == 'url_white') {
                 $query_where = "(`value` " . strtolower($sql_match) . " AND `type` = 'domain_white') OR (`id` IN(";
                 $query_where_regex = "`type` = 'regex_white'";
             } else {
                 $query_where = "(`value` " . strtolower($sql_match) . " AND (`type` = 'domain_black' OR `type` = 'domain_white' OR `type` = 'domain_grey')) OR (`id` IN(";
                 $query_where_regex = "`type` = 'regex_white' OR `type` = 'regex_black'";
             }
             if ($regex_recs = $wpdb->get_results("SELECT * FROM `" . sk2_kBlacklistTable . "` WHERE {$query_where_regex}")) {
                 foreach ($regex_recs as $regex_rec) {
                     //echo $regex_rec->value, " ?match? " , $match_value;
                     if (preg_match($regex_rec->value, $match_value)) {
                         $query_where .= $regex_rec->id . ", ";
                     }
                 }
             }
             $query_where .= "-1))";
             break;
         case 'regex_match':
         case 'regex_content_match':
             if ($match_type == 'regex_match') {
                 $type = 'regex';
             } else {
                 $type = 'regex_content';
             }
             $query_where = "`id` IN(";
             if ($regex_recs = $wpdb->get_results("SELECT * FROM `" . sk2_kBlacklistTable . "` WHERE `type` = '{$type}_white' OR `type` = '{$type}_black'")) {
                 foreach ($regex_recs as $regex_rec) {
                     //echo $regex_rec->value, " ?match? " , $match_value;
                     $res = @preg_match($regex_rec->value, $match_value);
                     if ($res === FALSE) {
                         $this->log_msg(sprintf(__("Regex ID: %d (<code>%s</code>) appears to be an invalid regex string! Please fix it in the Blacklist control panel.", 'sk2'), $regex_rec->id, $regex_rec->value), 7);
                     } elseif ($res) {
                         $query_where .= $regex_rec->id . ", ";
                     }
                 }
             }
             $query_where .= "-1)";
             break;
         case 'domain_black':
         case 'ip_black':
         case 'domain_white':
         case 'ip_white':
             if (($match_type == 'domain_black' || $match_type == 'domain_white') && ($grey_rslt = $wpdb->get_results("SELECT * FROM `" . sk2_kBlacklistTable . "` WHERE `type` = 'domain_grey' AND `value` {$sql_match}"))) {
                 $query_where = "";
                 $this->log_msg(__("Grey blacklist match: ignoring."), 6);
             } else {
                 $query_where = "(`value` {$sql_match} AND `type` = '" . $match_type . "')";
             }
             break;
         case 'domain_grey':
             $query_where = "(`value` {$sql_match} AND `type` = 'domain_grey')";
             break;
         case 'domain':
         case 'ip':
         case 'regex':
             if ($match_type == 'domain' && ($grey_rslt = $wpdb->get_results("SELECT * FROM `" . sk2_kBlacklistTable . "` WHERE `type` = 'domain_grey' AND `value` {$sql_match}"))) {
                 $query_where = "";
                 $this->log_msg(__("Grey blacklist match: ignoring."), 6);
             } else {
                 //$this->log_msg("BLAAAAA: $sql_match. ". "SELECT * FROM `" . sk2_kBlacklistTable . "` WHERE `type` = 'domain_grey' AND `value` $sql_match", 7);
                 $query_where = "(`value` {$sql_match} AND (`type` = '" . $match_type . "_black' OR `type` = '" . $match_type . "_white'))";
             }
             break;
         case 'all':
             $query_where = "`value` {$sql_match}";
             break;
         case 'kumo_seed':
         case 'rbl_server':
         default:
             $query_where = "`value` {$sql_match} AND `type` = '{$match_type}'";
             break;
     }
     if (empty($query_where)) {
         return false;
     } else {
         if ($min_score) {
             $query_where .= " AND `score` > {$min_score}";
         }
         if ($min_trust) {
             $query_where .= " AND `trust` > {$min_trust}";
         }
         $query = "SELECT * FROM `" . sk2_kBlacklistTable . "` WHERE {$query_where} ORDER BY `score` DESC";
         if ($limit) {
             $query .= ' LIMIT ' . $limit;
         }
         //echo $query;
         $blacklist_rows = $wpdb->get_results($query);
         if (mysql_error()) {
             $this->log_msg(__("Failed to query blacklist: ", 'sk2') . "<em>{$match_type}</em> - <em>{$match_value}</em>. " . __("Query: ", 'sk2') . $query, 8, true);
             return false;
         }
         return $blacklist_rows;
     }
 }
Exemple #3
0
 function set_comment_sk_info($comment_ID = 0, $comment_sk_info = 0, $append = false)
 {
     // if $comment_ID != 0: must provide $comment_sk_info
     global $sk2_settings, $wpdb;
     if (!$comment_ID) {
         if (!$this->cur_comment->ID) {
             $this->log_msg(__("Cannot update sk2_kSpamTable info (no comment ID provided)."), 8);
             return false;
         }
         $comment_sk_info = array();
         $comment_ID = $comment_sk_info['comment_ID'] = $this->cur_comment->ID;
         $comment_sk_info['karma'] = $this->cur_comment->karma;
         $comment_sk_info['karma_cmts'] = $this->cur_comment->karma_cmts;
         $comment_sk_info['unlock_keys'] = $this->cur_comment->unlock_keys;
         $comment_sk_info['remaining_attempts'] = $this->cur_comment->remaining_attempts;
     }
     $comment_sk_info_orig = $this->get_comment_sk_info($comment_ID);
     if ($comment_sk_info_orig) {
         if ($append) {
             if (!is_array($comment_sk_info_orig->karma_cmts)) {
                 $comment_sk_info_orig->karma_cmts = array();
             }
             if (!is_array($comment_sk_info_orig->unlock_keys)) {
                 $comment_sk_info_orig->unlock_keys = array();
             }
             if (!is_array($comment_sk_info['karma_cmts'])) {
                 $comment_sk_info['karma_cmts'] = array();
             }
             if (!is_array($comment_sk_info['unlock_keys'])) {
                 $comment_sk_info['unlock_keys'] = array();
             }
             $comment_sk_info['karma_cmts'] = $comment_sk_info_orig->karma_cmts + $comment_sk_info['karma_cmts'];
             $comment_sk_info['unlock_keys'] = $comment_sk_info_orig->unlock_keys + $comment_sk_info['unlock_keys'];
             if (!isset($comment_sk_info['karma'])) {
                 $comment_sk_info['karma'] = $comment_sk_info_orig->karma;
             }
             if (!isset($comment_sk_info['remaining_attempts'])) {
                 $comment_sk_info['remaining_attempts'] = $comment_sk_info_orig->remaining_attempts;
             }
             //	print_r($comment_sk_info);
         }
         $query = "UPDATE `" . sk2_kSpamTable . "` SET ";
         $query_end = "`last_mod` = NOW() WHERE `id` = " . $comment_sk_info_orig->id;
     } else {
         $query = "INSERT INTO `" . sk2_kSpamTable . "` SET ";
         $query_end = "`last_mod` = NOW(), `comment_ID` = {$comment_ID}";
     }
     foreach ($comment_sk_info as $key => $val) {
         if ($key == 'comment_ID') {
             continue;
         }
         if (is_array($val)) {
             $val = serialize($val);
         }
         if (is_int($val) || is_float($val)) {
             $query .= "`{$key}` = " . $val . ",";
         } else {
             $query .= "`{$key}` = '" . sk2_escape_string($val) . "', ";
         }
     }
     $query .= $query_end;
     //echo $query;
     $wpdb->query($query);
     if (!mysql_error()) {
         $this->log_msg(__("Inserted/Updated sk2_kSpamTable record for comment ID: ", 'sk2') . $comment_ID . " (" . ($append ? __("mode: append", 'sk2') : __("mode: overwrite", 'sk2')) . ").", 0);
     } else {
         $this->log_msg(__("Failed inserting/updating sk2_kSpamTable record for comment ID:", 'sk2') . $comment_ID . " (" . ($append ? __("mode: append", 'sk2') : __("mode: overwrite", 'sk2')) . "). <br/>" . __("Query: ", 'sk2') . "<code>{$query}</code>", 8, true);
     }
 }
Exemple #4
0
 function log_msg($msg, $level = 0, $comment_id = 0, $component = "", $live = false, $div_wrapper = true)
 {
     global $wpdb;
     if ($this->live_output && ($level >= $this->live_threshold || $live)) {
         if ($div_wrapper) {
             echo "<div class=\"wrap sk_first\">\n";
         }
         echo "<div class=\"sk2_log sk_level_{$level}\">{$msg}</div>";
         if ($div_wrapper) {
             echo "</div>";
         }
         $echoed = true;
     } else {
         $echoed = false;
     }
     $this->logs[] = array($msg, $level, $comment_id, time(), $echoed);
     if ($level >= $this->db_threshold) {
         @$wpdb->query("INSERT INTO `" . sk2_kLogTable . "` SET `msg` = '" . sk2_escape_string($msg) . "', `component` = '" . sk2_escape_string($component) . "', `level` = {$level}, `ts` = NOW()");
     }
 }