#!/bin/sh

if [ -f "/tmp/wget_file_result" ]; then
	/bin/rm /tmp/wget_file_result
fi

cfg_dns_hijack=$(/bin/config get dns_hijack)

if [ "$cfg_dns_hijack" = "1" ]; then
	/bin/config set dns_hijack="0"	#free dns hijack
	/usr/sbin/dns-hijack
fi

case $1 in
"sso")
/usr/bin/curl --connect-timeout 10 -I https://accounts.netgear.com --capath /etc/ssl/certs | /bin/grep -i "location: /login" > /tmp/wget_file
	;;
*)
/usr/bin/curl --connect-timeout 10 -o - https://www.netgear.com --capath /etc/ssl/certs | /bin/grep -i "netgear.com" > /tmp/wget_file
	;;
esac
mv /tmp/wget_file /tmp/wget_file_result

if [ "$cfg_dns_hijack" = "1" ]; then	#recover dns hijack mode
	/bin/config set dns_hijack="1"
	/usr/sbin/dns-hijack
fi
