Browse Source

check if result of iproute is ip address

4.3
lazedo 7 years ago
committed by Luis Azedo
parent
commit
7e8f70042c
1 changed files with 19 additions and 1 deletions
  1. +19
    -1
      system/sbin/kazoo-kamailio

+ 19
- 1
system/sbin/kazoo-kamailio View File

@ -12,6 +12,24 @@ if [ -f /etc/kazoo/kamailio/options ]; then
. /etc/kazoo/kamailio/options . /etc/kazoo/kamailio/options
fi fi
is_ipaddress ()
{
if [ $(echo $1 | grep -o '\.' | wc -l) -ne 3 ]; then
return 1
elif [ $(echo $1 | tr '.' ' ' | wc -w) -ne 4 ]; then
return 1
else
for OCTET in $(echo $1 | tr '.' ' '); do
if ! [[ $OCTET =~ ^[0-9]+$ ]]; then
return 1
elif [[ $OCTET -lt 0 || $OCTET -gt 255 ]]; then
return 1
fi
done
fi
return 0
}
RETVAL=1 RETVAL=1
USER=${KAMAILIO_USER:-kamailio} USER=${KAMAILIO_USER:-kamailio}
GROUP=${KAMAILIO_GROUP:-daemon} GROUP=${KAMAILIO_GROUP:-daemon}
@ -29,7 +47,7 @@ RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false}
EXTRA_OPTIONS=${EXTRA_OPTIONS:-"-x tlsf -w /tmp"} EXTRA_OPTIONS=${EXTRA_OPTIONS:-"-x tlsf -w /tmp"}
MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print ""$NF""; exit}') MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print ""$NF""; exit}')
if [[ ! -z ${MY_LOCAL_IP} ]]; then
if is_ipaddress ${MY_LOCAL_IP}; then
EXTRA_OPTIONS+=" -A MY_LOCAL_IP=${MY_LOCAL_IP}" EXTRA_OPTIONS+=" -A MY_LOCAL_IP=${MY_LOCAL_IP}"
fi fi


Loading…
Cancel
Save