Config File
This commit is contained in:
parent
09273f00dd
commit
ece6c7c07b
@ -265,6 +265,7 @@ config_file() {
|
||||
|
||||
local ip_cidr_regex='^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/([0-9]{1,2})$'
|
||||
local ip_regex='^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$'
|
||||
ip_range_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}-([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}$"
|
||||
|
||||
if [[ -n ${NET-} ]]; then
|
||||
if [ "$NET" == "dhcp" ]; then
|
||||
@ -279,13 +280,46 @@ config_file() {
|
||||
else
|
||||
msg_error "Invalid IP Address format for Gateway. Needs to be 0.0.0.0, was ${GATE}"
|
||||
exit
|
||||
fi
|
||||
else
|
||||
msg_error "Gateway IP Address cannot be empty"
|
||||
exit
|
||||
fi
|
||||
elif [[ "$NET" =~ $ip_range_regex ]]; then
|
||||
base="${BASH_REMATCH[1]}"
|
||||
start="${BASH_REMATCH[2]}"
|
||||
end="${BASH_REMATCH[4]}"
|
||||
cidr="${BASH_REMATCH[3]}"
|
||||
|
||||
msg_info "Checking IPs from $base.$start/$cidr to $base.$end/$cidr"
|
||||
|
||||
for ((i=start; i<=end; i++)); do
|
||||
ip="$base.$i"
|
||||
if ! ping -c 1 -W 1 "$ip" > /dev/null 2>&1; then
|
||||
NET="$ip/$cidr"
|
||||
msg_ok "Selected unused IP: $NET"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ! "$NET" =~ / ]]; then
|
||||
msg_error "No free IP found in range"
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$GATE" ]; then
|
||||
if [[ "$GATE" =~ $ip_regex ]]; then
|
||||
echo -e "${GATEWAY}${BOLD}${DGN}Gateway IP Address: ${BGN}$GATE${CL}"
|
||||
GATE=",gw=$GATE"
|
||||
else
|
||||
msg_error "Invalid IP Address format for Gateway. Needs to be 0.0.0.0, was ${GATE}"
|
||||
exit
|
||||
fi
|
||||
else
|
||||
msg_error "Gateway IP Address cannot be empty"
|
||||
exit
|
||||
fi
|
||||
else
|
||||
msg_error "Gateway IP Address cannot be empty"
|
||||
exit
|
||||
fi
|
||||
else
|
||||
msg_error "Invalid IP Address format. Needs to be 0.0.0.0/0, was ${NET}"
|
||||
msg_error "Invalid IP Address format. Needs to be 0.0.0.0/0 or a range like 10.0.0.1/24-10.0.0.10/24, was ${NET}"
|
||||
exit
|
||||
fi
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user