Prevent configurator from setting unwanted or malformed hostnames

This commit is contained in:
Clemens John 2013-09-19 15:45:54 +00:00
parent a4c5d79aa5
commit 18b82b58a8
1 changed files with 20 additions and 9 deletions

View File

@ -45,16 +45,27 @@ fi
sync_hostname() { sync_hostname() {
err "Syncing hostname" err "Syncing hostname"
api_return=$(wget -T $API_TIMEOUT -q -O - "http://$netmon_api/api_csv_configurator.php?section=get_hostname&authentificationmethod=$CRAWL_METHOD&nickname=$CRAWL_NICKNAME&password=$CRAWL_PASSWORD&router_auto_update_hash=$CRAWL_UPDATE_HASH&router_id=$CRAWL_ROUTER_ID") api_return=$(wget -T $API_TIMEOUT -q -O - "http://$netmon_api/api_csv_configurator.php?section=get_hostname&authentificationmethod=$CRAWL_METHOD&nickname=$CRAWL_NICKNAME&password=$CRAWL_PASSWORD&router_auto_update_hash=$CRAWL_UPDATE_HASH&router_id=$CRAWL_ROUTER_ID")
netmon_hostname=${api_return%,*} ret=${api_return%%,*}
netmon_hostname=${netmon_hostname#*,} if [ "$ret" != "success" ]; then
if [ "$netmon_hostname" != "" ]; then err "Ther was an error fetching the hostname"
if [ "$netmon_hostname" != "`cat /proc/sys/kernel/hostname`" ]; then exit 0
err "Setting new hostname: $netmon_hostname" elif [ "$ret" = "success" ]; then
uci set system.@system[0].hostname=$netmon_hostname netmon_hostname=${api_return%,*}
uci commit netmon_hostname=${netmon_hostname#*,}
echo $netmon_hostname > /proc/sys/kernel/hostname #use regex to check if hostname is valid (not empty, only characters and numbers)
#http://stackoverflow.com/questions/8696906/check-for-valid-number-in-busybox
if echo -n $netmon_hostname | egrep -q '^[A-Za-z0-9]*$'; then
if [ "$netmon_hostname" != "`cat /proc/sys/kernel/hostname`" ]; then
err "Setting new hostname: $netmon_hostname"
uci set system.@system[0].hostname=$netmon_hostname
uci commit
echo $netmon_hostname > /proc/sys/kernel/hostname
else
err "Hostname is up to date"
fi
else else
err "Hostname is up to date" err "Hostname ist malformed"
exit 0
fi fi
fi fi
} }