Skip to content

Commit 55512ed

Browse files
committed
fix fmt
1 parent 9500ff5 commit 55512ed

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

dnsapi/dns_gname.sh

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ GNAME_TLDS_CACHE=""
1515

1616
######## Public functions #####################
1717

18-
#Usage: add _acme-challenge.www.domain.com "T1rxqRBosdIK90xWCG3KLZNf6q_0HG9i01zxXp5CASc"
18+
#Usage: add _acme-challenge.www.domain.com "T1rxqRBosdIK90xWCG3KLZNf6q_0HG9i01zxXp5CAS3"
1919
dns_gname_add() {
2020
fulldomain=$1
2121
txtvalue=$(printf "%s" "$2" | _url_encode)
@@ -54,8 +54,8 @@ dns_gname_add() {
5454
return 0
5555
else
5656
if _contains "$post_response" "the same host records and record values"; then
57-
_info "Successfully DNS record already exists."
58-
return 0
57+
_info "Successfully DNS record already exists."
58+
return 0
5959
fi
6060
_err "Failed to add DNS record via Gname API."
6161
return 1
@@ -90,14 +90,14 @@ dns_gname_rm() {
9090

9191
_debug "Query DNS record ID $ext_domain $final_hostname $txtvalue"
9292

93-
record_id=$(_get_record_id $ext_domain $final_hostname $txtvalue)
93+
record_id=$(_get_record_id "$ext_domain" "$final_hostname" "$txtvalue")
9494

9595
if [ -z "$record_id" ]; then
9696
_err "No DNS record found"
9797
return 1
9898
fi
9999

100-
_debug "DNS record ID:$record_id";
100+
_debug "DNS record ID:$record_id"
101101
gntime=$(date +%s)
102102
body="appid=$GNAME_APPID&gntime=$gntime&jxid=$record_id&lang=us&ym=$ext_domain"
103103

@@ -136,7 +136,7 @@ _get_record_id() {
136136

137137
_debug "Searching with host: $target_zjt and feature: $jxz_feature"
138138

139-
matched_row=$(echo "$records" | grep "\"zjt\":\"$target_zjt\"" | grep "\"jxz\":\"$jxz_feature")
139+
matched_row=$(echo "$records" | grep -i "\"zjt\":\"$target_zjt\"" | grep "\"jxz\":\"$jxz_feature")
140140

141141
_debug "Final Matched Row: $matched_row"
142142

@@ -161,14 +161,14 @@ _post_to_api() {
161161
uri=$1
162162
body=$2
163163
url="$GNAME_Api$uri"
164-
gntoken=$(_gntoken $body)
164+
gntoken=$(_gntoken "$body")
165165
body="$body&gntoken=$gntoken"
166166
post_response="$(_post "$body" "$url" "" "POST" "application/x-www-form-urlencoded")"
167167

168168
curl_err_code=$?
169169
if [ "$curl_err_code" != "0" ]; then
170-
_err "POST API $url curl error:$curl_err_code"
171-
return 1
170+
_err "POST API $url curl error:$curl_err_code"
171+
return 1
172172
fi
173173

174174
ret_code=$(echo "$post_response" | sed 's/.*"code":\([-0-9]*\).*/\1/')
@@ -208,46 +208,44 @@ _extract_domain() {
208208
ext_hostname=""
209209
ext_domain="$host"
210210

211-
elif [ "$dot_count" -gt 1 ]; then
212-
matched_suffix=""
213-
for suffix in $suffix_list; do
214-
case "$host" in
215-
*".$suffix")
216-
if [ -z "$matched_suffix" ] || [ "${#suffix}" -gt "${#matched_suffix}" ]; then
217-
matched_suffix="$suffix"
218-
fi
219-
;;
220-
esac
221-
done
222-
223-
if [ -n "$matched_suffix" ]; then
224-
prefix="${host%.$matched_suffix}"
225-
main_name="${prefix##*.}"
226-
227-
ext_domain="$main_name.$matched_suffix"
228-
229-
if [ "$host" = "$ext_domain" ]; then
230-
ext_hostname=""
231-
else
232-
ext_hostname="${host%.$ext_domain}"
233-
fi
234-
235-
else
236-
ext_domain=$(echo "$host" | awk -F. '{print $(NF-1)"."$NF}')
237-
ext_hostname=$(echo "$host" | rev | cut -d. -f3- | rev)
211+
elif [ "$dot_count" -gt 1 ]; then
212+
matched_suffix=""
213+
for suffix in $suffix_list; do
214+
case "$host" in
215+
*".$suffix")
216+
if [ -z "$matched_suffix" ] || [ "${#suffix}" -gt "${#matched_suffix}" ]; then
217+
matched_suffix="$suffix"
238218
fi
219+
;;
220+
esac
221+
done
222+
223+
if [ -n "$matched_suffix" ]; then
224+
prefix="${host%."$matched_suffix"}"
225+
main_name="${prefix##*.}"
226+
227+
ext_domain="$main_name.$matched_suffix"
228+
229+
if [ "$host" = "$ext_domain" ]; then
230+
ext_hostname=""
231+
else
232+
ext_hostname="${host%."$ext_domain"}"
233+
fi
234+
235+
else
236+
ext_domain=$(echo "$host" | awk -F. '{print $(NF-1)"."$NF}')
237+
ext_hostname=$(echo "$host" | rev | cut -d. -f3- | rev)
239238
fi
240-
_debug "ext_hostname:$ext_hostname"
241-
_debug "ext_domain:$ext_domain"
239+
fi
240+
_debug "ext_hostname:$ext_hostname"
241+
_debug "ext_domain:$ext_domain"
242242
}
243243

244244
# Obtain the list of domain suffixes via API
245245
_get_suffixes_json() {
246246
_debug "GET request URL: $GNAME_TLD_Api Retrieves a list of domain suffixes."
247247

248-
response="$(_get "$GNAME_TLD_Api")"
249-
250-
if [ "$?" != "0" ]; then
248+
if ! response="$(_get "$GNAME_TLD_Api")"; then
251249
_err "Failed to retrieve list of domain suffixes"
252250
return 1
253251
fi
@@ -272,7 +270,7 @@ _gntoken() {
272270
data_to_sign="$1"
273271
full_data="${data_to_sign}${GNAME_APPKEY}"
274272
hash=$(printf "%s" "$full_data" | _digest md5 hex | tr -d ' ')
275-
hash_upper=$(printf "%s" "$hash" | tr 'a-z' 'A-Z')
273+
hash_upper=$(printf "%s" "$hash" | tr '[:lower:]' '[:upper:]')
276274
_debug "Signature value: $hash_upper"
277275
printf "%s" "$hash_upper"
278-
}
276+
}

0 commit comments

Comments
 (0)