2019-02-17 23:20:17 +01:00
#!/usr/bin/env sh
2023-11-18 17:57:12 +01:00
# shellcheck disable=SC2034
dns_one_info = ' one.com
Site: one.com
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_one
Options:
ONECOM_User Username
ONECOM_Password Password
Issues: github.com/acmesh-official/acme.sh/issues/2103
'
2021-04-14 16:18:01 +02:00
2019-02-17 23:20:17 +01:00
dns_one_add( ) {
2019-05-20 17:40:43 +02:00
fulldomain = $1
2019-02-17 23:20:17 +01:00
txtvalue = $2
2019-05-31 08:26:48 +02:00
2019-05-24 09:44:13 +02:00
if ! _dns_one_login; then
_err "login failed"
return 1
fi
_debug "detect the root domain"
2019-05-20 17:40:43 +02:00
if ! _get_root " $fulldomain " ; then
2019-05-24 09:44:13 +02:00
_err "root domain not found"
2019-05-20 17:40:43 +02:00
return 1
fi
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
subdomain = " ${ _sub_domain } "
maindomain = ${ _domain }
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
_debug subdomain " $subdomain "
_debug maindomain " $maindomain "
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
#Check if the TXT exists
_dns_one_getrecord "TXT" " $subdomain " " $txtvalue "
2020-04-09 12:17:08 +02:00
if [ -n " $id " ] ; then
2020-04-07 19:25:39 +02:00
_info " $( __green "Txt record with the same value found. Skip adding." ) "
return 0
fi
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
_dns_one_addrecord "TXT" " $subdomain " " $txtvalue "
2019-02-17 23:20:17 +01:00
if [ -z " $id " ] ; then
2020-04-09 12:17:08 +02:00
_err "Add TXT record error."
2019-02-17 23:20:17 +01:00
return 1
else
2020-04-07 19:25:39 +02:00
_info " $( __green " Added, OK ( $id ) " ) "
2019-02-17 23:20:17 +01:00
return 0
fi
}
dns_one_rm( ) {
2019-05-20 17:40:43 +02:00
fulldomain = $1
2019-02-17 23:20:17 +01:00
txtvalue = $2
2019-05-31 08:26:48 +02:00
2019-05-24 09:44:13 +02:00
if ! _dns_one_login; then
_err "login failed"
return 1
fi
_debug "detect the root domain"
2019-05-20 17:40:43 +02:00
if ! _get_root " $fulldomain " ; then
2019-05-24 09:44:13 +02:00
_err "root domain not found"
2019-05-20 17:40:43 +02:00
return 1
fi
2019-05-31 08:26:48 +02:00
2020-04-07 19:25:39 +02:00
subdomain = " ${ _sub_domain } "
maindomain = ${ _domain }
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
_debug subdomain " $subdomain "
_debug maindomain " $maindomain "
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
#Check if the TXT exists
_dns_one_getrecord "TXT" " $subdomain " " $txtvalue "
2019-02-17 23:20:17 +01:00
if [ -z " $id " ] ; then
_err "Txt record not found."
return 1
fi
2020-04-09 12:17:08 +02:00
2019-02-17 23:20:17 +01:00
# delete entry
2020-04-07 19:25:39 +02:00
if _dns_one_delrecord " $id " ; then
2020-04-09 12:17:08 +02:00
_info " $( __green Removed, OK) "
return 0
2019-02-20 11:54:48 +01:00
else
2020-04-09 12:17:08 +02:00
_err "Removing txt record error."
return 1
2019-02-17 23:20:17 +01:00
fi
2019-02-20 09:44:25 +01:00
}
2019-05-20 17:40:43 +02:00
#_acme-challenge.www.domain.com
#returns
# _sub_domain=_acme-challenge.www
# _domain=domain.com
_get_root( ) {
2019-05-31 08:55:21 +02:00
domain = " $1 "
2021-04-14 16:18:01 +02:00
i = 1
2019-05-20 17:40:43 +02:00
p = 1
while true; do
2024-10-13 17:41:22 +02:00
h = $( printf "%s" " $domain " | cut -d . -f " $i " -100)
2019-05-31 08:55:21 +02:00
2019-05-20 17:40:43 +02:00
if [ -z " $h " ] ; then
#not valid
return 1
fi
2019-05-31 08:55:21 +02:00
2019-05-24 09:44:13 +02:00
response = " $( _get " https://www.one.com/admin/api/domains/ $h /dns/custom_records " ) "
2019-05-31 08:55:21 +02:00
2019-05-25 17:35:40 +02:00
if ! _contains " $response " "CRMRST_000302" ; then
2024-10-13 17:41:22 +02:00
_sub_domain = $( printf "%s" " $domain " | cut -d . -f 1-" $p " )
2019-05-20 17:40:43 +02:00
_domain = " $h "
return 0
fi
p = $i
i = $( _math " $i " + 1)
done
_err "Unable to parse this domain"
return 1
}
2019-05-24 09:44:13 +02:00
_dns_one_login( ) {
# get credentials
ONECOM_User = " ${ ONECOM_User :- $( _readaccountconf_mutable ONECOM_User) } "
ONECOM_Password = " ${ ONECOM_Password :- $( _readaccountconf_mutable ONECOM_Password) } "
if [ -z " $ONECOM_User " ] || [ -z " $ONECOM_Password " ] ; then
ONECOM_User = ""
ONECOM_Password = ""
_err "You didn't specify a one.com username and password yet."
_err "Please create the key and try again."
return 1
fi
#save the api key and email to the account conf file.
_saveaccountconf_mutable ONECOM_User " $ONECOM_User "
_saveaccountconf_mutable ONECOM_Password " $ONECOM_Password "
# Login with user and password
postdata = "loginDomain=true"
postdata = " $postdata &displayUsername= $ONECOM_User "
postdata = " $postdata &username= $ONECOM_User "
postdata = " $postdata &targetDomain= "
postdata = " $postdata &password1= $ONECOM_Password "
postdata = " $postdata &loginTarget= "
#_debug postdata "$postdata"
2019-05-31 08:55:21 +02:00
2019-05-24 09:44:13 +02:00
response = " $( _post " $postdata " "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded" ) "
#_debug response "$response"
2019-05-31 08:55:21 +02:00
2019-05-24 09:44:13 +02:00
# Get SessionID
JSESSIONID = " $( grep "OneSIDCrmAdmin" " $HTTP_HEADER " | grep "^[Ss]et-[Cc]ookie:" | _head_n 1 | _egrep_o 'OneSIDCrmAdmin=[^;]*;' | tr -d ';' ) "
_debug jsessionid " $JSESSIONID "
2019-05-31 08:55:21 +02:00
2019-05-24 09:44:13 +02:00
if [ -z " $JSESSIONID " ] ; then
_err "error sessionid cookie not found"
return 1
fi
2019-05-31 08:55:21 +02:00
2019-05-24 09:44:13 +02:00
export _H1 = " Cookie: ${ JSESSIONID } "
2019-05-31 08:55:21 +02:00
2019-05-24 09:44:13 +02:00
return 0
2019-05-31 08:26:48 +02:00
}
2020-04-07 19:25:39 +02:00
_dns_one_getrecord( ) {
type = " $1 "
name = " $2 "
value = " $3 "
if [ -z " $type " ] ; then
2020-04-09 12:17:08 +02:00
type = "TXT"
2020-04-07 19:25:39 +02:00
fi
if [ -z " $name " ] ; then
2020-04-09 12:17:08 +02:00
_err "Record name is empty."
return 1
2020-04-07 19:25:39 +02:00
fi
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
response = " $( _get " https://www.one.com/admin/api/domains/ $maindomain /dns/custom_records " ) "
response = " $( echo " $response " | _normalizeJson) "
_debug response " $response "
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
if [ -z " ${ value } " ] ; then
id = $( printf -- "%s" " $response " | sed -n " s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\" ${ name } \",\"type\":\" ${ type } \",\"content\":\"[^\"]*\",\"priority\":0,\"ttl\":600}.*/\1/p " )
response = $( printf -- "%s" " $response " | sed -n " s/.*{\"type\":\"dns_custom_records\",\"id\":\"[^\"]*\",\"attributes\":{\"prefix\":\" ${ name } \",\"type\":\" ${ type } \",\"content\":\"\([^\"]*\)\",\"priority\":0,\"ttl\":600}.*/\1/p " )
else
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 " )
fi
if [ -z " $id " ] ; then
return 1
fi
return 0
}
_dns_one_addrecord( ) {
type = " $1 "
name = " $2 "
value = " $3 "
if [ -z " $type " ] ; then
2020-04-09 12:17:08 +02:00
type = "TXT"
2020-04-07 19:25:39 +02:00
fi
if [ -z " $name " ] ; then
2020-04-09 12:17:08 +02:00
_err "Record name is empty."
return 1
2020-04-07 19:25:39 +02:00
fi
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
postdata = " {\"type\":\"dns_custom_records\",\"attributes\":{\"priority\":0,\"ttl\":600,\"type\":\" ${ type } \",\"prefix\":\" ${ name } \",\"content\":\" ${ value } \"}} "
_debug postdata " $postdata "
response = " $( _post " $postdata " " https://www.one.com/admin/api/domains/ $maindomain /dns/custom_records " "" "POST" "application/json" ) "
response = " $( echo " $response " | _normalizeJson) "
_debug response " $response "
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 " )
if [ -z " $id " ] ; then
return 1
else
return 0
fi
}
_dns_one_delrecord( ) {
id = " $1 "
if [ -z " $id " ] ; then
2020-04-09 12:17:08 +02:00
return 1
2020-04-07 19:25:39 +02:00
fi
2020-04-09 12:17:08 +02:00
2020-04-07 19:25:39 +02:00
response = " $( _post "" " https://www.one.com/admin/api/domains/ $maindomain /dns/custom_records/ $id " "" "DELETE" "application/json" ) "
response = " $( echo " $response " | _normalizeJson) "
_debug response " $response "
if [ " $response " = '{"result":null,"metadata":null}' ] ; then
2020-04-09 12:17:08 +02:00
return 0
2020-04-07 19:25:39 +02:00
else
2020-04-09 12:17:08 +02:00
return 1
2020-04-07 19:25:39 +02:00
fi
}