Compare commits

..

No commits in common. "0ebd1abdd76ab089d2031e1f20cd5990104822b6" and "39c5196349d53c7d13c490f9e71d33424e692a67" have entirely different histories.

58
log.py
View file

@ -108,58 +108,33 @@ class logsManager:
try: try:
conn = pyodbc.connect(self.conn_str) if 'delayUntil' in locals() and datetime.now() < delayUntil:
cursor = conn.cursor()
timeThreshold = datetime.now() - timedelta(days=1)
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) print("Rate limit exceeded. Please wait before trying again.")
return None
rows = cursor.fetchall() url = f"https://ipinfo.io/{ip}?token={token}"
geoinfo = [] response = requests.get(url)
response.raise_for_status()
data = response.json()
for row in rows: if response.status_code == 429:
geoinfo = {
"ip": row.blockedipaddress,
"hostname": row.hostname,
"city": row.city,
"region": row.region,
"country": row.country,
"loc": row.loc,
"org": row.org,
"postal": row.postal,
"timezone": row.timezone,
}
if not geoinfo: print("Rate limit exceeded. Please wait before trying again.")
today = datetime.now()
if 'delayUntil' in locals() and datetime.now() < delayUntil: if today.month == 12:
print("Rate limit exceeded. Please wait before trying again.") delayUntil = datetime(today.year + 1, 1, 1)
return None
url = f"https://ipinfo.io/{ip}?token={token}" else:
response = requests.get(url) delayUntil = datetime(today.year, today.month + 1, 1)
response.raise_for_status()
data = response.json()
if response.status_code == 429: return None
print("Rate limit exceeded. Please wait before trying again.") geoinfo = {
today = datetime.now()
if today.month == 12:
delayUntil = datetime(today.year + 1, 1, 1)
else:
delayUntil = datetime(today.year, today.month + 1, 1)
return None
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"),
@ -171,6 +146,7 @@ class logsManager:
"timezone": data.get("timezone"), "timezone": data.get("timezone"),
} }
return geoinfo return geoinfo
except Exception as e: except Exception as e: