]>
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 | # | |
8400d1e6 | 21 | # Report bugs to https://github.com/acmesh-official/acme.sh/issues/2840 |
22 | # | |
5530e743 | 23 | # JOKER_USERNAME="xxxx" |
24 | # JOKER_PASSWORD="xxxx" | |
25 | ||
26 | JOKER_API="https://svc.joker.com/nic/replace" | |
27 | ||
28 | ######## Public functions ##################### | |
29 | ||
30 | #Usage: dns_joker_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | |
31 | dns_joker_add() { | |
32 | fulldomain=$1 | |
33 | txtvalue=$2 | |
34 | ||
35 | JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}" | |
36 | JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}" | |
37 | ||
38 | if [ -z "$JOKER_USERNAME" ] || [ -z "$JOKER_PASSWORD" ]; then | |
39 | _err "No Joker.com username and password specified." | |
40 | return 1 | |
41 | fi | |
42 | ||
43 | _saveaccountconf_mutable JOKER_USERNAME "$JOKER_USERNAME" | |
44 | _saveaccountconf_mutable JOKER_PASSWORD "$JOKER_PASSWORD" | |
45 | ||
46 | if ! _get_root "$fulldomain"; then | |
47 | _err "Invalid domain" | |
48 | return 1 | |
49 | fi | |
50 | ||
51 | _info "Adding TXT record" | |
52 | if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value=$txtvalue"; then | |
53 | if _startswith "$response" "OK"; then | |
54 | _info "Added, OK" | |
55 | return 0 | |
56 | fi | |
57 | fi | |
58 | _err "Error adding TXT record." | |
59 | return 1 | |
60 | } | |
61 | ||
62 | #fulldomain txtvalue | |
63 | dns_joker_rm() { | |
64 | fulldomain=$1 | |
65 | txtvalue=$2 | |
66 | ||
67 | JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}" | |
68 | JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}" | |
69 | ||
70 | if ! _get_root "$fulldomain"; then | |
71 | _err "Invalid domain" | |
72 | return 1 | |
73 | fi | |
74 | ||
75 | _info "Removing TXT record" | |
76 | # TXT record is removed by setting its value to empty. | |
77 | if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value="; then | |
78 | if _startswith "$response" "OK"; then | |
79 | _info "Removed, OK" | |
80 | return 0 | |
81 | fi | |
82 | fi | |
83 | _err "Error removing TXT record." | |
84 | return 1 | |
85 | } | |
86 | ||
87 | #################### Private functions below ################################## | |
88 | #_acme-challenge.www.domain.com | |
89 | #returns | |
90 | # _sub_domain=_acme-challenge.www | |
91 | # _domain=domain.com | |
92 | _get_root() { | |
93 | fulldomain=$1 | |
94 | i=1 | |
95 | while true; do | |
96 | h=$(printf "%s" "$fulldomain" | cut -d . -f $i-100) | |
97 | _debug h "$h" | |
98 | if [ -z "$h" ]; then | |
99 | return 1 | |
100 | fi | |
101 | ||
102 | # Try to remove a test record. With correct root domain, username and password this will return "OK: ..." regardless | |
19c43451 | 103 | # of record in question existing or not. |
5530e743 | 104 | if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$h&label=jokerTXTUpdateTest&type=TXT&value="; then |
105 | if _startswith "$response" "OK"; then | |
106 | _sub_domain="$(echo "$fulldomain" | sed "s/\\.$h\$//")" | |
107 | _domain=$h | |
108 | return 0 | |
109 | fi | |
110 | fi | |
111 | ||
112 | i=$(_math "$i" + 1) | |
113 | done | |
114 | ||
115 | _debug "Root domain not found" | |
116 | return 1 | |
117 | } | |
118 | ||
119 | _joker_rest() { | |
120 | data="$1" | |
121 | _debug data "$data" | |
122 | ||
c064b389 | 123 | if ! response="$(_post "$data" "$JOKER_API" "" "POST")"; then |
5530e743 | 124 | _err "Error POSTing" |
125 | return 1 | |
126 | fi | |
127 | _debug response "$response" | |
128 | return 0 | |
129 | } |