4 #OVH_AK="sdfsdfsdfljlbjkljlkjsdfoiwje"
7 #OVH_AS="sdfsafsdfsdfdsfsdfsa"
10 #OVH_CK="sdfsdfsdfsdfsdfdsf"
15 OVH_EU
='https://eu.api.ovh.com/1.0'
18 OVH_CA
='https://ca.api.ovh.com/1.0'
21 KSF_EU
='https://eu.api.kimsufi.com/1.0'
24 KSF_CA
='https://ca.api.kimsufi.com/1.0'
27 SYS_EU
='https://eu.api.soyoustart.com/1.0'
30 SYS_CA
='https://ca.api.soyoustart.com/1.0'
33 RAV_CA
='https://api.runabove.com/1.0'
35 wiki
="https://github.com/acmesh-official/acme.sh/wiki/How-to-use-OVH-domain-api"
37 ovh_success
="https://github.com/acmesh-official/acme.sh/wiki/OVH-Success"
52 kimsufi-eu | kimsufieu
)
56 kimsufi-ca | kimsufica
)
60 soyoustart-eu | soyoustarteu
)
64 soyoustart-ca | soyoustartca
)
68 runabove-ca | runaboveca
)
75 _err
"Unknown parameter : $1"
82 OVH_AK
="${OVH_AK:-$(_readaccountconf_mutable OVH_AK)}"
83 OVH_AS
="${OVH_AS:-$(_readaccountconf_mutable OVH_AS)}"
85 if [ -z "$OVH_AK" ] ||
[ -z "$OVH_AS" ]; then
88 _err
"You don't specify OVH application key and application secret yet."
89 _err
"Please create you key and try again."
93 if [ "$OVH_AK" != "$(_readaccountconf OVH_AK)" ]; then
94 _info
"It seems that your ovh key is changed, let's clear consumer key first."
95 _clearaccountconf_mutable OVH_CK
97 _saveaccountconf_mutable OVH_AK
"$OVH_AK"
98 _saveaccountconf_mutable OVH_AS
"$OVH_AS"
100 OVH_END_POINT
="${OVH_END_POINT:-$(_readaccountconf_mutable OVH_END_POINT)}"
101 if [ -z "$OVH_END_POINT" ]; then
102 OVH_END_POINT
="ovh-eu"
104 _info
"Using OVH endpoint: $OVH_END_POINT"
105 if [ "$OVH_END_POINT" != "ovh-eu" ]; then
106 _saveaccountconf_mutable OVH_END_POINT
"$OVH_END_POINT"
109 OVH_API
="$(_ovh_get_api $OVH_END_POINT)"
110 _debug OVH_API
"$OVH_API"
112 OVH_CK
="${OVH_CK:-$(_readaccountconf_mutable OVH_CK)}"
113 if [ -z "$OVH_CK" ]; then
114 _info
"OVH consumer key is empty, Let's get one:"
115 if ! _ovh_authentication
; then
116 _err
"Can not get consumer key."
118 #return and wait for retry.
121 _saveaccountconf_mutable OVH_CK
"$OVH_CK"
123 _info
"Checking authentication"
125 if ! _ovh_rest GET
"domain" || _contains
"$response" "INVALID_CREDENTIAL" || _contains
"$response" "NOT_CREDENTIAL"; then
126 _err
"The consumer key is invalid: $OVH_CK"
127 _err
"Please retry to create a new one."
128 _clearaccountconf_mutable OVH_CK
131 _info
"Consumer key is ok."
135 ######## Public functions #####################
137 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
146 _debug
"First detect the root zone"
147 if ! _get_root
"$fulldomain"; then
148 _err
"invalid domain"
152 _debug _sub_domain
"$_sub_domain"
153 _debug _domain
"$_domain"
155 _info
"Adding record"
156 if _ovh_rest POST
"domain/zone/$_domain/record" "{\"fieldType\":\"TXT\",\"subDomain\":\"$_sub_domain\",\"target\":\"$txtvalue\",\"ttl\":60}"; then
157 if _contains
"$response" "$txtvalue"; then
158 _ovh_rest POST
"domain/zone/$_domain/refresh"
159 _debug
"Refresh:$response"
160 _info
"Added, sleep 10 seconds."
165 _err
"Add txt record error."
179 _debug
"First detect the root zone"
180 if ! _get_root
"$fulldomain"; then
181 _err
"invalid domain"
185 _debug _sub_domain
"$_sub_domain"
186 _debug _domain
"$_domain"
187 _debug
"Getting txt records"
188 if ! _ovh_rest GET
"domain/zone/$_domain/record?fieldType=TXT&subDomain=$_sub_domain"; then
192 for rid
in $
(echo "$response" |
tr '][,' ' '); do
194 if ! _ovh_rest GET
"domain/zone/$_domain/record/$rid"; then
197 if _contains
"$response" "\"target\":\"$txtvalue\""; then
198 _debug
"Found txt id:$rid"
199 if ! _ovh_rest DELETE
"domain/zone/$_domain/record/$rid"; then
202 _ovh_rest POST
"domain/zone/$_domain/refresh"
203 _debug
"Refresh:$response"
211 #################### Private functions below ##################################
213 _ovh_authentication
() {
215 _H1
="X-Ovh-Application: $OVH_AK"
216 _H2
="Content-type: application/json"
220 _ovhdata
='{"accessRules": [{"method": "GET","path": "/auth/time"},{"method": "GET","path": "/domain"},{"method": "GET","path": "/domain/zone/*"},{"method": "GET","path": "/domain/zone/*/record"},{"method": "POST","path": "/domain/zone/*/record"},{"method": "POST","path": "/domain/zone/*/refresh"},{"method": "PUT","path": "/domain/zone/*/record/*"},{"method": "DELETE","path": "/domain/zone/*/record/*"}],"redirection":"'$ovh_success'"}'
222 response
="$(_post "$_ovhdata" "$OVH_API/auth
/credential
")"
223 _debug3 response
"$response"
224 validationUrl
="$(echo "$response" | _egrep_o "validationUrl
\":\"[^
\"]*\"" | _egrep_o "http.
*\"" | tr -d '"')"
225 if [ -z "$validationUrl" ]; then
226 _err "Unable to get validationUrl"
229 _debug validationUrl "$validationUrl"
231 consumerKey="$(echo "$response" | _egrep_o "consumerKey\":\"[^\"]*\"" | cut -d : -f 2 | tr -d '"')"
232 if [ -z "$consumerKey" ]; then
233 _err
"Unable to get consumerKey"
236 _secure_debug consumerKey
"$consumerKey"
238 OVH_CK
="$consumerKey"
239 _saveaccountconf_mutable OVH_CK
"$OVH_CK"
240 _info
"Please open this link to do authentication: $(__green "$validationUrl")"
242 _info
"Here is a guide for you: $(__green "$wiki")"
243 _info
"Please retry after the authentication is done."
247 #_acme-challenge.www.domain.com
249 # _sub_domain=_acme-challenge.www
256 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
262 if ! _ovh_rest GET
"domain/zone/$h"; then
266 if ! _contains
"$response" "This service does not exist" >/dev
/null
&&
267 ! _contains
"$response" "This call has not been granted" >/dev
/null
&&
268 ! _contains
"$response" "NOT_GRANTED_CALL" >/dev
/null
; then
269 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
285 _get
"$OVH_API/auth/time" "" 30
294 _ovh_url
="$OVH_API/$ep"
295 _debug2 _ovh_url
"$_ovh_url"
296 _ovh_t
="$(_ovh_timestamp)"
297 _debug2 _ovh_t
"$_ovh_t"
298 _ovh_p
="$OVH_AS+$OVH_CK+$m+$_ovh_url+$data+$_ovh_t"
299 _secure_debug _ovh_p
"$_ovh_p"
300 _ovh_hex
="$(printf "%s
" "$_ovh_p" | _digest sha1 hex)"
301 _debug2 _ovh_hex
"$_ovh_hex"
303 export _H1
="X-Ovh-Application: $OVH_AK"
304 export _H2
="X-Ovh-Signature: \$1\$$_ovh_hex"
306 export _H3
="X-Ovh-Timestamp: $_ovh_t"
307 export _H4
="X-Ovh-Consumer: $OVH_CK"
308 export _H5
="Content-Type: application/json;charset=utf-8"
309 if [ "$data" ] ||
[ "$m" = "POST" ] ||
[ "$m" = "PUT" ] ||
[ "$m" = "DELETE" ]; then
311 response
="$(_post "$data" "$_ovh_url" "" "$m")"
313 response
="$(_get "$_ovh_url")"
316 if [ "$?" != "0" ] || _contains
"$response" "INVALID_CREDENTIAL"; then
317 _err
"error $response"
320 _debug2 response
"$response"