Pup Advert Blocker 0.3

This is a very useful little GUI application created by sc0ttman:

http://murga-linux.com/puppy/viewtopic.php?t=59290

So nice in fact that I reckon it should be in all Woof-built puppies. So, I have put the script 'pup-advert-blocker' into rootfs-skeleton/usr/sbin in Woof, and I created a new icon rootfs-skeleton/usr/local/lib/X11/mini-icons/adblock.xpm (22x22).

Great job, sc0ttman!

One small thing, I found a bug in the 0.3 version of the script, that breaks it. Fixed script:

#!/bin/sh

#v0.3 created by sc0ttman, August 2010
#GPL license /usr/share/doc/legal/gpl-2.0.txt
#100830 BK added GPL license, amended Exit msg, bug fixes.

# advert blocker
# downloads a list of known advert servers
# then appends them to /etc/hosts so that
# many online adverts are blocked from sight

# make a hosts file if none found, or add a marker
if [ ! -f /etc/hosts ];then
echo "#host file
127.0.0.1 localhost puppypc
" > /etc/hosts
fi

# set vars
export appver='0.3'
export title='Pup Advert Blocker'
# the markers used to find the changes in /etc/hosts, which are made by this app
export markerstart='# pup-advert-blocker IPs below'
export markerend='# pup-advert-blocker IPs above'
export mvps='false'
export systcl='false'
export technobeta='false'
export yoyo='false'

# create functions
set -a

# cleanup all leftover files
cleanup () {
# remove all temp files
rm -f /tmp/adlist1 /tmp/adlist2 /tmp/adlist3 /tmp/adlist4 /tmp/adlist-all /tmp/hosts-temp
}

# download the ads lists
download_adlist () {
# mvps
if [ "$mvps" = true ]; then
wget -c -4 -t 0 -O /tmp/adlist1 'http://www.mvps.org/winhelp2002/hosts.txt'
fi
# systcl
if [ "$systcl" = true ]; then
wget -c -4 -t 0 -O /tmp/adlist2 'http://sysctl.org/cameleon/hosts'
fi
# technobeta
if [ "$technobeta" = true ]; then
wget -c -4 -t 0 -O /tmp/adlist3 'http://www.technobeta.com/download/urlfilter.ini'
fi
# yoyo
if [ "$yoyo" = true ]; then
wget -c -4 -t 0 -O /tmp/adlist4 'http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext'
fi
#100830 BK bug fix: create if not exist...
touch /tmp/adlist1
touch /tmp/adlist2
touch /tmp/adlist3
touch /tmp/adlist4
# combine the downloaded lists, then sort and remove duplicates
cat /tmp/adlist1 /tmp/adlist2 /tmp/adlist3 /tmp/adlist4 |grep ^[1-9] |sed "s/\t//g"|sort |uniq > /tmp/adlist-all
}

# clean out everything but the list of IPs and servers
clean_adlist () {
sed -i '/^#/d' /tmp/adlist-all # remove all comments
sed -i '/localhost/d' /tmp/adlist-all # remove the original links to localhost (we already have them)
sed -i '/^$/d' /tmp/adlist-all # remove empty lines
sed -i 's/\t/ /' /tmp/adlist-all # replace all tabs with spaces
sed -i 's/ / /g' /tmp/adlist-all # remove double spaces
dos2unix -u /tmp/adlist-all # change all carriage returns to UNIX format
#cat /tmp/adlist-all |sort |uniq > /tmp/adlist-all # remove duplicates (again)
ADLISTALL="`cat /tmp/adlist-all |sort | uniq`" #100830 BK
echo "$ADLISTALL" > /tmp/adlist-all #100830 BK
}

# append the list to the /etc/hosts
append_adlist () {
# echo all but the stuff between the markers to a temp hosts file
sed -e "/$markerstart/,/$markerend/d" /etc/hosts > /tmp/hosts-temp
# remove the markers
sed -i -e "/$markerstart/d" /tmp/hosts-temp
sed -i -e "/$markerend/d" /tmp/hosts-temp
# check the size of the final adlist
if [ -s /tmp/adlist-all ];then
# get contents of the downloaded adlist
adlist=`cat /tmp/adlist-all`
# add list contents into the hosts file, below a marker (for easier removal)
echo "$markerstart" >> /tmp/hosts-temp
echo "$adlist" >> /tmp/hosts-temp
echo "$markerend" >> /tmp/hosts-temp
else
Xdialog --title "$title $appver" --msgbox "No ad lists selected. Ad blocking will be disabled." 0 0
fi
# replace the original with the cleaned version
mv "/tmp/hosts-temp" "/etc/hosts"
}

success () {
# tell user
Xdialog --title "$title $appver" --msgbox "Success - your settings have been changed.\n\nYour hosts file has been updated.\nRestart your browser to see the changes." 0 0 &
}

# create a GUI
export HELP_GUI='<window title="'$title' '$appver'">
<frame>
<vbox>
<text width-request="360">
<label> The "'$title'" tool adds stuff to your "/etc/hosts" file, so that many advertising servers and websites will not be able to connect to this PC.</label>
</text>
<text><label>""</label></text>

<text width-request="360">
<label>Leave your cursor over a service to see a short description. You can choose one service or combine multiple services for more advert protection.</label>
</text>
<text><label>""</label></text>

<text width-request="360">
<label>Blocking ad servers protects your privacy, saves you bandwidth, greatly improves web-browsing speeds and makes the internet much less annoying in general.</label>
</text>
<text><label>""</label></text>

<text width-request="360">
<label>'$title' '$appver', by sc0ttman</label>
</text>
</vbox>

<text><label>""</label></text>

<hbox>
<button tooltip-text="Close this help dialog">
<input file icon="gtk-quit"></input>
<label>Close</label>
<action>exec gtkdialog3 --program GUI --center &</action>
<action type="exit">EXIT_NOW</action>
</button>
</hbox>
</frame>
</window>'

export GUI='<window title="'$title' '$appver'">
<vbox>
<vbox homogeneous="true">
<frame>
<text><label>'$title'</label></text>
<text><label>Block online ads in all browsers with this simple tool</label></text>
</frame>
</vbox>
<vbox>

<frame>
<vbox>
<text>
<label>Choose your preferred ad blocking service(s)</label>
</text>
</vbox>
<hbox>
<checkbox tooltip-text="Blocks many known malware sites and unsafe adult networks">
<label>Mvps.org</label>
<variable>mvps</variable>
<default>false</default>
</checkbox>
<checkbox tooltip-text="A large, fairly comprehensive list of many known ad servers">
<label>Systcl.org</label>
<variable>systcl</variable>
<default>false</default>
</checkbox>
<checkbox tooltip-text="A smaller list of popup adverts, ad servers and ad networks">
<label>Technobeta.com</label>
<variable>technobeta</variable>
<default>false</default>
</checkbox>
<checkbox tooltip-text="A small and effective list of popular ad servers">
<label>Yoyo.org</label>
<variable>yoyo</variable>
<default>false</default>
</checkbox>
</hbox>
</frame>

<frame>
<vbox>
<hbox>
<text>
<label>Click the "Start" button to download and block the latest list of known advertising servers</label>
</text>
<button width-request="70" tooltip-text="Click to download and then block a list of advertising servers">
<variable>START</variable>
<input file icon="gtk-execute"></input>
<label>Start</label>
<action>download_adlist</action>
<action>clean_adlist</action>
<action>append_adlist</action>
<action>cleanup</action>
<action>success</action>
</button>
</hbox>

<text><label>""</label></text>

<hbox>
<text>
<label>Or click the "Edit" button to manually edit your hosts file, using your default text editor</label>
</text>
<button width-request="70" tooltip-text="Manually edit your hosts file in a text editor, adding or removing any entries you like">
<variable>EDIT</variable>
<input file icon="gtk-edit"></input>
<label>Edit</label>
<action>defaulttexteditor /etc/hosts &</action>
</button>
</hbox>
</vbox>
</frame>

<frame>
<hbox>
<button tooltip-text="Learn more about blocking ads">
<variable>HELP</variable>
<input file icon="gtk-help"></input>
<label>Help</label>
<action>exec gtkdialog3 --program HELP_GUI --center &</action>
<action type="exit">EXIT_NOW</action>
</button>
<button tooltip-text="Exit Pup Advert Blocker">
<variable>QUIT</variable>
<input file icon="gtk-quit"></input>
<label>Quit</label>
<action type="exit">EXIT_NOW</action>
</button>
</hbox>
</frame>

</vbox>
</vbox>
</window>'

# cleanup before start
cleanup
# run the program
gtkdialog3 --program GUI --center



Posted on 30 Aug 2010, 8:15


Comments:

Posted on 30 Aug 2010, 12:23 by bigpup
swapfile manager
Have you seen this?
Swapfile manager for Puppy.
http://www.murga-linux.com/puppy/viewtopic.php?t=58615


Posted on 30 Aug 2010, 15:47 by BarryK
Re swapfile manager
...looks interesting, I'll check it out



Posted on 30 Aug 2010, 22:51 by gjuhasz
Works fine
0.3 modified by Barry above is fine. With 0.4 downloaded from the forum, I got "no lists selected" error message - the hosts file remained the same.

I use Wary 060 installed on my ancient PII Toshiba Tecra, 256 MB memory. I copy/pasted Midori files one-by-one from Luci 219 (extremely fast). Then I ran an "adblockbyhosts" script based on this:

https://bbs.archlinux.org/viewtopic.php?pid=689169

It works fine. So I think the bug in Pup Advert Blocker 0.4 will be fixed and blocking should be OK soon.
There are a couple of (minor) disadvantages, however. The hosts file should be updated manually, and browsing becomes slower if if the list is toooo long.

Miracle comes. ----------------
Now I am playing with Adblock plus subscriptions. Midori is able to utilize some Netscape/Mozilla add-ons, for example to block advertisements based on Adblock installed for Firefox.
Note that the above Adblock utilization works only by this tweak and only in Wary. Midori in the parent Lupu-219 does not import Adblock filters.
Be sure, I used the original /etc/hosts file.
----------- Miracle presented.
I still try to understand how this can succeed in Wary and fail in other puppies.