added bash
This commit is contained in:
49
network-config.sh
Normal file → Executable file
49
network-config.sh
Normal file → Executable file
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
INTERFACES_FILE="/etc/network/interfaces"
|
INTERFACES_FILE="/etc/network/interfaces"
|
||||||
|
|
||||||
|
# SHA256 hash of the shell access password.
|
||||||
|
# To change it: echo -n "yourpassword" | sha256sum
|
||||||
|
# Default password: admin
|
||||||
|
SHELL_PASSWORD_HASH="d26c61e6f4963bcfbfab0c209cb4d24043f2f611ffcf8938cb974bda60a92f0c"
|
||||||
|
|
||||||
# ── helpers ──────────────────────────────────────────────────────────────────
|
# ── helpers ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
get_interfaces() {
|
get_interfaces() {
|
||||||
@@ -317,9 +322,42 @@ print(ipaddress.IPv4Network('0.0.0.0/$1', strict=False).prefixlen)
|
|||||||
" 2>/dev/null || echo "24"
|
" 2>/dev/null || echo "24"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ── shell access ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
shell_access() {
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo "╔══════════════════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ Shell Access ║"
|
||||||
|
echo "╚══════════════════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
local attempts=3
|
||||||
|
while (( attempts-- > 0 )); do
|
||||||
|
local input input_hash
|
||||||
|
read -rsp " Password: " input
|
||||||
|
echo ""
|
||||||
|
input_hash=$(echo -n "$input" | sha256sum | cut -d' ' -f1)
|
||||||
|
|
||||||
|
if [ "$input_hash" = "$SHELL_PASSWORD_HASH" ]; then
|
||||||
|
echo ""
|
||||||
|
echo " Access granted. Type 'exit' to return to the menu."
|
||||||
|
echo ""
|
||||||
|
bash
|
||||||
|
return
|
||||||
|
else
|
||||||
|
echo " Incorrect password.$( (( attempts > 0 )) && echo " $attempts attempt(s) remaining." || echo "" )"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo " Access denied."
|
||||||
|
echo ""
|
||||||
|
read -rp "Press Enter to continue..."
|
||||||
|
}
|
||||||
|
|
||||||
# ── main menu ─────────────────────────────────────────────────────────────────
|
# ── main menu ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
MENU_ITEMS=("Set Static IP" "Set DHCP" "Refresh")
|
MENU_ITEMS=("Refresh" "Set Static IP" "Set DHCP" "Shell")
|
||||||
|
|
||||||
main_menu() {
|
main_menu() {
|
||||||
local choice
|
local choice
|
||||||
@@ -330,21 +368,24 @@ main_menu() {
|
|||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
0)
|
0)
|
||||||
|
;; # Refresh — just redraw
|
||||||
|
1)
|
||||||
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..."
|
||||||
;;
|
;;
|
||||||
1)
|
2)
|
||||||
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..."
|
||||||
;;
|
;;
|
||||||
2)
|
3)
|
||||||
;; # just redraw
|
shell_access
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user