Welcome!
Important information
-- Spectre and Meltdown vulnerabilities
-- Change in MX sources

News
-- MX Linux on social media: here
-- Mepis support still here

Current releases
-- MX-17.1 Final release info here
-- antiX-17 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

Lighter, non-leaky Ad Blocker.

Message
Author
User avatar
m_pav
Forum Guide
Forum Guide
Posts: 2676
Joined: Sun Aug 06, 2006 3:02 pm

Re: Lighter, non-leaky Ad Blocker.

#11 Post by m_pav » Tue Feb 10, 2015 2:42 pm

Data bases are not static. I compared the last number of blocked ad servers with the updated version generated by the script yesterday.
Last version had a total of 24106 lines in the hosts file, minus 14 = 24091 blocked ad servers.
last update had a total of 24607 lines in the hosts file, minus 14 = 24593, so that's an additional 502 over the last time I did it, which was about 4-5 months back.

The antiX guys may have an updated script around, but in case they haven't, make a new empty file called block-advert.sh then copy and paste the contents of the script below into it, save it, copy it to /usr/local/bin mark it as executable and follow the instructions in my video to block ad servers at the complete system level instead of restricting the blocks to only the browsers.

Code: Select all

#!/bin/bash

#v0.4 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.
# zenity version by lagopus for antiX, Decemder 2010
# modified to yad by Dave for antiX, September 2011

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

TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=block-advert.sh

export title="antiX 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'

info_text=$"The <b>$title</b> tool adds stuff to your /etc/hosts file, so \n\
that many advertising servers and websites will not be able to connect \n\
to this PC.\n\n\
You can choose one service or combine multiple services for more advert protection.\n\
Blocking ad servers protects your privacy, saves you bandwidth, greatly \n\
improves web-browsing speed and makes the internet much less annoying in general.\n\n\
Do you want to proceed?"

# width of progress dialogs
WIDTH=360

# cleanup all leftover files
function cleanup
{
    # remove all temp files
    rm -f /tmp/adlist{1,2,3,4} /tmp/adlist-all /tmp/hosts-temp
}

# concatenate the downloaded files
# clean out everything but the list of IPs and servers
function build_adlist_all
{
    #echo "====================YTO"
    # suppress comments, then empty lines, replace tabs by spaces
    # remove double spaces, remove lines not beginning by a number,
    # suppress \r at end of line
    # then sort unique by field 2 (url)
    cat /tmp/adlist{1,2,3,4} | sed '/^#/d' | \
                               sed '/^$/d' | \
                               sed 's/[\t]/ /g' | \
                               sed 's/  / /g' | \
                               sed -n '/^[0-9]/p' | \
                               tr -d '\015' | \
                               sort -u -k 2 \
                               > /tmp/adlist-all
    #echo "====================YTO"
}


# append the list to the /etc/hosts
function append_adlist
{
	# copy /etc/hosts, 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
    size=$(stat -c%s /tmp/adlist-all 2>/dev/null)
    #echo $size
	if [ -n "$size" ] && [ "$size" -gt "0" ];then
		# add list contents into the hosts file, below a marker (for easier removal)
		echo "$markerstart" >> /tmp/hosts-temp
		cat /tmp/adlist-all >> /tmp/hosts-temp
		echo "$markerend"   >> /tmp/hosts-temp
	else
		yad --image="info" --title "$title" --text=$"Empty ad list. No change made in /etc/hosts."
        exit 1
	fi
	# replace the original /etc/hosts with the new version and backup original
    # require root privilege
    cp "/etc/hosts" "/etc/hosts.saved"
    mv "/tmp/hosts-temp" "/etc/hosts"
}


# usage: wget_dialog url file
# $1 : url of the file
# $2 : file: location of the downloaded file
function wget_dialog
{
    #echo "url: [$1]"
    url=$1
    # extract domain name between // and /
    domain=$(echo "$url" | cut -d/ -f3)
    #echo "===> $domain"
    
    # '--progress=dot' prints dots and a percentage at the end of the line
    # print $7 to cut the percentage
    # system("") to flush the output of awk in the pipe
    # sed to delete the ending '%' sign
    # sed -u to flush the output of sed
    # changed -t 0 (tries) to -t 20
    wget -c -4 -t 20 -T 10 --progress=dot -O $2 "$1" 2>&1 | \
        awk '{print $7}; system("")' | sed -u 's/%//' | \
        yad --title "$title" --progress --width $WIDTH \
               --text=$"Loading  adlist from $domain" \
               --percentage=0 \
               --auto-close
}

# download the ads lists
function download_adlist
{
    # mvps
    if [ "$mvps" = true ]; then
        wget_dialog http://www.mvps.org/winhelp2002/hosts.txt /tmp/adlist1
    fi
    # systcl
    if [ "$sysctl" = true ]; then
        wget_dialog http://sysctl.org/cameleon/hosts /tmp/adlist2
    fi
    # technobeta
    if [ "$technobeta" = true ]; then
        wget_dialog 'http://www.technobeta.com/download/urlfilter.ini' /tmp/adlist3
    fi
    # yoyo
    if [ "$yoyo" = true ]; then
        wget_dialog 'http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext' /tmp/adlist4
    fi

    #100830 BK bug fix: create if not exist...
    touch /tmp/adlist{1,2,3,4} 
}


function success
{
	# tell user 
	yad --image "info" --title "$title" --text=$"Success - your settings have been changed.\n\n\
Your hosts file has been updated.\n\
Restart your browser to see the changes."
}

#=======================================================================
# main
#

# display message and ask to continue
yad --title "$title" --width "$WIDTH" --image "question" --text "$info_text"
rsp=$?

if [ $rsp != 0 ]; then
    exit 0
fi

# selection dialog
ans=$(yad --title "$title" \
             --width "$WIDTH" --height 220 \
             --list --separator=":" \
             --text $"Choose your preferred ad blocking service(s)" \
             --checklist  --column "Pick" --column "Service"\
             FALSE "mvps.org" \
             FALSE "sysctl.org" \
             FALSE "technobeta.com" \
             FALSE "yoyo.org")

#echo $ans

# transform the list separated by ':' into arr
arr=$(echo $ans | tr ":" "\n")

selected=""
for x in $arr
do
    #echo "> [$x]"
    case $x in
    mvps.org)
        mvps='true'
        selected='yes'
        ;;
    sysctl.org)
        sysctl='true'
        selected='yes'
        ;;
    technobeta.com)
        technobeta='true'
        selected='yes'
        ;;
    yoyo.org)
        yoyo='true'
        selected='yes'
        ;;
    esac    
done

if [ -z $selected ]; then
    # nothing selected
    echo $"No item selected"
    exit 0
fi

cleanup
download_adlist
build_adlist_all
append_adlist
cleanup
success
Mike P

Regd Linux User #472293
(Mine)Lenovo T560, i7-6600U, 16GB, 2.0TB SSHD, MX17 64-bit
(Wifes) Asus M4A88TD-M, AMD Phenom II x4 955 CPU, nVidia GF610, 6Gb, 500GB+320GB, MX17 + KDE
(Kids) Intel NUC, J1900, 4GB, 64GB SSD, MX17

User avatar
kmathern
Forum Veteran
Forum Veteran
Posts: 9341
Joined: Wed Jul 12, 2006 2:26 pm

Re: Lighter, non-leaky Ad Blocker.

#12 Post by kmathern » Tue Feb 10, 2015 3:27 pm

m_pav wrote:Data bases are not static. I compared the last number of blocked ad servers with the updated version generated by the script yesterday.
Last version had a total of 24106 lines in the hosts file, minus 14 = 24091 blocked ad servers.
last update had a total of 24607 lines in the hosts file, minus 14 = 24593, so that's an additional 502 over the last time I did it, which was about 4-5 months back.

The antiX guys may have an updated script around, but in case they haven't, make a new empty file called block-advert.sh then copy and paste the contents of the script below into it, save it, copy it to /usr/local/bin mark it as executable and follow the instructions in my video to block ad servers at the complete system level instead of restricting the blocks to only the browsers. ...
The advert-block-antix package from the antix.daveserver.info repo (enabled by default in MX-14) will install the /usr/local/bin/block-advert.sh script.

In MX-14 it can be started from the Whiskermenu entry: Settings -> advert-block.

And it uses yad for the gui:
antiXadvertblock1.png
You do not have the required permissions to view the files attached to this post.

User avatar
lucky9
Forum Veteran
Forum Veteran
Posts: 11380
Joined: Wed Jul 12, 2006 5:54 am

Re: Lighter, non-leaky Ad Blocker.

#13 Post by lucky9 » Tue Feb 10, 2015 5:09 pm

Probably have to logout/login to get it on the menu?
Yes, even I am dishonest. Not in many ways, but in some. Forty-one, I think it is.
--Mark Twain

User avatar
kmathern
Forum Veteran
Forum Veteran
Posts: 9341
Joined: Wed Jul 12, 2006 2:26 pm

Re: Lighter, non-leaky Ad Blocker.

#14 Post by kmathern » Tue Feb 10, 2015 5:21 pm

lucky9 wrote:Probably have to logout/login to get it on the menu?
I didn't need to.
I installed the advert-block-antix package a little bit before I made my last post.
It showed up in the menu right away without needing to logout/login.

User avatar
lucky9
Forum Veteran
Forum Veteran
Posts: 11380
Joined: Wed Jul 12, 2006 5:54 am

Re: Lighter, non-leaky Ad Blocker.

#15 Post by lucky9 » Tue Feb 10, 2015 9:58 pm

I wonder what the difference is. Because it doesn't show in my Menu under any category. I have not logged out and back in as yet.
(I installed it when I read your post kmathern.)
Yes, even I am dishonest. Not in many ways, but in some. Forty-one, I think it is.
--Mark Twain

User avatar
m_pav
Forum Guide
Forum Guide
Posts: 2676
Joined: Sun Aug 06, 2006 3:02 pm

Re: Lighter, non-leaky Ad Blocker.

#16 Post by m_pav » Wed Feb 11, 2015 12:01 am

kmathern wrote:The advert-block-antix package from the antix.daveserver.info repo (enabled by default in MX-14) will install the /usr/local/bin/block-advert.sh script.
Thanks Kent. I placed the whole script here for the sake of Linux users coming from a different distro. I added a comment to my video which links to this thread.
Mike P

Regd Linux User #472293
(Mine)Lenovo T560, i7-6600U, 16GB, 2.0TB SSHD, MX17 64-bit
(Wifes) Asus M4A88TD-M, AMD Phenom II x4 955 CPU, nVidia GF610, 6Gb, 500GB+320GB, MX17 + KDE
(Kids) Intel NUC, J1900, 4GB, 64GB SSD, MX17

User avatar
GuiGuy
Forum Guide
Forum Guide
Posts: 1439
Joined: Sun Dec 16, 2007 6:29 pm

Re: Lighter, non-leaky Ad Blocker.

#17 Post by GuiGuy » Wed Feb 11, 2015 6:07 pm

lucky9 wrote:I wonder what the difference is. Because it doesn't show in my Menu under any category. I have not logged out and back in as yet.
......
I also did not see it in the menu until I logged out-and-in (two different MX machines) but it is there now and appears to launch OK.

User avatar
Stevo
Forum Veteran
Forum Veteran
Posts: 16512
Joined: Fri Dec 15, 2006 8:07 pm

Re: Lighter, non-leaky Ad Blocker.

#18 Post by Stevo » Wed Feb 11, 2015 9:15 pm

In my test, I also had to log out and in. Four other programs did show up immediately in the Live Session I'm testing.

So there's something going on with certain packages that prevents them from updating the menu immediately. I wonder what it is.

User avatar
kmathern
Forum Veteran
Forum Veteran
Posts: 9341
Joined: Wed Jul 12, 2006 2:26 pm

Re: Lighter, non-leaky Ad Blocker.

#19 Post by kmathern » Wed Feb 11, 2015 9:40 pm

Stevo wrote:In my test, I also had to log out and in. Four other programs did show up immediately in the Live Session I'm testing.

So there's something going on with certain packages that prevents them from updating the menu immediately. I wonder what it is.
Fwiw, I have the 1.4.2 whiskermenu update that you mentioned in the other topic (in the Development team subforum).

User avatar
Stevo
Forum Veteran
Forum Veteran
Posts: 16512
Joined: Fri Dec 15, 2006 8:07 pm

Re: Lighter, non-leaky Ad Blocker.

#20 Post by Stevo » Sat Sep 05, 2015 2:08 pm

Apparntly the original developer of ublock forked and abandoned the original ublock in favor of Ublock Origin. Aparently he is sort of a grump and wanted exclusive control of the code, though it is open-source. He also refuses donations so he won't feel any obligation to the user base and can drop the project at any time. The extension is available for all browsers, barring MS Edge.

One immediate effect I noticed over ublock is that the annoying video ads that precede highlight clips at mlb.com are gone, along with the video ads that pop up between innings if you're following a live game on Gameday.

It works fine just out of the box, but also allows very advanced configuration, and scored highest in this review: https://www.raymond.cc/blog/10-ad-block ... /view-all/

Post Reply

Return to “Desktop Environment”