From 661f7fe32c5844e86ec976514f662ba79a3d498e Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 11 Jul 2023 16:48:50 +0200 Subject: [PATCH] Proxy scan improvements - handle custom proxies, dont restart when a scan is already running (#1689) --- .../blueprint/check_proxies/__init__.py | 19 ++++++++++++++----- changedetectionio/static/js/recheck-proxy.js | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/changedetectionio/blueprint/check_proxies/__init__.py b/changedetectionio/blueprint/check_proxies/__init__.py index a1c76cf6..bb5ed9b2 100644 --- a/changedetectionio/blueprint/check_proxies/__init__.py +++ b/changedetectionio/blueprint/check_proxies/__init__.py @@ -46,14 +46,18 @@ def construct_blueprint(datastore: ChangeDetectionStore): except content_fetcher.Non200ErrorCodeReceived as e: if e.status_code == 404: status.update({'status': 'OK', 'length': len(contents), 'text': f"OK but 404 (page not found)"}) - elif e.status_code == 403: - status.update({'status': 'ERROR', 'length': len(contents), 'text': f"403 - Access denied"}) + elif e.status_code == 403 or e.status_code == 401: + status.update({'status': 'ERROR', 'length': len(contents), 'text': f"{e.status_code} - Access denied"}) else: status.update({'status': 'ERROR', 'length': len(contents), 'text': f"Status code: {e.status_code}"}) except text_json_diff.FilterNotFoundInResponse: status.update({'status': 'OK', 'length': len(contents), 'text': f"OK but CSS/xPath filter not found (page changed layout?)"}) except content_fetcher.EmptyReply as e: - status.update({'status': 'ERROR OTHER', 'length': len(contents) if contents else 0, 'text': "Empty reply, needs chrome?"}) + if e.status_code == 403 or e.status_code == 401: + status.update({'status': 'ERROR OTHER', 'length': len(contents), 'text': f"Got empty reply with code {e.status_code} - Access denied"}) + else: + status.update({'status': 'ERROR OTHER', 'length': len(contents) if contents else 0, 'text': f"Empty reply with code {e.status_code}, needs chrome?"}) + except Exception as e: status.update({'status': 'ERROR OTHER', 'length': len(contents) if contents else 0, 'text': 'Error: '+str(e)}) else: @@ -94,8 +98,13 @@ def construct_blueprint(datastore: ChangeDetectionStore): if not datastore.proxy_list: return - # @todo - Cancel any existing runs - checks_in_progress[uuid] = {} + if checks_in_progress.get(uuid): + state = _recalc_check_status(uuid=uuid) + for proxy_key, v in state.items(): + if v.get('status') == 'RUNNING': + return state + else: + checks_in_progress[uuid] = {} for k, v in datastore.proxy_list.items(): if not checks_in_progress[uuid].get(k): diff --git a/changedetectionio/static/js/recheck-proxy.js b/changedetectionio/static/js/recheck-proxy.js index e42d2036..5380fe4d 100644 --- a/changedetectionio/static/js/recheck-proxy.js +++ b/changedetectionio/static/js/recheck-proxy.js @@ -12,7 +12,7 @@ $(function () { function set_proxy_check_status(proxy_key, state) { // select input by value name - const proxy_li = $("input[value=" + proxy_key + "]").parent(); + const proxy_li = $('input[value="' + proxy_key + '" ]').parent(); if (state['status'] === 'RUNNING') { $('.proxy-status', proxy_li).html(''); }