Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
c6f5c7f1
Commit
c6f5c7f1
authored
Feb 14, 2018
by
neilpang
Browse files
fix gd
parent
a6b6e31c
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_gd.sh
View file @
c6f5c7f1
...
...
@@ -15,6 +15,8 @@ dns_gd_add() {
fulldomain
=
$1
txtvalue
=
$2
GD_Key
=
"
${
GD_Key
:-
$(
_readaccountconf_mutable GD_Key
)
}
"
GD_Secret
=
"
${
GD_Secret
:-
$(
_readaccountconf_mutable GD_Secret
)
}
"
if
[
-z
"
$GD_Key
"
]
||
[
-z
"
$GD_Secret
"
]
;
then
GD_Key
=
""
GD_Secret
=
""
...
...
@@ -24,8 +26,8 @@ dns_gd_add() {
fi
#save the api key and email to the account conf file.
_saveaccountconf GD_Key
"
$GD_Key
"
_saveaccountconf GD_Secret
"
$GD_Secret
"
_saveaccountconf
_mutable
GD_Key
"
$GD_Key
"
_saveaccountconf
_mutable
GD_Secret
"
$GD_Secret
"
_debug
"First detect the root zone"
if
!
_get_root
"
$fulldomain
"
;
then
...
...
@@ -36,8 +38,27 @@ dns_gd_add() {
_debug _sub_domain
"
$_sub_domain
"
_debug _domain
"
$_domain
"
_debug
"Getting existing records"
if
!
_gd_rest GET
"domains/
$_domain
/records/TXT/
$_sub_domain
"
;
then
return
1
fi
if
_contains
"
$response
"
"
$txtvalue
"
;
then
_info
"The record is existing, skip"
return
0
;
fi
_add_data
=
"{
\"
data
\"
:
\"
$txtvalue
\"
}"
for
t
in
$(
echo
"
$response
"
|
tr
'{'
"
\n
"
|
grep
"
\"
name
\"
:
\"
$_sub_domain
\"
"
|
tr
','
"
\n
"
|
grep
'"data"'
|
cut
-d
:
-f
2
)
;
do
_debug2 t
"
$t
"
if
[
"
$t
"
]
;
then
_add_data
=
"
$_add_data
,{
\"
data
\"
:
$t
}"
fi
done
_debug2 _add_data
"
$_add_data
"
_info
"Adding record"
if
_gd_rest PUT
"domains/
$_domain
/records/TXT/
$_sub_domain
"
"[
{
\"
data
\"
:
\"
$txtvalue
\"
}
]"
;
then
if
_gd_rest PUT
"domains/
$_domain
/records/TXT/
$_sub_domain
"
"[
$_add_data
]"
;
then
if
[
"
$response
"
=
"{}"
]
;
then
_info
"Added, sleeping 10 seconds"
_sleep 10
...
...
@@ -56,7 +77,47 @@ dns_gd_add() {
#fulldomain
dns_gd_rm
()
{
fulldomain
=
$1
txtvalue
=
$2
GD_Key
=
"
${
GD_Key
:-
$(
_readaccountconf_mutable GD_Key
)
}
"
GD_Secret
=
"
${
GD_Secret
:-
$(
_readaccountconf_mutable GD_Secret
)
}
"
_debug
"First detect the root zone"
if
!
_get_root
"
$fulldomain
"
;
then
_err
"invalid domain"
return
1
fi
_debug _sub_domain
"
$_sub_domain
"
_debug _domain
"
$_domain
"
_debug
"Getting existing records"
if
!
_gd_rest GET
"domains/
$_domain
/records/TXT/
$_sub_domain
"
;
then
return
1
fi
if
!
_contains
"
$response
"
"
$txtvalue
"
;
then
_info
"The record is not existing, skip"
return
0
;
fi
_add_data
=
""
for
t
in
$(
echo
"
$response
"
|
tr
'{'
"
\n
"
|
grep
"
\"
name
\"
:
\"
$_sub_domain
\"
"
|
tr
','
"
\n
"
|
grep
'"data"'
|
cut
-d
:
-f
2
)
;
do
_debug2 t
"
$t
"
if
[
"
$t
"
]
&&
[
"
$t
"
!=
"
\"
$txtvalue
\"
"
]
;
then
if
[
"
$_add_data
"
]
;
then
_add_data
=
"
$_add_data
,{
\"
data
\"
:
$t
}"
else
_add_data
=
"{
\"
data
\"
:
$t
}"
fi
fi
done
if
[
-z
"
$_add_data
"
]
;
then
_add_data
=
"{
\"
data
\"
:
\"\"
}"
fi
_debug2 _add_data
"
$_add_data
"
_gd_rest PUT
"domains/
$_domain
/records/TXT/
$_sub_domain
"
"[
$_add_data
]"
;
}
#################### Private functions below ##################################
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment