3 # bug reports to stepan@plyask.in
6 # export VEESP_User="username"
7 # export VEESP_Password="password"
9 VEESP_Api
="https://secure.veesp.com/api"
11 ######## Public functions #####################
13 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18 VEESP_Password
="${VEESP_Password:-$(_readaccountconf_mutable VEESP_Password)}"
19 VEESP_User
="${VEESP_User:-$(_readaccountconf_mutable VEESP_User)}"
20 VEESP_auth
=$
(printf "%s" "$VEESP_User:$VEESP_Password" | _base64
)
22 if [ -z "$VEESP_Password" ] ||
[ -z "$VEESP_User" ]; then
25 _err
"You don't specify veesp api key and email yet."
26 _err
"Please create you key and try again."
30 #save the api key and email to the account conf file.
31 _saveaccountconf_mutable VEESP_Password
"$VEESP_Password"
32 _saveaccountconf_mutable VEESP_User
"$VEESP_User"
34 _debug
"First detect the root zone"
35 if ! _get_root
"$fulldomain"; then
39 _debug _domain_id
"$_domain_id"
40 _debug _sub_domain
"$_sub_domain"
41 _debug _domain
"$_domain"
44 if VEESP_rest POST
"service/$_service_id/dns/$_domain_id/records" "{\"name\":\"$fulldomain\",\"ttl\":1,\"priority\":0,\"type\":\"TXT\",\"content\":\"$txtvalue\"}"; then
45 if _contains
"$response" "\"success\":true"; then
47 #todo: check if the record takes effect
50 _err
"Add txt record error."
56 # Usage: fulldomain txtvalue
57 # Used to remove the txt record after validation
62 VEESP_Password
="${VEESP_Password:-$(_readaccountconf_mutable VEESP_Password)}"
63 VEESP_User
="${VEESP_User:-$(_readaccountconf_mutable VEESP_User)}"
64 VEESP_auth
=$
(printf "%s" "$VEESP_User:$VEESP_Password" | _base64
)
66 _debug
"First detect the root zone"
67 if ! _get_root
"$fulldomain"; then
71 _debug _domain_id
"$_domain_id"
72 _debug _sub_domain
"$_sub_domain"
73 _debug _domain
"$_domain"
75 _debug
"Getting txt records"
76 VEESP_rest GET
"service/$_service_id/dns/$_domain_id"
78 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"type\":\"TXT\",\"content\":\".\"$txtvalue.\"\"" |
wc -l |
tr -d " ")
80 if [ "$count" = "0" ]; then
81 _info
"Don't need to remove."
83 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"{\"id\":[^}]*\"type\":\"TXT\",\"content\":\".\"$txtvalue.\"\"" | cut
-d\" -f4)
84 _debug
"record_id" "$record_id"
85 if [ -z "$record_id" ]; then
86 _err
"Can not get record id to remove."
89 if ! VEESP_rest DELETE
"service/$_service_id/dns/$_domain_id/records/$record_id"; then
90 _err
"Delete record error."
93 _contains
"$response" "\"success\":true"
97 #################### Private functions below ##################################
98 #_acme-challenge.www.domain.com
100 # _sub_domain=_acme-challenge.www
102 # _domain_id=sdjkglgdfewsdfg
107 if ! VEESP_rest GET
"dns"; then
111 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
118 if _contains
"$response" "\"name\":\"$h\""; then
119 _domain_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"domain_id\":[^,]*,\"name\":\"$h\"" | cut
-d : -f 2 | cut
-d , -f 1 | cut
-d '"' -f 2)
120 _debug _domain_id
"$_domain_id"
121 _service_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"name\":\"$h\",\"service_id\":[^}]*" | cut
-d : -f 3 | cut
-d '"' -f 2)
122 _debug _service_id
"$_service_id"
123 if [ "$_domain_id" ]; then
124 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
142 export _H1
="Accept: application/json"
143 export _H2
="Authorization: Basic $VEESP_auth"
144 if [ "$m" != "GET" ]; then
146 export _H3
="Content-Type: application/json"
147 response
="$(_post "$data" "$VEESP_Api/$ep" "" "$m")"
149 response
="$(_get "$VEESP_Api/$ep")"
152 if [ "$?" != "0" ]; then
156 _debug2 response
"$response"