Zap Annoyances on the Web, Part I

April 29th, 2004 by Frank Merenda in

Get rid of annoying Web marketing and protect your privacy, using both the browser and a proxy server.
Your rating: None Average: 2.7 (3 votes)

Surfing the Web is something most of us do daily. At home I am on a dial-up connection, and I'm constantly looking for ways to make my browsing experience more efficient and to protect my privacy while on-line. The approach I describe here allows you to stop many ads, images, Web bugs and pop-up windows. In case you are not familiar with Web bugs, they are small graphics included on a Web site or in an e-mail that are used to track who is reading. Whether you are on a dial-up connection or a high-speed connection, the tools presented in this article are guaranteed to make your on-line browsing experience more enjoyable and to protect your personal habits from nosy marketers.

My environment consists of an IBM A31 ThinkPad with a 1.9GHz Pentium 4 Mobile CPU and 1GB of RAM running Fedora Core 1 (fedora.redhat.com). I am using Mozilla 1.5 (www.mozilla.org) as my Web browser.

The Approach

The approach we take here consists of the following three basic parts: Mozilla's image, JavaScript and pop-up window management capabilities; a proxy server to cache Web content; and a program to intercept requests for undesired content.

If you are not familiar with proxy servers, here's a quick overview. For the purpose of this article, we define a proxy server as an intermediate server used to intercept requests for Web pages and associated files. The proxy server either handles the request itself or passes the request on to another proxy server or to the original target. A proxy server can be transparent, intercepting all requests automatically. In our example we manually configure the browser to go through our proxy server. Proxy servers also can be used to proxy other types of requests, but that falls outside the scope of this article.

We are using Squid (www.squid-cache.org) as our proxy server. Squid is an extremely popular proxy server that's in use all over the world. Squid allows you to cache Web content locally, so instead of going out to the Internet for content you have previously downloaded, you can retrieve it from Squid's local cache. Squid is smart enough to know if content can be read from cache or if it must be updated from the originating Web site. If you are looking at a news site, for example, Squid knows that it needs to refresh the text on the site, but it usually loads the static images on the site from cache. Squid also gives us the ability to add in something called redirects, which intercept requests and possibly modify them in some way. For example, if you request an image that is known to be an advertisement, the intercept may return a placeholder image instead of the image requested, completely bypassing the request for the original image.

Implementing Our Solution

The first step is to set up Mozilla to block pop-up windows. The option to enable this feature can be found under Edit→Preferences→Privacy & Security→Popup Windows. You are greeted by the screen shown in Figure 1. Choosing the option to Block unrequested pop-up windows does exactly that. You can play a sound or display an icon when pop-ups are blocked if you so desire. There also is an option to allow pop-ups explicitly from certain sites. If you click on the button labeled Allowed Sites..., you are shown the screen in Figure 2. This feature is handy for sites that pop up external windows for things like showing progress for a long-running task. You can leave this list blank to start and add sites as you go.

Figure 1. Block unrequested pop-up windows from Mozilla.

Figure 2. You can permit pop-ups from sites that use them for legitimate purposes.

The second step is to configure Mozilla to manage JavaScript events. These settings can be found under Edit→Preferences→Advanced→Scripts & Plugins. Check boxes on this screen allow you to turn off JavaScript completely for your browser, mail and news readers. You also can keep JavaScript enabled and configure Mozilla to stop scripts from moving or resizing windows, raising or lowering windows, hiding or changing the statusbar, changing images, creating or changing cookies and reading cookies. The settings I use can be seen in Figure 3 and should work well for most situations.

Figure 3. Disable the JavaScript features that Webmasters use to create annoyances.

The next step is to tackle setting up our Squid proxy server. If you have never set up a proxy server before, have no fear; setting up Squid is much easier than you think. First, check to see if you have Squid already installed on your system. This can be done by typing which squid. If you get back a path to Squid you're all set. If not, you can download prebuilt RPMs from rpmfind.net/linux/rpm2html/search.php?query=squid&submit=Search+..., or download the source from www.squid-cache.org. You also need Perl installed, which is pretty much guaranteed to be on your system already. Installing from source is easy; follow the three-step install instructions in the INSTALL file included with the source distribution:

% ./configure --prefix=/usr/local/squid
% make all
% make install

The latest version of Squid, at the time of this writing, is 2.5.STABLE4. I am using version 2.5.STABLE3, which shipped with Fedora Core 1.

Next, we configure Squid. Before updating your Squid configuration, we issue the stop command, /etc/init.d/squid stop, to make sure Squid is not running.

Now, edit the /etc/squid/squid.conf file as root. We are going to change only one setting in the default squid.conf file. Locate the line that reads:

# http_port 3128

and change it to:

http_port 8080 

This line changes the port on which Squid is running from the default port of 3128 to the easy-to-remember port of 8080. Although this step is not necessary, you probably want to do it so you can remember on which port Squid is running without having to look at the squid.conf file in the future. Keep in mind, though, that port 8080 may conflict with some applications, such as Tomcat or JBoss. If there is a port conflict, you can choose a different port for Squid. Now it's time to test our Squid configuration. Type the following command as root to start up Squid: /etc/init.d/squid start. You should see an OK after Squid starts. If you get an error, go back and check your configuration settings to identify the problem.

Now we're going to set up Mozilla to use Squid as a proxy server. To do this, go to Edit→Preferences→Advanced→Proxies. Choose the Manual proxy configuration and put in 127.0.0.1 for your HTTP Proxy and 8080 as the port. If you are running Squid on a port other than 8080, enter that value here. Put in the same values for your SSL Proxy. You should end up with something similar to what is shown in Figure 4.

Click OK and try to browse any Web site to make sure that Squid is functioning properly. A good test for this is to go to images.google.com and search on the term penguin. After the page loads up, click refresh in your browser and notice how much more quickly the images load the second time. The increased speed is from a combination of Mozilla's own built-in caching capabilities and Squid's caching of the images for you. As a test, I turned off Mozilla's built-in caching functionality and loaded up the penguin images page. The initial loading of the page took 27 seconds on my dial-up connection, while the second viewing took only a little over two seconds.

Figure 4. Configure your browser to use the proxy server.

Part II of this articles explains how to use AdZapper to block many ads and Web bugs.

Frank Merenda is a systems architect for John Deere, where he writes J2EE applications on Linux, as well as a coauthor of the Linux site, uptime (uptime.steidler.net). He and his wife Jacq live with their seven dogs and five cats in rural Jackson County, Georgia, where they both are helping the Humane Society of Jackson County (www.hsjc.com) build an animal shelter. He can be reached at linux@frankandjacq.com.

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

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

Re: Zap Annoyances on the Web, Part I

On May 7th, 2004 Anonymous says:

Try adblock - it's a VERY nifty little tool that plugs right into Mozilla or Firefox...

Anonymous's picture

Re: Zap Annoyances on the Web, Part I

On May 5th, 2004 Anonymous says:

Do you have any suggestions on Content Filtering with Squid?
ie blocking explicit sites

Thanks in advance

Anonymous's picture

Re: Zap Annoyances on the Web, Part I

On May 6th, 2004 Anonymous says:

squid-guard

dmarti's picture

Re: Zap Annoyances on the Web, Part I

On May 5th, 2004 dmarti (not verified) says:

Anonymous's picture

Privoxy

On May 5th, 2004 Anonymous says:

I use Privoxy to block ads--they really have done a lot of this work already. http://www.privoxy.org/

I believe it can also be chained to a cache (like squid) if desired.

Anonymous's picture

Re: Zap Annoyances on the Web, Part I

On May 4th, 2004 Anonymous says:

I note that Mozilla allows one to set a very large cache, under Preferences. The default on my Mozilla came at 50 MB. I increased this to 150 MB, and now have a sizeable cache to speed up web page loading, using dialup.

Do you think squid provides better caching than the one in Mozilla?

Anonymous's picture

Re: Zap Annoyances on the Web, Part I

On May 3rd, 2004 Anonymous says:

man, that is so blindingly fast, i can`t believe it! my browser now runs "blink and you miss it".

Anonymous's picture

Re: Zap Annoyances on the Web, Part I

On May 4th, 2004 Anonymous says:

I configured Squid as per your instructions in both Mozilla 1.6 and in Firebird 0.8 and get the following error message:

"The connection was refused when attempting to contact the proxy server you have configured. Please check your proxy settings and try again."

The file I edited was "/etc/squid/squid.conf" and not "/etc/squid/squid.conf.default." The file read:
#Default:
# http_port 3128

I just uncommented the line "# http_port 3128" and made the proxy setting in Mozilla and Firebird read the same port "3128". I don't know what I am doing wrong.

Anonymous's picture

Re: Zap Annoyances on the Web, Part I

On June 8th, 2004 Anonymous says:

I am having a similar problem (I'm running Slackware current) with details as follows:

I changed the conf file to this, which I think should work (I got the
IP address from LISaDaemom):

INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

# Example rule allowing access from your local networks. Adapt
# to list your (internal) IP networks from where browsing should
# be allowed
acl our_networks src 192.168.0.0/24
http_access allow our_networks

# And finally deny all other access to this proxy
http_access deny all

I set the http_port to 8080 and then configured firefox as follows:

HTTP Proxy : 127.0.0.1 Port: 8080
SSL Proxy : 127.0.0.1 Port :8080

and there is no proxy for localhost, 127.0.0.1

Squid is running fine. When I try to open a web page, I now get a
message that says "The connection was refused when attempting to
contact the proxy server you have configured. Please check your proxy
settings and try again."

I am also running a firewall script as follows, could this be part of
the problem?

#!/bin/bash
#
# Basic script to keep the nasties out of slack-lap
# First we make the default policy to drop everything
iptables -P INPUT DROP
iptables -P FORWARD DROP
# Allow established connections and programs that use loopback
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -s 127.0.0.0/8 -d 127.0.0.0/8 -i lo -j ACCEPT
# Lets allow ssh to connect
iptables -A INPUT -p tcp --dport 22 -i ppp0 -j ACCEPT
#end script

I am really new to linux and I find this networking stuff a bit
confusing..but I'm learning..., so please bear with me!

Thanks,
Lucinda

Anonymous's picture

Re: Zap Annoyances on the Web, Part I

On May 4th, 2004 Anonymous says:

You have to permit or allow your own network to use the proxy. I believe the entry is something like:

my network 192.168.0.0
allow my network

Then reload squid and you should be good to go.

Cheers

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.


Read this issue