]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_kinghost.sh
Merge pull request #4542 from alexleigh/master
[mirror_acme.sh.git] / dnsapi / dns_kinghost.sh
CommitLineData
ae329385
FB
1#!/usr/bin/env sh
2
48bdfa23
FB
3############################################################
4# KingHost API support #
3c933158 5# https://api.kinghost.net/doc/ #
48bdfa23
FB
6# #
7# Author: Felipe Keller Braz <felipebraz@kinghost.com.br> #
8# Report Bugs here: https://github.com/kinghost/acme.sh #
9# #
10# Values to export: #
6787c81a 11# export KINGHOST_Username="email@provider.com" #
48bdfa23
FB
12# export KINGHOST_Password="xxxxxxxxxx" #
13############################################################
ae329385
FB
14
15KING_Api="https://api.kinghost.net/acme"
16
17# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18# Used to add txt record
19dns_kinghost_add() {
4d2a0697
FB
20 fulldomain=$1
21 txtvalue=$2
22
23 KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}"
24 KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}"
25 if [ -z "$KINGHOST_Username" ] || [ -z "$KINGHOST_Password" ]; then
26 KINGHOST_Username=""
27 KINGHOST_Password=""
28 _err "You don't specify KingHost api password and email yet."
29 _err "Please create you key and try again."
30 return 1
31 fi
32
33 #save the credentials to the account conf file.
f8fb0e67
FB
34 _saveaccountconf_mutable KINGHOST_Username "$KINGHOST_Username"
35 _saveaccountconf_mutable KINGHOST_Password "$KINGHOST_Password"
4d2a0697
FB
36
37 _debug "Getting txt records"
38 _kinghost_rest GET "dns" "name=$fulldomain&content=$txtvalue"
39
eca57bee 40 #This API call returns "status":"ok" if dns record does not exist
4d2a0697
FB
41 #We are creating a new txt record here, so we expect the "ok" status
42 if ! echo "$response" | grep '"status":"ok"' >/dev/null; then
43 _err "Error"
44 _err "$response"
45 return 1
46 fi
47
48 _kinghost_rest POST "dns" "name=$fulldomain&content=$txtvalue"
49 if ! echo "$response" | grep '"status":"ok"' >/dev/null; then
50 _err "Error"
51 _err "$response"
52 return 1
53 fi
54
86ef6e69 55 return 0
ae329385
FB
56}
57
58# Usage: fulldomain txtvalue
59# Used to remove the txt record after validation
60dns_kinghost_rm() {
4d2a0697
FB
61 fulldomain=$1
62 txtvalue=$2
63
64 KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}"
65 KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}"
86ef6e69 66 if [ -z "$KINGHOST_Password" ] || [ -z "$KINGHOST_Username" ]; then
4d2a0697
FB
67 KINGHOST_Password=""
68 KINGHOST_Username=""
69 _err "You don't specify KingHost api key and email yet."
70 _err "Please create you key and try again."
71 return 1
72 fi
73
4d2a0697
FB
74 _kinghost_rest DELETE "dns" "name=$fulldomain&content=$txtvalue"
75 if ! echo "$response" | grep '"status":"ok"' >/dev/null; then
76 _err "Error"
77 _err "$response"
78 return 1
79 fi
80
86ef6e69 81 return 0
ae329385
FB
82}
83
ae329385
FB
84#################### Private functions below ##################################
85_kinghost_rest() {
86 method=$1
87 uri="$2"
88 data="$3"
89 _debug "$uri"
90
6787c81a 91 export _H1="X-Auth-Email: $KINGHOST_Username"
ae329385
FB
92 export _H2="X-Auth-Key: $KINGHOST_Password"
93
94 if [ "$method" != "GET" ]; then
95 _debug data "$data"
96 response="$(_post "$data" "$KING_Api/$uri.json" "" "$method")"
97 else
98 response="$(_get "$KING_Api/$uri.json?$data")"
99 fi
100
101 if [ "$?" != "0" ]; then
102 _err "error $uri"
103 return 1
104 fi
105 _debug2 response "$response"
106 return 0
86ef6e69 107}