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