mirror of
https://github.com/OpenVoiceOS/OpenVoiceOS
synced 2025-06-05 22:19:21 +02:00
Bump ovos-utils
This commit is contained in:
@ -1,164 +0,0 @@
|
|||||||
From 99594333cb51091f27013cb4cf8b5b5c3177c4aa Mon Sep 17 00:00:00 2001
|
|
||||||
From: jarbasai <jarbasai@mailfence.com>
|
|
||||||
Date: Sat, 10 Dec 2022 15:52:32 +0000
|
|
||||||
Subject: [PATCH 1/2] improve network checks
|
|
||||||
|
|
||||||
---
|
|
||||||
ovos_utils/network_utils.py | 71 ++++++++++++++++++++++++++++++++++---
|
|
||||||
1 file changed, 66 insertions(+), 5 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/ovos_utils/network_utils.py b/ovos_utils/network_utils.py
|
|
||||||
index c7d21c2..4d75e2f 100644
|
|
||||||
--- a/ovos_utils/network_utils.py
|
|
||||||
+++ b/ovos_utils/network_utils.py
|
|
||||||
@@ -1,6 +1,25 @@
|
|
||||||
import socket
|
|
||||||
+
|
|
||||||
import requests
|
|
||||||
|
|
||||||
+from ovos_utils.log import LOG
|
|
||||||
+
|
|
||||||
+
|
|
||||||
+def get_network_tests_config():
|
|
||||||
+ """Get network_tests object from mycroft.configuration."""
|
|
||||||
+ from ovos_config import Configuration
|
|
||||||
+ config = Configuration()
|
|
||||||
+ return config.get(
|
|
||||||
+ "network_tests",
|
|
||||||
+ {
|
|
||||||
+ "ip_url": 'https://api.ipify.org',
|
|
||||||
+ "dns_primary": "1.1.1.1",
|
|
||||||
+ "dns_secondary": "8.8.8.8",
|
|
||||||
+ "web_url": "https://nmcheck.gnome.org/check_network_status.txt",
|
|
||||||
+ "web_url_secondary": "https://checkonline.home-assistant.io/online.txt"
|
|
||||||
+ }
|
|
||||||
+ )
|
|
||||||
+
|
|
||||||
|
|
||||||
def get_ip():
|
|
||||||
# taken from https://stackoverflow.com/a/28950776/13703283
|
|
||||||
@@ -17,27 +36,69 @@ def get_ip():
|
|
||||||
|
|
||||||
|
|
||||||
def get_external_ip():
|
|
||||||
- return requests.get('https://api.ipify.org').text
|
|
||||||
+ cfg = get_network_tests_config()
|
|
||||||
+ return requests.get(cfg["ip_url"]).text
|
|
||||||
|
|
||||||
|
|
||||||
-def is_connected_dns(host="1.1.1.1"):
|
|
||||||
+def is_connected_dns(host=None, port=53, timeout=3):
|
|
||||||
+ """Check internet connection by connecting to DNS servers
|
|
||||||
+ Returns:
|
|
||||||
+ True if internet connection can be detected
|
|
||||||
+ """
|
|
||||||
+
|
|
||||||
+ if host is None:
|
|
||||||
+ cfg = get_network_tests_config()
|
|
||||||
+ return is_connected_dns(cfg["dns_primary"]) or \
|
|
||||||
+ is_connected_dns(cfg["dns_secondary"])
|
|
||||||
+
|
|
||||||
try:
|
|
||||||
# connect to the host -- tells us if the host is actually reachable
|
|
||||||
- socket.create_connection((host, 53))
|
|
||||||
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
+ s.settimeout(timeout)
|
|
||||||
+ s.connect((host, port))
|
|
||||||
return True
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
-def is_connected_http(host="http://duckduckgo.com"):
|
|
||||||
+def is_connected_http(host=None):
|
|
||||||
+ """Check internet connection by connecting to some website
|
|
||||||
+ Returns:
|
|
||||||
+ True if connection attempt succeeded
|
|
||||||
+ """
|
|
||||||
+ if host is None:
|
|
||||||
+ cfg = get_network_tests_config()
|
|
||||||
+ return is_connected_http(cfg["web_url"]) or \
|
|
||||||
+ is_connected_http(cfg["web_url_secondary"])
|
|
||||||
+
|
|
||||||
try:
|
|
||||||
status = requests.head(host).status_code
|
|
||||||
return True
|
|
||||||
- except OSError:
|
|
||||||
+ except:
|
|
||||||
pass
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def is_connected():
|
|
||||||
return any((is_connected_dns(), is_connected_http()))
|
|
||||||
+
|
|
||||||
+
|
|
||||||
+def check_captive_portal(url="http://start.mycroft.ai/portal-check.html",
|
|
||||||
+ expected_text="<title>Portal Check</title>") -> bool:
|
|
||||||
+ """Returns True if a captive portal page is detected"""
|
|
||||||
+ captive_portal = False
|
|
||||||
+
|
|
||||||
+ try:
|
|
||||||
+ # We need to check a site that doesn't use HTTPS
|
|
||||||
+ html_doc = requests.get(url).text
|
|
||||||
+
|
|
||||||
+ # If something different is in the html, we likely were redirected
|
|
||||||
+ # to the portal page.
|
|
||||||
+ if expected_text not in html_doc:
|
|
||||||
+ captive_portal = True
|
|
||||||
+ except Exception:
|
|
||||||
+ LOG.exception("Error checking for captive portal")
|
|
||||||
+
|
|
||||||
+ return captive_portal
|
|
||||||
+
|
|
||||||
|
|
||||||
From a9ccc2d015752959c67a5be29053bd3097380cff Mon Sep 17 00:00:00 2001
|
|
||||||
From: jarbasai <jarbasai@mailfence.com>
|
|
||||||
Date: Sat, 10 Dec 2022 16:25:48 +0000
|
|
||||||
Subject: [PATCH 2/2] portal check
|
|
||||||
|
|
||||||
---
|
|
||||||
ovos_utils/network_utils.py | 17 +++++++++++------
|
|
||||||
1 file changed, 11 insertions(+), 6 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/ovos_utils/network_utils.py b/ovos_utils/network_utils.py
|
|
||||||
index 4d75e2f..d980103 100644
|
|
||||||
--- a/ovos_utils/network_utils.py
|
|
||||||
+++ b/ovos_utils/network_utils.py
|
|
||||||
@@ -15,8 +15,10 @@ def get_network_tests_config():
|
|
||||||
"ip_url": 'https://api.ipify.org',
|
|
||||||
"dns_primary": "1.1.1.1",
|
|
||||||
"dns_secondary": "8.8.8.8",
|
|
||||||
- "web_url": "https://nmcheck.gnome.org/check_network_status.txt",
|
|
||||||
- "web_url_secondary": "https://checkonline.home-assistant.io/online.txt"
|
|
||||||
+ "web_url": "http://nmcheck.gnome.org/check_network_status.txt",
|
|
||||||
+ "web_url_secondary": "https://checkonline.home-assistant.io/online.txt",
|
|
||||||
+ "captive_portal_url": "http://nmcheck.gnome.org/check_network_status.txt",
|
|
||||||
+ "captive_portal_text": "NetworkManager is online"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -84,15 +86,18 @@ def is_connected():
|
|
||||||
return any((is_connected_dns(), is_connected_http()))
|
|
||||||
|
|
||||||
|
|
||||||
-def check_captive_portal(url="http://start.mycroft.ai/portal-check.html",
|
|
||||||
- expected_text="<title>Portal Check</title>") -> bool:
|
|
||||||
+def check_captive_portal(host=None, expected_text=None) -> bool:
|
|
||||||
"""Returns True if a captive portal page is detected"""
|
|
||||||
captive_portal = False
|
|
||||||
|
|
||||||
+ if not host or not expected_text:
|
|
||||||
+ cfg = get_network_tests_config()
|
|
||||||
+ host = host or cfg["captive_portal_url"]
|
|
||||||
+ expected_text = expected_text or cfg["captive_portal_url_text"]
|
|
||||||
+
|
|
||||||
try:
|
|
||||||
# We need to check a site that doesn't use HTTPS
|
|
||||||
- html_doc = requests.get(url).text
|
|
||||||
-
|
|
||||||
+ html_doc = requests.get(host).text
|
|
||||||
# If something different is in the html, we likely were redirected
|
|
||||||
# to the portal page.
|
|
||||||
if expected_text not in html_doc:
|
|
@ -4,4 +4,4 @@ config BR2_PACKAGE_PYTHON_OVOS_UTILS
|
|||||||
collection of simple utilities for use
|
collection of simple utilities for use
|
||||||
across the mycroft ecosystem
|
across the mycroft ecosystem
|
||||||
|
|
||||||
https://github.com/OpenVoiceOS/ovos_utils
|
https://github.com/OpenVoiceOS/ovos-utils
|
||||||
|
@ -1 +1 @@
|
|||||||
sha256 a1ece6a14b2f086ba0e025e850585201572cddbae0c7fe965f23af13da24bb63 python-ovos-utils-2421af7b156a83e620900a50ef058602233eb08d.tar.gz
|
sha256 fae11d62272132489c8170210c8abf70437faaf0b586875f735f916dc69d6e73 python-ovos-utils-9586b18e4e3a00e8f079d6afd4ca8c859d9c549e.tar.gz
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
PYTHON_OVOS_UTILS_VERSION = 2421af7b156a83e620900a50ef058602233eb08d
|
PYTHON_OVOS_UTILS_VERSION = 9586b18e4e3a00e8f079d6afd4ca8c859d9c549e
|
||||||
PYTHON_OVOS_UTILS_SITE = $(call github,OpenVoiceOS,ovos_utils,$(PYTHON_OVOS_UTILS_VERSION))
|
PYTHON_OVOS_UTILS_SITE = $(call github,OpenVoiceOS,ovos_utils,$(PYTHON_OVOS_UTILS_VERSION))
|
||||||
PYTHON_OVOS_UTILS_SETUP_TYPE = setuptools
|
PYTHON_OVOS_UTILS_SETUP_TYPE = setuptools
|
||||||
PYTHON_OVOS_UTILS_LICENSE_FILES = LICENSE
|
PYTHON_OVOS_UTILS_LICENSE_FILES = LICENSE
|
||||||
|
Reference in New Issue
Block a user