From d45a32b8d29b437dcba25881c3c74044569c760f Mon Sep 17 00:00:00 2001 From: DAProgs Date: Tue, 6 Oct 2026 07:40:42 -0400 Subject: [PATCH] 2610.12 - Adding timeframe. --- network-config.sh | 52 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/network-config.sh b/network-config.sh index 2302c67..d42c76b 100755 --- a/network-config.sh +++ b/network-config.sh @@ -3,6 +3,14 @@ INTERFACES_FILE="/etc/network/interfaces" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 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. # To change it: echo -n "yourpassword" | sha256sum @@ -94,7 +102,7 @@ status_box() { echo " ╠══════════════════════════════════════════════════════════════════════════╣" echo " ║ Network Interface Status ║" echo " ╠══════════════════════════════════════════════════════════════════════════╣" - echo " ║ v0.16 ║" + echo " ║ v0.17 ║" local ifaces mapfile -t ifaces < <(get_interfaces) @@ -408,19 +416,20 @@ shell_access() { } # ── log helpers ─────────────────────────────────────────────────────────────── -# Prints the last 5 events from the past hour (always exactly 5 lines): -# timestamp (local time), src_ip, dst_port. +# Prints the last 5 events within the last $EVENTS_HOURS hours +# (always exactly 5 lines): timestamp (local time), src_ip, dst_port. log_last5() { if [ ! -f "$LOG_FILE" ]; then echo " (log file not found)" return fi - tail -n 5 "$LOG_FILE" | python3 -c ' -import sys, json + tail -n 100 "$LOG_FILE" | EVENTS_HOURS="$EVENTS_HOURS" python3 -c ' +import sys, json, os from datetime import datetime, timedelta, timezone +hours = int(os.environ.get("EVENTS_HOURS", "1")) out = [] -cutoff = datetime.now(timezone.utc) - timedelta(hours=1) +cutoff = datetime.now(timezone.utc) - timedelta(hours=hours) for line in sys.stdin: line = line.strip() if not line: @@ -444,8 +453,10 @@ for line in sys.stdin: dst = str(e.get("dst_port", "?")) local_ts = ts.astimezone().strftime("%Y-%m-%d %H:%M:%S") out.append(f" {local_ts:<34} {src:<18} {dst}") +out = out[-5:] 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: out.append("") print("\n".join(out)) @@ -467,7 +478,7 @@ show_log_viewer() { clear 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 @@ -530,7 +541,7 @@ main_screen() { print_menu_lines echo "" echo " ╔══════════════════════════════════════════════════════════════════════════╗" - printf " ║ %-75s║\n" "Last 5 Events ── portspoof.log" + printf " ║ %-75s║\n" "Last 5 Events (last ${EVENTS_HOURS}h) ── portspoof.log" echo " ╚══════════════════════════════════════════════════════════════════════════╝" log_columns for (( i=0; i<5; i++ )); do printf '\n'; done @@ -573,7 +584,17 @@ main_screen() { # ── 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() { local choice @@ -590,26 +611,29 @@ main_menu() { read -rp "Press Enter to continue..." ;; 2) + toggle_timeframe + ;; + 3) if select_interface; then set_static "$SELECTED_IFACE" fi echo "" read -rp "Press Enter to continue..." ;; - 3) + 4) if select_interface; then set_dhcp "$SELECTED_IFACE" fi echo "" read -rp "Press Enter to continue..." ;; - 4) + 5) shell_access ;; - 5) + 6) reboot_confirm ;; - 6) + 7) run_update ;; esac