issue 26: removed unused module and over indentation

This commit is contained in:
SovereigntyIsNotFreedom 2025-05-17 13:26:11 +01:00
parent f5913a9cef
commit b653171e84

View file

@ -1,6 +1,6 @@
from dotenv import load_dotenv from dotenv import load_dotenv
import asyncio
import os,re,pwd import os,re,pwd
import csv import csv
import random import random
@ -28,168 +28,169 @@ tor_port = os.getenv("TOR_PORT")
#apt install python3-pandas python3-requests python3-socks #apt install python3-pandas python3-requests python3-socks
def main(): def main():
print('[+] ONION UPTIME CHECKER')
print('[+] ONION UPTIME CHECKER')
# TODO get the instance name and exit if its not there # TODO get the instance name and exit if its not there
rootpath='/srv/darknet-lantern/' rootpath='/srv/darknet-lantern/'
urlpath=pwd.getpwuid(os.getuid()).pw_dir+"/.darknet_participant_url" urlpath=pwd.getpwuid(os.getuid()).pw_dir+"/.darknet_participant_url"
#print(urlpath) #print(urlpath)
# check if ~/.darknet_participant_url exists, # check if ~/.darknet_participant_url exists,
# if exists, instance= the content of ~/.darknet_participant_url (which is the url: such as uptime.nowherejez...onion) # if exists, instance= the content of ~/.darknet_participant_url (which is the url: such as uptime.nowherejez...onion)
isitvalid="n" isitvalid="n"
while isitvalid != "y": while isitvalid != "y":
if os.path.isfile(urlpath): if os.path.isfile(urlpath):
with open(urlpath) as f: with open(urlpath) as f:
instance = f.read().rstrip() instance = f.read().rstrip()
# check if the instance URL domain is valid # check if the instance URL domain is valid
if IsOnionValid(instance): if IsOnionValid(instance):
print("[+] Instance Name:",instance,IsOnionValid(instance)) print("[+] Instance Name:",instance,IsOnionValid(instance))
isitvalid="y" isitvalid="y"
else: else:
print('[-] Invalid instance name in ~/.darknet_participant_url:', instance) print('[-] Invalid instance name in ~/.darknet_participant_url:', instance)
return False return False
else: else:
print("[-] Instance path doesn't exist yet, run darknet_exploration.py to set it up" ) print("[-] Instance path doesn't exist yet, run darknet_exploration.py to set it up" )
return False return False
proxies = {
'http': f'{tor_host}:{tor_port}',
'https': f'{tor_host}:{tor_port}'
}
instancepath=rootpath+'www/participants/'+instance+'/'
csvfiles2check=['verified.csv','unverified.csv','webring-participants.csv']
csvfiles2sortcat=['verified.csv','unverified.csv']
#for csvfile in glob.glob("/srv/darknet-lantern/www/links/*.csv"):
for csvfilename in csvfiles2check:
csvfile = instancepath+csvfilename
print('[+] Reading the CSV File:', csvfile)
df = pd.read_csv(csvfile) proxies = {
print(df[['Name','URL']]) 'http': f'{tor_host}:{tor_port}',
print('[+] Checking if each .onion link is reachable:') 'https': f'{tor_host}:{tor_port}'
#for i in range(df.index.stop): }
for i in df.index:
print("[+] Editing the uptime score")
#if empty, set to 100
if pd.isnull(df.at[i,"Score"]):
df.at[i,"Score"] = 100
print(i) instancepath=rootpath+'www/participants/'+instance+'/'
#print(df.at[i,"URL"]) csvfiles2check=['verified.csv','unverified.csv','webring-participants.csv']
url=df.at[i,"URL"] csvfiles2sortcat=['verified.csv','unverified.csv']
try:
index1 = url.find("http://") #for csvfile in glob.glob("/srv/darknet-lantern/www/links/*.csv"):
index2 = url.find("https://") for csvfilename in csvfiles2check:
csvfile = instancepath+csvfilename
print('[+] Reading the CSV File:', csvfile)
if url.startswith("smp://") or url.startswith("xftp://"): df = pd.read_csv(csvfile)
if IsSimpleXServerValid(url): print(df[['Name','URL']])
with connect(f"ws://localhost:3030") as websocket: print('[+] Checking if each .onion link is reachable:')
if url.startswith("smp"): #for i in range(df.index.stop):
query = f"/_server test 1 {url}" for i in df.index:
command = { print("[+] Editing the uptime score")
'corrId': f"id{random.randint(0,999999)}", #if empty, set to 100
'cmd': query, if pd.isnull(df.at[i,"Score"]):
} df.at[i,"Score"] = 100
websocket.send(json.dumps(command))
message = websocket.recv() print(i)
response = json.loads(message) #print(df.at[i,"URL"])
failed_response = response['resp'].get('testFailure') url=df.at[i,"URL"]
try:
index1 = url.find("http://")
index2 = url.find("https://")
if failed_response is None: if url.startswith("smp://") or url.startswith("xftp://"):
print(url, "✔️") if IsSimpleXServerValid(url):
df.at[i, "Status"]="YES" with connect(f"ws://localhost:3030") as websocket:
if df.at[i, "Score"] < 100: if url.startswith("smp"):
df.at[i,"Score"] = df.at[i,"Score"] + 1 query = f"/_server test 1 {url}"
else: command = {
'corrId': f"id{random.randint(0,999999)}",
print(url,"") 'cmd': query,
df.at[i,"Status"]="NO" }
#if uptime >0 do -1 to the value websocket.send(json.dumps(command))
if df.at[i,"Score"] > 0: message = websocket.recv()
df.at[i,"Score"] = df.at[i,"Score"] - 1 response = json.loads(message)
failed_response = response['resp'].get('testFailure')
if failed_response is None:
print(url, "✔️")
df.at[i, "Status"]="YES"
if df.at[i, "Score"] < 100:
df.at[i,"Score"] = df.at[i,"Score"] + 1
else: else:
query = f"/_server test 1 {url}"
command = {
'corrId': f"id{random.randint(0,999999)}",
'cmd': query,
}
websocket.send(json.dumps(command))
message = websocket.recv()
response = json.loads(message)
failed_response = response['resp']['testFailure']
if failed_response is None:
print(url, "✔️")
df.at[i, "Status"]="YES"
if df.at[i, "Score"] < 100:
df.at[i,"Score"] = df.at[i,"Score"] + 1
else:
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
else:
if index1 == -1 and index2 == -1:
url = "http://"+url
status = requests.get(url,proxies=proxies, timeout=5).status_code
print('[+]',url,status)
if status != 502:
print(url,"✔️")
df.at[i,"Status"]="YES"
#if uptime <100 do +1 to the value
if df.at[i,"Score"] < 100:
df.at[i,"Score"] = df.at[i,"Score"] + 1
else:
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
except requests.ConnectionError as e:
#print(e)
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
except requests.exceptions.ReadTimeout as e:
#print(e)
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
except ConnectionRefusedError:
print(url,"✔️")
df.at[i, "Status"]="YES"
if df.at[i, "Score"] < 100:
df.at[i,"Score"] = df.at[i,"Score"] + 1
df2 = df.sort_values(by=["Score"], ascending=False) print(url,"")
#sort by category if you are verified/unverified.csv df.at[i,"Status"]="NO"
if csvfilename in csvfiles2sortcat: #if uptime >0 do -1 to the value
df2 = df.sort_values(by=["Category"], ascending=True) if df.at[i,"Score"] > 0:
#print(df2) df.at[i,"Score"] = df.at[i,"Score"] - 1
df2.to_csv(csvfile, index=False)
else:
query = f"/_server test 1 {url}"
command = {
'corrId': f"id{random.randint(0,999999)}",
'cmd': query,
}
websocket.send(json.dumps(command))
message = websocket.recv()
response = json.loads(message)
failed_response = response['resp']['testFailure']
if failed_response is None:
print(url, "✔️")
df.at[i, "Status"]="YES"
if df.at[i, "Score"] < 100:
df.at[i,"Score"] = df.at[i,"Score"] + 1
else:
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
else:
if index1 == -1 and index2 == -1:
url = "http://"+url
status = requests.get(url,proxies=proxies, timeout=5).status_code
print('[+]',url,status)
if status != 502:
print(url,"✔️")
df.at[i,"Status"]="YES"
#if uptime <100 do +1 to the value
if df.at[i,"Score"] < 100:
df.at[i,"Score"] = df.at[i,"Score"] + 1
else:
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
except requests.ConnectionError as e:
#print(e)
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
except requests.exceptions.ReadTimeout as e:
#print(e)
print(url,"")
df.at[i,"Status"]="NO"
#if uptime >0 do -1 to the value
if df.at[i,"Score"] > 0:
df.at[i,"Score"] = df.at[i,"Score"] - 1
except ConnectionRefusedError:
print(url,"✔️")
df.at[i, "Status"]="YES"
if df.at[i, "Score"] < 100:
df.at[i,"Score"] = df.at[i,"Score"] + 1
df2 = df.sort_values(by=["Score"], ascending=False)
#sort by category if you are verified/unverified.csv
if csvfilename in csvfiles2sortcat:
df2 = df.sort_values(by=["Category"], ascending=True)
#print(df2)
df2.to_csv(csvfile, index=False)
def IsUrlValid(url:str)->bool: def IsUrlValid(url:str)->bool:
""" """