This commit is contained in:
Thomas Williams 2024-08-21 12:15:48 +01:00
parent 512f94d7f6
commit 0ebd1abdd7
Signed by: thomas
GPG key ID: EB8F975CF60BCBFF

44
log.py
View file

@ -107,12 +107,12 @@ class logsManager:
global delayUntil global delayUntil
try: try:
conn = pyodbc.connect(self.conn_str) conn = pyodbc.connect(self.conn_str)
cursor = conn.cursor() cursor = conn.cursor()
timeThreshold = datetime.now() - timedelta(days=1) timeThreshold = datetime.now() - timedelta(days=1)
cursor.execute("SELECT blockedipaddress, hostname, city, region, country, loc, org, postal, timezone FROM monutil_geoip WHERE logtime >= ?", timeThreshold) cursor.execute("SELECT blockedipaddress, monutil_geoip.hostname, city, region, country, loc, org, postal, timezone FROM monutil_geoip INNER JOIN monutil_ipblock ON monutil_geoip.logID = monutil_ipblock.logID WHERE logtime >= ? AND blockedipaddress = ?", timeThreshold, ip)
rows = cursor.fetchall() rows = cursor.fetchall()
@ -130,24 +130,24 @@ class logsManager:
"postal": row.postal, "postal": row.postal,
"timezone": row.timezone, "timezone": row.timezone,
} }
if not geoinfo: if not geoinfo:
if 'delayUntil' in locals() and datetime.now() < delayUntil: if 'delayUntil' in locals() and datetime.now() < delayUntil:
print("Rate limit exceeded. Please wait before trying again.") print("Rate limit exceeded. Please wait before trying again.")
return None return None
url = f"https://ipinfo.io/{ip}?token={token}" url = f"https://ipinfo.io/{ip}?token={token}"
response = requests.get(url) response = requests.get(url)
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
if response.status_code == 429: if response.status_code == 429:
print("Rate limit exceeded. Please wait before trying again.") print("Rate limit exceeded. Please wait before trying again.")
today = datetime.now() today = datetime.now()
if today.month == 12: if today.month == 12:
@ -159,17 +159,17 @@ class logsManager:
return None return None
geoinfo = { geoinfo = {
"ip": data.get("ip"), "ip": data.get("ip"),
"hostname": data.get("hostname"), "hostname": data.get("hostname"),
"city": data.get("city"), "city": data.get("city"),
"region": data.get("region"), "region": data.get("region"),
"country": data.get("country"), "country": data.get("country"),
"loc": data.get("loc"), "loc": data.get("loc"),
"org": data.get("org"), "org": data.get("org"),
"postal": data.get("postal"), "postal": data.get("postal"),
"timezone": data.get("timezone"), "timezone": data.get("timezone"),
} }
return geoinfo return geoinfo