From 52bd62772ebc1f39ad261744b3f8bb73c06c604e Mon Sep 17 00:00:00 2001 From: Skull Writter <7103685+skullwritter@users.noreply.github.com> Date: Fri, 26 Oct 2018 01:31:51 +0000 Subject: [PATCH] $VESTACP dns api REQURES 2 VARIABLES FROM EXPORT: $USER $DOMAIN --- dnsapi/dns-vesta.sh | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 dnsapi/dns-vesta.sh diff --git a/dnsapi/dns-vesta.sh b/dnsapi/dns-vesta.sh new file mode 100644 index 00000000..e0f8aba7 --- /dev/null +++ b/dnsapi/dns-vesta.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +######## Public functions ##################### + +#Usage: dns_nsupdate_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" +dns_vestacp_add() { + fulldomain=$1 + txtvalue=$2 + _debug $DOMAIN "========================================" + _debug $DOMAIN "= VESTA =" + _debug $DOMAIN "========================================" + _debug $DOMAIN " REMEMBER: VESTA RESPONSE EMPTY == GOOD " + _debug $DOMAIN " ADD DNS VESTACP " + _debug $DOMAIN "----------------------------------------" + _debug $DOMAIN "ADD ACME CHALLENGE:" + _debug $DOMAIN "DATA:" + _debug $DOMAIN "USER:$VESTA_USER" + _debug $DOMAIN "DOMAIN:$DOMAIN" + _debug $DOMAIN "RECORD:_acme-challenge" + _debug $DOMAIN "TYPE:TXT" + _debug $DOMAIN "VALUE:$txtvalue" + exists_dns_record=$($VESTA/bin/v-exists-dns-record "$VESTA_USER" "$DOMAIN" "_acme-challenge" "A"); + + add_dns=$($VESTA/bin/v-add-dns-record "$VESTA_USER" "$DOMAIN" "_acme-challenge" "TXT" "\"$txtvalue\""); + _debug $DOMAIN "RESULT ADD DNS: $add_dns"; + restart_dns=$($VESTA/bin/v-restart-dns) + + _debug $DOMAIN "CURRENT VESTA DNS RECORDS:" + UPDATED=$($VESTA/bin/v-list-dns-records "$VESTA_USER" "$DOMAIN") + _debug $DOMAIN "$UPDATED"; + + _debug $DOMAIN echo "VESTA restart dns result: $restart_dns" + _debug $DOMAIN "#########################################" +} + +#Usage: dns_nsupdate_rm _acme-challenge.www.domain.com +dns_vestacp_rm() { + fulldomain=$1 + txtvalue="${txtvalue}"; + _debug $DOMAIN "========================================" + _debug $DOMAIN "= VESTA =" + _debug $DOMAIN "========================================" + _debug $DOMAIN " REMEMBER: VESTA RESPONSE EMPTY == GOOD " + _debug $DOMAIN " REMOVE DNS VESTACP " + _debug $DOMAIN "----------------------------------------" + + if [ -z "$VESTA_BYPASS_DELETE" ]; then + VESTA_BYPASS_DELETE="0"; + fi; + _debug $DOMAIN "VESTA - BYPASS RECORD REMOVAL: $VESTA_BYPASS_DELETE [VESTA_BYPASS_DELETE]" + if [ "$VESTA_BYPASS_DELETE" = "1" ]; then + record="-1"; + else + record=$(_get_vestacp_dns_record_id) + fi; + + _debug $DOMAIN "RECORD TO DELETE FROM VESTA: $record (-1 IS GOOB)" + + if [ "$record" != "-1" ]; then + DNS=$($VESTA/bin/v-delete-dns-record "$VESTA_USER" "$DOMAIN" "$record" "1"); + _debug $DOMAIN "RESPONSE FROM VESTA API: $DNS" + + _debug $DOMAIN "THE !WHILE! CYCLE" + + while [[ "$record" != "-1" ]]; + do + record=$(_get_vestacp_dns_record_id) + _debug $DOMAIN "RECORD TO DELETE FROM VESTA: $record (-1 IS GOOD)" + + if [ "$record" != "-1" ]; then + DNS=$($VESTA/bin/v-delete-dns-record "$VESTA_USER" "$DOMAIN" "$record" "1"); + _debug $DOMAIN "RESPONSE FROM VESTA API: $DNS" + else + _debug $DOMAIN "NO MORE DNS FROM ACME" + fi; + done; + _debug $DOMAIN "END #WHILE# CYCLE" + fi; + _debug $DOMAIN "CURRENT VESTA DNS RECORDS:" + UPDATED=$($VESTA/bin/v-list-dns-records "$VESTA_USER" "$DOMAIN") + _debug $DOMAIN "$UPDATED"; + + DNS_UPDATE=$($VESTA/bin/v-restart-dns) + _debug $DOMAIN "DNS UPDATE RESPONSE: $DNS_UPDATE" + _debug $DOMAIN "#########################################" +} + +#################### Private functions below ################################## + +_get_vestacp_dns_record_id(){ + data=$($VESTA/bin/v-get-dns-record-id "$VESTA_USER" "$DOMAIN" "_acme-challenge"); + echo "$data"; +}