mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git
synced 2025-07-01 22:16:41 +00:00
issue #25: still WIP
This commit is contained in:
parent
3e4fa309ef
commit
fb09b21684
3 changed files with 167 additions and 18 deletions
54
SimpleX/utils.py
Normal file
54
SimpleX/utils.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import re
|
||||
|
||||
def IsOnionValid(url: str)-> bool:
|
||||
"""
|
||||
Checks if the domain(param) is a valid onion domain and return True else False.
|
||||
"""
|
||||
try:
|
||||
pattern = re.compile("^[A-Za-z0-9.]+(.onion)?$")
|
||||
url = url.strip().removesuffix('/')
|
||||
if url.startswith('http://'):
|
||||
domain = url.split('/')[2]
|
||||
if pattern.fullmatch(domain) is not None:
|
||||
if len(domain.split('.')) > 3:
|
||||
return False
|
||||
else:
|
||||
if len(domain) < 62:
|
||||
return False
|
||||
return True
|
||||
elif pattern.fullmatch(domain) is None:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
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)
|
||||
if pattern.fullmatch(url) is not None:
|
||||
if len(url.split('.')) > 3:
|
||||
return False
|
||||
else:
|
||||
if len(url) < 62:
|
||||
return False
|
||||
return True
|
||||
elif pattern.fullmatch(url) is None:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
def IsUrlValid(url:str)->bool:
|
||||
"""
|
||||
Check if url is valid both dark net end clearnet.
|
||||
"""
|
||||
pattern = re.compile("^[A-Za-z0-9:/.-]+$")
|
||||
url = str(url)
|
||||
if len(url) < 4:
|
||||
return False
|
||||
if url.endswith('.onion'):
|
||||
return IsOnionValid(url)
|
||||
else:
|
||||
if not url.__contains__('.'):
|
||||
return False
|
||||
if pattern.fullmatch(url) is None:
|
||||
return False
|
||||
return True
|
Loading…
Add table
Add a link
Reference in a new issue