<?php
/**
- * NP_Blacklist(JP) ($Revision: 1.8 $)
+ * NP_Blacklist(JP) ($Revision: 1.14 $)
* by hsur ( http://blog.cles.jp/np_cles )
- * $Id: NP_Blacklist.php,v 1.8 2007-02-11 08:57:12 hsur Exp $
+ * $Id: NP_Blacklist.php,v 1.14 2008-06-09 10:33:40 hsur Exp $
*
* Based on NP_Blacklist 0.98
* by xiffy
*/
/*
- * Copyright (C) 2005-2007 cles All rights reserved.
+ * Copyright (C) 2005-2008 cles All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-include_once(dirname(__FILE__)."/blacklist/blacklist_lib.php");
+require_once(dirname(__FILE__)."/blacklist/blacklist_lib.php");
class NP_Blacklist extends NucleusPlugin {
function getName() {
return 'http://blog.cles.jp/np_cles/category/31/subcatid/11';
}
function getVersion() {
- return '1.0.2';
+ return '1.3.1';
}
function getDescription() {
- return '[$Revision: 1.8 $]<br />'.NP_BLACKLIST_description;
+ return '[$Revision: 1.14 $]<br />'.NP_BLACKLIST_description;
}
function supportsFeature($what) {
switch ($what) {
$this->createOption('redirect', NP_BLACKLIST_redirect, 'text', '');
$this->createOption('ipblock', NP_BLACKLIST_ipblock, 'yesno', 'yes');
$this->createOption('ipthreshold', NP_BLACKLIST_ipthreshold, 'text', '10');
- $this->createOption('BulkfeedsKey', NP_BLACKLIST_BulkfeedsKey, 'text', '');
$this->createOption('SkipNameResolve', NP_BLACKLIST_SkipNameResolve, 'yesno', 'yes');
$this->_initSettings();
// handle SpamCheck event
function event_SpamCheck(& $data) {
- global $DIR_PLUGINS;
if (isset ($data['spamcheck']['result']) && $data['spamcheck']['result'] == true) {
// Already checked... and is spam
return;
$data['spamcheck']['data'] = $data['spamcheck']['body']."\n";
$data['spamcheck']['data'] .= $data['spamcheck']['author']."\n";
$data['spamcheck']['data'] .= $data['spamcheck']['url']."\n";
+ $data['spamcheck']['data'] .= $data['spamcheck']['email']."\n";
break;
case 'trackback' :
$data['spamcheck']['data'] = $data['spamcheck']['title']."\n";
break;
}
}
- $ipblock = ($data['spamcheck']['ipblock']) || ($data['spamcheck']['live']);
+ $ipblock = ($data['spamcheck']['ipblock'] == true ) || ($data['spamcheck']['live'] == true);
// Check for spam
$result = $this->blacklist($data['spamcheck']['type'], $data['spamcheck']['data'], $ipblock);
}
}
- // Obsolete
- function event_PreAddComment(& $data) {
- $comment = $data['comment'];
- $result = $this->blacklist('comment', postVar('body')."\n".$comment['host']."\n".$comment['user']."\n".$comment['userid']);
- if ($result) {
- pbl_logspammer('comment: '.$result);
- $this->_redirect($this->getOption('redirect'));
- }
- }
-
- // Obsolete
- function event_ValidateForm(& $data) {
- if ($data['type'] == 'comment') {
- $comment = $data['comment'];
- $result = $this->blacklist('comment', postVar('body')."\n".$comment['host']."\n".$comment['user']."\n".$comment['userid']);
- if ($result) {
- pbl_logspammer('comment: '.$result);
- $this->_redirect($this->getOption('redirect'));
- }
- } else {
- if ($data['type'] == 'membermail') {
- $result = $this->blacklist('membermail', postVar('frommail')."\n".postVar('message'));
- if ($result) {
- pbl_logspammer('membermail: '.$result);
- $this->_redirect($this->getOption('redirect'));
- }
- }
- }
- }
-
- // Obsolete
- function event_PreSkinParse(& $data) {
- $result = $this->blacklist('PreSkinParse', '');
- if ($result) {
- pbl_logspammer('PreSkinParse: '.$result);
- $this->_redirect($this->getOption('redirect'));
- }
- }
-
function blacklist($type, $testString, $ipblock = true) {
- global $DIR_PLUGINS, $member;
+ global $member;
if ($this->resultCache)
return $this->resultCache.'[Cached]';
}
}
- function submitSpamToBulkfeeds($url) {
- if (is_array($url))
- $url = implode("\n", $url);
-
- $postData['apikey'] = $this->getOption('BulkfeedsKey');
- if (!$postData['apikey'])
- return "BulkfeedsKey not found. see http://bulkfeeds.net/app/register_api.html";
- $postData['url'] = $url;
-
- $data = $this->_http('http://bulkfeeds.net:80/app/submit_spam.xml', 'POST', '', $postData);
- return $data;
- }
-
- function _http($url, $method = "GET", $headers = "", $post = array ("")) {
- $URL = parse_url($url);
-
- if (isset ($URL['query'])) {
- $URL['query'] = "?".$URL['query'];
- } else {
- $URL['query'] = "";
- }
-
- if (!isset ($URL['port']))
- $URL['port'] = 80;
-
- $request = $method." ".$URL['path'].$URL['query']." HTTP/1.0\r\n";
-
- $request .= "Host: ".$URL['host']."\r\n";
- $request .= "User-Agent: NP_Blacklist/".phpversion()."\r\n";
-
- if (isset ($URL['user']) && isset ($URL['pass'])) {
- $request .= "Authorization: Basic ".base64_encode($URL['user'].":".$URL['pass'])."\r\n";
- }
-
- $request .= $headers;
-
- if (strtoupper($method) == "POST") {
- while (list ($name, $value) = each($post)) {
- $POST[] = $name."=".urlencode($value);
- }
- $postdata = implode("&", $POST);
- $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
- $request .= "Content-Length: ".strlen($postdata)."\r\n";
- $request .= "\r\n";
- $request .= $postdata;
- } else {
- $request .= "\r\n";
- }
-
- $fp = fsockopen($URL['host'], $URL['port'], $errno, $errstr, 20);
-
- if ($fp) {
- socket_set_timeout($fp, 20);
- fputs($fp, $request);
- $response = "";
- while (!feof($fp)) {
- $response .= fgets($fp, 4096);
- }
- fclose($fp);
- $DATA = split("\r\n\r\n", $response, 2);
- return $DATA[1];
- } else {
- $host = $URL['host'];
- $port = $URL['port'];
- ACTIONLOG :: add(WARNING, $this->getName().':'."[$errno]($host:$port) $errstr");
- return "";
- }
- }
-
function _redirect($url) {
if (!$url) {
header("HTTP/1.0 403 Forbidden");
function _initSettings() {
$settingsDir = dirname(__FILE__).'/blacklist/settings/';
- $settings = array ('blacklist.log', 'blockip.pbl', 'matched.pbl', 'blacklist.pbl', 'blacklist.txt', 'suspects.pbl',);
- $personalBlacklist = $settingsDir.'personal_blacklist.pbl';
- $personalBlacklistDist = $settingsDir.'personal_blacklist.pbl.dist';
+ $settings = array (
+ 'blacklist.log',
+ 'blockip.pbl',
+ 'whiteip.pbl',
+ 'matched.pbl',
+ 'blacklist.pbl',
+ 'blacklist.txt',
+ 'suspects.pbl',
+ 'personal_blacklist.pbl',
+ );
// setup settings
if ($this->_is_writable($settingsDir)) {
- foreach ($settings as $setting) {
- touch($settingsDir.$setting);
- }
- // setup personal blacklist
- if (!file_exists($personalBlacklist)) {
- if (copy($personalBlacklistDist, $personalBlacklist)) {
- $this->_warn("'$personalBlacklist' ".NP_BLACKLIST_isCreated);
- } else {
- $this->_warn("'$personalBlacklist' ".NP_BLACKLIST_canNotCreate);
+ // setup distfile\r foreach (glob($settingsDir.'*.dist') as $distfile) {
+ $userFile = substr($distfile, 0, strlen($distfile)-5);
+ if (!file_exists($userFile)) {
+ if (copy($distfile, $userFile)) {
+ @chmod($userFile, 0666);
+ $this->_warn("'$userFile' ".NP_BLACKLIST_isCreated);
+ } else {
+ $this->_warn("'$userFile' ".NP_BLACKLIST_canNotCreate);
+ }
}
}
+
+ foreach ($settings as $setting) {
+ @touch($settingsDir.$setting);
+ }
}
// check settings
foreach ($settings as $setting) {
$this->_is_writable($settingsDir.$setting);
}
- $this->_is_writable($personalBlacklist);
// setup and check cache dir
$cacheDir = NP_BLACKLIST_CACHE_DIR;