Zap Annoyances on the Web, Part II

Using AdZapper to block many ads and Web bugs.

Read Part I of this article here.

Now it's time to block some of those ads and Web bugs. I'm sure you have all heard the saying, “If it ain't broke, don't fix it.” Well, we're going to ignore that piece of advice completely and change our perfectly working Squid configuration. As mentioned above, Squid gives us the ability to redirect requests made from a browser to a secondary program and then process the results of that program. That program may return the original request (signified by a blank line), modify the request in some way or return something completely different. This functionality is completely transparent to the user—all you see is the end result. As you can guess, our next step is to modify our Squid installation to use a redirector.

The redirector we are going to use is called AdZapper (adzapper.sourceforge.net). AdZapper is a program that intercepts requests for many ads and Web bugs and replaces them with a request for placeholder images. The intercepted requests never get sent out to the Internet once the placeholder images are cached in Squid, saving you time while protecting you from Web bugs and other types of ads that track your path while you browse the Internet.

The first installation step is to download the AdZapper script from adzapper.sourceforge.net/scripts/squid_redirect. We save this script as /usr/bin/squid_redirect for this article, but you can place it in a different location if you want.

The next step is to find out where your Perl executable is located. You can do this by typing the command which perl in a terminal window. If you do not get back /usr/bin/perl, you need to update the first line of the squid_redirect file to match the location of Perl on your machine. If this is necessary, change the first line of the file from #!/usr/bin/perl to the location of your Perl executable. Be sure to leave the leading #! with no space before your path. After the file is set up properly, make it executable by typing chmod 777 /usr/bin/squid_redirect in a terminal window as root.

Now we tell Squid to use this program to filter our Web requests. Edit the /etc/squid/squid.conf once again (be sure you are doing this as root). Search for the line that reads:

#  TAG: redirect_program

Right below the explanation of this tag there's two lines that say:

#Default:
# none

Remove these two lines and replace them with the following:

redirect_program /usr/bin/squid_redirect

If you did not save your script as /usr/bin/squid_redirect, you now need to change the above line to reflect the location of your script file.

It's time to test our new configuration. Restart Squid with the command /etc/init.d/squid restart, and browse to bannerblind.mozdev.org/testpage.html. If you do not have the Flash browser plugin installed, press Cancel when prompted to get the plugin. After the page loads you should see something similar to Figure 1. The original page can be seen in Figure 2. If you see the images that read This Ad Zapped, you've configured Squid to use AdZapper correctly. AdZapper does much more than blocking ads based on size; it also blocks requests based on the patterns at the bottom of the squid_redirect file.

Figure 1. The AdZapper Test Page with Ads Zapped

Figure 2. The Original AdZapper Test Page

So far we've streamlined our browsing experience significantly. We've also eliminated pop-ups and other JavaScript annoyances. But what if that's not enough? Let's take a look at the popular site Slashdot (slashdot.org). What if you don't want to view the images on the page, say the Slashdot logo and the images to search on the current topics?

This is where Mozilla's built-in ad blocking capabilities come in. To block images from a site, simply right-click on an image from the site you wish to block and choose Block Images from this Server. To see what Slashdot looks like after blocking the images, see Figure 3. Now that's a speedy download. Reversing this behavior is easy, too; right-click where the image usually would be and choose Unblock Images from this Server. You also can manage image permissions from the menu option under Tools→Image Manager→Manage Image Permissions. This screen can be seen in Figure 4. Blocking images in this manner also comes in handy when AdZapper misses ads. Mozilla doesn't hide images only from servers that have been blocked, but it also does not make the request at all. This has all the same advantages as AdZapper concerning speed and privacy.

Figure 3. Make your favorite sites load faster by blocking unneeded images.

Figure 4. This Mozilla dialog lets you decide from which sites you want to see images.

If you do encounter pages where AdZapper is not blocking ads as it should, please consider e-mailing the maintainer of AdZapper with the page and image that was missed. You can find his e-mail address at the top of your /usr/bin/squid_redirect script. You can choose to receive e-mails when AdZapper is updated by joining the mailing list. Details can be found on AdZapper's home page.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Zap Annoyances on the Web, Part II

Anonymous's picture

If you want annoyance (ad, flash, ..) blocking on a personal basis, I highly recommend the program Privoxy.There has been some problems with breaking pages historically, but most has been fixed in the latest version. It is available for a lot of operating systems, including packages for all Linux distros and a very easy installer for win32. All you need to configure is the "proxy" setting of your web browser.

Re: Zap Annoyances on the Web, Part II

Anonymous's picture

If you want annoyance (ad, flash, ..) blocking on a personal basis, I highly recommend the program Privoxy.

You can also chain privoxy in to your squid proxy by adding a "forward" directive to your /etc/privoxy/config file to get the best of both worlds:

forward / 127.0.0.1:3128

Squid will cache for you and privoxy will clean and anonymize your web requests.

Small Security Problem with the squid_redirect file

fmerenda's picture

Many thanks to Ziyad A. M. AL-Batly, who pointed out that the permissions for /usr/bin/squid_redirect should be '755' and not '777'.

Take care,
-Frank Merenda

This stuff is

Anonymous's picture

This stuff is hilarious.....waaaaaay too tough to get it working.

Got squid. Got squidGuard. Got redirect_squid thingie.....AND NONE OF IT WORKS right.

This is way too freaking hard for a regular user to get. I'm very disappointed in how hard it is to configure.

Why does this have to be so hard? why so much command line to get it going?.....yep, very very frustrated.

linux

Anonymous's picture

its obious ur not use to linux at all.expecally linux servers. with all the comandline it gives you more flexiblity then windows ever could or with any gui every could.