<?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>Guy Rutenberg</title>
	<atom:link href="http://www.guyrutenberg.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Sat, 21 Aug 2010 11:44:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>spass-2.0 &#8211; Secure Password Generator</title>
		<link>http://www.guyrutenberg.com/2010/08/21/spass-2-0-secure-password-generator/</link>
		<comments>http://www.guyrutenberg.com/2010/08/21/spass-2-0-secure-password-generator/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 11:44:14 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[spass]]></category>
		<category><![CDATA[c/c++]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=717</guid>
		<description><![CDATA[This is a complete rewrite of my secure password generator. The new version uses my a true random number generator (and here). The major change was using the new true random number generator in order to ensure strong passwords. Less significant changes include an easy way to specify password&#8217;s strips, and some calling convention changes. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a complete rewrite of my <a href="/2008/05/04/spass-11-secure-password-generator/">secure password generator</a>. The new version uses my a <a href="/2010/08/13/statistical-tests-for-my-audio-based-random-number-generator/">true random number generator</a> (and <a href="/2010/05/14/audio-based-true-random-number-generator-poc/">here</a>).</p>
<p>The major change was using the new true random number generator in order to ensure strong passwords. Less significant changes include an easy way to specify password&#8217;s strips, and some calling convention changes.</p>
<p>Usage examples:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">$ ./spass
E5pT35Fg
$ ./spass -l 14
R$tfOm4g_yRQ2J
$ ./spass -s 0-9a-f -l 32
8b5f14a1eeaabe58c2878ab5416a9ebb</pre></div></div>

<p>Download the tarball <a href="/wp-content/uploads/2010/08/spass-2.0.tar.bz2"><code>spass-2.0.tar.bz2</code></a>. The program depends on <a href="http://www.boost.org/">Boost</a>&#8216;s program_options (it was tested against version 1.37 and 1.42 and should work with other versions too).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/08/21/spass-2-0-secure-password-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Statistical Tests for My Audio Based Random Number Generator</title>
		<link>http://www.guyrutenberg.com/2010/08/13/statistical-tests-for-my-audio-based-random-number-generator/</link>
		<comments>http://www.guyrutenberg.com/2010/08/13/statistical-tests-for-my-audio-based-random-number-generator/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 21:37:25 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[c/c++]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=699</guid>
		<description><![CDATA[In May I&#8217;ve written about a way to generate random number from audio noise. Basically it went like this: Get audio sample from the microphone. Push the least significant bit to a buffer. Repeat steps 1-2 until the buffer is full (buffer size == block size for the hash function). Apply the hash function on [...]]]></description>
			<content:encoded><![CDATA[<p>In May I&#8217;ve written about a <a href="/2010/05/14/audio-based-true-random-number-generator-poc/"> way to generate random number from audio noise</a>. Basically it went like this:</p>
<ol>
<li> Get audio sample from the microphone.</li>
<li>Push the least significant bit to a buffer.</li>
<li>Repeat steps 1-2 until the buffer is full (buffer size == block size for the hash function).</li>
<li>Apply the hash function on the buffer.</li>
<li>Get random bits from the digest.</li>
</ol>
<p>In order to continue developing this random number generator (RNG), I&#8217;ve written a C++ class that simplifies working with it.<br />
<span id="more-699"></span></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/*
 * Copyright (C) 2010  Guy Rutenberg
 * http://www.guyrutenberg.com
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */</span>
&nbsp;
<span style="color: #339900;">#include &lt;cstdio&gt;</span>
<span style="color: #339900;">#include &quot;md5.h&quot;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Grandom <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
		Grandom<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">virtual</span> ~Grandom<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #ff0000; font-style: italic;">/**
		 * Generate a random dword
		 */</span>
		uint32_t operator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
		<span style="color: #0000ff;">void</span> gather_entropy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">void</span> get_block<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">FILE</span><span style="color: #000040;">*</span> m_dsp_fd<span style="color: #008080;">;</span>
		uint32_t m_index<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">union</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">char</span> digest<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
			uint32_t v<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span> m_buffer<span style="color: #008080;">;</span>
&nbsp;
		md5_ctx m_md5_ctx<span style="color: #008080;">;</span>
		uint32_t m_block<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">512</span><span style="color: #000040;">/</span><span style="color: #0000dd;">32</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The <code>Grandom</code> class uses MD5 as the hash function, 16-bit samples and 44.1KHz sampling rate. This configuration should work well on any modern sound card. The full implementation is available in <a href="/wp-content/uploads/2010/08/grandom-1.0.tar.bz2"><code>grandom-1.0.tar.bz2</code></a>, which is a small test app.</p>
<p>To have some evidence for the quality of the random number generation I&#8217;ve tested it against <a href="http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html">NIST&#8217;s statistical test suite</a>. I&#8217;ve tested 320 streams of 1M bits each. The results showed that the random number generator passed all of the tests but one (one of the non-overlapping pattern test, although it was very close to pass). If you wan to see the results, take a look at the <a href="/wp-content/uploads/2010/08/finalAnalysisReport.txt">final analysis report</a>.</p>
<p>Overall, <code>Grandom</code> seems to be a good way to generate small amounts of high quality random numbers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/08/13/statistical-tests-for-my-audio-based-random-number-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting Comments from Tickets in Trac</title>
		<link>http://www.guyrutenberg.com/2010/05/19/deleting-comments-from-tickets-in-trac/</link>
		<comments>http://www.guyrutenberg.com/2010/05/19/deleting-comments-from-tickets-in-trac/#comments</comments>
		<pubDate>Wed, 19 May 2010 12:42:06 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Trac]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=684</guid>
		<description><![CDATA[Spammers apparently love Trac. After trying to fighting spam tickets and later installing the SpamFilter plugin, I&#8217;ve managed to control spam tickets in the Open Yahtzee Trac site.. But now spammers started spamming in the ticket comments. The bad news is that Trac (at least in version 0.11) doesn&#8217;t have built-in facilities to completely remove [...]]]></description>
			<content:encoded><![CDATA[<p>Spammers apparently love Trac. After trying to fighting spam <a href="/2009/01/08/deleting-a-range-of-tickets-in-trac/">tickets</a> and later installing the SpamFilter plugin, I&#8217;ve managed to control spam tickets in the <a href="http://www.openyahtzee.org">Open Yahtzee</a> Trac site.. But now spammers started spamming in the ticket comments. The bad news is that Trac (at least in version 0.11) doesn&#8217;t have built-in facilities to completely remove ticket comments.</p>
<p><a href="http://www.guyrutenberg.com/wp-content/uploads/2010/05/trac-comment.png"><img src="http://www.guyrutenberg.com/wp-content/uploads/2010/05/trac-comment.png" alt="" title="trac-comment" width="509" height="311" class="aligncenter size-full wp-image-688" /></a><br />
<span id="more-684"></span><br />
The solution is to directly delete them from Trac&#8217;s SQLite backend. There are several type of comments: Plain ones and comments that describe a change to the ticket&#8217;s properties. I&#8217;ll deal with only the plain comments, but the methods I describe should also be applicable to the other kinds.</p>
<p>First things you should note down the ticket number and the comment number. The comment number appears in the URL of the permalink to it. It is the number that is pointed by an arrow in the screenshot above, it will be displayed when you hover over the circled link. Now in the shell, <code>cd</code> to the <code>db</code> directory of you trac installation and do:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sqlite3 trac.db &quot;delete from ticket_change where ticket=&lt;TICKET NUM&gt; and field='comment' and oldvalue=&lt;COMMENT NUM&gt;&quot;</pre></div></div>

<p>For example for the ticket in the screenshot:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sqlite3 trac.db &quot;delete from ticket_change where ticket=12 and field='comment' and oldvalue=3&quot;</pre></div></div>

<p>You can delete different kinds of tickets by using other values in the <code>field</code> column, such as <code>keywords</code> and <code>summary</code>. Another useful column is the <code>author</code> column.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/05/19/deleting-comments-from-tickets-in-trac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Audio Based True Random Number Generator POC</title>
		<link>http://www.guyrutenberg.com/2010/05/14/audio-based-true-random-number-generator-poc/</link>
		<comments>http://www.guyrutenberg.com/2010/05/14/audio-based-true-random-number-generator-poc/#comments</comments>
		<pubDate>Fri, 14 May 2010 12:18:14 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=678</guid>
		<description><![CDATA[Few days ago I came up with an idea to create a true random number generator based on noise gathered from a cheap microphone attached to my computer. Tests showed that when sampling the microphone, the least significant bit behaves pretty randomly. This lead me to think it might be good source for gathering entropy [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I came up with an idea to create a true random number generator based on noise gathered from a cheap microphone attached to my computer. Tests showed that when sampling the microphone, the least significant bit behaves pretty randomly. This lead me to think it might be good source for gathering entropy for a true random number generator.<br />
<span id="more-678"></span><br />
The base design was to gather the noise from the microphone than apply a process that will make in more uniform and refine its randomness. After some design iterations I came up with a process based on applying a hash function to the noise. Each iteration involves filling block of the hash function from the least significant bits of the microphone output and applying the hash. Each iteration outputs the current hash digest. Assuming the hash function is uniform, this will output a uniformly distributed blocks of bits. Furthermore, because there the previous state of the hash function influences the next digest computation, the process accumulates entropy that can smooth out potentially less random blocks. Because for all commonly used hash function the block size is much larger than the digest size the output can tell much about the current state or any future or past state. This also holds true even if someone can find all pre-images of the hash function as the amount of possible states will be too big.</p>
<p>I&#8217;ve built a Python proof of concept (using md5 as a hash function) suitable for Linux.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">struct</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> GRandom:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">audio</span> = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/dev/dsp&quot;</span>,<span style="color: #483d8b;">&quot;rb&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span> = hashlib.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_raw_block<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        buffer = <span style="color: #008000;">self</span>.<span style="color: black;">audio</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">block_size</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
        <span style="color: #dc143c;">bytes</span> = <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%iB&quot;</span><span style="color: #66cc66;">%</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>buffer<span style="color: black;">&#41;</span>, buffer<span style="color: black;">&#41;</span>
&nbsp;
        longs = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">block_size</span>/<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>:
            temp = <span style="color: #ff4500;">0</span>
            <span style="color: #ff7700;font-weight:bold;">for</span> b <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">bytes</span><span style="color: black;">&#91;</span>i<span style="color: #66cc66;">*</span><span style="color: #ff4500;">32</span>:<span style="color: black;">&#40;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">32</span><span style="color: black;">&#93;</span>:
                temp = <span style="color: black;">&#40;</span>temp <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> ^ <span style="color: black;">&#40;</span>b <span style="color: #66cc66;">&amp;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
            longs.<span style="color: black;">append</span><span style="color: black;">&#40;</span>temp<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%iI&quot;</span><span style="color: #66cc66;">%</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>longs<span style="color: black;">&#41;</span>, <span style="color: #66cc66;">*</span>longs<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_block<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">get_raw_block</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The amount of generated bits per second is given by (sample rate)*(digest size)/(block size). So for 8KHz (default) sampling rate and md5 we&#8217;ll get a theoretical speed of 2000b/s. SHA type hashes have higher digest to block size ration thus may result in higher speeds. Another source of speed up may be to change the sample rate of the microphone. But setting it too high may have negative effects on the entropy. The code may get a considerable performance gain by porting it to c/c++, as it uses both bit manipulations and calculates hashes. Anyways, even the Python implementation&#8217;s speed allows us it be used for many cases where true randomness is required, such as generating passwords.</p>
<p><strong>Update 2010-08-07</strong> I&#8217;ve corrected the speed calculation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/05/14/audio-based-true-random-number-generator-poc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python&#8217;s base64 Module Fails to Decode Unicode Strings</title>
		<link>http://www.guyrutenberg.com/2010/05/03/pythons-base64-module-fails-to-decode-unicode-strings/</link>
		<comments>http://www.guyrutenberg.com/2010/05/03/pythons-base64-module-fails-to-decode-unicode-strings/#comments</comments>
		<pubDate>Mon, 03 May 2010 18:18:24 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=672</guid>
		<description><![CDATA[If you&#8217;ve got a base64 string as a unicode object and you try to use Python&#8217;s base64 module with altchars set, it fails with the following error: TypeError: character mapping must return integer, None or unicode This is pretty unhelpful error message also occurs if you try any method that indirectly use altchars. For example: [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve got a <code>base64</code> string as a <code>unicode</code> object and you try to use Python&#8217;s <a href="http://docs.python.org/library/base64.html"><code>base64</code></a> module with <code>altchars</code> set, it fails with the following error:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">TypeError: character mapping must return integer, None or unicode</pre></div></div>

<p>This is pretty unhelpful error message also occurs if you try any method that indirectly use <code>altchars</code>. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #dc143c;">base64</span>.<span style="color: black;">urlsafe_b64decode</span><span style="color: black;">&#40;</span><span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'aass'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">base64</span>.<span style="color: black;">b64decode</span><span style="color: black;">&#40;</span><span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'aass'</span><span style="color: black;">&#41;</span>,<span style="color: #483d8b;">'-_'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>both fail while the following works:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #dc143c;">base64</span>.<span style="color: black;">urlsafe_b64decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'aass'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">base64</span>.<span style="color: black;">b64decode</span><span style="color: black;">&#40;</span><span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'aass'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>While it&#8217;s not complicated to fix it (just convert any <code>unicode</code> string to <code>ascii</code> string), it&#8217;s still annoying.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/05/03/pythons-base64-module-fails-to-decode-unicode-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL-Safe Timestamps using Base64</title>
		<link>http://www.guyrutenberg.com/2010/04/30/url-safe-timestamps-using-base64/</link>
		<comments>http://www.guyrutenberg.com/2010/04/30/url-safe-timestamps-using-base64/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 17:08:56 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=667</guid>
		<description><![CDATA[Passing around timestamps in URLs is a common task. We usually want our URLs to be as shortest as possible. I&#8217;ve found using Base64 to result in the shortest URL-safe representation, just 6 chars. This compares with the 12 chars of the naive way, and 8 chars when using hex representation. The following Python functions [...]]]></description>
			<content:encoded><![CDATA[<p>Passing around timestamps in URLs is a common task. We usually want our URLs to be as shortest as possible. I&#8217;ve found using Base64 to result in the shortest URL-safe representation, just 6 chars. This compares with the 12 chars of the naive way, and 8 chars when using hex representation.</p>
<p>The following Python functions allow you to build and read these 6 chars URL-safe timestamps:<br />
<span id="more-667"></span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">base64</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">struct</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> build_timestamp<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Return a 6 chars url-safe timestamp
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">base64</span>.<span style="color: black;">urlsafe_b64encode</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;!L&quot;</span>,<span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> read_timestamp<span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Convert a 6 chars url-safe timestamp back to time
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;!L&quot;</span>,<span style="color: #dc143c;">base64</span>.<span style="color: black;">urlsafe_b64decode</span><span style="color: black;">&#40;</span>t+<span style="color: #483d8b;">&quot;==&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span></pre></div></div>

<p>These functions work by translating the timestamp into a 4-byte binary form and then encoding it using a URL-safe version of Base64. And finally we strip the padding, which is neither URL-safe nor necessary (as we know the size of the encoded data).</p>
<p>The result looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">In [72]: build_timestamp()
Out[72]: 'S9sNOQ'</pre></div></div>

<p>We got a timestamp in using only 6 URL-safe chars.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/04/30/url-safe-timestamps-using-base64/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash Puppy 0.2</title>
		<link>http://www.guyrutenberg.com/2010/03/31/hash-puppy-0-2/</link>
		<comments>http://www.guyrutenberg.com/2010/03/31/hash-puppy-0-2/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 21:15:06 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Hash Puppy]]></category>
		<category><![CDATA[QT]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=656</guid>
		<description><![CDATA[This is an update for my simple easy-to-use checksum calculator. It supports md4, md5, and sha1 hash functions. I wrote the project as a way to experience and learn Qt. Changes since the previous version (Hash Puppy 0.1) include ability to abort a checksum calculation and improved GUI responsiveness. Also there were other minor tweaks [...]]]></description>
			<content:encoded><![CDATA[<p>This is an update for my simple easy-to-use checksum calculator. It supports md4, md5, and sha1 hash functions. I wrote the project as a way to experience and learn Qt.<br />
<img src="http://www.guyrutenberg.com/wp-content/uploads/2010/03/hashpuppy-0.2.png" alt="" title="hashpuppy-0.2" width="565" height="205" class="aligncenter size-full wp-image-661" /><br />
Changes since the previous version (<a href="/2009/05/29/hash-puppy-a-qt-checksum-calculator/">Hash Puppy 0.1</a>) include ability to abort a checksum calculation and improved GUI responsiveness. Also there were other minor tweaks to make Hash Puppy easier to use.<br />
<span id="more-656"></span><br />
The software is available under the GPL license.<br />
Source code: <a href="/wp-content/uploads/2010/03/hashpuppy-0.2.tar.gz">hashpuppy-0.2.tar.gz</a><br />
Binary for Windows: <a href="/wp-content/uploads/2010/03/hashpuppy-0.2.zip">hashpuppy-0.2.zip</a> (Compiled against Qt 4.6.2).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/03/31/hash-puppy-0-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improved FTP Backup for WordPress</title>
		<link>http://www.guyrutenberg.com/2010/02/28/improved-ftp-backup-for-wordpress/</link>
		<comments>http://www.guyrutenberg.com/2010/02/28/improved-ftp-backup-for-wordpress/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 06:38:44 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[backup]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=637</guid>
		<description><![CDATA[This script backups both the database and files of a WordPress blog into a remote FTP server (while keeping a local copy). It&#8217;s an update of my WordPress Backup to FTP script. The main changes are auto-detecting database settings and better support for caching plugins (specifically WP-Cache). The new version makes it easier to backup [...]]]></description>
			<content:encoded><![CDATA[<p>This script backups both the database and files of a WordPress blog into a remote FTP server (while keeping a local copy). It&#8217;s an update of my <a href="/2009/01/06/wordpress-backup-to-ftp/">WordPress Backup to FTP</a> script. The main changes are auto-detecting database settings and better support for caching plugins (specifically WP-Cache). The new version makes it easier to backup multiple WordPress blogs to the same FTP server.<br />
<span id="more-637"></span><br />
Usage is pretty simple after a short initial configuration. First, save the the script and make it executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x wp-backup</pre></div></div>

<p>(assuming you saved it under the name <code>wp-backup</code>). After saving it edit the file with your favorite editor and set the 5 configuration variable to whatever is appropriate for you. <code>BACKUP_DIR</code> is the folder to save the local backups to. <code>FTP_HOST</code>, <code>FTP_USER</code>, <code>FTP_PASS</code> control the FTP host, username and password, respectively, for the remote backup server. <code>FTP_BACKUP_DIR</code> sets the folder on the FTP server to save the remote backup to.</p>
<p>Now that the initial configuration is done, all you need to do is execute the script and give the path to the blog as an argument. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>wp-backup <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>someuser<span style="color: #000000; font-weight: bold;">/</span>myblog</pre></div></div>

<p>And that it, the script will backup your files (excluding cache) and database to both a local and remote locations. This allows using the same script to backup multiple WordPress blogs, unlike the previous script which had to be modified for each blog.</p>
<p>And now the script itself:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Copyright 2008, 2010 Guy Rutenberg &lt;http://www.guyrutenberg.com/contact-me&gt;</span>
<span style="color: #666666; font-style: italic;"># WordPress FTP backup 2.0</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Easily backup wordpress instances via ftp.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Change Log:</span>
<span style="color: #666666; font-style: italic;"># ===========</span>
<span style="color: #666666; font-style: italic;"># 2.0:</span>
<span style="color: #666666; font-style: italic;">#  - Auto-detect database settings.</span>
<span style="color: #666666; font-style: italic;">#  - Exclude cache data from backups.</span>
&nbsp;
<span style="color: #007800;">BACKUP_DIR</span>=
<span style="color: #007800;">FTP_HOST</span>=
<span style="color: #007800;">FTP_USER</span>=
<span style="color: #007800;">FTP_PASS</span>=
<span style="color: #007800;">FTP_BACKUP_DIR</span>=
&nbsp;
<span style="color: #666666; font-style: italic;"># end of configuration - you probably don't need to touch anything bellow</span>
&nbsp;
<span style="color: #007800;">PROG</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;$0&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
print_usage <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;USAGE: <span style="color: #007800;">${PROG}</span> [options] BLOG_ROOT&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup a WordPress blog&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_usage
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
&nbsp;
Options:
    -h, --help          show this help message and exit
&nbsp;
EOF</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">TEMP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">getopt</span> <span style="color: #660033;">-o</span> h <span style="color: #660033;">--long</span> <span style="color: #7a0874; font-weight: bold;">help</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROG</span>&quot;</span> <span style="color: #660033;">--</span> <span style="color: #ff0000;">&quot;$@&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$?</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    print_usage
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">--</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TEMP</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span> ; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        -h<span style="color: #000000; font-weight: bold;">|</span>--help<span style="color: #7a0874; font-weight: bold;">&#41;</span> print_help; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">;;</span>
        --<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">shift</span>; <span style="color: #7a0874; font-weight: bold;">break</span><span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 print_usage <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>stderr
 <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">BLOG_DIR</span>=$<span style="color: #000000;">1</span>
<span style="color: #007800;">DB_NAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&lt;?php require_once(<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">${BLOG_DIR}</span>/wp-config.php<span style="color: #000099; font-weight: bold;">\&quot;</span>); echo DB_NAME;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> php<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">DB_USER</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&lt;?php require_once(<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">${BLOG_DIR}</span>/wp-config.php<span style="color: #000099; font-weight: bold;">\&quot;</span>); echo DB_USER;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> php<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">DB_PASS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&lt;?php require_once(<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">${BLOG_DIR}</span>/wp-config.php<span style="color: #000099; font-weight: bold;">\&quot;</span>); echo DB_PASSWORD;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> php<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">DB_HOST</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&lt;?php require_once(<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">${BLOG_DIR}</span>/wp-config.php<span style="color: #000099; font-weight: bold;">\&quot;</span>); echo DB_HOST;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> php<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">BLOG_DIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$BLOG_DIR</span>&quot;</span><span style="color: #000000; font-weight: bold;">`/`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$BLOG_DIR</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">BACKUP_DIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$BACKUP_DIR</span>&quot;</span><span style="color: #000000; font-weight: bold;">`/`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$BACKUP_DIR</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;dumping database... &quot;</span>
<span style="color: #007800;">DUMP_NAME</span>=<span style="color: #800000;">${DB_NAME}</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.sql.bz2
mysqldump <span style="color: #660033;">--user</span>=<span style="color: #800000;">${DB_USER}</span> <span style="color: #660033;">--password</span>=<span style="color: #800000;">${DB_PASS}</span> <span style="color: #660033;">--host</span>=<span style="color: #800000;">${DB_HOST}</span> \
 <span style="color: #660033;">--databases</span> <span style="color: #800000;">${DB_NAME}</span> \
 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bzip2</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #800000;">${BACKUP_DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${DUMP_NAME}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed!&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Creating tarball... &quot;</span>
<span style="color: #007800;">TAR_NAME</span>=<span style="color: #800000;">${BLOG_DIR##*/}</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.bz2
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-cjf</span> <span style="color: #800000;">${BACKUP_DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${BLOG_DIR##*/}</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.bz2 <span style="color: #660033;">--exclude</span> cache <span style="color: #800000;">${BLOG_DIR}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed!&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Uploading SQL dump and tarball to FTP... &quot;</span>
lftp <span style="color: #660033;">-u</span> <span style="color: #800000;">${FTP_USER}</span>,<span style="color: #800000;">${FTP_PASS}</span> <span style="color: #800000;">${FTP_HOST}</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF
cd &quot;${FTP_BACKUP_DIR}&quot;
put &quot;${BACKUP_DIR}/${DUMP_NAME}&quot;
put &quot;${BACKUP_DIR}/${TAR_NAME}&quot;
&nbsp;
EOF</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed!&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">3</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/02/28/improved-ftp-backup-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>&#8220;CC Yourself&#8221; and Spam</title>
		<link>http://www.guyrutenberg.com/2010/02/09/cc-yourself-and-spam/</link>
		<comments>http://www.guyrutenberg.com/2010/02/09/cc-yourself-and-spam/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 21:27:33 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Spam]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=624</guid>
		<description><![CDATA[Every good web programmer will note that the following contact form markup is probably flawed &#60;form&#62; ... &#60;input type=&#34;hidden&#34; name=&#34;to&#34; value=&#34;support@example.com&#34; /&#62; ... &#60;/form&#62; as it is likely that if the value of the &#8220;to&#8221; field changes the message will be sent to the modified address. The problem with this kind of functionality is that [...]]]></description>
			<content:encoded><![CDATA[<p>Every good web programmer will note that the following contact form markup is probably flawed</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form&gt;
...
    &lt;input type=&quot;hidden&quot; name=&quot;to&quot; value=&quot;support@example.com&quot; /&gt;
...
&lt;/form&gt;</pre></div></div>

<p>as it is likely that if the value of the &#8220;to&#8221; field changes the message will be sent to the modified address. The problem with this kind of functionality is that it allows a malicious user to send emails from your mail server. More specifically,  it can allow spammers to user your benign server t send their spam (and as a side effect you might be flagged as a spammer yourself).</p>
<p>As this case is pretty obvious one doesn&#8217;t see many real-life uses of it anymore (but careless programmers used it more often n the past until they learned better). However one can achieve similar goals (spam-wise) by utilizing a common feature in contact forms: the &#8220;CC yourself&#8221; checkbox.<br />
<a href="http://www.guyrutenberg.com/wp-content/uploads/2010/02/contact_form.png"><img src="http://www.guyrutenberg.com/wp-content/uploads/2010/02/contact_form.png" alt="" title="CC Yourself" width="425" height="320" class="aligncenter size-full wp-image-632" /></a><br />
<span id="more-624"></span><br />
&#8220;CC yourself&#8221;  is a convention used by some people when mailing, to verify that the email was indeed sent. It had found a place in many contact forms, as people wanted a way to make sure the form indeed works. But contact forms (as well as some mail servers) don&#8217;t verify that the email provided as the &#8220;from&#8221; is indeed owned by whoever fills the form. Combine that with the fact that many contact forms don&#8217;t employ CAPTCHAs (to make the form simpler to use), and you&#8217;ll get a situation much like the one discussed above.</p>
<p>In the first case there was a usability advantage to the programmer (who could easily re-use the form&#8217;s backend for other forms), which can be easily sacrificed for enhanced security. This time it&#8217;s worse as this is a usability feature for the user, which many people believe to be very convinient in contact forms.</p>
<p>I think there are several solutions possible:</p>
<ol>
<li>Adding CAPTCHA to the form. This will make life for the spammers harder, but it also hurt the users by raising the bar for filling out the form. Also, nowadays, it getting harder and harder to find a strong yet easy for humans CAPTCHA.</li>
<li>Removing the &#8220;CC yourself&#8221; feature. this hurts the usability of the contact form.</li>
<li>Seperating verified users and unverified. Keeping the feature for registered users, but at the same time, removing it or adding CAPTCHA for unverified users. This seems like a good trade-off, but it requires more work and registration is not applicable for all websites.</li>
</ol>
<p>In my opinion none of the solutions is perfect. It seems that once again spammers hurt the user experience for everybody else in order to fill our inboxes with unsolicited email.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/02/09/cc-yourself-and-spam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MusicBrainz when Ripping CDs in KDE</title>
		<link>http://www.guyrutenberg.com/2010/01/09/using-musicbrainz-when-ripping-cds-in-kde/</link>
		<comments>http://www.guyrutenberg.com/2010/01/09/using-musicbrainz-when-ripping-cds-in-kde/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 08:37:29 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[KDE]]></category>
		<category><![CDATA[MusicBrainz]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=610</guid>
		<description><![CDATA[I guess this tip is Gentoo specific. By default KDE uses FreeDB for getting CD info when ripping CDs. If you want to use MusicBrainz native service (not via their FreeDB proxy), there are several steps you&#8217;ll need to take. First, you should compile kde-base/libkcddb with the musicbrainz use-flag turned on. Next you should go [...]]]></description>
			<content:encoded><![CDATA[<p>I guess this tip is Gentoo specific. By default KDE uses FreeDB for getting CD info when ripping CDs. If you want to use MusicBrainz native service (not via their FreeDB proxy), there are several steps you&#8217;ll need to take.<br />
<span id="more-610"></span><br />
First, you should compile <code>kde-base/libkcddb</code> with the <code>musicbrainz</code> use-flag turned on. Next you should go to System Settings->Advanced->CDDB Retrieval and check the &#8220;Enable MusicBrainz lookup&#8221; box. From my experience MusicBrainz is not a complete replacement for FreeDB as some CDs aren&#8217;t recognized by it (but recognized by FreeDB). </p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/01/09/using-musicbrainz-when-ripping-cds-in-kde/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.155 seconds -->
<!-- Cached page served by WP-Cache -->
