mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git
synced 2025-07-01 12:46:41 +00:00
issue #25: all test checked and passed. the funcs in the utils file are specifically for this folder don't use elsewhere
This commit is contained in:
parent
fb09b21684
commit
574a11fdc5
3 changed files with 37 additions and 50 deletions
Binary file not shown.
|
@ -17,61 +17,48 @@ pattern = re.compile('[0-9A-Za-z-_]*')
|
||||||
# Regular expression pattern for a valid hostname (can be an IP, domain, or onion)
|
# Regular expression pattern for a valid hostname (can be an IP, domain, or onion)
|
||||||
hostname_pattern = re.compile(r'^(?:[a-zA-Z0-9.-]+|[0-9]{1,3}(?:\.[0-9]{1,3}){3}|[a-zA-Z0-9-]+\.onion)$')
|
hostname_pattern = re.compile(r'^(?:[a-zA-Z0-9.-]+|[0-9]{1,3}(?:\.[0-9]{1,3}){3}|[a-zA-Z0-9-]+\.onion)$')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def IsSimpleXChatroomValid(url: str) -> bool:
|
def IsSimpleXChatroomValid(url: str) -> bool:
|
||||||
# Step 1: Check if it starts with http://, https://, or simplex:/
|
"""Validate the SimpleX chatroom URL."""
|
||||||
if url.startswith(('http://', 'https://', 'simplex:/')):
|
REQUIRED_SUBSTRING = "contact#/?v=2-7&smp=smp%3A%2F"
|
||||||
# Step 1.5: If http:// or https://, check for valid clearnet or onion domain
|
|
||||||
if url.startswith(('http://', 'https://')):
|
# Step 1: Check if it starts with http://, https://, or simplex:/
|
||||||
parsed_url = urllib.parse.urlparse(url)
|
if url.startswith(('http://', 'https://', 'simplex:/')):
|
||||||
print(parsed_url.hostname)
|
# Step 1.5: If http:// or https://, check for valid clearnet or onion domain
|
||||||
if not IsUrlValid(parsed_url.hostname):
|
if url.startswith(('http://', 'https://')):
|
||||||
return False # Invalid domain
|
return IsUrlValid(url)
|
||||||
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
|
||||||
|
if REQUIRED_SUBSTRING not in url:
|
||||||
|
return False # Required substring not found
|
||||||
|
|
||||||
# Step 2: Check for the presence of "contact#/?v=2-7&smp=smp%3A%2F"
|
# Step 3: Extract the part after "smp=smp%3A%2F"
|
||||||
if "contact#/?v=2-7&smp=smp%3A%2F" not in url:
|
smp_start = url.find("smp=smp%3A%2F")
|
||||||
return False # Required substring not found
|
if smp_start == -1:
|
||||||
|
return False # Required substring not found
|
||||||
|
|
||||||
|
smp_start += len("smp=smp%3A%2F")
|
||||||
|
smp_end = url.find("&", smp_start)
|
||||||
|
if smp_end == -1:
|
||||||
|
smp_end = len(url) # Take until the end if no "&" is found
|
||||||
|
|
||||||
# Step 3: Extract the part after "smp=smp%3A%2F" and before the next "&" or end of string
|
smp_value = urllib.parse.unquote(url[smp_start:smp_end]) # Decode the URL-encoded string
|
||||||
smp_start = url.find("smp=smp%3A%2F")
|
|
||||||
if smp_start == -1:
|
|
||||||
return False # Required substring not found
|
|
||||||
|
|
||||||
|
# Step 3.5: Check if the smp_value contains a valid hostname
|
||||||
|
if '@' not in smp_value:
|
||||||
|
return False # Must contain '@' to separate fingerprint and hostname
|
||||||
|
|
||||||
smp_start += len("smp=smp%3A%2F")
|
fingerprint, hostname = smp_value.split('@', 1)
|
||||||
smp_end = url.find("&", smp_start)
|
if not IsUrlValid(hostname):
|
||||||
if smp_end == -1:
|
return False # Invalid hostname
|
||||||
smp_end = len(url) # Take until the end if no "&" is found
|
|
||||||
|
|
||||||
|
# Step 4: Check for the presence of "%2F" in the original URL
|
||||||
|
if "%2F" not in url:
|
||||||
|
return False # Required substring not found
|
||||||
|
|
||||||
smp_value = urllib.parse.unquote(url[smp_start:smp_end]) # Decode the URL-encoded string
|
# If all checks pass, return True
|
||||||
|
return True
|
||||||
|
|
||||||
# Step 3.5: Check if the smp_value contains a valid hostname
|
|
||||||
if '@' not in smp_value:
|
|
||||||
return False # Must contain '@' to separate fingerprint and hostname
|
|
||||||
|
|
||||||
|
|
||||||
fingerprint, hostname = smp_value.split('@', 1)
|
|
||||||
if not IsUrlValid(hostname):
|
|
||||||
return False # Invalid hostname
|
|
||||||
|
|
||||||
|
|
||||||
# Step 4: Check for the presence of "%2F" in the original URL
|
|
||||||
if "%2F" not in url:
|
|
||||||
return False # Required substring not found
|
|
||||||
|
|
||||||
|
|
||||||
# If all checks pass, return True
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#xftp://fingerprint:password@host1,host2
|
#xftp://fingerprint:password@host1,host2
|
||||||
|
@ -139,6 +126,6 @@ if __name__ == '__main__':
|
||||||
#link = 'https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D'
|
#link = 'https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D'
|
||||||
#link = 'simplex:/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D'
|
#link = 'simplex:/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2FOReK0M4-3C5NeZyQx_yFuTHSknVVS-3h%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEANi5VHx-Q1mIKmgZEg2ls47NGSlntttvcgLLbfKBpym4%253D&data=%7B%22groupLinkId%22%3A%22ndniy85i4DjITgVhB-MXnQ%3D%3D%22%7D'
|
||||||
#link = 'https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
#link = 'https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
||||||
link = 'https://simplex.hackliberty.org/contact/#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
#link = 'https://simplex.hackliberty.org/contact/#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
||||||
#link = 'http://b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion/contact/#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
#link = 'http://b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion/contact/#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F2KNui9H8xxaPTuHAsQzJlfLmz_SOMsFk%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA8BPETTg3ooyvQ1LiMGeCFbh2MeK9NyubT6NLE8EJzyA%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22type%22%3A%22group%22%2C%22groupLinkId%22%3A%22wNDKKQR3EW8Y045FsVofSg%3D%3D%22%7D'
|
||||||
print(IsSimpleXChatroomValid(link))
|
print(IsSimpleXChatroomValid(link))
|
||||||
|
|
|
@ -5,7 +5,7 @@ def IsOnionValid(url: str)-> bool:
|
||||||
Checks if the domain(param) is a valid onion domain and return True else False.
|
Checks if the domain(param) is a valid onion domain and return True else False.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
pattern = re.compile("^[A-Za-z0-9.]+(.onion)?$")
|
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+(.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]
|
||||||
|
@ -40,7 +40,7 @@ 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("^[A-Za-z0-9:/.-]+$")
|
pattern = re.compile(r"^[A-Za-z0-9:/._%-=#?&@]+$")
|
||||||
url = str(url)
|
url = str(url)
|
||||||
if len(url) < 4:
|
if len(url) < 4:
|
||||||
return False
|
return False
|
||||||
|
@ -51,4 +51,4 @@ def IsUrlValid(url:str)->bool:
|
||||||
return False
|
return False
|
||||||
if pattern.fullmatch(url) is None:
|
if pattern.fullmatch(url) is None:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue