peterleinchen / harbour-defender

Defender is a privacy guard for SailfishOS
GNU General Public License v3.0
5 stars 5 forks source link

Block Lists pane absent on Xperia 10 iii with SFOX 4.4.0.64 #5

Open DrYak opened 2 years ago

DrYak commented 2 years ago

Hi, currently migrating to an Xperia 10 iii. After flashing SFOX 4.4.0.64, and attempting to install harbour-defender, I notice that Adblock Lists pane is empty. (nothing shows up under "Sources"), and the counters are missing on the buttons in the main pane.

Quick glance at the journal:

Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [D] unknown:0 - "PyOtherSide error: Traceback (most recent call last):\n\n  File \"/usr/share/harbour-defender/qml/python/defender.py\", line 247, in cookie_is_locked\n    st = os.stat(cookies_path)\n\nFileNotFoundError: [Errno 2] No such file or directory: '/home/nemo/.mozilla/mozembed/cookies.sqlite'\n"
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:0 - Unhandled PyOtherSide error: Return value of PyObject call is NULL: Traceback (most recent call last):

                                                      File "/usr/share/harbour-defender/qml/python/defender.py", line 247, in cookie_is_locked
                                                        st = os.stat(cookies_path)

                                                    FileNotFoundError: [Errno 2] No such file or directory: '/home/nemo/.mozilla/mozembed/cookies.sqlite'
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [D] unknown:0 - "PyOtherSide error: Traceback (most recent call last):\n\n  File \"/usr/share/harbour-defender/qml/python/defender.py\", line 251, in get_stats\n    hosts_lines = int(check_output([\"wc\", \"-l\", \"/etc/hosts\"]).decode(\"utf-8\").split(' ')[0])\n\n  File \"/usr/lib64/python3.8/subprocess.py
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:0 - Unhandled PyOtherSide error: Return value of PyObject call is NULL: Traceback (most recent call last):

                                                      File "/usr/share/harbour-defender/qml/python/defender.py", line 251, in get_stats
                                                        hosts_lines = int(check_output(["wc", "-l", "/etc/hosts"]).decode("utf-8").split(' ')[0])

                                                      File "/usr/lib64/python3.8/subprocess.py", line 415, in check_output
                                                        return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,

                                                      File "/usr/lib64/python3.8/subprocess.py", line 493, in run
                                                        with Popen(*popenargs, **kwargs) as process:

                                                      File "/usr/lib64/python3.8/subprocess.py", line 858, in __init__
                                                        self._execute_child(args, executable, preexec_fn, close_fds,

                                                      File "/usr/lib64/python3.8/subprocess.py", line 1704, in _execute_child
                                                        raise child_exception_type(errno_num, err_msg, err_filename)

                                                    PermissionError: [Errno 13] Permission denied: 'wc'
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [D] unknown:0 - "PyOtherSide error: Traceback (most recent call last):\n\n  File \"/usr/share/harbour-defender/qml/python/defender.py\", line 251, in get_stats\n    hosts_lines = int(check_output([\"wc\", \"-l\", \"/etc/hosts\"]).decode(\"utf-8\").split(' ')[0])\n\n  File \"/usr/lib64/python3.8/subprocess.py
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:0 - Unhandled PyOtherSide error: Return value of PyObject call is NULL: Traceback (most recent call last):

                                                      File "/usr/share/harbour-defender/qml/python/defender.py", line 251, in get_stats
                                                        hosts_lines = int(check_output(["wc", "-l", "/etc/hosts"]).decode("utf-8").split(' ')[0])

                                                      File "/usr/lib64/python3.8/subprocess.py", line 415, in check_output
                                                        return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,

                                                      File "/usr/lib64/python3.8/subprocess.py", line 493, in run
                                                        with Popen(*popenargs, **kwargs) as process:

                                                      File "/usr/lib64/python3.8/subprocess.py", line 858, in __init__
                                                        self._execute_child(args, executable, preexec_fn, close_fds,

                                                      File "/usr/lib64/python3.8/subprocess.py", line 1704, in _execute_child
                                                        raise child_exception_type(errno_num, err_msg, err_filename)

                                                    PermissionError: [Errno 13] Permission denied: 'wc'
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:0 - Unhandled PyOtherSide error: file:///usr/share/harbour-defender/qml/harbour-defender.qml:41: Error: Cannot assign [undefined] to bool
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [D] :49 - Working directory: /home/nemo
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:22 - file:///usr/share/harbour-defender/qml/cover/CoverPage.qml:22: TypeError: Cannot read property 'last_sources' of undefined
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:24 - file:///usr/share/harbour-defender/qml/pages/components/CookiesMenuItem.qml:24: TypeError: Cannot read property 'cookies_count' of undefined
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:29 - file:///usr/share/harbour-defender/qml/pages/components/CookiesMenuItem.qml:29: TypeError: Cannot read property 'domains_count' of undefined
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:24 - file:///usr/share/harbour-defender/qml/pages/components/SourcesMenuItem.qml:24: TypeError: Cannot read property 'hosts_lines' of undefined
Jun 13 12:41:12 Xperia10III harbour-defender[5646]: [W] unknown:29 - file:///usr/share/harbour-defender/qml/pages/components/SourcesMenuItem.qml:29: TypeError: Cannot read property 'sources_enabled_count' of undefined

The failure to wc -l /etc/hosts seems weird, I might be due to the permissions systems that got introduced in the recent 4.x series of SFOX and defender not requesting the correct one.

DrYak commented 2 years ago

Update, playing around with the Python code:

diff --git a/usr/share/harbour-defender/qml/python/defender.py.orig b/usr/share/harbour-defender/qml/python/defender.py
index 906bd0d..4109128 100644
--- a/usr/share/harbour-defender/qml/python/defender.py.orig
+++ b/usr/share/harbour-defender/qml/python/defender.py
@@ -248,8 +248,19 @@ def cookie_is_locked():
     return not bool(st.st_mode & S_IWUSR)

 def get_stats():
-    hosts_lines = int(check_output(["wc", "-l", "/etc/hosts"]).decode("utf-8").split(' ')[0])
-    hosts_editable_lines = int(check_output(["wc", "-l", "/etc/hosts.editable"]).decode("utf-8").split(' ')[0])
+    try:
+        hosts_lines = int(check_output(["wc", "-l", "/etc/hosts"]).decode("utf-8").split(' ')[0])
+    except: # execution permissions missing
+        with open("/etc/hosts", "r") as hf:
+            hosts_lines = len(hf.readlines(  ))
+    try:
+        hosts_editable_lines = int(check_output(["wc", "-l", "/etc/hosts.editable"]).decode("utf-8").split(' ')[0])
+    except: # execution permissions missing
+        try:
+            with open("/etc/hosts.editable", "r") as hf:
+                hosts_editable_lines = len(hf.readlines(  ))
+        except: # hosts.editable file not exposed withing sailjail
+            hosts_editable_lines = 2
     config_etc = configparser.ConfigParser()
     config_etc.read(CONFIG_ETC_PATH)
     config_home = configparser.ConfigParser()
@@ -260,10 +271,11 @@ def get_stats():
     for src in sources:
         if src['sourceenabled']:
             sources_enabled_count += 1
-    cur = sqlite3.connect(cookies_path).cursor()
-    cookies_count, domains_count = cur.execute("SELECT COUNT(*) AS cookies_count, COUNT(DISTINCT baseDomain) AS domains_count FROM moz_cookies").fetchall()[0]
-    cur.connection.close()
-    cookie_bl_count = len(cookie_load_list(blacklist = True))
+    #cur = sqlite3.connect(cookies_path).cursor()
+    #cookies_count, domains_count = cur.execute("SELECT COUNT(*) AS cookies_count, COUNT(DISTINCT baseDomain) AS domains_count FROM moz_cookies").fetchall()[0]
+    #cur.connection.close()
+    #cookie_bl_count = len(cookie_load_list(blacklist = True))
+    cookies_count = domains_count = cookie_bl_count = 0
     if os.path.isfile(LOGFILE_LAST):
         with open(LOGFILE_LAST) as data_file:    
             data = json.load(data_file)

...gets us a bit further.

Key points:

nick8325 commented 1 year ago

You can disable sailjail for defender by adding the following lines to /usr/share/applications/harbour-defender.desktop:

[X-Sailjail]
Sandboxing=Disabled

After I did that, I was able to download and use the adblock lists via the GUI.