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/Neilpang/acme.sh/wiki/How-to-use-OVH-domain-api"
37 ovh_success
="https://github.com/Neilpang/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"
83 if [ -z "$OVH_AK" ] ||
[ -z "$OVH_AS" ]; then
86 _err
"You don't specify OVH application key and application secret yet."
87 _err
"Please create you key and try again."
91 #save the api key and email to the account conf file.
92 _saveaccountconf OVH_AK
"$OVH_AK"
93 _saveaccountconf OVH_AS
"$OVH_AS"
95 if [ -z "$OVH_END_POINT" ]; then
96 OVH_END_POINT
="ovh-eu"
98 _info
"Using OVH endpoint: $OVH_END_POINT"
99 if [ "$OVH_END_POINT" != "ovh-eu" ]; then
100 _saveaccountconf OVH_END_POINT
"$OVH_END_POINT"
103 OVH_API
="$(_ovh_get_api $OVH_END_POINT)"
104 _debug OVH_API
"$OVH_API"
106 if [ -z "$OVH_CK" ]; then
107 _info
"OVH consumer key is empty, Let's get one:"
108 if ! _ovh_authentication
; then
109 _err
"Can not get consumer key."
111 #return and wait for retry.
115 _info
"Checking authentication"
117 if ! _ovh_rest GET
"domain" || _contains
"$response" "INVALID_CREDENTIAL"; then
118 _err
"The consumer key is invalid: $OVH_CK"
119 _err
"Please retry to create a new one."
120 _clearaccountconf OVH_CK
123 _info
"Consumer key is ok."
127 ######## Public functions #####################
129 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
138 _debug
"First detect the root zone"
139 if ! _get_root
"$fulldomain"; then
140 _err
"invalid domain"
144 _debug _sub_domain
"$_sub_domain"
145 _debug _domain
"$_domain"
147 _info
"Adding record"
148 if _ovh_rest POST
"domain/zone/$_domain/record" "{\"fieldType\":\"TXT\",\"subDomain\":\"$_sub_domain\",\"target\":\"$txtvalue\",\"ttl\":60}"; then
149 if _contains
"$response" "$txtvalue"; then
150 _ovh_rest POST
"domain/zone/$_domain/refresh"
151 _debug
"Refresh:$response"
156 _err
"Add txt record error."
170 _debug
"First detect the root zone"
171 if ! _get_root
"$fulldomain"; then
172 _err
"invalid domain"
176 _debug _sub_domain
"$_sub_domain"
177 _debug _domain
"$_domain"
178 _debug
"Getting txt records"
179 if ! _ovh_rest GET
"domain/zone/$_domain/record?fieldType=TXT&subDomain=$_sub_domain"; then
183 for rid
in $
(echo "$response" |
tr '[,]' ' '); do
185 if ! _ovh_rest GET
"domain/zone/$_domain/record/$rid"; then
188 if _contains
"$response" "\"target\":\"$txtvalue\""; then
189 _debug
"Found txt id:$rid"
190 if ! _ovh_rest DELETE
"domain/zone/$_domain/record/$rid"; then
200 #################### Private functions below ##################################
202 _ovh_authentication
() {
204 _H1
="X-Ovh-Application: $OVH_AK"
205 _H2
="Content-type: application/json"
209 _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'"}'
211 response
="$(_post "$_ovhdata" "$OVH_API/auth
/credential
")"
212 _debug3 response
"$response"
213 validationUrl
="$(echo "$response" | _egrep_o "validationUrl
\":\"[^
\"]*\"" | _egrep_o "http.
*\"" | tr -d '"')"
214 if [ -z "$validationUrl" ]; then
215 _err "Unable to get validationUrl"
218 _debug validationUrl "$validationUrl"
220 consumerKey="$(echo "$response" | _egrep_o "consumerKey\":\"[^\"]*\"" | cut -d : -f 2 | tr -d '"')"
221 if [ -z "$consumerKey" ]; then
222 _err
"Unable to get consumerKey"
225 _secure_debug consumerKey
"$consumerKey"
227 OVH_CK
="$consumerKey"
228 _saveaccountconf OVH_CK
"$OVH_CK"
230 _info
"Please open this link to do authentication: $(__green "$validationUrl")"
232 _info
"Here is a guide for you: $(__green "$wiki")"
233 _info
"Please retry after the authentication is done."
237 #_acme-challenge.www.domain.com
239 # _sub_domain=_acme-challenge.www
246 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
252 if ! _ovh_rest GET
"domain/zone/$h"; then
256 if ! _contains
"$response" "This service does not exist" >/dev
/null
&& ! _contains
"$response" "NOT_GRANTED_CALL" >/dev
/null
; then
257 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
273 _get
"$OVH_API/auth/time" "" 30
282 _ovh_url
="$OVH_API/$ep"
283 _debug2 _ovh_url
"$_ovh_url"
284 _ovh_t
="$(_ovh_timestamp)"
285 _debug2 _ovh_t
"$_ovh_t"
286 _ovh_p
="$OVH_AS+$OVH_CK+$m+$_ovh_url+$data+$_ovh_t"
287 _secure_debug _ovh_p
"$_ovh_p"
288 _ovh_hex
="$(printf "%s
" "$_ovh_p" | _digest sha1 hex)"
289 _debug2 _ovh_hex
"$_ovh_hex"
291 export _H1
="X-Ovh-Application: $OVH_AK"
292 export _H2
="X-Ovh-Signature: \$1\$$_ovh_hex"
294 export _H3
="X-Ovh-Timestamp: $_ovh_t"
295 export _H4
="X-Ovh-Consumer: $OVH_CK"
296 export _H5
="Content-Type: application/json;charset=utf-8"
297 if [ "$data" ] ||
[ "$m" = "POST" ] ||
[ "$m" = "PUT" ] ||
[ "$m" = "DELETE" ]; then
299 response
="$(_post "$data" "$_ovh_url" "" "$m")"
301 response
="$(_get "$_ovh_url")"
304 if [ "$?" != "0" ] || _contains
"$response" "INVALID_CREDENTIAL"; then
305 _err
"error $response"
308 _debug2 response
"$response"