]>
Commit | Line | Data |
---|---|---|
5530e743 | 1 | #!/usr/bin/env sh |
2 | ||
3 | # Joker.com API for acme.sh | |
4 | # | |
5 | # This script adds the necessary TXT record to a domain in Joker.com. | |
6 | # | |
7 | # You must activate Dynamic DNS in Joker.com DNS configuration first. | |
8 | # Username and password below refer to Dynamic DNS authentication, | |
9 | # not your Joker.com login credentials. | |
10 | # See: https://joker.com/faq/content/11/427/en/what-is-dynamic-dns-dyndns.html | |
11 | # | |
12 | # NOTE: This script does not support wildcard certificates, because | |
13 | # Joker.com API does not support adding two TXT records with the same | |
14 | # subdomain. Adding the second record will overwrite the first one. | |
15 | # See: https://joker.com/faq/content/6/496/en/let_s-encrypt-support.html | |
16 | # "... this request will replace all TXT records for the specified | |
17 | # label by the provided content" | |
18 | # | |
19 | # Author: aattww (https://github.com/aattww/) | |
20 | # | |
21 | # JOKER_USERNAME="xxxx" | |
22 | # JOKER_PASSWORD="xxxx" | |
23 | ||
24 | JOKER_API="https://svc.joker.com/nic/replace" | |
25 | ||
26 | ######## Public functions ##################### | |
27 | ||
28 | #Usage: dns_joker_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | |
29 | dns_joker_add() { | |
30 | fulldomain=$1 | |
31 | txtvalue=$2 | |
32 | ||
33 | JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}" | |
34 | JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}" | |
35 | ||
36 | if [ -z "$JOKER_USERNAME" ] || [ -z "$JOKER_PASSWORD" ]; then | |
37 | _err "No Joker.com username and password specified." | |
38 | return 1 | |
39 | fi | |
40 | ||
41 | _saveaccountconf_mutable JOKER_USERNAME "$JOKER_USERNAME" | |
42 | _saveaccountconf_mutable JOKER_PASSWORD "$JOKER_PASSWORD" | |
43 | ||
44 | if ! _get_root "$fulldomain"; then | |
45 | _err "Invalid domain" | |
46 | return 1 | |
47 | fi | |
48 | ||
49 | _info "Adding TXT record" | |
50 | if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value=$txtvalue"; then | |
51 | if _startswith "$response" "OK"; then | |
52 | _info "Added, OK" | |
53 | return 0 | |
54 | fi | |
55 | fi | |
56 | _err "Error adding TXT record." | |
57 | return 1 | |
58 | } | |
59 | ||
60 | #fulldomain txtvalue | |
61 | dns_joker_rm() { | |
62 | fulldomain=$1 | |
63 | txtvalue=$2 | |
64 | ||
65 | JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}" | |
66 | JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}" | |
67 | ||
68 | if ! _get_root "$fulldomain"; then | |
69 | _err "Invalid domain" | |
70 | return 1 | |
71 | fi | |
72 | ||
73 | _info "Removing TXT record" | |
74 | # TXT record is removed by setting its value to empty. | |
75 | if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value="; then | |
76 | if _startswith "$response" "OK"; then | |
77 | _info "Removed, OK" | |
78 | return 0 | |
79 | fi | |
80 | fi | |
81 | _err "Error removing TXT record." | |
82 | return 1 | |
83 | } | |
84 | ||
85 | #################### Private functions below ################################## | |
86 | #_acme-challenge.www.domain.com | |
87 | #returns | |
88 | # _sub_domain=_acme-challenge.www | |
89 | # _domain=domain.com | |
90 | _get_root() { | |
91 | fulldomain=$1 | |
92 | i=1 | |
93 | while true; do | |
94 | h=$(printf "%s" "$fulldomain" | cut -d . -f $i-100) | |
95 | _debug h "$h" | |
96 | if [ -z "$h" ]; then | |
97 | return 1 | |
98 | fi | |
99 | ||
100 | # Try to remove a test record. With correct root domain, username and password this will return "OK: ..." regardless | |
101 | # of record in question existing or not. | |
102 | if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$h&label=jokerTXTUpdateTest&type=TXT&value="; then | |
103 | if _startswith "$response" "OK"; then | |
104 | _sub_domain="$(echo "$fulldomain" | sed "s/\\.$h\$//")" | |
105 | _domain=$h | |
106 | return 0 | |
107 | fi | |
108 | fi | |
109 | ||
110 | i=$(_math "$i" + 1) | |
111 | done | |
112 | ||
113 | _debug "Root domain not found" | |
114 | return 1 | |
115 | } | |
116 | ||
117 | _joker_rest() { | |
118 | data="$1" | |
119 | _debug data "$data" | |
120 | ||
121 | response="$(_post "$data" "$JOKER_API" "" "POST")" | |
122 | ||
123 | if [ "$?" != "0" ]; then | |
124 | _err "Error POSTing" | |
125 | return 1 | |
126 | fi | |
127 | _debug response "$response" | |
128 | return 0 | |
129 | } |