4 * NP_Blacklist(JP) ($Revision: 1.14 $)
5 * by hsur ( http://blog.cles.jp/np_cles )
6 * $Id: NP_Blacklist.php,v 1.14 2008-06-09 10:33:40 hsur Exp $
8 * Based on NP_Blacklist 0.98
10 * http://forum.nucleuscms.org/viewtopic.php?t=5300
14 * Copyright (C) 2005-2008 cles All rights reserved.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 require_once(dirname(__FILE__)."/blacklist/blacklist_lib.php");
33 class NP_Blacklist extends NucleusPlugin {
35 return 'Blacklist(JP)';
37 function getAuthor() {
38 return 'xiffy + hsur';
41 return 'http://blog.cles.jp/np_cles/category/31/subcatid/11';
43 function getVersion() {
46 function getDescription() {
47 return '[$Revision: 1.14 $]<br />'.NP_BLACKLIST_description;
49 function supportsFeature($what) {
51 case 'SqlTablePrefix' :
59 // create some options
60 $this->createOption('enabled', NP_BLACKLIST_enabled, 'yesno', 'yes');
61 $this->createOption('redirect', NP_BLACKLIST_redirect, 'text', '');
62 $this->createOption('ipblock', NP_BLACKLIST_ipblock, 'yesno', 'yes');
63 $this->createOption('ipthreshold', NP_BLACKLIST_ipthreshold, 'text', '10');
64 $this->createOption('SkipNameResolve', NP_BLACKLIST_SkipNameResolve, 'yesno', 'yes');
66 $this->_initSettings();
69 function unInstall() {
72 function getPluginOption($name) {
73 return $this->getOption($name);
76 function getEventList() {
77 $this->_initSettings();
78 return array ('QuickMenu', 'SpamCheck');
81 function hasAdminArea() {
86 // include language file for this plugin
87 $language = ereg_replace('[\\|/]', '', getLanguageName());
88 if (file_exists($this->getDirectory().'language/'.$language.'.php'))
89 @ include_once ($this->getDirectory().'language/'.$language.'.php');
91 @ include_once ($this->getDirectory().'language/english.php');
92 $this->resultCache = false;
95 function event_QuickMenu(& $data) {
96 global $member, $nucleus, $blogid;
97 // only show to admins
98 if (preg_match("/MD$/", $nucleus['version'])) {
99 $isblogadmin = $member->isBlogAdmin(-1);
101 $isblogadmin = $member->isBlogAdmin($blogid);
103 if (!($member->isLoggedIn() && ($member->isAdmin() | $isblogadmin)))
105 array_push($data['options'], array ('title' => NP_BLACKLIST_name, 'url' => $this->getAdminURL(), 'tooltip' => NP_BLACKLIST_nameTips,));
108 // handle SpamCheck event
109 function event_SpamCheck(& $data) {
110 if (isset ($data['spamcheck']['result']) && $data['spamcheck']['result'] == true) {
111 // Already checked... and is spam
115 if (!isset ($data['spamcheck']['return'])) {
116 $data['spamcheck']['return'] = true;
119 // for SpamCheck API 2.0 compatibility
120 if (!$data['spamcheck']['data']) {
121 switch (strtolower($data['spamcheck']['type'])) {
123 $data['spamcheck']['data'] = $data['spamcheck']['body']."\n";
124 $data['spamcheck']['data'] .= $data['spamcheck']['author']."\n";
125 $data['spamcheck']['data'] .= $data['spamcheck']['url']."\n";
126 $data['spamcheck']['data'] .= $data['spamcheck']['email']."\n";
129 $data['spamcheck']['data'] = $data['spamcheck']['title']."\n";
130 $data['spamcheck']['data'] .= $data['spamcheck']['excerpt']."\n";
131 $data['spamcheck']['data'] .= $data['spamcheck']['blogname']."\n";
132 $data['spamcheck']['data'] .= $data['spamcheck']['url'];
135 $data['spamcheck']['data'] = $data['spamcheck']['url'];
139 $ipblock = ($data['spamcheck']['ipblock'] == true ) || ($data['spamcheck']['live'] == true);
142 $result = $this->blacklist($data['spamcheck']['type'], $data['spamcheck']['data'], $ipblock);
147 pbl_logspammer($data['spamcheck']['type'].': '.$result);
148 if (isset ($data['spamcheck']['return']) && $data['spamcheck']['return'] == true) {
150 $data['spamcheck']['result'] = true;
151 $data['spamcheck']['plugin'] = $this->getName();
152 $data['spamcheck']['message'] = 'Marked as spam by NP_Blacklist';
155 $this->_redirect($this->getOption('redirect'));
160 function blacklist($type, $testString, $ipblock = true) {
162 if ($this->resultCache)
163 return $this->resultCache.'[Cached]';
165 if ($member->isLoggedIn()) {
169 if ($this->getOption('enabled') == 'yes') {
170 // update the blacklist first file
171 //pbl_updateblacklist($this->getOption('update'),false);
173 $ipblock = ($this->getOption('ipblock') == 'yes') ? true : false;
177 if ($ipblock || $testString != '') {
178 $result = pbl_checkforspam($testString, $ipblock, $this->getOption('ipthreshold'), true);
182 $this->resultCache = $result;
189 function _redirect($url) {
191 header("HTTP/1.0 403 Forbidden");
192 header("Status: 403 Forbidden");
194 include (dirname(__FILE__).'/blacklist/blocked.txt');
196 $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $url);
197 header('Location: '.$url);
202 function _initSettings() {
203 $settingsDir = dirname(__FILE__).'/blacklist/settings/';
212 'personal_blacklist.pbl',
216 if ($this->_is_writable($settingsDir)) {
217 // setup distfile
\r foreach (glob($settingsDir.'*.dist') as $distfile) {
218 $userFile = substr($distfile, 0, strlen($distfile)-5);
219 if (!file_exists($userFile)) {
220 if (copy($distfile, $userFile)) {
221 @chmod($userFile, 0666);
222 $this->_warn("'$userFile' ".NP_BLACKLIST_isCreated);
224 $this->_warn("'$userFile' ".NP_BLACKLIST_canNotCreate);
229 foreach ($settings as $setting) {
230 @touch($settingsDir.$setting);
235 foreach ($settings as $setting) {
236 $this->_is_writable($settingsDir.$setting);
239 // setup and check cache dir
240 $cacheDir = NP_BLACKLIST_CACHE_DIR;
241 $this->_is_writable($cacheDir);
244 function _is_writable($file) {
245 $ret = is_writable($file);
247 $this->_warn("'$file' ".NP_BLACKLIST_isNotWritable);
252 function _warn($msg) {
253 ACTIONLOG :: add(WARNING, 'Blacklist: '.$msg);