3 #Usage specify a private keyfile to use with dynv6 'export KEY="path/to/keyfile"'
4 #or use the HTTP REST API by by specifying a token 'export DYNV6_TOKEN="value"
5 #if no keyfile is specified, you will be asked if you want to create one in /home/$USER/.ssh/dynv6 and /home/$USER/.ssh/dynv6.pub
7 dynv6_api
="https://dynv6.com/api/v2"
8 ######## Public functions #####################
9 # Please Read this guide first: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide
10 #Usage: dns_dynv6_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
14 _info
"Using dynv6 api"
15 _debug fulldomain
"$fulldomain"
16 _debug txtvalue
"$txtvalue"
18 if [ "$dynv6_token" ]; then
22 _info
"using key file $dynv6_keyfile"
23 _your_hosts
="$(ssh -i "$dynv6_keyfile" api@dynv6.com hosts)"
24 if ! _get_domain
"$fulldomain" "$_your_hosts"; then
25 _err
"Host not found on your account"
28 _debug
"found host on your account"
29 returnval
="$(ssh -i "$dynv6_keyfile" api@dynv6.com hosts \""$_host"\" records set \""$_record"\" txt data \""$txtvalue"\")"
30 _debug
"Dynv6 returned this after record was added: $returnval"
31 if _contains
"$returnval" "created"; then
33 elif _contains
"$returnval" "updated"; then
36 _err
"Something went wrong! it does not seem like the record was added successfully"
43 #Usage: fulldomain txtvalue
44 #Remove the txt record after validation.
48 _info
"Using dynv6 API"
49 _debug fulldomain
"$fulldomain"
50 _debug txtvalue
"$txtvalue"
52 if [ "$dynv6_token" ]; then
56 _info
"using key file $dynv6_keyfile"
57 _your_hosts
="$(ssh -i "$dynv6_keyfile" api@dynv6.com hosts)"
58 if ! _get_domain
"$fulldomain" "$_your_hosts"; then
59 _err
"Host not found on your account"
62 _debug
"found host on your account"
63 _info
"$(ssh -i "$dynv6_keyfile" api@dynv6.com hosts "\"$_host\"" records del "\"$_record\"" txt)"
67 #################### Private functions below ##################################
68 #Usage: No Input required
70 #dynv6_keyfile the path to the new key file that has been generated
72 dynv6_keyfile
="$(eval echo ~"$USER")/.ssh/dynv6"
73 _info
"Path to key file used: $dynv6_keyfile"
74 if [ ! -f "$dynv6_keyfile" ] && [ ! -f "$dynv6_keyfile.pub" ]; then
75 _debug
"generating key in $dynv6_keyfile and $dynv6_keyfile.pub"
76 ssh-keygen
-f "$dynv6_keyfile" -t ssh-ed25519
-N ''
78 _err
"There is already a file in $dynv6_keyfile or $dynv6_keyfile.pub"
83 #Usage: _acme-challenge.www.example.dynv6.net "$_your_hosts"
84 #where _your_hosts is the output of ssh -i ~/.ssh/dynv6.pub api@dynv6.com hosts
86 #_host= example.dynv6.net
87 #_record=_acme-challenge.www
88 #aborts if not a valid domain
90 #_your_hosts="$(ssh -i ~/.ssh/dynv6.pub api@dynv6.com hosts)"
94 _your_hosts
="$(echo "$_your_hosts" | awk '/\./ {print $1}')"
95 for l
in $_your_hosts; do
97 if test "${_full_domain#*$l}" != "$_full_domain"; then
98 _record
="${_full_domain%.$l}"
100 _debug
"The host is $_host and the record $_record"
104 _err
"Either their is no such host on your dnyv6 account or it cannot be accessed with this key"
108 # Usage: No input required
110 #dynv6_keyfile path to the key that will be used
111 _get_authentication
() {
112 dynv6_token
="${DYNV6_TOKEN:-$(_readaccountconf_mutable dynv6_token)}"
113 if [ "$dynv6_token" ]; then
114 _debug
"Found HTTP Token. Going to use the HTTP API and not the SSH API"
115 if [ "$DYNV6_TOKEN" ]; then
116 _saveaccountconf_mutable dynv6_token
"$dynv6_token"
119 _debug
"no HTTP token found. Looking for an SSH key"
120 dynv6_keyfile
="${dynv6_keyfile:-$(_readaccountconf_mutable dynv6_keyfile)}"
121 _debug
"Your key is $dynv6_keyfile"
122 if [ -z "$dynv6_keyfile" ]; then
123 if [ -z "$KEY" ]; then
124 _err
"You did not specify a key to use with dynv6"
125 _info
"Creating new dynv6 API key to add to dynv6.com"
127 _info
"Please add this key to dynv6.com $(cat "$dynv6_keyfile.pub
")"
128 _info
"Hit Enter to continue"
130 #save the credentials to the account conf file.
134 _saveaccountconf_mutable dynv6_keyfile
"$dynv6_keyfile"
139 _dns_dynv6_add_http
() {
140 _debug
"Got HTTP token form _get_authentication method. Going to use the HTTP API"
141 if ! _get_zone_id
"$fulldomain"; then
142 _err
"Could not find a matching zone for $fulldomain. Maybe your HTTP Token is not authorized to access the zone"
145 _get_zone_name
"$_zone_id"
146 record
="${fulldomain%%.$_zone_name}"
147 _set_record TXT
"$record" "$txtvalue"
148 if _contains
"$response" "$txtvalue"; then
149 _info
"Successfully added record"
152 _err
"Something went wrong while adding the record"
157 _dns_dynv6_rm_http
() {
158 _debug
"Got HTTP token form _get_authentication method. Going to use the HTTP API"
159 if ! _get_zone_id
"$fulldomain"; then
160 _err
"Could not find a matching zone for $fulldomain. Maybe your HTTP Token is not authorized to access the zone"
163 _get_zone_name
"$_zone_id"
164 record
="${fulldomain%%.$_zone_name}"
165 _get_record_id
"$_zone_id" "$record" "$txtvalue"
166 _del_record
"$_zone_id" "$_record_id"
167 if [ -z "$response" ]; then
168 _info
"Successfully deleted record"
171 _err
"Something went wrong while deleting the record"
176 #get the zoneid for a specifc record or zone
177 #usage: _get_zone_id §record
178 #where $record is the record to get the id for
179 #returns _zone_id the id of the zone
182 _debug
"getting zone id for $record"
183 _dynv6_rest GET zones
185 zones
="$(echo "$response" | tr '}' '\n' | tr ',' '\n' | grep name | sed 's/\[//g' | tr -d '{' | tr -d '"')"
192 if _contains "$record" "$z"; then
193 _debug "$z found in $record"
197 if [ -z "$selected" ]; then
202 zone_id="$(echo "$response" | tr '}' '\n' | grep "$selected" | tr ',' '\n' | grep id | tr -d '"')"
203 _zone_id
="${zone_id#id:}"
204 _debug
"zone id: $_zone_id"
209 _dynv6_rest GET zones
/"$_zone_id"
210 _zone_name
="$(echo "$response" | tr ',' '\n' | tr -d '{' | grep name | tr -d '"')"
211 _zone_name="${_zone_name#name:}"
214 #usaage _get_record_id $zone_id $record
215 # where zone_id is thevalue returned by _get_zone_id
216 # and record ist in the form _acme.www for an fqdn of _acme.www.example.com
222 _dynv6_rest GET "zones/$_zone_id/records"
223 if ! _get_record_id_from_response "$response"; then
224 _err "no such record $record found in zone $_zone_id"
229 _get_record_id_from_response() {
231 _record_id="$(echo "$response" | tr '}' '\n' | grep "\"name\":\"$record\"" | grep "\"data\":\"$value\"" | tr ',' '\n' | grep id | tr -d '"' | tr -d 'id:')"
232 #_record_id="${_record_id#id:}"
233 if [ -z "$_record_id" ]; then
234 _err
"no such record: $record found in zone $_zone_id"
237 _debug
"record id: $_record_id"
240 #usage: _set_record TXT _acme_challenge.www longvalue 12345678
241 #zone id is optional can also be set as vairable bevor calling this method
249 data
="{\"name\": \"$record\", \"data\": \"$value\", \"type\": \"$type\"}"
250 #data='{ "name": "acme.test.thorn.dynv6.net", "type": "A", "data": "192.168.0.1"}'
252 #"{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":120}"
253 _dynv6_rest POST
"zones/$_zone_id/records" "$data"
258 _dynv6_rest DELETE zones
/"$_zone_id"/records
/"$_record_id"
262 m
=$1 #method GET,POST,DELETE or PUT
263 ep
="$2" #the endpoint
267 token_trimmed
=$
(echo "$dynv6_token" |
tr -d '"')
269 export _H1
="Authorization: Bearer $token_trimmed"
270 export _H2
="Content-Type: application/json"
272 if [ "$m" != "GET" ]; then
274 response
="$(_post "$data" "$dynv6_api/$ep" "" "$m")"
276 response
="$(_get "$dynv6_api/$ep")"
279 if [ "$?" != "0" ]; then
283 _debug2 response
"$response"