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
0dd6377f
Commit
0dd6377f
authored
Mar 14, 2017
by
boyanpeychev
Browse files
Add DNS API for ClouDNS
parent
c7257e0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_cloudns.sh
View file @
0dd6377f
...
@@ -7,7 +7,7 @@ CLOUDNS_API="https://api.cloudns.net"
...
@@ -7,7 +7,7 @@ CLOUDNS_API="https://api.cloudns.net"
######## Public functions #####################
######## Public functions #####################
#Usage: dns_cloudns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
#Usage: dns_cloudns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_cloudns_add
()
{
dns_cloudns_add
()
{
_info
"Using cloudns"
_info
"Using cloudns"
if
!
_dns_cloudns_init_check
;
then
if
!
_dns_cloudns_init_check
;
then
...
@@ -20,8 +20,8 @@ dns_cloudns_add () {
...
@@ -20,8 +20,8 @@ dns_cloudns_add () {
return
1
return
1
fi
fi
host
=
"
$(
echo
$1
|
sed
"s/
\.
$zone
\$
//"
)
"
host
=
"
$(
echo
"
$1
"
|
sed
"s/
\.
$zone
\$
//"
)
"
record
=
$2
record
=
$2
record_id
=
$(
_dns_cloudns_get_record_id
"
$zone
"
"
$host
"
)
record_id
=
$(
_dns_cloudns_get_record_id
"
$zone
"
"
$host
"
)
_debug zone
"
$zone
"
_debug zone
"
$zone
"
...
@@ -52,14 +52,14 @@ dns_cloudns_add () {
...
@@ -52,14 +52,14 @@ dns_cloudns_add () {
}
}
#Usage: dns_cloudns_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
#Usage: dns_cloudns_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_cloudns_rm
()
{
dns_cloudns_rm
()
{
_info
"Using cloudns"
_info
"Using cloudns"
if
!
_dns_cloudns_init_check
;
then
if
!
_dns_cloudns_init_check
;
then
return
1
return
1
fi
fi
if
[
-z
$zone
]
;
then
if
[
-z
"
$zone
"
]
;
then
zone
=
"
$(
_dns_cloudns_get_zone_name
$1
)
"
zone
=
"
$(
_dns_cloudns_get_zone_name
$1
)
"
if
[
-z
"
$zone
"
]
;
then
if
[
-z
"
$zone
"
]
;
then
_err
"Missing DNS zone at ClouDNS. Please log into your control panel and create the required DNS zone for the initial setup."
_err
"Missing DNS zone at ClouDNS. Please log into your control panel and create the required DNS zone for the initial setup."
...
@@ -67,8 +67,8 @@ dns_cloudns_rm () {
...
@@ -67,8 +67,8 @@ dns_cloudns_rm () {
fi
fi
fi
fi
host
=
"
$(
echo
$1
|
sed
"s/
\.
$zone
\$
//"
)
"
host
=
"
$(
echo
"
$1
"
|
sed
"s/
\.
$zone
\$
//"
)
"
record
=
$2
record
=
$2
record_id
=
$(
_dns_cloudns_get_record_id
"
$zone
"
"
$host
"
)
record_id
=
$(
_dns_cloudns_get_record_id
"
$zone
"
"
$host
"
)
_debug zone
"
$zone
"
_debug zone
"
$zone
"
...
@@ -89,8 +89,8 @@ dns_cloudns_rm () {
...
@@ -89,8 +89,8 @@ dns_cloudns_rm () {
}
}
#################### Private functions below ##################################
#################### Private functions below ##################################
_dns_cloudns_init_check
()
{
_dns_cloudns_init_check
()
{
if
[
!
-z
$CLOUDNS_INIT_CHECK_COMPLETED
]
;
then
if
[
!
-z
"
$CLOUDNS_INIT_CHECK_COMPLETED
"
]
;
then
return
0
return
0
fi
fi
...
@@ -109,7 +109,7 @@ _dns_cloudns_init_check () {
...
@@ -109,7 +109,7 @@ _dns_cloudns_init_check () {
return
0
return
0
}
}
_dns_cloudns_get_zone_name
()
{
_dns_cloudns_get_zone_name
()
{
i
=
2
i
=
2
while
true
;
do
while
true
;
do
zoneForCheck
=
$(
printf
"%s"
"
$1
"
|
cut
-d
.
-f
$i
-100
)
zoneForCheck
=
$(
printf
"%s"
"
$1
"
|
cut
-d
.
-f
$i
-100
)
...
@@ -123,7 +123,7 @@ _dns_cloudns_get_zone_name () {
...
@@ -123,7 +123,7 @@ _dns_cloudns_get_zone_name () {
_dns_cloudns_http_api_call
"dns/get-zone-info.json"
"domain-name=
$zoneForCheck
"
_dns_cloudns_http_api_call
"dns/get-zone-info.json"
"domain-name=
$zoneForCheck
"
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Failed
\"
"
;
then
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Failed
\"
"
;
then
echo
$zoneForCheck
echo
"
$zoneForCheck
"
return
0
return
0
fi
fi
...
@@ -132,16 +132,16 @@ _dns_cloudns_get_zone_name () {
...
@@ -132,16 +132,16 @@ _dns_cloudns_get_zone_name () {
return
1
return
1
}
}
_dns_cloudns_get_record_id
()
{
_dns_cloudns_get_record_id
()
{
_dns_cloudns_http_api_call
"dns/records.json"
"domain-name=
$1
&host=
$2
&type=TXT"
_dns_cloudns_http_api_call
"dns/records.json"
"domain-name=
$1
&host=
$2
&type=TXT"
if
_contains
"
$response
"
"
\"
id
\"
:"
;
then
if
_contains
"
$response
"
"
\"
id
\"
:"
;
then
echo
$response
|
awk
'BEGIN { FS="\"" } {print $2}'
echo
"
$response
"
|
awk
'BEGIN { FS="\"" } {print $2}'
return
0
return
0
fi
fi
return
1
return
1
}
}
_dns_cloudns_http_api_call
()
{
_dns_cloudns_http_api_call
()
{
method
=
$1
method
=
$1
_debug CLOUDNS_AUTH_ID
"
$CLOUDNS_AUTH_ID
"
_debug CLOUDNS_AUTH_ID
"
$CLOUDNS_AUTH_ID
"
...
...
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