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:
parent
54faeadf07
commit
76e933b3a4
103
misc/build.func
103
misc/build.func
@ -780,7 +780,13 @@ if ! declare -p VAR_WHITELIST >/dev/null 2>&1; then
|
|||||||
)
|
)
|
||||||
fi
|
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() {
|
_sanitize_value() {
|
||||||
# Disallow Command-Substitution / Shell-Meta
|
# Disallow Command-Substitution / Shell-Meta
|
||||||
@ -1112,7 +1118,7 @@ advanced_settings() {
|
|||||||
TAGS="community-script;${var_tags:-}"
|
TAGS="community-script;${var_tags:-}"
|
||||||
local STEP=1
|
local STEP=1
|
||||||
local MAX_STEP=19
|
local MAX_STEP=19
|
||||||
|
|
||||||
# Store values for back navigation
|
# Store values for back navigation
|
||||||
local _ct_type="${CT_TYPE:-1}"
|
local _ct_type="${CT_TYPE:-1}"
|
||||||
local _pw=""
|
local _pw=""
|
||||||
@ -1142,7 +1148,7 @@ advanced_settings() {
|
|||||||
local _mount_fs=""
|
local _mount_fs=""
|
||||||
local _protect_ct="no"
|
local _protect_ct="no"
|
||||||
local _ct_timezone=""
|
local _ct_timezone=""
|
||||||
|
|
||||||
# Helper to show current progress
|
# Helper to show current progress
|
||||||
show_progress() {
|
show_progress() {
|
||||||
local current=$1
|
local current=$1
|
||||||
@ -1175,7 +1181,7 @@ advanced_settings() {
|
|||||||
done
|
done
|
||||||
IFS=$OLD_IFS
|
IFS=$OLD_IFS
|
||||||
BRIDGES=$(echo "$BRIDGES" | grep -v '^\s*$' | sort | uniq)
|
BRIDGES=$(echo "$BRIDGES" | grep -v '^\s*$' | sort | uniq)
|
||||||
|
|
||||||
# Build bridge menu
|
# Build bridge menu
|
||||||
BRIDGE_MENU_OPTIONS=()
|
BRIDGE_MENU_OPTIONS=()
|
||||||
if [[ -n "$BRIDGES" ]]; then
|
if [[ -n "$BRIDGES" ]]; then
|
||||||
@ -1192,15 +1198,18 @@ advanced_settings() {
|
|||||||
# Main wizard loop
|
# Main wizard loop
|
||||||
while [ $STEP -le $MAX_STEP ]; do
|
while [ $STEP -le $MAX_STEP ]; do
|
||||||
case $STEP in
|
case $STEP in
|
||||||
|
|
||||||
# ═══════════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
# STEP 1: Container Type
|
# STEP 1: Container Type
|
||||||
# ═══════════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
1)
|
1)
|
||||||
local default_on="ON"
|
local default_on="ON"
|
||||||
local default_off="OFF"
|
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]" \
|
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
|
||||||
--title "CONTAINER TYPE" \
|
--title "CONTAINER TYPE" \
|
||||||
--ok-button "Next" --cancel-button "Exit" \
|
--ok-button "Next" --cancel-button "Exit" \
|
||||||
@ -1224,7 +1233,7 @@ advanced_settings() {
|
|||||||
--ok-button "Next" --cancel-button "Back" \
|
--ok-button "Next" --cancel-button "Back" \
|
||||||
--passwordbox "\nSet Root Password (needed for root ssh access)\n\nLeave blank for automatic login (no password)" 12 58 \
|
--passwordbox "\nSet Root Password (needed for root ssh access)\n\nLeave blank for automatic login (no password)" 12 58 \
|
||||||
3>&1 1>&2 2>&3); then
|
3>&1 1>&2 2>&3); then
|
||||||
|
|
||||||
if [[ -z "$PW1" ]]; then
|
if [[ -z "$PW1" ]]; then
|
||||||
_pw=""
|
_pw=""
|
||||||
_pw_display="Automatic Login"
|
_pw_display="Automatic Login"
|
||||||
@ -1390,7 +1399,7 @@ advanced_settings() {
|
|||||||
"dhcp" "Automatic (DHCP, recommended)" \
|
"dhcp" "Automatic (DHCP, recommended)" \
|
||||||
"static" "Static (manual entry)" \
|
"static" "Static (manual entry)" \
|
||||||
3>&1 1>&2 2>&3); then
|
3>&1 1>&2 2>&3); then
|
||||||
|
|
||||||
if [[ "$result" == "static" ]]; then
|
if [[ "$result" == "static" ]]; then
|
||||||
# Get static IP
|
# Get static IP
|
||||||
local static_ip
|
local static_ip
|
||||||
@ -1442,43 +1451,43 @@ advanced_settings() {
|
|||||||
"static" "Static (manual entry)" \
|
"static" "Static (manual entry)" \
|
||||||
"none" "Disabled" \
|
"none" "Disabled" \
|
||||||
3>&1 1>&2 2>&3); then
|
3>&1 1>&2 2>&3); then
|
||||||
|
|
||||||
_ipv6_method="$result"
|
_ipv6_method="$result"
|
||||||
case "$result" in
|
case "$result" in
|
||||||
static)
|
static)
|
||||||
local ipv6_addr
|
local ipv6_addr
|
||||||
if ipv6_addr=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
if ipv6_addr=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
||||||
--title "STATIC IPv6 ADDRESS" \
|
--title "STATIC IPv6 ADDRESS" \
|
||||||
--inputbox "\nEnter IPv6 CIDR address\n(e.g. 2001:db8::1/64)" 12 58 "" \
|
--inputbox "\nEnter IPv6 CIDR address\n(e.g. 2001:db8::1/64)" 12 58 "" \
|
||||||
3>&1 1>&2 2>&3); then
|
3>&1 1>&2 2>&3); then
|
||||||
if [[ "$ipv6_addr" =~ ^([0-9a-fA-F:]+:+)+[0-9a-fA-F]+(/[0-9]{1,3})$ ]]; then
|
if [[ "$ipv6_addr" =~ ^([0-9a-fA-F:]+:+)+[0-9a-fA-F]+(/[0-9]{1,3})$ ]]; then
|
||||||
_ipv6_addr="$ipv6_addr"
|
_ipv6_addr="$ipv6_addr"
|
||||||
# Optional gateway
|
# Optional gateway
|
||||||
_ipv6_gate=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
_ipv6_gate=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
||||||
--title "IPv6 GATEWAY" \
|
--title "IPv6 GATEWAY" \
|
||||||
--inputbox "\nEnter IPv6 gateway (optional, leave blank for none)" 10 58 "" \
|
--inputbox "\nEnter IPv6 gateway (optional, leave blank for none)" 10 58 "" \
|
||||||
3>&1 1>&2 2>&3) || true
|
3>&1 1>&2 2>&3) || true
|
||||||
((STEP++))
|
((STEP++))
|
||||||
else
|
else
|
||||||
whiptail --msgbox "Invalid IPv6 CIDR format." 8 58
|
whiptail --msgbox "Invalid IPv6 CIDR format." 8 58
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
;;
|
fi
|
||||||
dhcp)
|
;;
|
||||||
_ipv6_addr="dhcp"
|
dhcp)
|
||||||
_ipv6_gate=""
|
_ipv6_addr="dhcp"
|
||||||
((STEP++))
|
_ipv6_gate=""
|
||||||
;;
|
((STEP++))
|
||||||
none)
|
;;
|
||||||
_ipv6_addr="none"
|
none)
|
||||||
_ipv6_gate=""
|
_ipv6_addr="none"
|
||||||
((STEP++))
|
_ipv6_gate=""
|
||||||
;;
|
((STEP++))
|
||||||
*)
|
;;
|
||||||
_ipv6_addr=""
|
*)
|
||||||
_ipv6_gate=""
|
_ipv6_addr=""
|
||||||
((STEP++))
|
_ipv6_gate=""
|
||||||
;;
|
((STEP++))
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
((STEP--))
|
((STEP--))
|
||||||
@ -1609,7 +1618,7 @@ advanced_settings() {
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
|
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
|
||||||
--title "VERBOSE MODE" \
|
--title "VERBOSE MODE" \
|
||||||
--defaultno \
|
--defaultno \
|
||||||
@ -1628,7 +1637,7 @@ advanced_settings() {
|
|||||||
# Build summary
|
# Build summary
|
||||||
local ct_type_desc="Unprivileged"
|
local ct_type_desc="Unprivileged"
|
||||||
[[ "$_ct_type" == "0" ]] && ct_type_desc="Privileged"
|
[[ "$_ct_type" == "0" ]] && ct_type_desc="Privileged"
|
||||||
|
|
||||||
local summary="Container Type: $ct_type_desc
|
local summary="Container Type: $ct_type_desc
|
||||||
Container ID: $_ct_id
|
Container ID: $_ct_id
|
||||||
Hostname: $_hostname
|
Hostname: $_hostname
|
||||||
@ -1678,14 +1687,14 @@ Options:
|
|||||||
TAGS="$_tags"
|
TAGS="$_tags"
|
||||||
ENABLE_FUSE="$_enable_fuse"
|
ENABLE_FUSE="$_enable_fuse"
|
||||||
VERBOSE="$_verbose"
|
VERBOSE="$_verbose"
|
||||||
|
|
||||||
# Format optional values
|
# Format optional values
|
||||||
[[ -n "$_mtu" ]] && MTU=",mtu=$_mtu" || MTU=""
|
[[ -n "$_mtu" ]] && MTU=",mtu=$_mtu" || MTU=""
|
||||||
[[ -n "$_sd" ]] && SD="-searchdomain=$_sd" || SD=""
|
[[ -n "$_sd" ]] && SD="-searchdomain=$_sd" || SD=""
|
||||||
[[ -n "$_ns" ]] && NS="-nameserver=$_ns" || NS=""
|
[[ -n "$_ns" ]] && NS="-nameserver=$_ns" || NS=""
|
||||||
[[ -n "$_mac" ]] && MAC=",hwaddr=$_mac" || MAC=""
|
[[ -n "$_mac" ]] && MAC=",hwaddr=$_mac" || MAC=""
|
||||||
[[ -n "$_vlan" ]] && VLAN=",tag=$_vlan" || VLAN=""
|
[[ -n "$_vlan" ]] && VLAN=",tag=$_vlan" || VLAN=""
|
||||||
|
|
||||||
# Alpine UDHCPC fix
|
# Alpine UDHCPC fix
|
||||||
if [ "$var_os" == "alpine" ] && [ "$NET" == "dhcp" ] && [ -n "$_ns" ]; then
|
if [ "$var_os" == "alpine" ] && [ "$NET" == "dhcp" ] && [ -n "$_ns" ]; then
|
||||||
UDHCPC_FIX="yes"
|
UDHCPC_FIX="yes"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user