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
=$
(printf "%s\n" "$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 _info
"Successfully retrieved the record id for ACME challenge."
66 _err
"Unable to retrieve the record id."
71 # Remove the DNS record using record id.
72 if _namesilo_rest GET
"dnsDeleteRecord?version=1&type=xml&key=$Namesilo_Key&domain=$_domain&rrid=$_record_id"; then
73 retcode
=$
(printf "%s\n" "$response" | _egrep_o
"<code>300")
74 if [ "$retcode" ]; then
75 _info
"Successfully removed the TXT record."
78 _err
"Unable to remove the DNS record."
84 #################### Private functions below ##################################
86 # _acme-challenge.www.domain.com
88 # _sub_domain=_acme-challenge.www
95 if ! _namesilo_rest GET
"listDomains?version=1&type=xml&key=$Namesilo_Key"; then
99 # Need to exclude the last field (tld)
100 numfields
=$
(echo "$domain" | _egrep_o
"\." |
wc -l)
101 while [ $i -le "$numfields" ]; do
102 host=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
104 if [ -z "$host" ]; then
108 if _contains
"$response" "$host"; then
109 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
124 if [ "$method" != "GET" ]; then
125 response
="$(_post "$data" "$Namesilo_API/$param" "" "$method")"
127 response
="$(_get "$Namesilo_API/$param")"
130 if [ "$?" != "0" ]; then
135 _debug2 response
"$response"