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
try:
conn = pyodbc.connect(self.conn_str)
cursor = conn.cursor()
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()
@ -130,24 +130,24 @@ class logsManager:
"postal": row.postal,
"timezone": row.timezone,
}
if not geoinfo:
if 'delayUntil' in locals() and datetime.now() < delayUntil:
print("Rate limit exceeded. Please wait before trying again.")
return None
url = f"https://ipinfo.io/{ip}?token={token}"
url = f"https://ipinfo.io/{ip}?token={token}"
response = requests.get(url)
response.raise_for_status()
data = response.json()
response = requests.get(url)
response.raise_for_status()
data = response.json()
if response.status_code == 429:
if response.status_code == 429:
print("Rate limit exceeded. Please wait before trying again.")
today = datetime.now()
print("Rate limit exceeded. Please wait before trying again.")
today = datetime.now()
if today.month == 12:
@ -159,17 +159,17 @@ class logsManager:
return None
geoinfo = {
"ip": data.get("ip"),
"hostname": data.get("hostname"),
"city": data.get("city"),
"region": data.get("region"),
"country": data.get("country"),
"loc": data.get("loc"),
"org": data.get("org"),
"postal": data.get("postal"),
"timezone": data.get("timezone"),
}
geoinfo = {
"ip": data.get("ip"),
"hostname": data.get("hostname"),
"city": data.get("city"),
"region": data.get("region"),
"country": data.get("country"),
"loc": data.get("loc"),
"org": data.get("org"),
"postal": data.get("postal"),
"timezone": data.get("timezone"),
}
return geoinfo