This commit is contained in:
DAProgs committed 2026-10-03 20:14:34 -04:00
1 parent c2180fcc8f
commit e16320124b
1 file changed
+19 -3
+19 -3
View File
@@ -408,7 +408,8 @@ shell_access() {
}
# ── log helpers ───────────────────────────────────────────────────────────────
# Prints the last 5 log events (always exactly 5 lines): timestamp, src_ip, dst_port.
# Prints the last 5 events from the past hour (always exactly 5 lines):
# timestamp (local time), src_ip, dst_port.
log_last5() {
if [ ! -f "$LOG_FILE" ]; then
@@ -417,7 +418,9 @@ log_last5() {
fi
tail -n 5 "$LOG_FILE" | python3 -c '
import sys, json
from datetime import datetime, timedelta, timezone
out = []
cutoff = datetime.now(timezone.utc) - timedelta(hours=1)
for line in sys.stdin:
line = line.strip()
if not line:
@@ -426,10 +429,23 @@ for line in sys.stdin:
e = json.loads(line)
except ValueError:
continue
ts = str(e.get("timestamp", "?"))
raw_ts = str(e.get("timestamp", ""))
if raw_ts.endswith("Z"):
raw_ts = raw_ts[:-1] + "+00:00"
try:
ts = datetime.fromisoformat(raw_ts)
except ValueError:
continue
if ts.tzinfo is None:
ts = ts.replace(tzinfo=timezone.utc)
if ts < cutoff:
continue
src = str(e.get("src_ip", "?"))
dst = str(e.get("dst_port", "?"))
out.append(f" {ts:<34} {src:<18} {dst}")
local_ts = ts.astimezone().strftime("%Y-%m-%d %H:%M:%S")
out.append(f" {local_ts:<34} {src:<18} {dst}")
if not out:
out.append(" (no events in the last hour)")
while len(out) < 5:
out.append("")
print("\n".join(out))