wagon/back/lib/ns_lookup_send

31 lines
761 B
Bash
Executable File

#!/bin/bash
# FILE: wgapi:back/lib/ns_lookup_send
# DESCRIPTION: Send nslookup command to DNS master server
# USAGE: send [option] cmd
# ERRORS:
# 3: bad usage
# 4: not found
# 5: server down
# 6: nslookup not found
# 7: config file not found
# 8: other nslookup error
# 9: nslookup refused
CONFIG_FILE='/etc/wgapi/config'
[ ${#} -eq 1 ] || [ ${#} -eq 2 ] || exit 3
[ -f "${CONFIG_FILE}" ] || exit 7
[ -x /usr/bin/nslookup ] || exit 6
source "${CONFIG_FILE}"
if ! res="$(/usr/bin/nslookup ${@} "${DNS_MASTER}")"
then exit 8
fi
if <<<"${res}" grep ';; .* timed out'
then exit 5
elif <<<"${res}" grep "\*\* .*: NXDOMAIN\|\*\*\* .*: No answer"
then exit 4
elif <<<"${res}" grep "\*\* .*: REFUSED"
then exit 9
else printf '%s' "${res}"
fi