mirror of
https://github.com/acmesh-official/acme.sh.git
synced 2025-05-08 13:47:01 +00:00
Refactoring from bash to dash
Some errors
This commit is contained in:
parent
bc36b9e89d
commit
936d6cf837
@ -1,15 +1,15 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#Original Author: Gerardo Trotta <gerardo.trotta@euronet.aero>
|
||||
|
||||
#Application username
|
||||
#ARUBA_AK="username"
|
||||
#ARUBA_AK="xxxxx"
|
||||
#
|
||||
#Application password
|
||||
#ARUBA_AS="password"
|
||||
#ARUBA_AS="xxxxxx"
|
||||
#
|
||||
#API key
|
||||
#ARUBA_TK="token"
|
||||
#ARUBA_TK="xxxxxxxx"
|
||||
#
|
||||
#Consumer Key
|
||||
#ARUBA_CK="sdfsdfsdfsdfsdfdsf"
|
||||
@ -30,6 +30,7 @@ _aruba_get_api() {
|
||||
;;
|
||||
|
||||
*)
|
||||
|
||||
_err "Unknown parameter : $1"
|
||||
return 1
|
||||
;;
|
||||
@ -45,7 +46,7 @@ _initAuth() {
|
||||
ARUBA_AK=""
|
||||
ARUBA_AS=""
|
||||
ARUBA_TK=""
|
||||
_err "You don't specify ARUBA application key or application secret yet."
|
||||
_err "You don't specify ARUBA application key and application secret yet."
|
||||
_err "Please create you key and try again."
|
||||
return 1
|
||||
fi
|
||||
@ -76,10 +77,10 @@ _initAuth() {
|
||||
_info "ARUBA consumer key is empty, Let's get one:"
|
||||
if ! _aruba_authentication; then
|
||||
_err "Can not get consumer key."
|
||||
fi
|
||||
#return and wait for retry.
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
_info "Checking authentication and get domain details"
|
||||
|
||||
@ -93,9 +94,9 @@ _initAuth() {
|
||||
domainData=$(echo "$response" | tr -d '\r' )
|
||||
|
||||
# get all Ids and peek only values
|
||||
temp="$(echo "$domainData" | grep -oP "Id\": \d{1,}" | cut -d : -f 2)"
|
||||
read -ra ADDR <<< "$temp" #put Ids into array
|
||||
domain_id="${ADDR[0]}" # first element is zone Id
|
||||
temp="$(echo "$domainData" | grep -oP "Id\": \d{1,}" | cut -d : -f 2 | head -1)"
|
||||
#read -ra ADDR <<< "$temp" #put Ids into array
|
||||
domain_id=$temp # first element is zone Id
|
||||
|
||||
_info "DomainId is: $domain_id"
|
||||
_info "Consumer key is ok."
|
||||
@ -113,14 +114,16 @@ dns_aruba_add() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "Check if _acme-challenge record exists"
|
||||
if ! _get_zone_id "$_domain"; then
|
||||
_debug _domain "$_domain"
|
||||
_sub_domain="_acme-challenge"
|
||||
|
||||
_debug "Check if _acme-challenge record exists in " "$_domain"
|
||||
if ! _extract_record_id "$_sub_domain$_domain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug _domain "$_domain"
|
||||
_sub_domain="_acme-challenge"
|
||||
|
||||
|
||||
_payload="{ \"IdDomain\": $domain_id, \"Type\": \"TXT\", \"Name\": \"$_sub_domain\", \"Content\": \"\\\"$txtvalue\\\"\" }"
|
||||
|
||||
@ -155,7 +158,7 @@ dns_aruba_rm() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! _ovh_rest DELETE "api/domains/dns/record/$_recordId"; then
|
||||
if ! _aruba_rest DELETE "api/domains/dns/record/$_recordId"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
@ -169,20 +172,32 @@ _extract_record_id() {
|
||||
subdomain=$1
|
||||
_arrayid=0
|
||||
_ids="$(echo $domainData | grep -oP '(?<="Id": )[^,]+')"
|
||||
_temp="$(echo $domainData | grep -oP "\"DomainId\":\s\d{1,}," | tr -d ' ')"
|
||||
_domainids="$(echo $_temp | tr -d ' ')"
|
||||
_names="$(echo $domainData | grep -oP '(?<="Name": ")[^"]+')"
|
||||
ARRAY_IDS=($(echo $_ids | tr ", " "\n"))
|
||||
ARRAY_NAMES=($_names)
|
||||
ARRAY_IDS=$(echo $_ids | tr ", " "\n")
|
||||
ARRAY_NAMES=$_names
|
||||
|
||||
for i in "${!ARRAY_NAMES[@]}"
|
||||
j=0
|
||||
for i in $ARRAY_NAMES;
|
||||
do
|
||||
if [[ ${ARRAY_NAMES[$i]} = $subdomain ]]; then
|
||||
_debug printf "%s\t%s\n" "$i" "${ARRAY_NAMES[$i]}"
|
||||
_arrayid=$i
|
||||
_debug"Found txt record id: ${ARRAY_IDS[$_arrayid]}"
|
||||
_recordId=${ARRAY_IDS[$_arrayid}
|
||||
#printf "%s" ${ARRAY_IDS[$_arrayid}
|
||||
if [ "$i" = "$subdomain" ]; then
|
||||
_debug printf "%s\t%s\n" "$i"
|
||||
_arrayname=$i
|
||||
_arrayId=$j
|
||||
_debug "Found txt record id: $_arrayId"
|
||||
fi
|
||||
j=$(_math "$j" + 1)
|
||||
done
|
||||
|
||||
n=0
|
||||
for i in $ARRAY_IDS;
|
||||
do
|
||||
if [ "$n" = "$_arrayId" ]; then
|
||||
_recordId=$i
|
||||
return 0
|
||||
fi
|
||||
n=$(_math "$n" + 1)
|
||||
done
|
||||
|
||||
return 1
|
||||
@ -198,7 +213,7 @@ _aruba_authentication() {
|
||||
_arubadata="grant_type=password&username=$ARUBA_AK&password=$ARUBA_AS"
|
||||
|
||||
response="$(_post "$_arubadata" "$ARUBA_API/auth/token")"
|
||||
|
||||
_debug "$(_post "$_arubadata" "$ARUBA_API/auth/token")"
|
||||
_debug3 response "$response"
|
||||
|
||||
access_token="$(echo "$response" | _egrep_o "access_token\":\"[^\"]*\"" | cut -d : -f 2 | tr -d '"')"
|
||||
@ -230,8 +245,8 @@ _aruba_rest() {
|
||||
export _H4="Authorization-Key: $ARUBA_TK"
|
||||
export _H5="Accept: application/json"
|
||||
|
||||
_debug3 _H3 "$_H3"
|
||||
_debug3 _H4 "$_H4"
|
||||
_debug2 _H3 "$_H3"
|
||||
_debug2 _H4 "$_H4"
|
||||
if [ "$data" ] || [ "$m" = "POST" ] || [ "$m" = "PUT" ] || [ "$m" = "DELETE" ]; then
|
||||
_debug data "$data"
|
||||
response="$(_post "$data" "$_aruba_url" "" "$m")"
|
||||
@ -239,7 +254,7 @@ _aruba_rest() {
|
||||
response="$(_get "$_aruba_url")"
|
||||
fi
|
||||
|
||||
if [ "$?" != "0" ] || _contains "$response" "wrong credentials" || _contains "$response" "Unprocessable"; then
|
||||
if [ "$?" != "0" ] || _contains "$response" "wrong credentials" || _contains "$response" "Unprocessable" || _contains "$response" "denied"; then
|
||||
_err "Response error $response"
|
||||
return 1
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user