]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_nm.sh
fixing https://github.com/koalaman/shellcheck/wiki/SC2181 problems
[mirror_acme.sh.git] / dnsapi / dns_nm.sh
1 #!/usr/bin/env sh
2
3 ########################################################################
4 # https://namemaster.de hook script for acme.sh
5 #
6 # Environment variables:
7 #
8 # - $NM_user (your namemaster.de API username)
9 # - $NM_md5 (your namemaster.de API password_as_md5hash)
10 #
11 # Author: Thilo Gass <thilo.gass@gmail.com>
12 # Git repo: https://github.com/ThiloGa/acme.sh
13
14 #-- dns_nm_add() - Add TXT record --------------------------------------
15 # Usage: dns_nm_add _acme-challenge.subdomain.domain.com "XyZ123..."
16
17 dns_nm_add() {
18 fulldomain=$1
19 txt_value=$2
20 _info "Using DNS-01 namemaster hook"
21
22 NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
23 NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}"
24 if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then
25 NM_user=""
26 NM_md5=""
27 _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables."
28 return 1
29 fi
30 #save the api user and md5 password to the account conf file.
31 _debug "Save user and hash"
32 _saveaccountconf_mutable NM_user "$NM_user"
33 _saveaccountconf_mutable NM_md5 "$NM_md5"
34
35 zone="$(echo $fulldomain | _egrep_o "[^.]+.[^.]+$")"
36 get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=ACME&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Auto&Lifetime=3600"
37
38 if ! erg="$(_get "$get")"; then
39 _err "error Deleting $zone TXT: $txt_value"
40 _err "Error $exit_code"
41 return 1
42 fi
43
44 if _contains "$erg" "Success"; then
45 _info "Success, TXT Added, OK"
46 else
47 _err "error Adding $zone TXT: $txt_value erg: $erg"
48 return 1
49 fi
50
51 _debug "ok Auto $zone TXT: $txt_value erg: $erg"
52 return 0
53 }
54
55 dns_nm_rm() {
56
57 fulldomain=$1
58 txt_value=$2
59
60 NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
61 NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}"
62 if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then
63 NM_user=""
64 NM_md5=""
65 _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables."
66 return 1
67 fi
68
69 zone="$(echo $fulldomain | _egrep_o "[^.]+.[^.]+$")"
70 get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=TXT&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Delete_IN&TTL=0"
71
72 if ! erg="$(_get "$get")"; then
73 _err "error Deleting $zone TXT: $txt_value"
74 _err "Error $exit_code"
75 return 1
76 fi
77
78 if _contains "$erg" "Success"; then
79 _info "Success, TXT removed, OK"
80 else
81 _err "error Auto $zone TXT: $txt_value erg: $erg"
82 return 1
83 fi
84
85 _debug "ok Auto $zone TXT: $txt_value erg: $erg"
86 return 0
87
88 }