<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0">

<channel>
	<title>Muffin Research Labs</title>
	
	<link>http://muffinresearch.co.uk</link>
	<description>the personal blog of Stuart Colville covering modern web development techniques and best practices</description>
	<lastBuildDate>Wed, 11 Nov 2009 11:57:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/muffinres/skimmed" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Spotify: Linking to a specific time in a track</title>
		<link>http://muffinresearch.co.uk/archives/2009/11/11/spotify-linking-to-a-specific-time-in-a-track/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/11/11/spotify-linking-to-a-specific-time-in-a-track/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 11:56:10 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[social]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=757</guid>
		<description><![CDATA[For a while I&#8217;ve wanted to be able to share a link to a track on spotify so that it jumps the right place. An example is when learning covers for the band I play in; or just to point out a great part of the track.
The good new is that this is already possible! [...]]]></description>
			<content:encoded><![CDATA[<p>For a while I&#8217;ve wanted to be able to share a link to a track on spotify so that it jumps the right place. An example is when learning covers for the band I play in; or just to point out a great part of the track.</p>
<p>The good new is that this is already possible! I asked a question on <a href="http://getsatisfaction.com/spotify/topics/allow_linking_to_a_point_into_a_track">Get Satisfaction</a> and a Spotify employee Emil Hesslow answered straight away that this feature already exists. Here&#8217;s some examples:</p>
<ul class="ext">
<li>Check out George Benson&#8217;s guitar break: <a href="http://open.spotify.com/track/39Bi2scq80BWdgnxz2llWT%2304%3A04">Uncle Albert/Admiral Halsey 4:04</a></li>
<li>A Nice hammond organ break from Greg Rolie: <a href="http://open.spotify.com/track/6s3pzloNKkO3dzZaHaKaoi%230%3A46">Toussaint L&#8217;Overture 0:46</a></li>
</ul>
<p>You can also use the spotify protocol:</p>
<p>e.g: <a href="spotify:track:39Bi2scq80BWdgnxz2llWT#04:04">spotify:track:39Bi2scq80BWdgnxz2llWT#04:04</a></p>
<p>The format for the link is just a simple fragment identifier added to the end of the link in the format #mins:secs e.g: #4:04</p>
<p>From using this (I&#8217;m running Spotify under wine) I&#8217;ve found you need to URLencode this in the &#8220;http://open.spotify&hellip;&#8221; links for it to work so #4:04 becomes %2304%3A04.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zEtHn01s0OI:nTcP5J0tXvk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zEtHn01s0OI:nTcP5J0tXvk:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zEtHn01s0OI:nTcP5J0tXvk:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zEtHn01s0OI:nTcP5J0tXvk:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/11/11/spotify-linking-to-a-specific-time-in-a-track/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Application Security – LugRadio Live 2009</title>
		<link>http://muffinresearch.co.uk/archives/2009/11/01/web-application-security-lugradio-live-2009/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/11/01/web-application-security-lugradio-live-2009/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 11:04:32 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Slides]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=745</guid>
		<description><![CDATA[These are my slides from the presentation I gave at LugRadio Live 2009 at Wolverhampton. The presentation was a brief tour of some common security issues you might come across developing web applications. I also covered ReDOS which is a lot less well known but an interesting vulnerability.
The notes are available on slideshare.net

View more presentations [...]]]></description>
			<content:encoded><![CDATA[<p>These are my slides from the presentation I gave at LugRadio Live 2009 at Wolverhampton. The presentation was a brief tour of some common security issues you might come across developing web applications. I also covered ReDOS which is a lot less well known but an interesting vulnerability.</p>
<p>The <a href="http://www.slideshare.net/muffinresearch/security-presentation-2437395">notes are available on slideshare.net</a></p>
<div style="width:425px;text-align:left" id="__ss_2437395"><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=security-presentation-091106061759-phpapp02&#038;stripped_title=security-presentation-2437395" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=security-presentation-091106061759-phpapp02&#038;stripped_title=security-presentation-2437395" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/muffinresearch">Stuart  Colville</a>.</div>
</div>
<p><del datetime="2009-11-06T12:23:17+00:00">I&#8217;ve had to pull the presentation from slideshare.net temporarily &#8211; I&#8217;ll re-upload as soon as possible</del> <ins datetime="2009-11-06T12:23:17+00:00">The problem at slideshare has now been resolved.</ins></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=1n85StSPqPg:sV3FSoVF76g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=1n85StSPqPg:sV3FSoVF76g:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=1n85StSPqPg:sV3FSoVF76g:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=1n85StSPqPg:sV3FSoVF76g:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/11/01/web-application-security-lugradio-live-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu: Lock Screen and Pause Spotify</title>
		<link>http://muffinresearch.co.uk/archives/2009/10/22/ubuntu-lock-screen-and-pause-spotify/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/10/22/ubuntu-lock-screen-and-pause-spotify/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 16:23:00 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux/Unix]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=719</guid>
		<description><![CDATA[When I used a mac I had a shonky little applescript to pause iTunes when I locked the screen. 
These days I mostly listen to Spotify (running under wine) on Ubuntu which of course doesn&#8217;t have applescript. What I wanted was a similar script so I can hit a keystroke and pause spotify and lock [...]]]></description>
			<content:encoded><![CDATA[<p>When I used a mac I had a shonky little <a href="http://muffinresearch.co.uk/archives/2008/04/24/mac-tip-lock-screen-and-pause-itunes/">applescript to pause iTunes when I locked the screen</a>. </p>
<p>These days I mostly listen to Spotify (running under wine) on Ubuntu which of course doesn&#8217;t have applescript. What I wanted was a similar script so I can hit a keystroke and pause spotify and lock the screen at the same time.</p>
<p>With a few utilities I was able to programatically tell if Spotify is playing and get focus on the Spotify window and send a keystroke to get spotify to pause. But the solution it has to be said is far from perfect.</p>
<p>The need to know if Spotify is actively playing is as a result of there only being a play/pause toggle activated by spacebar. Without testing this locking the screen with Spotify already paused and open would result in it starting when you lock the screen.</p>
<p>You&#8217;ll need the following packages installed to get it to work:</p>
<pre><code>sudo apt-get install wmctrl xvkbd</code></pre>
<p>wmctrl is a window manager CLI tool and xvkbd is a vitual keyboard that also has a CLI interface to send keystrokes.</p>
<p>Here&#8217;s the script:</p>
<pre><code>#!/usr/bin/env bash

# By Stuart Colville
# http://muffinresearch.co.uk/archives/2009/10/22/ubuntu-lock-screen-and-pause-spotify/
# sudo apt-get install wmctrl xvkbd

# Check the title in the window list to work out if it's playing
TITLE=$(wmctrl -l | grep -o -e "Spotify.*$")

# If it's playing pause it
if [[ "$TITLE" != Spotify ]]; then
    wmctrl -a "Spotify" &#038;&#038; xvkbd -q -delay 100 -text '\ '
fi

# Lock the screen
gnome-screensaver-command --lock

exit 0
</code></pre>
<p>Save it somewhere and make it executable e.g. <code>chmod +x ~/bin/lock_screen.sh</code>.</p>
<p>If you want it to work on a keycombo then just add an item to System -> Preference -> Keyboard Shortcuts</p>
<p><del datetime="2009-10-23T08:51:25+00:00">Known Issue: A problem I&#8217;ve spotted is that locking the screen causes Spotify to start playing if it&#8217;s open and paused. So I need to add a way to detect if Spotify is currently playing without which this script is pretty much useless.</del> <ins datetime="2009-10-23T08:51:25+00:00"><del datetime="2009-10-23T11:28:04+00:00">Fixed with libinotify-tools</del></ins></p>
<p><del datetime="2009-10-23T11:22:27+00:00">The <strong>EPIC Hack</strong> here is using libinotify to detect if Spotify is playing by watching file accesses to the Storage directory. Can&#8217;t help but feeling there&#8217;s got to be a better way. It also means that a delay of 5 secs is needed to wait for an event.</del> &#8211; <ins datetime="2009-10-23T11:22:27+00:00"><em>There was a better way!</em> This is now done by interogating the window list via wmctrl</ins></p>
<p>Updates and suggestions are welcomed.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=xIxbLC9Tnr0:w2RFrJPJPe8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=xIxbLC9Tnr0:w2RFrJPJPe8:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=xIxbLC9Tnr0:w2RFrJPJPe8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=xIxbLC9Tnr0:w2RFrJPJPe8:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/10/22/ubuntu-lock-screen-and-pause-spotify/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Redirects and Phishing Vectors</title>
		<link>http://muffinresearch.co.uk/archives/2009/09/30/open-redirects-and-phishing-vectors/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/09/30/open-redirects-and-phishing-vectors/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 22:43:52 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=471</guid>
		<description><![CDATA[There was an interesting article on the Google Webmaster Central blog back in Jan talking about open redirects being abused by spammers.
One point they didn&#8217;t go into too much detail on is that of phishing vectors. If you&#8217;re running a site with any kind of user registration and you have a redirect script that allows [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://muffinresearch.co.uk/i/redirect-attack2.png"><img class="bord" src="http://muffinresearch.co.uk/i/open-redirect.jpg" alt="Open Redirect Phishing Vector Diagram" height="291" width="540" /></a></p>
<p>There was an interesting article on the <a href="http://googlewebmastercentral.blogspot.com/2009/01/open-redirect-urls-is-your-site-being.html">Google Webmaster Central blog</a> back in Jan talking about open redirects being abused by spammers.</p>
<p>One point they didn&#8217;t go into too much detail on is that of phishing vectors. If you&#8217;re running a site with any kind of user registration and you have a redirect script that allows redirects to any arbitrary urls. Then it&#8217;s fairly likely that you&#8217;ve straight away made it possible for a 3rd party to phish your registration form.</p>
<p>Let&#8217;s see an example of how something like this would work, first a standard redirection script:</p>
<dl class='tb'>
<dt>Target Site</dt>
<dd>buyeverythingawesome.com</dd>
<dt>Attack URL</dt>
<dd>http://buyeverythingawesome.com/redirect?url=http://buyeverythingawesome<strong>e</strong>.com/login/</dd>
<dt>Attacker&#8217;s Bogus Domain</dt>
<dd>buyeverythingawesome<strong>e</strong>.com</dd>
</dl>
<p>The target site has a script which blindly redirects to anything passed to it.</p>
<p>All the attacker has to do is send a victim an email telling them to login to their account to view the latest offers. The link they send is <code>http://buyeverythingawesome.com/redirect?url=http://buyeverythingawesomee.com/login/</code></p>
<p>On the bogus domain the attacker will have prepared a copy of the site&#8217;s login screen. All they need to do is get the user to login and then redirect the user back to the original site and if possible directly to the failed login page of the original site.</p>
<p>The way to mitigate this is to only allow redirects to your internal site or provide a whitelist of external urls that are allowed to be redirected to. </p>
<h3>Open Redirect Login Script</h3>
<p>Open Redirects in a login script are even worse in a way as the attacker will send the user to  the real site&#8217;s login script.</p>
<p>The symptoms of this kind of problem are visible with a setup like so:</p>
<dl class="tb">
<dt>Target Site</dt>
<dd>buyeverythingawesome.com</dd>
<dt>Attack URL</dt>
<dd>http://someawesomsite.com/login?after=http//:some<strong>w</strong>awesomsite.com/loginfailed/</dd>
<dt>Attacker&#8217;s Bogus Domain</dt>
<dd>some<strong>w</strong>awesomsite.com</dd>
</dl>
<p>All the attacker needs to do is to get the unwitting victim to visit <code>http://someawesomsite.com/login?after=http://some<strong>w</strong>awesomsite.com/loginfailed/</code></p>
<p>The user will be presented with the login screen for the genuine site. Once they login they are redirected to a bogus site with a &#8220;Your login has failed message &#8211; please try again&#8221; simply copied from the real site. The second time the user logs in they are logging-in to a bogus copy of the real site. Once the credentials are stolen the user can be redirected back to the real site where they are successfully logged in (This is because they aren&#8217;t redirected until they sucessfully login).</p>
<p>This is particularly nasty because the start and end points of this hack <em>are</em> the genuine site and as a result this kind of attack is much more likely to slip by unnoticed.</p>
<p>As a picture speaks a thousand words see this diagram of the flow: <a href="http://muffinresearch.co.uk/i/redirect-attack2.png">Open Redirect Phishing Vector (.png)</a></p>
<h3>Preventing these kind of attacks</h3>
<p>Firstly make absolutely sure you only allow redirects to internal links or whitelisted sites. If you need to redirect to arbitrary sites an interstitial page might be necessary to make it absolutely clear that the user is being redirected to a third party.</p>
<p>You might think that your site is already checking that links redirected are only internal ones. However it&#8217;s crucial that you take care to check more than just validating that the url starts with a slash.</p>
<h4>Check you&#8217;ve covered all eventualities</h4>
<p>It&#8217;s possible to write a link as  <code>//foo.com</code> and the scheme (http/https etc) will be inherited from the base <acronym title="Uniform Resource Identifier">URI</acronym>. So if you&#8217;re on <code>http://baz.com</code> and there&#8217;s a link with an  href attribute of <code>//google.com</code> this will resolve to <code>http://google.com</code>. It&#8217;s therefore important that any validation of redirect URLs covers this case or you could be caught out. </p>
<p>Note: If you&#8217;re interested this aspect of how URIs work is covered by <a href="http://labs.apache.org/webarch/uri/rfc/rfc3986.html#reference-examples">examples given in rfc 3986</a></p>
<p>As an example<code> http://has-open-redirect.com/login/?done=//google.com</code> would redirect to <code>http://google.com</code> after login if vulnerable.</p>
<h3>Why is any of this important?</h3>
<p>Right now you&#8217;re probably thinking that there&#8217;s nothing behind the login to your site that a hacker would want.</p>
<p>However, have you stopped to consider that your users might also use the same username and password to login to their amazon account for example?</p>
<p>Lot&#8217;s of people will only have one username and password for every site they use (<a href="http://www.infosecurity-magazine.com/view/3779/many-people-use-same-password-on-all-websites-says-cpp/">this infosecurity magazine article claims 46% of all UK adults us the same password</a>). If it&#8217;s possible to phish accounts on a low profile site &#8211; the chances are there will come a point when the attacker will hit the jackpot and get access to every site that user frequents with same username and password. </p>
<p class="update">Update: The GMail team has a nice post detailing some good <a href="http://gmailblog.blogspot.com/2009/10/choosing-smart-password.html">tips for choosing a good password</a>. Tip number one is don&#8217;t use the same password for all sites</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zH2S9iuIkDQ:vGZill7Lu2o:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zH2S9iuIkDQ:vGZill7Lu2o:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zH2S9iuIkDQ:vGZill7Lu2o:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=zH2S9iuIkDQ:vGZill7Lu2o:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/09/30/open-redirects-and-phishing-vectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Distraxion</title>
		<link>http://muffinresearch.co.uk/archives/2009/09/16/distraxion/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/09/16/distraxion/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 12:01:28 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[humour]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=686</guid>
		<description><![CDATA[Brilliant animation &#8211; and nails exactly how I feel about Smooth Jazz. via BoingBoing
]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/uxezt4Ks5XA&#038;hl=en&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/uxezt4Ks5XA&#038;hl=en&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Brilliant animation &#8211; and nails exactly how I feel about Smooth Jazz. via <a href="http://www.boingboing.net/2009/09/15/animated-short-about.html">BoingBoing</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Wio8SwQW-Tc:ZO5f_Jlw7Nc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Wio8SwQW-Tc:ZO5f_Jlw7Nc:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Wio8SwQW-Tc:ZO5f_Jlw7Nc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Wio8SwQW-Tc:ZO5f_Jlw7Nc:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/09/16/distraxion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross Platform Keyring Library for Python</title>
		<link>http://muffinresearch.co.uk/archives/2009/08/26/cross-platform-keyring-library-for-python/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/08/26/cross-platform-keyring-library-for-python/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 10:18:46 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=673</guid>
		<description><![CDATA[Kang Zhang has been busy on a Google Summer of Code project to create a cross platform keychain library for Python.
The Python keyring lib provides a easy way to access the system keyring service from python. It can be used in any application that needs safe password storage. It supports OSX, KDE, Gnome and Windows&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://kangzhang.org/">Kang Zhang</a> has been busy on a Google Summer of Code project to create a cross platform keychain library for Python.</p>
<blockquote><p>The Python keyring lib provides a easy way to access the system keyring service from python. It can be used in any application that needs safe password storage. It supports OSX, KDE, Gnome and Windows&#8217;s native password storing services. Besides this, it is shipped with kinds of Python implemented keyring for the left environments.</p>
</blockquote>
<p>It&#8217;s also been written in a way that makes it possible to create your own Keyring backend if you want to. </p>
<p>As this provides a native Python interface to the OSX keychain I&#8217;d certainly recommend looking at this over and above my own noddy OSX keychain wrapper. </p>
<p>Good stuff!</p>
<p>See the site for more info: <a href="http://home.python-keyring.org">http://home.python-keyring.org</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=vhsGqexvI1g:aohU_D0NgUc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=vhsGqexvI1g:aohU_D0NgUc:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=vhsGqexvI1g:aohU_D0NgUc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=vhsGqexvI1g:aohU_D0NgUc:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/08/26/cross-platform-keyring-library-for-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Multiple DNS Queries Using fopen</title>
		<link>http://muffinresearch.co.uk/archives/2009/08/12/php-multiple-dns-queries-using-fopen/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/08/12/php-multiple-dns-queries-using-fopen/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 18:03:16 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=660</guid>
		<description><![CDATA[Whilst working on some inherited PHP code that used fopen I noticed an interesting comment in the PHP manual which pointed out that fopen always makes a DNS lookup for every request. Taking the following code as an example:
&#60;?php
$handle = fopen("http://muffinresearch.co.uk/robots.txt", "r");
$contents = stream_get_contents($handle); // PHP5+ ONLY
echo $contents;
?&#62;
Using wireshark for capturing and calling that script [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst working on some inherited PHP code that used <code>fopen</code> I noticed an interesting <a href="http://uk3.php.net/manual/en/function.fopen.php#73132">comment</a> in the PHP manual which pointed out that fopen always makes a DNS lookup for every request. Taking the following code as an example:</p>
<pre><code>&lt;?php
$handle = fopen("http://muffinresearch.co.uk/robots.txt", "r");
$contents = stream_get_contents($handle); // PHP5+ ONLY
echo $contents;
?&gt;</code></pre>
<p>Using <a href="http://www.wireshark.org/">wireshark</a> for capturing and calling that script 3 times I got 3 DNS lookups because fopen doesn&#8217;t make use of any DNS lookup caches:</p>
<p><img src="http://muffinresearch.co.uk/i/fopen-wireshark.png" alt="Wireshark dialogue showing 3 DNS queries for muffinresearch.co.uk" /></p>
<p>Not only is this a problem for fopen but I also found the same problem with file_get_contents too.</p>
<p>The comment in the manual suggests using <code>gethostbyname</code> which uses the DNS cache. You can then use this to provide the ip address in the arguments to fopen. However as soon as you&#8217;re trying to fetch something which uses name-based virtual hosts this approach will fail. This is due to there being several sites on the same server all being served on the same ip address; if you contact the server by ip address it will simply serve you content from the default virtual host which is the conf which happens to be first alphabetically.</p>
<h3>A Solution</h3>
<p>The  cURL library (php5-curl is the package you&#8217;ll need on Ubuntu) <em>is</em> the preferred way of fetching content with PHP, mainly because it gives you far greater control over requests.</p>
<p>The other big benefit of using  cURL is that it makes use of the DNS cache so we can save a DNS lookup for repetitive calls to the same hostname:</p>
<pre><code>&lt;?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://muffinresearch.co.uk/robots.txt");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    echo $output;
    curl_close($ch);
?&gt;</code></pre>
<p>Running that script three times now results in only one DNS request (I manually cleared the DNS cache with <code>sudo /etc/init.d/networking restart</code> first)</p>
<p><img class="bord" src="http://muffinresearch.co.uk/i/wireshark-curl.png" alt="Wireshark dialogue showing 1 DNS query for muffinresearch.co.uk" /></p>
<h3>Conclusion</h3>
<p>If you&#8217;re using php to fetch data from the web cURL is a much more powerful solution than relying on <code>fopen</code> or <code>file_get_contents</code>. Not only that if you&#8217;re fetching a lot of data from the same hosts frequently your scripts will run faster as a result of only making the minimum DNS requests.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=G_smyk6yj60:ImROEmx8o-4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=G_smyk6yj60:ImROEmx8o-4:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=G_smyk6yj60:ImROEmx8o-4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=G_smyk6yj60:ImROEmx8o-4:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/08/12/php-multiple-dns-queries-using-fopen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>VirtualBox: Error: Cannot register the hard disk</title>
		<link>http://muffinresearch.co.uk/archives/2009/07/23/virtualbox-error-cannot-register-the-hard-disk/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/07/23/virtualbox-error-cannot-register-the-hard-disk/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 10:27:08 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux/Unix]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=653</guid>
		<description><![CDATA[If when cloning VirtualBox VMs you get an error like this:
$ VBoxManage clonehd WinXP-IE7.vdi WinXP-IE8.vdi
VirtualBox Command Line Management Interface Version 2.2.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

ERROR: Cannot register the hard disk '/home/scol/.VirtualBox/VDI/WinXP-IE7.vdi' with UUID {3858b1b1-c306-4505-8264-235af812f337} because a hard disk '/home/scol/.VirtualBox/VDI/WinXP-IE7.vdi' with UUID {3858b1b1-c306-4505-8264-235af812f337} already exists in the media registry ('/home/scol/.VirtualBox/VirtualBox.xml')
Details: code NS_ERROR_INVALID_ARG (0x80070057), component [...]]]></description>
			<content:encoded><![CDATA[<p>If when cloning VirtualBox VMs you get an error like this:</p>
<pre><code>$ VBoxManage clonehd WinXP-IE7.vdi WinXP-IE8.vdi
VirtualBox Command Line Management Interface Version 2.2.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

ERROR: Cannot register the hard disk '/home/scol/.VirtualBox/VDI/WinXP-IE7.vdi' with UUID {3858b1b1-c306-4505-8264-235af812f337} because a hard disk '/home/scol/.VirtualBox/VDI/WinXP-IE7.vdi' with UUID {3858b1b1-c306-4505-8264-235af812f337} already exists in the media registry ('/home/scol/.VirtualBox/VirtualBox.xml')
Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
Context: "OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, srcDisk.asOutParam())" at line 603 of file VBoxManageDisk.cpp</code></pre>
<p>Talk about a completely ambiguous error message! The solution is to provide an absolute path to the source VDI and target VDIs (leaving the path off the target will put the image in ~/.VirtualBox/HardDisks by default):</p>
<pre><code>$ VBoxManage clonehd $(pwd)/WinXP-IE7.vdi $(pwd)/WinXP-IE8.vdi
VirtualBox Command Line Management Interface Version 2.2.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VDI'. UUID: b7166421-9743-4808-aedf-3c90aeb7c902</code></pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=eyFhEcuYRyY:u4EU2NlXX3A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=eyFhEcuYRyY:u4EU2NlXX3A:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=eyFhEcuYRyY:u4EU2NlXX3A:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=eyFhEcuYRyY:u4EU2NlXX3A:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/07/23/virtualbox-error-cannot-register-the-hard-disk/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Project Fondue Blog</title>
		<link>http://muffinresearch.co.uk/archives/2009/07/14/project-fondue-blog/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/07/14/project-fondue-blog/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 11:16:16 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Project Fondue]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=650</guid>
		<description><![CDATA[Last weekend I was in Paris with Cyril and Ed spending some time on Project Fondue Projects. One of the things we got done was putting out the initial iteration of the Project Fondue Blog. This is based on Pocoo&#8217;s Zine which we&#8217;ve really enjoyed using. The only downside so far is that it&#8217;s dependencies [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend I was in Paris with Cyril and Ed spending some time on Project Fondue Projects. One of the things we got done was putting out the initial iteration of the <a href="http://blog.projectfondue.com/">Project Fondue Blog</a>. This is based on <a href="http://zine.pocoo.org/">Pocoo&#8217;s Zine</a> which we&#8217;ve really enjoyed using. The <em>only</em> downside so far is that it&#8217;s dependencies are quite cutting edge so if you are sticking to older Debian based distros (in our case Hardy LTS) it&#8217;s a case of pulling together the necessary packages from Debian Repos.</p>
<p>I&#8217;d certainly recommend subscribing to the <a href="http://blog.projectfondue.com/feed.atom">rss feed</a> &#8211; as there will be some interesting posts coming up. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Nj5l5R4-gNU:QEHmdVJ3YHM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Nj5l5R4-gNU:QEHmdVJ3YHM:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Nj5l5R4-gNU:QEHmdVJ3YHM:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Nj5l5R4-gNU:QEHmdVJ3YHM:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/07/14/project-fondue-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BASH: Using brace expansion</title>
		<link>http://muffinresearch.co.uk/archives/2009/06/22/bash-using-brace-expansion/</link>
		<comments>http://muffinresearch.co.uk/archives/2009/06/22/bash-using-brace-expansion/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 22:17:47 +0000</pubDate>
		<dc:creator>Stuart Colville</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux/Unix]]></category>

		<guid isPermaLink="false">http://muffinresearch.co.uk/?p=642</guid>
		<description><![CDATA[There&#8217;s a nice feature of BASH which is to use a comma delimited list of strings inside of curly braces to reduce the amount of typing:
here&#8217;s an example of using brace expansion to create log files for apache:
sudo touch {access,error}.log
Something seen less often is a blank entry like so:
cp foo{,.bck}
Which is shorthand for cp foo [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a nice feature of BASH which is to use a comma delimited list of strings inside of curly braces to reduce the amount of typing:</p>
<p>here&#8217;s an example of using brace expansion to create log files for apache:</p>
<pre><code>sudo touch {access,error}.log</code></pre>
<p>Something seen less often is a blank entry like so:</p>
<pre><code>cp foo{,.bck}</code></pre>
<p>Which is shorthand for <code>cp foo foo.bck</code>. This is really useful when copying and moving files around using long paths. Using brace expansion can minimise the amount of typing and help avoid errors caused by typos too.</p>
<p>Another use of brace expansion since BASH v3.0 is the possibility of using ranges within the lists like so:</p>
<pre><code>for foo in {1..10}
> do
> echo $foo
> done
1
2
3
4
5
6
7
8
9
10</code></pre>
<p>Or alternatively with letters too:</p>
<pre><code>echo {a..f}
a b c d e f
</code></pre>
<p>See the <a href="http://tldp.org/LDP/abs/html/special-chars.html#BRACEEXPREF">advanced bash scripting guide</a> for more examples.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Cr5w5QigONg:HttqPeBnEvk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Cr5w5QigONg:HttqPeBnEvk:2nqncYFp4_M"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2nqncYFp4_M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Cr5w5QigONg:HttqPeBnEvk:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/muffinres/skimmed?a=Cr5w5QigONg:HttqPeBnEvk:2mJPEYqXBVI"><img src="http://feeds.feedburner.com/~ff/muffinres/skimmed?d=2mJPEYqXBVI" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://muffinresearch.co.uk/archives/2009/06/22/bash-using-brace-expansion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.536 seconds -->
