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"
81 ######## Public functions #####################
83 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
88 if [ -z "$OVH_AK" ] ||
[ -z "$OVH_AS" ]; then
91 _err
"You don't specify OVH application key and application secret yet."
92 _err
"Please create you key and try again."
96 #save the api key and email to the account conf file.
97 _saveaccountconf OVH_AK
"$OVH_AK"
98 _saveaccountconf OVH_AS
"$OVH_AS"
100 if [ -z "$OVH_END_POINT" ]; then
101 OVH_END_POINT
="ovh-eu"
103 _info
"Using OVH endpoint: $OVH_END_POINT"
104 if [ "$OVH_END_POINT" != "ovh-eu" ]; then
105 _saveaccountconf OVH_END_POINT
"$OVH_END_POINT"
108 OVH_API
="$(_ovh_get_api $OVH_END_POINT)"
109 _debug OVH_API
"$OVH_API"
111 if [ -z "$OVH_CK" ]; then
112 _info
"OVH consumer key is empty, Let's get one:"
113 if ! _ovh_authentication
; then
114 _err
"Can not get consumer key."
116 #return and wait for retry.
120 _info
"Checking authentication"
122 response
="$(_ovh_rest GET "domain
/")"
123 if _contains
"$response" "INVALID_CREDENTIAL"; then
124 _err
"The consumer key is invalid: $OVH_CK"
125 _err
"Please retry to create a new one."
126 _clearaccountconf OVH_CK
129 _info
"Consumer key is ok."
131 _debug
"First detect the root zone"
132 if ! _get_root
"$fulldomain"; then
133 _err
"invalid domain"
137 _debug _sub_domain
"$_sub_domain"
138 _debug _domain
"$_domain"
140 _debug
"Getting txt records"
141 _ovh_rest GET
"domain/zone/$_domain/record?fieldType=TXT&subDomain=$_sub_domain"
143 if _contains
"$response" '\[\]' || _contains
"$response" "This service does not exist"; then
144 _info
"Adding record"
145 if _ovh_rest POST
"domain/zone/$_domain/record" "{\"fieldType\":\"TXT\",\"subDomain\":\"$_sub_domain\",\"target\":\"$txtvalue\",\"ttl\":60}"; then
146 if _contains
"$response" "$txtvalue"; then
147 _ovh_rest POST
"domain/zone/$_domain/refresh"
148 _debug
"Refresh:$response"
149 _info
"Added, sleeping 10 seconds"
154 _err
"Add txt record error."
156 _info
"Updating record"
157 record_id
=$
(printf "%s" "$response" |
tr -d "[]" | cut
-d , -f 1)
158 if [ -z "$record_id" ]; then
159 _err
"Can not get record id."
162 _debug
"record_id" "$record_id"
164 if _ovh_rest PUT
"domain/zone/$_domain/record/$record_id" "{\"target\":\"$txtvalue\",\"subDomain\":\"$_sub_domain\",\"ttl\":60}"; then
165 if _contains
"$response" "null"; then
166 _ovh_rest POST
"domain/zone/$_domain/refresh"
167 _debug
"Refresh:$response"
168 _info
"Updated, sleeping 10 seconds"
185 #################### Private functions below ##################################
187 _ovh_authentication
() {
189 _H1
="X-Ovh-Application: $OVH_AK"
190 _H2
="Content-type: application/json"
194 _ovhdata
='{"accessRules": [{"method": "GET","path": "/*"},{"method": "POST","path": "/*"},{"method": "PUT","path": "/*"},{"method": "DELETE","path": "/*"}],"redirection":"'$ovh_success'"}'
196 response
="$(_post "$_ovhdata" "$OVH_API/auth
/credential
")"
197 _debug3 response
"$response"
198 validationUrl
="$(echo "$response" | _egrep_o "validationUrl
\":\"[^
\"]*\"" | _egrep_o "http.
*\"" | tr -d '"')"
199 if [ -z "$validationUrl" ]; then
200 _err "Unable to get validationUrl"
203 _debug validationUrl "$validationUrl"
205 consumerKey="$(echo "$response" | _egrep_o "consumerKey\":\"[^\"]*\"" | cut -d : -f 2 | tr -d '"')"
206 if [ -z "$consumerKey" ]; then
207 _err
"Unable to get consumerKey"
210 _secure_debug consumerKey
"$consumerKey"
212 OVH_CK
="$consumerKey"
213 _saveaccountconf OVH_CK
"$OVH_CK"
215 _info
"Please open this link to do authentication: $(__green "$validationUrl")"
217 _info
"Here is a guide for you: $(__green "$wiki")"
218 _info
"Please retry after the authentication is done."
222 #_acme-challenge.www.domain.com
224 # _sub_domain=_acme-challenge.www
231 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
237 if ! _ovh_rest GET
"domain/zone/$h"; then
241 if ! _contains
"$response" "This service does not exist" >/dev
/null
; then
242 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
258 _get
"$OVH_API/auth/time" "" 30
267 _ovh_url
="$OVH_API/$ep"
268 _debug2 _ovh_url
"$_ovh_url"
269 _ovh_t
="$(_ovh_timestamp)"
270 _debug2 _ovh_t
"$_ovh_t"
271 _ovh_p
="$OVH_AS+$OVH_CK+$m+$_ovh_url+$data+$_ovh_t"
272 _secure_debug _ovh_p
"$_ovh_p"
273 _ovh_hex
="$(printf "%s
" "$_ovh_p" | _digest sha1 hex)"
274 _debug2 _ovh_hex
"$_ovh_hex"
276 export _H1
="X-Ovh-Application: $OVH_AK"
277 export _H2
="X-Ovh-Signature: \$1\$$_ovh_hex"
279 export _H3
="X-Ovh-Timestamp: $_ovh_t"
280 export _H4
="X-Ovh-Consumer: $OVH_CK"
281 export _H5
="Content-Type: application/json;charset=utf-8"
282 if [ "$data" ] ||
[ "$m" = "POST" ] ||
[ "$m" = "PUT" ]; then
284 response
="$(_post "$data" "$_ovh_url" "" "$m")"
286 response
="$(_get "$_ovh_url")"
289 if [ "$?" != "0" ]; then
293 _debug2 response
"$response"