Validate host/domain of Local DNS records as well

Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
Christian König 2021-10-19 21:34:16 +02:00
parent a872fabe7d
commit 596689b4c9
No known key found for this signature in database
GPG key ID: 4CDA6F249DD2B485

View file

@ -711,12 +711,18 @@ AddCustomDNSAddress() {
host="${args[3]}" host="${args[3]}"
reload="${args[4]}" reload="${args[4]}"
if valid_ip "${ip}" || valid_ip6 "${ip}" ; then validHost="$(checkDomain "${host}")"
echo "${ip} ${host}" >> "${dnscustomfile}" if [[ -n "${validHost}" ]]; then
else if valid_ip "${ip}" || valid_ip6 "${ip}" ; then
echo -e " ${CROSS} Invalid IP has been passed" echo "${ip} ${validHost}" >> "${dnscustomfile}"
exit 1 else
fi echo -e " ${CROSS} Invalid IP has been passed"
exit 1
fi
else
echo " ${CROSS} Invalid Domain passed!"
exit 1
fi
# Restart dnsmasq to load new custom DNS entries only if $reload not false # Restart dnsmasq to load new custom DNS entries only if $reload not false
if [[ ! $reload == "false" ]]; then if [[ ! $reload == "false" ]]; then
@ -731,11 +737,17 @@ RemoveCustomDNSAddress() {
host="${args[3]}" host="${args[3]}"
reload="${args[4]}" reload="${args[4]}"
if valid_ip "${ip}" || valid_ip6 "${ip}" ; then validHost="$(checkDomain "${host}")"
sed -i "/^${ip} ${host}$/d" "${dnscustomfile}" if [[ -n "${validHost}" ]]; then
else if valid_ip "${ip}" || valid_ip6 "${ip}" ; then
echo -e " ${CROSS} Invalid IP has been passed" sed -i "/^${ip} ${validHost}$/d" "${dnscustomfile}"
exit 1 else
echo -e " ${CROSS} Invalid IP has been passed"
exit 1
fi
else
echo " ${CROSS} Invalid Domain passed!"
exit 1
fi fi
# Restart dnsmasq to load new custom DNS entries only if reload is not false # Restart dnsmasq to load new custom DNS entries only if reload is not false