123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #!/usr/bin/env sh
- dns_one_add() {
- mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev)
- mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev)
- txtvalue=$2
-
- 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
-
- _saveaccountconf_mutable ONECOM_USER "$ONECOM_USER"
- _saveaccountconf_mutable ONECOM_PASSWORD "$ONECOM_PASSWORD"
-
- postdata="loginDomain=true"
- postdata="$postdata&displayUsername=$ONECOM_USER"
- postdata="$postdata&username=$ONECOM_USER"
- postdata="$postdata&targetDomain=$mydomain"
- postdata="$postdata&password1=$ONECOM_PASSWORD"
- postdata="$postdata&loginTarget="
-
- response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")"
-
- JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')"
- _debug jsessionid "$JSESSIONID"
- export _H1="Cookie: ${JSESSIONID}"
-
- response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")"
- _debug response "$response"
- CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')"
- export _H2="Cookie: ${CSRF_G_TOKEN}"
-
- postdata="{\"type\":\"dns_custom_records\",\"attributes\":{\"priority\":0,\"ttl\":600,\"type\":\"TXT\",\"prefix\":\"$mysubdomain\",\"content\":\"$txtvalue\"}}"
- _debug postdata "$postdata"
- response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records" "" "POST" "application/json")"
- response="$(echo "$response" | _normalizeJson)"
- _debug response "$response"
- id=$(printf -- "%s" "$response" | sed -n "s/{\"result\":{\"data\":{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}}},\"metadata\":null}/\1/p")
- if [ -z "$id" ]; then
- _err "Add txt record error."
- return 1
- else
- _info "Added, OK ($id)"
- return 0
- fi
- }
- dns_one_rm() {
- mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev)
- mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev)
- txtvalue=$2
-
- 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
-
- postdata="loginDomain=true"
- postdata="$postdata&displayUsername=$ONECOM_USER"
- postdata="$postdata&username=$ONECOM_USER"
- postdata="$postdata&targetDomain=$mydomain"
- postdata="$postdata&password1=$ONECOM_PASSWORD"
- postdata="$postdata&loginTarget="
- response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")"
-
- JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')"
- _debug jsessionid "$JSESSIONID"
- export _H1="Cookie: ${JSESSIONID}"
-
- response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")"
- response="$(echo "$response" | _normalizeJson)"
- _debug response "$response"
- CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')"
- export _H2="Cookie: ${CSRF_G_TOKEN}"
- id=$(printf -- "%s" "$response" | sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}.*/\1/p")
- if [ -z "$id" ]; then
- _err "Txt record not found."
- return 1
- fi
-
- response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records/$id" "" "DELETE" "application/json")"
- response="$(echo "$response" | _normalizeJson)"
- _debug response "$response"
- if [ "$response" = '{"result":null,"metadata":null}' ]; then
- _info "Removed, OK"
- return 0
- else
- _err "Removing txt record error."
- return 1
- fi
- }
|