]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env sh | |
2 | ||
3 | #Author: RhinoLance | |
4 | #Report Bugs here: https://github.com/RhinoLance/acme.sh | |
5 | # | |
6 | ||
7 | #define the api endpoint | |
8 | DH_API_ENDPOINT="https://api.dreamhost.com/" | |
9 | querystring="" | |
10 | ||
11 | ######## Public functions ##################### | |
12 | ||
13 | #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | |
14 | dns_dreamhost_add() { | |
15 | fulldomain=$1 | |
16 | txtvalue=$2 | |
17 | ||
18 | if ! validate "$fulldomain" "$txtvalue"; then | |
19 | return 1 | |
20 | fi | |
21 | ||
22 | querystring="key=$DH_API_KEY&cmd=dns-add_record&record=$fulldomain&type=TXT&value=$txtvalue" | |
23 | if ! submit "$querystring"; then | |
24 | return 1 | |
25 | fi | |
26 | ||
27 | return 0 | |
28 | } | |
29 | ||
30 | #Usage: fulldomain txtvalue | |
31 | #Remove the txt record after validation. | |
32 | dns_dreamhost_rm() { | |
33 | fulldomain=$1 | |
34 | txtvalue=$2 | |
35 | ||
36 | if ! validate "$fulldomain" "$txtvalue"; then | |
37 | return 1 | |
38 | fi | |
39 | ||
40 | querystring="key=$DH_API_KEY&cmd=dns-remove_record&record=$fulldomain&type=TXT&value=$txtvalue" | |
41 | if ! submit "$querystring"; then | |
42 | return 1 | |
43 | fi | |
44 | ||
45 | return 0 | |
46 | } | |
47 | ||
48 | #################### Private functions below ################################## | |
49 | ||
50 | #send the command to the api endpoint. | |
51 | submit() { | |
52 | querystring=$1 | |
53 | ||
54 | url="$DH_API_ENDPOINT?$querystring" | |
55 | ||
56 | _debug url "$url" | |
57 | ||
58 | if ! response="$(_get "$url")"; then | |
59 | _err "Error <$1>" | |
60 | return 1 | |
61 | fi | |
62 | ||
63 | if [ -z "$2" ]; then | |
64 | message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")" | |
65 | if [ -n "$message" ]; then | |
66 | _err "$message" | |
67 | return 1 | |
68 | fi | |
69 | fi | |
70 | ||
71 | _debug response "$response" | |
72 | ||
73 | return 0 | |
74 | } | |
75 | ||
76 | #check that we have a valid API Key | |
77 | validate() { | |
78 | fulldomain=$1 | |
79 | txtvalue=$2 | |
80 | ||
81 | _info "Using dreamhost" | |
82 | _debug fulldomain "$fulldomain" | |
83 | _debug txtvalue "$txtvalue" | |
84 | ||
85 | #retrieve the API key from the environment variable if it exists, otherwise look for a saved key. | |
86 | DH_API_KEY="${DH_API_KEY:-$(_readaccountconf_mutable DH_API_KEY)}" | |
87 | ||
88 | if [ -z "$DH_API_KEY" ]; then | |
89 | DH_API_KEY="" | |
90 | _err "You didn't specify the DreamHost api key yet (export DH_API_KEY=\"<api key>\")" | |
91 | _err "Please login to your control panel, create a key and try again." | |
92 | return 1 | |
93 | fi | |
94 | ||
95 | #save the api key to the account conf file. | |
96 | _saveaccountconf_mutable DH_API_KEY "$DH_API_KEY" | |
97 | } |