Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
c73c33f9
Commit
c73c33f9
authored
Oct 01, 2017
by
sahsanu
Committed by
GitHub
Oct 01, 2017
Browse files
Update dns_cloudns.sh
parent
6c7da215
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_cloudns.sh
View file @
c73c33f9
...
@@ -11,160 +11,174 @@ CLOUDNS_API="https://api.cloudns.net"
...
@@ -11,160 +11,174 @@ CLOUDNS_API="https://api.cloudns.net"
#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
return
1
return
1
fi
fi
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."
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
"
_debug host
"
$host
"
_debug host
"
$host
"
_debug record
"
$record
"
_debug record
"
$record
"
_debug record_id
"
$record_id
"
_debug record_id
"
$record_id
"
if
[
-z
"
$record_id
"
]
;
then
if
[
-z
"
$record_id
"
]
;
then
_info
"Adding the TXT record for
$1
"
_info
"Adding the TXT record for
$1
"
_dns_cloudns_http_api_call
"dns/add-record.json"
"domain-name=
$zone
&record-type=TXT&host=
$host
&record=
$record
&ttl=60"
_dns_cloudns_http_api_call
"dns/add-record.json"
"domain-name=
$zone
&record-type=TXT&host=
$host
&record=
$record
&ttl=60"
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
_err
"Record cannot be added."
_err
"Record cannot be added."
return
1
return
1
fi
fi
_info
"Added."
_info
"Added."
else
else
_info
"Updating the TXT record for
$1
"
_info
"Updating the TXT record for
$1
"
_dns_cloudns_http_api_call
"dns/mod-record.json"
"domain-name=
$zone
&record-id=
$record_id
&record-type=TXT&host=
$host
&record=
$record
&ttl=60"
_dns_cloudns_http_api_call
"dns/mod-record.json"
"domain-name=
$zone
&record-id=
$record_id
&record-type=TXT&host=
$host
&record=
$record
&ttl=60"
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
_err
"The TXT record for
$1
cannot be updated."
_err
"The TXT record for
$1
cannot be updated."
return
1
return
1
fi
fi
_info
"Updated."
_info
"Updated."
fi
fi
return
0
return
0
}
}
#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."
return
1
return
1
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
"
_debug host
"
$host
"
_debug host
"
$host
"
_debug record
"
$record
"
_debug record
"
$record
"
_debug record_id
"
$record_id
"
_debug record_id
"
$record_id
"
if
[
!
-z
"
$record_id
"
]
;
then
if
[
!
-z
"
$record_id
"
]
;
then
_info
"Deleting the TXT record for
$1
"
_info
"Deleting the TXT record for
$1
"
_dns_cloudns_http_api_call
"dns/delete-record.json"
"domain-name=
$zone
&record-id=
$record_id
"
_dns_cloudns_http_api_call
"dns/delete-record.json"
"domain-name=
$zone
&record-id=
$record_id
"
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
_err
"The TXT record for
$1
cannot be deleted."
_err
"The TXT record for
$1
cannot be deleted."
return
1
return
1
fi
fi
_info
"Deleted."
_info
"Deleted."
fi
fi
return
0
return
0
}
}
#################### 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
if
[
-z
"
$CLOUDNS_AUTH_ID
"
]
;
then
CLOUDNS_AUTH_ID
=
"
${
CLOUDNS_AUTH_ID
:-
$(
_readaccountconf_mutable CLOUDNS_AUTH_ID
)
}
"
_err
"CLOUDNS_AUTH_ID is not configured"
CLOUDNS_AUTH_PASSWORD
=
"
${
CLOUDNS_AUTH_PASSWORD
:-
$(
_readaccountconf_mutable CLOUDNS_AUTH_PASSWORD
)
}
"
return
1
if
[
-z
"
$CLOUDNS_AUTH_ID
"
]
||
[
-z
"
$CLOUDNS_AUTH_PASSWORD
"
]
;
then
fi
CLOUDNS_AUTH_ID
=
""
CLOUDNS_AUTH_PASSWORD
=
""
if
[
-z
"
$CLOUDNS_AUTH_PASSWORD
"
]
;
then
_err
"You don't specify cloudns api id and password yet."
_err
"CLOUDNS_AUTH_PASSWORD is not configured"
_err
"Please create you id and password and try again."
return
1
return
1
fi
fi
_dns_cloudns_http_api_call
"dns/login.json"
""
if
[
-z
"
$CLOUDNS_AUTH_ID
"
]
;
then
_err
"CLOUDNS_AUTH_ID is not configured"
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
return
1
_err
"Invalid CLOUDNS_AUTH_ID or CLOUDNS_AUTH_PASSWORD. Please check your login credentials."
fi
return
1
fi
if
[
-z
"
$CLOUDNS_AUTH_PASSWORD
"
]
;
then
_err
"CLOUDNS_AUTH_PASSWORD is not configured"
CLOUDNS_INIT_CHECK_COMPLETED
=
1
return
1
fi
return
0
_dns_cloudns_http_api_call
"dns/login.json"
""
if
!
_contains
"
$response
"
"
\"
status
\"
:
\"
Success
\"
"
;
then
_err
"Invalid CLOUDNS_AUTH_ID or CLOUDNS_AUTH_PASSWORD. Please check your login credentials."
return
1
fi
#save the api id and password to the account conf file.
_saveaccountconf_mutable CLOUDNS_AUTH_ID
"
$CLOUDNS_AUTH_ID
"
_saveaccountconf_mutable CLOUDNS_AUTH_PASSWORD
"
$CLOUDNS_AUTH_PASSWORD
"
CLOUDNS_INIT_CHECK_COMPLETED
=
1
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
)
if
[
-z
"
$zoneForCheck
"
]
;
then
if
[
-z
"
$zoneForCheck
"
]
;
then
return
1
return
1
fi
fi
_debug zoneForCheck
"
$zoneForCheck
"
_debug zoneForCheck
"
$zoneForCheck
"
_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
i
=
$(
_math
"
$i
"
+ 1
)
i
=
$(
_math
"
$i
"
+ 1
)
done
done
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
"
|
cut
-d
'"'
-f
2
echo
"
$response
"
|
cut
-d
'"'
-f
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
"
_debug CLOUDNS_AUTH_PASSWORD
"
$CLOUDNS_AUTH_PASSWORD
"
_debug CLOUDNS_AUTH_PASSWORD
"
$CLOUDNS_AUTH_PASSWORD
"
if
[
-z
"
$2
"
]
;
then
if
[
-z
"
$2
"
]
;
then
data
=
"auth-id=
$CLOUDNS_AUTH_ID
&auth-password=
$CLOUDNS_AUTH_PASSWORD
"
data
=
"auth-id=
$CLOUDNS_AUTH_ID
&auth-password=
$CLOUDNS_AUTH_PASSWORD
"
else
else
data
=
"auth-id=
$CLOUDNS_AUTH_ID
&auth-password=
$CLOUDNS_AUTH_PASSWORD
&
$2
"
data
=
"auth-id=
$CLOUDNS_AUTH_ID
&auth-password=
$CLOUDNS_AUTH_PASSWORD
&
$2
"
fi
fi
response
=
"
$(
_get
"
$CLOUDNS_API
/
$method
?
$data
"
)
"
response
=
"
$(
_get
"
$CLOUDNS_API
/
$method
?
$data
"
)
"
_debug2 response
"
$response
"
_debug2 response
"
$response
"
return
0
return
0
}
}
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