5 #Updated 03/01/2018, rewrote to support name.com API v4
6 #Utilize name.com API to finish dns-01 verifications.
7 ######## Public functions #####################
9 Namecom_API
="https://api.name.com/v4"
11 # First we need name.com credentials.
12 if [ -z "$Namecom_Username" ]; then
14 _err
"Username for name.com is missing."
15 _err
"Please specify that in your environment variable."
19 if [ -z "$Namecom_Token" ]; then
21 _err
"API token for name.com is missing."
22 _err
"Please specify that in your environment variable."
26 # Save them in configuration.
27 _saveaccountconf Namecom_Username
"$Namecom_Username"
28 _saveaccountconf Namecom_Token
"$Namecom_Token"
31 # Name.com API v4 uses http basic auth to authenticate
32 # need to convert the token for http auth
33 _namecom_auth
=$
(printf "%s:%s" "$Namecom_Username" "$Namecom_Token" | base64
)
35 #Usage: dns_namecom_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
41 if ! _namecom_login
; then
45 # Find domain in domain list.
46 if ! _namecom_get_root
"$fulldomain"; then
47 _err
"Unable to find domain specified."
52 _namecom_addtxt_json
="{\"host\":\"$_sub_domain\",\"type\":\"TXT\",\"answer\":\"$txtvalue\",\"ttl\":\"300\"}"
53 if _namecom_rest POST
"domains/$_domain/records" "$_namecom_addtxt_json"; then
54 _retvalue
=$
(printf "%s\n" "$response" | _egrep_o
"\"$_sub_domain\"")
55 if [ "$_retvalue" ]; then
56 _info
"Successfully added TXT record, ready for validation."
59 _err
"Unable to add the DNS record."
65 #Usage: fulldomain txtvalue
66 #Remove the txt record after validation.
71 if ! _namecom_login
; then
75 # Find domain in domain list.
76 if ! _namecom_get_root
"$fulldomain"; then
77 _err
"Unable to find domain specified."
82 if _namecom_rest GET
"domains/$_domain/records"; then
83 _record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[0-9]+,\"domainName\":\"$_domain\",\"host\":\"$_sub_domain\"" | cut
-d \" -f 3 | _egrep_o
[0-9]+)
84 _debug record_id
"$_record_id"
85 if [ "$_record_id" ]; then
86 _info
"Successfully retrieved the record id for ACME challenge."
88 _err
"Unable to retrieve the record id."
93 # Remove the DNS record using record id.
94 if _namecom_rest DELETE
"domains/$_domain/records/$_record_id"; then
95 _info
"Successfully removed the TXT record."
98 _err
"Unable to delete record id."
103 #################### Private functions below ##################################
109 export _H1
="Authorization: Basic $_namecom_auth"
110 export _H2
="Content-Type: application/json"
112 if [ "$method" != "GET" ]; then
113 response
="$(_post "$data" "$Namecom_API/$param" "" "$method")"
115 response
="$(_get "$Namecom_API/$param")"
118 if [ "$?" != "0" ]; then
123 _debug response
"$response"
128 if _namecom_rest GET
"hello"; then
129 retcode
=$
(printf "%s\n" "$response" | _egrep_o
"\"username\"\:\"$Namecom_Username\"")
130 if [ "$retcode" ]; then
131 _info
"Successfully logged in."
133 _err
"Logging in failed."
139 _namecom_get_root
() {
144 if ! _namecom_rest GET
"domains"; then
148 # Need to exclude the last field (tld)
149 numfields
=$
(echo "$domain" | _egrep_o
"\." |
wc -l)
150 while [ $i -le "$numfields" ]; do
151 host=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
153 if [ -z "$host" ]; then
157 if _contains
"$response" "$host"; then
158 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)