▄▄██▄█ ▀███▀  ▀███▀ ▀███▄ ▀███▀ ▀███▀███▄▄  ███       ▄██▀▀██▄  ▄██▀▀███ ▀███▀  ▀███▀
  ▄▓▓▓▀  ▓  ▓▓▓    ▓▓▓   ▓▓▓▓▓▄▓▓▓   ▓▓▓   ▀▓▓▓ ▓▓▓      ▓▓▓    ▓▓▓ ▓▓▓   ▀▓  ▓▓▓    ▓▓▓ 
 ▒▒▒▀       ▒▒▒    ▒▒▒   ▒▒▒ ▀▒▒▒▒   ▒▒▒    ▒▒▒ ▒▒▒      ▒▒▒    ▒▒▒ ▒▒▒       ▒▒▒    ▒▒▒ 
▐░░░▄       ░░░    ░░░   ░░░   ░░░   ░░░   ▄░░▀ ░░░      ░░░    ░░░ ░░░       ░░░   ▄░░▀ 
 ▀▀    ▄                                ▄   ▀▀                                   ▄   ▀▀  
     ▀░░░   ░░░    ░░░   ░░░   ░░░   ░░░  ▀░░▄  ░░░      ░░░    ░░░ ░░░       ░░░  ▀░░▄  
      ▐▒▒▌  ▒▒▒    ▒▒▒   ▒▒▒   ▒▒▒   ▒▒▒   ▐▒▒▒ ▒▒▒      ▒▒▒    ▒▒▒ ▒▒▒       ▒▒▒   ▐▒▒▌ 
 ▄   ▄▓▓▓   ▓▓▓    ▓▓▓   ▓▓▓   ▓▓▓   ▓▓▓   ▐▓▓▓ ▓▓▓    ▄ ▓▓▓    ▓▓▓ ▓▓▓    ▄  ▓▓▓    ▓▓▓ 
 █▄▄███▀    ▀███▄ ▄██▀   ███   ███   ███ ▄▄██▀  ███  ▄██ ▀███▄ ▄██▀ ███  ▄██  ███    ███ 
 ▀ ▀▀▀        ▀▀▀▀▀     ▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀      ▀▀▀▀▀▀▀   ▀▀▀▀▀▀    ▀▀▀▀▀▀▀ ▀▀▀▀▀  ▀▀▀▀▀


The summer has arrived and that means chillin and swimming and a MASSIVE FUCKING HEATWAVE.

When i started this project i was bored and forced to stay inside to not get cooked alive. Thats when i built sunblock, a lightweight adblocker for gnu/linux operating systems.



How its made

This project has been made using python and bash. Why the combination of the two? well its simple because i can. But also because bash is a tool mostly made for automising processes that are deemed to be too repetetive for the end user. Part of me also wanted to grow in programming in bash and i found it to be a nice challenge as an opposed to do everything in python.



the bash scripts

In this part we will be looking at the sunblock.sh and pythonexecute.sh scripts. Both scripts are fairly simple. The sunblock script is the first script and the program that the user must run in order for the application to work in its entirety. It starts by seeying if there are options executed. These options beying: -p, -a, and -h. if -p has been executed the variable AD_FILE will be the path to the list of sketchey fishing websites it then scans for the begin and ending markers in the hosts file. If the content between the markers exist but have been altered it will replace the block. If the marker at the end is missing it will apped it. If for whatever reason the content exists but the markers do not it will also scan for the exact content and automatically ad the markers at the end. It will also just plainly add the content if nothing exists in the file. Neat right?

It will work the same way for the -a option. the -h option is more of an explaination and a little cheat sheet for options.

When the user executes this program without any options it will not add anything at all automatically to the hosts file.

The pythonexecute script is very simple. It just activates the venv and then executes the python script.



the python script

The script domainblocker.py is the only python script in this application. Its also the script the user will interact the most with since it is directly connected with the user interface. What it does is it indexes all of the entries of the hosts file in a list box named lv_Listview (forgive me for the often wierd naming for it is a remnant of my c# winforms coding experience). Of course the program would shit itself if all of the automatically added entries are all displayed in one go so i restricted it in only showing max 20 entries. To make navigating better the application counts how many lines are in the hosts file and skips nearly to the last line.

When the user has clicked the remove button it reads all the lines from the hosts file, each line is stripped of its trailing newline character and the checked against the selected entry. after filering the selected line will be removed from both the hosts file as from the listview.

The entry add window is another awesome feature. It only executes when the on_confirm button is pressed. It then strips the text and compares it with a regex pattern too see if the text is truly an url. (I used this site for the regex making its great). If all is fine and dandy it will add the local ip adress to the url and writes (in append mode) it to the hosts file with utf-8 encoding. Then if all is well it restarts the python application To apply the changes.





styling with glade and css

The styling is nothing much special. Glade is my go to choise when making python ui because it just works brah. Most of the time its drag'n drop and adding signals or functions to it is easy as pie.

For the css I chose for a dark aero look because i am a sucker for alternative design and i wanted it to differ a bit from the mathplotter program i made a while back.




Download, install and usage

To download this you must run $ git clone https://codeberg.org/prime-suspect/sunblock.git

then cd sunblock

To run you must run you must first alter the properties of both .sh files for them to be able to execute: $ chmod +x pythonexecute.sh && chmod +x sunblock.sh (you dont have to keep doint it, only for first run)

Then for normal run to you must run sudo ./sunblock.sh

For help ./sunblock.sh -h

For for the auto blocking of adverts sudo ./sunblock.sh -a

and for blocking of phising sites sudo ./sunblock.sh -p

Dont worry when executing this program as sudo, Its the only way when altering files located in the /etc/ folder

The UI should be self explainitory. If the user has added entries using this program they should reboot their pc in order for the OS to apply the changes


So where is the repo wise guy

If you would like to take a look at the repository. be muy guest. You can fork it if you want i published it under the X11 license


 ______________________________________
/ Thanks to sunblock I dont get cooked \
\ alive by the sun now, THANKS!        /
 --------------------------------------
   \
    \
        .--.
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /'\_   _/`\
    \___)=(___/