From d400d98a02e7da8993de0924e00cb0cb5d269c00 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Mon, 3 Mar 2025 09:26:06 +0100 Subject: [PATCH] Add setting to enable opting out of PHONEHOME Fixes #52 --- bugsink/app_settings.py | 1 + bugsink/conf_templates/docker.py.template | 2 ++ bugsink/views.py | 2 ++ phonehome/tasks.py | 2 ++ 4 files changed, 7 insertions(+) diff --git a/bugsink/app_settings.py b/bugsink/app_settings.py index a79a094..d6e217f 100644 --- a/bugsink/app_settings.py +++ b/bugsink/app_settings.py @@ -66,6 +66,7 @@ DEFAULTS = { # Security: "MINIMIZE_INFORMATION_EXPOSURE": False, + "PHONEHOME": True, } diff --git a/bugsink/conf_templates/docker.py.template b/bugsink/conf_templates/docker.py.template index f675d73..7551ae0 100644 --- a/bugsink/conf_templates/docker.py.template +++ b/bugsink/conf_templates/docker.py.template @@ -143,6 +143,8 @@ BUGSINK = { "KEEP_ENVELOPES": int(os.getenv("KEEP_ENVELOPES", 0)), # keep this many in the database; 0 means "don't keep" "MINIMIZE_INFORMATION_EXPOSURE": os.getenv("MINIMIZE_INFORMATION_EXPOSURE", "false").lower() in ("true", "1", "yes"), + + "PHONEHOME": os.getenv("PHONEHOME", "true").lower() in ("true", "1", "yes"), } diff --git a/bugsink/views.py b/bugsink/views.py index aff3dd2..f20fa81 100644 --- a/bugsink/views.py +++ b/bugsink/views.py @@ -62,6 +62,8 @@ def _phone_home(): # features in snappea, [b] we introduce a certain symmetry of measurement between the 2 setups, i.e. the choice of # lazyness does not influence counting and [c] do I really want to get pings for sites where nobody visits home()? + # NOTE: each time this function is called, it will schedule a new task, even when the task would quickly return + # (nothing due, or configured to never send). We _could_ improve that, but doesn't seem performance-critical enough. send_if_due.delay() # _phone_home() wrapper serves as a place for the comment above diff --git a/phonehome/tasks.py b/phonehome/tasks.py index 70b5299..a71556f 100644 --- a/phonehome/tasks.py +++ b/phonehome/tasks.py @@ -32,6 +32,8 @@ INTERVAL = 60 * 60 # phone-home once an hour def send_if_due(): # considered: not sending if DEBUG=True. But why? Expectation is: I'm the sole user of that setting. Better send # also, to keep symmetry, and indirectly check whether my own phone-home still works. + if not get_settings().PHONEHOME: + return # Note on attempted_at / sent_at distinction: attempted_at is when we first tried to send the message, and sent_at # is when we actually sent it. This allows us to try only once an hour, as well as track whether sending succeeded.