]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_kappernet.sh
now with "_saveaccountconf_mutable"
[mirror_acme.sh.git] / dnsapi / dns_kappernet.sh
1 #!/usr/bin/env sh
2
3 # kapper.net domain api
4 # for further questions please contact: support@kapper.net
5 # please report issues here: https://github.com/acmesh-official/acme.sh/issues/2977
6
7 #KAPPERNETDNS_Key="yourKAPPERNETapikey"
8 #KAPPERNETDNS_Secret="yourKAPPERNETapisecret"
9
10 KAPPERNETDNS_Api="https://dnspanel.kapper.net/API/1.2?APIKey=$KAPPERNETDNS_Key&APISecret=$KAPPERNETDNS_Secret"
11
12 ###############################################################################
13 # called with
14 # fullhostname: something.example.com
15 # txtvalue: someacmegenerated string
16 dns_kappernet_add() {
17 fullhostname=$1
18 txtvalue=$2
19
20 if [ -z "$KAPPERNETDNS_Key" ] || [ -z "$KAPPERNETDNS_Secret" ]; then
21 KAPPERNETDNS_Key=""
22 KAPPERNETDNS_Secret=""
23 _err "You haven't defined kapper.net api key and secret yet."
24 _err "Please send us mail to support@kapper.net get your key and secret."
25 return 1
26 fi
27
28 #store the api key and email to the account conf file.
29 _saveaccountconf_mutable KAPPERNETDNS_Key "$KAPPERNETDNS_Key"
30 _saveaccountconf_mutable KAPPERNETDNS_Secret "$KAPPERNETDNS_Secret"
31 _debug "Checking Domain ..."
32 if ! _get_root "$fullhostname"; then
33 _err "invalid domain"
34 return 1
35 fi
36 _debug _sub_domain "SUBDOMAIN: $_sub_domain"
37 _debug _domain "DOMAIN: $_domain"
38
39 _info "Trying to add TXT DNS Record"
40 data="%7B%22name%22%3A%22$fullhostname%22%2C%22type%22%3A%22TXT%22%2C%22content%22%3A%22$txtvalue%22%2C%22ttl%22%3A%223600%22%2C%22prio%22%3A%22%22%7D"
41 if _kappernet_api GET "action=new&subject=$_domain&data=$data"; then
42
43 if _contains "$response" "{\"OK\":true"; then
44 _info "Waiting 120 seconds for DNS to spread the new record"
45 _sleep 120
46 return 0
47 else
48 _err "Error creating a TXT DNS Record: $fullhostname TXT $txtvalue"
49 _err "Error Message: $response"
50 return 1
51 fi
52 fi
53 _err "Failed creating TXT Record"
54 }
55
56 ###############################################################################
57 # called with
58 # fullhostname: something.example.com
59 dns_kappernet_rm() {
60 fullhostname=$1
61 txtvalue=$2
62
63 if [ -z "$KAPPERNETDNS_Key" ] || [ -z "$KAPPERNETDNS_Secret" ]; then
64 KAPPERNETDNS_Key=""
65 KAPPERNETDNS_Secret=""
66 _err "You haven't defined kapper.net api key and secret yet."
67 _err "Please send us mail to get your key and secret."
68 return 1
69 fi
70
71 #store the api key and email to the account conf file.
72 _saveaccountconf_mutable KAPPERNETDNS_Key "$KAPPERNETDNS_Key"
73 _saveaccountconf_mutable KAPPERNETDNS_Secret "$KAPPERNETDNS_Secret"
74
75 _info "Trying to remove the TXT Record: $fullhostname"
76 data="%7B%22name%22%3A%22$fullhostname%22%2C%22type%22%3A%22TXT%22%2C%22content%22%3A%22$txtvalue%22%2C%22ttl%22%3A%223600%22%2C%22prio%22%3A%22%22%7D"
77 if _kappernet_api GET "action=del&subject=$fullhostname&data=$data"; then
78 if _contains "$response" "{\"OK\":true"; then
79 return 0
80 else
81 _err "Error deleting DNS Record: $fullhostname"
82 _err "Problem: $response"
83 return 1
84 fi
85 fi
86 _err "Problem creating TXT DNS record"
87 }
88
89 #################### Private functions below ##################################
90 # called with hostname
91 # e.g._acme-challenge.www.domain.com returns
92 # _sub_domain=_acme-challenge.www
93 # _domain=domain.com
94 _get_root() {
95 domain=$1
96 i=2
97 p=1
98 while true; do
99 h=$(printf "%s" "$domain" | cut -d . -f $i-100)
100 if [ -z "$h" ]; then
101 #not valid
102 return 1
103 fi
104 if ! _kappernet_api GET "action=list&subject=$h"; then
105 return 1
106 fi
107 if _contains "$response" '"OK":false'; then
108 _debug "$h not found"
109 else
110 _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
111 _domain="$h"
112 return 0
113 fi
114 p="$i"
115 i=$(_math "$i" + 1)
116 done
117 return 1
118 }
119
120 ################################################################################
121 # calls the kapper.net DNS Panel API
122 # with
123 # method
124 # param
125 _kappernet_api() {
126 method=$1
127 param="$2"
128
129 _debug param "PARAMETER=$param"
130 url="$KAPPERNETDNS_Api&$param"
131 _debug url "URL=$url"
132
133 if [ "$method" = "GET" ]; then
134 response="$(_get "$url")"
135 else
136 _err "Unsupported method"
137 return 1
138 fi
139
140 _debug2 response "$response"
141 return 0
142 }