OSDN Git Service

v0.98 jp8 import
authorhsur <hsur@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 30 Sep 2006 09:48:05 +0000 (09:48 +0000)
committerhsur <hsur@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 30 Sep 2006 09:48:05 +0000 (09:48 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@386 1ca29b6e-896d-4ea0-84a5-967f57386b96

14 files changed:
trunk/NP_Blacklist/NP_Blacklist.php [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/blacklist_lib.php [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/blocked.txt [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/cache/readme.txt [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/cache_eaccelerator.php [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/cache_file.php [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/help.html [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/icons/i_edit.gif [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/icons/i_log.gif [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/icons/i_prefs.gif [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/index.php [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/ipblock.txt [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/pblbutton.png [new file with mode: 0644]
trunk/NP_Blacklist/blacklist/settings/personal_blacklist.pbl.dist [new file with mode: 0644]

diff --git a/trunk/NP_Blacklist/NP_Blacklist.php b/trunk/NP_Blacklist/NP_Blacklist.php
new file mode 100644 (file)
index 0000000..9ce30c1
--- /dev/null
@@ -0,0 +1,408 @@
+<?php
+
+/*                                                                                */
+/* NP_Blacklist                                                                   */
+/* ------------------------------------                                           */
+/* version information ----------------                                           */
+/* 0.90 initial release                                                           */
+/* 0.91 issues with xhtml compliance. sloppy coding removed                       */
+/* 0.92 added user, userid and host to check for spam                             */
+/* 0.93 bug in fetching fresh blacklist solved                                    */
+/* 0.94 code cleanup,no more pivot specific functions and files                   */
+/* 0.952 added the posibility to block on the referrerfield against the same lists
+         added the option to ip-ban the commenting machine (commented out! with //ip
+         remove all '//ip' if you want to checkout this functionality.
+         personally i don't like it -xiffy-
+*/
+/* 0.95b2 removed ip-ban option.
+          added the yet non-existent event PreActioAddComment to kick in at the right moment
+          and not 'too late'. Solves emailnotification problem on adding comments
+*/
+/* 0.95 final
+        removed the option to have a different url for referrer spamming. This will grow wild
+        if more spam-blocking types (like trackback) will be introduced.
+        So 1 url to serve them all.
+        the function blacklist is from now on the 1 function to call from other plugins
+        to call blacklist from inside your plugin add the following code:
+--deleted obsolete call for blacklist --
+*/
+/* 0.96 Beta
+        added ip-based blocking. This option differs from earlier attempts to add the ip to the nucleus ip-ban
+        Now, wehn a machine spam your website above the ip-block-threshold (default 10) the machine will be added
+        to the blocked ip addresses table. This way, newly undiscovered spamming domains won't be showing up
+        easily since most spamming is done by a subset of machines (zombies)
+        added menu item to maintain blocked ip-addresses.
+*/
+/* 0.96 Beta 2
+        .htaccess snippets work. Thanks to Karma for his regexp reworke
+        there are two modes, one for blocked IP's and one for matched rules, each give a different kind of output
+        Once you've generated the rules and incorporated the finished result into your .htaccess you should Reset the file.
+        Otherwise you would end up with doubles inside your .htaccess, this should be avoided, but is completly acceptable for apache.
+*/
+/* 0.96 Beta 3
+        Plugins calling plugins. Rakaz and I think we made it happen on a way that is future prove and a proof of concept for
+        other plugin writers. This plugin listens to the event SpamCheck, which is unknown inside nucleus-core.
+        NP_MailToAFriend, NP_Trackback and Referrer2 call this plugin if it is installed. It handles redirection itself.
+        The easy way:
+// check for spam attempts, you never knnow !
+    $spamcheck = array ('type'  => 'MailtoaFriend',
+                        'data'  => $extra."\n".$toEmail."\n".$fromEmail);
+    $manager->notify('SpamCheck', array ('spamcheck' => & $spamcheck));
+// done
+        The hard way and Total Control!
+    $spamcheck = array (
+        'type'  => 'Referer',
+        'data'  => 'data that needs to be checked',
+        'return'  => true
+    );
+
+    $manager->notify('SpamCheck',
+        array ('spamcheck' => & $spamcheck)
+    );
+
+    if (isset($spamcheck['result']) &&
+        $spamcheck['result'] == true)
+    {
+        // Handle spam
+    }
+*/
+/* 0.97 Added eventHandler for the new ValidateForm event (nucleus 3.2)
+*/
+/* 0.98 Solved naar.be bug
+*/
+
+class NP_Blacklist extends NucleusPlugin {
+       function getName()                { return 'Blacklist'; }
+       function getAuthor()      { return 'xiffy + cles'; }
+       function getURL()                 { return 'http://blog.cles.jp/np_cles/category/31/subcatid/11'; }
+       function getVersion()     { return '0.98 jp8'; }
+       function getDescription() { return 'Blacklist for commentspammers (SpamCheck API 2.0 compatible)';      }
+       function supportsFeature($what) {
+               switch($what) {
+                   case 'SqlTablePrefix':
+                               return 1;
+                       default:
+                               return 0;
+               }
+       }
+
+    function install() {
+        // create some options
+        $this->createOption('enabled','Blacklist engine enabled?','yesno','yes');
+        $this->createOption('redirect','To which URL should spammers be redireted?','text','');
+//        $this->createOption('update','From which URL should we get a fresh blacklist copy?', 'text','');
+        $this->createOption('referrerblock','Enable referrer based blocking?','yesno','no');
+        $this->createOption('ipblock','Enable ip based blocking?','yesno','yes');
+        $this->createOption('ipthreshold','','text','10');
+               $this->createOption('BulkfeedsKey', 'Bulkfeeds API Key', 'text', '');
+               $this->createOption('SkipNameResolve', 'Skip reverse DNS lookup ?', 'yesno','yes');
+               
+               $this->_initSettings();
+    }
+
+       function unInstall() {}
+
+    function getPluginOption ($name) {
+        return $this->getOption($name);
+    }
+
+       function getEventList() {
+               $this->_initSettings();
+               return array('QuickMenu','PreAddComment','PreSkinParse','ValidateForm', 'SpamCheck');
+       }
+
+       function hasAdminArea() {
+               return 1;
+       }
+       
+       function init(){
+               $this->resultCache = false;
+       }
+
+       function event_QuickMenu(&$data) {
+               global $member, $nucleus, $blogid;
+               // only show to admins
+               if (preg_match("/MD$/", $nucleus['version'])) {
+                       $isblogadmin = $member->isBlogAdmin(-1);
+               } else {
+                       $isblogadmin = $member->isBlogAdmin($blogid);
+               }
+               if (!($member->isLoggedIn() && ($member->isAdmin() | $isblogadmin))) return;
+               array_push(
+                       $data['options'],
+                       array(
+                               'title' => 'Blacklist',
+                               'url' => $this->getAdminURL(),
+                               'tooltip' => 'Manage your blacklist'
+                       )
+               );
+       }
+
+    // for other plugin writers ...
+    function event_SpamCheck (&$data) {
+        global $DIR_PLUGINS;
+//        $fp  = fopen ($DIR_PLUGINS."blacklist/settings/debug.txt", 'a');
+//        fwrite($fp,"==called ==\n");
+//        fwrite($fp,'type : ' .$data['spamcheck']['type']."\n");
+//        fwrite($fp,'data : ' .$data['spamcheck']['data']."\n");
+//        fclose($fp);
+        if (isset($data['spamcheck']['result']) && $data['spamcheck']['result'] == true){
+            // Already checked... and is spam
+            return;
+        }
+               
+               if( ! isset($data['spamcheck']['return']) ){
+                       $data['spamcheck']['return'] = true;
+               }
+               
+               // for SpamCheck API 2.0 compatibility
+               if( ! $data['spamcheck']['data'] ){
+                       switch( strtolower($data['spamcheck']['type']) ){
+                               case 'comment':
+                                       $data['spamcheck']['data']  = $data['spamcheck']['body'] . "\n";
+                                       $data['spamcheck']['data'] .= $data['spamcheck']['author'] . "\n";
+                                       $data['spamcheck']['data'] .= $data['spamcheck']['url'] . "\n"; 
+                                       break;
+                               case 'trackback':
+                                       $data['spamcheck']['data']  = $data['spamcheck']['title']. "\n"; 
+                                       $data['spamcheck']['data'] .= $data['spamcheck']['excerpt']. "\n";
+                                       $data['spamcheck']['data'] .= $data['spamcheck']['blogname']. "\n";
+                                       $data['spamcheck']['data'] .= $data['spamcheck']['url'];
+                                       break;
+                               case 'referer':
+                                       $data['spamcheck']['data'] = $data['spamcheck']['url'];
+                                       break;
+                       }
+               }
+               $ipblock = ( $data['spamcheck']['ipblock'] ) || ($data['spamcheck']['live']);
+               
+        // Check for spam
+        $result = $this->blacklist($data['spamcheck']['type'], $data['spamcheck']['data'], $ipblock);
+
+        if ($result) {
+            // Spam found
+            // logging !
+            pbl_logspammer($data['spamcheck']['type'].': '.$result);
+            if  (isset($data['spamcheck']['return']) && $data['spamcheck']['return'] == true) {
+                // Return to caller
+                $data['spamcheck']['result'] = true;
+                return;
+            } else {
+                $this->_redirect($this->getOption('redirect'));
+            }
+        }
+    }
+
+    // will become obsolete when nucleus is patched ...
+       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'));
+        }
+    }
+
+       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'));
+                       }
+               }
+    }
+
+       // preskinparse will check the referrer for spamming attempts
+       // only when option enabled !
+       // logging also only when option enabled ...
+       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;
+               if( $this->resultCache )
+                       return $this->resultCache . '[Cached]';
+               
+           if ($this->getOption('enabled') == 'yes') {
+            include_once($DIR_PLUGINS."blacklist/blacklist_lib.php");
+            // update the blacklist first file
+            //pbl_updateblacklist($this->getOption('update'),false);
+            if ($ipblock) {
+                $ipblock = ( $this->getOption('ipblock') == 'yes' ) ? true : false ;
+            }
+                       
+                       $result = '';
+            if ($this->getOption('referrerblock') == 'yes')  {
+                               $refer = parse_url(serverVar('HTTP_REFERER'));
+                $result = pbl_checkforspam($refer['host']."\n".$testString, $ipblock , $this->getOption('ipthreshold'), true);
+            } elseif ($ipblock || $testString != '') {
+                $result = pbl_checkforspam($testString, $ipblock, $this->getOption('ipthreshold'), true);
+            }
+                       
+                       if( $result ){
+                               $this->resultCache = $result;
+                       }
+                       
+                       return $result;
+        }
+    }
+       
+       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);
+               //preg_match('#<result>([^<]*)</result>#mi', $data, $matches);
+               //$result = trim($matches[1]);
+               
+               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: PHP/".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 _spamMark($word){
+               $_GET["expression"] = preg_quote($word, '/');
+               $_GET["comment"] = 'SpamMark [' . date("Y/m/d H:i:s") . ']';
+
+               $existTest = pbl_checkforspam(getVar("expression"));
+               if (! (strlen($existTest) > 0))  {
+                       pbl_addexpression();
+               }
+       }
+       
+       function _redirect($url) {
+               if( !$url ){
+                       header("HTTP/1.0 403 Forbidden");
+                       header("Status: 403 Forbidden");
+                       
+                       include(dirname(__FILE__).'/blacklist/blocked.txt');
+               } else {
+                       $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $url);
+                       header('Location: ' . $url);
+               }
+               exit;
+       }
+       
+       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';
+
+               // 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' created.");
+                               } else {
+                                       $this->_warn("'$personalBlacklist' cannot create.");
+                               }
+                       }
+               }
+       
+               // 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;
+               $this->_is_writable($cacheDir);
+       }
+       
+       function _is_writable($file){
+               $ret = is_writable($file);
+               if( ! $ret ){
+                       $this->_warn("'$file' is not writable.");
+               }
+               return $ret;
+       }
+       
+       function _warn($msg) {
+               ACTIONLOG :: add(WARNING, 'Blacklist: '.$msg);
+       }
+       
+}
+?>
diff --git a/trunk/NP_Blacklist/blacklist/blacklist_lib.php b/trunk/NP_Blacklist/blacklist/blacklist_lib.php
new file mode 100644 (file)
index 0000000..341b1f4
--- /dev/null
@@ -0,0 +1,833 @@
+<?php
+// Pivot-Blacklist version 0.4 (with Nucleus Support!)
+//
+// A simple (but effective) spam blocker based on the MT-Blacklist
+// available at: http://www.jayallen.org/comment_spam/
+//
+// Includes realtime blacklist check functions by
+// John Sinteur (http://weblog.sinteur.com/)
+//
+// This code (c) 2004 by Marco van Hylckama Vlieg
+//                    adapted and extended by Appie Verschoor
+// License is GPL, just like Pivot / Nucleus
+//
+// http://www.i-marco.nl/
+// marco@i-marco.nl
+//
+// http://xiffy.nl/
+// blacklist@xiffy.nl
+
+define('__WEBLOG_ROOT', dirname(dirname(realpath(__FILE__))));
+define('__EXT', '/blacklist');
+
+define('NP_BLACKLIST_CACHE_DIR', dirname(__FILE__).'/cache');
+define('NP_BLACKLIST_CACHE_LIFE', 86400);
+define('NP_BLACKLIST_CACHE_GC_INTERVAL', NP_BLACKLIST_CACHE_LIFE/8);
+define('NP_BLACKLIST_CACHE_GC_TIMESTAMP', 'gctime');
+define('NP_BLACKLIST_CACHE_GC_TIMESTAMP_LIFE', NP_BLACKLIST_CACHE_LIFE*3);
+require_once(dirname(__FILE__).'/cache_file.php');
+//require_once(dirname(__FILE__).'/cache_eaccelerator.php');
+
+function pbl_getconfig()  {
+    global $pbl_config;
+       $pbl_config = array();
+    $pbl_config['enabled']  = getPluginOption('enabled');
+    $pbl_config['redirect'] = getPluginOption('redirect');
+    //$pbl_config['update']   = getPluginOption('update');
+    // convert 'yes' into '1'
+    if ($pbl_config['enabled'] == 'yes') {$pbl_config['enabled'] = 1;}
+       return $pbl_config;
+}
+
+function pbl_checkforspam($text, $ipblock = false, $ipthreshold = 10, $logrule = true)  {
+       // check whether a string contains spam
+       // if it does, we return the rule that was matched first
+       //$text = strtolower($text);
+       $text = trim($text);
+
+    // first line of defense; block notorious spammers
+    if ($ipblock) {
+        if (pbl_blockIP()) {
+            return "<b>IP Blocked</b>: ".serverVar('REMOTE_ADDR')." (".serverVar('REMOTE_HOST').")";
+        }
+    }
+       // second line of defense: Check whether our poster is using
+       // an open proxy
+       //if(check_for_open_proxy())  {
+    //    if ($ipblock == 'yes') {
+    //        pbl_suspectIP ($ipthreshold);
+    //    }
+       //      return "open spam proxy";
+       //}
+
+       // third line of defense: Check whether our poster promotes
+       // known spamsite url's listed at www.surbl.org
+       //if(check_for_surbl($text))    {
+    //    if ($ipblock == 'yes') {
+    //        pbl_suspectIP ($ipthreshold);
+    //    }
+       //      return("url(s) listed on www.surbl.org found");
+       //}
+
+       // fourth line of defense: Run the MT-Blacklist check
+       if( $text && file_exists(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl") ){      
+               $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl", "r");
+               while (!feof($handle)) {
+                       $buffer = fgets($handle, 4096);
+                       $splitbuffer = explode("####", $buffer);
+                       $expression = $splitbuffer[0];
+                       $explodedSplitBuffer = explode("/", $expression);
+                       $expression = $explodedSplitBuffer[0];
+                       if (strlen($expression) > 0)  {
+                               if(preg_match("/".trim($expression)."/i", $text))  {
+                       if ($ipblock) {
+                           pbl_suspectIP ($ipthreshold);
+                       }
+                       if ($logrule) {
+                           pbl_logRule($expression);
+                       }
+                                       return $expression;
+                               }
+                       }
+               }
+               fclose($handle);
+       }
+
+       // fifth line of defense: run the personal blacklist entries
+       if ($text &&file_exists(__WEBLOG_ROOT.__EXT.'/settings/personal_blacklist.pbl'))  {
+               $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "r");
+               while (!feof($handle)) {
+                       $buffer = fgets($handle, 4096);
+                       $splitbuffer = explode("####", $buffer);
+                       $expression = $splitbuffer[0];
+                   if (strlen($expression) > 0)  {
+//                 if(is_domain($expression))  {
+//                         $expression = str_replace(".","\.",$expression);
+//                     }
+                           if(preg_match("/".trim($expression)."/i", $text))  {
+                    if ($ipblock) {
+                        pbl_suspectIP ($ipthreshold);
+                    }
+                    if ($logrule) {
+                        pbl_logRule($expression);
+                    }
+                                       fclose($handle);
+                                   return $expression;
+                               }
+                       }
+               }
+               fclose($handle);
+       }
+
+       if( $ipblock && $listedrbl = check_for_iprbl() )  {
+               pbl_suspectIP ($ipthreshold);
+               $ref = serverVar('HTTP_REFERER');
+               return "ip listed on {$listedrbl[0]} found (Referer:{$ref})";
+       }
+
+       if( $text && ($listedrbl = check_for_domainrbl($text)) ) {
+        if ($ipblock) {
+            pbl_suspectIP ($ipthreshold);
+        }
+               return("url(s) listed on {$listedrbl[0]} ({$listedrbl[1]}) found");
+       }
+
+       // w00t! it's probably not spam!
+       return "";
+}
+
+function pbl_updateblacklist($url, $force=false)  {
+/*
+       $listAge = time() - @filemtime(__WEBLOG_ROOT.__EXT.'/settings/blacklist.txt');
+       // 86400 is 24hours (24*60*60)
+       if ((($listAge > 86400 ) || (!file_exists(__WEBLOG_ROOT.__EXT.'/settings/blacklist.txt'))) || ($force))  {
+               $handle = @fopen($url, "r");
+               if ($handle) {
+                   while (!feof($handle)) {
+                           $buffer = fgets($handle, 4096);
+                       $newBlackList .= $buffer;
+               }
+               fclose($handle);
+       }
+
+               // Check whether we really have the file
+               // if not we keep the old one because we don't want to break
+               // the engine with a bad or missing file
+
+               if(strstr($newBlackList, "MT-Blacklist Master Copy"))  {
+                       $newFile = fopen(__WEBLOG_ROOT.__EXT.'/settings/blacklist.txt', 'w');
+                       fwrite($newFile, $newBlackList);
+                       fclose($newFile);
+                       pbl_processblacklist();
+               }
+       }
+*/
+       return true;
+}
+
+/*
+function pbl_processblacklist()  {
+       // reformat the list to match our own format
+       $listString = "";
+       $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.txt", "r")  or die ("could not open: ".__WEBLOG_ROOT.__EXT."/settings/blacklist.txt");
+       while (!feof($handle)) {
+               $buffer = fgets($handle, 4096);
+               $splitbuffer = explode("#", $buffer);
+               $expression = $splitbuffer[0];
+               $explodedSplitBuffer = explode("/", $expression);
+               $expression = $explodedSplitBuffer[0];
+               if (strlen($expression) > 0)  {
+                       $listString .= preg_replace("/([^\\\|^_]|^)\./",'$1\\.',trim($expression));
+                       if(strlen($splitbuffer[1]) > 5)  {
+                               $listString .= " #### ".trim($splitbuffer[1]);
+                       }
+                       $listString .= "\n";
+               }
+       }
+       fclose($handle);
+       if(file_exists(__WEBLOG_ROOT.__EXT.'/settings/blacklist.pbl'))  {
+       }
+       $newhandle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl", "w");
+       fwrite($newhandle, $listString);
+       fclose($newhandle);
+}
+*/
+
+function is_domain($stheDomain) {
+       return ( (strpos($stheDomain,"\\")==0) && (strpos($stheDomain,"[")==0) && (strpos($stheDomain, "(")==0) );
+}
+
+
+function pbl_nucmenu() {
+       echo "<h2>Blacklist menu</h2>\n";
+       echo "<ul>\n";
+       echo "<li><a href=\"".serverVar('PHP_SELF')."?page=blacklist\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_edit.gif\" /> Blacklist Editor</a></li>\n";
+       echo "<li><a href=\"".serverVar('PHP_SELF')."?page=log\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_log.gif\" /> Blacklist Log</a></li>\n";
+       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";
+       echo "<li><a href=\"".serverVar('PHP_SELF')."?page=testpage\"><img src=\"".dirname(serverVar('PHP_SELF'))."/icons/i_edit.gif\" /> Test Blacklist</a></li>\n";
+       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";
+       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";
+       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";
+       echo "</ul>\n";
+}
+
+function pbl_blacklisteditor()  {
+
+       global $pblmessage;
+
+       if(strlen($pblmessage) > 0)  {
+               echo "<div class=\"pblmessage\">$pblmessage</div>\n";
+       }
+
+/*
+       echo "<div id=\"jayallen\">\n";
+       echo "<div class=\"pbldescription\">";
+       if(!file_exists(__WEBLOG_ROOT.__EXT."/settings/blacklist.pbl"))  {
+               echo "You don't have a blacklist file yet!<br />";
+               echo "Click the button below to get the latest MT-Blacklist from Jay Allen's site.";
+               echo "</div>";
+               echo "<div class=\"pbform\">\n";
+               echo "<form action=\"index.php\" method=\"get\">\n";
+               echo "<input type=\"hidden\" name=\"page\" value=\"getblacklist\" />\n";
+               echo "<input type=\"submit\" value=\"Download and install\" />\n";
+               echo "</form>\n";
+               echo "</div>\n";
+       }
+       else  {
+               $updatetime = @filemtime(__WEBLOG_ROOT.__EXT."/settings/blacklist.txt");
+               echo "Your MT-Blacklist file was last updated at: ";
+               echo date("Y/m/d H:i:s", $updatetime)." <br />";
+#              echo date("F d Y H:i", $updatetime)." <br />";
+               echo "It's updated automatically every day but you can click below to update it immediately";
+               echo "</div>\n";
+               echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
+               echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
+               echo "<input type=\"hidden\" name=\"page\" value=\"getblacklist\" />\n";
+               echo "<input type=\"submit\" value=\"Update now\" />\n";
+               echo "</form>\n";
+               echo "</div>\n";
+       }
+       echo "</div>\n";
+*/
+       echo "<div id=\"personal\">\n";
+       echo "<div class=\"pbldescription\">";
+       echo "You can add url's, regular expressions or words to your personal blacklist below.";
+       echo "</div>\n";
+       echo "<div class=\"pbform\">\n";
+       echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
+       echo "<input type=\"hidden\" name=\"page\" value=\"addpersonal\" />\n";
+       echo "<table class=\"pblform\">\n";
+       echo "<tr>\n";
+       echo "<td>expression</td>\n";
+       echo "<td><input class=\"pbltextinput\" type=\"text\" name=\"expression\" /></td>\n";
+       echo "</tr>\n";
+       echo "<tr>";
+       echo "  <td>comment</td>\n";
+       echo "  <td><input class=\"pbltextinput\" type=\"text\" name=\"comment\" /></td>\n";
+       echo "</tr>\n";
+       echo "<tr>";
+       echo "  <td>enable regular expressions ?</td>\n";
+       echo "  <td><input class=\"pbltextinput\" type=\"checkbox\" name=\"enable_regex\" value=\"1\" /></td>\n";
+       echo "</tr>\n";
+       echo "<tr><td colspan=\"2\" style=\"border:none;\"><input type=\"submit\" value=\"Add\" /></td>\n";
+       echo "</tr>\n";
+       echo "</table>\n";
+       echo "</form>\n";
+       echo "</div>\n";
+       echo "<div class=\"pbldescription\">Below is your personal blacklist</div>\n";
+       if (file_exists(__WEBLOG_ROOT.__EXT.'/settings/personal_blacklist.pbl'))  {
+               $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "r");
+               echo "<table>\n";
+               echo "<tr>\n";
+               echo "<th>expression</th>\n";
+               echo "<th>comment</th>\n";
+               echo "<th>deletion</th>\n";
+               echo "</tr>\n";
+               $line = 0;
+               while (!feof($handle)) {
+                       $buffer = fgets($handle, 4096);
+                       $line++;
+                       $configParam = explode("####", $buffer);
+                       $key = $configParam[0];
+                       $value = $configParam[1];
+                       if(strlen($key) > 0)  {
+                               echo "<tr>\n";
+                               echo "<td>".htmlspecialchars($key,ENT_QUOTES)."</td>\n";
+                               echo "<td>".htmlspecialchars($value,ENT_QUOTES)."</td>\n";
+                               echo "<td>";
+                               echo "<a href=\"".serverVar('PHP_SELF')."?page=deleteexpression&amp;line=".$line."\">delete</a>";
+                               echo "</td>";
+                               echo "</tr>\n";
+                       }
+               }
+               echo "</table>\n";
+       }
+}
+function pbl_deleteexpression()  {
+       if(isset($_GET["line"]))  {
+               if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl") ){
+                       echo "Error: personal_blacklist.pbl is not writable. ";
+               }
+               $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "r");
+               $line = 0;
+               $newFile = "";
+               while (!feof($handle)) {
+                       $buffer = fgets($handle, 4096);
+                       $line++;
+                       if($line != getVar("line"))  {
+                               $newFile .= $buffer;
+                       }
+               }
+               fclose($handle);
+               $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "w");
+               fwrite($handle, $newFile);
+               fclose($handle);
+       }
+}
+function pbl_addexpression($expression, $comment)  {
+       if(strlen($expression) > 0)  {
+               if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl") ){
+                       echo "Error: personal_blacklist.pbl is not writable. ";
+               }
+               $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/personal_blacklist.pbl", "a");
+               if(strlen($comment) > 0)  {
+                               $expression = $expression." #### ".$comment;
+               }
+               fwrite($handle, $expression."\n");
+               fclose($handle);
+               
+       }
+}
+
+$g_reOk = false;
+function _hdl($errno, $errstr) {
+       global $g_reOk;
+       $g_reOk = false;
+}
+
+function pbl_checkregexp($re) {
+       // Thanks to 'OneOfBorg' on Gathering Of Tweakers
+       // http://gathering.tweakers.net/forum/user_profile/109376
+       global $g_reOk;
+       $g_reOk = true;
+       set_error_handler("_hdl");
+       preg_match("/".trim($re)."/i", "");
+       restore_error_handler();
+       return $g_reOk;
+}
+
+function pbl_addpersonal()  {
+       if(isset($_GET["expression"]))  {
+               $expression = getVar("expression");
+               if( getVar('comment') ){
+                       $comment = getVar('comment');
+               }
+               if($expression != "")  {
+                       $enable_regex = true;
+                       if( ! getVar('enable_regex') ){
+                               $enable_regex = false;
+                               $expression = preg_quote($expression,'/');
+                       } 
+                       
+                       if($enable_regex && (!pbl_checkregexp($expression)))  {
+                               echo "<div class=\"pblmessage\">Your expression contained errors and couldn't be added: <b>".htmlspecialchars($expression,ENT_QUOTES)."</b></div>\n";
+                       }
+                       else  {
+                               $existTest = pbl_checkforspam($expression);
+
+                               if (strlen($existTest) > 0)  {
+                                       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";
+                               }
+                               else  {
+                                       pbl_addexpression($expression,$comment);
+                                       echo "<div class=\"pblmessage\">New entry added to your list: <b>".htmlspecialchars($expression,ENT_QUOTES)."</b></div>";
+                               }
+                       }
+               }
+               else  {
+                       echo "<div class=\"pblmessage\">There's no use in adding empty expressions.<b>".htmlspecialchars($expression,ENT_QUOTES)."</b></div>";
+               }
+       }
+}
+
+function pbl_logspammer($spam)  {
+       $spam = trim($spam);
+       if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/blacklist.log") ){
+               echo "Error: blacklist.log is not writable. ";
+       }
+       $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.log", "a");
+       $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit');
+       if( $lastVisit ){
+               //$lastVisit = $this->getCorrectTime($lastVisit);
+               $logline = date("Y/m/d H:i:s")." #### ".serverVar("REMOTE_ADDR")." #### ".$spam. ' [lastVisit ' .date("Y/m/d H:i:s", $lastVisit). "]\n";
+       } else {
+               $logline = date("Y/m/d H:i:s")." #### ".serverVar("REMOTE_ADDR")." #### ".$spam."\n";
+       }
+       fwrite($handle, $logline);
+       fclose($handle);
+}
+
+function pbl_log($text)  {
+       $text = trim($text);
+       if( ! is_writable(__WEBLOG_ROOT.__EXT."/settings/blacklist.log") ){
+               echo "Error: blacklist.log is not writable. ";
+       }
+       $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.log", "a");
+       $logline = date("Y/m/d H:i:s")." #### localhost #### ".$text."\n";
+       fwrite($handle, $logline);
+       fclose($handle);
+}
+
+
+function pbl_logtable()  {
+       if (file_exists(__WEBLOG_ROOT.__EXT."/settings/blacklist.log"))  {
+               $handle = fopen(__WEBLOG_ROOT.__EXT."/settings/blacklist.log", "r");
+               $logrows = "";
+               $numb=0;
+               while (!feof($handle)) {
+                       $buffer = fgets($handle, 4096);
+                       $thisline = explode("####", $buffer);
+                       if($thisline[0] != "")  {
+                               $logrows .= "<tr>";
+                               $logrows .= "<td class=\"log$numb\" >$thisline[0]</td>";
+                               if( getPluginOption('SkipNameResolve') == 'no' )
+                                       $logrows .= "<td class=\"log$numb\" >$thisline[1]<br />(" . gethostbyaddr( trim($thisline[1]) ) .  ")</td>";
+                               else
+                                       $logrows .= "<td class=\"log$numb\" >$thisline[1]</td>";
+                               $logrows .= "<td class=\"log$numb\" >$thisline[2]</td>";
+                               $logrows .= "</tr>\n";
+                       }
+                       if($numb == 0)
+                       $numb=1;
+                       else
+                       $numb=0;
+               }
+               fclose($handle);
+               echo "<table class=\"pbllog\">\n";
+               echo "<tr><th>Date/Time</th><th>IP</th><th>Rule Matched</th></tr>\n";
+               echo $logrows;
+               echo "</table>\n";
+       }
+       if(strlen($logrows) < 10)  {
+               echo "<div class=\"pbldescription\">Your log is empty.</div>\n";
+       }
+       echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
+       echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
+       echo "<input type=\"hidden\" name=\"page\" value=\"resetlog\" />\n";
+       echo "<input type=\"submit\" value=\"Reset log\" />\n";
+       echo "</form>\n";
+       echo "</div>\n";
+}
+
+function check_for_open_proxy()        {
+       $spammer_ip = serverVar('REMOTE_ADDR');
+       list($a, $b, $c, $d) = split('.', $spammer_ip);
+       if( gethostbyname("$d.$c.$b.$a.list.dsbl.org") != "$d.$c.$b.$a.list.dsbl.org") {
+               return true;
+       }
+       return false;
+}
+
+function check_for_surbl ( $comment_text ) {
+       /*  for a full explanation, see http://www.surbl.org
+       summary: blocks comment if it contains an url that's on a known spammers list.
+       */
+       //get site names found in body of comment.
+       $regex_url   = "/(www\.)([^\/\"<\s]*)/i";
+       $mk_regex_array = array();
+       preg_match_all($regex_url, $comment_text, $mk_regex_array);
+
+       for( $cnt=0; $cnt < count($mk_regex_array[2]); $cnt++ ) {
+               $domain_to_test = rtrim($mk_regex_array[2][$cnt],"\\");
+
+               if (strlen($domain_to_test) > 3)
+               {
+                       $domain_to_test = $domain_to_test . ".multi.surbl.org";
+                       if( strstr(gethostbyname($domain_to_test),'127.0.0')) {
+                               return true;
+                       }
+               }
+       }
+       return false;
+}
+
+//add hsur +++++++++++++
+
+function check_for_iprbl () {
+       if( pbl_ipcache_read() ) return false;
+       
+       //$iprbl = array('sc.surbl.org', 'bsb.spamlookup.net', 'opm.blitzed.org', 'list.dsbl.org');
+       $iprbl = array('niku.2ch.net', 'list.dsbl.org', 'bsb.spamlookup.net');
+
+       $spammer_ip = serverVar('REMOTE_ADDR');
+       list($a, $b, $c, $d) = explode('.', $spammer_ip);
+               
+       foreach($iprbl as $rbl ){
+               if( strstr( gethostbyname( "$d.$c.$b.$a.$rbl" ),'127.0.0') ) {
+                       return array($rbl, $spammer_ip);
+               }
+       }
+       pbl_ipcache_write();
+       return false;
+}
+
+function check_for_domainrbl ( $comment_text ) {
+       $domainrbl = array('rbl.bulkfeeds.jp', 'url.rbl.jp', 'bsb.spamlookup.net');
+       //$regex_url   = "/((http:\/\/)|(www\.))([^\/\"<\s]*)/i";
+       $regex_url   = "{https?://(?:www\.)?([a-z0-9._-]{2,})(?::[0-9]+)?((?:/[_.!~*a-z0-9;@&=+$,%-]+){0,2})}m";
+       $comment_text = mb_strtolower($comment_text);
+
+       $mk_regex_array = array();
+       preg_match_all($regex_url, $comment_text, $mk_regex_array);
+
+       $mk_regex_array[1] = array_unique($mk_regex_array[1]);
+
+       for( $cnt=0; $cnt < count($mk_regex_array[1]); $cnt++ ) {
+               $domain_to_test = rtrim($mk_regex_array[1][$cnt],"\\");
+               foreach($domainrbl as $rbl ){
+                       if (strlen($domain_to_test) > 3)
+                       {
+                               if( strstr(gethostbyname($domain_to_test.'.'.$rbl),'127.0.0')) {
+                                       return array($rbl, $domain_to_test);
+                               }
+                       }
+               }
+       }
+       return false;
+}
+
+//add hsur end ++++++++++++++
+
+function pbl_blockIP() {
+    $remote_ip = trim(serverVar('REMOTE_ADDR'));
+       $filename  = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
+       $block     = false;
+       // already in ipblock?
+       if (file_exists($filename)) {
+        $fp = fopen(__WEBLOG_ROOT.__EXT."/settings/blockip.pbl", "r");
+        while ($line = trim(fgets($fp,255))) {
+            if( strpos($remote_ip, $line) !== false){$block = true;}
+        }
+        fclose ($fp);
+    } else {
+        $fp = fopen(__WEBLOG_ROOT.__EXT."/settings/blockip.pbl", "w");
+        fwrite($fp, "");
+        fclose ($fp);
+    }
+    return $block;
+}
+
+function pbl_logRule($expression) {
+    $filename  = __WEBLOG_ROOT.__EXT."/settings/matched.pbl";
+    $count = 0;
+    $fp = fopen($filename,"r+");
+    if ($fp) {
+        while ($line = fgets($fp, 4096)) {
+            if (! (strpos($line, $expression) === false )) {
+                $count++;
+                break;
+            }
+        }
+        fclose($fp);
+    }
+    if ($count == 0 && !trim($expression) == "" ) {
+        $fp = fopen($filename,"a+");
+        fwrite($fp,$expression."\n");
+    }
+}
+
+// this function logs all ip-adresses in a 'suspected ip-list'
+// if the ip of the currently catched spammer is above the ip-treshold (plugin option) then
+// the spamming ipaddress is transfered to the blocked-ip list.
+// this list is the first line of defense, so notorious spamming machine will be kicked of real fast
+// improves blacklist performance
+// possible danger: blacklisting real humans who post on-the-edge comments
+function pbl_suspectIP($threshold, $remote_ip = '') {
+       if ($remote_ip == '' ) {$remote_ip = serverVar('REMOTE_ADDR');}
+       $filename  = __WEBLOG_ROOT.__EXT."/settings/suspects.pbl";
+       $blockfile = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
+       $count     = 0;
+    // suspectfile ?
+       if (! file_exists($filename)) {
+        $fp = fopen($filename, "w");
+        fwrite($fp, "");
+        fclose ($fp);
+    }
+
+    $fp = fopen($filename, "r");
+    while ($line = fgets($fp,255)) {
+        if ( strpos($line, $remote_ip) !== false ) {
+            $count++;
+        }
+    }
+    fclose ($fp);
+
+    // not above threshold ? add ip to suspect ...
+    if ($count < $threshold) {
+        $fp = fopen($filename,'a+');
+        fwrite($fp,$remote_ip."\n");
+        fclose($fp);
+    } else {
+        // remove from suspect to ip-block
+        $fp = fopen($filename, "r");
+        $rewrite = "";
+        while ($line = fgets($fp,255)) {
+            // keep all lines except the catched ip-address
+            if(strpos ($line, $remote_ip) !== false) {
+                $rewrite .= $line;
+            }
+        }
+        fclose($fp);
+        $fp = fopen($filename, "w");
+        fwrite($fp, $rewrite);
+        fclose ($fp);
+        // transfer to blocked-ip file
+        $fp = fopen($blockfile,'a+');
+        fwrite($fp,$remote_ip."\n");
+        fclose($fp);
+    }
+}
+
+function pbl_showipblock() {
+    global $pblmessage;
+       $filename  = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
+       $line = 0;
+       $fp = fopen($filename,'r');
+       echo "<div class=\"pbform\">\n";
+       echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
+       echo "<input type=\"hidden\" name=\"page\" value=\"addip\" />\n";
+       echo "Add IP to block: ";
+       echo "<input class=\"pbltextinput\" type=\"text\" name=\"ipaddress\" />\n";
+       echo "<input type=\"submit\" value=\"Add\" />\n";
+       echo "</form>";
+       echo "</div>\n";
+       echo "<table>";
+       echo "<tr>\n";
+       echo "<th>IP Address</th>\n";
+       echo "<th>reversed lookup</th>\n";
+       echo "<th>deletion</th>\n";
+       echo "</tr>\n";
+       while ($ip = fgets($fp,255)) {
+           $line++;
+               if( getPluginOption('SkipNameResolve') == 'no' )
+                       echo "<tr><td>".$ip."</td><td>[".gethostbyaddr(rtrim($ip))."]</td><td>";
+               else
+                       echo "<tr><td>".$ip."</td><td>[<em>skipped</em>]</td><td>";
+               echo "<a href=\"".serverVar('PHP_SELF')."?page=deleteipblock&amp;line=".$line."\">delete</a>";
+               echo "</td></tr>";
+       }
+       echo "</table>";
+}
+function pbl_addipblock() {
+       if(isset($_GET["ipaddress"]))  {
+           pbl_suspectIP(0,getVar("ipaddress"));
+       }
+}
+
+function pbl_deleteipblock() {
+    global $pblmessage;
+       $filename  = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
+       if(isset($_GET["line"]))  {
+               $handle = fopen($filename, "r");
+               $line = 0;
+               $newFile = "";
+               while (!feof($handle)) {
+                       $buffer = fgets($handle, 4096);
+                       $line++;
+                       if($line != getVar("line"))  {
+                               $newFile .= $buffer;
+                       }
+               }
+               fclose($handle);
+               $handle = fopen($filename, "w");
+               fwrite($handle, $newFile);
+               fclose($handle);
+       }
+}
+
+function pbl_htaccess($type) {
+    $htaccess = "";
+    switch($type) {
+        case "ip":
+           $filename  = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
+            $htaccess  = "# This htaccess snippet blocks machine based on IP Address. \n"
+                       . "# these lines are generated by NP_Blackist\n";
+            break;
+        case "rules":
+            $filename  = __WEBLOG_ROOT.__EXT."/settings/matched.pbl";
+            $htaccess  = "# This htaccess snippet blocks machine based on referrers. \n"
+                       . "# these lines are generated by NP_Blackist\n"
+                       . "# You need to have the following line once in your .htaccess file\n"
+                       . "# RewriteEngine On\n";
+            break;
+        default:
+            $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";
+            return $htaccess;
+    }
+
+    $fp = fopen($filename, 'r');
+    $count = 0;
+    while ($line = fgets($fp,4096)) {
+        if ($type == "ip") {
+            $htaccess .= "deny from ".$line;
+        } else {
+            if (rtrim($line) != "" ) {
+                if ($count > 0) {$htaccess .= "[NC,OR]\n";}
+                // preg_replace does the magic of converting . into \. while keeping \. and _. intact
+                $htaccess .= "RewriteCond %{HTTP_REFERER} ". preg_replace("/([^\\\|^_]|^)\./",'$1\\.',rtrim($line)).".*$ ";
+                $count++;
+            }
+        }
+    }
+    if ($type != "ip") {
+        $htaccess .= "\nRewriteRule .* � [F,L]\n";
+    }
+    return $htaccess;
+}
+
+function pbl_htaccesspage() {
+       global $pblmessage;
+       if(strlen($pblmessage) > 0)  {
+               echo "<div class=\"pblmessage\">$pblmessage</div>\n";
+       }
+
+    if (isset($_POST["type"])) {
+        if (strstr(postVar("type"),"blocked")) {
+            $type = 'ip';
+        } else {
+            $type = 'rules';
+        }
+    }
+       echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
+       echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"post\">\n";
+    echo "<input type=\"submit\" label=\"ip\" value=\"Generate blocked IP's\" name=\"type\" />\n";
+    echo "<input type=\"submit\" label=\"ip\" value=\"Generate rewrite rules\" name=\"type\" />\n";
+    echo "<br />";
+    echo "<br />";
+       echo "<input type=\"hidden\" name=\"page\" value=\"htaccess\" />\n";
+    echo "<textarea class=\"pbltextinput\" cols=\"60\" rows=\"15\" name=\"snippet\" >". pbl_htaccess($type)."</textarea><br />";
+    echo "<br />";
+    echo "<input title=\"this will clean your block IP addresses file\" type=\"submit\" label=\"ip\" value=\"Reset blocked IP's\" name=\"type\" />\n";
+    echo "<input title=\"This will clean your matched file\" type=\"submit\" label=\"ip\" value=\"Reset rewrite rules\" name=\"type\" />\n";
+       echo "</form>\n";
+       // if user asked for a reset, do it now
+    if (stristr(postVar("type"),"reset")) {
+        echo "restting file ...";
+        pbl_resetfile($type);
+    }
+       echo "</div>\n";
+} // pbl_htaccesspage()
+
+function pbl_resetfile($type){
+    global $pblmessage;
+    switch ($type) {
+        case 'log':
+            $filename = __WEBLOG_ROOT.__EXT."/settings/blacklist.log";
+            break;
+        case 'ip':
+            $filename  = __WEBLOG_ROOT.__EXT."/settings/blockip.pbl";
+            break;
+        case 'rules':
+            $filename  = __WEBLOG_ROOT.__EXT."/settings/matched.pbl";
+            break;
+    }
+       if(file_exists($filename))      {
+        $fp = fopen($filename, "w");
+       fwrite($fp, "");
+           fclose($fp);
+       }
+}
+
+function pbl_test () {
+    // test's user input, no loggin.
+       global $pblmessage;
+       if(isset($_GET["expression"]))  {
+               if(getVar("expression") != "")  {
+            $pblmessage = "Your expression: <br />".htmlspecialchars(getVar("expression"), ENT_QUOTES);
+            $return = pbl_checkforspam(getVar("expression"),false,0,false);
+
+            if (! $return == "" ) {
+                $pblmessage .= "<br />matched rule: <strong>".$return."</strong>";
+            } else {
+                $pblmessage .= "<br /> did not match any rule.";
+            }
+        }
+    }
+}
+
+function pbl_testpage () {
+    // shows user testpage ...
+       global $pblmessage;
+       if(strlen($pblmessage) > 0)  {
+               echo "<div class=\"pblmessage\">$pblmessage</div>\n";
+       }
+       echo "<div class=\"pbform\" style=\"margin-left:10px;\">\n";
+       echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
+       echo "<input type=\"hidden\" name=\"page\" value=\"test\" />\n";
+    echo "<textarea class=\"pbltextinput\" cols=\"60\" rows=\"6\" name=\"expression\" ></textarea><br />";
+       echo "<input type=\"submit\" value=\"Test this\" />\n";
+       echo "</form>\n";
+       echo "</div>\n";
+}
+
+function pbl_spamsubmission_form()  {
+               // form 
+               echo "<form action=\"".serverVar('PHP_SELF')."?page=spamsubmission&action=send\" method=\"post\">\n";
+
+               // table
+               echo "<table>\n";
+               echo "<tr>\n";
+               echo "<th>Report Spam</th>\n";
+               echo "</tr>\n";
+
+               echo "<tr>\n";
+               echo "<td><textarea name=\"url\" rows=\"6\" cols=\"60\"></textarea></td>\n";
+               echo "</tr>\n";
+
+               echo '<tr><td><div align="right"><input type="submit" name="submit" value="submit" /></div></td></tr>';
+       
+               echo "</table>\n";
+               echo "</form>\n";
+}
+
+?>
diff --git a/trunk/NP_Blacklist/blacklist/blocked.txt b/trunk/NP_Blacklist/blacklist/blocked.txt
new file mode 100644 (file)
index 0000000..c98424a
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html>
+<head>
+<meta name="robots" content="noindex,nofollow" />
+<meta name="robots" content="noarchive" />
+<meta http-equiv="Pragma" content="no-cache" />
+<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
+<meta http-equiv="Expires" content="-1" />
+<title>403 Forbidden</title>
+</head>
+<body>
+<h1>Forbidden</h1>
+<p>You don't have permission to access on this server.</p>
+</body>
+</html>
diff --git a/trunk/NP_Blacklist/blacklist/cache/readme.txt b/trunk/NP_Blacklist/blacklist/cache/readme.txt
new file mode 100644 (file)
index 0000000..361b7d5
--- /dev/null
@@ -0,0 +1 @@
+cachedir
diff --git a/trunk/NP_Blacklist/blacklist/cache_eaccelerator.php b/trunk/NP_Blacklist/blacklist/cache_eaccelerator.php
new file mode 100644 (file)
index 0000000..4afe361
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+/**
+* cache_eaccelerator.php ($Revision: 1.1 $)
+* 
+* by hsur ( http://blog.cles.jp/np_cles )
+* $Id: cache_eaccelerator.php,v 1.1 2006-09-30 09:48:05 hsur Exp $
+*/
+
+function pbl_ipcache_write(){
+       $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
+       if( ! rand(0,19) ) pbl_ipcache_gc();
+       
+       // eAccelerator Cache
+       eaccelerator_lock($key);
+       eaccelerator_put($key, true, NP_BLACKLIST_CACHE_LIFE);
+       eaccelerator_unlock($key);
+}
+
+function pbl_ipcache_read(){
+       $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
+       // eAccelerator Cache
+       if( eaccelerator_get($key) ){
+               return true;    
+       }
+       return false;
+}
+
+function pbl_ipcache_gc(){
+       $now = time();
+       $lastGc = -1;
+       
+       // eAccelerator Cache
+       $lastGc = intval(eaccelerator_get(NP_BLACKLIST_CACHE_GC_TIMESTAMP));
+       if($now - $lastGc > NP_BLACKLIST_CACHE_GC_INTERVAL){
+               eaccelerator_gc();
+               $lastGc = $now;
+               eaccelerator_lock(NP_BLACKLIST_CACHE_GC_TIMESTAMP);
+               eaccelerator_put(NP_BLACKLIST_CACHE_GC_TIMESTAMP, $lastGc, NP_BLACKLIST_CACHE_GC_TIMESTAMP_LIFE);
+               eaccelerator_unlock(NP_BLACKLIST_CACHE_GC_TIMESTAMP);
+       }
+       
+       return $lastGc;
+}
+?>
\ No newline at end of file
diff --git a/trunk/NP_Blacklist/blacklist/cache_file.php b/trunk/NP_Blacklist/blacklist/cache_file.php
new file mode 100644 (file)
index 0000000..e66734f
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+/**
+* cache_file.php ($Revision: 1.1 $)
+* 
+* by hsur ( http://blog.cles.jp/np_cles )
+* $Id: cache_file.php,v 1.1 2006-09-30 09:48:05 hsur Exp $
+*/
+
+function pbl_ipcache_write(){
+       $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
+       if( ! rand(0,19) ) pbl_ipcache_gc();
+       
+       // FileCache
+       $cacheFile = NP_BLACKLIST_CACHE_DIR.'/'.$key;
+       @touch($cacheFile) && @chmod($cacheFile, 0666);
+       // FileCache    
+}
+
+function pbl_ipcache_read(){
+       $key = sprintf("BL%u", ip2long(serverVar('REMOTE_ADDR')));
+       
+       // FileCache
+       $cacheFile = NP_BLACKLIST_CACHE_DIR.'/'.$key;
+       if( file_exists($cacheFile) ){ 
+               if( time() - filemtime($cacheFile) < NP_BLACKLIST_CACHE_LIFE ){
+                       return true;
+               }
+       }
+       return false;
+       // FileCache
+}
+
+function pbl_ipcache_gc(){
+       $now = time();
+       $lastGc = -1;
+       
+       // FileCache
+       $gcTimestampFile = NP_BLACKLIST_CACHE_DIR.'/'.NP_BLACKLIST_CACHE_GC_TIMESTAMP;
+       if(file_exists($gcTimestampFile)){
+               $lastGc = filemtime($gcTimestampFile);
+               if( $now - $lastGc > NP_BLACKLIST_CACHE_GC_INTERVAL ){
+                       $count = 0;
+                       pbl_log("GC started.");
+                       @touch($gcTimestampFile);
+                       foreach (glob(NP_BLACKLIST_CACHE_DIR.'/BL*', GLOB_NOSORT) as $filename) {       
+                               if($now - filemtime($filename) > NP_BLACKLIST_CACHE_LIFE){
+                                       @unlink($filename) && $count += 1;
+                               }
+                       }
+                       pbl_log("GC finished. ($count files deleted.)");
+               }
+       } else {
+               @touch($gcTimestampFile);
+       }
+       // FileCache
+       return $lastGc;
+}
+
+?>
\ No newline at end of file
diff --git a/trunk/NP_Blacklist/blacklist/help.html b/trunk/NP_Blacklist/blacklist/help.html
new file mode 100644 (file)
index 0000000..60298bf
--- /dev/null
@@ -0,0 +1,20 @@
+<h3>バージョン履歴</h3>
+
+<ul>
+       <li>Version 0.98 jp8: (2006/09/30)</li>
+       <li> [Changed] IPブロックが正常に動作していなかった不具合を修正</li>
+       <li> [Changed] ブロックの際に画面が真っ白になってしまう不具合を修正</li>
+       <li> [Changed] 英語のtypoを修正</li>
+       <li> [Added] 設定ファイルの上書きを防ぐため配布アーカイブに含まれる設定ファイルの名前を変更</li>
+       <li> [Added] インストール時に設定ファイルを自動生成を追加</li>
+       <li> [Added] DNSBLの応答をキャッシュするようにした</li>
+       <li> [Added] 正規表現利用の可否を選択可能にした</li>
+       <li> [Added] magic_quotes_gpc onの環境に対応した</li>
+</ul>
+
+<ul>
+       <li>Version 0.98 jp7: (2006/09/16)</li>
+       <li> [Changed] obsoleteなイベントを削除</li>
+       <li> [Changed] デフォルトの状態において、リンク付のコメントをブロックしてしまう不具合を修正</li>
+       <li> [Added] membermailの内容についてもチェックを行うようにした</li>
+</ul>
diff --git a/trunk/NP_Blacklist/blacklist/icons/i_edit.gif b/trunk/NP_Blacklist/blacklist/icons/i_edit.gif
new file mode 100644 (file)
index 0000000..2d81052
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/icons/i_edit.gif differ
diff --git a/trunk/NP_Blacklist/blacklist/icons/i_log.gif b/trunk/NP_Blacklist/blacklist/icons/i_log.gif
new file mode 100644 (file)
index 0000000..c273dd2
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/icons/i_log.gif differ
diff --git a/trunk/NP_Blacklist/blacklist/icons/i_prefs.gif b/trunk/NP_Blacklist/blacklist/icons/i_prefs.gif
new file mode 100644 (file)
index 0000000..e62d758
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/icons/i_prefs.gif differ
diff --git a/trunk/NP_Blacklist/blacklist/index.php b/trunk/NP_Blacklist/blacklist/index.php
new file mode 100644 (file)
index 0000000..a3dee06
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+    require_once("blacklist_lib.php");
+
+    //
+    // Nucleus Admin section;
+    // Created by Xiffy
+    //
+       $strRel = '../../../';
+       include($strRel . 'config.php');
+
+       include($DIR_LIBS . 'PLUGINADMIN.php');
+
+       if ($blogid) {$isblogadmin = $member->isBlogAdmin($blogid);}
+       else $isblogadmin = 0;
+
+       if (!($member->isAdmin() || $isblogadmin)) {
+               $oPluginAdmin = new PluginAdmin('Blacklist');
+               $pbl_config = array();
+               $oPluginAdmin->start();
+               echo "<p>"._ERROR_DISALLOWED."</p>";
+               $oPluginAdmin->end();
+               exit;
+       }
+
+
+       if (isset($_GET['page'])) {$action = $_GET['page'];}
+       if (isset($_POST['page'])) {$action = $_POST['page'];}
+
+       // Okay; we are allowed. let's go
+       // create the admin area page
+       $oPluginAdmin = new PluginAdmin('Blacklist');
+       $oPluginAdmin->start();
+       // get the plugin options; stored in the DB
+    $pbl_config['enabled']       = $oPluginAdmin->plugin->getOption('enabled');
+    $pbl_config['redirect']      = $oPluginAdmin->plugin->getOption('redirect');
+    //$pbl_config['update']        = $oPluginAdmin->plugin->getOption('update');
+    $pbl_config['referrerblock'] = $oPluginAdmin->plugin->getOption('referrerblock');
+    $pbl_config['ipblock']       = $oPluginAdmin->plugin->getOption('ipblock');
+    $pbl_config['ipthreshold']   = $oPluginAdmin->plugin->getOption('ipthreshold');
+    $pbl_config['BulkfeedsKey']   = $oPluginAdmin->plugin->getOption('BulkfeedsKey');
+    $pbl_config['SkipNameResolve']   = $oPluginAdmin->plugin->getOption('SkipNameResolve');
+
+       function getPluginOption($name) {
+           global $pbl_config;
+           return $pbl_config[$name];
+       }
+       function getPlugid() {
+           global $oPluginAdmin;
+           return $oPluginAdmin->plugin->plugid;
+       }
+
+       pbl_nucmenu();
+       if ($action == 'blacklist') {
+           pbl_blacklisteditor();
+       echo "</div>";
+//     } elseif ($action == 'getblacklist') {
+//       if (pbl_updateblacklist($pbl_config['update'],true))  {
+//             $pblmessage = "Blacklist succesfully updated!";
+//         pbl_blacklisteditor();
+//             echo "</div>";
+//     }
+       } elseif ($action == 'addpersonal') {
+       pbl_addpersonal();
+       pbl_blacklisteditor();
+       echo "</div>";
+       } elseif ($action == 'deleteexpression') {
+       pbl_deleteexpression();
+           echo "<div class=\"pblmessage\">Expression deleted from personal blacklist.</div>\n";
+       pbl_blacklisteditor();
+    } elseif ($action == 'log') {
+       echo "<h2 style=\"text-align:left\"><span style=\"margin-left:10px;\">Blacklist: Blacklist Log</span></h2>";
+           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";
+       pbl_logtable();
+    } elseif ($action == 'resetlog') {
+       pbl_resetfile('log');
+       echo "<h2> logfile has been reset</h2>";
+       echo "<h2 style=\"text-align:left\"><span style=\"margin-left:10px;\">Blacklist: Blacklist Log</span></h2>";
+           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";
+       pbl_logtable();
+    } elseif ($action == 'testpage') {
+       echo "<h2>Test if an expression is considered spam</h2>";
+        pbl_testpage();
+    } elseif ($action == 'test') {
+       echo "<h2>Test if an expression is considered spam</h2>";
+        pbl_test();
+        pbl_testpage();
+    } elseif ($action == 'showipblock') {
+        echo "<h2>These ip-addresses are blocked</h2>";
+        pbl_showipblock();
+    } elseif ($action == 'addip') {
+        pbl_addipblock();
+        echo "<h2>These ip-addresses are blocked</h2>";
+        pbl_showipblock();
+    } elseif  ($action == 'deleteipblock') {
+       pbl_deleteipblock();
+           echo "<div class=\"pblmessage\">Block deleted</div>\n";
+        echo "<h2>These ip-addresses are blocked</h2>";
+        pbl_showipblock();
+    } elseif ($action == 'htaccess') {
+        echo "<h2>Here you can generate .htaccess snippets</h2>";
+        pbl_htaccesspage();
+    } elseif ($action == 'spamsubmission') {
+               if( $_REQUEST['action'] == 'send' && !empty($_REQUEST['url']) ){
+                       $result = $oPluginAdmin->plugin->submitSpamToBulkfeeds($_REQUEST['url']);
+
+                       echo "<h2>Spam submission</h2>";
+                       echo "<h3>result</h3>";
+                       echo "<pre>" . htmlspecialchars($result) . "</pre>";
+                                               
+               } else {
+                       echo "<h2>Spam submission</h2>";
+                       pbl_spamsubmission_form();
+               }
+    }
+    echo "<br />";
+       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/>";
+
+       $oPluginAdmin->end();
+
+?>
diff --git a/trunk/NP_Blacklist/blacklist/ipblock.txt b/trunk/NP_Blacklist/blacklist/ipblock.txt
new file mode 100644 (file)
index 0000000..01bcf43
--- /dev/null
@@ -0,0 +1,12 @@
+<h1>Warning; possible hijacked computer</h1>
+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.
+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.
+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.
+Instead we show you this message until you requested the ban to be lifted.
+You can contact us at <emailaddres site owner>.
+Include this ip-number in the message
+___message
+IP_ADDRESS
+Please remove my ip ban,
+I've done a complete virus-check and removed all found spyware from my pc.
+___message
\ No newline at end of file
diff --git a/trunk/NP_Blacklist/blacklist/pblbutton.png b/trunk/NP_Blacklist/blacklist/pblbutton.png
new file mode 100644 (file)
index 0000000..590eb31
Binary files /dev/null and b/trunk/NP_Blacklist/blacklist/pblbutton.png differ
diff --git a/trunk/NP_Blacklist/blacklist/settings/personal_blacklist.pbl.dist b/trunk/NP_Blacklist/blacklist/settings/personal_blacklist.pbl.dist
new file mode 100644 (file)
index 0000000..a825a07
--- /dev/null
@@ -0,0 +1,19 @@
+porn
+texas
+teen
+viagra
+discount
+cheap
+sex
+xxx
+bestiality
+finance
+free
+levitra
+penis
+poker
+roulette
+casino
+insurance
+slot
+href=
\ No newline at end of file