Defender

Rating: 
4.75
Your rating: None Average: 4.8 (4 votes)

Defender - a privacy guard for SailfishOS.

As an alternative/replacement to the Hosts Adblock, Defender uses the /etc/hosts approach  - a proven way of blocking ads, banners, 3rd party cookies, 3rd party page counters etc. by adding blocking rules to the /etc/hosts system file. Bundled with a simple cookie manager, it allows to choose from multiple sources, either from a safe GUI (which does not require root access), or by editing the configuration files.

 

Features

  • Blocker entry sanitization - all entries from remote sources are sanitized in a way that should minimize the risk of their compromisation (all entries point to 0.0.0.0).
  • Add more sources by editing the /etc/defender.conf file.
  • Whitelist capability - add favorite hosts to whitelist by editing the /etc/defender.conf Settings section (separate by commas)
  • Graphical interface to choose hosts sources
  • Option to update only if the device is connected to WLAN - to minimize data costs
  • Your own rules are preserved and you can still edit them and add new ones by editing /etc/hosts.editable file. Mind that for your changes to come to effect, you need to choose Update in the app itself.
  • Ability to easily disable the functionality without removing the app.
  • Simple Cookie Manager with ability to specify blacklist/whitelist of cookies to delete and to lock the cookies altogether.
  • Source code available here

Why the mixed .config + GUI approach?

This allows to easily enable and disable different sources, while still keeping your system in non-root environment.

TODO

  • Better documentation
  • More stats and logging
  • Easier command line interface
  • Cleaner code (the current one is atrocious)
  • Automated cookie removal and/or blocking
  • Split /etc/defender.conf and default sources, so the config doesn't get flushed on update

Attribution

This app uses a modified version of the python-hosts library.

Sources of ad/spyware blocking rules and their websites are to be found in the application itself. Do not forget to thank/donate to their creators.

Warning

Mind that the app is still in an early version, so use with caution, as damage may occur. You have been warned. Please let me know if you experience any problems.

Data costs may apply, so check the WLAN only option to be safe from the data cost from your provider. Updating may take a long time, depending on the size of the sources.

Also, it is unlikely that the third party sources available in the app may compromise your device, but it may happen (that is why none are enabled by default). Enable only sources you trust - I am not responsible for their contents.

 

If you like this app, please consider a small donation:

Donate in EUR

Donate in USD

Screenshots: 
Application versions: 
AttachmentSizeDate
harbour-defender-0.1-2.armv7hl.rpm82.54 KB01/02/2017 - 01:38
harbour-defender-0.1-2.i486.rpm82.56 KB01/02/2017 - 01:38
harbour-defender-0.2-1.i486.rpm82.61 KB01/02/2017 - 01:49
harbour-defender-0.2-1.armv7hl.rpm82.55 KB01/02/2017 - 01:49
harbour-defender-0.3-1.armv7hl.rpm73.08 KB02/02/2017 - 01:23
harbour-defender-0.3-1.i486.rpm73.06 KB02/02/2017 - 01:23
harbour-defender-0.4.0-1.i486.rpm73.41 KB03/02/2017 - 01:45
harbour-defender-0.4.0-1.armv7hl.rpm73.4 KB03/02/2017 - 01:45
Changelog: 

0.4

  • Fix for devices without AlienDalvik
  • The ability to have different .editable files for native hosts and AlienDalvik hosts is brought back
  • Different formats of source files now supported (the support for list of addresses to block in a text file was added

 

0.3

  • Important fixes to packacking. Update to get the app working.
  • Landscape mode improvements

 

0.2

  • Fixes

0.1

  • Initial version

Comments

olf's picture

Hey nodevel,

your shell script Hosts Adblock made automatically updated hosts file based blocking on SFOS usable, as it was a great enhancement over noADShosts.
But Defender is just awesome. Wow, cool, fully GUI based for John Does and still with all the manually configurable functionality for expert users Hosts Adblock provides. That split is just right, both technically and in terms of usability, IMO.

Some minor flaws and enhancements, I thought of while configuring and using Defender 0.4.0 on SFOS 2.0.5.6:

a. Unconfigured (i.e. initially) and after deselecting all blocking lists (with a subsequent triggering of "Update") Defender states for "Adblock lists": "Blocked 2, Lists 0/25"
This is a bit irritating, as the two entries mentioned as "Blocked" are just the default (localhost) entries and not blocking entries. Maybe subtracting the number of lines of the /etc/hosts.editable file which do not end in 0.0.0.0 from the ones of /etc/hosts yields a better user experience (or my line of thought is too simplistic).

b. The (temporary) "Disable" pulley function in the "Adblock lists" submenu does display a remorse timer with "Preparing", but nothing is done (looking at the hosts files) except for displaying an empty list of hosts blocking lists thereafter. When returning to Defender's top menu, it still (correctly) states the number of blocking entries and blocking lists, going back into "Adblock lists" still (and incorrectly) an empty list is shown (one can go back and forth multiple times, the contradicting information presented persists). It takes a restart of Defender to make the "Adblock lists" submenu reflect reality, again. This was primarily tested with the "Unified basic" (i.e. a single) list.

c. It would be nice to have the blocking list(s) refresh interval configurable in n days (but not hours, as likely some people abuse that to pull blocking lists insanely often).

Getting carried away (daydreaming about a Defender 2.0) ...

d. The ability to provide an exclude list for an blocking list entry. When a blocking list entry is selected in the "Adblock lists" submenu, that would prevent the selection of the entries on its exclude list (maybe plus "graying them out" visually). So putting all the blocking lists integrated into a cumulative list (e.g. one of the various "Unified" lists) on its exclude list as well as other overlapping cumulative lists, would prevent one from selecting and downloading the same entries multiple times on each and every blocking lists update (e.g. by selecting them all, which is currently possible).
NB: In a shell script, I would immediately think of an unique and fixed number for each blocking list entry, but in Python unique (and clearly defined) names / identifiers plus various ways of possible programming magic come to my mind. But again (as I am not a Python programmer), that is likely easier imagined than implemented.

e. Retry failed downloads, if ...

  • ... the device was off, when the download was scheduled.
  • ... the device was on, when the download was scheduled, but no (or deselected, i.e. 2/3/4G when "WLAN only" is set) network was available.
  • ... a download started, but failed.
  • NB: To implement the last point per downloaded file may be overkill, per scheduled download should suit most people well.

    Spontaneous thoughts on implementing:

  • When started (both, by cron or interactively) and e.g. /var/tmp/defender-dwnld.next (or in /var/cache/ , dunno what is more appropriate) does not exist (and at least one blocking list is enabled) write a timestamp of the current time plus 50 Minutes into that file.
  • When the timestamp file does exist and its content (i.e. the timestamp) is in the past, start downloading. If it is not in the past, do nothing.
  • After a successful download of all subscribed blocking lists, add the refresh interval to the current time and write it into the timestamp file.
  • Get woken up by cron every hour in order to check the timestamp file (as depicted in the preceding bullet points).
  • No matter how much of this daydreaming ever becomes true, you are doing a great job: Thanks a lot!

    olf's picture

    Ah, WRT e.: defender-refresh.next looks and sounds better.

    DarkTuring's picture

    Cookie locking improvement idea: when locking the cookie list i cannot delete all blacklisted cookies;

    Allow deletion of blacklisted cookies even with cookie list locked, prevent deletion of whitelisted cookies with locked cookie list.

    abis866p's picture

    Hi, I still cannot use this application. I am on 2.0.5.6 with the Defender version 0.4. The application is stuck in updating phase. In my case, I have previously and manually compiled a host file from the one provided by Hostman on window. I have uploaded that file on my phone and then replaced the /etc/host one. I also replaced the one for android, but I forgot the path for it. Maybe it is a permission issue although I have allowed write permissions to both group and others on /etc/hosts file. I have aliendalvik installed. Any suggestions?

    olf's picture

    Defender 0.4.0 runs nicely on my Jolla 1 under SFOS 2.0.5.6
    Sounds as if you screwed up your hosts files by *replacing* them with ones from Microsoft Windows.
    Suggestion: Overwrite the two hosts files from Windows with the original ones, which you surley backed up before replacing them.
    Just in case you did not:
    - /etc/hosts
    127.0.0.1 localhost.localdomain localhost
    ::1 localhost6.localdomain6 localhost6

    - /system/etc/hosts
    127.0.0.1 localhost

    Mind the empty line at the end of both hosts files.
    Access rights and ownerships for both are: -rw-r--r-- root root
    The /opt/alien/etc/hosts reflects the /etc/hosts file, IIRC.

    abis866p's picture

    The other file that Ihave replaced is /opt/alien/etc/hosts

    DarkTuring's picture

    Bug: the cookie list get overwritten after a while, say i whitelisted domain www.ello.co then after a couple days and regardless of wetger having accesses www.ello.co again i check on the cookie list and its red instead of green assuming that means its been added to the blocked list in the background.

     

     

    I believe there might be a bug that causes cookie settings to be overwritten (my cookie list is not locked).

    nodevel's picture

    Thanks for the feedback. Yes, I will have to rethink the cookie manager part... It looks like it is indeed overwritten. I have a couple of ideas how to solve it and hope to get to it this weekend.

    DarkTuring's picture

    great i look forward to the update, right now i lock it as soon as i can to prevent overwriting or changes to cookie assignments.

    bomo's picture

    I experienced something similar: just installed defender and checked the cookies ans saw that a site (random?) was added.to the whitelist.

    giskard's picture

    How about adding an enable/disable toggle on the cover? It could be useful if you want to check if a particular website doesn't load correctly because of the filters, without opening the full application.

    DarkTuring's picture

    @nodevel For the cookie manager a nice UI touch and improvement would be to index domains by say first letter so facebook would be in the F index and allow expanding and collapsing of cookie content within each domain, that simply will reduce length of scroll list for long cookie lists.

    Within cookie list screen allow ability to sort, non categorized cookies first, new cookies first, Whitelisted or Blocked cookies first (these alphabetical)

    eson's picture

    Can't make it work. App says "Updating", but nothing more happens. No hosts generated and "Updating" is stuck on screen. Tried reinstall but it did not help. Can't even find a way to kill the "Updating".

    SFOS 2.0.5.6 @ Jolla C

     

    <code>

    ,---
    | SailfishOS 2.0.5.6 (Haapajoki) (armv7hl)
    '---
    [nemo@Sailfish ~]$ harbour-defender
    [D] QWaylandEglClientBufferIntegration::QWaylandEglClientBufferIntegration:62 - Using Wayland-EGL
    [W] unknown:24 - file:///usr/share/harbour-defender/qml/pages/components/CookiesMenuItem.qml:24: TypeError: Cannot read property 'cookies_count' of undefined
    [W] unknown:29 - file:///usr/share/harbour-defender/qml/pages/components/CookiesMenuItem.qml:29: TypeError: Cannot read property 'domains_count' of undefined
    [W] unknown:24 - file:///usr/share/harbour-defender/qml/pages/components/SourcesMenuItem.qml:24: TypeError: Cannot read property 'hosts_lines' of undefined
    [W] unknown:29 - file:///usr/share/harbour-defender/qml/pages/components/SourcesMenuItem.qml:29: TypeError: Cannot read property 'sources_enabled_count' of undefined
    [D] :49 - Working directory: /home/nemo

    </code>
     

    nodevel's picture

    Hi,

    thanks for the feedback. First, there's nothing wrong with the output you attached, just a normally working app.

    Second, which version do you have installed? Is it 0.3?

    Finally, updating can take a long time to finish, depending on the number of sources you have enabled. You cannot kill the update from the app and that is by design, as it would require root privileges and could compromise your device.

    If you want to check if the update is running, you can launch top from the terminal and see if there's a python3 process with high CPU usage, if there is, then that's probably it. You can kill it from there, but you need to make sure to remove the following files afterwards:

    • /tmp/hosts
    • /home/nemo/.config/harbour-defender/update

    If there is no such process, then try selecting Update now from the app again and see if it appears.

    I will consider adding an option to Settings to delete these two files in case the update has failed without deleting them.

    eson's picture

    Yes, it's v0.3. No python3 process and I can start it again. Had it running for a moment, but it seemed to kill it self.

    I'll clean up and start it all over again. Hope this time it goes better. I missed the /tmp/hosts last time.

     

    Edit:

    Seems like update went ok, because there is a full /tmp/hosts, but the app gui still says "Updating", and the /etc/hosts is still empty. I only have one list so far (MVPS Hosts).

     

    giskard's picture

    I can confirm the exact same issue. SF 2.0.5 on Jolla 1.

    /tmp/hosts is created, but not copied to /etc/hosts

    No python process listed on top

    nodevel's picture

    Thanks for feedback! I will try to investigate the issue, as it works fine here.

    I already have some ideas - do you have AlienDalvik installed and if you do, are the following directories present in the filesystem?

    • /system/etc
    • /opt/alien/system/etc
    eson's picture

    No AlienDalvik here. Never used it.

    nodevel's picture

    Funny thing is that I almost never used it, but have it installed just in case, so this problem escaped me.

    It should be fixed in the 0.4 version. Thanks for your patience.

    eson's picture

    Yes, thanks! Loading lists in 0.4 is working. All this testing caused other errors, however.

    Defender frontpage doesn't show blocked, lists, cookies or domains anymore. Also my cookie handeling is gone. Cookies seem to be locked, no matter what settings. Browser don't save cookies no more. Problem resist also when I remove Defender.

    I locked cookies ones in Defender 0.3, but unlocked it again almost immediately. That's when this issue appeared.

    My scenario was:

    1. Whitelist 4 cookies
    2. Delete all not whitelisted
    3. Lock cookies
    4. Close Defender and launch Jolla browser to check whitelisted domains (working)
    5. Reboot phone

    ...and this issue was a fact.

    babba22's picture

    Same for me, I followed exactly the same steps as eson and now defender can't access cookies database anymore

    giskard's picture

    No aliendalvik in my case (but I installed and removed it some time ago). I have also restored the default /etc/hosts which was manually substituted by a version with the MPV blocklist.

    /etc/hosts permissions are -rw-r--r-- and is owned by root:root

    I have /system/etc but not /opt/alien/system/etc

    nodevel's picture

    Thanks! It was the problem I suspected - I did not test it without AlienDalvik, which I should have. Version 0.4 should be up with a fix for your scenario, together with other fixes.

    Thanks for the patience.

    giskard's picture

    I don't know why, but it looks like it's happening again. Defender can't update my hosts file. Last time it was changed was 2017-02-08. I can't even disable it and meke it restore my previous hosts file.

     

    EDIT: Apparently resolved by reinstalling Defender.

    giskard's picture

    I can confirm that now it can download lists and update /etc/hosts :)

    lkdhf's picture

    Wonderful, thank you!

    bomo's picture

    Maybe a stupid question, but how to enable a certain hosts provider ? Normal and long press just open their info page.

    nodevel's picture

    That's not a stupid question at all, thanks for asking!

    You need to tap the indicator on the left. I thought about bringing another indicator to the info page, so I can consider it for a future update.

    Either way, please update to 0.3 which fixes the main functionality (generating /etc/hosts file).

    eson's picture

    Thanks! Great app.

    nodevel's picture

    I'm glad you like it!

    PS: Please update to 0.3 which brings an important fix to the functionality.

    Pages