<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michiel Bijland &#187; Django</title>
	<atom:link href="http://michiel.bijland.net/category/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://michiel.bijland.net</link>
	<description></description>
	<lastBuildDate>Fri, 06 Nov 2009 08:41:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using django&#8217;s common middleware against&#160;spam</title>
		<link>http://michiel.bijland.net/2009/08/19/using-djangos-common-middleware-against-spam/</link>
		<comments>http://michiel.bijland.net/2009/08/19/using-djangos-common-middleware-against-spam/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:44:26 +0000</pubDate>
		<dc:creator>Michiel Bijland</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[anti-spam]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://michiel.bijland.net/?p=149</guid>
		<description><![CDATA[Django&#8217;s common middleware is active on most Django sites, and has very nice function to block request based on their user agents. By default this will be empty and not doing much, until a offender comes a long and we add it on after thought, wouldn&#8217;t be nice to have a default list that blocks [...]]]></description>
			<content:encoded><![CDATA[<p>Django&#8217;s common middleware is active on most Django sites, and has very nice function to block request based on their user agents. By default this will be empty and not doing much, until a offender comes a long and we add it on after thought, wouldn&#8217;t be nice to have a default list that blocks known offenders from the start.<br />
Bad Behaviour a anti-spam script in php has a nice blacklist and has proven his capabilities more then once on this site and others, so let&#8217;s get that list into Django.</p>
<p>The following code should be in your settings.py&nbsp;file:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
regex_list = <span style="color: black;">&#40;</span>
    <span style="color: #483d8b;">'; Widows '</span>,
    <span style="color: #483d8b;">'a href='</span>,
    <span style="color: #483d8b;">'Bad Behavior Test'</span>,
    <span style="color: #483d8b;">'compatible ; MSIE'</span>,
    <span style="color: #483d8b;">'compatible-'</span>,
    <span style="color: #483d8b;">'DTS Agent'</span>,
    <span style="color: #483d8b;">'Email Extractor'</span>,
    <span style="color: #483d8b;">'Gecko/25'</span>,
    <span style="color: #483d8b;">'grub-client'</span>,
    <span style="color: #483d8b;">'hanzoweb'</span>,
    <span style="color: #483d8b;">'Indy Library'</span>,
    <span style="color: #483d8b;">'larbin@unspecified'</span>,
    <span style="color: #483d8b;">'Murzillo compatible'</span>,
    <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\\</span>.NET CLR 1<span style="color: #000099; font-weight: bold;">\\</span>)'</span>,
    <span style="color: #483d8b;">'POE-Component-Client'</span>,
    <span style="color: #483d8b;">'Turing Machine'</span>,
    <span style="color: #483d8b;">'User-agent: '</span>,
    <span style="color: #483d8b;">'WebaltBot'</span>,
    <span style="color: #483d8b;">'WISEbot'</span>,
    <span style="color: #483d8b;">'WISEnutbot'</span>,
    <span style="color: #483d8b;">'Windows NT 4<span style="color: #000099; font-weight: bold;">\\</span>.0;<span style="color: #000099; font-weight: bold;">\\</span>)'</span>,
    <span style="color: #483d8b;">'Windows NT 5<span style="color: #000099; font-weight: bold;">\\</span>.0;<span style="color: #000099; font-weight: bold;">\\</span>)'</span>,
    <span style="color: #483d8b;">'Windows NT 5<span style="color: #000099; font-weight: bold;">\\</span>.1;<span style="color: #000099; font-weight: bold;">\\</span>)'</span>,
    <span style="color: #483d8b;">'Windows XP 5'</span>,
    <span style="color: #483d8b;">'WordPress/4<span style="color: #000099; font-weight: bold;">\\</span>.01'</span>,
    <span style="color: #483d8b;">'^
&nbsp;
As you can see, we compile a long regular expression rather then creating 60+ entries in the DISALLOWED_USER_AGENTS, this way you can add your own regular expressions and comment, instead of adding it to the already large list.
&nbsp;
Hope this will help some other Djangonauts.</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://michiel.bijland.net/2009/08/19/using-djangos-common-middleware-against-spam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
