2610.12 - Adding timeframe.
This commit is contained in:
1 parent
a87f7cedd9
commit
d45a32b8d2
1 file changed
+38
-14
+38
-14
@@ -3,6 +3,14 @@
|
|||||||
INTERFACES_FILE="/etc/network/interfaces"
|
INTERFACES_FILE="/etc/network/interfaces"
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
LOG_FILE="/var/log/portspoof.log"
|
LOG_FILE="/var/log/portspoof.log"
|
||||||
|
EVENTS_WINDOW_FILE="$SCRIPT_DIR/.events_window"
|
||||||
|
EVENTS_HOURS=1
|
||||||
|
if [ -f "$EVENTS_WINDOW_FILE" ]; then
|
||||||
|
read -r _loaded < "$EVENTS_WINDOW_FILE" 2>/dev/null
|
||||||
|
case "$_loaded" in
|
||||||
|
1|72) EVENTS_HOURS="$_loaded" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
# SHA256 hash of the shell access password.
|
# SHA256 hash of the shell access password.
|
||||||
# To change it: echo -n "yourpassword" | sha256sum
|
# To change it: echo -n "yourpassword" | sha256sum
|
||||||
@@ -94,7 +102,7 @@ status_box() {
|
|||||||
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
||||||
echo " ║ Network Interface Status ║"
|
echo " ║ Network Interface Status ║"
|
||||||
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
||||||
echo " ║ v0.16 ║"
|
echo " ║ v0.17 ║"
|
||||||
|
|
||||||
local ifaces
|
local ifaces
|
||||||
mapfile -t ifaces < <(get_interfaces)
|
mapfile -t ifaces < <(get_interfaces)
|
||||||
@@ -408,19 +416,20 @@ shell_access() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ── log helpers ───────────────────────────────────────────────────────────────
|
# ── log helpers ───────────────────────────────────────────────────────────────
|
||||||
# Prints the last 5 events from the past hour (always exactly 5 lines):
|
# Prints the last 5 events within the last $EVENTS_HOURS hours
|
||||||
# timestamp (local time), src_ip, dst_port.
|
# (always exactly 5 lines): timestamp (local time), src_ip, dst_port.
|
||||||
|
|
||||||
log_last5() {
|
log_last5() {
|
||||||
if [ ! -f "$LOG_FILE" ]; then
|
if [ ! -f "$LOG_FILE" ]; then
|
||||||
echo " (log file not found)"
|
echo " (log file not found)"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
tail -n 5 "$LOG_FILE" | python3 -c '
|
tail -n 100 "$LOG_FILE" | EVENTS_HOURS="$EVENTS_HOURS" python3 -c '
|
||||||
import sys, json
|
import sys, json, os
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
hours = int(os.environ.get("EVENTS_HOURS", "1"))
|
||||||
out = []
|
out = []
|
||||||
cutoff = datetime.now(timezone.utc) - timedelta(hours=1)
|
cutoff = datetime.now(timezone.utc) - timedelta(hours=hours)
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line:
|
if not line:
|
||||||
@@ -444,8 +453,10 @@ for line in sys.stdin:
|
|||||||
dst = str(e.get("dst_port", "?"))
|
dst = str(e.get("dst_port", "?"))
|
||||||
local_ts = ts.astimezone().strftime("%Y-%m-%d %H:%M:%S")
|
local_ts = ts.astimezone().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
out.append(f" {local_ts:<34} {src:<18} {dst}")
|
out.append(f" {local_ts:<34} {src:<18} {dst}")
|
||||||
|
out = out[-5:]
|
||||||
if not out:
|
if not out:
|
||||||
out.append(" (no events in the last hour)")
|
label = "hour" if hours == 1 else f"{hours} hours"
|
||||||
|
out.append(f" (no events in the last {label})")
|
||||||
while len(out) < 5:
|
while len(out) < 5:
|
||||||
out.append("")
|
out.append("")
|
||||||
print("\n".join(out))
|
print("\n".join(out))
|
||||||
@@ -467,7 +478,7 @@ show_log_viewer() {
|
|||||||
clear
|
clear
|
||||||
echo ""
|
echo ""
|
||||||
echo "╔══════════════════════════════════════════════════════════════════════════╗"
|
echo "╔══════════════════════════════════════════════════════════════════════════╗"
|
||||||
printf "║ %-75s║\n" "Last 5 Events ── portspoof.log"
|
printf "║ %-75s║\n" "Last 5 Events (last ${EVENTS_HOURS}h) ── portspoof.log"
|
||||||
echo "╚══════════════════════════════════════════════════════════════════════════╝"
|
echo "╚══════════════════════════════════════════════════════════════════════════╝"
|
||||||
echo ""
|
echo ""
|
||||||
log_columns
|
log_columns
|
||||||
@@ -530,7 +541,7 @@ main_screen() {
|
|||||||
print_menu_lines
|
print_menu_lines
|
||||||
echo ""
|
echo ""
|
||||||
echo " ╔══════════════════════════════════════════════════════════════════════════╗"
|
echo " ╔══════════════════════════════════════════════════════════════════════════╗"
|
||||||
printf " ║ %-75s║\n" "Last 5 Events ── portspoof.log"
|
printf " ║ %-75s║\n" "Last 5 Events (last ${EVENTS_HOURS}h) ── portspoof.log"
|
||||||
echo " ╚══════════════════════════════════════════════════════════════════════════╝"
|
echo " ╚══════════════════════════════════════════════════════════════════════════╝"
|
||||||
log_columns
|
log_columns
|
||||||
for (( i=0; i<5; i++ )); do printf '\n'; done
|
for (( i=0; i<5; i++ )); do printf '\n'; done
|
||||||
@@ -573,7 +584,17 @@ main_screen() {
|
|||||||
|
|
||||||
# ── main menu ─────────────────────────────────────────────────────────────────
|
# ── main menu ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
MENU_ITEMS=("Refresh" "Log" "Set Static IP" "Set DHCP" "Shell" "Reboot" "Update")
|
MENU_ITEMS=("Refresh" "Timeframe: ${EVENTS_HOURS}h" "Set Static IP" "Set DHCP" "Shell" "Reboot" "Update")
|
||||||
|
|
||||||
|
toggle_timeframe() {
|
||||||
|
if [ "$EVENTS_HOURS" = "1" ]; then
|
||||||
|
EVENTS_HOURS=72
|
||||||
|
else
|
||||||
|
EVENTS_HOURS=1
|
||||||
|
fi
|
||||||
|
echo "$EVENTS_HOURS" > "$EVENTS_WINDOW_FILE"
|
||||||
|
MENU_ITEMS[2]="Timeframe: ${EVENTS_HOURS}h"
|
||||||
|
}
|
||||||
|
|
||||||
main_menu() {
|
main_menu() {
|
||||||
local choice
|
local choice
|
||||||
@@ -590,26 +611,29 @@ main_menu() {
|
|||||||
read -rp "Press Enter to continue..."
|
read -rp "Press Enter to continue..."
|
||||||
;;
|
;;
|
||||||
2)
|
2)
|
||||||
|
toggle_timeframe
|
||||||
|
;;
|
||||||
|
3)
|
||||||
if select_interface; then
|
if select_interface; then
|
||||||
set_static "$SELECTED_IFACE"
|
set_static "$SELECTED_IFACE"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
read -rp "Press Enter to continue..."
|
read -rp "Press Enter to continue..."
|
||||||
;;
|
;;
|
||||||
3)
|
4)
|
||||||
if select_interface; then
|
if select_interface; then
|
||||||
set_dhcp "$SELECTED_IFACE"
|
set_dhcp "$SELECTED_IFACE"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
read -rp "Press Enter to continue..."
|
read -rp "Press Enter to continue..."
|
||||||
;;
|
;;
|
||||||
4)
|
5)
|
||||||
shell_access
|
shell_access
|
||||||
;;
|
;;
|
||||||
5)
|
6)
|
||||||
reboot_confirm
|
reboot_confirm
|
||||||
;;
|
;;
|
||||||
6)
|
7)
|
||||||
run_update
|
run_update
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in new issue
Block a user