<?php // vim:sw=4:encoding=UTF-8:nowrap:smartindent:filetype=php:fileformat=unix /** * Nucleus Plugin: NP_PHYFS - PHYFS Help You Fuck the Spammers * * 2006 (c) Jiri Kratochvil * http://www.kl0k.net/ * * This program 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. * * ChangeLog: * Ver: 1.0 * - initial release * * Ver: 1.0.1 * - bugfix for older MySQL (there doesn't work graylist table * creating with: gl_time default now() * * Ver: 1.1 * - ADD new feature, check 'membermail' body for spam * * Ver: 1.1.1 * - FIX: error with message "Testicek" **/ define("PHYFS_HTTP_REGEX","/http:\/\/[^ \t\n]*/"); class NP_PHYFS extends NucleusPlugin { function getName() { return "PHYFS (PHYFS Help You Fuck the Spammers)"; } function getAuthor() { return "kl0k"; } function getURL() { return 'http://www.kl0k.net'; } function getVersion() { return '1.1.1'; } function getDescription() { return <<<EOD This plugin is another attempt to help You, to fight againts the Fucking Spammer Bastards. There are a few simple tests: Count of http links in one comment; Timeout limit for send another comment from same IP address; EOD; } function supportFeature($what) { switch ($what) { case 'SqlTablePrefix'; return 1; default; return 0; } } function getMinNucleusVersion() { return 320; //required because ValidateForm event; } function getEventList() { return array ('ValidateForm'); } function init() { $this->graylist_table = sql_table("plug_PHYFS_graylist"); } function install() { $this->createOption("PHYFS_CheckMembers","Apply PHYFS filter for your site members?","yesno","no"); $this->createOption("HttpRef_Check","Allow HTTP count checking","yesno","yes"); $this->createOption("HttpRef_Count","Allowed count of http references in comment","text","10","datatype=numerical"); $this->createOption("HttpRef_Err","Error messsage if Refence count is exceed","text","Do you really need too many links in your comment? :)"); $this->createOption("GrayList_Check","Allow IP gray list checking","yesno","yes"); $this->createOption("GrayList_TimeOut","Time in second between send comments from same IP","text","10","datatype=numerical"); $this->createOption("GrayList_Err","Error messsage if GrayList filter is positive","text","Are you really able to send comments so quickly? :)"); $query = <<<EOQ CREATE TABLE {$this->graylist_table} ( gl_id int(11) NOT NULL auto_increment, gl_ip varchar(30) NOT NULL, gl_time timestamp NOT NULL, PRIMARY KEY (gl_id) ) EOQ; sql_query($query); } function unInstall() { $this->deleteOption("PHYFS_CheckMembers"); $this->deleteOption("HttpRef_Check"); $this->deleteOption("HttpRef_Count"); $this->deleteOption("HttpRef_Err"); $this->deleteOption("GrayList_Check"); $this->deleteOption("GrayList_TimeOut"); $this->deleteOption("GrayList_Err"); $query = <<<EOQ DROP TABLE {$this->graylist_table} EOQ; sql_query($query); } function getTableList() { return array(sql_table('plug_PHYFS_graylist')); } var $user,$mail,$data; function mustVerify(&$data) { global $member; //$verify = ($data['type'] == 'comment') && (($this->getOption('PHYFS_CheckMembers') == 'yes') || (!$member->isLoggedIn())); //var_dump($verify); return (($data['type'] == 'comment') || ($data['type'] == 'membermail')) && (($this->getOption('PHYFS_CheckMembers') == 'yes') || (!$member->isLoggedIn())); } /* heart of plugin */ function event_ValidateForm(&$data) { if ($data['type'] == 'membermail') { $this->data = postVar('message'); } else if ($data['type'] == 'comment') { $this->data = $data['comment']['body']; } if ($this->mustVerify($data)) { if ($this->getOption('HttpRef_Check') == 'yes') { $this->validate_HttpCount($data); } if ($this->getOption('GrayList_Check') == 'yes') { $this->validate_GrayList($data); } } } function validate_HttpCount(&$data) { $refcnt = preg_match_all(PHYFS_HTTP_REGEX,$this->data,$matches); if (((int)$this->getOption("HttpRef_Count")) < $refcnt) { $data['error'] = $this->getOption("HttpRef_Err"); ACTIONLOG::add(INFO, "PHYFS block " . $data['type'] . " (http refr count exceed($refcnt)): '" . $this->data . "'"); } } function validate_GrayList(&$data) { $timeout = $this->getOption('GrayList_TimeOut'); $ip = $_SERVER['REMOTE_ADDR']; // do clear graylist from timeouted IP $query = <<<EOQ DELETE FROM {$this->graylist_table} WHERE gl_time+{$timeout} < now() EOQ; sql_query($query); // do check against current graylisted IP $query =<<<EOQ SELECT * FROM {$this->graylist_table} WHERE gl_time+{$timeout} >= now() AND gl_ip = '{$ip}' EOQ; $res = sql_query($query); $rows = mysql_num_rows($res); // do check against GrayList_TimeOut if ($rows > 0) { $data['error'] = $this->getOption("GrayList_Err"); ACTIONLOG::add(INFO, "PHYFS block " . $data['type'] . " (gl timeout): '" . $this->data . "'"); } // last but not least insert graylist record $query = <<<EOQ INSERT INTO {$this->graylist_table} VALUES (NULL,'{$ip}',NULL); EOQ; //var_dump($result); sql_query($query); } } ?>