mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git
synced 2025-05-16 20:26:58 +00:00
fix simplex parsing
This commit is contained in:
parent
13d39dc5c2
commit
013673fffb
2 changed files with 9 additions and 6 deletions
|
@ -20,17 +20,18 @@ hostname_pattern = re.compile(r'^(?:[a-zA-Z0-9.-]+|[0-9]{1,3}(?:\.[0-9]{1,3}){3}
|
||||||
def IsSimpleXChatroomValid(url: str) -> bool:
|
def IsSimpleXChatroomValid(url: str) -> bool:
|
||||||
"""Validate the SimpleX chatroom URL."""
|
"""Validate the SimpleX chatroom URL."""
|
||||||
REQUIRED_SUBSTRING = "contact#/?v=2-7&smp=smp%3A%2F"
|
REQUIRED_SUBSTRING = "contact#/?v=2-7&smp=smp%3A%2F"
|
||||||
|
REQUIRED_SUBSTRING2 = "contact/#/?v=2-7&smp=smp%3A%2F"
|
||||||
|
|
||||||
# Step 1: Check if it starts with http://, https://, or simplex:/
|
# Step 1: Check if it starts with http://, https://, or simplex:/
|
||||||
if url.startswith(('http://', 'https://', 'simplex:/')):
|
if url.startswith(('http://', 'https://', 'simplex:/')):
|
||||||
# Step 1.5: If http:// or https://, check for valid clearnet or onion domain
|
# Step 1.5: If http:// or https://, check for valid clearnet or onion domain
|
||||||
if url.startswith(('http://', 'https://')):
|
if url.startswith(('http://', 'https://')) and not IsUrlValid(url):
|
||||||
return IsUrlValid(url)
|
return False
|
||||||
elif not url.startswith('simplex:/'):
|
elif not url.startswith('simplex:/'):
|
||||||
return False # Must start with one of the valid protocols
|
return False # Must start with one of the valid protocols
|
||||||
|
|
||||||
# Step 2: Check for the presence of the required substring
|
# Step 2: Check for the presence of the required substring
|
||||||
if REQUIRED_SUBSTRING not in url:
|
if REQUIRED_SUBSTRING not in url and REQUIRED_SUBSTRING2 not in url:
|
||||||
return False # Required substring not found
|
return False # Required substring not found
|
||||||
|
|
||||||
# Step 3: Extract the part after "smp=smp%3A%2F"
|
# Step 3: Extract the part after "smp=smp%3A%2F"
|
||||||
|
|
|
@ -6,6 +6,7 @@ def IsOnionValid(url: str)-> bool:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+(.onion)$")
|
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+(.onion)$")
|
||||||
|
url_pattern = re.compile(r"^(\w+:)?(?://)?(\w+\.)?[a-z2-7]{56}\.onion")
|
||||||
url = url.strip().removesuffix('/')
|
url = url.strip().removesuffix('/')
|
||||||
if url.startswith('http://'):
|
if url.startswith('http://'):
|
||||||
domain = url.split('/')[2]
|
domain = url.split('/')[2]
|
||||||
|
@ -22,14 +23,14 @@ def IsOnionValid(url: str)-> bool:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
#TODO : edit the url to make sure it has http:// at the beginning, in case if it's missing? (problem is that it only returns true or false)
|
#TODO : edit the url to make sure it has http:// at the beginning, in case if it's missing? (problem is that it only returns true or false)
|
||||||
if pattern.fullmatch(url) is not None:
|
if url_pattern.match(url) is not None:
|
||||||
if len(url.split('.')) > 3:
|
if len(url.split('.')) > 3:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if len(url) < 62:
|
if len(url) < 62:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
elif pattern.fullmatch(url) is None:
|
elif url_pattern.match(url) is None:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -41,10 +42,11 @@ def IsUrlValid(url:str)->bool:
|
||||||
Check if url is valid both dark net end clearnet.
|
Check if url is valid both dark net end clearnet.
|
||||||
"""
|
"""
|
||||||
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+$")
|
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+$")
|
||||||
|
onion_pattern = re.compile(r"^(\w+:)?(?://)?(\w+\.)?[a-z2-7]{56}\.onion")
|
||||||
url = str(url)
|
url = str(url)
|
||||||
if len(url) < 4:
|
if len(url) < 4:
|
||||||
return False
|
return False
|
||||||
if url.endswith('.onion'):
|
if onion_pattern.match(url) is not None:
|
||||||
return IsOnionValid(url)
|
return IsOnionValid(url)
|
||||||
else:
|
else:
|
||||||
if not url.__contains__('.'):
|
if not url.__contains__('.'):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue