From 73482e5a26839dad2c1e044b27efadb454973ed4 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Thu, 26 Sep 2024 15:16:03 -0400 Subject: [PATCH] Really sketchy AMPRDNS automation --- scripts/amprdns-delete-record | 28 ++++++++++++++++++++++++++++ scripts/amprdns-list-records | 20 ++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 scripts/amprdns-delete-record create mode 100755 scripts/amprdns-list-records diff --git a/scripts/amprdns-delete-record b/scripts/amprdns-delete-record new file mode 100755 index 0000000..76ae616 --- /dev/null +++ b/scripts/amprdns-delete-record @@ -0,0 +1,28 @@ +#! /bin/bash +# A really hacky way of programatically deleting a record from an ampr.org zone +set -e + +# Require a subdomain ID and record ID +if [[ -z "$1" || -z "$2" ]]; then + echo "Usage: $0 " + echo " subdomain_id: The numeric ID of your subdomain (probably 39)" + echo " record_id: The numeric ID of the record to delete" + exit 1 +fi + +# Ask for the session cookie +if [[ -z "$COOKIE" ]]; then + echo -n "Enter your session cookie: " + read -s COOKIE +fi + +# Ask for a token +if [[ -z "$TOKEN" ]]; then + echo -n "Enter your CSRF token: " + read -s TOKEN +fi + +# Delete the record +echo "Deleting record $2 from subdomain $1" +curl -X POST "https://portal.ampr.org/subdomain-records/$2" -H "Cookie: $COOKIE" -H "Accept: application/json" --data "_method=DELETE&_token=$TOKEN" 2>/dev/null +echo \ No newline at end of file diff --git a/scripts/amprdns-list-records b/scripts/amprdns-list-records new file mode 100755 index 0000000..ab12b4a --- /dev/null +++ b/scripts/amprdns-list-records @@ -0,0 +1,20 @@ +#! /bin/bash +# A really hacky way of exposing the list of configured records on a ampr.org zone +set -e + +# Require a subdomain ID and page number +if [[ -z "$1" || -z "$2" ]]; then + echo "Usage: $0 " + echo " subdomain_id: The numeric ID of your subdomain (probably 39)" + echo " page: The page number to fetch" + exit 1 +fi + +# Ask for the session cookie +if [[ -z "$COOKIE" ]]; then + echo -n "Enter your session cookie: " + read -s COOKIE +fi + +# Fetch the records +curl -X GET "https://portal.ampr.org/subdomain-records/$1" -H "Cookie: $COOKIE" -H "Accept: application/json" 2>/dev/null | tr -d " " | grep -E "^action|^onsubmit" | tr -d "\n" | tr ">" "\n" | cut -d '"' -f 2,4 | tr '"' "|" | tr "'" "|" | tr "/" "|" | cut -d "|" -f 3,5,7 | column -t -s "|" \ No newline at end of file