]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_regru.sh
Merge pull request #3734 from acmesh-official/dev
[mirror_acme.sh.git] / dnsapi / dns_regru.sh
CommitLineData
e05ef230
A
1#!/usr/bin/env sh
2
3#
6151debe 4# REGRU_API_Username="test"
e05ef230 5#
6151debe
A
6# REGRU_API_Password="test"
7#
e05ef230 8
6151debe 9REGRU_API_URL="https://api.reg.ru/api/regru2"
e05ef230
A
10
11######## Public functions #####################
12
6151debe 13dns_regru_add() {
e05ef230
A
14 fulldomain=$1
15 txtvalue=$2
16
6151debe
A
17 REGRU_API_Username="${REGRU_API_Username:-$(_readaccountconf_mutable REGRU_API_Username)}"
18 REGRU_API_Password="${REGRU_API_Password:-$(_readaccountconf_mutable REGRU_API_Password)}"
19 if [ -z "$REGRU_API_Username" ] || [ -z "$REGRU_API_Password" ]; then
20 REGRU_API_Username=""
21 REGRU_API_Password=""
22 _err "You don't specify regru password or username."
e05ef230
A
23 return 1
24 fi
25
6151debe
A
26 _saveaccountconf_mutable REGRU_API_Username "$REGRU_API_Username"
27 _saveaccountconf_mutable REGRU_API_Password "$REGRU_API_Password"
e05ef230 28
5d0dde5c 29 _debug "First detect the root zone"
30 if ! _get_root "$fulldomain"; then
31 _err "invalid domain"
32 return 1
33 fi
34 _debug _domain "$_domain"
35
956114fc
A
36 _subdomain=$(echo "$fulldomain" | sed -r "s/.$_domain//")
37 _debug _subdomain "$_subdomain"
38
6151debe 39 _info "Adding TXT record to ${fulldomain}"
956114fc 40 _regru_rest POST "zone/add_txt" "input_data={%22username%22:%22${REGRU_API_Username}%22,%22password%22:%22${REGRU_API_Password}%22,%22domains%22:[{%22dname%22:%22${_domain}%22}],%22subdomain%22:%22${_subdomain}%22,%22text%22:%22${txtvalue}%22,%22output_content_type%22:%22plain%22}&input_format=json"
e05ef230 41
5d0dde5c 42 if ! _contains "${response}" 'error'; then
6151debe 43 return 0
e05ef230 44 fi
6151debe
A
45 _err "Could not create resource record, check logs"
46 _err "${response}"
e05ef230 47 return 1
e05ef230
A
48}
49
6151debe 50dns_regru_rm() {
e05ef230
A
51 fulldomain=$1
52 txtvalue=$2
6151debe
A
53
54 REGRU_API_Username="${REGRU_API_Username:-$(_readaccountconf_mutable REGRU_API_Username)}"
55 REGRU_API_Password="${REGRU_API_Password:-$(_readaccountconf_mutable REGRU_API_Password)}"
56 if [ -z "$REGRU_API_Username" ] || [ -z "$REGRU_API_Password" ]; then
57 REGRU_API_Username=""
58 REGRU_API_Password=""
59 _err "You don't specify regru password or username."
e05ef230
A
60 return 1
61 fi
e05ef230 62
5d0dde5c 63 _debug "First detect the root zone"
64 if ! _get_root "$fulldomain"; then
65 _err "invalid domain"
66 return 1
67 fi
68 _debug _domain "$_domain"
69
956114fc
A
70 _subdomain=$(echo "$fulldomain" | sed -r "s/.$_domain//")
71 _debug _subdomain "$_subdomain"
72
6151debe 73 _info "Deleting resource record $fulldomain"
956114fc 74 _regru_rest POST "zone/remove_record" "input_data={%22username%22:%22${REGRU_API_Username}%22,%22password%22:%22${REGRU_API_Password}%22,%22domains%22:[{%22dname%22:%22${_domain}%22}],%22subdomain%22:%22${_subdomain}%22,%22content%22:%22${txtvalue}%22,%22record_type%22:%22TXT%22,%22output_content_type%22:%22plain%22}&input_format=json"
e05ef230 75
5d0dde5c 76 if ! _contains "${response}" 'error'; then
6151debe 77 return 0
e05ef230 78 fi
6151debe
A
79 _err "Could not delete resource record, check logs"
80 _err "${response}"
e05ef230
A
81 return 1
82}
5d0dde5c 83
84#################### Private functions below ##################################
85#_acme-challenge.www.domain.com
86#returns
87# _domain=domain.com
88_get_root() {
89 domain=$1
90
91 _regru_rest POST "service/get_list" "username=${REGRU_API_Username}&password=${REGRU_API_Password}&output_format=xml&servtype=domain"
92 domains_list=$(echo "${response}" | grep dname | sed -r "s/.*dname=\"([^\"]+)\".*/\\1/g")
93
f00e2890 94 for ITEM in ${domains_list}; do
5d0dde5c 95 case "${domain}" in
19c43451 96 *${ITEM}*)
97 _domain=${ITEM}
98 _debug _domain "${_domain}"
99 return 0
100 ;;
5d0dde5c 101 esac
102 done
103
104 return 1
105}
106
107#returns
108# response
109_regru_rest() {
110 m=$1
111 ep="$2"
112 data="$3"
113 _debug "$ep"
114
115 export _H1="Content-Type: application/x-www-form-urlencoded"
116
117 if [ "$m" != "GET" ]; then
118 _debug data "$data"
119 response="$(_post "$data" "$REGRU_API_URL/$ep" "" "$m")"
120 else
c16757b0 121 response="$(_get "$REGRU_API_URL/$ep?$data")"
5d0dde5c 122 fi
123
c16757b0 124 _debug response "${response}"
5d0dde5c 125 return 0
44b9a8e7 126}