From 0e194aa4b4eb79a0ed6135ecedc3663543852e56 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 15 Sep 2022 16:58:23 +0200 Subject: [PATCH] Default proxy settings fixes --- changedetectionio/__init__.py | 19 ++++++++++++++----- changedetectionio/fetch_site_status.py | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 23693446..de9c3903 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -661,15 +661,16 @@ def changedetection_app(config=None, datastore_o=None): default = deepcopy(datastore.data['settings']) if datastore.proxy_list is not None: + available_proxies = list(datastore.proxy_list.keys()) # When enabled system_proxy = datastore.data['settings']['requests']['proxy'] # In the case it doesnt exist anymore - if not any([system_proxy in tup for tup in datastore.proxy_list]): + if not system_proxy in available_proxies: system_proxy = None - default['requests']['proxy'] = system_proxy if system_proxy is not None else datastore.proxy_list[0][0] + default['requests']['proxy'] = system_proxy if system_proxy is not None else available_proxies[0] # Used by the form handler to keep or remove the proxy settings - default['proxy_list'] = datastore.proxy_list + default['proxy_list'] = available_proxies[0] # Don't use form.data on POST so that it doesnt overrid the checkbox status from the POST status @@ -684,7 +685,10 @@ def changedetection_app(config=None, datastore_o=None): # @todo - Couldn't get setattr() etc dynamic addition working, so remove it instead del form.requests.form.proxy else: - form.requests.form.proxy.choices = datastore.proxy_list + form.requests.form.proxy.choices = [] + for p in datastore.proxy_list: + form.requests.form.proxy.choices.append(tuple((p, datastore.proxy_list[p]['label']))) + if request.method == 'POST': # Password unset is a GET, but we can lock the session to a salted env password to always need the password @@ -1441,7 +1445,12 @@ def ticker_thread_check_time_launch_checks(): # Proxies can be set to have a limit on seconds between which they can be called watch_proxy = watch.get('proxy') - if watch_proxy and any([watch_proxy in p for p in datastore.proxy_list]): + if not watch_proxy: + watch_proxy = datastore.data['settings']['requests']['proxy'] + if not watch_proxy: + watch_proxy = list(datastore.proxy_list.keys())[0] + + if watch_proxy and watch_proxy in list(datastore.proxy_list.keys()): # Proxy may also have some threshold minimum proxy_list_reuse_time_minimum = int(datastore.proxy_list.get(watch_proxy, {}).get('reuse_time_minimum', 0)) if proxy_list_reuse_time_minimum: diff --git a/changedetectionio/fetch_site_status.py b/changedetectionio/fetch_site_status.py index fdc4d7dd..26113353 100644 --- a/changedetectionio/fetch_site_status.py +++ b/changedetectionio/fetch_site_status.py @@ -33,14 +33,14 @@ class perform_site_check(): return None # If its a valid one - if any([watch['proxy'] in p for p in self.datastore.proxy_list]): + if watch['proxy'] and watch['proxy'] in list(self.datastore.proxy_list.keys()): proxy_args = self.datastore.proxy_list.get(watch['proxy']).get('url') # not valid (including None), try the system one else: system_proxy = self.datastore.data['settings']['requests']['proxy'] # Is not None and exists - if self.datastore.proxy_list.get(): + if self.datastore.proxy_list.get(system_proxy): proxy_args = self.datastore.proxy_list.get(system_proxy).get('url') # Fallback - Did not resolve anything, use the first available