Refactor advanced_settings and add whitelist check

Moved and redefined _is_whitelisted_key as a global function for use in multiple locations. Improved formatting and readability in the advanced_settings wizard, including better handling of container type selection and IPv6 configuration steps.
This commit is contained in:
CanbiZ 2025-11-27 16:36:53 +01:00
parent 54faeadf07
commit 76e933b3a4

View File

@ -780,7 +780,13 @@ if ! declare -p VAR_WHITELIST >/dev/null 2>&1; then
)
fi
# Note: _is_whitelisted_key() is defined above in default_var_settings section
# Global whitelist check function (used by _load_vars_file_to_map and others)
_is_whitelisted_key() {
local k="$1"
local w
for w in "${VAR_WHITELIST[@]}"; do [ "$k" = "$w" ] && return 0; done
return 1
}
_sanitize_value() {
# Disallow Command-Substitution / Shell-Meta
@ -1199,7 +1205,10 @@ advanced_settings() {
1)
local default_on="ON"
local default_off="OFF"
[[ "$_ct_type" == "0" ]] && { default_on="OFF"; default_off="ON"; }
[[ "$_ct_type" == "0" ]] && {
default_on="OFF"
default_off="ON"
}
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "CONTAINER TYPE" \
@ -1445,40 +1454,40 @@ advanced_settings() {
_ipv6_method="$result"
case "$result" in
static)
local ipv6_addr
if ipv6_addr=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
--title "STATIC IPv6 ADDRESS" \
--inputbox "\nEnter IPv6 CIDR address\n(e.g. 2001:db8::1/64)" 12 58 "" \
3>&1 1>&2 2>&3); then
if [[ "$ipv6_addr" =~ ^([0-9a-fA-F:]+:+)+[0-9a-fA-F]+(/[0-9]{1,3})$ ]]; then
_ipv6_addr="$ipv6_addr"
# Optional gateway
_ipv6_gate=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
--title "IPv6 GATEWAY" \
--inputbox "\nEnter IPv6 gateway (optional, leave blank for none)" 10 58 "" \
3>&1 1>&2 2>&3) || true
((STEP++))
else
whiptail --msgbox "Invalid IPv6 CIDR format." 8 58
fi
static)
local ipv6_addr
if ipv6_addr=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
--title "STATIC IPv6 ADDRESS" \
--inputbox "\nEnter IPv6 CIDR address\n(e.g. 2001:db8::1/64)" 12 58 "" \
3>&1 1>&2 2>&3); then
if [[ "$ipv6_addr" =~ ^([0-9a-fA-F:]+:+)+[0-9a-fA-F]+(/[0-9]{1,3})$ ]]; then
_ipv6_addr="$ipv6_addr"
# Optional gateway
_ipv6_gate=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
--title "IPv6 GATEWAY" \
--inputbox "\nEnter IPv6 gateway (optional, leave blank for none)" 10 58 "" \
3>&1 1>&2 2>&3) || true
((STEP++))
else
whiptail --msgbox "Invalid IPv6 CIDR format." 8 58
fi
;;
dhcp)
_ipv6_addr="dhcp"
_ipv6_gate=""
((STEP++))
;;
none)
_ipv6_addr="none"
_ipv6_gate=""
((STEP++))
;;
*)
_ipv6_addr=""
_ipv6_gate=""
((STEP++))
;;
fi
;;
dhcp)
_ipv6_addr="dhcp"
_ipv6_gate=""
((STEP++))
;;
none)
_ipv6_addr="none"
_ipv6_gate=""
((STEP++))
;;
*)
_ipv6_addr=""
_ipv6_gate=""
((STEP++))
;;
esac
else
((STEP--))