mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/darknet-lantern.git
synced 2025-07-02 03:06:41 +00:00
FINished adding the trusted and the refactoring of 6
This commit is contained in:
parent
8b0ba4833f
commit
14231fff92
5 changed files with 631 additions and 321 deletions
|
@ -7,11 +7,15 @@ def download_participant_data(participant):
|
|||
"""
|
||||
Downloads the participants csv files and banner
|
||||
|
||||
Parameters:
|
||||
participant (str): The url of the webring participant.
|
||||
Parameters
|
||||
----------
|
||||
participant : str
|
||||
The url of the webring participant.
|
||||
|
||||
Returns:
|
||||
Boolean: True if all files downloaded, False if any of them failed
|
||||
Returns
|
||||
-------
|
||||
Boolean
|
||||
True if all files downloaded, False if any of them failed
|
||||
"""
|
||||
|
||||
try:
|
||||
|
@ -44,28 +48,34 @@ def download_participant_data(participant):
|
|||
utils.print_colors(f"[+] Downloaded webring {participant} csv files and banner")
|
||||
|
||||
except Exception as err:
|
||||
print_colors("[-] Downloading webring participant's files failed.", is_error=True)
|
||||
utils.print_colors("[-] Downloading webring participant's files failed.", is_error=True)
|
||||
|
||||
def clean_csv(df, blacklist):
|
||||
"""
|
||||
Cleans duplications and blacklisted rows
|
||||
|
||||
Parameters:
|
||||
df (dataframe): The dataframe we want to clean.
|
||||
blacklist (list): The blacklisted words.
|
||||
Parameters
|
||||
----------
|
||||
df pd.DataFrame
|
||||
The dataframe we want to clean.
|
||||
blacklist : list
|
||||
The blacklisted words.
|
||||
|
||||
Returns:
|
||||
Dataframe: Cleaned dataframe.
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Cleaned dataframe.
|
||||
"""
|
||||
|
||||
try:
|
||||
if not df.empty:
|
||||
df = utils.remove_duplications(df)
|
||||
|
||||
df = df[~df.apply(lambda row: any(word in str(value) for word in blacklist for value in row), axis=1)]
|
||||
|
||||
|
||||
if not df.empty:
|
||||
df = df[df.apply(utils.is_row_valid, axis=1)]
|
||||
|
||||
|
||||
except Exception as err:
|
||||
print_colors("[-] cleaning dataframe failed", is_error=True)
|
||||
|
||||
|
@ -75,12 +85,17 @@ def mark_sensitive(df, sensitive_list):
|
|||
"""
|
||||
Marks rows as sensitive
|
||||
|
||||
Parameters:
|
||||
df (dataframe): The dataframe we want to mark.
|
||||
sensitive (list): The sensitive words.
|
||||
Parameters
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
The dataframe we want to mark.
|
||||
sensitive : list
|
||||
The sensitive words.
|
||||
|
||||
Returns:
|
||||
Dataframe: Marked dataframe.
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Marked dataframe.
|
||||
"""
|
||||
|
||||
try:
|
||||
|
@ -91,6 +106,72 @@ def mark_sensitive(df, sensitive_list):
|
|||
df.loc[~sensitive_rows, 'Sensitive'] = 'NO'
|
||||
|
||||
except Exception as err:
|
||||
print_colors("[-] MArking sensitive words failed.", is_error=True)
|
||||
print_colors("[-] Marking sensitive words failed.", is_error=True)
|
||||
|
||||
return df
|
||||
return df
|
||||
|
||||
def mark_webring_participant_trusted(webring_df, participant_id, trustworthy):
|
||||
"""
|
||||
Marks a webring to be trusted or not
|
||||
|
||||
Parameters
|
||||
----------
|
||||
webring_df : pd.DataFrame
|
||||
dataframe of all the webring participants
|
||||
participant_id : int
|
||||
the index of the participant
|
||||
trustworthy : bool
|
||||
is the participant trustworthy or not
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Marked webring dataframe with trust/untrust.
|
||||
"""
|
||||
|
||||
try:
|
||||
|
||||
webring_df.iloc[participant_id, webring_df.columns.get_loc('Trusted')] = "YES" if trustworthy else "NO"
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors("[-] Trusting or untrusting a webring participant failed", is_error = True)
|
||||
|
||||
return webring_df
|
||||
|
||||
def mark_webring_participant_blacklist(webring_df, participant_instance, participant_id, blacklisted):
|
||||
"""
|
||||
Marks a webring to be blacklisted or not
|
||||
|
||||
Parameters
|
||||
----------
|
||||
webring_df : pd.DataFrame
|
||||
dataframe of all the webring participants
|
||||
participant_id :int
|
||||
the index of the participant
|
||||
blacklisted : bool
|
||||
is the participant set to be blacklisted or not
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Marked webring dataframe with blacklist/unblacklist.
|
||||
"""
|
||||
|
||||
try:
|
||||
if blacklisted:
|
||||
webring_df.iloc[participant_id, webring_df.columns.get_loc('Blacklisted')] = "YES"
|
||||
|
||||
utils.print_colors(f'[+] Adding new word to blacklist')
|
||||
local_blacklist_df = utils.add_word_to_blacklist(participant_instance)
|
||||
|
||||
else:
|
||||
webring_df.iloc[participant_id, webring_df.columns.get_loc('Blacklisted')] = "NO"
|
||||
|
||||
utils.print_colors(f'[+] Removing word from blacklist')
|
||||
local_blacklist_df = utils.remove_word_from_blacklist(participant_instance)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors("[-] Blacklisting or unblacklisting a webring participlant failed", is_error = True)
|
||||
raise err
|
||||
|
||||
return webring_df
|
213
scripts/logic/options.py
Normal file
213
scripts/logic/options.py
Normal file
|
@ -0,0 +1,213 @@
|
|||
import utils
|
||||
import conf
|
||||
import lantern_logic as lantern
|
||||
|
||||
def run_option_4():
|
||||
try:
|
||||
|
||||
utils.print_colors("4) Synchronize new links from new or existing webring participants, into your local csv files")
|
||||
|
||||
utils.print_colors('[+] Syncing official webrings to local webrings')
|
||||
|
||||
webring_df = utils.get_local_webring_participants()
|
||||
|
||||
current_instance = utils.get_current_instance()
|
||||
|
||||
utils.print_colors('[+] Reading local blacklist and sensitive words')
|
||||
local_blacklist_df = utils.get_local_blacklist()
|
||||
local_sensitive_df = utils.get_local_sensitive()
|
||||
|
||||
utils.print_colors('[+] Reading local verified and unverified')
|
||||
local_verified_df, local_unverified_df = utils.get_local_verified_and_unverified()
|
||||
|
||||
#Remove all rows
|
||||
local_unverified_df = local_unverified_df[0:0]
|
||||
local_verified_df = local_verified_df[0:0]
|
||||
|
||||
for participant in webring_df.itertuples(index=False, name='columns'):
|
||||
# Check if the participant is my instance
|
||||
if current_instance in participant:
|
||||
continue
|
||||
|
||||
if participant.Blacklisted == 'YES':
|
||||
continue
|
||||
|
||||
if not utils.is_participant_reachable(participant.URL):
|
||||
utils.print_colors("[-] Webring {participant.URL} isn't reachable, skipping", is_error=True)
|
||||
continue
|
||||
|
||||
utils.print_colors('[+] Downloading participant\'s files to store locally')
|
||||
lantern.download_participant_data(participant.URL)
|
||||
|
||||
participant_url = utils.generate_local_participant_dir(participant.URL)
|
||||
|
||||
utils.print_colors('[+] Reading webrring participant\'s verified and unverified')
|
||||
participant_verified_df, participant_unverified_df = utils.get_participant_local_verified_and_unverified(participant_url)
|
||||
|
||||
utils.print_colors('[+] Removing unvalidated and blacklisted rows')
|
||||
participant_verified_df = lantern.clean_csv(participant_verified_df, local_blacklist_df['blacklisted-words'].tolist())
|
||||
participant_unverified_df = lantern.clean_csv(participant_unverified_df, local_blacklist_df['blacklisted-words'].tolist())
|
||||
|
||||
utils.print_colors('[+] Marking sensitive rows')
|
||||
participant_verified_df = lantern.mark_sensitive(participant_verified_df, local_sensitive_df['sensitive-words'].tolist())
|
||||
participant_unverified_df = lantern.mark_sensitive(participant_unverified_df, local_sensitive_df['sensitive-words'].tolist())
|
||||
|
||||
if participant.Trusted == 'YES':
|
||||
utils.print_colors('[+] This participant is trusted, copying participant\'s verified to local verified')
|
||||
local_verified_df = utils.merge_verification_df(local_verified_df, participant_verified_df)
|
||||
|
||||
else:
|
||||
utils.print_colors('[+] This participant is not trusted, copying participant\'s verified to local unverified')
|
||||
local_unverified_df = utils.merge_verification_df(local_unverified_df, participant_verified_df)
|
||||
|
||||
utils.print_colors('[+] Copying participant\'s unverified to local unverified')
|
||||
local_unverified_df = utils.merge_verification_df(local_unverified_df, participant_unverified_df)
|
||||
|
||||
utils.print_colors('[+] Saving local verified and unverified')
|
||||
utils.save_local_verified_and_unverified(local_verified_df, local_unverified_df)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors("[-] Option 4 failed suddently, please try again", is_error=True)
|
||||
|
||||
def run_option_6():
|
||||
while True:
|
||||
utils.print_colors("[+] Trust/UnTrust/Blacklist a webring participant (Potentially dangerous)")
|
||||
|
||||
webring_df = utils.get_local_webring_participants()
|
||||
|
||||
webring_path = conf.LOCAL_DIR + conf.WEBRING_CSV_FILE
|
||||
|
||||
utils.print_colors(f'{webring_df[["URL","Trusted", "Blacklisted"]]}')
|
||||
|
||||
try:
|
||||
index = int(input('What is the index of the webring participant that you want to edit? -1 to exit ').strip())
|
||||
|
||||
if index == -1:
|
||||
break
|
||||
|
||||
if index in webring_df.index:
|
||||
choice = input('Do you want to 1) Trust, 2) UnTrust, or 3) Blacklist the webring participant?').strip()
|
||||
|
||||
utils.print_colors('[+] Reading local verified and unverified')
|
||||
local_verified_df, local_unverified_df = utils.get_local_verified_and_unverified()
|
||||
|
||||
participant_instance = webring_df.iloc[index, webring_df.columns.get_loc("URL")]
|
||||
|
||||
|
||||
match choice:
|
||||
case '1':
|
||||
|
||||
# trust the webring participant
|
||||
approve=input('You\'re about to trust another peer, this means that you\'re going to automatically trust all of the links they have in their verified.csv file! If this is a malicious peer, this action might be potentially risky! Do you want to continue ? (y/n)')
|
||||
|
||||
# to lower case incase someone enters Y instead of y
|
||||
if approve.lower() == 'y':
|
||||
try:
|
||||
utils.print_colors(f'[+] Trusting webring participant {participant_instance}')
|
||||
|
||||
webring_df = lantern.mark_webring_participant_trusted(webring_df, index, True)
|
||||
|
||||
webring_df = lantern.mark_webring_participant_blacklist(webring_df, participant_instance, index, False)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors('[-] Trusting webring participant failed', is_error=True)
|
||||
|
||||
else:
|
||||
utils.print_colors('[-] not trusting webring participant', is_error=True)
|
||||
|
||||
case '2':
|
||||
|
||||
try:
|
||||
utils.print_colors(f'[+] Untrusting webring participant {participant_instance}')
|
||||
|
||||
webring_df = lantern.mark_webring_participant_trusted(webring_df, index, False)
|
||||
|
||||
webring_df = lantern.mark_webring_participant_blacklist(webring_df, participant_instance, index, False)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors('[-] Untrusting webring participant failed', is_error=True)
|
||||
|
||||
case '3':
|
||||
|
||||
try:
|
||||
|
||||
utils.print_colors(f'[+] Blacklisting webring participant {participant_instance}')
|
||||
|
||||
webring_df = lantern.mark_webring_participant_trusted(webring_df, index, False)
|
||||
|
||||
webring_df = lantern.mark_webring_participant_blacklist(webring_df, participant_instance, index, True)
|
||||
|
||||
local_blacklist_df = utils.get_local_blacklist()
|
||||
|
||||
utils.print_colors('[+] Removing unvalidated and blacklisted rows')
|
||||
local_verified_df = lantern.clean_csv(local_verified_df, local_blacklist_df['blacklisted-words'].tolist())
|
||||
local_unverified_df = lantern.clean_csv(local_verified_df, local_blacklist_df['blacklisted-words'].tolist())
|
||||
|
||||
participant_dir = f'{conf.PARTICIPANT_DIR}{participant_instance}'
|
||||
|
||||
utils.print_colors(f"[+] removing the participant's directory at {participant_dir}")
|
||||
shutil.rmtree(participant_dir)
|
||||
|
||||
except FileNotFoundError as err:
|
||||
utils.print_colors('[-] File already blacklisted', is_error=True)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors('[-] Blacklisting webring participant failed', is_error=True)
|
||||
|
||||
|
||||
utils.save_dataframe(webring_df, webring_path)
|
||||
|
||||
utils.print_colors('[+] Saving local verified and unverified')
|
||||
utils.save_local_verified_and_unverified(local_verified_df, local_unverified_df)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors("[-] Option 6 failed suddently, please try again", is_error=True)
|
||||
|
||||
def run_option_9():
|
||||
utils.print_colors("[+] 9) Cleaning up all duplicates in your own unverified + verified.csv (based on the url)")
|
||||
|
||||
try:
|
||||
|
||||
utils.print_colors('[+] Reading local verified and unverified')
|
||||
verified_df, unverified_df = utils.get_local_verified_and_unverified()
|
||||
|
||||
utils.print_colors('[+] Removing cross dataframe replications')
|
||||
verified_df, unverified_df = utils.remove_cross_dataframe_replications(verified_df, unverified_df)
|
||||
|
||||
utils.print_colors('[+] Saving local verified and unverified')
|
||||
utils.save_local_verified_and_unverified(verified_df, unverified_df)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors("[-] Option 9 failed suddenly, please try again", is_error=True)
|
||||
|
||||
def run_option_10():
|
||||
utils.print_colors("[+] 10) perform sanity checks on all csv files (to mark them as sensitive / or remove the ones that are blacklisted)")
|
||||
|
||||
try:
|
||||
utils.print_colors('[+] Reading local blacklist and sensitive words')
|
||||
local_blacklist_df = utils.get_local_blacklist()
|
||||
local_sensitive_df = utils.get_local_sensitive()
|
||||
|
||||
for participant in os.listdir(conf.PARTICIPANT_DIR):
|
||||
participant_local_dir = conf.PARTICIPANT_DIR + participant + '/'
|
||||
|
||||
utils.print_colors('[+] Reading webrring participant\'s verified and unverified')
|
||||
participant_verified_df, participant_unverified_df = utils.get_participant_local_verified_and_unverified(participant_local_dir)
|
||||
|
||||
utils.print_colors('[+] Removing unverified and blacklisted rows')
|
||||
participant_verified_df = lantern.clean_csv(participant_verified_df, local_blacklist_df['blacklisted-words'].tolist())
|
||||
participant_unverified_df = lantern.clean_csv(participant_unverified_df, local_blacklist_df['blacklisted-words'].tolist())
|
||||
|
||||
utils.print_colors('[+] Marking sensitive rows')
|
||||
participant_verified_df = lantern.mark_sensitive(participant_verified_df, local_sensitive_df['sensitive-words'].tolist())
|
||||
participant_unverified_df = lantern.mark_sensitive(participant_unverified_df, local_sensitive_df['sensitive-words'].tolist())
|
||||
|
||||
utils.print_colors('[+] Saving local participant verified and unverified')
|
||||
utils.save_local_participant_verified_and_unverified(participant_verified_df, participant_unverified_df, participant_local_dir)
|
||||
|
||||
except Exception as err:
|
||||
utils.print_colors("[-] Option 10 failed suddently, please try again", is_error=True)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue