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"
|
||||
|
||||
# SHA256 hash of the shell access password.
|
||||
# To change it: echo -n "yourpassword" | sha256sum
|
||||
# Default password: admin
|
||||
SHELL_PASSWORD_HASH="d26c61e6f4963bcfbfab0c209cb4d24043f2f611ffcf8938cb974bda60a92f0c"
|
||||
|
||||
# ── helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
get_interfaces() {
|
||||
@@ -317,9 +322,42 @@ print(ipaddress.IPv4Network('0.0.0.0/$1', strict=False).prefixlen)
|
||||
" 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 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
MENU_ITEMS=("Set Static IP" "Set DHCP" "Refresh")
|
||||
MENU_ITEMS=("Refresh" "Set Static IP" "Set DHCP" "Shell")
|
||||
|
||||
main_menu() {
|
||||
local choice
|
||||
@@ -330,21 +368,24 @@ main_menu() {
|
||||
|
||||
case "$choice" in
|
||||
0)
|
||||
;; # Refresh — just redraw
|
||||
1)
|
||||
if select_interface; then
|
||||
set_static "$SELECTED_IFACE"
|
||||
fi
|
||||
echo ""
|
||||
read -rp "Press Enter to continue..."
|
||||
;;
|
||||
1)
|
||||
2)
|
||||
if select_interface; then
|
||||
set_dhcp "$SELECTED_IFACE"
|
||||
fi
|
||||
echo ""
|
||||
read -rp "Press Enter to continue..."
|
||||
;;
|
||||
2)
|
||||
;; # just redraw
|
||||
3)
|
||||
shell_access
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user