4 #PointHQ_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
6 #PointHQ_Email="xxxx@sss.com"
8 PointHQ_Api
="https://api.pointhq.com"
10 ######## Public functions #####################
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 PointHQ_Key
="${PointHQ_Key:-$(_readaccountconf_mutable PointHQ_Key)}"
18 PointHQ_Email
="${PointHQ_Email:-$(_readaccountconf_mutable PointHQ_Email)}"
19 if [ -z "$PointHQ_Key" ] ||
[ -z "$PointHQ_Email" ]; then
22 _err
"You didn't specify a PointHQ API key and email yet."
23 _err
"Please create the key and try again."
27 if ! _contains
"$PointHQ_Email" "@"; then
28 _err
"It seems that the PointHQ_Email=$PointHQ_Email is not a valid email address."
29 _err
"Please check and retry."
33 #save the api key and email to the account conf file.
34 _saveaccountconf_mutable PointHQ_Key
"$PointHQ_Key"
35 _saveaccountconf_mutable PointHQ_Email
"$PointHQ_Email"
37 _debug
"First detect the root zone"
38 if ! _get_root
"$fulldomain"; then
42 _debug _sub_domain
"$_sub_domain"
43 _debug _domain
"$_domain"
46 if _pointhq_rest POST
"zones/$_domain/records" "{\"zone_record\": {\"name\":\"$_sub_domain\",\"record_type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":3600}}"; then
47 if printf -- "%s" "$response" |
grep "$fulldomain" >/dev
/null
; then
51 _err
"Add txt record error."
55 _err
"Add txt record error."
64 PointHQ_Key
="${PointHQ_Key:-$(_readaccountconf_mutable PointHQ_Key)}"
65 PointHQ_Email
="${PointHQ_Email:-$(_readaccountconf_mutable PointHQ_Email)}"
66 if [ -z "$PointHQ_Key" ] ||
[ -z "$PointHQ_Email" ]; then
69 _err
"You didn't specify a PointHQ API key and email yet."
70 _err
"Please create the key and try again."
74 _debug
"First detect the root zone"
75 if ! _get_root
"$fulldomain"; then
79 _debug _sub_domain
"$_sub_domain"
80 _debug _domain
"$_domain"
82 _debug
"Getting txt records"
83 _pointhq_rest GET
"zones/${_domain}/records?record_type=TXT&name=$_sub_domain"
85 if ! printf "%s" "$response" |
grep "^\[" >/dev
/null
; then
90 if [ "$response" = "[]" ]; then
91 _info
"No records to remove."
93 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[^,]*" | cut
-d : -f 2 |
tr -d \" |
head -n 1)
94 _debug
"record_id" "$record_id"
95 if [ -z "$record_id" ]; then
96 _err
"Can not get record id to remove."
99 if ! _pointhq_rest DELETE
"zones/$_domain/records/$record_id"; then
100 _err
"Delete record error."
103 _contains
"$response" '"status":"OK"'
107 #################### Private functions below ##################################
108 #_acme-challenge.www.domain.com
110 # _sub_domain=_acme-challenge.www
117 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
124 if ! _pointhq_rest GET
"zones"; then
128 if _contains
"$response" "\"name\":\"$h\"" >/dev
/null
; then
129 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
145 _pointhq_auth
=$
(printf "%s:%s" "$PointHQ_Email" "$PointHQ_Key" | _base64
)
147 export _H1
="Authorization: Basic $_pointhq_auth"
148 export _H2
="Content-Type: application/json"
149 export _H3
="Accept: application/json"
151 if [ "$m" != "GET" ]; then
153 response
="$(_post "$data" "$PointHQ_Api/$ep" "" "$m")"
155 response
="$(_get "$PointHQ_Api/$ep")"
158 if [ "$?" != "0" ]; then
162 _debug2 response
"$response"