<?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>Thu, 29 Sep 2011 13:33:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ZoneMinder Control Script for Foscam FI8918W</title>
		<link>http://durdle.com/archives/2011/02/26/zoneminder-control-module-for-foscam-fi8918w/</link>
		<comments>http://durdle.com/archives/2011/02/26/zoneminder-control-module-for-foscam-fi8918w/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 22:57:34 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Control Module]]></category>
		<category><![CDATA[Control Script]]></category>
		<category><![CDATA[FI8918W]]></category>
		<category><![CDATA[Foscam]]></category>
		<category><![CDATA[Foscam FI8918W]]></category>
		<category><![CDATA[Zone Minder]]></category>
		<category><![CDATA[ZoneMinder]]></category>

		<guid isPermaLink="false">http://durdle.com/?p=856</guid>
		<description><![CDATA[Update 27/02/2011: Added IR control and password passthrough.I&#8217;ve recently put together a CCTV solution using a few Foscam FI8918W cameras and the excellent ZoneMinder software. This is all running on a CentOS 5.5 virtual machine under Hyper-V (more on this setup another time). The Foscam cameras have pan, tilt and the ability to set and...]]></description>
			<content:encoded><![CDATA[<p><a href="http://durdle.com/wp-content/uploads/zoneminder.png" rel="lightbox[856]"><img class="size-medium wp-image-862 alignleft" title="Gnarly asleep via ZoneMinder" src="http://durdle.com/wp-content/uploads/zoneminder-300x224.png" alt="" width="300" height="224" /></a><strong>Update 27/02/2011: Added IR control and password passthrough.</strong><br/>I&#8217;ve recently put together a CCTV solution using a few Foscam FI8918W cameras and the excellent <a href="http://www.zoneminder.com/">ZoneMinder</a> software.  This is all running on a CentOS 5.5 virtual machine under Hyper-V (more on this setup another time).  The Foscam cameras have pan, tilt and the ability to set and move to preset locations.</p>
<p>The Foscam control script for ZoneMinder which I found on the <a href="http://www.zoneminder.com/wiki/index.php/Foscam">ZoneMinder wiki</a> was a good starting point, but seemed to have left and right wired backwards, and didn&#8217;t support the presets.  So I&#8217;ve updated it to fix those issues, the script is below.</p>
<p>To install:  find where the control scripts are installed on your distro.  In mine I found the files in:</p>
<pre>/usr/lib/perl5/site_perl/5.8.8/ZoneMinder/Control/</pre>
<p>If you&#8217;re not sure where to look, run the command:</p>
<pre>locate PanasonicIP.pm</pre>
<p>This will return the location of one of the existing control scripts.</p>
<p>Once you&#8217;ve found them, create a new file called <strong>FoscamFI8918W.pm</strong> and paste the code below into it.  <del datetime="2011-02-27T14:49:50+00:00">As with the original script this assumes there is an admin user with no password on your camera.  This will have to do until I can work out how to pass through a proper username and password from the ZoneMinder frontend.</del><strong>Update 27/02/2011:</strong> the username and password are now passed via the Control Device field.  See below.</p>
<p>You&#8217;ll need to add the control script to the ZoneMinder interface and attach it to your camera.   First make sure that ZoneMinder is configured to support controllable cameras.  Open <strong>Options</strong> from the main console and click <strong>OPT_CONTROL</strong> in the <strong>System</strong> tab.</p>
<p>Then open the source options for the camera you want to control.  Select the <strong>Control</strong> tab, and click <strong>Edit</strong> next to <strong>Control Type</strong>.  Click the <strong>Add New Control</strong> button, then enter the following settings (<strong>Update 27/02/2011, see bottom of post for updated settings for IR control and username/password.</strong>):</p>
<p><a href="http://durdle.com/wp-content/uploads/zm_control_01_main.png" rel="lightbox[856]"><img class="alignnone size-full wp-image-857" title="zm_control_01_main" src="http://durdle.com/wp-content/uploads/zm_control_01_main.png" alt="" width="416" height="411" /></a></p>
<p><a href="http://durdle.com/wp-content/uploads/zm_control_02_move.png" rel="lightbox[856]"><img class="alignnone size-full wp-image-857" title="zm_control_02_move" src="http://durdle.com/wp-content/uploads/zm_control_02_move.png" alt="" width="416" height="411" /></a></p>
<p><a href="http://durdle.com/wp-content/uploads/zm_control_03_pan.png" rel="lightbox[856]"><img class="alignnone size-full wp-image-857" title="zm_control_03_pan" src="http://durdle.com/wp-content/uploads/zm_control_03_pan.png" alt="" width="416" height="411" /></a></p>
<p><a href="http://durdle.com/wp-content/uploads/zm_control_04_tilt.png" rel="lightbox[856]"><img class="alignnone size-full wp-image-857" title="zm_control_04_tilt" src="http://durdle.com/wp-content/uploads/zm_control_04_tilt.png" alt="" width="416" height="411" /></a></p>
<p><a href="http://durdle.com/wp-content/uploads/zm_control_05_presets.png" rel="lightbox[856]"><img class="alignnone size-full wp-image-857" title="zm_control_05_presets" src="http://durdle.com/wp-content/uploads/zm_control_05_presets.png" alt="" width="416" height="411" /></a></p>
<p>Now save and close that window, and refresh the one for your camera.  You should now see the Foscam FI8918W script in the list.  Select it, and enter the IP address of the camera in the <strong>Control Address</strong> box.  Make sure <strong>Controllable</strong> is ticked, then click <strong>Save</strong>.</p>
<p>Now if you view the camera you&#8217;ll have a <strong>Control</strong> option near the top.  Click it to reveal the Pan/Tilt controls, along with the presets:<br />
<a href="http://durdle.com/wp-content/uploads/zm_controls.png" rel="lightbox[856]"><img class="alignnone size-medium wp-image-863" title="ZoneMinder Controls" src="http://durdle.com/wp-content/uploads/zm_controls-262x300.png" alt="" width="262" height="300" /></a></p>
<p>That&#8217;s it.  Enjoy your controllable cameras!Â<br />
<br/>Download the <a href='http://durdle.com/wp-content/uploads/FoscamFI8918W.pm_.txt'>FoscamFI8918W.pm</a> script.  Rename to .pm.<br/><br />
<del datetime="2011-02-27T13:24:37+00:00">I&#8217;ll update this post when I work out the password passthrough and how to turn the IR LED on and off via ZoneMinder.</del> <strong>Update 27/02/2011:</strong> the script now uses Sleep and Wake to turn the IR off and on and passes the username and password via the Control Device parameter.  You&#8217;ll need to enable those options on the Main tab of the Control like so:<br />
<a href="http://durdle.com/wp-content/uploads/zm_control_01_main_b1.png" rel="lightbox[856]"><img src="http://durdle.com/wp-content/uploads/zm_control_01_main_b1.png" alt="" title="zm_control_01_main_b" width="416" height="325" class="alignnone size-full wp-image-866" /></a><br />
And put your username and password query string in the <strong>Control Device</strong> field:<br />
<a href="http://durdle.com/wp-content/uploads/zm_controls_device.png" rel="lightbox[856]"><img src="http://durdle.com/wp-content/uploads/zm_controls_device.png" alt="" title="zm_controls_device" width="396" height="388" class="alignnone size-full wp-image-867" /></a></p>
<div class="wp_syntax">
<div class="code">
<pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ==========================================================================</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># ZoneMinder Foscam FI8918W IP Control Protocol Module, $Date: 2009-11-25 09:20:00 +0000 (Wed, 04 Nov 2009) $, $Revision: 0001 $</span>
<span style="color: #666666; font-style: italic;"># Copyright (C) 2001-2008 Philip Coombes</span>
<span style="color: #666666; font-style: italic;"># Modified for use with Foscam FI8918W IP Camera by Dave Harris</span>
<span style="color: #666666; font-style: italic;"># Modified Feb 2011 by Howard Durdle (http://durdl.es/x) to:</span>
<span style="color: #666666; font-style: italic;">#      fix horizontal panning, add presets and IR on/off</span>
<span style="color: #666666; font-style: italic;">#      use Control Device field to pass username and password</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This program is free software; you can redistribute it and/or</span>
<span style="color: #666666; font-style: italic;"># modify it under the terms of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;"># as published by the Free Software Foundation; either version 2</span>
<span style="color: #666666; font-style: italic;"># of the License, or (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span style="color: #666666; font-style: italic;"># GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;"># along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;"># Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># ==========================================================================</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This module contains the implementation of the Foscam FI8918W IP camera control</span>
<span style="color: #666666; font-style: italic;"># protocol</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000066;">package</span> ZoneMinder<span style="color: #339933;">::</span><span style="color: #006600;">Control</span><span style="color: #339933;">::</span><span style="color: #006600;">FoscamFI8918W</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> <span style="color: #cc66cc;">5.006</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">require</span> ZoneMinder<span style="color: #339933;">::</span><span style="color: #006600;">Base</span><span style="color: #339933;">;</span>
<span style="color: #000066;">require</span> ZoneMinder<span style="color: #339933;">::</span><span style="color: #006600;">Control</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">@ISA</span> <span style="color: #339933;">=</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>ZoneMinder<span style="color: #339933;">::</span><span style="color: #006600;">Control</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$VERSION</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ZoneMinder</span><span style="color: #339933;">::</span><span style="color: #006600;">Base</span><span style="color: #339933;">::</span><span style="color: #006600;">VERSION</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ==========================================================================</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Foscam FI8918W IP Control Protocol</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># ==========================================================================</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> ZoneMinder<span style="color: #339933;">::</span><span style="color: #006600;">Debug</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>all<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> ZoneMinder<span style="color: #339933;">::</span><span style="color: #006600;">Config</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>all<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">use</span> Time<span style="color: #339933;">::</span><span style="color: #006600;">HiRes</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span> usleep <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000000; font-weight: bold;">new</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> ZoneMinder<span style="color: #339933;">::</span><span style="color: #006600;">Control</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$logindetails</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">bless</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$class</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">srand</span><span style="color: #009900;">&#40;</span> <span style="color: #000066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">return</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$AUTOLOAD</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> AUTOLOAD
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span> <span style="color: #339933;">=</span> <span style="color: #000066;">ref</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$self</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> croak<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;$self not object&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$AUTOLOAD</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$name</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/.*://</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	Fatal<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Can't access $name member of object of class $class&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$stop_command</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000066;">open</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">loadMonitor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">use</span> LWP<span style="color: #339933;">::</span><span style="color: #006600;">UserAgent</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>ua<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> LWP<span style="color: #339933;">::</span><span style="color: #006600;">UserAgent</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>ua<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">agent</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;ZoneMinder Control Agent/&quot;</span><span style="color: #339933;">.</span>ZM_VERSION <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>state<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'open'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000066;">close</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>state<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'closed'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> printMsg
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$msg_len</span> <span style="color: #339933;">=</span> <span style="color: #000066;">length</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$msg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$msg</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;[&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$msg_len</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;]&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> sendCmd
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000066;">undef</span><span style="color: #339933;">;</span>
	printMsg<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Tx&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$req</span> <span style="color: #339933;">=</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Request</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span> GET<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Monitor<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>ControlAddress<span style="color: #009900;">&#125;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;/$cmd&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Monitor<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>ControlDevice<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$res</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>ua<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">request</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$req</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">is_success</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #000066;">undef</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		Error<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Error check failed:'&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">status_line</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;'&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$result</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #b1b100;">reset</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Camera Reset&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;reboot.cgi?&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Up Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConUp
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Up&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=0&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Down Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConDown
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Down&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=2&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Left Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConLeft
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Left&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=6&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Right Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConRight
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Right&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=4&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Diagonally Up Right Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConUpRight
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Diagonally Up Right&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=90&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Diagonally Down Right Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConDownRight
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Diagonally Down Right&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=92&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Diagonally Up Left Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConUpLeft
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Diagonally Up Left&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=91&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Diagonally Down Left Arrow</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveConDownLeft
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Diagonally Down Left&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=93&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Stop</span>
<span style="color: #000000; font-weight: bold;">sub</span> moveStop
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Move Stop&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=1&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Move Camera to Home Position</span>
<span style="color: #000000; font-weight: bold;">sub</span> presetHome
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Home Preset&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=25&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Set preset</span>
<span style="color: #000000; font-weight: bold;">sub</span> presetSet
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$preset</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">getParam</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$params</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'preset'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$presetCmd</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$preset</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Set Preset $preset with cmd $presetCmd&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=$presetCmd&amp;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Goto preset</span>
<span style="color: #000000; font-weight: bold;">sub</span> presetGoto
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$stop_command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$preset</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">getParam</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$params</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'preset'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$presetCmd</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$preset</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Goto Preset $preset with cmd $presetCmd&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=$presetCmd&amp;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Turn IR on</span>
<span style="color: #000000; font-weight: bold;">sub</span> wake
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Wake - IR on&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=95&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Turn IR off</span>
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000066;">sleep</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	Debug<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Sleep - IR off&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;decoder_control.cgi?command=94&amp;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">sendCmd</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$cmd</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2011/02/26/zoneminder-control-module-for-foscam-fi8918w/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Exchange 2010 SP1 breaks pre-SP1 Transport Agents</title>
		<link>http://durdle.com/archives/2010/12/21/exchange-2010-sp1-breaks-pre-sp1-transport-agents/</link>
		<comments>http://durdle.com/archives/2010/12/21/exchange-2010-sp1-breaks-pre-sp1-transport-agents/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 11:42:45 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[exchange server 2010]]></category>
		<category><![CDATA[exchange server 2010 sp1]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[transport agent]]></category>

		<guid isPermaLink="false">http://durdle.com/?p=850</guid>
		<description><![CDATA[I&#8217;d encountered a few anomalies with the Exchange 2010 server over the last few weeks, so took the opportunity yesterday to upgrade it to SP1 and the latest Update Rollup. This revealed an annoying feature of &#8211; or bug in &#8211; Microsoft&#8217;s code that loads Transport Agents causing my RegExCatchAll Agent to crash. I also...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d encountered a few anomalies with the Exchange 2010 server over the last few weeks, so took the opportunity yesterday to upgrade it to SP1 and the latest Update Rollup.  This revealed an annoying feature of &#8211; or bug in &#8211; Microsoft&#8217;s code that loads Transport Agents causing my <a href="http://durdle.com/regexcatchall/">RegExCatchAll</a> Agent to crash.  I also learned something I didn&#8217;t know about Powershell.<br />
<span id="more-850"></span><br />
The bug I found is that if you try to install a Transport Agent that is built with Exchange 2010 pre SP1 binaries on an Exchange 2010 SP1 server you will get an error:</p>
<pre>The TransportAgentFactory type "RegExCatchAll.CatchAllFactory" doesn't exist.
The TransportAgentFactory type must be the Microsoft .NET class type of the transport agent factory.
Parameter name: TransportAgentFactory
    + CategoryInfo          : InvalidArgument: (:) [Install-TransportAgent], ArgumentException
    + FullyQualifiedErrorId : 6F5E297B,Microsoft.Exchange.Management.AgentTasks.InstallTransportAgent
</pre>
<p>This error occurs because when you install the assembly Exchange Server checks for the Types associated with the Transport Agent Assembly.  This means it looks for the versions of Microsoft.Exchange.Data.Common.dll and Microsoft.Exchange.Data.Transport.dll it was compiled with.  Since they were pre SP1 DLLs it won&#8217;t find them on the SP1 system.  This is also true if (as in my case) you had already successfully installed the Transport Agent on a non SP1 system and subsequently upgraded Exchange to SP1.  Once Exchange starts as SP1 for the first time, your Transport Agent will fail to start and crash the Exchange Transport Service. </p>
<p>The fix, for now, is to recompile the Transport Agent using the SP1 copies of the two DLLs which you&#8217;ll find on the Exchange Server in:</p>
<pre>C:\Program Files\Microsoft\Exchange Server\V14\Public</pre>
<p>Once you have a fixed DLL, you&#8217;ll need to <a href="http://durdle.com/regexcatchall/uninstall/">replace the running copy</a> on your Exchange Server.  This took me several attempts &#8211; and for about 20 minutes I thought there was an error with my code as I continued to get the error message above.  It turned out that because I had tried to <a href="http://durdle.com/regexcatchall/installation/">install</a> the broken DLL once in my Powershell session, and hadn&#8217;t exited and restarted Powershell, it was in some sense &#8220;caching&#8221; the failure.  In the end I issued an IISRESET from within Powershell, then tried to install the DLL again.  </p>
<p>This time it worked perfectly and now my Transport Agent is running happily under Exchange Server 2010 SP1.</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2010/12/21/exchange-2010-sp1-breaks-pre-sp1-transport-agents/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extracting Zip from Embedded Resource with Streams</title>
		<link>http://durdle.com/archives/2010/10/05/extracting-zip-from-embedded-resource-with-streams/</link>
		<comments>http://durdle.com/archives/2010/10/05/extracting-zip-from-embedded-resource-with-streams/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 11:41:06 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dotnetzip]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ionic]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://durdle.com/?p=846</guid>
		<description><![CDATA[I recently needed to extract files from a password protected zip that was a resource in a .NET application, without writing the zip file itself or the extracted files to the disk. The code fragment below is part of a method which gets the zip file from the resource as a stream, then uses the...]]></description>
			<content:encoded><![CDATA[<p>I recently needed to extract files from a password protected zip that was a resource in a .NET application, without writing the zip file itself or the extracted files to the disk.  The code fragment below is part of a method which gets the zip file from the resource as a stream, then uses the excellent <a href="http://dotnetzip.codeplex.com/">DotNetZip</a> library to open the stream and extract a specific compressed file to another stream for further processing.<span id="more-846"></span></p>
<p>In this case I&#8217;m loading SQL scripts from an AES encrypted zip and running them against a database.  The name of the resource (<code>bundle</code>) and the script (<code>scriptname</code>) I want to run have been passed in as strings.  <code>passwordForZip</code> is a string containing the password for the zip file.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// get the assembly and resource stream for our bundle</span>
Assembly _assembly<span style="color: #008000;">;</span>
_assembly <span style="color: #008000;">=</span> Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
Stream _zipFileStream<span style="color: #008000;">;</span>
_zipFileStream <span style="color: #008000;">=</span> _assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetManifestResourceStream</span><span style="color: #008000;">&#40;</span>bundle<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// use Ionic.Zip to open the zip file</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>ZipFile zipFile <span style="color: #008000;">=</span> ZipFile<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span>_zipFileStream<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// continue if the file exists in the zip</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>zipFile<span style="color: #008000;">.</span><span style="color: #0000FF;">EntryFileNames</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>scriptname<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// memoryStream and streamReader to load and parse the file</span>
		MemoryStream memoryStream <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemoryStream<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		StreamReader streamReader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #008000;">&#40;</span>memoryStream<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// load the script</span>
		ZipEntry zipEntry <span style="color: #008000;">=</span> zipFile<span style="color: #008000;">&#91;</span>scriptname<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// extract using the password, piping output to the memorystream</span>
		zipEntry<span style="color: #008000;">.</span><span style="color: #0000FF;">ExtractWithPassword</span><span style="color: #008000;">&#40;</span>memoryStream, passwordForZip<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// seek to the beginning of the file,</span>
                <span style="color: #008080; font-style: italic;">// then read entire contents into string</span>
		memoryStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Seek</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, SeekOrigin<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		scriptText <span style="color: #008000;">=</span> streamReader<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadToEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// try and execute it, return false if failure, tidy up afterwards</span>
		<span style="color: #0600FF; font-weight: bold;">try</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServerConnection</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ExecuteNonQuery</span><span style="color: #008000;">&#40;</span>scriptText<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>SqlException exception<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			LogMessageToFile<span style="color: #008000;">&#40;</span>exception<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">finally</span>
		<span style="color: #008000;">&#123;</span>
			streamReader<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2010/10/05/extracting-zip-from-embedded-resource-with-streams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 escaping of request...]]></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; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> RcptToHandler<span style="color: #008000;">&#40;</span>ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #008080; font-style: italic;">// Get the recipient address as a lowercase string.</span>
<span style="color: #6666cc; font-weight: bold;">string</span> strRecipientAddress <span style="color: #008000;">=</span> rcptArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">RecipientAddress</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#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: #6666cc; font-weight: bold;">bool</span> exists <span style="color: #008000;">=</span> catchAllConfig<span style="color: #008000;">.</span><span style="color: #0000FF;">Banned</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>element <span style="color: #008000;">=&gt;</span> element <span style="color: #008000;">==</span> strRecipientAddress<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>exists<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#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: #008000;">.</span><span style="color: #0000FF;">RejectCommand</span><span style="color: #008000;">&#40;</span>CatchAllAgent<span style="color: #008000;">.</span><span style="color: #0000FF;">rejectResponse</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// No further processing.</span>
	<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#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; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var pair <span style="color: #0600FF; font-weight: bold;">in</span> catchAllConfig<span style="color: #008000;">.</span><span style="color: #0000FF;">AddressMap</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#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: #008000;">&#40;</span>pair<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	RoutingAddress emailAddress <span style="color: #008000;">=</span> pair<span style="color: #008000;">.</span><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; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>emailPattern<span style="color: #008000;">.</span><span style="color: #0000FF;">IsMatch</span><span style="color: #008000;">&#40;</span>strRecipientAddress<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// And if the recipient is NOT in the address book.</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">addressBook</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span>
			<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">addressBook</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Find</span><span style="color: #008000;">&#40;</span>rcptArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">RecipientAddress</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Redirect the recipient to the other address.</span>
			rcptArgs<span style="color: #008000;">.</span><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>
			<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#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>2</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...]]></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;"><span style="color: #993333; font-weight: bold;">EXEC</span> 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;"><span style="color: #993333; font-weight: bold;">EXEC</span> 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;"><span style="color: #993333; font-weight: bold;">EXEC</span> 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...]]></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>17</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)...]]></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 where a...]]></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>
	</channel>
</rss>

