Some suggestions on antiX advert blocker

Message
Author
LionelZaylan
Posts: 97
Joined: Sat May 22, 2021 12:37 am

Re: Some suggestions on antiX advert blocker

#21 Post by LionelZaylan »

- in python script output a trailing "new-line" is missing, so the end-marker is not on a new line
Do you mean our code adds something like

Code: Select all

 0.0.0.0 zzz.onion.pet zzzrtrcm2.com zzztube.com# END (above) - IPs added by antiX Advert Blocker # 
at the end of /etc/hosts.

It should have been

Code: Select all

 0.0.0.0 zzz.onion.pet zzzrtrcm2.com zzztube.com
# END (above) - IPs added by antiX Advert Blocker # 
Last edited by LionelZaylan on Sat Jun 19, 2021 1:32 am, edited 1 time in total.

LionelZaylan
Posts: 97
Joined: Sat May 22, 2021 12:37 am

Re: Some suggestions on antiX advert blocker

#22 Post by LionelZaylan »

@fehlix I think the following code in function append_blocklist would fix it . This code adds newlines where appropriate .

Code: Select all

	       # Add newlines where needed
	       # add list contents into the hosts file, below a marker (for easier removal)
	       echo "" >> $WORKINGDIR/hosts-temp
		echo "$markerstart" >> $WORKINGDIR/hosts-temp
		echo "# These kinds of sites are blocked : $what_to_block" >> $WORKINGDIR/hosts-temp # Show what blocking options are used
		cat $WORKINGDIR/blocklist-all >> $WORKINGDIR/hosts-temp
		echo "" >> $WORKINGDIR/hosts-temp
		echo "$markerend" >> $WORKINGDIR/hosts-temp
		# Ensure trailing newline
		echo "" >> $WORKINGDIR/hosts-temp
Last edited by LionelZaylan on Sat Jun 19, 2021 1:33 am, edited 1 time in total.

LionelZaylan
Posts: 97
Joined: Sat May 22, 2021 12:37 am

Re: Some suggestions on antiX advert blocker

#23 Post by LionelZaylan »

- unblock using hosts.ORIGNAL might not always give the desired result as user could have changed hostname, without adjusting hosts.ORIGINAL, which could later results in further issues.
Yes , a better way to unblock would be to remove all lines between $markerstart and $markerend . This keeps all modifications done by the user but removes all modifications done by antiX advert blocker .

To fix this , in function download_blocklist ,

Code: Select all

        mv -f "/etc/hosts.ORIGINAL" "/etc/hosts" 
        rm -f "/etc/hosts.saved"
could be replaced with

Code: Select all

		# Remove everything between markers to unblock everything
		sed -i -e "/$markerstart/,/$markerend/d" /etc/hosts
		#remove the markers
		sed -i -e "/$markerstart/d" /etc/hosts
		sed -i -e "/$markerend/d"   /etc/hosts
                rm -f "/etc/hosts.saved"

LionelZaylan
Posts: 97
Joined: Sat May 22, 2021 12:37 am

Re: Some suggestions on antiX advert blocker

#24 Post by LionelZaylan »

- the python script might not always work, as /tmp may be mounted with noexec
We can do something like

Code: Select all

cat << EndOfFile > $WORKINGDIR/compress.py
................ python code ................
EndOfFile
cat $WORKINGDIR/compress.py | /usr/bin/python3 -
So, we don't need executable bit to execute python code ( python can read code from its stdin )

LionelZaylan
Posts: 97
Joined: Sat May 22, 2021 12:37 am

Re: Some suggestions on antiX advert blocker

#25 Post by LionelZaylan »

One more thing worth considering :

Running antiX advert blocker repeatedly may put a lot of empty lines in the hosts file .

Repeated empty lines may be removed by replacing

Code: Select all

	sed -e "/$markerstart/,/$markerend/d" /etc/hosts > $WORKINGDIR/hosts-temp
with

Code: Select all

	sed -e "/$markerstart/,/$markerend/d" /etc/hosts | cat --squeeze-blank > $WORKINGDIR/hosts-temp
in the function append_blocklist

( reference: man cat )

LionelZaylan
Posts: 97
Joined: Sat May 22, 2021 12:37 am

Re: Some suggestions on antiX advert blocker

#26 Post by LionelZaylan »

Anyway , thanks to the developers for taking up my humble idea .

Thanks to @figueroa too for this useful blocklist :
https://raw.githubusercontent.com/hosh ... hosts.txt

I hadn't known it until now , and we are planning to use this list too in our upcoming cross-platform GUI app to block nuisances

Post Reply

Return to “antiX”