The wiki is currently undergoing some major improvements. If you need some information and you don't know where to look, please come to #ecnet

Pfsense-AprilFoolsDayHack

From ECNet Wiki
Jump to: navigation, search

Use this hack to flip or blur all images that go through the squid proxy. This is for pfSence 1.2.3. It may work on other versions but this is the only version I tested it on.

1) Install the squid package from the web interface.
2) Install ImageMagik with "pkg_add -r ImageMagick" either via SSH or "Execute Command" tab in the web interface.
3) Create /var/squid/redirect.py

#!/usr/bin/env python
import os, sys
import urllib, re, subprocess
outdir = '/usr/local/www/squidimages'
wwwpath = 'http://127.0.0.1/squidimages';
img_regex = re.compile(r'(?i).(jpg|jpeg|png|gif)$')
operation = '-flip' # mogrify -help for more options
operation = operation.split()
count = 0
while True:
        l = raw_input().split(' ')
        url = l[0]
        m = img_regex.search(url)
        if m:
                outname = '%d-%d.%s' % (os.getpid(), count, m.group(1))
                outpath = os.path.join(outdir, outname)
                count += 1
                try:
                        urllib.urlretrieve(url, outpath)
                        os.chmod(outpath, 0644)
                        subprocess.call(['/usr/local/bin/mogrify'] + operation + [outpath])
                        print '/'.join([wwwpath, outname])
                except (IOError, urllib.ContentTooShortError):
                        print url

        else:
                print url
        sys.stdout.flush()

4) chmod 755 /var/squid/redirect.py
5) mkdir /usr/local/www/squidimages
6) chmod 777 /usr/local/www/squidimages
7) Add to the Custom Options box in the squid package "url_rewrite_program /var/squid/redirect.py" and Save.

Note: Change "-flip" to "-blur 4" to get blurred images that are not as intrusive as flipped ones. Change 127.0.0.1 to your LAN IP address in redirect.py to use the transparent proxy with this hack. Also /usr/local/www/squidimages can get very large depending on how many users/websites go through your squid proxy. Clear it out regularly or make a cron script to do so.

Credits: http://www.debian-administration.org/users/johns/weblog/1