So I’ve been messing around with Squid recently. One of the features I had planned to add was the ability to fall back to Coral Cache if the web site that Squid is trying to cache goes down.

So I wrote this little redirector script in PHP:

Stuff this in /etc/squid/coralcache.redirect and make it executable (chmod a+rwx /etc/squid/coralcache.redirect):

#!/usr/bin/php
<?
        /* Coral Cache on 404/No Server */

        $t=array();
        while($input=fgets(STDIN)){
                ob_start();
                $t=split(' ',$input);
                $url = $t[0];
                $ch = curl_init($url);
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,false);
                curl_setopt($ch,CURLOPT_VERBOSE,false);
                $ci = @curl_exec($ch);
                $status = @curl_getinfo($ch);
                ob_end_clean();
                if($status["http_code"] > 400){
                        $uriparts = explode('/',$url);
                        $uriparts[2] = rtrim($uriparts[2]) . ".nyud.net";
                        echo "302:" . implode('/',$uriparts) . "\n";
                }
        }

Then, at the top of your squid.conf;

redirect_program /etc/squid/coralcache.redirect

Restart squid, and all unavailable pages should now redirect to Coral Cache. =)

3 Comments

  1. Squid + iptables = UPSIDEDOWNTERNET

  2. Haha, you’ve got me researching ideas with Squid redirectors and ImageMagick now.

    Starting point being here — http://ex-parrot.com/~pete/upside-down-ternet.html

  3. Hmm upside down internet sounds mildly interesting.

    Do it do it turn the numptynet upside down.

    We think its waterproof but is it still waterproof when upside down ??.


Post a Comment

*
*