File: //volume1/@appstore/DNSServer/hook_scripts/synodns_hook.sh
#!/bin/sh
PRIVATE_LOCATION="/var/packages/DNSServer/target"
PKG_APP_PATH="${PRIVATE_LOCATION}/app"
GetSupportNetTopology()
{
echo `/usr/syno/bin/synogetkeyvalue /etc/synoinfo.conf support_net_topology`
}
GetNetTopology()
{
echo `/usr/syno/bin/synogetkeyvalue /etc/synoinfo.conf net_topology`
}
IsRouterMode()
{
local tmp1=$(GetSupportNetTopology)
local tmp2=$(GetNetTopology)
if [ "${tmp1}" == "yes" ] && [ "${tmp2}" == "router" ]; then
return 1
else
return 0
fi
}
GetInternalNetwork()
{
local os_name=$(/usr/syno/bin/synogetkeyvalue /etc/synoinfo.conf os_name)
if [ "x$os_name" != "x" ] && [ "x$os_name" == "xNSM" ]; then
echo $(/usr/syno/bin/synodhcpservertool -s)
else
echo $(/usr/syno/sbin/synonetdtool --get-internal-network)
fi
}
GetDnsMasqSubnetList()
{
local list=$(GetInternalNetwork)
local retStr=""
for subnet in ${list}
do
if [ "${retStr}" == "" ]; then
retStr=${subnet} #first time
else
retStr=${retStr}";"${subnet}
fi
done
retStr=${retStr}";"
echo ${retStr}
}
LoadDnsMasqSubnetListToAllowRecursive()
{
if [ 1 -eq $1 ]; then
szSubnetList=$(GetDnsMasqSubnetList)
`${PKG_APP_PATH}/synodnstool --set-dnsmasq-allow-recursion $szSubnetList`
else
`${PKG_APP_PATH}/synodnstool --clear-dnsmasq-allow-recursion`
fi
}
Load()
{
if [ -e "/var/packages/DNSServer/enabled" ]; then
# register local subnet ip for allowing recursive query
IsRouterMode
LoadDnsMasqSubnetListToAllowRecursive $?
fi
}
case $1 in
--sdk-mod-ver)
#Print SDK support version
echo "1.0";
;;
--name)
#Print package name
echo "synodns"
;;
--pkg-ver)
#Print package version
echo "1.0";
;;
--vendor)
#Print package vendor
echo "Synology";
;;
--pre)
;;
--post)
# do nothing when link updown on booting-up step
if /usr/syno/bin/synobootseq --is-booting-up > /dev/null 2>&1 ; then
exit
fi
# do nothing when link updown shutdown step
if /usr/syno/bin/synobootseq --is-shutdown > /dev/null 2>&1 ; then
exit
fi
Load
;;
*)
echo "Usage: $0 --sdk-mod-ver|--name|--pkg-ver|--vendor|--pre|--post"
;;
esac