Update network-config.sh
This commit is contained in:
1 parent
f2a2c65325
commit
77c39586c8
1 file changed
+134
-28
+134
-28
@@ -2,7 +2,7 @@
|
||||
|
||||
INTERFACES_FILE="/etc/network/interfaces"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LOG_FILE="var/log/portspoof.log"
|
||||
LOG_FILE="$SCRIPT_DIR/portspoof.log"
|
||||
|
||||
# SHA256 hash of the shell access password.
|
||||
# To change it: echo -n "yourpassword" | sha256sum
|
||||
@@ -88,15 +88,13 @@ arrow_menu() {
|
||||
|
||||
# ── status box ────────────────────────────────────────────────────────────────
|
||||
|
||||
show_status() {
|
||||
clear
|
||||
echo ""
|
||||
status_box() {
|
||||
echo " ╔══════════════════════════════════════════════════════════════════════════╗"
|
||||
echo " ║ DAProgs HoneyPot Server. ║"
|
||||
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
||||
echo " ║ Network Interface Status ║"
|
||||
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
||||
echo " ║ v0.10 ║"
|
||||
echo " ║ v0.11 ║"
|
||||
|
||||
local ifaces
|
||||
mapfile -t ifaces < <(get_interfaces)
|
||||
@@ -131,6 +129,12 @@ show_status() {
|
||||
fi
|
||||
|
||||
echo " ╚══════════════════════════════════════════════════════════════════════════╝"
|
||||
}
|
||||
|
||||
show_status() {
|
||||
clear
|
||||
echo ""
|
||||
status_box
|
||||
echo ""
|
||||
echo " Use ↑ ↓ to navigate, Enter to select, Ctrl+C to exit"
|
||||
echo ""
|
||||
@@ -403,6 +407,40 @@ shell_access() {
|
||||
read -rp "Press Enter to continue..."
|
||||
}
|
||||
|
||||
# ── log helpers ───────────────────────────────────────────────────────────────
|
||||
# Prints the last 5 log events (always exactly 5 lines): timestamp, 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
|
||||
out = []
|
||||
for line in sys.stdin:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
e = json.loads(line)
|
||||
except ValueError:
|
||||
continue
|
||||
ts = str(e.get("timestamp", "?"))
|
||||
src = str(e.get("src_ip", "?"))
|
||||
dst = str(e.get("dst_port", "?"))
|
||||
out.append(f" {ts:<34} {src:<18} {dst}")
|
||||
while len(out) < 5:
|
||||
out.append("")
|
||||
print("\n".join(out))
|
||||
'
|
||||
}
|
||||
|
||||
log_columns() {
|
||||
printf " %-34s %-18s%s\n" "Timestamp" "Source IP" "Destination Port"
|
||||
printf " %s %s %s\n" "──────────────────────────────────" "──────────────────" "──────────────────"
|
||||
}
|
||||
|
||||
# ── log viewer ────────────────────────────────────────────────────────────────
|
||||
|
||||
show_log_viewer() {
|
||||
@@ -416,27 +454,8 @@ show_log_viewer() {
|
||||
printf "║ %-71s║\n" "Last 5 Events ── portspoof.log"
|
||||
echo "╚══════════════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
printf " %-28s %-20s%s\n" "Timestamp" "Source IP" "Destination Port"
|
||||
printf " %s %s %s\n" "────────────────────────────" "──────────────────────" "────────────────"
|
||||
if [ -f "$LOG_FILE" ]; then
|
||||
tail -n 5 "$LOG_FILE" | python3 -c '
|
||||
import sys, json
|
||||
for line in sys.stdin:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
e = json.loads(line)
|
||||
except ValueError:
|
||||
continue
|
||||
ts = str(e.get("timestamp", "?"))
|
||||
src = str(e.get("src_ip", "?"))
|
||||
dst = str(e.get("dst_port", "?"))
|
||||
print(f" {ts:<28} {src:<20} {dst}")
|
||||
'
|
||||
else
|
||||
echo " Log file not found: $LOG_FILE"
|
||||
fi
|
||||
log_columns
|
||||
log_last5
|
||||
echo ""
|
||||
echo " Auto-refresh: 1s — press any key to return to the menu"
|
||||
if IFS= read -rsn1 -t 1 _; then
|
||||
@@ -448,6 +467,94 @@ for line in sys.stdin:
|
||||
trap - INT
|
||||
}
|
||||
|
||||
# ── main screen: status + menu + live log (1s refresh) ────────────────────────
|
||||
# Fixed geometry, measured up from the hint line at the bottom:
|
||||
# 1 blank + 5 log data lines + 5 log header lines + 1 blank + $count menu lines
|
||||
|
||||
main_screen() {
|
||||
local -n _res="$1"
|
||||
local cur=0
|
||||
local count=${#MENU_ITEMS[@]}
|
||||
local key esc
|
||||
|
||||
local status log_lines
|
||||
status=$(status_box)
|
||||
|
||||
print_menu_lines() {
|
||||
local i
|
||||
for (( i=0; i<count; i++ )); do
|
||||
tput el
|
||||
if [ "$i" -eq "$cur" ]; then
|
||||
printf " \e[1;7m %-72s \e[0m\n" "${MENU_ITEMS[$i]}"
|
||||
else
|
||||
printf " %-72s\n" "${MENU_ITEMS[$i]}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
print_log_lines() {
|
||||
local i
|
||||
for (( i=0; i<5; i++ )); do
|
||||
tput el
|
||||
printf '%s\n' "${log_lines[$i]:-}"
|
||||
done
|
||||
}
|
||||
|
||||
tput civis
|
||||
trap 'tput cnorm; echo; exit 130' INT
|
||||
|
||||
mapfile -t log_lines < <(log_last5)
|
||||
|
||||
clear
|
||||
echo ""
|
||||
printf '%s\n' "$status"
|
||||
echo ""
|
||||
for (( i=0; i<count; i++ )); do printf '\n'; done
|
||||
tput cuu "$count"
|
||||
print_menu_lines
|
||||
echo ""
|
||||
echo " ╔══════════════════════════════════════════════════════════════════════════╗"
|
||||
printf " ║ %-71s║\n" "Last 5 Events ── portspoof.log"
|
||||
echo " ╚══════════════════════════════════════════════════════════════════════════╝"
|
||||
log_columns
|
||||
for (( i=0; i<5; i++ )); do printf '\n'; done
|
||||
tput cuu 5
|
||||
print_log_lines
|
||||
echo ""
|
||||
echo " Use ↑ ↓ to navigate, Enter to select, Ctrl+C to exit"
|
||||
tput cuu 1 # park on the hint line; refreshes below are relative to it
|
||||
|
||||
while true; do
|
||||
if IFS= read -rsn1 -t 1 key; then
|
||||
case "$key" in
|
||||
'')
|
||||
break # Enter — selection made
|
||||
;;
|
||||
$'\x1b')
|
||||
IFS= read -rsn2 -t 0.05 esc
|
||||
case "$key$esc" in
|
||||
$'\x1b[A')
|
||||
(( cur = (cur - 1 + count) % count ))
|
||||
tput cuu $((12 + count)); print_menu_lines; tput cud 12
|
||||
;;
|
||||
$'\x1b[B')
|
||||
(( cur = (cur + 1) % count ))
|
||||
tput cuu $((12 + count)); print_menu_lines; tput cud 12
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
else
|
||||
mapfile -t log_lines < <(log_last5)
|
||||
tput cuu 6; print_log_lines; tput cud 1
|
||||
fi
|
||||
done
|
||||
|
||||
tput cnorm
|
||||
trap - INT
|
||||
_res=$cur
|
||||
}
|
||||
|
||||
# ── main menu ─────────────────────────────────────────────────────────────────
|
||||
|
||||
MENU_ITEMS=("Refresh" "Log" "Set Static IP" "Set DHCP" "Shell" "Reboot" "Update")
|
||||
@@ -455,8 +562,7 @@ MENU_ITEMS=("Refresh" "Log" "Set Static IP" "Set DHCP" "Shell" "Reboot" "Update"
|
||||
main_menu() {
|
||||
local choice
|
||||
while true; do
|
||||
show_status
|
||||
arrow_menu choice "${MENU_ITEMS[@]}"
|
||||
main_screen choice
|
||||
echo ""
|
||||
|
||||
case "$choice" in
|
||||
|
||||
Reference in new issue
Block a user