mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
diagnostics: Use curl instead of wget for URLs
wget does not seem to support interface scoping for IPv6 addresses. For example, http_proxy=http://[fe80::babe:ff:ffff:babe%eth0]:8118/ . Curl supports this. This fixes most of the failures for IPv6 related addresses. Hide the last failure as there does not seem to be a proper fix from OS level: when using link local addresses, if a hostname is resolved to IPv6 link local address, it is not scoped to that interface. It can't properly be used by any tool then.
This commit is contained in:
parent
97b77e3719
commit
d3f386733f
@ -285,17 +285,20 @@ def _check_port(port, kind='tcp', listen_address=None):
|
||||
return False
|
||||
|
||||
|
||||
def diagnose_url(url, kind=None, env=None, extra_options=None, wrapper=None,
|
||||
expected_output=None):
|
||||
def diagnose_url(url, kind=None, env=None, check_certificate=True,
|
||||
extra_options=None, wrapper=None, expected_output=None):
|
||||
"""Run a diagnostic on whether a URL is accessible.
|
||||
|
||||
Kind can be '4' for IPv4 or '6' for IPv6.
|
||||
"""
|
||||
command = ['wget', '-q', '-O', '-', url]
|
||||
command = ['curl', '-f', '-w', '%{response_code}', url]
|
||||
|
||||
if wrapper:
|
||||
command.insert(0, wrapper)
|
||||
|
||||
if not check_certificate:
|
||||
command.append('-k')
|
||||
|
||||
if extra_options:
|
||||
command.extend(extra_options)
|
||||
|
||||
@ -303,14 +306,16 @@ def diagnose_url(url, kind=None, env=None, extra_options=None, wrapper=None,
|
||||
command.append({'4': '-4', '6': '-6'}[kind])
|
||||
|
||||
try:
|
||||
output = subprocess.check_output(command, env=env)
|
||||
process = subprocess.run(
|
||||
command, env=env, check=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
result = 'passed'
|
||||
if expected_output and expected_output not in output.decode():
|
||||
if expected_output and expected_output not in process.stdout.decode():
|
||||
result = 'failed'
|
||||
except subprocess.CalledProcessError as exception:
|
||||
result = 'failed'
|
||||
# Authorization failed is a success
|
||||
if exception.returncode == 6:
|
||||
if exception.stdout.decode().strip() == '401':
|
||||
result = 'passed'
|
||||
except FileNotFoundError:
|
||||
result = 'error'
|
||||
|
||||
@ -88,6 +88,6 @@ def diagnose():
|
||||
results.append(action_utils.diagnose_port_listening(8112, 'tcp4'))
|
||||
results.append(action_utils.diagnose_port_listening(8112, 'tcp6'))
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/deluge', extra_options=['--no-check-certificate']))
|
||||
'https://{host}/deluge', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
@ -51,6 +51,6 @@ def diagnose():
|
||||
results.append(action_utils.diagnose_port_listening(8000, 'tcp4'))
|
||||
results.append(action_utils.diagnose_port_listening(8000, 'tcp6'))
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'http://{host}/plinth/', extra_options=['--no-check-certificate']))
|
||||
'http://{host}/plinth/', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
@ -85,6 +85,6 @@ def diagnose():
|
||||
results = []
|
||||
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/ikiwiki', extra_options=['--no-check-certificate']))
|
||||
'https://{host}/ikiwiki', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
@ -102,7 +102,7 @@ def diagnose():
|
||||
results = []
|
||||
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/owncloud', extra_options=['--no-check-certificate']))
|
||||
'https://{host}/owncloud', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
@ -91,6 +91,6 @@ def diagnose():
|
||||
results.append(action_utils.diagnose_port_listening(5232, 'tcp4'))
|
||||
results.append(action_utils.diagnose_port_listening(5232, 'tcp6'))
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/radicale', extra_options=['--no-check-certificate']))
|
||||
'https://{host}/radicale', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
@ -96,6 +96,6 @@ def diagnose():
|
||||
results = []
|
||||
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/roundcube', extra_options=['--no-check-certificate']))
|
||||
'https://{host}/roundcube', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
@ -95,7 +95,6 @@ def diagnose():
|
||||
results.append(action_utils.diagnose_port_listening(9091, 'tcp4'))
|
||||
results.append(action_utils.diagnose_port_listening(9091, 'tcp6'))
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/transmission',
|
||||
extra_options=['--no-check-certificate']))
|
||||
'https://{host}/transmission', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
@ -87,6 +87,6 @@ def diagnose():
|
||||
results = []
|
||||
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/tt-rss', extra_options=['--no-check-certificate']))
|
||||
'https://{host}/tt-rss', check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user