Created
March 16, 2018 13:44
-
-
Save InsanePrawn/a0851e2a8823cbb729471d30acd8e1ad to your computer and use it in GitHub Desktop.
Hurricane Electric DNS Hook script for Dehydrated and Let's Encrypt
This file contains hidden or 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
#!/bin/bash | |
### salvaged from some forum and patched by me | |
url=https://dns.he.net/ | |
# These should be set in .hedns-credentials | |
login= | |
password= | |
zoneid= | |
# Optionally override these. | |
ttl=300 | |
if [ -e ${HOME}/.hedns-credentials ]; then | |
. ${HOME}/.hedns-credentials | |
fi | |
if [[ "z$password" = "z" ]]; then | |
echo 'enter password' | |
read -s password | |
echo 'thanks, working...' | |
fi | |
function usage() | |
{ | |
prog=$(basename $0) | |
cat <<EOF | |
Create/update: | |
$prog NAME TYPE CONTENT [TTL] | |
Delete: | |
$prog NAME "DELETE" | |
EOF | |
} | |
record=$1 | |
type=$2 | |
content=$3 | |
usettl=${4-${ttl}} | |
if [ $# -lt 2 ] || [ $# -lt 3 -a "${type}" != DELETE ]; then | |
usage | |
exit 1 | |
fi | |
cookies=${HOME}/.hedns-cookies.txt | |
touch ${cookies} | |
chmod 0600 ${cookies} | |
function get_id() | |
{ | |
curl -sS --cookie ${cookies} "${url}?hosted_dns_zoneid=${zoneid}&menu=edit_zone&hosted_dns_editzone" | grep -B5 ">${record}" | sed -nre 's/.*dns_tr.* id="([^"]*)".*/\1/p' | head -n 1 | |
} | |
# Get any initial cookies. | |
curl -sS --cookie-jar ${cookies} ${url} -o /dev/null | |
# Login. | |
curl -sS --cookie ${cookies} --cookie-jar ${cookies} --data "email=${login}&pass=${password}&submit=Login%21" ${url} -o /dev/null | |
# Check if we should update or create new. | |
recordid=$(get_id) | |
if [ "${type}" == DELETE ]; then | |
if [ ! "${recordid}" ]; then | |
echo "No such record" | |
exit 1 | |
fi | |
curl -sS --cookie ${cookies} --data "menu=edit_zone&hosted_dns_zoneid=${zoneid}&hosted_dns_recordid=${recordid}&hosted_dns_editzone=1&hosted_dns_delrecord=1" "${url}index.cgi" | grep "^${record}" | |
[ $? -ne 0 ] | |
exit | |
fi | |
if [ "${recordid}" ]; then | |
op=Update | |
else | |
op=Submit | |
fi | |
curl -sS --cookie ${cookies} --data "account=&menu=edit_zone&Type=${type}&hosted_dns_zoneid=${zoneid}&hosted_dns_recordid=${recordid}&hosted_dns_editzone=1&Priority=&Name=${record}&Content=${content}&TTL=${usettl}&hosted_dns_editrecord=${op}" "${url}?hosted_dns_zoneid=${zoneid}&menu=edit_zone&hosted_dns_editzone" | grep "^${record}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment