Modified grep and TXT search

This commit is contained in:
Gerardo 2020-04-19 14:25:48 +02:00 committed by GitHub
parent afee487a80
commit 6e589de5eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,29 +3,29 @@
#Original Author: Gerardo Trotta <gerardo.trotta@euronet.aero> #Original Author: Gerardo Trotta <gerardo.trotta@euronet.aero>
#Application username #Application username
ARUBA_AK="xxxxx" #ARUBA_AK="xxxxx"
# #
#Application password #Application password
ARUBA_AS="xxxxxx" #ARUBA_AS="xxxxxx"
# #
#API key #API key
ARUBA_TK="xxxxxxxx" #ARUBA_TK="xxxxxxxx"
# #
#Consumer Key #Consumer Key
#ARUBA_CK="sdfsdfsdfsdfsdfdsf" #ARUBA_CK="sdfsdfsdfsdfsdfdsf"
#ARUBA_END_POINT=aruba-it #ARUBA_END_POINT=aruba-it
#'aruba-it' #'aruba-business-it'
ARUBA_IT='https://api.arubabusiness.it' ARUBA_BUSINESS_IT='https://api.arubabusiness.it'
_aruba_get_api() { _aruba_get_api() {
_ogaep="$1" _ogaep="$1"
case "${_ogaep}" in case "${_ogaep}" in
aruba-it | arubait) aruba-b-it | arubabit)
printf "%s" $ARUBA_IT printf "%s" $ARUBA_BUSINESS_IT
return return
;; ;;
@ -94,7 +94,7 @@ _initAuth() {
domainData=$(echo "$response" | tr -d '\r' ) domainData=$(echo "$response" | tr -d '\r' )
# get all Ids and peek only values # get all Ids and peek only values
temp="$(echo "$domainData" | grep -oP "Id\": \d{1,}" | cut -d : -f 2 | head -1)" temp="$(echo "$domainData" | _egrep_o "Id\": [^,]*" | cut -d : -f 2 | head -1)"
#read -ra ADDR <<< "$temp" #put Ids into array #read -ra ADDR <<< "$temp" #put Ids into array
domain_id=$temp # first element is zone Id domain_id=$temp # first element is zone Id
@ -118,17 +118,17 @@ dns_aruba_add() {
_sub_domain="_acme-challenge" _sub_domain="_acme-challenge"
_debug "Check if _acme-challenge record exists in " "$_domain" _debug "Check if _acme-challenge record exists in " "$_domain"
if ! _extract_record_id "$_sub_domain$_domain"; then if ! _extract_record_id "$_sub_domain.$_domain."; then
_err "invalid domain" _method="POST"
return 1 else
_method="PUT"
fi fi
_payload="{ \"IdDomain\": $domain_id, \"Type\": \"TXT\", \"Name\": \"$_sub_domain\", \"Content\": \"\\\"$txtvalue\\\"\" }" _payload="{ \"IdDomain\": $domain_id, \"Type\": \"TXT\", \"Name\": \"$_sub_domain\", \"Content\": \"\\\"$txtvalue\\\"\" }"
_info "Adding record" _info "Adding record"
if _aruba_rest POST "api/domains/dns/record" "$_payload"; then if _aruba_rest "$_method" "api/domains/dns/record" "$_payload"; then
if _contains "$response" "$txtvalue"; then if _contains "$response" "$txtvalue"; then
_aruba_rest GET "api/domains/dns/$_domain/details" _aruba_rest GET "api/domains/dns/$_domain/details"
_debug "Refresh:$response" _debug "Refresh:$response"
@ -149,15 +149,16 @@ dns_aruba_rm() {
if ! _initAuth; then if ! _initAuth; then
return 1 return 1
fi fi
_sub_domain="_acme-challenge.${_domain}"
_debug _sub_domain "$_sub_domain"
_debug "Getting TXT record to delete"
if ! _extract_record_id $_sub_domain; then _sub_domain="_acme-challenge"
_debug "Getting TXT record to delete: $_sub_domain.$_domain."
if ! _extract_record_id "$_sub_domain.$_domain"; then
return 1 return 1
fi fi
_debug "Deleting TXT record: $_sub_domain.$_domain"
if ! _aruba_rest DELETE "api/domains/dns/record/$_recordId"; then if ! _aruba_rest DELETE "api/domains/dns/record/$_recordId"; then
return 1 return 1
fi fi
@ -169,12 +170,14 @@ dns_aruba_rm() {
# returns TXT record and put it in_record_id, if esists # returns TXT record and put it in_record_id, if esists
_extract_record_id() { _extract_record_id() {
subdomain=$1 subdomain="$1"
_arrayid=0 _arrayid=0
_ids="$(echo $domainData | grep -oP '(?<="Id": )[^,]+')" _ids="$(echo $domainData | _egrep_o '"Id": [^,]+' | cut -d : -f 2)"
_temp="$(echo $domainData | grep -oP "\"DomainId\":\s\d{1,}," | tr -d ' ')" _debug $ids
_domainids="$(echo $_temp | tr -d ' ')" #_temp="$(echo $domainData | grep -oP "\"DomainId\":\s\d{1,}," | tr -d ' ')"
_names="$(echo $domainData | grep -oP '(?<="Name": ")[^"]+')" #_domainids="$(echo $_temp | tr -d ' ')"
_names="$(echo $domainData | _egrep_o '"Name": [^,]*' | cut -d : -f 2)"
_debug $names
ARRAY_IDS=$(echo $_ids | tr ", " "\n") ARRAY_IDS=$(echo $_ids | tr ", " "\n")
ARRAY_NAMES=$_names ARRAY_NAMES=$_names
@ -185,7 +188,7 @@ _extract_record_id() {
_debug printf "%s\t%s\n" "$i" _debug printf "%s\t%s\n" "$i"
_arrayname=$i _arrayname=$i
_arrayId=$j _arrayId=$j
_debug "Found txt record id: $_arrayId" _info "Found txt record id: $_arrayId"
fi fi
j=$(_math "$j" + 1) j=$(_math "$j" + 1)
done done
@ -195,6 +198,7 @@ _extract_record_id() {
do do
if [ "$n" = "$_arrayId" ]; then if [ "$n" = "$_arrayId" ]; then
_recordId=$i _recordId=$i
_info "recordid found: $_recordId"
return 0 return 0
fi fi
n=$(_math "$n" + 1) n=$(_math "$n" + 1)