diff options
author | V3n3RiX <venerix@koprulu.sector> | 2024-12-04 13:10:54 +0000 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2024-12-04 13:10:54 +0000 |
commit | 8c65a871066c2cca819b96337554edb674b82f03 (patch) | |
tree | 1e020ac7cb3329267b061c4aae404ce1c62d1b5e /src | |
parent | 9641629f358be1c67bee22cf4c64da179aedae48 (diff) |
bugfix : https://bugs.redcorelinux.org/show_bug.cgi?id=164
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/checkenv.py | 41 |
1 files changed, 40 insertions, 1 deletions
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) |