Ad blocking in SailfishOS in 2023 - What are the options?

The question was specific but in general what is required is a configuration manager.

How to provide a configuration manager?

Can be an RPM that install a set of scripts and allows to run them by a GUI providing parameters.

Because a configuration manager should be available also in rescue mode (no graphic interface available) or via remote console (e.g. SSH).

Is this enough?

Nope, if the configuration manager does not manage also the package installation set, as well.

This is possible only if there is a centralized organisation of the RPM repositories which is not the case of SFOS.

Changing the DNS is not the only thing that people wish to do, but just one of many.

Where is the best place to put a configuration manager considering the peculiarities of the smartphone market?

Into a rescue image, not in the system.

Oplà! :blush:

Hello,
my most promising solution for ad block is the modification of the hosts file. AdBlocking on Sailfish OS via /etc/hosts | dt.iki.fi developed a suitable solution. However for me it was still very complicated to process all the steps. Therefore I wrote a bash script that includes all steps.

just download and run the following script with root permission and after reboot ad block should work out of the box: adblock-script/adblock-script.sh at main · teertinker/adblock-script · GitHub

I hope this helps some users.

4 Likes

This usually works for me.
Type in terminal as root -

curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -o /etc/hosts

Naturally, you should be able to link it to any other hosts file of your choice.

After you do that, reboot the device, and that’s it.

6 Likes

Just to clarify:

There’s nothing wrong with using a single hosts file, but I wanted to go the extra mile, as discussed in this thread.

Therefore the script has grown quite complex:

  • it converts uBO’s uAssets as far as possible to be used by /etc/hosts
  • it downloads everything from firebog.net’s meta list plus Steven Black’s largest hosts file
  • it combines and unique-sorts everything, adds a header and finally overwrites the old /etc/hosts

My tutorial mostly describes how to make updates automatic; the script itself can be treated as opaque.

Thanks to @FelixWilke for automating that in turn, and directly linking to my script. If you want you can use this link instead and I’ll try my best to make sure not to break compatibility in future updates.

5 Likes

That sounds pretty cool. Thanks for making it.

1 Like

Finally when actually trying to move to C2 I have made an attempt to rpm-ize this @ohnonot RPM packaging (!1) · Merge requests · ohnonot / sfos · GitLab

(Waiting for @olf’s review of course :wink: )

I may have misused chum metadata, I can edit that later. One thing I am not comfortable with is that I placed the rpm folder inside the hosts folder, which might prevent a chum build on OBS, maybe I should stick to a top-level rpm dir…

Still, if you checkout that repo, cd hosts and sfdk build you’d get a rpm.

1 Like

For testing purposes I am pre-publishing the package on hosts-block | OpenRepos.net — Community Repository System :crossed_fingers:

5 Likes

I’m not an expert but looking at this script, I perceive it as something missing. As far as I know, you need reboot for updated hosts list to take effect? Don’t you?

Changes to the /etc/hosts file are usually picked up immetiately without a reboot. Just give it a try by changing some IP and use ping to trigger hostname resolution.

Well, I don’t know about ‘usually’ but it sure doesn’t work like that on my C2 - SFOS 5.0.0.43.

I did my test a bit different, like this…

  1. Add openrepos.net to your hosts file and save.
  2. Launch Jolla browser and go to openrepos.net with no errors.
  3. Reboot phone.
  4. Launch Jolla browser and go to openrepos.net, and get error message ‘cold not access’.
  5. Update hosts file to be without openrepos.net
  6. Launch Jolla browser and go to openrepos.net, and get error message ‘cold not access’.
  7. Reboot phone
  8. Launch Jolla browser and go to openrepos.net with no errors.

The same goes for my Linux desktop.

1 Like

With these steps I get the result you describe als on 4.6.0.15 but the reason is probably, that the browser uses its own resolver. After a pkill -f browser that should have killed sailfish-browser as well as browser-booster, the changes are picked up without a reboot.

1 Like

I don’t have the time to test right now, but if that is true, there actually is something missing in that script. :wink:

Which is the script you’re referring to?

1 Like

Yours, or whoever wrote it… Ad blocking in SailfishOS in 2023 - What are the options? - #46 by vlagged

Ok, so my rpm packages @ohnonot 's script from here hosts/hostsupdate · master · ohnonot / sfos · GitLab

Not sure what you’re saying, it should restart the browser (and browser booster service) at hosts update?

1 Like

Yes, if that really is working. As I said, I didn’t test.
I imagine that browser is the real world use case, so I would want the hosts file to apply without having to reboot… or being prompted to reboot… or choose a 100% working solution, even if it’s a bit manually.

I haven’t checked yet because I have other problems to solve first with C2, but I wonder if without an app it might work by modifying the host file. CF: DNS Block List [Wiki de sebsauvage.net]

Of course, you do not need an app (or script) to make the hosts file work as a block list.
Me, myself is using a simple command which I manually execute now and then… maybe once a month.
I also made the command a quick launcher in my app drawer using the qCommand app.
The personal command of mine is…
devel-su curl https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-social/hosts -o /etc/hosts && pkill -f browser

…but of course you can use any list URL of your choice.

1 Like

Probably it will work with a systemd service or something

1 Like

If qCommand is already root one can reboot or killall browsers anyway.

Speaking of systemd, if you have a timer based service to update hosts, it would be weird that once a week, say, your browser or phone restarts (the latter is dangerous since unattended restarts mean also inability for alarms to work)

I think in this latter case a notification that restarts the browser at will would be a solution, but that is deterred by the fact that you’re root (the notification…)

1 Like