49 lines
2.4 KiB
Python
49 lines
2.4 KiB
Python
import requests
|
|
import re
|
|
import os
|
|
import datetime
|
|
import json
|
|
import smtplib
|
|
|
|
url = "https://onionoo.torproject.org/details"
|
|
r = requests.get(url)
|
|
relays = json.loads(r.content)["relays"]
|
|
|
|
relayWatchEmail = "From: relay status <relaystatus@encryptionin.space>\nTo: relaywatch@lists.encryptionin.space\nSubject: Relay Status " + datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H') + "\n\n"
|
|
relayStatus = ""
|
|
|
|
exitWatchEmail = "From: relay status <relaystatus@encryptionin.space>\nTo: exitwatch@lists.encryptionin.space\nSubject: Exit Status " + datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H') + "\n\n"
|
|
exitStatus = ""
|
|
|
|
for new_relay in relays:
|
|
if datetime.datetime.strptime(new_relay["first_seen"], "%Y-%m-%d %H:%M:%S") > (datetime.datetime.utcnow() - datetime.timedelta(hours=1)):
|
|
exit = "no"
|
|
eol = "no"
|
|
contact = ""
|
|
if "contact" in new_relay:
|
|
test = re.search("([a-zA-Z0-9_.+-]+(\[\]|\@|at)[a-zA-Z0-9-.]+\.[a-zA-Z0-9-.]+)", relay["contact"], re.IGNORECASE)
|
|
if test:
|
|
contact = ", contact: " + test.group(1)
|
|
if not re.search("0.3.5|0.4.5|0.4.6|0.4.7", new_relay["platform"], re.IGNORECASE):
|
|
eol = "yes"
|
|
if new_relay["exit_policy"][0] != "reject *:*":
|
|
exit = "yes"
|
|
exitStatus += "\"" + new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", EOL: " + eol + ", effective family: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n"
|
|
relayStatus += "\"" + new_relay["nickname"] + "\", fingerprint: " + new_relay["fingerprint"] + ", exit: " + exit + ", EOL: " + eol + contact + ", effective family: " + str(len(new_relay["effective_family"])-1) + "; https://metrics.torproject.org/rs.html#search/" + new_relay["fingerprint"] + "\n"
|
|
|
|
if relayStatus:
|
|
relayWatchEmail += relayStatus
|
|
try:
|
|
smtp = smtplib.SMTP('localhost')
|
|
smtp.sendmail('relaystatus@encryptionin.space', ['relaywatch@lists.encryptionin.space'], relayWatchEmail)
|
|
except:
|
|
print("couldn't send")
|
|
|
|
if exitStatus:
|
|
exitWatchEmail += exitStatus
|
|
try:
|
|
smtp = smtplib.SMTP('localhost')
|
|
smtp.sendmail('relaystatus@encryptionin.space', ['exitwatch@lists.encryptionin.space'], exitWatchEmail)
|
|
except:
|
|
print("couldn't send")
|