<?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>Breaking Systems for Fun and Profit &#187; Squid Squalor</title>
	<atom:link href="http://breakingsystemsforfunandprofit.com/archives/tag/squid/feed" rel="self" type="application/rss+xml" />
	<link>http://breakingsystemsforfunandprofit.com</link>
	<description>You _can_ stop the signal.</description>
	<lastBuildDate>Mon, 17 May 2010 09:58:45 +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>The Lolcats, they are everywhere!</title>
		<link>http://breakingsystemsforfunandprofit.com/archives/118</link>
		<comments>http://breakingsystemsforfunandprofit.com/archives/118#comments</comments>
		<pubDate>Fri, 07 Aug 2009 07:57:18 +0000</pubDate>
		<dc:creator>Mule</dc:creator>
				<category><![CDATA[Squid Squalor]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://breakingsystemsforfunandprofit.com/?p=118</guid>
		<description><![CDATA[All your images are belong to cheezburger. Or regrubzeehC if you prefer]]></description>
			<content:encoded><![CDATA[<p>Do you use squid? Are your users under-appreciating the blissful goodness that is the LOLcat? Feel like educating them a bit? Add or replace the following line in <code>/etc/squid/squid.conf</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">url_rewrite_program <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-u</span> <span style="color: #660033;">-r</span> s<span style="color: #000000; font-weight: bold;">!</span>^<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>^<span style="color: #7a0874; font-weight: bold;">&#91;</span>:space:<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span>jp<span style="color: #7a0874; font-weight: bold;">&#40;</span>e<span style="color: #7a0874; font-weight: bold;">&#41;</span>?g<span style="color: #000000; font-weight: bold;">|</span>gif<span style="color: #000000; font-weight: bold;">|</span>png<span style="color: #000000; font-weight: bold;">|</span>tiff<span style="color: #000000; font-weight: bold;">|</span>bmp<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;">*</span><span style="color: #007800;">$!</span>http:<span style="color: #000000; font-weight: bold;">//</span>icanhascheezburger.files.wordpress.com<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2009</span><span style="color: #000000; font-weight: bold;">/</span>04<span style="color: #000000; font-weight: bold;">/</span>funny-pictures-cat-is-on-your-computer.jpg<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>Enterprising bofh&#8217;s could use a script to download the referred image, modify it, place it somewhere in <code>/var/www/html</code> and have the rewritten url point to the new bastardised image for extra credit, like <a href="http://ex-parrot.com/~pete/upside-down-ternet.html">this guy</a> did.</p>
<p>It takes a bit more work, so let&#8217;s go over the steps:<br />
Make sure you&#8217;ve got a webserver running on the same box as your proxy<br />
Add/modify this line in <code>/etc/squid/squid.conf</code></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">url_rewrite_program <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>squid<span style="color: #000000; font-weight: bold;">/</span>mirror.sh</pre></div></div>

<p>Now make <code>/var/www/html</code> writable by the <code>squid</code> user:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">setfacl <span style="color: #660033;">-m</span> u:squid:rwx <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>html</pre></div></div>

<p>And last but not least add this file as <code>/etc/squid/mirror.sh</code> and make it executable:</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>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> URL
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #007800;">SURL</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${URL}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #ff0000;">&quot; &quot;</span> -f1<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${SURL}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-qi</span> <span style="color: #ff0000;">&quot;\.(jp(e)?g|gif|png|tiff|bmp|ico)$&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>
        <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">umask</span> 002
         <span style="color: #007800;">PIC</span>=<span style="color: #007800;">$$</span>-<span style="color: #800000;">${RANDOM}</span>
         <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${PIC}</span> <span style="color: #800000;">${SURL}</span>
         convert <span style="color: #660033;">-quiet</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${PIC}</span> <span style="color: #660033;">-flop</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>html<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${PIC}</span>.png <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>;
            <span style="color: #7a0874; font-weight: bold;">echo</span> http:<span style="color: #000000; font-weight: bold;">//</span>127.0.0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${PIC}</span>.png
        <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$URL</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>The end result:<a class="lightbox" title="moc.elgoog" href="http://breakingsystemsforfunandprofit.com/wp-content/uploads/2009/08/elgoog.png"><img class="aligncenter size-medium wp-image-124" title="moc.elgoog" src="http://breakingsystemsforfunandprofit.com/wp-content/uploads/2009/08/elgoog-300x229.png" alt="" width="300" height="229" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://breakingsystemsforfunandprofit.com/archives/118/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
