Skip to main content

How To Make a WiFi Network That Only Transmits Cat Pictures With A Raspberry Pi

It’s a common use case scenario: you want to broadcast a public WiFi network for anyone to use, but you’ve got strict requirements that only cat images be permitted. Great news: your Raspberry Pi is a perfect transmoggification machine. Intrigued? Read on.

This project starts out identical to the Onion Router we built a few weeks back. We’ll make the Raspberry Pi into a standard WiFi network first, then place a proxy in the middle. The proxy will be filtering posts through a Perl script, which will replace the images on every HTTP request with cat GIFs from TheCatAPI.com. Watch as befuddled users are both intensely frustrated, yet strangely calmed. Here’s the BBC, post-cat modifications.
post cat bbc1   How To Make a WiFi Network That Only Transmits Cat Pictures With A Raspberry Pi

Making a WiFi Network

Since this part of the tutorial is exactly the same as the DIY Onion Router, please follow the instructions there up to the point of Install Tor.
The only small change we need to make is to broadcast an open WiFi network instead of one secured with WPA. Once you’ve followed the setup there, change /etc/hostapd/hostapd.conf, pasting in the following configurations instead. Restart to apply the changes.
interface=wlan0
driver=nl80211
ssid=Kittens
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0
You should now have a wireless network being broadcasted on your Raspberry Pi that’s publicly accessible. The rest of this guide will focus on getting the interesting stuff happening.
If things aren’t working, type:
ifconfig -a
and look for an IP address on wlan0. If one isn’t being assigned on reboot, try the following:
sudo nano /etc/default/ifplugd
Change the following lines from:
INTERFACES="auto"
HOTPLUG_INTERFACES="all"
to:
INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
Reboot, and verify you’re able to connect to the WiFi network, and access the Internet.

Squid Proxy and IPTables

Start by installing the prerequisites, then create a new routing table. We’ll be serving images from the Raspberry Pi later, so we’ll also need Apache web-server.
sudo apt-get install squid3 bridge-utils apache perl
nano iptables.sh
Paste the following:
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -t nat -A PREROUTING -i wlan0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.42.1:3128
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
Save, then exit.
chmod +x iptables.sh
sudo cp iptables.sh /etc/init.d/
sudo update-rc.d iptables.sh start 99
iptable sh error   How To Make a WiFi Network That Only Transmits Cat Pictures With A Raspberry Pi
Ignore the warnings, it just means we haven’t complied with some Debian rules (but doesn’t break anything). Lastly, we still have the old iptables rules on boot, so remove the following line from /etc/network/interfaces
up iptables-restore < /etc/iptables.ipv4.nat
(Delete or comment it out)
Then restart. Next We’ll delete the default Squid proxy config, and make a fresh one.
sudo rm /etc/squid3/squid.conf
sudo nano /etc/squid3/squid.conf
Paste the following into the blank file:
cache_mgr pi
cachemgr_passwd pi all
redirect_program /home/pi/cats.pl
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 192.168.42.0/24 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128 transparent
umask 022
cache_mem 128 MB
cache_dir ufs /var/spool/squid3 1500 16 256
coredump_dir /var/spool/squid3
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
Save and exit. Initialise the cache directories with the following command, then edit the script we’ll use to catify all the images:
sudo squid3 -z
nano /home/pi/cats.pl
Paste in:
#!/usr/bin/perl
$|=1;
$count = 0;
$pid = $$;

open (DEBUG, '>>/tmp/cats.log');
autoflush DEBUG 1;
 
print DEBUG "########################################################################\n";

while (<>) {
        chomp $_;
        if (m/nosquid/) {
              print DEBUG "Input NOSQUID: $url\n";
              print "$_\n";
              print DEBUG "Output NOSQUID: $_\n";
        }
        elsif ($_ =~ /(.*\.jpg)/i) {
                $url = $1;
                print DEBUG "Input: $url\n";
                system("/usr/bin/wget", "-q", "-O","/var/www/images/$pid-$count.gif", "http://thecatapi.com/api/images/get?format=src&type=gif&nosquid");
                chmod 0777,"/var/www/images/$pid-$count.gif";
                print "http://127.0.0.1/images/$pid-$count.gif\n";
        }
        elsif ($_ =~ /(.*\.gif)/i) {
                $url = $1;
                print DEBUG "Input: $url\n";
                system("/usr/bin/wget", "-q", "-O","/var/www/images/$pid-$count.gif", "http://thecatapi.com/api/images/get?format=src&type=gif&nosquid");
                chmod 0777,"/var/www/images/$pid-$count.gif";
                print "http://127.0.0.1/images/$pid-$count.gif\n";
        }
        elsif ($_ =~ /(.*\.png)/i) {
                $url = $1;
                print DEBUG "Input: $url\n";
                system("/usr/bin/wget", "-q", "-O","/var/www/images/$pid-$count.gif", "http://thecatapi.com/api/images/get?format=src&type=gif&nosquid");
                chmod 0777,"/var/www/images/$pid-$count.gif";
                print "http://127.0.0.1/images/$pid-$count.gif\n";
        }
        elsif ($_ =~ /(.*\.jpeg)/i) {
                $url = $1;
                print DEBUG "Input: $url\n";
                system("/usr/bin/wget", "-q", "-O","/var/www/images/$pid-$count.gif", "http://thecatapi.com/api/images/get?format=src&type=gif&nosquid");
                chmod 0777,"/var/www/images/$pid-$count.gif";
                print "http://127.0.0.1/images/$pid-$count.gif\n"; 
        }
        else {
                print "$_\n";
        }
        $count++;
}

Make the script executable, and we also ned to make some directories for it to work with.
sudo chmod +x cats.pl
sudo mkdir /var/www/images
sudo chmod 777 /var/www/images
sudo usermod -a -G www-data proxy
sudo chown www-data:www-data /var/www
sudo chown www-data:www-data /var/www/images
touch /tmp/cats.log
chmod 777 /tmp/cats.log
You can tail the log at any time with:
tail -f /tmp/cats.log

Popular posts from this blog

Build Your Own Awesome Personal 3D Avatar with Avatara

Do you use social networks and want to build your own awesome 3D avatar? Maybe you want to send someone a cute cuddly image of yourself (kind of)? Or maybe you have your own ideas of what you would do with an Avatar… Well look no further than Avatara which I discovered from the MakeUseOf directory . You can create 3d avatars out of pre-set up templates or create your own from scratch. To start, visit Avatara’s homepage . You will see this screen: Click Get Started to umm, get started! That will take you to this screen: You see that you can build your own Avatar using an uploaded head shot like the Obama one above (just an example, guys). Or roll with one of their awesome avatars. I chose to start with a blank avatar by clicking Start with a blank avatar at the bottom of the screen. That takes you to here: I clicked on the filter at the top and told it to filter out everything but male characters and then I saw this: I rolled with Buck and continued. You need to click Select...

MoviePass drops pricing to under $7 per month, if you opt for the annual plan

MoviePass, the subscription service that lets consumers pay a monthly fee to see unlimited movies in theaters across the U.S., is slashing its prices yet again. The company announced today it’s now offering its service for $6.95 per month, down from the current price of $9.95 per month, when customers commit to a one-year subscription plan. That works out to a flat fee of $89.95 annually. The deal is a limited-time promotion, as opposed to a permanent pricing change, but MoviePass didn’t say how long the offer is valid. However, it is open to both new and existing subscribers – the latter who would receive a 25 percent savings on their current subscription if switching over to the annual plan. This is not the first time that MoviePass has dropped its pricing. When the company introduced its $9.95 per month, one-movie-per-day plan this August, down from $15 for 2 movies per month (or more in select markets like L.A. and NYC, and going as high as $50), it saw so many new sign-up...

ASUS VivoBook X202E Windows 8 Touchscreen Laptop Review And Giveaway

It wasn’t very long ago when prices of touchscreen Windows 8 laptops soared beyond $1000. Thankfully, those days are behind us, and portable computers can easily be purchased – touchscreen and all – for under $500. That’s precisely the demographic in which the ASUS VivoBook X202E falls. When compared to a high-end laptop, its specifications might seem modest, but for laptop buyers just looking for a way to browse the web, watch videos, use basic apps, and not spend too much money, something in this budget is perfectly suitable. The question is, of course, how does the ASUS VivoBook X202E compare to others on the market, and is it the one which you should be spending your hard-earned money on? Well, you’re just going to have to keep reading to find out. Best of all, we are giving away an ASUS VivoBook X202E to one lucky winner. Keep reading for your chance to take home this Windows 8 touchscreen laptop! Introducing the ASUS VivoBook X202E Laptop The ASUS VivoBook X202...