mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git
synced 2025-05-17 04:36:57 +00:00
bring support for simplex links now
This commit is contained in:
parent
35b90d927f
commit
6de26c5fa5
6 changed files with 95 additions and 9 deletions
|
@ -2,6 +2,9 @@ import re
|
|||
import os
|
||||
import requests
|
||||
from PIL import Image
|
||||
#from SimpleX.utils import IsUrlValid
|
||||
import urllib.parse
|
||||
|
||||
|
||||
PURPLE = '\033[35;40m'
|
||||
BOLD_PURPLE = '\033[35;40;1m'
|
||||
|
@ -90,16 +93,59 @@ def IsOnionValid(url: str)-> bool:
|
|||
except Exception as e:
|
||||
return False
|
||||
|
||||
def IsSimpleXChatroomValid(url: str) -> bool:
|
||||
"""Validate the SimpleX chatroom URL."""
|
||||
REQUIRED_SUBSTRING = "#/?v=2-7&smp=smp%3A%2F"
|
||||
|
||||
# Step 1: Check if it starts with http://, https://, or simplex:/
|
||||
if url.startswith(('http://', 'https://', 'simplex:/')):
|
||||
# Step 1.5: If http:// or https://, check for valid clearnet or onion domain
|
||||
if url.startswith(('http://', 'https://')) and not IsUrlValid(url):
|
||||
return False
|
||||
elif not url.startswith('simplex:/'):
|
||||
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 3: Extract the part after "smp=smp%3A%2F"
|
||||
smp_start = url.find("smp=smp%3A%2F")
|
||||
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
|
||||
|
||||
smp_value = urllib.parse.unquote(url[smp_start:smp_end]) # Decode the URL-encoded string
|
||||
|
||||
# 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
|
||||
|
||||
def IsUrlValid(url:str)->bool:
|
||||
"""
|
||||
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:/._%-=#?&@]+$")
|
||||
onion_pattern = re.compile(r"^(\w+:)?(?://)?(\w+\.)?[a-z2-7]{56}\.onion")
|
||||
url = str(url)
|
||||
if len(url) < 4:
|
||||
return False
|
||||
if url.endswith('.onion'):
|
||||
if onion_pattern.match(url) is not None:
|
||||
return IsOnionValid(url)
|
||||
else:
|
||||
if not url.__contains__('.'):
|
||||
|
@ -109,6 +155,24 @@ def IsUrlValid(url:str)->bool:
|
|||
return True
|
||||
|
||||
|
||||
#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
|
||||
|
||||
|
||||
def IsStatusValid(status: str)-> bool:
|
||||
"""
|
||||
Checks if status contains only ['YES','NO']. Verbose only if False is returned
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue