2 # one.com ui wrapper for acme.sh
5 # export ONECOM_User="username"
6 # export ONECOM_Password="password"
12 if ! _dns_one_login
; then
17 _debug
"detect the root domain"
18 if ! _get_root
"$fulldomain"; then
19 _err
"root domain not found"
23 subdomain
="${_sub_domain}"
26 _debug subdomain
"$subdomain"
27 _debug maindomain
"$maindomain"
29 #Check if the TXT exists
30 _dns_one_getrecord
"TXT" "$subdomain" "$txtvalue"
32 _info
"$(__green "Txt record with the same value found. Skip adding.
")"
36 _dns_one_addrecord
"TXT" "$subdomain" "$txtvalue"
38 _err
"Add TXT record error."
41 _info
"$(__green "Added
, OK
($id)")"
50 if ! _dns_one_login
; then
55 _debug
"detect the root domain"
56 if ! _get_root
"$fulldomain"; then
57 _err
"root domain not found"
61 subdomain
="${_sub_domain}"
64 _debug subdomain
"$subdomain"
65 _debug maindomain
"$maindomain"
67 #Check if the TXT exists
68 _dns_one_getrecord
"TXT" "$subdomain" "$txtvalue"
70 _err
"Txt record not found."
75 if _dns_one_delrecord
"$id"; then
76 _info
"$(__green Removed, OK)"
79 _err
"Removing txt record error."
84 #_acme-challenge.www.domain.com
86 # _sub_domain=_acme-challenge.www
93 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
100 response
="$(_get "https
://www.one.com
/admin
/api
/domains
/$h/dns
/custom_records
")"
102 if ! _contains
"$response" "CRMRST_000302"; then
103 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
110 _err
"Unable to parse this domain"
117 ONECOM_User
="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}"
118 ONECOM_Password
="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}"
119 if [ -z "$ONECOM_User" ] ||
[ -z "$ONECOM_Password" ]; then
122 _err
"You didn't specify a one.com username and password yet."
123 _err
"Please create the key and try again."
127 #save the api key and email to the account conf file.
128 _saveaccountconf_mutable ONECOM_User
"$ONECOM_User"
129 _saveaccountconf_mutable ONECOM_Password
"$ONECOM_Password"
131 # Login with user and password
132 postdata
="loginDomain=true"
133 postdata
="$postdata&displayUsername=$ONECOM_User"
134 postdata
="$postdata&username=$ONECOM_User"
135 postdata
="$postdata&targetDomain="
136 postdata
="$postdata&password1=$ONECOM_Password"
137 postdata
="$postdata&loginTarget="
138 #_debug postdata "$postdata"
140 response
="$(_post "$postdata" "https
://www.one.com
/admin
/login.
do" "" "POST
" "application
/x-www-form-urlencoded
")"
141 #_debug response "$response"
144 JSESSIONID
="$(grep "OneSIDCrmAdmin
" "$HTTP_HEADER" | grep "^
[Ss
]et-
[Cc
]ookie
:" | _head_n 1 | _egrep_o 'OneSIDCrmAdmin=[^;]*;' | tr -d ';')"
145 _debug jsessionid
"$JSESSIONID"
147 if [ -z "$JSESSIONID" ]; then
148 _err
"error sessionid cookie not found"
152 export _H1
="Cookie: ${JSESSIONID}"
157 _dns_one_getrecord
() {
161 if [ -z "$type" ]; then
164 if [ -z "$name" ]; then
165 _err
"Record name is empty."
169 response
="$(_get "https
://www.one.com
/admin
/api
/domains
/$maindomain/dns
/custom_records
")"
170 response
="$(echo "$response" | _normalizeJson)"
171 _debug response
"$response"
173 if [ -z "${value}" ]; then
174 id
=$
(printf -- "%s" "$response" |
sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"${name}\",\"type\":\"${type}\",\"content\":\"[^\"]*\",\"priority\":0,\"ttl\":600}.*/\1/p")
175 response
=$
(printf -- "%s" "$response" |
sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"[^\"]*\",\"attributes\":{\"prefix\":\"${name}\",\"type\":\"${type}\",\"content\":\"\([^\"]*\)\",\"priority\":0,\"ttl\":600}.*/\1/p")
177 id
=$
(printf -- "%s" "$response" |
sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"${name}\",\"type\":\"${type}\",\"content\":\"${value}\",\"priority\":0,\"ttl\":600}.*/\1/p")
179 if [ -z "$id" ]; then
185 _dns_one_addrecord
() {
189 if [ -z "$type" ]; then
192 if [ -z "$name" ]; then
193 _err
"Record name is empty."
197 postdata
="{\"type\":\"dns_custom_records\",\"attributes\":{\"priority\":0,\"ttl\":600,\"type\":\"${type}\",\"prefix\":\"${name}\",\"content\":\"${value}\"}}"
198 _debug postdata
"$postdata"
199 response
="$(_post "$postdata" "https
://www.one.com
/admin
/api
/domains
/$maindomain/dns
/custom_records
" "" "POST
" "application
/json
")"
200 response
="$(echo "$response" | _normalizeJson)"
201 _debug response
"$response"
203 id
=$
(echo "$response" |
sed -n "s/{\"result\":{\"data\":{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$subdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}}},\"metadata\":null}/\1/p")
205 if [ -z "$id" ]; then
212 _dns_one_delrecord
() {
214 if [ -z "$id" ]; then
218 response
="$(_post "" "https
://www.one.com
/admin
/api
/domains
/$maindomain/dns
/custom_records
/$id" "" "DELETE
" "application
/json
")"
219 response
="$(echo "$response" | _normalizeJson)"
220 _debug response
"$response"
222 if [ "$response" = '{"result":null,"metadata":null}' ]; then