diff options
| author | Bobby <[email protected]> | 2024-12-16 00:41:02 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-12-16 00:41:02 -0500 |
| commit | 04788ddd83c5e80a09a468d07427f0e365db71d7 (patch) | |
| tree | 5c33a8ba990f21c227dc97b5c76729a39cfe0c67 /internal | |
| parent | 5c14aa56c401915a99cf1c6f5700e8e3cb88453b (diff) | |
| download | thatcomputerscientist-04788ddd83c5e80a09a468d07427f0e365db71d7.tar.xz thatcomputerscientist-04788ddd83c5e80a09a468d07427f0e365db71d7.zip | |
pagoda realm
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/pagoda_utilities.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/pagoda_utilities.py b/internal/pagoda_utilities.py new file mode 100644 index 00000000..37c5ca7e --- /dev/null +++ b/internal/pagoda_utilities.py @@ -0,0 +1,44 @@ +from apps.pagoda.models import PagodaSites +import random +import string +import re + + +def pagoda_unique_site_id_generator(): + site_id = "".join(random.choices(string.ascii_letters + string.digits, k=16)) + if PagodaSites.objects.filter(siteUniqueIdentifier=site_id).exists(): + return pagoda_unique_site_id_generator() + return site_id + + +def pagoda_verification_record_generator(record_type): + if record_type == "DNS": + txtName = "".join(random.choices(string.ascii_letters + string.digits, k=8)) + txtValue = "".join(random.choices(string.ascii_letters + string.digits, k=48)) + return txtName, txtValue + elif record_type == "Meta": + metaName = "".join(random.choices(string.ascii_letters + string.digits, k=8)) + metaValue = "".join(random.choices(string.ascii_letters + string.digits, k=48)) + return metaName, metaValue + else: + return None, None + + +def pagoda_url_sanitizer(url): + if not url.startswith("http://") and not url.startswith("https://"): + url = f"http://{url}" + + # Validate if the URL is valid + regex = re.compile( + r"^(?:http|ftp)s?://" + r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}|" + r"localhost|" + r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})" + r"(?::\d+)?" + r"(?:/?|[/?]\S+)$", + re.IGNORECASE, + ) + + if not regex.match(url): + return None + return url |
