@@ -27,8 +27,16 @@ dns_nanelo_add() {
2727 fi
2828 _saveaccountconf_mutable NANELO_TOKEN " $NANELO_TOKEN "
2929
30+ _debug " First detect the root zone"
31+ if ! _get_root " $fulldomain " ; then
32+ _err " invalid domain"
33+ return 1
34+ fi
35+ _debug _sub_domain " $_sub_domain "
36+ _debug _domain " $_domain "
37+
3038 _info " Adding TXT record to ${fulldomain} "
31- response=" $( _get " $NANELO_API$NANELO_TOKEN /dns/addrecord?type=TXT&ttl=60&name=${fulldomain } &value=${txtvalue} " ) "
39+ response=" $( _post " " " $NANELO_API$NANELO_TOKEN /dns/addrecord?domain= ${_domain} & type=TXT&ttl=60&name=${_sub_domain } &value=${txtvalue} " " " " " " " ) "
3240 if _contains " ${response} " ' success' ; then
3341 return 0
3442 fi
@@ -51,12 +59,62 @@ dns_nanelo_rm() {
5159 fi
5260 _saveaccountconf_mutable NANELO_TOKEN " $NANELO_TOKEN "
5361
62+ _debug " First, let's detect the root zone:"
63+ if ! _get_root " $fulldomain " ; then
64+ _err " invalid domain"
65+ return 1
66+ fi
67+ _debug _sub_domain " $_sub_domain "
68+ _debug _domain " $_domain "
69+
5470 _info " Deleting resource record $fulldomain "
55- response=" $( _get " $NANELO_API$NANELO_TOKEN /dns/deleterecord?type=TXT&ttl=60&name=${fulldomain } &value=${txtvalue} " ) "
71+ response=" $( _post " " " $NANELO_API$NANELO_TOKEN /dns/deleterecord?domain= ${_domain} & type=TXT&ttl=60&name=${_sub_domain } &value=${txtvalue} " " " " " " " ) "
5672 if _contains " ${response} " ' success' ; then
5773 return 0
5874 fi
5975 _err " Could not delete resource record, please check the logs"
6076 _err " ${response} "
6177 return 1
6278}
79+
80+ # ################### Private functions below ##################################
81+ # _acme-challenge.www.domain.com
82+ # returns
83+ # _sub_domain=_acme-challenge.www
84+ # _domain=domain.com
85+
86+ _get_root () {
87+ fulldomain=$1
88+
89+ # Fetch all zones from Nanelo
90+ response=" $( _get " $NANELO_API$NANELO_TOKEN /dns/getzones" ) " || return 1
91+
92+ # Extract "zones" array into space-separated list
93+ zones=$( echo " $response " |
94+ tr -d ' \n' |
95+ sed -n ' s/.*"zones":\[\([^]]*\)\].*/\1/p' |
96+ tr -d ' "' |
97+ tr , ' ' )
98+ _debug zones " $zones "
99+
100+ bestzone=" "
101+ for z in $zones ; do
102+ case " $fulldomain " in
103+ * ." $z " | " $z " )
104+ if [ ${# z} -gt ${# bestzone} ]; then
105+ bestzone=$z
106+ fi
107+ ;;
108+ esac
109+ done
110+
111+ if [ -z " $bestzone " ]; then
112+ _err " No matching zone found for $fulldomain "
113+ return 1
114+ fi
115+
116+ _domain=" $bestzone "
117+ _sub_domain=$( printf " %s" " $fulldomain " | sed " s/\\ .$_domain \$ //" )
118+
119+ return 0
120+ }
0 commit comments