big changes, closer to prod

This commit is contained in:
root 2025-01-18 21:16:22 +01:00
parent 95474141f4
commit f23a6e3ac8
12 changed files with 191 additions and 73 deletions

View file

@ -125,75 +125,91 @@ Maintenance:
#####################################################
case "1":
print("\n[+] Add a new Website entry (into unverified.csv)")
name=''
while(IsNameValid(name) is not True):
name = input("What is the Website name ? ")
category=''
while(IsCategoryValid(category) is not True):
category = input("What is the website Category ? ")
# the url of the website (required) + check if its valid
url=''
while(IsUrlValid(url) is not True):
url=input("What is the website URL ? ")
done = False
while done == False:
print("\n[+] Add a new Website entry (into unverified.csv)")
name=''
while(IsNameValid(name) is not True):
name = input("What is the Website name ? ")
category=''
while(IsCategoryValid(category) is not True):
category = input("What is the website Category ? ")
# the url of the website (required) + check if its valid
url=''
while(IsUrlValid(url) is not True):
url=input("What is the website URL ? ")
# a quick description (optional) + check if its valid
desc='DEFAULT'
while(IsDescriptionValid(desc) is not True):
desc=input("Description for the website ? (Optional)")
# sensitive ? (y/n) + check if its valid
#entry_sensi = input("is it a sensitive website ? (ex: website related to drugs) (y/n)")
sensi = ''
while(IsStatusValid(sensi) is not True):
sensi=input("Is this website sensitive (ex: related to drugs) ? (y/n)")
# a quick description (optional) + check if its valid
desc='DEFAULT'
while(IsDescriptionValid(desc) is not True):
desc=input("Description for the website ? (Optional) ")
# sensitive ? (y/n) + check if its valid
#entry_sensi = input("is it a sensitive website ? (ex: website related to drugs) (y/n)")
newrow=[instance,category,name,url,sensi,desc,'','']
print("[+] NEWROW=",newrow)
# (rest is automatic: status, score, instance is = '' because it is your own instance)
# TODO check if the entry doesn't already exist in verified.csv and in unverified.csv
# if it doesnt exist, add it into unverified.csv
uvdf.loc[-1] = newrow # adding a row
uvdf.index = uvdf.index + 1 # shifting index
uvdf = uvdf.sort_index() # sorting by index
print("[+] New row added! now writing the csv file:")
uvdf.to_csv(unverifiedcsvfile, index=False)
choice=input("Is the website sensitive ? (ex: related to drugs) (y/n) ")
if choice == "n":
sensi = ''
else:
sensi = '✔️'
newrow=[instance,category,name,url,sensi,desc,'','']
print("[+] NEWROW=",newrow)
# (rest is automatic: status, score, instance is = '' because it is your own instance)
# TODO check if the entry doesn't already exist in verified.csv and in unverified.csv
# if it doesnt exist, add it into unverified.csv
uvdf.loc[-1] = newrow # adding a row
uvdf.index = uvdf.index + 1 # shifting index
uvdf = uvdf.sort_index() # sorting by index
print("[+] New row added! now writing the csv file:")
uvdf.to_csv(unverifiedcsvfile, index=False)
choice=input("\n[+] Want to add another website ? (y/n) ")
if choice == "n":
done = True
case "2":
print("[+] Trust a Website entry (move an entry from unverified to verified.csv)")
# search for a word
print(uvdf[['Name','URL']])
name=''
while(IsNameValid(name) is not True):
name = input("What is the Website name you want to trust ? (ex: Nowhere)")
filter_uvdf = uvdf[uvdf.Name.str.contains(name)]
# NOTE and display only the matching entries in unverified.csv in an array format (display it in CLI).
print(filter_uvdf[['Name','URL']])
# check if there are no results, dont proceed if there are none!
if filter_uvdf.size == 0:
print("ERROR no results, skipping.")
else:
# Each of the rows has an index,
index=-1
while (index not in filter_uvdf.index):
# prompt the user to ask for with row they want to move to verified.csv
index = int(input("What is the index of the entry that you want to move to verified.csv ? (ex: 3) "))
# once selected, it must be able to SAVE and print that row:
print(uvdf.iloc[index].values)
newrow=uvdf.iloc[index].values
done = False
while done == False:
vdf = pd.read_csv(verifiedcsvfile)
uvdf = pd.read_csv(unverifiedcsvfile)
# search for a word
print(uvdf[['Name','URL']])
name=''
while(IsNameValid(name) is not True):
name = input("What is the Website name you want to trust ? (ex: Nowhere)")
filter_uvdf = uvdf[uvdf.Name.str.contains(name)]
# NOTE and display only the matching entries in unverified.csv in an array format (display it in CLI).
print(filter_uvdf[['Name','URL']])
# check if there are no results, dont proceed if there are none!
if filter_uvdf.size == 0:
print("ERROR no results, skipping.")
else:
# Each of the rows has an index,
index=-1
while (index not in filter_uvdf.index):
# prompt the user to ask for with row they want to move to verified.csv
index = int(input("What is the index of the entry that you want to move to verified.csv ? (ex: 3) "))
# once selected, it must be able to SAVE and print that row:
print(uvdf.iloc[index].values)
newrow=uvdf.iloc[index].values
# append it into verified.csv
vdf.loc[-1] = newrow # adding a row
vdf.index = vdf.index + 1 # shifting index
vdf = vdf.sort_index() # sorting by index
vdf.to_csv(verifiedcsvfile, index=False)
print("[+] New row added to verified.csv! now writing to the csv")
# append it into verified.csv
vdf.loc[-1] = newrow # adding a row
vdf.index = vdf.index + 1 # shifting index
vdf = vdf.sort_index() # sorting by index
vdf.to_csv(verifiedcsvfile, index=False)
print("[+] New row added to verified.csv! now writing to the csv")
# remove it from unverified.csv
uvdf.drop(index, inplace= True)
uvdf.to_csv(unverifiedcsvfile, index=False)
print("[+] Link is now moved to verified.csv!")
# remove it from unverified.csv
uvdf.drop(index, inplace= True)
uvdf.to_csv(unverifiedcsvfile, index=False)
print("[+] Link is now moved to verified.csv!")
choice=input("\n[+] Want to trust another website ? (y/n) ")
if choice == "n":
done = True
case "3":
print("[+] Untrust a Website entry (move an entry from verified to unverified.csv)")
@ -1035,7 +1051,7 @@ def IsUrlValid(url:str)->bool:
# check that it is only http(s)://wordA.wordB or http(s)://WordC.WordB.WordC, (onion or not), clearnet is fine too (double check if those are fine!)
# if OK return True
#if not : return False
pattern = re.compile("^[A-Za-z0-9:/.]+$")
pattern = re.compile("^[A-Za-z0-9:/.-]+$")
url = str(url)
if len(url) < 4:
#print("Status: Got more than one character or nothing.")
@ -1096,7 +1112,7 @@ def IsScoreValid(score:str)->bool:
def IsDescriptionValid(desc:str)->bool:
"""
Check the categories are only [a-zA-Z0-9,.' ] with 256 max chars.
Check the categories are only [a-zA-Z0-9.' ] with 256 max chars.
"""
# check if the characters are only [a-zA-Z0-9.,' ] with maximum 256 chars max
#(careful with the ' and , make sure you test if it fucks the csv up or else)
@ -1105,7 +1121,7 @@ def IsDescriptionValid(desc:str)->bool:
if desc == "":
# empty description is fine as it's optional
return True
pattern = re.compile("^[A-Za-z0-9-.,' ]+$")
pattern = re.compile("^[A-Za-z0-9-.' ]+$")
desc = str(desc)
desc.strip()
if pattern.fullmatch(desc) is None: