5 #Utilize namesilo.com API to finish dns-01 verifications.
7 Namesilo_API
="https://www.namesilo.com/api"
9 ######## Public functions #####################
11 #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
16 if [ -z "$Namesilo_Key" ]; then
18 _err
"API token for namesilo.com is missing."
19 _err
"Please specify that in your environment variable."
23 #save the api key and email to the account conf file.
24 _saveaccountconf Namesilo_Key
"$Namesilo_Key"
26 if ! _get_root
"$fulldomain"; then
27 _err
"Unable to find domain specified."
31 _debug _sub_domain
"$_sub_domain"
32 _debug _domain
"$_domain"
34 _debug txtvalue
"$txtvalue"
35 if _namesilo_rest GET
"dnsAddRecord?version=1&type=xml&key=$Namesilo_Key&domain=$_domain&rrtype=TXT&rrhost=$_sub_domain&rrvalue=$txtvalue"; then
36 retcode
=$
(printf "%s\n" "$response" | _egrep_o
"<code>300")
37 if [ "$retcode" ]; then
38 _info
"Successfully added TXT record, ready for validation."
41 _err
"Unable to add the DNS record."
47 #Usage: fulldomain txtvalue
48 #Remove the txt record after validation.
53 if ! _get_root
"$fulldomain"; then
54 _err
"Unable to find domain specified."
59 if _namesilo_rest GET
"dnsListRecords?version=1&type=xml&key=$Namesilo_Key&domain=$_domain"; then
60 retcode
=$
(printf "%s\n" "$response" | _egrep_o
"<code>300")
61 if [ "$retcode" ]; then
62 _record_id
=$
(echo "$response" | _egrep_o
"<record_id>([^<]*)</record_id><type>TXT</type><host>$fulldomain</host>" | _egrep_o
"<record_id>([^<]*)</record_id>" |
sed -r "s/<record_id>([^<]*)<\/record_id>/\1/" |
tail -n 1)
63 _debug _record_id
"$_record_id"
64 if [ "$_record_id" ]; then
65 _info
"Successfully retrieved the record id for ACME challenge."
67 _info
"Empty record id, it seems no such record."
71 _err
"Unable to retrieve the record id."
76 # Remove the DNS record using record id.
77 if _namesilo_rest GET
"dnsDeleteRecord?version=1&type=xml&key=$Namesilo_Key&domain=$_domain&rrid=$_record_id"; then
78 retcode
=$
(printf "%s\n" "$response" | _egrep_o
"<code>300")
79 if [ "$retcode" ]; then
80 _info
"Successfully removed the TXT record."
83 _err
"Unable to remove the DNS record."
89 #################### Private functions below ##################################
91 # _acme-challenge.www.domain.com
93 # _sub_domain=_acme-challenge.www
100 if ! _namesilo_rest GET
"listDomains?version=1&type=xml&key=$Namesilo_Key"; then
104 # Need to exclude the last field (tld)
105 numfields
=$
(echo "$domain" | _egrep_o
"\." |
wc -l)
106 while [ $i -le "$numfields" ]; do
107 host=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
109 if [ -z "$host" ]; then
113 if _contains
"$response" "<domain>$host"; then
114 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
129 if [ "$method" != "GET" ]; then
130 response
="$(_post "$data" "$Namesilo_API/$param" "" "$method")"
132 response
="$(_get "$Namesilo_API/$param")"
135 if [ "$?" != "0" ]; then
140 _debug2 response
"$response"