LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Linux Answers > Networking
User Name
Password

Notices

By cadj at 2005-04-21 22:03
INTRO: UNIVERSAL ADD BLOCKER

This tutorial will explain how to replace those annoying banner ad's on webpages with a simple "Ad Blocked" message.
As far as i know this method will work with ALL web browsers, but i have only tested on Konqueror and Firefox.

This method is very easy to do, and can either take 2 or 5 steps, depending on if you want custom messages.

STEP ONE: CREATE YOUR .PAC FILE
STEP TWO: CONFIGURING YOUR FILE / BROWSER

(If you want "Ad Blocked" message)
STEP THREE: INSTALLING CONFIGURING THTTPD
STEP FOUR: RECONFIGURING YOUR PROXY.PAC SCRIPT
STEP FIVE: ITS ALL DONE!


Have you ever noticed "Use the following proxy configuration URL" in the proxy configuration of you browser?
It turns out that this URL is nothing that a very simple script file, often referred to a .PAC file (Proxy Auto
Configuration?)

After looking around the net, i discovered that you could create your own .PAC file/add filters and redirect your
requests.

Using the idea of the Firefox adblock project, i decided to configure my .PAC file to redirect any requests for
banner ad's.

STEP ONE: CREATE YOUR .PAC FILE

Create a file and call it PROXY.PAC in /home/user
Enter the following code

Code:
    function FindProxyForURL(/questions/url, host)
    {
    if (       shExpMatch(host, '*.ad*')
    || shExpMatch(host, '*.ads*')
    || shExpMatch(host, '*banners*')
    || shExpMatch(host, '*doubleclick*')
    || shExpMatch(host, '*googlesyndication*')   
    )   
    return "PROXY 0.0.0.0:8000;";
    else
    return "DIRECT";
    }
Save the file.

The above is quite easy to understand, Basically every request is passed thru the "IF" statement, which says in english

Code:
    if (the host) contains the word ".ad" or ".ads" etc.. set the browser to use the proxy 0.0.0.0:8000
if you read the script now, you will notice that the || means OR

STEP TWO: CONFIGURING YOUR FILE / BROWSER

Now that you understand how the script works, you can add your own filters! These could include adult content, ads,
or bad websites.

Open your favorite web browser (Konqueror?) and configure it to use your /home/user/PROXY.PAC file. This configuration
option is usually found in the proxy config section of your web browser.

Restart your browser to be sure, and start browsing. You will notice that most of you banner ad's will be replaced
with
Code:
    An error occurred while loading
    http://ad.doubleclick.net/adi/linuxquestions.ds/home;pos=r_home;sz=120x6...


    Could not connect to host Proxy 0.0.0.0 at port 8000.
Or something similar.

STEP THREE: INSTALLING CONFIGURING THTTPD

If the error message doesn't bother you, skip this step

Instead of our PROXY.PAC script sending requests thru a 0.0.0.0 (a location that doesn't exist), we will
configure our script to use a webserver we setup ourselves, with a custom error message, or none at all!

You may need to look elsewhere to install THTTPD, but as far as i know there are binaries available for many
platforms.

Once THTTPD is installed / configured and started, we need to create a custom 404 error message, to do this, create
an "errors" directory in your web root (mine is in /var/www, so this is what i will use here)

in /var/www/errors, create a file called err404.html (not.htm, wont work) and add the following
Code:
        <table height="2000">
            <tr>
            <td valign="top">
            <b>Ad Blocked</b>
            </td>
            </tr>
            </table>
STEP FOUR: RECONFIGURING YOUR PROXY.PAC SCRIPT

Instead of sending requests to null, now we will send them to ourselves, change the following
return "PROXY 0.0.0.0:8000;";

change it too

Code:
        return "PROXY 127.0.0.1:80;";
STEP FIVE: ITS ALL DONE!

reload your script in your browser and begin to surf, most banner ads will now be "ad blocked" messages.








  



All times are GMT -5. The time now is 05:44 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration