This file is part of phpCF. phpCF is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. phpCF is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with phpCF; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ /** * NAMING CONVENTIONS: * Content check functions are prefixed with "c_" * Email check functions are prefixed with "ec_" * Failing to obey these simple naming conventions, will result * in the check never being run. */ require_once 'class.CFBase.php'; class CF extends CFBase { // Scanning methods function c_num_urls($text) { global $NUM_URLS; // The hardcore regex for url matching: preg_match_all("/((f|ht)tps?\:\/\/)([a-z0-9@:%_.~#\-\?&-]+)((\=|[a-z0-9]|\?|&|%|\/|\.|-|:|æ|ø|å)+){0,}/msi", $text, $matches); // And the light, but efficient: // preg_match_all("/(ht|f)tp(s?)\:\/\//msi", $text, $matches); $urls = count($matches[0]); $score = $NUM_URLS * $urls; if ($urls > 0) { $this->log[] = "num_urls: $urls URL(s) found (+$score)"; } return $score; } function c_poker_ref($text) { global $POKER_REF; preg_match_all("/\b(poker|texas(\s|-)hold(\s?)em|blackjack|gambling)\b/msi", $text, $matches); $ref = count($matches[0]); $score = $POKER_REF * $ref; if ($ref > 0) { $this->log[] = "poker_ref: $ref poker reference(s) found (+$score)"; } return $score; } function c_medic_ref($text) { global $MEDIC_REF; preg_match_all("/\b(viagra|phentermine)\b/msi", $text, $matches); $ref = count($matches[0]); $score = $MEDIC_REF * $ref; if ($ref > 0) { $this->log[] = "medic_ref: $ref medicine reference(s) found (+$score)"; } return $score; } function c_html_percentage($text) { global $HTML_PERCENTAGE; global $HTML_PERCENTAGE_ALLOW_TAGS; $orig = $text; $stripped = strip_tags($text, $HTML_PERCENTAGE_ALLOW_TAGS); $percent = round(((strlen($orig)-strlen($stripped)) / strlen($orig)) * 100); $score = $HTML_PERCENTAGE * $percent; if ($return > 0) { $this->log[] = "html_percentage: $percent% (+$score)"; } return $score; } // FIXME: This blacklist doesn't exist anymore. :-/ // Remove all references to it. /* {{{ Dysfunctional now... function c_ja_blacklist($text) { global $CACHE_DIR; global $NET_ALLOWED; global $JA_BLACKLIST; global $JA_BLACKLIST_EXPIRES; if (!$NET_ALLOWED) { return 0; } $bl = preg_replace("/\/$/", "", $CACHE_DIR) . "/ja_blacklist.txt"; $bl_url = "http://www.jayallen.org/comment_spam/blacklist_initial.txt"; if (!file_exists($bl)) { $this->debug("File: $bl doesn't exist. Are you sure CACHE_DIR is set correctly?"); $JA_BLACKLIST = 0; } else if (!is_writable($bl)) { $this->debug("File: $bl isn't writable. Cannot update cache!"); $JA_BLACKLIST_EXPIRES = 999999999999999; } if ($JA_BLACKLIST > 0) { // Is the blacklist outdated? if (time() - filemtime($bl) > $JA_BLACKLIST_EXPIRES) { $this->debug("Attempting to update $bl ..."); // It is, write a fresh one. $cache = @implode("", @file($bl_url)); if ($cache === false) { $this->debug("Couldn't fetch $bl_url"); } else { $fh = @fopen($bl, "w"); if (is_resource($fh)) { if (@fwrite($fh, $cache) === false) { $this->debug("Couldn't write to file: $bl"); } @fclose($fh); } } } // Make an array of the regex's in ja_blacklist.txt function stripComments($str) { return trim(preg_replace("/^(.*?)#.*$/", "\\1", $str)); } $regArr = array_map("stripComments", file($bl)); foreach ($regArr as $k => $v) { if (empty($v)) { unset($regArr[$k]); } } // Start scoring. $score = 0; foreach ($regArr as $regex) { $m = preg_match_all(":$regex:", $text, $matches); if ($m > 0 && $m !== false) { $score += $JA_BLACKLIST * $m; $this->debug("ja_blacklist: Pattern \"$regex\" matched $m time(s)"); } else if ($m === false) { $this->debug("ja_blacklist: Error with pattern: $regex"); } } if ($score > 0) { $this->log[] = "ja_blacklist: " . ($score / $JA_BLACKLIST) . " hits (+$score)"; } return $score; } } }}} */ // Email checking methods: function ec_alpha_num($email) { global $ALPHA_NUM; if (preg_match("/^[a-z\_\-]+[0-9]+@/i", $email)) { $this->log[] = "alpha_num: Email username ending in numeric characters (+$ALPHA_NUM)"; return $ALPHA_NUM; } else { return 0; } } // IP checking methods: function ic_ln_blacklisted($ip) { global $NET_ALLOWED; global $LN_BLACKLISTED; if ($LN_BLACKLISTED > 0 && $NET_ALLOWED) { $bl_url = "http://lillesvin.net/bl.txt"; $bl = array(); foreach (file($bl_url) as $l) { if (preg_match("/^HOST:\s/", $l)) { $bl[] = trim(preg_replace("/^HOST:\s(.*)$/", "\\1", $l)); } } if (in_array($ip, $bl)) { $this->log[] = "ln_blacklisted: IP is blacklisted by Lillesvin Networks (+$LN_BLACKLISTED)"; $return = $LN_BLACKLISTED; } else { $return = 0; } return $return; } else { return 0; } } } ?>