[oneimage] Check if graph service address got from dhcp is valid url (#324)

* [oneimage] Check if graph service address got from dhcp is valid url
This commit is contained in:
Taoyu Li 2017-02-23 13:12:54 -08:00 committed by GitHub
parent 151a7d2a90
commit 873f6f8fb6

View File

@ -29,9 +29,14 @@ if [ "$src" = "dhcp" ]; then
HOSTNAME=`hostname -s`
GRAPH_URL=`sonic-cfggen -t /tmp/dhcp_graph_url -a "{\"hostname\": \"$HOSTNAME\"}"`
URL_REGEX='^(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'
if [[ ! $GRAPH_URL =~ $URL_REGEX ]]; then
echo "\"$GRAPH_URL\" is not a valid url. Skipping graph update."
exit 0
fi
if [ "$dhcp_as_static" = "true" ]; then
sed -i "/src=d/d" /etc/sonic/updategraph.conf
echo "src=$GRAPH_URL" >> /etc/sonic/updategraph.conf
sed -i "/src=/d" /etc/sonic/updategraph.conf
echo "src=\"$GRAPH_URL\"" >> /etc/sonic/updategraph.conf
fi
else
GRAPH_URL=$src