From 8c65a871066c2cca819b96337554edb674b82f03 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Wed, 4 Dec 2024 13:10:54 +0000 Subject: bugfix : https://bugs.redcorelinux.org/show_bug.cgi?id=164 --- src/backend/checkenv.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/backend/checkenv.py b/src/backend/checkenv.py index 4f540e9..8030bc9 100644 --- a/src/backend/checkenv.py +++ b/src/backend/checkenv.py @@ -1,18 +1,57 @@ #!/usr/bin/python3 import os +import re import subprocess import sisyphus.getenv +import sisyphus.getfs import sisyphus.getnews import urllib.request +from urllib.error import HTTPError + + +NETWORK_CHECK_URL_FILE = os.path.join( + sisyphus.getfs.s_cfg_dir, "network_check_url.conf") + + +def is_valid_url(url): + regex = re.compile( + r'^(http|https)://' + r'([a-zA-Z0-9.-]+)' + r'(\.[a-zA-Z]{2,})' + r'(:\d+)?' + r'(/.*)?$' + ) + return re.match(regex, url) is not None def connectivity(): is_online = int() + default_url = "https://redcorelinux.org" + + try: + with open(NETWORK_CHECK_URL_FILE, "r") as file: + url = file.readline().strip() + + if not url: + url = default_url + + elif not is_valid_url(url): + url = default_url + + except FileNotFoundError: + url = default_url try: - urllib.request.urlopen("http://www.google.com", timeout=5) + urllib.request.urlopen(url, timeout=5) is_online = int(1) + + except HTTPError as e: + if e.code == 429: + is_online = int(1) # ignore rate limiting errors + else: + is_online = int(1) # ignore all other http errors + except urllib.error.URLError: is_online = int(0) -- cgit v1.2.3