<?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>durdle.com &#187; Development</title>
	<atom:link href="http://durdle.com/archives/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://durdle.com</link>
	<description></description>
	<lastBuildDate>Mon, 23 Aug 2010 11:25:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Run YOURLS on IIS 7</title>
		<link>http://durdle.com/archives/2010/08/23/run-yourls-on-iis-7/</link>
		<comments>http://durdle.com/archives/2010/08/23/run-yourls-on-iis-7/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 11:23:55 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[iis7]]></category>
		<category><![CDATA[urlrewrite]]></category>
		<category><![CDATA[yourls]]></category>

		<guid isPermaLink="false">http://durdle.com/?p=845</guid>
		<description><![CDATA[If you&#8217;re running YOURLS on an IIS 7 box you&#8217;ll need the correct settings in your web.config to perform the URL Rewriting.  An example web.config with the correct settings is below.  
Note the security section which disables some paranoid protection IIS has switched on by default.  If your server doesn&#8217;t allow double...]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re running <a href="http://yourls.org/">YOURLS</a> on an IIS 7 box you&#8217;ll need the correct settings in your web.config to perform the URL Rewriting.  An example web.config with the correct settings is below.  <span id="more-845"></span></p>
<p>Note the security section which disables some paranoid protection IIS has switched on by default.  If your server doesn&#8217;t allow double escaping of request strings, the YOURLS links with a + in them don&#8217;t work.  This breaks the admin interface and the stats reporting pages.</p>
<p>The rest of the web.config is standard stuff to fix a non-canonical hostname, and make sure the IDs are rewritten to the right pages:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;requestFiltering</span> <span style="color: #000066;">allowDoubleEscaping</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Canonical Host Name&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;(.*)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{HTTP_HOST}&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^domain\.com$&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Redirect&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://domain.com/{R:1}&quot;</span> <span style="color: #000066;">redirectType</span>=<span style="color: #ff0000;">&quot;Permanent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YOURLS 1&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;^([0-9A-Za-z]+)/?$&quot;</span> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conditions</span> <span style="color: #000066;">logicalGrouping</span>=<span style="color: #ff0000;">&quot;MatchAll&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsFile&quot;</span> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsDirectory&quot;</span> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Rewrite&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;/yourls-go.php?id={R:1}&quot;</span> <span style="color: #000066;">appendQueryString</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YOURLS 2&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;^([0-9A-Za-z]+)\+/?$&quot;</span> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Rewrite&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;/yourls-infos.php?id={R:1}&quot;</span> <span style="color: #000066;">appendQueryString</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YOURLS 3&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;^([0-9A-Za-z]+)\+all/?$&quot;</span> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Rewrite&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;/yourls-infos.php?id={R:1}&amp;amp;all=1&quot;</span> <span style="color: #000066;">appendQueryString</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2010/08/23/run-yourls-on-iis-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RegExCatchAll Transport Agent for Exchange 2007/2010</title>
		<link>http://durdle.com/archives/2010/05/29/regexcatchall/</link>
		<comments>http://durdle.com/archives/2010/05/29/regexcatchall/#comments</comments>
		<pubDate>Sat, 29 May 2010 15:31:16 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[catchall]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[email suffix]]></category>
		<category><![CDATA[exchange]]></category>
		<category><![CDATA[exchange 2007]]></category>
		<category><![CDATA[exchange 2010]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[transport agent]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/?p=777</guid>
		<description><![CDATA[How moving email services to an Exchange Server revealed email suffix matching as a missing feature, and how to implement that feature using a Transport Agent.]]></description>
			<content:encoded><![CDATA[<p>For a number of years now I have been doing two things with email:</p>
<p>1) I run my own <a href="http://www.microsoft.com/exchange/">Exchange Server</a>.  <a href="/wp-content/uploads/Exchange2010Logo.png" rel="lightbox[818]"><img class="alignleft  size-full wp-image-805" title="Exchange 2010 Logo" src="/wp-content/uploads/Exchange2010Logo.png" alt="Exchange 2010 Logo" width="150" height="150" /></a>It provides <a href="http://technet.microsoft.com/en-us/exchange/bb288524.aspx">ActiveSync</a>, <a href="http://www.microsoft.com/exchange/code/OWA/index.html">Outlook Web Access</a>, and <a href="http://office.microsoft.com/en-us/outlook/hp101024441033.aspx">Outlook Anywhere</a> for my company’s email domains and my personal durdle.com domain.</p>
<p>2) I provide email addresses at durdle.com for family members (and a few people who just happen to share the family name).</p>
<p>&nbsp;<br />
&nbsp;</p>
<p>Historically all those family emails have been maintained by <a href="http://www.gradwell.com/">Gradwell</a> without going near my Exchange Server.  The durdle.com <a href="http://en.wikipedia.org/wiki/MX_record">MX records</a> in DNS pointed to Gradwell’s servers for mail delivery and I had a forwarder at Gradwell that would redirect my – and only my – messages to the Exchange Server.  For a number of reasons I needed to change this so that all email is delivered via my Exchange Server.  I made this change yesterday, discovering one problem in the process.</p>
<h5>Email Suffixes</h5>
<p>Gradwell’s mail server supports email suffix matching.  If you have a <a href="http://mail.google.com/">GMail</a> account you may be familiar with the approach.  Say you have an email <a href="mailto:john@gmail.com">john@gmail.com</a>.  Gmail will actually deliver mail to <a href="mailto:john+anything@gmail.com">john+anything@gmail.com</a>; you can add any suffix you like after the + and GMail will still deliver it to your inbox.  Gradwell support this by allowing you to place a period after the local part so you can use <a href="mailto:john.anything@example.com">john.anything@example.com</a>.  You don’t have to create these email addresses anywhere – you can just start using it and the mail server will make sure it gets to you.</p>
<p>This is fantastically useful because it means that when a website asks for your email address you can give out a custom throwaway email just for that site.  So when you sign up at DodgyCo.com, you give them the email <a href="mailto:john.dodgyco@example.com">john.dodgyco@example.com</a>.  If you ever receive spam because DodgyCo sold your email address you’ll know a) who sold you out, and b) which email address to add to your spam filter.</p>
<h5>Exchange Server</h5>
<p>Enter Microsoft Exchange Server.  I’m currently running the 2010 edition, but the problem I’m about to describe (and solve!) exists in every recent version.  Exchange Server doesn’t support email suffixes.  Every recipient has to have an alias created on the server.  If you want to deliver to <a href="mailto:john.suffix@example.com">john.suffix@example.com</a> you’d better remember to create an alias for that user, otherwise the Exchange Recipient Filter will reject the message since – as far as it is concerned – the user does not exist on the server.</p>
<p>Worse, Exchange doesn’t even implement any generic <a href="http://en.wikipedia.org/wiki/Catch-all">CatchAll</a> functionality.  CatchAll would allow the server to redirect messages for non-existing recipients to a specific address. <a href="http://catchallagent.codeplex.com/" target="_blank">Smart people</a> have created solutions to the CatchAll problem but all that does is allow you to define one mailbox for ALL non-deliverable messages to be delivered to.  Since I need to provide suffix matching to multiple users this doesn’t work for me.</p>
<p>Time to extend Exchange’s functionality!</p>
<h5>Transport Agents</h5>
<p><a href="http://technet.microsoft.com/en-us/library/bb125012.aspx" target="_blank">Transport Agents</a> were introduced in Exchange 2007 to replace Exchange 2003’s SMTP Event Sinks and have been retained largely unchanged in Exchange 2010.  Broadly speaking when a message arrives at an Exchange Server it is moved through the transport pipeline as each SMTP event occurs.  Each <a href="http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol">SMTP event</a> (Connect, MAIL FROM, RCPT TO, etc) can trigger an interested Transport Agent to perform some actions on the message.<br />
The complete list of SMTP events and their sequence is described on <a href="http://technet.microsoft.com/en-us/library/bb125012.aspx" target="_blank">this Exchange Server TechCenter page</a>.</p>
<p>Transport Agents are simply DLLs written in managed code that fire on SMTP events.  Back when I contracted for the <a href="http://www.mod.uk/">MOD</a> I wrote a Transport Agent for Exchange 2007 which demonstrated that Exchange was capable of performing Dominance Checking on outgoing emails so I knew that it wouldn&#8217;t take to long to write a Transport Agent to filter incoming messages.  I was able to reuse some of that code and also made use of some of <a href="http://www.codeplex.com/site/users/view/wilbertdg" target="_blank">Wilbert De Graaf</a>’s <a href="http://catchallagent.codeplex.com/" target="_blank">CatchAll Agent</a> code which made the handling of a configuration file very quick to implement.  Thank you Wilbert!</p>
<h5>Requirements</h5>
<p>I had a couple of requirements for my Transport Agent:</p>
<p>1) It should allow redirection of multiple suffixes to different recipients.</p>
<p>2) It should allow me to ban delivery to any previously used suffixes and ensure that the sender receives a non-deliverable report.</p>
<p>I ended up meeting these requirements by using C# to write a Transport Agent that accepts its configuration from an XML file.  The config.xml defines multiple regular expressions to match against along with associated redirect addresses.  It also lists banned email addresses which the Transport Agent should reject.</p>
<p>To mimic the <a href="http://www.gradwell.com/support/howto/article/392">Gradwell behaviour</a> which we were already making use of I needed to match firstname then a dot and then any word before the domain.  This is a fairly simple <a href="http://support.microsoft.com/kb/308252">regular expression in C#</a>, and looks like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;">^firstname+\.[a-z]+@example.com$</pre>
</div>
</div>
<p>The config.xml takes the form:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;redirect</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^john+\.[a-z]+@domain.com$&quot;</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;john@domain.com&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;redirect</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^jane+\.[a-z]+@domain.com$&quot;</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;jane.doe@gmail.com&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;banned</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;john.spam@domain.com&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;banned</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;jane.newsletter@domain.com&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>Here we define two patterns for redirect, one to an internal recipient and one redirect to an external SMTP address.  We also ban two known &#8220;bad&#8221; recipient addresses.</p>
<p>You’ll need to provide at least one redirect entry, but you’re not required to ban any addresses if you don&#8217;t want to.  Also, while redirects specifiy regular expressions to match, banned addresses are just strings which are simply compared.  I leave it as an exercise for the reader to add regular expressions to the banned list!</p>
<h5>The Code</h5>
<p>Whenever the config.xml file is changed, the agent reloads it and parses the XML.  It puts the banned emails into a List and the regular expression patterns and redirect addresses into a Dictionary.  If any of the emails in the config appear invalid the new configuration is rejected and the agent continues to use the running config.</p>
<p>The agent defines a RCPT TO: handler.  This event is fired as soon as the sending MTA starts to transmit the recipient addresses.  rcptArgs contains the argument we need: RecipientAddress, which we store as a lowercase string for comparison.  Although the spec (<a href="http://www.faqs.org/rfcs/rfc2821.html">RFC2821</a>) actually requires email addresses to be case sensitive, I&#8217;ve never met an MTA that adheres to that part of the spec.  So for our purposes email addresses are case insensitive and we can do all comparisons in lowercase.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> RcptToHandler<span style="color: #000000;">&#40;</span>ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-style: italic;">// Get the recipient address as a lowercase string.</span>
<span style="color: #FF0000;">string</span> strRecipientAddress <span style="color: #008000;">=</span> rcptArgs.<span style="color: #0000FF;">RecipientAddress</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>It performs two checks.  First &#8211; is the recipient address in the ban list?</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Search the banned email List for the recipient.</span>
<span style="color: #FF0000;">bool</span> exists <span style="color: #008000;">=</span> catchAllConfig.<span style="color: #0000FF;">Banned</span>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>element <span style="color: #008000;">=&gt;</span> element <span style="color: #008000;">==</span> strRecipientAddress<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>exists<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// If found respond to the sending MTA with the reject response.</span>
	source.<span style="color: #0000FF;">RejectCommand</span><span style="color: #000000;">&#40;</span>CatchAllAgent.<span style="color: #0000FF;">rejectResponse</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// No further processing.</span>
	return<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>And second, does the recipient address match any of the regular expressions?</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// For each pair of regexps to email addresses</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var pair <span style="color: #0600FF;">in</span> catchAllConfig.<span style="color: #0000FF;">AddressMap</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// Create the regular expression and the routing address from the dictionary.</span>
	Regex emailPattern <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Regex<span style="color: #000000;">&#40;</span>pair.<span style="color: #0000FF;">Key</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	RoutingAddress emailAddress <span style="color: #008000;">=</span> pair.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// If the recipient address matches the regular expression.</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>emailPattern.<span style="color: #0000FF;">IsMatch</span><span style="color: #000000;">&#40;</span>strRecipientAddress<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// And if the recipient is NOT in the address book.</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">addressBook</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span>
			<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">addressBook</span>.<span style="color: #0000FF;">Find</span><span style="color: #000000;">&#40;</span>rcptArgs.<span style="color: #0000FF;">RecipientAddress</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Redirect the recipient to the other address.</span>
			rcptArgs.<span style="color: #0000FF;">RecipientAddress</span> <span style="color: #008000;">=</span> emailAddress<span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// No further processing.</span>
			return<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
</div>
</div>
<p>Note that in both cases as soon as we&#8217;ve got a positive result we stop further processing.  If an address is in the ban list we immediately reject it, and if we find a matching regular expression we use its paired address to redirect the message and stop looking for further matches.</p>
<p>I&#8217;ve given enough information here that a C# developer with some spare time could create this Transport Agent themselves.  However I know that it is really useful to have a package you can just download and install without having to worry about compiling it yourself.  So I&#8217;ve packaged the DLL together with installation scripts and the <a href="/regexcatchall/installation/">install and configuration guide</a>.  </p>
<p>Please visit the <a href="/regexcatchall/">product page</a> for more information and to purchase the Transport Agent.  Payment is via PayPal, you will receive the download link within minutes of payment.</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2010/05/29/regexcatchall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix orphaned SQL Server users</title>
		<link>http://durdle.com/archives/2010/03/11/fix-orphaned-sql-server-users/</link>
		<comments>http://durdle.com/archives/2010/03/11/fix-orphaned-sql-server-users/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 17:04:21 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Future Howard]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/?p=765</guid>
		<description><![CDATA[I always forget this in between using it, so for the benefit of future Howard, here&#8217;s how to fix orphaned users resulting from restoring a SQL database to a different machine.
First, list the orphan users to make sure this is the problem:


EXEC sp_change_users_login 'Report'


Usually I already have the login and password set up on the...]]></description>
			<content:encoded><![CDATA[<p>I always forget this in between using it, so for the benefit of future Howard, here&#8217;s how to fix orphaned users resulting from restoring a SQL database to a different machine.<span id="more-765"></span></p>
<p>First, list the orphan users to make sure this is the problem:</p>
<div class="wp_syntax">
<div class="code">
<pre class="sql" style="font-family:monospace;">EXEC sp_change_users_login <span style="color: #ff0000;">'Report'</span></pre>
</div>
</div>
<p>Usually I already have the login and password set up on the server, this being the case you can fix the orphan by doing:</p>
<div class="wp_syntax">
<div class="code">
<pre class="sql" style="font-family:monospace;">EXEC sp_change_users_login <span style="color: #ff0000;">'Auto_Fix'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'user'</span></pre>
</div>
</div>
<p>If not, and you want/need to create the login and password, you&#8217;ll need to do this instead:</p>
<div class="wp_syntax">
<div class="code">
<pre class="sql" style="font-family:monospace;">EXEC sp_change_users_login <span style="color: #ff0000;">'Auto_Fix'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'user'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'login'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'password'</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2010/03/11/fix-orphaned-sql-server-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IIS7 web.config fun</title>
		<link>http://durdle.com/archives/2010/03/08/iis7-web-config-fun/</link>
		<comments>http://durdle.com/archives/2010/03/08/iis7-web-config-fun/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 20:15:11 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[gradwell]]></category>
		<category><![CDATA[iis7]]></category>
		<category><![CDATA[memset]]></category>
		<category><![CDATA[web.config]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[workavoidance]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/?p=747</guid>
		<description><![CDATA[I spent some time last weekend migrating the Work Avoidance site away from Gradwell and onto a dedicated virtual server from MEMSET.  Since this involved a move to a Windows box away from UNIX hosting, I had to configure in IIS7 some of the settings I had in the .htaccess under the UNIX host.
For...]]></description>
			<content:encoded><![CDATA[<p><a href="/wp-content/uploads/iis7-logo.jpg" rel="lightbox[747]"><img src="/wp-content/uploads/iis7-logo.jpg" alt="IIS7 Logo" title="IIS7" width="200" height="125" class="alignleft size-full wp-image-757" /></a>I spent some time last weekend migrating the <a href="http://workavoidance.net">Work Avoidance</a> site away from <a href="http://www.gradwell.net/">Gradwell</a> and onto a dedicated virtual server from <a href="http://www.memset.com/dedicated-servers/virtual.php">MEMSET</a>.  Since this involved a move to a Windows box away from UNIX hosting, I had to configure in IIS7 some of the settings I had in the .htaccess under the UNIX host.<span id="more-747"></span></p>
<p>For example, I want a canonical host name (so visitors always see <a href="http://workavoidance.net">workavoidance.net</a> with no www prefix in the address bar) and to ensure that the <a href="http://wordpress.org/">Wordpress</a> permalinks work properly.  While I was at it I took the opportunity to disable hot-linking of our images, since for some reason a Russian website had taken a shine to some of our <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=303892009&#038;mt=8">Armory</a> graphics.</p>
<p>Below is the <code>web.config</code> I created.  It redirects users to the canonical host name, enables Wordpress permalinks and disables hot-linking of our images.  The redirect proved something of a problem to begin with.  Our iPhone App &#8220;<a href="http://itunes.apple.com/us/app/monkey-shaker/id290779801?mt=8">Monkey Shaker</a>&#8221; has an online <a href="http://workavoidance.net/highscores/shaker/">high score system</a>.  Scores are submitted from the app via an encrypted HTTP POST to a PHP page which decrypts the information and updates the database.  I discovered that when you issue a server side redirect most clients won&#8217;t re-POST their data to the new page &#8211; they will issue a GET for the new page and the original POST data is lost.  This meant that highscore submissions were failing.</p>
<p>(NB: this isn&#8217;t as big a disaster as it sounds since we built a very robust mechanism to retry score submission into the app.)</p>
<p>So, you&#8217;ll note an extra entry in the web.config to exclude that page from a redirect:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{URL}&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;scoresubmit\.php$&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>&#8220;Why not just change the URL in the app to be canonical?!&#8221; You may well ask.  Yes, we probably will, but that relies on issuing an update and getting <strong>over a quarter of a million users</strong> to download it.  This way we don&#8217;t have to rely on that.</p>
<p>Still to come &#8211; how I implemented caching in Wordpress and in our high score system to improve performance.</p>
<p>Here&#8217;s the rewrite rules section of the completed web.config:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Canonical Host Name&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;(.*)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{HTTP_HOST}&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^workavoidance\.net$&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{URL}&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;scoresubmit\.php$&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Redirect&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://workavoidance.net/{R:1}&quot;</span> <span style="color: #000066;">redirectType</span>=<span style="color: #ff0000;">&quot;Permanent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Prevent image hotlinking&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;.*\.(gif|jpg|png)$&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{HTTP_REFERER}&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^$&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{HTTP_REFERER}&quot;</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^http://workavoidance\.net/.*$&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Rewrite&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;/no.png&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wordpress&quot;</span> <span style="color: #000066;">patternSyntax</span>=<span style="color: #ff0000;">&quot;Wildcard&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsFile&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsDirectory&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Rewrite&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;index.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2010/03/08/iis7-web-config-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Update 13 breaks Cisco SDM 2.5</title>
		<link>http://durdle.com/archives/2009/04/22/java-update-13-breaks-cisco-sdm-25/</link>
		<comments>http://durdle.com/archives/2009/04/22/java-update-13-breaks-cisco-sdm-25/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 09:24:50 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/?p=432</guid>
		<description><![CDATA[Another post in a series designed to help Future-Howard work out why things have broken.
If you install Java 6 Update 13 and then try and log into Cisco SDM 2.5 it will fail.  The SDM console will not load.
I found I had to go back to Java 6 Update 6 (available at the Java...]]></description>
			<content:encoded><![CDATA[<p>Another post in a series designed to help Future-Howard work out why things have broken.</p>
<p>If you install Java 6 Update 13 and then try and log into Cisco SDM 2.5 it will fail.  The SDM console will not load.</p>
<p>I found I had to go back to Java 6 Update 6 (available at the <a href="http://java.sun.com/products/archive/j2se/6u6/index.html">Java archive page</a>, or <a href="http://cds-esd.sun.com/ESD41/JSCDL/jdk/6u6/jre-6u6-windows-i586-p.exe?AuthParam=1240392304_c9e1fea007eb4de38eb1009830507b8c&#038;TicketId=B%2Fw3nBqGTltPSxFDOlNekgfm&#038;GroupName=CDS&#038;FilePath=/ESD41/JSCDL/jdk/6u6/jre-6u6-windows-i586-p.exe&#038;File=jre-6u6-windows-i586-p.exe">direct download</a>.).</p>
<p>With that the Cisco SDM started working again.  I&#8217;ve not found anything about this on the Cisco site.</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2009/04/22/java-update-13-breaks-cisco-sdm-25/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>LDAP Query based on account SID in VBscript</title>
		<link>http://durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/</link>
		<comments>http://durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 12:36:16 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[vbscript security ldap sid wmi]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/</guid>
		<description><![CDATA[This is a bit of code I wish I&#8217;d found sooner.  There is a &#8211; it seems mostly undocumented &#8211; feature of the ldap provider in Server 2003 that allows you to form an ldap query just on the SID of an account:



bindSid = &#34;LDAP://&#38;lt;sid =&#34; &#38;amp; SID &#38;amp; &#34;&#38;gt;&#34;
set oVal = GetObject(bindSid)
Result =...]]></description>
			<content:encoded><![CDATA[<p>This is a bit of code I wish I&#8217;d found sooner.  There is a &#8211; it seems mostly undocumented &#8211; feature of the ldap provider in Server 2003 that allows you to form an ldap query just on the SID of an account:<br />
</p>
<div class="wp_syntax">
<div class="code">
<pre class="vbscript" style="font-family:monospace;">bindSid = &quot;LDAP://&amp;lt;sid =&quot; &amp;amp; SID &amp;amp; &quot;&amp;gt;&quot;
set oVal = GetObject(bindSid)
Result = oVal.Get(&quot;cn&quot;)
set oVal = Nothing</pre>
</div>
</div>
<p>So if you have a list of SIDs and want to translate them into meaningful account names, this will do it without relying on using WMI &#8211; which on a lot of secure networks is locked down (or at least should be!).</p>
<p>Why do I need this?  It&#8217;s a part of a larger script I&#8217;m writing that will archive specific Group Policy Objects from the <strong>\SYSVOL\&lt;domainname&gt;\Policies\</strong> folder of a PDCe.  One of the files in a GPO is the <strong>GptTmpl.inf</strong> file which gives a list of the <a title="User Rights Assignments" href="http://technet2.microsoft.com/windowsserver/en/library/71b2772f-e3c0-4134-b7f0-54c244ee9aef1033.mspx?mfr=true" target="_blank">User Rights Assignments</a> (SeBackupPrivilege, SeShutdownPrivileg etc) along with the SIDs of the accounts that have been given those privileges (e.g. S-1-5-19).  I wrote a script that reads the SIDs and queries the DC for the account names.  This code fragment works more reliably (and I think faster) than the WMI calls I was previously using.</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Graphing Counter-Strike Source FPS/Users in MRTG on Windows</title>
		<link>http://durdle.com/archives/2007/12/04/graphing-counter-strike-source-fpsusers-in-mrtg-on-windows/</link>
		<comments>http://durdle.com/archives/2007/12/04/graphing-counter-strike-source-fpsusers-in-mrtg-on-windows/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 12:08:54 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[counter-strike source]]></category>
		<category><![CDATA[fps]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mrtg]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[rcon]]></category>
		<category><![CDATA[remote console]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/archives/2007/12/04/graphing-counter-strike-source-fpsusers-in-mrtg-on-windows/</guid>
		<description><![CDATA[In my last post, you discovered my obsession for generating statistics on my network usage and my use of MRTG to draw pretty little graphs.  Writing that post got me thinking about my Counter-Strike server, and what data I could usefully graph from it.  A bit of Googling led me to this page...]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/graphingcssfpsusers.png" style="border-width: 0px" alt="Network Frames per Second" align="left" border="0" height="69" width="244" />In my <a href="http://blog.durdle.com/archives/2007/12/03/traffic-graphing/">last post</a>, you discovered my obsession for generating statistics on my network usage and my use of <a href="http://oss.oetiker.ch/mrtg/" target="_blank">MRTG</a> to draw pretty little graphs.  Writing that post got me thinking about my Counter-Strike server, and what data I could usefully graph from it.  A bit of Googling led me to <a href="http://www.zokahn.nl/staticpages/index.php?page=HOWTO-CS-Graph" target="_blank">this page</a> where a Dutch guy had used MRTG to graph the number of users and the network frames per second of his CS:S server &#8211; running on Ubuntu Linux.</p>
<p><span id="more-272"></span></p>
<p>He used a custom compiled &#8220;rcon&#8221; binary to talk directly to the game server&#8217;s Remote Console port.  This is the port that allows an administrator to configure the game, kick players, change maps and generally do all the useful stuff that a game admin needs to do.  It&#8217;s the protocol used by the <a href="http://stats.durdle.com/hlstats/index.php?mode=live_stats&amp;server=1" target="_blank">hlstats live stats</a> page to determine what is happening <strong>right now</strong> on the game server.  Unfortunately, as far as my Googling shows, such a binary doesn&#8217;t exist for win32.  There is a perl module (<a href="http://kkrcon.sourceforge.net/" target="_blank">kkrcon.pm</a>) which does the work inside hlstats, but the command line wrapper for kkrcon.pm &#8211; kkrcon.pl &#8211; doesn&#8217;t seem to have been updated since 2001 and so doesn&#8217;t work for Source titles.</p>
<p>A little Perl hacking later and I&#8217;ve created a version of the kkrcon.pl wrapper that is capable of using the Source rcon protocol.  You can download both the module and the wrapper here: <a href="http://blog.durdle.com/wp-content/uploads/2007/12/kkrcon_durdle.zip" title="source server rcon perl script">source server rcon perl script</a>.  This was tested on Windows Server 2003 running ActiveState Perl.</p>
<p>With that done, we can use MRTG to run another Perl script which will run the new kkrcon.pl with the right parameters, request some data from the game server and then parse it into a format that MRTG can understand.  The two scripts I used are much the same as I found on the Zokahn site, but tweaked to use my new kkrcon.pl instead of the binary and to pass the parameters in a slightly different way.  You can grab the scripts here: <a href="http://blog.durdle.com/wp-content/uploads/2007/12/mrtg_counter-strike_source_perl_scripts_durdle.zip" title="MRTG Counter-Strike: Source perl data source scripts">MRTG Counter-Strike: Source perl data source scripts</a>.</p>
<p>The last step is the MRTG config file itself, here&#8217;s what the CSS Users part of mine looks like:</p>
<blockquote><p>Target[server.CS-Users]:`.\m_cs-s_users.pl &lt;server_ip&gt; &lt;port&gt; &lt;rcon_password&gt;`<br />
Title[server.CS-Users]: Active Counter-Strike:Source users<br />
PageTop[server.CS-Users]: &lt;H1&gt;Counter-Strike:Source Users&lt;/H1&gt;<br />
MaxBytes[server.CS-Users]: 16<br />
ShortLegend[server.CS-Users]: #<br />
YLegend[server.CS-Users]: Active Users<br />
Legend1[server.CS-Users]: Current active CS:Source users<br />
LegendI[server.CS-Users]: Users<br />
LegendO[server.CS-Users]:<br />
Options[server.CS-Users]: growright,nopercent,gauge,integer<br />
Unscaled[server.CS-Users]: ymwd</p></blockquote>
<p>It&#8217;s very important to note that those are back ticks (`) on the first line &#8211; NOT apostrophes (&#8216;).  This caught me out and stopped MRTG generating data until I&#8217;d fixed it.</p>
<p>You can see my graphs <a href="http://stats.durdle.com/mrtg/" target="_blank">here</a>, although there isn&#8217;t a lot of data yet &#8211; just waiting for the clan to wake up and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2007/12/04/graphing-counter-strike-source-fpsusers-in-mrtg-on-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VB.NET to C# and C# to VB.NET Translator</title>
		<link>http://durdle.com/archives/2007/07/31/vbnet-to-c-and-c-to-vbnet-translator/</link>
		<comments>http://durdle.com/archives/2007/07/31/vbnet-to-c-and-c-to-vbnet-translator/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 15:42:08 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Future Howard]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/archives/2007/07/31/vbnet-to-c-and-c-to-vbnet-translator/</guid>
		<description><![CDATA[This code translator is very handy.  Give it some C# and it will spit out VB.NET, give it VB.NET and it&#8217;ll give you C#.  Some of the code samples for manipulating Word documents are in VB.NET and I wanted to see them in C#.  I could have tried to translate them myself but this saved...]]></description>
			<content:encoded><![CDATA[<p>This <a title="VB.NET to C# and back again" href="http://www.carlosag.net/Tools/CodeTranslator/Default.aspx" target="_blank">code translator</a> is very handy.  Give it some C# and it will spit out VB.NET, give it VB.NET and it&#8217;ll give you C#.  Some of the code samples for manipulating Word documents are in VB.NET and I wanted to see them in C#.  I could have tried to translate them myself but this saved me the bother.  Sweet.</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2007/07/31/vbnet-to-c-and-c-to-vbnet-translator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
