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
import asyncio
import os,re,pwd
import csv
import random
@ -28,168 +28,169 @@ tor_port = os.getenv("TOR_PORT")
#apt install python3-pandas python3-requests python3-socks
def main():
print('[+] ONION UPTIME CHECKER')
print('[+] ONION UPTIME CHECKER')
# TODO get the instance name and exit if its not there
rootpath='/srv/darknet-lantern/'
urlpath=pwd.getpwuid(os.getuid()).pw_dir+"/.darknet_participant_url"
# TODO get the instance name and exit if its not there
rootpath='/srv/darknet-lantern/'
urlpath=pwd.getpwuid(os.getuid()).pw_dir+"/.darknet_participant_url"
#print(urlpath)
#print(urlpath)
# check if ~/.darknet_participant_url exists,
# if exists, instance= the content of ~/.darknet_participant_url (which is the url: such as uptime.nowherejez...onion)
isitvalid="n"
while isitvalid != "y":
if os.path.isfile(urlpath):
with open(urlpath) as f:
instance = f.read().rstrip()
# check if the instance URL domain is valid
if IsOnionValid(instance):
print("[+] Instance Name:",instance,IsOnionValid(instance))
isitvalid="y"
else:
print('[-] Invalid instance name in ~/.darknet_participant_url:', instance)
return False
else:
print("[-] Instance path doesn't exist yet, run darknet_exploration.py to set it up" )
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)
# check if ~/.darknet_participant_url exists,
# if exists, instance= the content of ~/.darknet_participant_url (which is the url: such as uptime.nowherejez...onion)
isitvalid="n"
while isitvalid != "y":
if os.path.isfile(urlpath):
with open(urlpath) as f:
instance = f.read().rstrip()
# check if the instance URL domain is valid
if IsOnionValid(instance):
print("[+] Instance Name:",instance,IsOnionValid(instance))
isitvalid="y"
else:
print('[-] Invalid instance name in ~/.darknet_participant_url:', instance)
return False
else:
print("[-] Instance path doesn't exist yet, run darknet_exploration.py to set it up" )
return False
df = pd.read_csv(csvfile)
print(df[['Name','URL']])
print('[+] Checking if each .onion link is reachable:')
#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
proxies = {
'http': f'{tor_host}:{tor_port}',
'https': f'{tor_host}:{tor_port}'
}
print(i)
#print(df.at[i,"URL"])
url=df.at[i,"URL"]
try:
index1 = url.find("http://")
index2 = url.find("https://")
if url.startswith("smp://") or url.startswith("xftp://"):
if IsSimpleXServerValid(url):
with connect(f"ws://localhost:3030") as websocket:
if url.startswith("smp"):
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'].get('testFailure')
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)
print(df[['Name','URL']])
print('[+] Checking if each .onion link is reachable:')
#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)
#print(df.at[i,"URL"])
url=df.at[i,"URL"]
try:
index1 = url.find("http://")
index2 = url.find("https://")
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
if url.startswith("smp://") or url.startswith("xftp://"):
if IsSimpleXServerValid(url):
with connect(f"ws://localhost:3030") as websocket:
if url.startswith("smp"):
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'].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:
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)
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:
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:
"""