Created
August 15, 2020 20:11
-
-
Save benaryorg/9bb701bcee90247ddc60fbd439bfe87e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
IFS=$'\t' | |
set -e | |
while | |
read -rd $'\t' cmd | |
do | |
case "${cmd}" in | |
HELO) | |
test "$(line)" != "1" && printf "FAIL\\n" && continue || true | |
printf "OK\\t%s\\n" "lxd proxy" | |
;; | |
Q) | |
read -r qname qclass qtype id ip | |
printf "LOG\\t%s\\t%s\\t%s\\t%s\\t%s\\n" "${qname}" "${qclass}" "${qtype}" "${id}" "${ip}" | |
case "${qtype}" in | |
SOA) | |
printf "DATA\\t%s\\t%s\\t%s\\t300\\t%s\\t%s\\t%s\\n" \ | |
"${qname}" "${qclass}" "${qtype}" "${id}" \ | |
"example.com. example.example.com. 1 86400 7200 3600000 3600" | |
printf "END\\n" | |
;; | |
AAAA|ANY) | |
sudo lxc list --format json -- "\\A${qname%%.*}\\z" \ | |
| jq -r --arg qname "${qname}" --arg qclass "${qclass}" --arg qtype AAAA --arg ttl 4 --arg id "${id}" \ | |
'.[].state.network.eth0.addresses[]? // empty | select(.family == "inet6" and .scope == "global") | ["DATA",$qname,$qclass,$qtype,$ttl,$id,.address] | @tsv' | |
printf "END\\n" | |
;; | |
*) | |
printf "FAIL\\n" | |
;; | |
esac | |
;; | |
*) | |
line > /dev/null | |
printf "FAIL\\n" | |
;; | |
esac | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment