• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revisionb0511fa13601434abbcf44946c9da381fa732c4e (tree)
Time2006-09-30 18:48:05
Authorhsur <hsur@1ca2...>
Commiterhsur

Log Message

v0.98 jp8 import

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@386 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- /dev/null
+++ b/trunk/NP_Blacklist/NP_Blacklist.php
@@ -0,0 +1,408 @@
1+<?php
2+
3+/* */
4+/* NP_Blacklist */
5+/* ------------------------------------ */
6+/* version information ---------------- */
7+/* 0.90 initial release */
8+/* 0.91 issues with xhtml compliance. sloppy coding removed */
9+/* 0.92 added user, userid and host to check for spam */
10+/* 0.93 bug in fetching fresh blacklist solved */
11+/* 0.94 code cleanup,no more pivot specific functions and files */
12+/* 0.952 added the posibility to block on the referrerfield against the same lists
13+ added the option to ip-ban the commenting machine (commented out! with //ip
14+ remove all '//ip' if you want to checkout this functionality.
15+ personally i don't like it -xiffy-
16+*/
17+/* 0.95b2 removed ip-ban option.
18+ added the yet non-existent event PreActioAddComment to kick in at the right moment
19+ and not 'too late'. Solves emailnotification problem on adding comments
20+*/
21+/* 0.95 final
22+ removed the option to have a different url for referrer spamming. This will grow wild
23+ if more spam-blocking types (like trackback) will be introduced.
24+ So 1 url to serve them all.
25+ the function blacklist is from now on the 1 function to call from other plugins
26+ to call blacklist from inside your plugin add the following code:
27+--deleted obsolete call for blacklist --
28+*/
29+/* 0.96 Beta
30+ added ip-based blocking. This option differs from earlier attempts to add the ip to the nucleus ip-ban
31+ Now, wehn a machine spam your website above the ip-block-threshold (default 10) the machine will be added
32+ to the blocked ip addresses table. This way, newly undiscovered spamming domains won't be showing up
33+ easily since most spamming is done by a subset of machines (zombies)
34+ added menu item to maintain blocked ip-addresses.
35+*/
36+/* 0.96 Beta 2
37+ .htaccess snippets work. Thanks to Karma for his regexp reworke
38+ there are two modes, one for blocked IP's and one for matched rules, each give a different kind of output
39+ Once you've generated the rules and incorporated the finished result into your .htaccess you should Reset the file.
40+ Otherwise you would end up with doubles inside your .htaccess, this should be avoided, but is completly acceptable for apache.
41+*/
42+/* 0.96 Beta 3
43+ Plugins calling plugins. Rakaz and I think we made it happen on a way that is future prove and a proof of concept for
44+ other plugin writers. This plugin listens to the event SpamCheck, which is unknown inside nucleus-core.
45+ NP_MailToAFriend, NP_Trackback and Referrer2 call this plugin if it is installed. It handles redirection itself.
46+ The easy way:
47+// check for spam attempts, you never knnow !
48+ $spamcheck = array ('type' => 'MailtoaFriend',
49+ 'data' => $extra."\n".$toEmail."\n".$fromEmail);
50+ $manager->notify('SpamCheck', array ('spamcheck' => & $spamcheck));
51+// done
52+ The hard way and Total Control!
53+ $spamcheck = array (
54+ 'type' => 'Referer',
55+ 'data' => 'data that needs to be checked',
56+ 'return' => true
57+ );
58+
59+ $manager->notify('SpamCheck',
60+ array ('spamcheck' => & $spamcheck)
61+ );
62+
63+ if (isset($spamcheck['result']) &&
64+ $spamcheck['result'] == true)
65+ {
66+ // Handle spam
67+ }
68+*/
69+/* 0.97 Added eventHandler for the new ValidateForm event (nucleus 3.2)
70+*/
71+/* 0.98 Solved naar.be bug
72+*/
73+
74+class NP_Blacklist extends NucleusPlugin {
75+ function getName() { return 'Blacklist'; }
76+ function getAuthor() { return 'xiffy + cles'; }
77+ function getURL() { return 'http://blog.cles.jp/np_cles/category/31/subcatid/11'; }
78+ function getVersion() { return '0.98 jp8'; }
79+ function getDescription() { return 'Blacklist for commentspammers (SpamCheck API 2.0 compatible)'; }
80+ function supportsFeature($what) {
81+ switch($what) {
82+ case 'SqlTablePrefix':
83+ return 1;
84+ default:
85+ return 0;
86+ }
87+ }
88+
89+ function install() {
90+ // create some options
91+ $this->createOption('enabled','Blacklist engine enabled?','yesno','yes');
92+ $this->createOption('redirect','To which URL should spammers be redireted?','text','');
93+// $this->createOption('update','From which URL should we get a fresh blacklist copy?', 'text','');
94+ $this->createOption('referrerblock','Enable referrer based blocking?','yesno','no');
95+ $this->createOption('ipblock','Enable ip based blocking?','yesno','yes');
96+ $this->createOption('ipthreshold','','text','10');
97+ $this->createOption('BulkfeedsKey', 'Bulkfeeds API Key', 'text', '');
98+ $this->createOption('SkipNameResolve', 'Skip reverse DNS lookup ?', 'yesno','yes');
99+
100+ $this->_initSettings();
101+ }
102+
103+ function unInstall() {}
104+
105+ function getPluginOption ($name) {
106+ return $this->getOption($name);
107+ }
108+
109+ function getEventList() {
110+ $this->_initSettings();
111+ return array('QuickMenu','PreAddComment','PreSkinParse','ValidateForm', 'SpamCheck');
112+ }
113+
114+ function hasAdminArea() {
115+ return 1;
116+ }
117+
118+ function init(){
119+ $this->resultCache = false;
120+ }
121+
122+ function event_QuickMenu(&$data) {
123+ global $member, $nucleus, $blogid;
124+ // only show to admins
125+ if (preg_match("/MD$/", $nucleus['version'])) {
126+ $isblogadmin = $member->isBlogAdmin(-1);
127+ } else {
128+ $isblogadmin = $member->isBlogAdmin($blogid);
129+ }
130+ if (!($member->isLoggedIn() && ($member->isAdmin() | $isblogadmin))) return;
131+ array_push(
132+ $data['options'],
133+ array(
134+ 'title' => 'Blacklist',
135+ 'url' => $this->getAdminURL(),
136+ 'tooltip' => 'Manage your blacklist'
137+ )
138+ );
139+ }
140+
141+ // for other plugin writers ...
142+ function event_SpamCheck (&$data) {
143+ global $DIR_PLUGINS;
144+// $fp = fopen ($DIR_PLUGINS."blacklist/settings/debug.txt", 'a');
145+// fwrite($fp,"==called ==\n");
146+// fwrite($fp,'type : ' .$data['spamcheck']['type']."\n");
147+// fwrite($fp,'data : ' .$data['spamcheck']['data']."\n");
148+// fclose($fp);
149+ if (isset($data['spamcheck']['result']) && $data['spamcheck']['result'] == true){
150+ // Already checked... and is spam
151+ return;
152+ }
153+
154+ if( ! isset($data['spamcheck']['return']) ){
155+ $data['spamcheck']['return'] = true;
156+ }
157+
158+ // for SpamCheck API 2.0 compatibility
159+ if( ! $data['spamcheck']['data'] ){
160+ switch( strtolower($data['spamcheck']['type']) ){
161+ case 'comment':
162+ $data['spamcheck']['data'] = $data['spamcheck']['body'] . "\n";
163+ $data['spamcheck']['data'] .= $data['spamcheck']['author'] . "\n";
164+ $data['spamcheck']['data'] .= $data['spamcheck']['url'] . "\n";
165+ break;
166+ case 'trackback':
167+ $data['spamcheck']['data'] = $data['spamcheck']['title']. "\n";
168+ $data['spamcheck']['data'] .= $data['spamcheck']['excerpt']. "\n";
169+ $data['spamcheck']['data'] .= $data['spamcheck']['blogname']. "\n";
170+ $data['spamcheck']['data'] .= $data['spamcheck']['url'];
171+ break;
172+ case 'referer':
173+ $data['spamcheck']['data'] = $data['spamcheck']['url'];
174+ break;
175+ }
176+ }
177+ $ipblock = ( $data['spamcheck']['ipblock'] ) || ($data['spamcheck']['live']);
178+
179+ // Check for spam
180+ $result = $this->blacklist($data['spamcheck']['type'], $data['spamcheck']['data'], $ipblock);
181+
182+ if ($result) {
183+ // Spam found
184+ // logging !
185+ pbl_logspammer($data['spamcheck']['type'].': '.$result);
186+ if (isset($data['spamcheck']['return']) && $data['spamcheck']['return'] == true) {
187+ // Return to caller
188+ $data['spamcheck']['result'] = true;
189+ return;
190+ } else {
191+ $this->_redirect($this->getOption('redirect'));
192+ }
193+ }
194+ }
195+
196+ // will become obsolete when nucleus is patched ...
197+ function event_PreAddComment(&$data) {
198+ $comment = $data['comment'];
199+ $result = $this->blacklist('comment',postVar('body')."\n".$comment['host']."\n".$comment['user']."\n".$comment['userid']);
200+ if ($result) {
201+ pbl_logspammer('comment: '.$result);
202+ $this->_redirect($this->getOption('redirect'));
203+ }
204+ }
205+
206+ function event_ValidateForm(&$data) {
207+ if( $data['type'] == 'comment' ){
208+ $comment = $data['comment'];
209+ $result = $this->blacklist('comment',postVar('body')."\n".$comment['host']."\n".$comment['user']."\n".$comment['userid']);
210+ if ($result) {
211+ pbl_logspammer('comment: '.$result);
212+ $this->_redirect($this->getOption('redirect'));
213+ }
214+ } else if( $data['type'] == 'membermail' ){
215+ $result = $this->blacklist('membermail',postVar('frommail')."\n".postVar('message'));
216+ if ($result) {
217+ pbl_logspammer('membermail: '.$result);
218+ $this->_redirect($this->getOption('redirect'));
219+ }
220+ }
221+ }
222+
223+ // preskinparse will check the referrer for spamming attempts
224+ // only when option enabled !
225+ // logging also only when option enabled ...
226+ function event_PreSkinParse(&$data) {
227+ $result = $this->blacklist('PreSkinParse','');
228+ if ($result) {
229+ pbl_logspammer('PreSkinParse: '.$result);
230+ $this->_redirect($this->getOption('redirect'));
231+ }
232+ }
233+
234+ function blacklist($type, $testString, $ipblock = true) {
235+ global $DIR_PLUGINS;
236+ if( $this->resultCache )
237+ return $this->resultCache . '[Cached]';
238+
239+ if ($this->getOption('enabled') == 'yes') {
240+ include_once($DIR_PLUGINS."blacklist/blacklist_lib.php");
241+ // update the blacklist first file
242+ //pbl_updateblacklist($this->getOption('update'),false);
243+ if ($ipblock) {
244+ $ipblock = ( $this->getOption('ipblock') == 'yes' ) ? true : false ;
245+ }
246+
247+ $result = '';
248+ if ($this->getOption('referrerblock') == 'yes') {
249+ $refer = parse_url(serverVar('HTTP_REFERER'));
250+ $result = pbl_checkforspam($refer['host']."\n".$testString, $ipblock , $this->getOption('ipthreshold'), true);
251+ } elseif ($ipblock || $testString != '') {
252+ $result = pbl_checkforspam($testString, $ipblock, $this->getOption('ipthreshold'), true);
253+ }
254+
255+ if( $result ){
256+ $this->resultCache = $result;
257+ }
258+
259+ return $result;
260+ }
261+ }
262+
263+ function submitSpamToBulkfeeds($url) {
264+ if( is_array($url) ) $url = implode("\n", $url);
265+
266+ $postData['apikey'] = $this->getOption('BulkfeedsKey');
267+ if( ! $postData['apikey'] ) return "BulkfeedsKey not found. see http://bulkfeeds.net/app/register_api.html";
268+ $postData['url'] = $url;
269+
270+ $data = $this->_http('http://bulkfeeds.net:80/app/submit_spam.xml', 'POST', '', $postData);
271+ //preg_match('#<result>([^<]*)</result>#mi', $data, $matches);
272+ //$result = trim($matches[1]);
273+
274+ return $data;
275+ }
276+
277+ function _http($url, $method = "GET", $headers = "", $post = array ("")) {
278+ $URL = parse_url($url);
279+
280+ if (isset ($URL['query'])) {
281+ $URL['query'] = "?".$URL['query'];
282+ } else {
283+ $URL['query'] = "";
284+ }
285+
286+ if (!isset ($URL['port']))
287+ $URL['port'] = 80;
288+
289+ $request = $method." ".$URL['path'].$URL['query']." HTTP/1.0\r\n";
290+
291+ $request .= "Host: ".$URL['host']."\r\n";
292+ $request .= "User-Agent: PHP/".phpversion()."\r\n";
293+
294+ if (isset ($URL['user']) && isset ($URL['pass'])) {
295+ $request .= "Authorization: Basic ".base64_encode($URL['user'].":".$URL['pass'])."\r\n";
296+ }
297+
298+ $request .= $headers;
299+
300+ if (strtoupper($method) == "POST") {
301+ while (list ($name, $value) = each($post)) {
302+ $POST[] = $name."=".urlencode($value);
303+ }
304+ $postdata = implode("&", $POST);
305+ $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
306+ $request .= "Content-Length: ".strlen($postdata)."\r\n";
307+ $request .= "\r\n";
308+ $request .= $postdata;
309+ } else {
310+ $request .= "\r\n";
311+ }
312+
313+ $fp = fsockopen($URL['host'], $URL['port'], $errno, $errstr, 20);
314+
315+ if ($fp) {
316+ socket_set_timeout($fp, 20);
317+ fputs($fp, $request);
318+ $response = "";
319+ while (!feof($fp)) {
320+ $response .= fgets($fp, 4096);
321+ }
322+ fclose($fp);
323+ $DATA = split("\r\n\r\n", $response, 2);
324+ return $DATA[1];
325+ } else {
326+ $host = $URL['host'];
327+ $port = $URL['port'];
328+ ACTIONLOG :: add(WARNING, $this->getName().':'."[$errno]($host:$port) $errstr");
329+ return "";
330+ }
331+ }
332+
333+ function _spamMark($word){
334+ $_GET["expression"] = preg_quote($word, '/');
335+ $_GET["comment"] = 'SpamMark [' . date("Y/m/d H:i:s") . ']';
336+
337+ $existTest = pbl_checkforspam(getVar("expression"));
338+ if (! (strlen($existTest) > 0)) {
339+ pbl_addexpression();
340+ }
341+ }
342+
343+ function _redirect($url) {
344+ if( !$url ){
345+ header("HTTP/1.0 403 Forbidden");
346+ header("Status: 403 Forbidden");
347+
348+ include(dirname(__FILE__).'/blacklist/blocked.txt');
349+ } else {
350+ $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $url);
351+ header('Location: ' . $url);
352+ }
353+ exit;
354+ }
355+
356+ function _initSettings(){
357+ $settingsDir = dirname(__FILE__).'/blacklist/settings/';
358+ $settings = array(
359+ 'blacklist.log',
360+ 'blockip.pbl',
361+ 'matched.pbl',
362+ 'blacklist.pbl',
363+ 'blacklist.txt',
364+ 'suspects.pbl',
365+ );
366+ $personalBlacklist = $settingsDir . 'personal_blacklist.pbl';
367+ $personalBlacklistDist = $settingsDir . 'personal_blacklist.pbl.dist';
368+
369+ // setup settings
370+ if( $this->_is_writable($settingsDir) ){
371+ foreach($settings as $setting ){
372+ touch($settingsDir.$setting);
373+ }
374+ // setup personal blacklist
375+ if( ! file_exists($personalBlacklist) ){
376+ if( copy( $personalBlacklistDist , $personalBlacklist ) ){
377+ $this->_warn("'$personalBlacklist' created.");
378+ } else {
379+ $this->_warn("'$personalBlacklist' cannot create.");
380+ }
381+ }
382+ }
383+
384+ // check settings
385+ foreach($settings as $setting ){
386+ $this->_is_writable($settingsDir.$setting);
387+ }
388+ $this->_is_writable($personalBlacklist);
389+
390+ // setup and check cache dir
391+ $cacheDir = NP_BLACKLIST_CACHE_DIR;
392+ $this->_is_writable($cacheDir);
393+ }
394+
395+ function _is_writable($file){
396+ $ret = is_writable($file);
397+ if( ! $ret ){
398+ $this->_warn("'$file' is not writable.");
399+ }
400+ return $ret;
401+ }
402+
403+ function _warn($msg) {
404+ ACTIONLOG :: add(WARNING, 'Blacklist: '.$msg);
405+ }
406+
407+}
408+?>
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/blacklist_lib.php
@@ -0,0 +1,833 @@
1+<?php
2+// Pivot-Blacklist version 0.4 (with Nucleus Support!)
3+//
4+// A simple (but effective) spam blocker based on the MT-Blacklist
5+// available at: http://www.jayallen.org/comment_spam/
6+//
7+// Includes realtime blacklist check functions by
8+// John Sinteur (http://weblog.sinteur.com/)
9+//
10+// This code (c) 2004 by Marco van Hylckama Vlieg
11+// adapted and extended by Appie Verschoor
12+// License is GPL, just like Pivot / Nucleus
13+//
14+// http://www.i-marco.nl/
15+// marco@i-marco.nl
16+//
17+// http://xiffy.nl/
18+// blacklist@xiffy.nl
19+
20+define('__WEBLOG_ROOT', dirname(dirname(realpath(__FILE__))));
21+define('__EXT', '/blacklist');
22+
23+define('NP_BLACKLIST_CACHE_DIR', dirname(__FILE__).'/cache');
24+define('NP_BLACKLIST_CACHE_LIFE', 86400);
25+define('NP_BLACKLIST_CACHE_GC_INTERVAL', NP_BLACKLIST_CACHE_LIFE/8);
26+define('NP_BLACKLIST_CACHE_GC_TIMESTAMP', 'gctime');
27+define('NP_BLACKLIST_CACHE_GC_TIMESTAMP_LIFE', NP_BLACKLIST_CACHE_LIFE*3);
28+require_once(dirname(__FILE__).'/cache_file.php');
29+//require_once(dirname(__FILE__).'/cache_eaccelerator.php');
30+
31+function pbl_getconfig() {
32+ global $pbl_config;
33+ $pbl_config = array();
34+ $pbl_config['enabled'] = getPluginOption('enabled');
35+ $pbl_config['redirect'] = getPluginOption('redirect');
36+ //$pbl_config['update'] = getPluginOption('update');
37+ // convert 'yes' into '1'
38+ if ($pbl_config['enabled'] == 'yes') {$pbl_config['enabled'] = 1;}
39+ return $pbl_config;
40+}
41+
42+function pbl_checkforspam($text, $ipblock = false, $ipthreshold = 10, $logrule = true) {
43+ // check whether a string contains spam
44+ // if it does, we return the rule that was matched first
45+ //$text = strtolower($text);
46+ $text = trim($text);
47+
48+ // first line of defense; block notorious spammers
49+ if ($ipblock) {
50+ if (pbl_blockIP()) {
51+ return "<b>IP Blocked</b>: ".serverVar('REMOTE_ADDR')." (".serverVar('REMOTE_HOST').")";
52+ }
53+ }
54+ // second line of defense: Check whether our poster is using
55+ // an open proxy
56+ //if(check_for_open_proxy()) {
57+ // if ($ipblock == 'yes') {
58+ // pbl_suspectIP ($ipthreshold);
59+ // }
60+ // return "open spam proxy";
61+ //}
62+
63+ // third line of defense: Check whether our poster promotes
64+ // known spamsite url's listed at www.surbl.org
65+ //if(check_for_surbl($text)) {
66+ // if ($ipblock == 'yes') {
67+ // pbl_suspectIP ($ipthreshold);
68+ // }
69+ // return("url(s) listed on www.surbl.org found");
70+ //}
71+
72+ // fourth line of defense: Run the MT-Blacklist check
73+ if( $text && file_exists(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl") ){
74+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl", "r");
75+ while (!feof($handle)) {
76+ $buffer = fgets($handle, 4096);
77+ $splitbuffer = explode("####", $buffer);
78+ $expression = $splitbuffer[0];
79+ $explodedSplitBuffer = explode("/", $expression);
80+ $expression = $explodedSplitBuffer[0];
81+ if (strlen($expression) > 0) {
82+ if(preg_match("/".trim($expression)."/i", $text)) {
83+ if ($ipblock) {
84+ pbl_suspectIP ($ipthreshold);
85+ }
86+ if ($logrule) {
87+ pbl_logRule($expression);
88+ }
89+ return $expression;
90+ }
91+ }
92+ }
93+ fclose($handle);
94+ }
95+
96+ // fifth line of defense: run the personal blacklist entries
97+ if ($text &&file_exists(__WEBLOG_ROOT.__EXT.'/settings/personal_blacklist.pbl')) {
98+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "r");
99+ while (!feof($handle)) {
100+ $buffer = fgets($handle, 4096);
101+ $splitbuffer = explode("####", $buffer);
102+ $expression = $splitbuffer[0];
103+ if (strlen($expression) > 0) {
104+// if(is_domain($expression)) {
105+// $expression = str_replace(".","\.",$expression);
106+// }
107+ if(preg_match("/".trim($expression)."/i", $text)) {
108+ if ($ipblock) {
109+ pbl_suspectIP ($ipthreshold);
110+ }
111+ if ($logrule) {
112+ pbl_logRule($expression);
113+ }
114+ fclose($handle);
115+ return $expression;
116+ }
117+ }
118+ }
119+ fclose($handle);
120+ }
121+
122+ if( $ipblock && $listedrbl = check_for_iprbl() ) {
123+ pbl_suspectIP ($ipthreshold);
124+ $ref = serverVar('HTTP_REFERER');
125+ return "ip listed on {$listedrbl[0]} found (Referer:{$ref})";
126+ }
127+
128+ if( $text && ($listedrbl = check_for_domainrbl($text)) ) {
129+ if ($ipblock) {
130+ pbl_suspectIP ($ipthreshold);
131+ }
132+ return("url(s) listed on {$listedrbl[0]} ({$listedrbl[1]}) found");
133+ }
134+
135+ // w00t! it's probably not spam!
136+ return "";
137+}
138+
139+function pbl_updateblacklist($url, $force=false) {
140+/*
141+ $listAge = time() - @filemtime(__WEBLOG_ROOT.__EXT.'/settings/blacklist.txt');
142+ // 86400 is 24hours (24*60*60)
143+ if ((($listAge > 86400 ) || (!file_exists(__WEBLOG_ROOT.__EXT.'/settings/blacklist.txt'))) || ($force)) {
144+ $handle = @fopen($url, "r");
145+ if ($handle) {
146+ while (!feof($handle)) {
147+ $buffer = fgets($handle, 4096);
148+ $newBlackList .= $buffer;
149+ }
150+ fclose($handle);
151+ }
152+
153+ // Check whether we really have the file
154+ // if not we keep the old one because we don't want to break
155+ // the engine with a bad or missing file
156+
157+ if(strstr($newBlackList, "MT-Blacklist Master Copy")) {
158+ $newFile = fopen(__WEBLOG_ROOT.__EXT.'/settings/blacklist.txt', 'w');
159+ fwrite($newFile, $newBlackList);
160+ fclose($newFile);
161+ pbl_processblacklist();
162+ }
163+ }
164+*/
165+ return true;
166+}
167+
168+/*
169+function pbl_processblacklist() {
170+ // reformat the list to match our own format
171+ $listString = "";
172+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.txt", "r") or die ("could not open: ".__WEBLOG_ROOT.__EXT."/settings/blacklist.txt");
173+ while (!feof($handle)) {
174+ $buffer = fgets($handle, 4096);
175+ $splitbuffer = explode("#", $buffer);
176+ $expression = $splitbuffer[0];
177+ $explodedSplitBuffer = explode("/", $expression);
178+ $expression = $explodedSplitBuffer[0];
179+ if (strlen($expression) > 0) {
180+ $listString .= preg_replace("/([^\\\|^_]|^)\./",'$1\\.',trim($expression));
181+ if(strlen($splitbuffer[1]) > 5) {
182+ $listString .= " #### ".trim($splitbuffer[1]);
183+ }
184+ $listString .= "\n";
185+ }
186+ }
187+ fclose($handle);
188+ if(file_exists(__WEBLOG_ROOT.__EXT.'/settings/blacklist.pbl')) {
189+ }
190+ $newhandle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl", "w");
191+ fwrite($newhandle, $listString);
192+ fclose($newhandle);
193+}
194+*/
195+
196+function is_domain($stheDomain) {
197+ return ( (strpos($stheDomain,"\\")==0) && (strpos($stheDomain,"[")==0) && (strpos($stheDomain, "(")==0) );
198+}
199+
200+
201+function pbl_nucmenu() {
202+ echo "<h2>Blacklist menu</h2>\n";
203+ echo "<ul>\n";
204+ echo "<li><a href=\"".serverVar('PHP_SELF')."?page=blacklist\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_edit.gif\" /> Blacklist Editor</a></li>\n";
205+ echo "<li><a href=\"".serverVar('PHP_SELF')."?page=log\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_log.gif\" /> Blacklist Log</a></li>\n";
206+ echo "<li><a href=\"".dirname(serverVar('PHP_SELF'))."/../../index.php?action=pluginoptions&amp;plugid=".getPlugid()."\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_prefs.gif\" /> Blacklist options</a></li>\n";
207+ echo "<li><a href=\"".serverVar('PHP_SELF')."?page=testpage\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_edit.gif\" /> Test Blacklist</a></li>\n";
208+ echo "<li><a href=\"".serverVar('PHP_SELF')."?page=showipblock\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_log.gif\" /> Show blocked ip addresses</a></li>\n";
209+ echo "<li><a href=\"".serverVar('PHP_SELF')."?page=htaccess\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_edit.gif\" /> Generate .htaccess snippets</a></li>\n";
210+ echo "<li><a href=\"".serverVar('PHP_SELF')."?page=spamsubmission\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_edit.gif\" /> Spam submission (Bulkfeeds)</a></li>\n";
211+ echo "</ul>\n";
212+}
213+
214+function pbl_blacklisteditor() {
215+
216+ global $pblmessage;
217+
218+ if(strlen($pblmessage) > 0) {
219+ echo "<div class=\"pblmessage\">$pblmessage</div>\n";
220+ }
221+
222+/*
223+ echo "<div id=\"jayallen\">\n";
224+ echo "<div class=\"pbldescription\">";
225+ if(!file_exists(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl")) {
226+ echo "You don't have a blacklist file yet!<br />";
227+ echo "Click the button below to get the latest MT-Blacklist from Jay Allen's site.";
228+ echo "</div>";
229+ echo "<div class=\"pbform\">\n";
230+ echo "<form action=\"index.php\" method=\"get\">\n";
231+ echo "<input type=\"hidden\" name=\"page\" value=\"getblacklist\" />\n";
232+ echo "<input type=\"submit\" value=\"Download and install\" />\n";
233+ echo "</form>\n";
234+ echo "</div>\n";
235+ }
236+ else {
237+ $updatetime = @filemtime(__WEBLOG_ROOT.__EXT."/settings/blacklist.txt");
238+ echo "Your MT-Blacklist file was last updated at: ";
239+ echo date("Y/m/d H:i:s", $updatetime)." <br />";
240+# echo date("F d Y H:i", $updatetime)." <br />";
241+ echo "It's updated automatically every day but you can click below to update it immediately";
242+ echo "</div>\n";
243+ echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
244+ echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
245+ echo "<input type=\"hidden\" name=\"page\" value=\"getblacklist\" />\n";
246+ echo "<input type=\"submit\" value=\"Update now\" />\n";
247+ echo "</form>\n";
248+ echo "</div>\n";
249+ }
250+ echo "</div>\n";
251+*/
252+ echo "<div id=\"personal\">\n";
253+ echo "<div class=\"pbldescription\">";
254+ echo "You can add url's, regular expressions or words to your personal blacklist below.";
255+ echo "</div>\n";
256+ echo "<div class=\"pbform\">\n";
257+ echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
258+ echo "<input type=\"hidden\" name=\"page\" value=\"addpersonal\" />\n";
259+ echo "<table class=\"pblform\">\n";
260+ echo "<tr>\n";
261+ echo "<td>expression</td>\n";
262+ echo "<td><input class=\"pbltextinput\" type=\"text\" name=\"expression\" /></td>\n";
263+ echo "</tr>\n";
264+ echo "<tr>";
265+ echo " <td>comment</td>\n";
266+ echo " <td><input class=\"pbltextinput\" type=\"text\" name=\"comment\" /></td>\n";
267+ echo "</tr>\n";
268+ echo "<tr>";
269+ echo " <td>enable regular expressions ?</td>\n";
270+ echo " <td><input class=\"pbltextinput\" type=\"checkbox\" name=\"enable_regex\" value=\"1\" /></td>\n";
271+ echo "</tr>\n";
272+ echo "<tr><td colspan=\"2\" style=\"border:none;\"><input type=\"submit\" value=\"Add\" /></td>\n";
273+ echo "</tr>\n";
274+ echo "</table>\n";
275+ echo "</form>\n";
276+ echo "</div>\n";
277+ echo "<div class=\"pbldescription\">Below is your personal blacklist</div>\n";
278+ if (file_exists(__WEBLOG_ROOT.__EXT.'/settings/personal_blacklist.pbl')) {
279+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "r");
280+ echo "<table>\n";
281+ echo "<tr>\n";
282+ echo "<th>expression</th>\n";
283+ echo "<th>comment</th>\n";
284+ echo "<th>deletion</th>\n";
285+ echo "</tr>\n";
286+ $line = 0;
287+ while (!feof($handle)) {
288+ $buffer = fgets($handle, 4096);
289+ $line++;
290+ $configParam = explode("####", $buffer);
291+ $key = $configParam[0];
292+ $value = $configParam[1];
293+ if(strlen($key) > 0) {
294+ echo "<tr>\n";
295+ echo "<td>".htmlspecialchars($key,ENT_QUOTES)."</td>\n";
296+ echo "<td>".htmlspecialchars($value,ENT_QUOTES)."</td>\n";
297+ echo "<td>";
298+ echo "<a href=\"".serverVar('PHP_SELF')."?page=deleteexpression&amp;line=".$line."\">delete</a>";
299+ echo "</td>";
300+ echo "</tr>\n";
301+ }
302+ }
303+ echo "</table>\n";
304+ }
305+}
306+function pbl_deleteexpression() {
307+ if(isset($_GET["line"])) {
308+ if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl") ){
309+ echo "Error: personal_blacklist.pbl is not writable. ";
310+ }
311+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "r");
312+ $line = 0;
313+ $newFile = "";
314+ while (!feof($handle)) {
315+ $buffer = fgets($handle, 4096);
316+ $line++;
317+ if($line != getVar("line")) {
318+ $newFile .= $buffer;
319+ }
320+ }
321+ fclose($handle);
322+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "w");
323+ fwrite($handle, $newFile);
324+ fclose($handle);
325+ }
326+}
327+function pbl_addexpression($expression, $comment) {
328+ if(strlen($expression) > 0) {
329+ if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl") ){
330+ echo "Error: personal_blacklist.pbl is not writable. ";
331+ }
332+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "a");
333+ if(strlen($comment) > 0) {
334+ $expression = $expression." #### ".$comment;
335+ }
336+ fwrite($handle, $expression."\n");
337+ fclose($handle);
338+
339+ }
340+}
341+
342+$g_reOk = false;
343+function _hdl($errno, $errstr) {
344+ global $g_reOk;
345+ $g_reOk = false;
346+}
347+
348+function pbl_checkregexp($re) {
349+ // Thanks to 'OneOfBorg' on Gathering Of Tweakers
350+ // http://gathering.tweakers.net/forum/user_profile/109376
351+ global $g_reOk;
352+ $g_reOk = true;
353+ set_error_handler("_hdl");
354+ preg_match("/".trim($re)."/i", "");
355+ restore_error_handler();
356+ return $g_reOk;
357+}
358+
359+function pbl_addpersonal() {
360+ if(isset($_GET["expression"])) {
361+ $expression = getVar("expression");
362+ if( getVar('comment') ){
363+ $comment = getVar('comment');
364+ }
365+ if($expression != "") {
366+ $enable_regex = true;
367+ if( ! getVar('enable_regex') ){
368+ $enable_regex = false;
369+ $expression = preg_quote($expression,'/');
370+ }
371+
372+ if($enable_regex && (!pbl_checkregexp($expression))) {
373+ echo "<div class=\"pblmessage\">Your expression contained errors and couldn't be added: <b>".htmlspecialchars($expression,ENT_QUOTES)."</b></div>\n";
374+ }
375+ else {
376+ $existTest = pbl_checkforspam($expression);
377+
378+ if (strlen($existTest) > 0) {
379+ echo "<div class=\"pblmessage\">Expression <b>".htmlspecialchars($expression,ENT_QUOTES)."</b> already matched by the following rule in your system:<br/> <b>$existTest</b></div>\n";
380+ }
381+ else {
382+ pbl_addexpression($expression,$comment);
383+ echo "<div class=\"pblmessage\">New entry added to your list: <b>".htmlspecialchars($expression,ENT_QUOTES)."</b></div>";
384+ }
385+ }
386+ }
387+ else {
388+ echo "<div class=\"pblmessage\">There's no use in adding empty expressions.<b>".htmlspecialchars($expression,ENT_QUOTES)."</b></div>";
389+ }
390+ }
391+}
392+
393+function pbl_logspammer($spam) {
394+ $spam = trim($spam);
395+ if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/blacklist.log") ){
396+ echo "Error: blacklist.log is not writable. ";
397+ }
398+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.log", "a");
399+ $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit');
400+ if( $lastVisit ){
401+ //$lastVisit = $this->getCorrectTime($lastVisit);
402+ $logline = date("Y/m/d H:i:s")." #### ".serverVar("REMOTE_ADDR")." #### ".$spam. ' [lastVisit ' .date("Y/m/d H:i:s", $lastVisit). "]\n";
403+ } else {
404+ $logline = date("Y/m/d H:i:s")." #### ".serverVar("REMOTE_ADDR")." #### ".$spam."\n";
405+ }
406+ fwrite($handle, $logline);
407+ fclose($handle);
408+}
409+
410+function pbl_log($text) {
411+ $text = trim($text);
412+ if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/blacklist.log") ){
413+ echo "Error: blacklist.log is not writable. ";
414+ }
415+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.log", "a");
416+ $logline = date("Y/m/d H:i:s")." #### localhost #### ".$text."\n";
417+ fwrite($handle, $logline);
418+ fclose($handle);
419+}
420+
421+
422+function pbl_logtable() {
423+ if (file_exists(__WEBLOG_ROOT.__EXT."/settings/blacklist.log")) {
424+ $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.log", "r");
425+ $logrows = "";
426+ $numb=0;
427+ while (!feof($handle)) {
428+ $buffer = fgets($handle, 4096);
429+ $thisline = explode("####", $buffer);
430+ if($thisline[0] != "") {
431+ $logrows .= "<tr>";
432+ $logrows .= "<td class=\"log$numb\" >$thisline[0]</td>";
433+ if( getPluginOption('SkipNameResolve') == 'no' )
434+ $logrows .= "<td class=\"log$numb\" >$thisline[1]<br />(" . gethostbyaddr( trim($thisline[1]) ) . ")</td>";
435+ else
436+ $logrows .= "<td class=\"log$numb\" >$thisline[1]</td>";
437+ $logrows .= "<td class=\"log$numb\" >$thisline[2]</td>";
438+ $logrows .= "</tr>\n";
439+ }
440+ if($numb == 0)
441+ $numb=1;
442+ else
443+ $numb=0;
444+ }
445+ fclose($handle);
446+ echo "<table class=\"pbllog\">\n";
447+ echo "<tr><th>Date/Time</th><th>IP</th><th>Rule Matched</th></tr>\n";
448+ echo $logrows;
449+ echo "</table>\n";
450+ }
451+ if(strlen($logrows) < 10) {
452+ echo "<div class=\"pbldescription\">Your log is empty.</div>\n";
453+ }
454+ echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
455+ echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
456+ echo "<input type=\"hidden\" name=\"page\" value=\"resetlog\" />\n";
457+ echo "<input type=\"submit\" value=\"Reset log\" />\n";
458+ echo "</form>\n";
459+ echo "</div>\n";
460+}
461+
462+function check_for_open_proxy() {
463+ $spammer_ip = serverVar('REMOTE_ADDR');
464+ list($a, $b, $c, $d) = split('.', $spammer_ip);
465+ if( gethostbyname("$d.$c.$b.$a.list.dsbl.org") != "$d.$c.$b.$a.list.dsbl.org") {
466+ return true;
467+ }
468+ return false;
469+}
470+
471+function check_for_surbl ( $comment_text ) {
472+ /* for a full explanation, see http://www.surbl.org
473+ summary: blocks comment if it contains an url that's on a known spammers list.
474+ */
475+ //get site names found in body of comment.
476+ $regex_url = "/(www\.)([^\/\"<\s]*)/i";
477+ $mk_regex_array = array();
478+ preg_match_all($regex_url, $comment_text, $mk_regex_array);
479+
480+ for( $cnt=0; $cnt < count($mk_regex_array[2]); $cnt++ ) {
481+ $domain_to_test = rtrim($mk_regex_array[2][$cnt],"\\");
482+
483+ if (strlen($domain_to_test) > 3)
484+ {
485+ $domain_to_test = $domain_to_test . ".multi.surbl.org";
486+ if( strstr(gethostbyname($domain_to_test),'127.0.0')) {
487+ return true;
488+ }
489+ }
490+ }
491+ return false;
492+}
493+
494+//add hsur +++++++++++++
495+
496+function check_for_iprbl () {
497+ if( pbl_ipcache_read() ) return false;
498+
499+ //$iprbl = array('sc.surbl.org', 'bsb.spamlookup.net', 'opm.blitzed.org', 'list.dsbl.org');
500+ $iprbl = array('niku.2ch.net', 'list.dsbl.org', 'bsb.spamlookup.net');
501+
502+ $spammer_ip = serverVar('REMOTE_ADDR');
503+ list($a, $b, $c, $d) = explode('.', $spammer_ip);
504+
505+ foreach($iprbl as $rbl ){
506+ if( strstr( gethostbyname( "$d.$c.$b.$a.$rbl" ),'127.0.0') ) {
507+ return array($rbl, $spammer_ip);
508+ }
509+ }
510+ pbl_ipcache_write();
511+ return false;
512+}
513+
514+function check_for_domainrbl ( $comment_text ) {
515+ $domainrbl = array('rbl.bulkfeeds.jp', 'url.rbl.jp', 'bsb.spamlookup.net');
516+ //$regex_url = "/((http:\/\/)|(www\.))([^\/\"<\s]*)/i";
517+ $regex_url = "{https?://(?:www\.)?([a-z0-9._-]{2,})(?::[0-9]+)?((?:/[_.!~*a-z0-9;@&=+$,%-]+){0,2})}m";
518+ $comment_text = mb_strtolower($comment_text);
519+
520+ $mk_regex_array = array();
521+ preg_match_all($regex_url, $comment_text, $mk_regex_array);
522+
523+ $mk_regex_array[1] = array_unique($mk_regex_array[1]);
524+
525+ for( $cnt=0; $cnt < count($mk_regex_array[1]); $cnt++ ) {
526+ $domain_to_test = rtrim($mk_regex_array[1][$cnt],"\\");
527+ foreach($domainrbl as $rbl ){
528+ if (strlen($domain_to_test) > 3)
529+ {
530+ if( strstr(gethostbyname($domain_to_test.'.'.$rbl),'127.0.0')) {
531+ return array($rbl, $domain_to_test);
532+ }
533+ }
534+ }
535+ }
536+ return false;
537+}
538+
539+//add hsur end ++++++++++++++
540+
541+function pbl_blockIP() {
542+ $remote_ip = trim(serverVar('REMOTE_ADDR'));
543+ $filename = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
544+ $block = false;
545+ // already in ipblock?
546+ if (file_exists($filename)) {
547+ $fp = fopen(__WEBLOG_ROOT.__EXT."/settings/blockip.pbl", "r");
548+ while ($line = trim(fgets($fp,255))) {
549+ if( strpos($remote_ip, $line) !== false){$block = true;}
550+ }
551+ fclose ($fp);
552+ } else {
553+ $fp = fopen(__WEBLOG_ROOT.__EXT."/settings/blockip.pbl", "w");
554+ fwrite($fp, "");
555+ fclose ($fp);
556+ }
557+ return $block;
558+}
559+
560+function pbl_logRule($expression) {
561+ $filename = __WEBLOG_ROOT.__EXT."/settings/matched.pbl";
562+ $count = 0;
563+ $fp = fopen($filename,"r+");
564+ if ($fp) {
565+ while ($line = fgets($fp, 4096)) {
566+ if (! (strpos($line, $expression) === false )) {
567+ $count++;
568+ break;
569+ }
570+ }
571+ fclose($fp);
572+ }
573+ if ($count == 0 && !trim($expression) == "" ) {
574+ $fp = fopen($filename,"a+");
575+ fwrite($fp,$expression."\n");
576+ }
577+}
578+
579+// this function logs all ip-adresses in a 'suspected ip-list'
580+// if the ip of the currently catched spammer is above the ip-treshold (plugin option) then
581+// the spamming ipaddress is transfered to the blocked-ip list.
582+// this list is the first line of defense, so notorious spamming machine will be kicked of real fast
583+// improves blacklist performance
584+// possible danger: blacklisting real humans who post on-the-edge comments
585+function pbl_suspectIP($threshold, $remote_ip = '') {
586+ if ($remote_ip == '' ) {$remote_ip = serverVar('REMOTE_ADDR');}
587+ $filename = __WEBLOG_ROOT.__EXT."/settings/suspects.pbl";
588+ $blockfile = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
589+ $count = 0;
590+ // suspectfile ?
591+ if (! file_exists($filename)) {
592+ $fp = fopen($filename, "w");
593+ fwrite($fp, "");
594+ fclose ($fp);
595+ }
596+
597+ $fp = fopen($filename, "r");
598+ while ($line = fgets($fp,255)) {
599+ if ( strpos($line, $remote_ip) !== false ) {
600+ $count++;
601+ }
602+ }
603+ fclose ($fp);
604+
605+ // not above threshold ? add ip to suspect ...
606+ if ($count < $threshold) {
607+ $fp = fopen($filename,'a+');
608+ fwrite($fp,$remote_ip."\n");
609+ fclose($fp);
610+ } else {
611+ // remove from suspect to ip-block
612+ $fp = fopen($filename, "r");
613+ $rewrite = "";
614+ while ($line = fgets($fp,255)) {
615+ // keep all lines except the catched ip-address
616+ if(strpos ($line, $remote_ip) !== false) {
617+ $rewrite .= $line;
618+ }
619+ }
620+ fclose($fp);
621+ $fp = fopen($filename, "w");
622+ fwrite($fp, $rewrite);
623+ fclose ($fp);
624+ // transfer to blocked-ip file
625+ $fp = fopen($blockfile,'a+');
626+ fwrite($fp,$remote_ip."\n");
627+ fclose($fp);
628+ }
629+}
630+
631+function pbl_showipblock() {
632+ global $pblmessage;
633+ $filename = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
634+ $line = 0;
635+ $fp = fopen($filename,'r');
636+ echo "<div class=\"pbform\">\n";
637+ echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
638+ echo "<input type=\"hidden\" name=\"page\" value=\"addip\" />\n";
639+ echo "Add IP to block: ";
640+ echo "<input class=\"pbltextinput\" type=\"text\" name=\"ipaddress\" />\n";
641+ echo "<input type=\"submit\" value=\"Add\" />\n";
642+ echo "</form>";
643+ echo "</div>\n";
644+ echo "<table>";
645+ echo "<tr>\n";
646+ echo "<th>IP Address</th>\n";
647+ echo "<th>reversed lookup</th>\n";
648+ echo "<th>deletion</th>\n";
649+ echo "</tr>\n";
650+ while ($ip = fgets($fp,255)) {
651+ $line++;
652+ if( getPluginOption('SkipNameResolve') == 'no' )
653+ echo "<tr><td>".$ip."</td><td>[".gethostbyaddr(rtrim($ip))."]</td><td>";
654+ else
655+ echo "<tr><td>".$ip."</td><td>[<em>skipped</em>]</td><td>";
656+ echo "<a href=\"".serverVar('PHP_SELF')."?page=deleteipblock&amp;line=".$line."\">delete</a>";
657+ echo "</td></tr>";
658+ }
659+ echo "</table>";
660+}
661+function pbl_addipblock() {
662+ if(isset($_GET["ipaddress"])) {
663+ pbl_suspectIP(0,getVar("ipaddress"));
664+ }
665+}
666+
667+function pbl_deleteipblock() {
668+ global $pblmessage;
669+ $filename = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
670+ if(isset($_GET["line"])) {
671+ $handle = fopen($filename, "r");
672+ $line = 0;
673+ $newFile = "";
674+ while (!feof($handle)) {
675+ $buffer = fgets($handle, 4096);
676+ $line++;
677+ if($line != getVar("line")) {
678+ $newFile .= $buffer;
679+ }
680+ }
681+ fclose($handle);
682+ $handle = fopen($filename, "w");
683+ fwrite($handle, $newFile);
684+ fclose($handle);
685+ }
686+}
687+
688+function pbl_htaccess($type) {
689+ $htaccess = "";
690+ switch($type) {
691+ case "ip":
692+ $filename = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
693+ $htaccess = "# This htaccess snippet blocks machine based on IP Address. \n"
694+ . "# these lines are generated by NP_Blackist\n";
695+ break;
696+ case "rules":
697+ $filename = __WEBLOG_ROOT.__EXT."/settings/matched.pbl";
698+ $htaccess = "# This htaccess snippet blocks machine based on referrers. \n"
699+ . "# these lines are generated by NP_Blackist\n"
700+ . "# You need to have the following line once in your .htaccess file\n"
701+ . "# RewriteEngine On\n";
702+ break;
703+ default:
704+ $htaccess = "Here you can generate two types of .htaccess snippets. The first part is based on blocked ip's. This is only relevant if you have IP blocking enabled in the options. \nThe other part is referrer based rewrite rules. Blacklist stores all rules matched in a different file. With this tool you convert these matched rules into .htaccess rewrite rules which you can incorporate into your existings .htaccess file (Apache only)\n After you've added the snippet to your .htaccess file it's safe and wise to reset the blocked ip list and/or matched rules file. That way you won't end up with double rules inside your .htaccess file\n";
705+ return $htaccess;
706+ }
707+
708+ $fp = fopen($filename, 'r');
709+ $count = 0;
710+ while ($line = fgets($fp,4096)) {
711+ if ($type == "ip") {
712+ $htaccess .= "deny from ".$line;
713+ } else {
714+ if (rtrim($line) != "" ) {
715+ if ($count > 0) {$htaccess .= "[NC,OR]\n";}
716+ // preg_replace does the magic of converting . into \. while keeping \. and _. intact
717+ $htaccess .= "RewriteCond %{HTTP_REFERER} ". preg_replace("/([^\\\|^_]|^)\./",'$1\\.',rtrim($line)).".*$ ";
718+ $count++;
719+ }
720+ }
721+ }
722+ if ($type != "ip") {
723+ $htaccess .= "\nRewriteRule .* � [F,L]\n";
724+ }
725+ return $htaccess;
726+}
727+
728+function pbl_htaccesspage() {
729+ global $pblmessage;
730+ if(strlen($pblmessage) > 0) {
731+ echo "<div class=\"pblmessage\">$pblmessage</div>\n";
732+ }
733+
734+ if (isset($_POST["type"])) {
735+ if (strstr(postVar("type"),"blocked")) {
736+ $type = 'ip';
737+ } else {
738+ $type = 'rules';
739+ }
740+ }
741+ echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
742+ echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"post\">\n";
743+ echo "<input type=\"submit\" label=\"ip\" value=\"Generate blocked IP's\" name=\"type\" />\n";
744+ echo "<input type=\"submit\" label=\"ip\" value=\"Generate rewrite rules\" name=\"type\" />\n";
745+ echo "<br />";
746+ echo "<br />";
747+ echo "<input type=\"hidden\" name=\"page\" value=\"htaccess\" />\n";
748+ echo "<textarea class=\"pbltextinput\" cols=\"60\" rows=\"15\" name=\"snippet\" >". pbl_htaccess($type)."</textarea><br />";
749+ echo "<br />";
750+ echo "<input title=\"this will clean your block IP addresses file\" type=\"submit\" label=\"ip\" value=\"Reset blocked IP's\" name=\"type\" />\n";
751+ echo "<input title=\"This will clean your matched file\" type=\"submit\" label=\"ip\" value=\"Reset rewrite rules\" name=\"type\" />\n";
752+ echo "</form>\n";
753+ // if user asked for a reset, do it now
754+ if (stristr(postVar("type"),"reset")) {
755+ echo "restting file ...";
756+ pbl_resetfile($type);
757+ }
758+ echo "</div>\n";
759+} // pbl_htaccesspage()
760+
761+function pbl_resetfile($type){
762+ global $pblmessage;
763+ switch ($type) {
764+ case 'log':
765+ $filename = __WEBLOG_ROOT.__EXT."/settings/blacklist.log";
766+ break;
767+ case 'ip':
768+ $filename = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
769+ break;
770+ case 'rules':
771+ $filename = __WEBLOG_ROOT.__EXT."/settings/matched.pbl";
772+ break;
773+ }
774+ if(file_exists($filename)) {
775+ $fp = fopen($filename, "w");
776+ fwrite($fp, "");
777+ fclose($fp);
778+ }
779+}
780+
781+function pbl_test () {
782+ // test's user input, no loggin.
783+ global $pblmessage;
784+ if(isset($_GET["expression"])) {
785+ if(getVar("expression") != "") {
786+ $pblmessage = "Your expression: <br />".htmlspecialchars(getVar("expression"), ENT_QUOTES);
787+ $return = pbl_checkforspam(getVar("expression"),false,0,false);
788+
789+ if (! $return == "" ) {
790+ $pblmessage .= "<br />matched rule: <strong>".$return."</strong>";
791+ } else {
792+ $pblmessage .= "<br /> did not match any rule.";
793+ }
794+ }
795+ }
796+}
797+
798+function pbl_testpage () {
799+ // shows user testpage ...
800+ global $pblmessage;
801+ if(strlen($pblmessage) > 0) {
802+ echo "<div class=\"pblmessage\">$pblmessage</div>\n";
803+ }
804+ echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
805+ echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
806+ echo "<input type=\"hidden\" name=\"page\" value=\"test\" />\n";
807+ echo "<textarea class=\"pbltextinput\" cols=\"60\" rows=\"6\" name=\"expression\" ></textarea><br />";
808+ echo "<input type=\"submit\" value=\"Test this\" />\n";
809+ echo "</form>\n";
810+ echo "</div>\n";
811+}
812+
813+function pbl_spamsubmission_form() {
814+ // form
815+ echo "<form action=\"".serverVar('PHP_SELF')."?page=spamsubmission&action=send\" method=\"post\">\n";
816+
817+ // table
818+ echo "<table>\n";
819+ echo "<tr>\n";
820+ echo "<th>Report Spam</th>\n";
821+ echo "</tr>\n";
822+
823+ echo "<tr>\n";
824+ echo "<td><textarea name=\"url\" rows=\"6\" cols=\"60\"></textarea></td>\n";
825+ echo "</tr>\n";
826+
827+ echo '<tr><td><div align="right"><input type="submit" name="submit" value="submit" /></div></td></tr>';
828+
829+ echo "</table>\n";
830+ echo "</form>\n";
831+}
832+
833+?>
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/blocked.txt
@@ -0,0 +1,15 @@
1+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2+<html>
3+<head>
4+<meta name="robots" content="noindex,nofollow" />
5+<meta name="robots" content="noarchive" />
6+<meta http-equiv="Pragma" content="no-cache" />
7+<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
8+<meta http-equiv="Expires" content="-1" />
9+<title>403 Forbidden</title>
10+</head>
11+<body>
12+<h1>Forbidden</h1>
13+<p>You don't have permission to access on this server.</p>
14+</body>
15+</html>
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/cache/readme.txt
@@ -0,0 +1 @@
1+cachedir
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/cache_eaccelerator.php
@@ -0,0 +1,45 @@
1+<?php
2+
3+/**
4+* cache_eaccelerator.php ($Revision: 1.1 $)
5+*
6+* by hsur ( http://blog.cles.jp/np_cles )
7+* $Id: cache_eaccelerator.php,v 1.1 2006-09-30 09:48:05 hsur Exp $
8+*/
9+
10+function pbl_ipcache_write(){
11+ $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
12+ if( ! rand(0,19) ) pbl_ipcache_gc();
13+
14+ // eAccelerator Cache
15+ eaccelerator_lock($key);
16+ eaccelerator_put($key, true, NP_BLACKLIST_CACHE_LIFE);
17+ eaccelerator_unlock($key);
18+}
19+
20+function pbl_ipcache_read(){
21+ $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
22+ // eAccelerator Cache
23+ if( eaccelerator_get($key) ){
24+ return true;
25+ }
26+ return false;
27+}
28+
29+function pbl_ipcache_gc(){
30+ $now = time();
31+ $lastGc = -1;
32+
33+ // eAccelerator Cache
34+ $lastGc = intval(eaccelerator_get(NP_BLACKLIST_CACHE_GC_TIMESTAMP));
35+ if($now - $lastGc > NP_BLACKLIST_CACHE_GC_INTERVAL){
36+ eaccelerator_gc();
37+ $lastGc = $now;
38+ eaccelerator_lock(NP_BLACKLIST_CACHE_GC_TIMESTAMP);
39+ eaccelerator_put(NP_BLACKLIST_CACHE_GC_TIMESTAMP, $lastGc, NP_BLACKLIST_CACHE_GC_TIMESTAMP_LIFE);
40+ eaccelerator_unlock(NP_BLACKLIST_CACHE_GC_TIMESTAMP);
41+ }
42+
43+ return $lastGc;
44+}
45+?>
\ No newline at end of file
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/cache_file.php
@@ -0,0 +1,60 @@
1+<?php
2+
3+/**
4+* cache_file.php ($Revision: 1.1 $)
5+*
6+* by hsur ( http://blog.cles.jp/np_cles )
7+* $Id: cache_file.php,v 1.1 2006-09-30 09:48:05 hsur Exp $
8+*/
9+
10+function pbl_ipcache_write(){
11+ $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
12+ if( ! rand(0,19) ) pbl_ipcache_gc();
13+
14+ // FileCache
15+ $cacheFile = NP_BLACKLIST_CACHE_DIR.'/'.$key;
16+ @touch($cacheFile) && @chmod($cacheFile, 0666);
17+ // FileCache
18+}
19+
20+function pbl_ipcache_read(){
21+ $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
22+
23+ // FileCache
24+ $cacheFile = NP_BLACKLIST_CACHE_DIR.'/'.$key;
25+ if( file_exists($cacheFile) ){
26+ if( time() - filemtime($cacheFile) < NP_BLACKLIST_CACHE_LIFE ){
27+ return true;
28+ }
29+ }
30+ return false;
31+ // FileCache
32+}
33+
34+function pbl_ipcache_gc(){
35+ $now = time();
36+ $lastGc = -1;
37+
38+ // FileCache
39+ $gcTimestampFile = NP_BLACKLIST_CACHE_DIR.'/'.NP_BLACKLIST_CACHE_GC_TIMESTAMP;
40+ if(file_exists($gcTimestampFile)){
41+ $lastGc = filemtime($gcTimestampFile);
42+ if( $now - $lastGc > NP_BLACKLIST_CACHE_GC_INTERVAL ){
43+ $count = 0;
44+ pbl_log("GC started.");
45+ @touch($gcTimestampFile);
46+ foreach (glob(NP_BLACKLIST_CACHE_DIR.'/BL*', GLOB_NOSORT) as $filename) {
47+ if($now - filemtime($filename) > NP_BLACKLIST_CACHE_LIFE){
48+ @unlink($filename) && $count += 1;
49+ }
50+ }
51+ pbl_log("GC finished. ($count files deleted.)");
52+ }
53+ } else {
54+ @touch($gcTimestampFile);
55+ }
56+ // FileCache
57+ return $lastGc;
58+}
59+
60+?>
\ No newline at end of file
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/help.html
@@ -0,0 +1,20 @@
1+<h3>バージョン履歴</h3>
2+
3+<ul>
4+ <li>Version 0.98 jp8: (2006/09/30)</li>
5+ <li> [Changed] IPブロックが正常に動作していなかった不具合を修正</li>
6+ <li> [Changed] ブロックの際に画面が真っ白になってしまう不具合を修正</li>
7+ <li> [Changed] 英語のtypoを修正</li>
8+ <li> [Added] 設定ファイルの上書きを防ぐため配布アーカイブに含まれる設定ファイルの名前を変更</li>
9+ <li> [Added] インストール時に設定ファイルを自動生成を追加</li>
10+ <li> [Added] DNSBLの応答をキャッシュするようにした</li>
11+ <li> [Added] 正規表現利用の可否を選択可能にした</li>
12+ <li> [Added] magic_quotes_gpc onの環境に対応した</li>
13+</ul>
14+
15+<ul>
16+ <li>Version 0.98 jp7: (2006/09/16)</li>
17+ <li> [Changed] obsoleteなイベントを削除</li>
18+ <li> [Changed] デフォルトの状態において、リンク付のコメントをブロックしてしまう不具合を修正</li>
19+ <li> [Added] membermailの内容についてもチェックを行うようにした</li>
20+</ul>
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/icons/i_edit.gif differ
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/icons/i_log.gif differ
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/icons/i_prefs.gif differ
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/index.php
@@ -0,0 +1,120 @@
1+<?php
2+ require_once("blacklist_lib.php");
3+
4+ //
5+ // Nucleus Admin section;
6+ // Created by Xiffy
7+ //
8+ $strRel = '../../../';
9+ include($strRel . 'config.php');
10+
11+ include($DIR_LIBS . 'PLUGINADMIN.php');
12+
13+ if ($blogid) {$isblogadmin = $member->isBlogAdmin($blogid);}
14+ else $isblogadmin = 0;
15+
16+ if (!($member->isAdmin() || $isblogadmin)) {
17+ $oPluginAdmin = new PluginAdmin('Blacklist');
18+ $pbl_config = array();
19+ $oPluginAdmin->start();
20+ echo "<p>"._ERROR_DISALLOWED."</p>";
21+ $oPluginAdmin->end();
22+ exit;
23+ }
24+
25+
26+ if (isset($_GET['page'])) {$action = $_GET['page'];}
27+ if (isset($_POST['page'])) {$action = $_POST['page'];}
28+
29+ // Okay; we are allowed. let's go
30+ // create the admin area page
31+ $oPluginAdmin = new PluginAdmin('Blacklist');
32+ $oPluginAdmin->start();
33+ // get the plugin options; stored in the DB
34+ $pbl_config['enabled'] = $oPluginAdmin->plugin->getOption('enabled');
35+ $pbl_config['redirect'] = $oPluginAdmin->plugin->getOption('redirect');
36+ //$pbl_config['update'] = $oPluginAdmin->plugin->getOption('update');
37+ $pbl_config['referrerblock'] = $oPluginAdmin->plugin->getOption('referrerblock');
38+ $pbl_config['ipblock'] = $oPluginAdmin->plugin->getOption('ipblock');
39+ $pbl_config['ipthreshold'] = $oPluginAdmin->plugin->getOption('ipthreshold');
40+ $pbl_config['BulkfeedsKey'] = $oPluginAdmin->plugin->getOption('BulkfeedsKey');
41+ $pbl_config['SkipNameResolve'] = $oPluginAdmin->plugin->getOption('SkipNameResolve');
42+
43+ function getPluginOption($name) {
44+ global $pbl_config;
45+ return $pbl_config[$name];
46+ }
47+ function getPlugid() {
48+ global $oPluginAdmin;
49+ return $oPluginAdmin->plugin->plugid;
50+ }
51+
52+ pbl_nucmenu();
53+ if ($action == 'blacklist') {
54+ pbl_blacklisteditor();
55+ echo "</div>";
56+// } elseif ($action == 'getblacklist') {
57+// if (pbl_updateblacklist($pbl_config['update'],true)) {
58+// $pblmessage = "Blacklist succesfully updated!";
59+// pbl_blacklisteditor();
60+// echo "</div>";
61+// }
62+ } elseif ($action == 'addpersonal') {
63+ pbl_addpersonal();
64+ pbl_blacklisteditor();
65+ echo "</div>";
66+ } elseif ($action == 'deleteexpression') {
67+ pbl_deleteexpression();
68+ echo "<div class=\"pblmessage\">Expression deleted from personal blacklist.</div>\n";
69+ pbl_blacklisteditor();
70+ } elseif ($action == 'log') {
71+ echo "<h2 style=\"text-align:left\"><span style=\"margin-left:10px;\">Blacklist: Blacklist Log</span></h2>";
72+ echo "<div class=\"pbldescription\">This is your Blacklist logviewer. Each blocked spam attempt will end up in this overview.If you wish you can reset the log below.</div>\n";
73+ pbl_logtable();
74+ } elseif ($action == 'resetlog') {
75+ pbl_resetfile('log');
76+ echo "<h2> logfile has been reset</h2>";
77+ echo "<h2 style=\"text-align:left\"><span style=\"margin-left:10px;\">Blacklist: Blacklist Log</span></h2>";
78+ echo "<div class=\"pbldescription\">This is your Blacklist logviewer. Each blocked spam attempt will end up in this overview.If you wish you can reset the log below.</div>\n";
79+ pbl_logtable();
80+ } elseif ($action == 'testpage') {
81+ echo "<h2>Test if an expression is considered spam</h2>";
82+ pbl_testpage();
83+ } elseif ($action == 'test') {
84+ echo "<h2>Test if an expression is considered spam</h2>";
85+ pbl_test();
86+ pbl_testpage();
87+ } elseif ($action == 'showipblock') {
88+ echo "<h2>These ip-addresses are blocked</h2>";
89+ pbl_showipblock();
90+ } elseif ($action == 'addip') {
91+ pbl_addipblock();
92+ echo "<h2>These ip-addresses are blocked</h2>";
93+ pbl_showipblock();
94+ } elseif ($action == 'deleteipblock') {
95+ pbl_deleteipblock();
96+ echo "<div class=\"pblmessage\">Block deleted</div>\n";
97+ echo "<h2>These ip-addresses are blocked</h2>";
98+ pbl_showipblock();
99+ } elseif ($action == 'htaccess') {
100+ echo "<h2>Here you can generate .htaccess snippets</h2>";
101+ pbl_htaccesspage();
102+ } elseif ($action == 'spamsubmission') {
103+ if( $_REQUEST['action'] == 'send' && !empty($_REQUEST['url']) ){
104+ $result = $oPluginAdmin->plugin->submitSpamToBulkfeeds($_REQUEST['url']);
105+
106+ echo "<h2>Spam submission</h2>";
107+ echo "<h3>result</h3>";
108+ echo "<pre>" . htmlspecialchars($result) . "</pre>";
109+
110+ } else {
111+ echo "<h2>Spam submission</h2>";
112+ pbl_spamsubmission_form();
113+ }
114+ }
115+ echo "<br />";
116+ echo "Based on pivot blacklist: <a style=\"border:0px; padding:0px; margin:10px;\" href=\"http://www.i-marco.nl/pivot-blacklist/\"><img style=\"border:0px\" src=\"".dirname($_SERVER['PHP_SELF'])."/pblbutton.png\" alt=\"Pivot Blacklist\"/></a><br/>";
117+
118+ $oPluginAdmin->end();
119+
120+?>
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/ipblock.txt
@@ -0,0 +1,12 @@
1+<h1>Warning; possible hijacked computer</h1>
2+We are sorry to inform you that the comment you tried to post on this weblog has not been accepted. This is done because your computer has been used before to post 'spam comments' on this weblog. Of course, we could be wrong in this assumption. We apollogize if this is the case.
3+We do however strongly reccomend that you run both a full virus scan on your computer with an up to date viruslist and when no virusus have been fund on your computer that you run a spyware cleaner on your pc. Some spyware leaves 'backdoors' on your pc open which allow others to use your pc for certain tasks without you knowing they do this. One of these tasks could be the dumping of comments on weblogs to increase traffic to their own websites.
4+As a countermeseaure, on this weblog 'Blacklist software' has been enabled. Once a spam-comment has been posted to this weblog, the machine that posted the message is automaticly banned from this weblog to post comments.
5+Instead we show you this message until you requested the ban to be lifted.
6+You can contact us at <emailaddres site owner>.
7+Include this ip-number in the message
8+___message
9+IP_ADDRESS
10+Please remove my ip ban,
11+I've done a complete virus-check and removed all found spyware from my pc.
12+___message
\ No newline at end of file
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/pblbutton.png differ
--- /dev/null
+++ b/trunk/NP_Blacklist/blacklist/settings/personal_blacklist.pbl.dist
@@ -0,0 +1,19 @@
1+porn
2+texas
3+teen
4+viagra
5+discount
6+cheap
7+sex
8+xxx
9+bestiality
10+finance
11+free
12+levitra
13+penis
14+poker
15+roulette
16+casino
17+insurance
18+slot
19+href=
\ No newline at end of file
Show on old repository browser