4 # https://console.online.net/en/api/
6 # Requires Online API key set in ONLINE_API_KEY
8 ######## Public functions #####################
10 ONLINE_API
="https://api.online.net/api/v1"
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 if ! _online_check_config
; then
21 _debug
"First detect the root zone"
22 if ! _get_root
"$fulldomain"; then
27 _debug _sub_domain
"$_sub_domain"
28 _debug _domain
"$_domain"
29 _debug _real_dns_version
"$_real_dns_version"
31 _info
"Creating temporary zone version"
32 _online_create_temporary_zone_version
33 _info
"Enabling temporary zone version"
34 _online_enable_zone
"$_temporary_dns_version"
37 _online_create_TXT_record
"$_real_dns_version" "$_sub_domain" "$txtvalue"
38 _info
"Disabling temporary version"
39 _online_enable_zone
"$_real_dns_version"
40 _info
"Destroying temporary version"
41 _online_destroy_zone
"$_temporary_dns_version"
52 if ! _online_check_config
; then
56 _debug
"First detect the root zone"
57 if ! _get_root
"$fulldomain"; then
62 _debug _sub_domain
"$_sub_domain"
63 _debug _domain
"$_domain"
64 _debug _real_dns_version
"$_real_dns_version"
66 _debug
"Getting txt records"
67 if ! _online_rest GET
"domain/$_domain/version/active"; then
71 rid
=$
(echo "$response" | _egrep_o
"\"id\":[0-9]+,\"name\":\"$_sub_domain\",\"data\":\"\\\u0022$txtvalue\\\u0022\"" | cut
-d ':' -f 2 | cut
-d ',' -f 1)
73 if [ -z "$rid" ]; then
77 _info
"Creating temporary zone version"
78 _online_create_temporary_zone_version
79 _info
"Enabling temporary zone version"
80 _online_enable_zone
"$_temporary_dns_version"
82 _info
"Removing DNS record"
83 _online_rest DELETE
"domain/$_domain/version/$_real_dns_version/zone/$rid"
84 _info
"Disabling temporary version"
85 _online_enable_zone
"$_real_dns_version"
86 _info
"Destroying temporary version"
87 _online_destroy_zone
"$_temporary_dns_version"
92 #################### Private functions below ##################################
94 _online_check_config
() {
95 ONLINE_API_KEY
="${ONLINE_API_KEY:-$(_readaccountconf_mutable ONLINE_API_KEY)}"
96 if [ -z "$ONLINE_API_KEY" ]; then
97 _err
"No API key specified for Online API."
98 _err
"Create your key and export it as ONLINE_API_KEY"
101 if ! _online_rest GET
"domain/"; then
102 _err
"Invalid API key specified for Online API."
106 _saveaccountconf_mutable ONLINE_API_KEY
"$ONLINE_API_KEY"
111 #_acme-challenge.www.domain.com
113 # _sub_domain=_acme-challenge.www
120 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
126 _online_rest GET
"domain/$h/version/active"
128 if ! _contains
"$response" "Domain not found" >/dev
/null
; then
129 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
131 _real_dns_version
=$
(echo "$response" | _egrep_o
'"uuid_ref":.*' | cut
-d ':' -f 2 | cut
-d '"' -f 2)
137 _err
"Unable to retrive DNS zone matching this domain"
141 # this function create a temporary zone version
142 # as online.net does not allow updating an active version
143 _online_create_temporary_zone_version
() {
145 _online_rest POST
"domain/$_domain/version" "name=acme.sh"
146 if [ "$?" != "0" ]; then
150 _temporary_dns_version
=$
(echo "$response" | _egrep_o
'"uuid_ref":.*' | cut
-d ':' -f 2 | cut
-d '"' -f 2)
152 # Creating a dummy record in this temporary version, because online.net doesn't accept enabling an empty version
153 _online_create_TXT_record
"$_temporary_dns_version" "dummy.acme.sh" "dummy"
158 _online_destroy_zone
() {
160 _online_rest DELETE
"domain/$_domain/version/$version_id"
162 if [ "$?" != "0" ]; then
168 _online_enable_zone
() {
170 _online_rest PATCH
"domain/$_domain/version/$version_id/enable"
172 if [ "$?" != "0" ]; then
178 _online_create_TXT_record
() {
183 _online_rest POST
"domain/$_domain/version/$version/zone" "type=TXT&name=$txt_name&data=%22$txt_value%22&ttl=60&priority=0"
185 # Note : the normal, expected response SHOULD be "Unknown method".
186 # this happens because the API HTTP response contains a Location: header, that redirect
187 # to an unknown online.net endpoint.
188 if [ "$?" != "0" ] || _contains
"$response" "Unknown method" || _contains
"$response" "\$ref"; then
191 _err
"error $response"
201 _online_url
="$ONLINE_API/$ep"
202 _debug2 _online_url
"$_online_url"
203 export _H1
="Authorization: Bearer $ONLINE_API_KEY"
204 export _H2
="X-Pretty-JSON: 1"
205 if [ "$data" ] ||
[ "$m" != "GET" ]; then
207 response
="$(_post "$data" "$_online_url" "" "$m")"
209 response
="$(_get "$_online_url")"
211 if [ "$?" != "0" ] || _contains
"$response" "invalid_grant" || _contains
"$response" "Method not allowed"; then
212 _err
"error $response"
215 _debug2 response
"$response"