Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Created August 15, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benaryorg/9bb701bcee90247ddc60fbd439bfe87e to your computer and use it in GitHub Desktop.
Save benaryorg/9bb701bcee90247ddc60fbd439bfe87e to your computer and use it in GitHub Desktop.
#!/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