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"
|
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="$SCRIPT_DIR/portspoof.log"
|
||||||
|
|
||||||
# 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
|
||||||
@@ -88,15 +88,13 @@ arrow_menu() {
|
|||||||
|
|
||||||
# ── status box ────────────────────────────────────────────────────────────────
|
# ── status box ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
show_status() {
|
status_box() {
|
||||||
clear
|
|
||||||
echo ""
|
|
||||||
echo " ╔══════════════════════════════════════════════════════════════════════════╗"
|
echo " ╔══════════════════════════════════════════════════════════════════════════╗"
|
||||||
echo " ║ DAProgs HoneyPot Server. ║"
|
echo " ║ DAProgs HoneyPot Server. ║"
|
||||||
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
||||||
echo " ║ Network Interface Status ║"
|
echo " ║ Network Interface Status ║"
|
||||||
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
echo " ╠══════════════════════════════════════════════════════════════════════════╣"
|
||||||
echo " ║ v0.10 ║"
|
echo " ║ v0.11 ║"
|
||||||
|
|
||||||
local ifaces
|
local ifaces
|
||||||
mapfile -t ifaces < <(get_interfaces)
|
mapfile -t ifaces < <(get_interfaces)
|
||||||
@@ -131,6 +129,12 @@ show_status() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo " ╚══════════════════════════════════════════════════════════════════════════╝"
|
echo " ╚══════════════════════════════════════════════════════════════════════════╝"
|
||||||
|
}
|
||||||
|
|
||||||
|
show_status() {
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
status_box
|
||||||
echo ""
|
echo ""
|
||||||
echo " Use ↑ ↓ to navigate, Enter to select, Ctrl+C to exit"
|
echo " Use ↑ ↓ to navigate, Enter to select, Ctrl+C to exit"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -403,6 +407,40 @@ shell_access() {
|
|||||||
read -rp "Press Enter to continue..."
|
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 ────────────────────────────────────────────────────────────────
|
# ── log viewer ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
show_log_viewer() {
|
show_log_viewer() {
|
||||||
@@ -416,27 +454,8 @@ show_log_viewer() {
|
|||||||
printf "║ %-71s║\n" "Last 5 Events ── portspoof.log"
|
printf "║ %-71s║\n" "Last 5 Events ── portspoof.log"
|
||||||
echo "╚══════════════════════════════════════════════════════════════════════════╝"
|
echo "╚══════════════════════════════════════════════════════════════════════════╝"
|
||||||
echo ""
|
echo ""
|
||||||
printf " %-28s %-20s%s\n" "Timestamp" "Source IP" "Destination Port"
|
log_columns
|
||||||
printf " %s %s %s\n" "────────────────────────────" "──────────────────────" "────────────────"
|
log_last5
|
||||||
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
|
|
||||||
echo ""
|
echo ""
|
||||||
echo " Auto-refresh: 1s — press any key to return to the menu"
|
echo " Auto-refresh: 1s — press any key to return to the menu"
|
||||||
if IFS= read -rsn1 -t 1 _; then
|
if IFS= read -rsn1 -t 1 _; then
|
||||||
@@ -448,6 +467,94 @@ for line in sys.stdin:
|
|||||||
trap - INT
|
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 ─────────────────────────────────────────────────────────────────
|
# ── main menu ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
MENU_ITEMS=("Refresh" "Log" "Set Static IP" "Set DHCP" "Shell" "Reboot" "Update")
|
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() {
|
main_menu() {
|
||||||
local choice
|
local choice
|
||||||
while true; do
|
while true; do
|
||||||
show_status
|
main_screen choice
|
||||||
arrow_menu choice "${MENU_ITEMS[@]}"
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
|
|||||||
Reference in new issue
Block a user