]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_nm.sh
adaptations to the new api functions
[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_sha256 (your namemaster.de API password_as_sha256hash)
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 namemaster_api="https://namemaster.de/api/api.php"
18
19
20 dns_nm_add() {
21 fulldomain=$1
22 txt_value=$2
23 _info "Using DNS-01 namemaster hook"
24
25 NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
26 NM_sha256="${NM_sha256:-$(_readaccountconf_mutable NM_sha256)}"
27 if [ -z "$NM_user" ] || [ -z "$NM_sha256" ]; then
28 NM_user=""
29 NM_sha256=""
30 _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_sha256 environment variables."
31 return 1
32 fi
33 #save the api user and sha256 password to the account conf file.
34 _debug "Save user and hash"
35 _saveaccountconf_mutable NM_user "$NM_user"
36 _saveaccountconf_mutable NM_sha256 "$NM_sha256"
37
38
39 _debug "First detect the root zone"
40 if ! _get_root "$fulldomain"; then
41 _err "invalid domain" "$fulldomain"
42 return 1
43 fi
44
45 _info "die Zone lautet:" "$zone"
46
47 get="$namemaster_api?User=$NM_user&Password=$NM_sha256&Antwort=csv&Typ=ACME&zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Auto&Lifetime=3600"
48
49 if ! erg="$(_get "$get")"
50 then
51 _err "error Adding $fulldomain TXT: $txt_value"
52 return 1
53 fi
54
55 if _contains "$erg" "Success"; then
56 _info "Success, TXT Added, OK"
57 else
58 _err "error Adding $fulldomain TXT: $txt_value erg: $erg"
59 return 1
60 fi
61
62 _debug "ok Auto $fulldomain TXT: $txt_value erg: $erg"
63 return 0
64 }
65
66 dns_nm_rm() {
67
68 fulldomain=$1
69 txt_value=$2
70
71 NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
72 NM_sha256="${NM_sha256:-$(_readaccountconf_mutable NM_sha256)}"
73 if [ -z "$NM_user" ] || [ -z "$NM_sha256" ]; then
74 NM_user=""
75 NM_sha256=""
76 _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_sha256 environment variables."
77 return 1
78 fi
79
80
81 zone="$(echo "$fulldomain" | _egrep_o "[^.]+.[^.]+$")"
82 get="$namemaster_api?User=$NM_user&Password=$NM_sha256&Antwort=csv&Typ=TXT&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Delete_IN"
83
84 if ! erg="$(_get "$get")"
85 then
86 _err "error Deleting $fulldomain TXT: $txt_value"
87 return 1
88 fi
89
90 if _contains "$erg" "Success"; then
91 _info "Success, TXT removed, OK"
92 else
93 _err "error Auto $fulldomain TXT: $txt_value erg: $erg"
94 return 1
95 fi
96
97 _debug "ok Auto $fulldomain TXT: $txt_value erg: $erg"
98 return 0
99
100 }
101
102
103 _get_root() {
104
105 domain=$1
106
107 get="$namemaster_api?User=$NM_user&Password=$NM_sha256&Typ=acme&hostname=$domain&Action=getzone&antwort=csv"
108
109 if ! zone="$(_get "$get")"
110 then
111 _err "error getting Zone"
112 return 1
113 else
114 if _contains "$zone" "hostname not found"
115 then
116 return 1
117 fi
118 fi
119
120 }