bring support for simplex links now

This commit is contained in:
root 2025-04-21 22:49:36 +02:00
parent 35b90d927f
commit 6de26c5fa5
6 changed files with 95 additions and 9 deletions

View file

@ -211,7 +211,7 @@ Maintenance:
category = input("What is the website Category? ")
# the url of the website (required) + check if its valid
url=''
while(IsUrlValid(url) is not True):
while(IsUrlValid(url) is not True and IsSimpleXChatroomValid(url) is not True):
url=input("What is the website URL ? ")
# a quick description (optional) + check if its valid
@ -412,7 +412,7 @@ Maintenance:
case 3:
# ask the user to select between 1) verified.csv and 2) unverified.csv
while True:
print_colors("[+] Edit link attributes (WIP)")
print_colors("[+] Edit link attributes")
choice = int(input("Do you want to edit link attributes in 1) verified.csv or 2) unverified.csv ? (-1 to exit)").strip())
index=-1
name=''
@ -460,7 +460,7 @@ Maintenance:
value = input("What is the description of the website ? ")
vdf.at[index,'Description']=value
value=''
print(newrow)
print(vdf.iloc[index].values)
print("[+] overwriting existing row with new values:")
vdf.to_csv(verifiedcsvfile, index=False)
break

View file

@ -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