5 #OVH_AK="sdfsdfsdfljlbjkljlkjsdfoiwje"
8 #OVH_AS="sdfsafsdfsdfdsfsdfsa"
11 #OVH_CK="sdfsdfsdfsdfsdfdsf"
18 OVH_EU
='https://eu.api.ovh.com/1.0'
21 OVH_CA
='https://ca.api.ovh.com/1.0'
24 KSF_EU
='https://eu.api.kimsufi.com/1.0'
27 KSF_CA
='https://ca.api.kimsufi.com/1.0'
30 SYS_EU
='https://eu.api.soyoustart.com/1.0'
33 SYS_CA
='https://ca.api.soyoustart.com/1.0'
36 RAV_CA
='https://api.runabove.com/1.0'
39 wiki
="https://github.com/Neilpang/acme.sh/wiki/How-to-use-OVH-domain-api"
41 ovh_success
="https://github.com/Neilpang/acme.sh/wiki/OVH-Success"
66 soyoustart-eu|soyoustarteu
)
70 soyoustart-ca|soyoustartca
)
74 runabove-ca|runaboveca
)
81 _err
"Unknown parameter : $1"
87 ######## Public functions #####################
89 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
94 if [ -z "$OVH_AK" ] ||
[ -z "$OVH_AS" ] ; then
95 _err
"You don't specify OVH application key and application secret yet."
96 _err
"Please create you key and try again."
100 #save the api key and email to the account conf file.
101 _saveaccountconf OVH_AK
"$OVH_AK"
102 _saveaccountconf OVH_AS
"$OVH_AS"
105 if [ -z "$OVH_END_POINT" ] ; then
106 OVH_END_POINT
="ovh-eu"
108 _info
"Using OVH endpoint: $OVH_END_POINT"
109 if [ "$OVH_END_POINT" != "ovh-eu" ] ; then
110 _saveaccountconf OVH_END_POINT
"$OVH_END_POINT"
113 OVH_API
="$(_ovh_get_api $OVH_END_POINT )"
114 _debug OVH_API
"$OVH_API"
116 if [ -z "$OVH_CK" ] ; then
117 _info
"OVH consumer key is empty, Let's get one:"
118 if ! _ovh_authentication
; then
119 _err
"Can not get consumer key."
121 #return and wait for retry.
126 _info
"Checking authentication"
128 response
="$(_ovh_rest GET "domain
/")"
129 if _contains
"$response" "INVALID_CREDENTIAL" ; then
130 _err
"The consumer key is invalid: $OVH_CK"
131 _err
"Please retry to create a new one."
132 _clearaccountconf OVH_CK
135 _info
"Consumer key is ok."
137 _debug
"First detect the root zone"
138 if ! _get_root
$fulldomain ; then
139 _err
"invalid domain"
142 _debug _domain_id
"$_domain_id"
143 _debug _sub_domain
"$_sub_domain"
144 _debug _domain
"$_domain"
146 _debug
"Getting txt records"
147 _ovh_rest GET
"domain/zone/$_domain/record?fieldType=TXT&subDomain=$_sub_domain"
149 if _contains
"$response" '\[\]' || _contains
"$response" "This service does not exist" ; then
150 _info
"Adding record"
151 if _ovh_rest POST
"domain/zone/$_domain/record" "{\"fieldType\":\"TXT\",\"subDomain\":\"$_sub_domain\",\"target\":\"$txtvalue\",\"ttl\":60}"; then
152 if _contains
"$response" "$txtvalue" ; then
153 _ovh_rest POST
"domain/zone/$_domain/refresh"
154 _debug
"Refresh:$response"
155 _info
"Added, sleeping 10 seconds"
160 _err
"Add txt record error."
162 _info
"Updating record"
163 record_id
=$
(printf "%s" "$response" |
tr -d "[]" | cut
-d , -f 1)
164 if [ -z "$record_id" ] ; then
165 _err
"Can not get record id."
168 _debug
"record_id" $record_id
170 if _ovh_rest PUT
"domain/zone/$_domain/record/$record_id" "{\"target\":\"$txtvalue\",\"subDomain\":\"$_sub_domain\",\"ttl\":60}" ; then
171 if _contains
"$response" "null" ; then
172 _ovh_rest POST
"domain/zone/$_domain/refresh"
173 _debug
"Refresh:$response"
174 _info
"Updated, sleeping 10 seconds"
193 #################### Private functions bellow ##################################
195 _ovh_authentication
() {
197 _H1
="X-Ovh-Application: $OVH_AK"
198 _H2
="Content-type: application/json"
202 _ovhdata
='{"accessRules": [{"method": "GET","path": "/*"},{"method": "POST","path": "/*"},{"method": "PUT","path": "/*"},{"method": "DELETE","path": "/*"}],"redirection":"'$ovh_success'"}'
204 response
="$(_post "$_ovhdata" "$OVH_API/auth
/credential
")"
205 _debug3 response
"$response"
206 validationUrl
="$(echo "$response" | _egrep_o "validationUrl
\":\"[^
\"]*\"" | _egrep_o "http.
*\"" | tr -d '"')"
207 if [ -z "$validationUrl" ] ; then
208 _err "Unable to get validationUrl"
211 _debug validationUrl "$validationUrl"
213 consumerKey="$(echo "$response" | _egrep_o "consumerKey\":\"[^\"]*\"" | cut -d : -f 2 | tr -d '"')"
214 if [ -z "$consumerKey" ] ; then
215 _err
"Unable to get consumerKey"
218 _debug consumerKey
"$consumerKey"
220 OVH_CK
="$consumerKey"
221 _saveaccountconf OVH_CK
"$OVH_CK"
223 _info
"Please open this link to do authentication: $(__green "$validationUrl" )"
225 _info
"Here is a guide for you: $(__green "$wiki" )"
226 _info
"Please retry after the authentication is done."
231 #_acme-challenge.www.domain.com
233 # _sub_domain=_acme-challenge.www
235 # _domain_id=sdjkglgdfewsdfg
241 h
=$
(printf $domain | cut
-d .
-f $i-100)
242 if [ -z "$h" ] ; then
247 if ! _ovh_rest GET
"domain/zone/$h" ; then
251 if ! _contains
"$response" "This service does not exist" >/dev
/null
; then
252 _sub_domain
=$
(printf $domain | cut
-d .
-f 1-$p)
268 _get
"$OVH_API/auth/time" "" 30
278 _ovh_url
="$OVH_API/$ep"
279 _debug2 _ovh_url
"$_ovh_url"
280 _ovh_t
="$(_ovh_timestamp)"
281 _debug2 _ovh_t
"$_ovh_t"
282 _ovh_p
="$OVH_AS+$OVH_CK+$m+$_ovh_url+$data+$_ovh_t"
283 _debug _ovh_p
"$_ovh_p"
284 _ovh_hex
="$(printf "%s
" "$_ovh_p" | _digest sha1 hex)"
285 _debug2 _ovh_hex
"$_ovh_hex"
288 _H1
="X-Ovh-Application: $OVH_AK"
289 _H2
="X-Ovh-Signature: \$1\$$_ovh_hex"
291 _H3
="X-Ovh-Timestamp: $_ovh_t"
292 _H4
="X-Ovh-Consumer: $OVH_CK"
293 _H5
="Content-Type: application/json;charset=utf-8"
294 if [ "$data" ] ||
[ "$m" = "POST" ] ||
[ "$m" = "PUT" ] ; then
296 response
="$(_post "$data" "$_ovh_url" "" $m)"
298 response
="$(_get "$_ovh_url")"
301 if [ "$?" != "0" ] ; then
305 _debug2 response
"$response"