diff --git a/bin/pdns-record-rep.sh b/bin/pdns-record-rep.sh index dd6dfd9..67e90b2 100755 --- a/bin/pdns-record-rep.sh +++ b/bin/pdns-record-rep.sh @@ -13,15 +13,18 @@ help() echo "$thisfilename" echo "Replace Resource Record set in zone." echo "" - echo "usage: $thisfilename -z -n -t -c [-l ] [-s ] [-h]" + echo "usage: $thisfilename -z -n -t -r [-l ] [-s ] [-c ] [-a ] [-h]" echo "" echo " -h Print this help." echo " -z Zone (domain name) to modify records." echo " -n Hostname for this record." echo " -t Type of record to modify (A, CNAME, TXT, etc.)." - echo " -c Resource record content (data / values)." + echo " -r Resource record content (data / values)." echo " -l TTL, optional, defaults to $zone_defaults_ttl." echo " -s <0|1> Status, optional. O (default) for active or 1 for disabled." + echo " -c An optional comment/note about the record." + echo " -a The account that the comment gets attributed too." + echo " Only used if comment is set. Optional, defaults to hostname of server running this script." echo echo " If record(s) do not exist they are created, if they already exist they are replaced." echo " Record Sets are matched against zone, name & type. This tool updates/replaces all records" @@ -124,11 +127,23 @@ if [[ $zone_status = 200 ]]; then if [[ $records_count < $resourcerecords_records_count ]]; then data="$data," + else + data="$data]" fi done - data="$data]}]}" + # add comment, if set + if [[ -n $comment ]]; then + # set account to hostname if not specified with -a option + if [[ -z $account ]]; then + account=$(/usr/bin/hostname -f) + fi + data= "$data,\"comments\":[{\"content\":\"$comment\",\"account\":\"$account\"}]" + fi + + # close out json string + data="$data}]}" # add record(s) zone_status=$(/usr/bin/curl --silent --request PATCH --output "/tmp/$zone" --write-out "%{http_code}" --header "X-API-Key: $api_key" --data "$data" "$api_base_url/zones/$zone") diff --git a/bin/pdns.sh b/bin/pdns.sh index b59fea4..61c6e58 100755 --- a/bin/pdns.sh +++ b/bin/pdns.sh @@ -118,7 +118,7 @@ function pdns::yesno() { function pdns:getoptions () { local OPTIND - while getopts "hbz:m:t:a:n:c:l:s:x" opt ; do + while getopts "hbz:m:t:a:n:r:c:l:s:x" opt ; do case "${opt}" in h ) # display help and exit help @@ -150,8 +150,11 @@ function pdns:getoptions () { n ) # name - hostname for this record name=${OPTARG,,} ;; - c ) # content - record data - content=${OPTARG} + r ) # record data + record=${OPTARG} + ;; + c ) # comment - a note about the record + comment=${OPTARG} ;; l ) # ttl - Time To Live ttl=${OPTARG}