ip format validator fix for cidr

This commit is contained in:
Serghey Rodin 2016-08-25 19:43:38 +03:00
commit 1ed58a9efc

View file

@ -97,7 +97,7 @@ check_result() {
# Argument list checker
check_args() {
if [ "$1" -gt "$2" ]; then
echo "Usage: $SCRIPT $3"
echo "Usage: $(basename $0) $3"
check_result $E_ARGS "not enought arguments" >/dev/null
fi
}
@ -501,15 +501,14 @@ is_alias_format_valid() {
is_ip_format_valid() {
object_name=${2-ip}
ip_regex='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'
ip_clean=$(echo "${1%/[0-9][0-9]}")
ip_clean=$(echo "${1%/[0-9]}")
ip_clean=$(echo "${1%/*}")
if ! [[ $ip_clean =~ ^$ip_regex\.$ip_regex\.$ip_regex\.$ip_regex$ ]]; then
check_result $E_INVALID "invalid $object_name format :: $1"
fi
if [ $1 != "$ip_clean" ]; then
ip_cidr="$ip_clean/"
ip_cidr=$(echo "${1#$ip_cidr}")
if [[ "$ip_cidr" -gt 32 ]]; then
if [[ "$ip_cidr" -gt 32 ]] || [[ "$ip_cidr" =~ [:alnum:] ]]; then
check_result $E_INVALID "invalid $object_name format :: $1"
fi
fi