[pLog-svn] r1204 - in plugins/trunk: . dnsantispam dnsantispam/class dnsantispam/class/action dnsantispam/class/security dnsantispam/class/view dnsantispam/locale dnsantispam/templates

mark at devel.plogworld.net mark at devel.plogworld.net
Thu Feb 24 17:21:00 GMT 2005


Author: mark
Date: 2005-02-24 17:20:59 +0000 (Thu, 24 Feb 2005)
New Revision: 1204

Added:
   plugins/trunk/dnsantispam/
   plugins/trunk/dnsantispam/class/
   plugins/trunk/dnsantispam/class/action/
   plugins/trunk/dnsantispam/class/action/plugindnsantispamconfigaction.class.php
   plugins/trunk/dnsantispam/class/action/plugindnsantispamupdateconfigaction.class.php
   plugins/trunk/dnsantispam/class/security/
   plugins/trunk/dnsantispam/class/security/dnsantispamfilter.class.php
   plugins/trunk/dnsantispam/class/view/
   plugins/trunk/dnsantispam/class/view/plugindnsantispamconfigview.class.php
   plugins/trunk/dnsantispam/locale/
   plugins/trunk/dnsantispam/locale/locale_en_UK.php
   plugins/trunk/dnsantispam/locale/locale_zh_TW.php
   plugins/trunk/dnsantispam/plugindnsantispam.class.php
   plugins/trunk/dnsantispam/templates/
   plugins/trunk/dnsantispam/templates/dnsantispam.template
Log:
Another Anti-Spam Measure. http://weblog.sinteur.com/?p=8106

Added: plugins/trunk/dnsantispam/class/action/plugindnsantispamconfigaction.class.php
===================================================================
--- plugins/trunk/dnsantispam/class/action/plugindnsantispamconfigaction.class.php	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/class/action/plugindnsantispamconfigaction.class.php	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,26 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/dnsantispam/class/view/plugindnsantispamconfigview.class.php" );
+
+	/**
+	 * shows a form with the current configuration
+	 */
+	class PluginDNSAntiSpamConfigAction extends AdminAction
+	{
+		
+		function PluginDNSAntiSpamConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function perform()
+		{
+            $this->_view = new PluginDNSAntiSpamConfigView( $this->_blogInfo );
+			
+			$this->setCommonData();
+			
+			return true;
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/dnsantispam/class/action/plugindnsantispamupdateconfigaction.class.php
===================================================================
--- plugins/trunk/dnsantispam/class/action/plugindnsantispamupdateconfigaction.class.php	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/class/action/plugindnsantispamupdateconfigaction.class.php	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,58 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/dnsantispam/class/view/plugindnsantispamconfigview.class.php" );
+		
+	/**
+	 * updates the plugin configuration
+	 */
+	class PluginDNSAntiSpamUpdateConfigAction extends AdminAction
+	{
+		var $_pluginEnabled;
+		
+		function PluginDNSAntiSpamUpdateConfigAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function validate()
+		{
+            $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+            $this->_pluginEnabled = ($this->_pluginEnabled != "" );			
+			
+			return true;
+		}
+		        
+		function perform()
+		{
+            // update the plugin configurations to blog setting
+			$blogSettings = $this->_blogInfo->getSettings();
+            $blogSettings->setValue( "plugin_dnsantispam_enabled", $this->_pluginEnabled );
+            $this->_blogInfo->setSettings( $blogSettings ); 
+		
+			// save the blogs settings
+			$blogs = new Blogs();
+            if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+                $this->_view = new PluginDNSAntiSpamConfigView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
+                $this->setCommonData();
+
+                return false;                       
+            }
+			
+			// if everything went ok...
+            $this->_blogInfo->setSettings( $blogSettings );
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+			
+			$this->_view = new PluginDNSAntiSpamConfigView( $this->_blogInfo );
+			$this->_view->setSuccessMessage( $this->_locale->tr("dnsantispam_settings_saved_ok"));			
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());					
+            
+            return true;		
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/dnsantispam/class/security/dnsantispamfilter.class.php
===================================================================
--- plugins/trunk/dnsantispam/class/security/dnsantispamfilter.class.php	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/class/security/dnsantispamfilter.class.php	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,164 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/security/pipelinefilter.class.php" );
+    include_once( PLOG_CLASS_PATH."class/net/client.class.php" );	
+
+    // custom error code that will be returned to the pipeline whenever an
+    // error is found... Be careful so as to not to have two different modules
+    // use the same code!!
+    define( "DNS_ANTISPAM_MATCH_FOUND", 600 );
+
+	class DNSAntiSpamFilter extends PipelineFilter 
+	{
+
+    	function DNSAntiSpamFilter( $pipelineRequest )
+        {
+        	$this->PipelineFilter( $pipelineRequest );
+        }
+
+        function filter()
+        {
+        	// get some info
+            $blogInfo = $this->_pipelineRequest->getBlogInfo();
+            $request  = $this->_pipelineRequest->getHttpRequest();
+
+        	// check if this section has been enabled or disabled
+            $blogSettings = $blogInfo->getSettings();
+		    $pluginEnabled = $blogSettings->getValue( "plugin_dnsantispam_enabled" );
+            if( !$pluginEnabled) {
+            	// if not, nothing to do here...
+                //_debug("ip address filter not enabled! quitting...<br/>");
+            	return new PipelineResult();
+            }
+
+            // we only have to filter the contents if the user is posting a comment
+            // so there's no point in doing anything else if that's not the case
+            if( $request->getValue( "op" ) != "AddComment" ) {
+            	$result = new PipelineResult();
+                return $result;
+            }
+
+            // text and topic of the comment
+            $commentText = $request->getValue( "commentText" );
+            $commentTopic = $request->getValue( "commentTopic" );
+            $userName = $request->getValue( "userName" );
+            $userEmail = $request->getValue( "userEmail" );
+            $userUrl = $request->getValue( "userUrl" );
+            $clientIp = Client::getIp();
+            $locale = $blogInfo->getLocale();            
+                        
+          	if( !$this->checkClientIP( $clientIp ) ) {
+               	// if there is a match, we can quit and reject this request
+                $result = new PipelineResult( false, DNS_ANTISPAM_MATCH_FOUND, $locale->tr("error_dnsantispam_client_ip_banned") );
+                return $result;
+            }
+
+          	if( !$this->checkCommentText( $commentTopic ) ) {
+               	// if there is a match, we can quit and reject this request
+                $result = new PipelineResult( false, DNS_ANTISPAM_MATCH_FOUND, $locale->tr("error_dnsantispam_comment_topic_banned") );
+                return $result;
+            }
+
+          	if( !$this->checkCommentText( $commentText ) ) {
+               	// if there is a match, we can quit and reject this request
+                $result = new PipelineResult( false, DNS_ANTISPAM_MATCH_FOUND, $locale->tr("error_dnsantispam_comment_text_banned") );
+                return $result;
+            }
+
+          	if( !$this->checkCommentText( $userName ) ) {
+               	// if there is a match, we can quit and reject this request
+                $result = new PipelineResult( false, DNS_ANTISPAM_MATCH_FOUND, $locale->tr("error_dnsantispam_user_name_banned") );
+                return $result;
+            }                        
+            
+          	if( !$this->checkCommentURL( $userUrl ) ) {
+               	// if there is a match, we can quit and reject this request
+                $result = new PipelineResult( false, DNS_ANTISPAM_MATCH_FOUND, $locale->tr("error_dnsantispam_comment_url_banned") );
+                return $result;
+            }
+
+            // if everything went fine, we can say so by returning
+            // a positive PipelineResult object
+            $result = new PipelineResult( true );
+            
+            return $result;
+        }
+
+        // The following function comese from John Sinteur
+        /*
+        Plugin Name: Block-lists anti-spam measures
+        Version: 1.5.1
+        Plugin URI: http://weblog.sinteur.com/index.php?p=8106
+        Description: check if a comment poster is on an open proxy list, and check if the content contains known spammer domains
+        Author: John Sinteur, with a big thank you to io_error!
+        Author URI: http://weblog.sinteur.com/
+        */
+
+        function checkClientIP( $spammer_ip )
+        {
+            $rev = array_reverse(explode('.', $spammer_ip));
+        
+            $lookup = implode('.', $rev) . '.' . 'l1.spews.dnsbl.sorbs.net.';
+        
+            if ($lookup != gethostbyname($lookup)) {
+                return false;
+            }
+            $lookup = implode('.', $rev) . '.' . 'sbl-xbl.spamhaus.org.';
+            if ($lookup != gethostbyname($lookup)) {
+                return false;
+            }
+            $lookup = implode('.', $rev) . '.' . 'list.dsbl.org.';
+            if ($lookup != gethostbyname($lookup)) {
+                return false;
+            }
+        
+            return true ;
+        }
+        
+        // for a full explanation, see http://www.surbl.org 
+        // summary: blocks comment if it contains an url that's on a known spammers list.
+        function checkCommentText ( $comment_text )
+        {
+            //get site names found in body of comment.
+            $regex_url   = "/(www.)([^\/\"<\s]*)/im";
+            $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],"\\");
+                $test .= $domain_to_test;
+                if (strlen($domain_to_test) > 3)
+                {
+                    $domain_to_test = $domain_to_test . ".multi.surbl.org.";
+                    if( gethostbyname($domain_to_test) != $domain_to_test ) {
+                        return false;
+                    }
+                }
+            }
+            return true;
+        }
+
+        // for a full explanation, see http://www.surbl.org 
+        // summary: blocks comment if it contains an url that's on a known spammers list.
+        function checkCommentURL ( $comment_url )
+        {
+            $pieces = explode('/',$comment_url);
+            for( $cnt=0; $cnt < count($pieces); $cnt++ ) {
+                $short_url = $pieces[$cnt];
+        
+                if ($short_url != 'http')
+                {
+                    $short_url = str_replace("www.", "", "$short_url");
+                    if (strlen($short_url) > 3)
+                    {
+                        $domain_to_test = $short_url . ".multi.surbl.org.";
+                        if( gethostbyname($domain_to_test) != $domain_to_test ) {
+                            return false;
+                        }
+                    }
+                }
+            }
+            return true;
+        }        
+    }
+?>

Added: plugins/trunk/dnsantispam/class/view/plugindnsantispamconfigview.class.php
===================================================================
--- plugins/trunk/dnsantispam/class/view/plugindnsantispamconfigview.class.php	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/class/view/plugindnsantispamconfigview.class.php	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,28 @@
+<?php
+	
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+	/**
+	 * implements the main view of the feed reader plugin
+	 */
+	class PluginDNSAntiSpamConfigView extends AdminPluginTemplatedView
+	{
+
+		function PluginDNSAntiSpamConfigView( $blogInfo )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "dnsantispam", "dnsantispam" );
+		}
+		
+		function render()
+		{
+			// load some configuration settings
+			$blogSettings = $this->_blogInfo->getSettings();
+			$pluginEnabled = $blogSettings->getValue( "plugin_dnsantispam_enabled" );
+			
+			// create a view and export the settings to the template
+			$this->setValue( "pluginEnabled", $pluginEnabled );		
+			
+			parent::render();
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/dnsantispam/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/dnsantispam/locale/locale_en_UK.php	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/locale/locale_en_UK.php	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,12 @@
+<?php
+$messages["manageAntiSpamPlugins"] = "Anti Spam Management";
+$messages["DNSAntiSpam"] = "DNS Anti Spam";
+
+$messages["dnsantispam_plugin_enabled"] = "Enable this plugin";
+$messages["dnsantispam_plugin"] = "DNS Anti Spam Plugin";
+
+$messages["dnsantispam_settings_saved_ok"] = "DNS Anti Spam settings saved successfully!";
+
+$messages["label_configuration"] = "Configuration";
+$messages["label_enable"] = "Enable";
+?>
\ No newline at end of file

Added: plugins/trunk/dnsantispam/locale/locale_zh_TW.php
===================================================================
--- plugins/trunk/dnsantispam/locale/locale_zh_TW.php	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/locale/locale_zh_TW.php	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,12 @@
+<?php
+$messages["manageAntiSpamPlugins"] = "防制垃圾干擾管理";
+$messages["DNSAntiSpam"] = "迴響網址阻絕設定";
+
+$messages["dnsantispam_plugin_enabled"] = "啟動外掛程式";
+$messages["dnsantispam_plugin"] = "迴響網址阻絕外掛程式";
+
+$messages["dnsantispam_settings_saved_ok"] = "迴響網址阻絕設定儲存成功。";
+
+$messages["label_configuration"] = "設定";
+$messages["label_enable"] = "啟動";
+?>
\ No newline at end of file

Added: plugins/trunk/dnsantispam/plugindnsantispam.class.php
===================================================================
--- plugins/trunk/dnsantispam/plugindnsantispam.class.php	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/plugindnsantispam.class.php	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,47 @@
+<?php
+	include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+	include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/dnsantispam/class/security/dnsantispamfilter.class.php" );
+
+	class PluginDNSAntiSpam extends PluginBase
+	{
+		var $pluginEnabled;
+		
+		function PluginDNSAntiSpam()
+		{
+			$this->PluginBase();
+
+			$this->id      = "dnsantispam";
+			$this->author  = 'Original build by <a href="http://weblog.sinteur.com/">John Sinteur</a> for WordPress, Ported to pLog by Mark Wu';
+			$this->desc    = "Check if a comment poster is on an open proxy list, and check if the content contains known spammer domains.";
+
+			$this->locales = Array( "en_UK" , "zh_TW" );
+
+			$this->init();
+		}
+
+		function init()
+		{
+            $this->registerFilter( "DNSAntiSpamFilter" );
+
+            $this->registerAdminAction( "dnsantispam", "PluginDNSAntiSpamConfigAction" );
+			$this->registerAdminAction( "updateDNSAntiSpamConfig", "PluginDNSAntiSpamUpdateConfigAction" );
+			
+			$menu =& Menu::getMenu();
+			if( !$menu->entryExists( "/menu/controlCenter/manageAntiSpamPlugins" ))						
+				$this->addMenuEntry( "/menu/controlCenter", "manageAntiSpamPlugins", "", "", true, false );			
+            $this->addMenuEntry( "/menu/controlCenter/manageAntiSpamPlugins", "DNSAntiSpam", "?op=dnsantispam", "" );            
+		}
+
+		function register()
+		{
+		    $blogSettings = $this->blogInfo->getSettings();
+			$this->pluginEnabled = $blogSettings->getValue( "plugin_dnsantispam_enabled" );
+		}
+
+	    function isEnabled()
+	    {
+	        return $this->pluginEnabled;
+	    }
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/dnsantispam/templates/dnsantispam.template
===================================================================
--- plugins/trunk/dnsantispam/templates/dnsantispam.template	2005-02-24 15:21:56 UTC (rev 1203)
+++ plugins/trunk/dnsantispam/templates/dnsantispam.template	2005-02-24 17:20:59 UTC (rev 1204)
@@ -0,0 +1,24 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=DNSAntiSpam title=$locale->tr("dnsantispam_plugin")}
+<form name="nofollowPluginConfig" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("label_configuration")}</legend>  
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}   
+  <div class="field">
+   <label for="pluginEnabled">{$locale->tr("label_enable")}</label>
+   <div class="formHelp">   
+    <input class="checkbox" type="checkbox" name="pluginEnabled" id="pluginEnabled" {if $pluginEnabled} checked="checked" {/if} value="1" />{$locale->tr("dnsantispam_plugin_enabled")}
+   </div>
+  </div>
+  
+ </fieldset>  
+
+ <div class="buttons">
+  <input type="hidden" name="op" value="updateDNSAntiSpamConfig" />
+  <input type="reset" name="{$locale->tr("reset")}" />    
+  <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file




More information about the pLog-svn mailing list