]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_selfhost.sh
Merge branch 'acmesh-official-dev' into dev
[mirror_acme.sh.git] / dnsapi / dns_selfhost.sh
CommitLineData
cc5cfc75
M
1#!/usr/bin/env sh
2#
3# Author: Marvin Edeler
4# Report Bugs here: https://github.com/Marvo2011/acme.sh/issues/1
2982e994 5# Last Edit: 17.02.2022
cc5cfc75
M
6
7dns_selfhost_add() {
8 domain=$1
9 txt=$2
10 _info "Calling acme-dns on selfhost"
11 _debug fulldomain "$domain"
12 _debug txtvalue "$txt"
13
14 SELFHOSTDNS_UPDATE_URL="https://selfhost.de/cgi-bin/api.pl"
610c3cf6
A
15
16 # Get values, but don't save until we successfully validated
cc5cfc75
M
17 SELFHOSTDNS_USERNAME="${SELFHOSTDNS_USERNAME:-$(_readaccountconf_mutable SELFHOSTDNS_USERNAME)}"
18 SELFHOSTDNS_PASSWORD="${SELFHOSTDNS_PASSWORD:-$(_readaccountconf_mutable SELFHOSTDNS_PASSWORD)}"
610c3cf6
A
19 # These values are domain dependent, so read them from there
20 _getdeployconf SELFHOSTDNS_MAP
21 _getdeployconf SELFHOSTDNS_RID
22 _getdeployconf SELFHOSTDNS_RID2
23 _getdeployconf SELFHOSTDNS_LAST_SLOT
cc5cfc75 24
96d45cc3
A
25 if [ -z "${SELFHOSTDNS_USERNAME:-}" ] || [ -z "${SELFHOSTDNS_PASSWORD:-}" ]; then
26 _err "SELFHOSTDNS_USERNAME and SELFHOSTDNS_PASSWORD must be set"
27 return 1
28 fi
29
cc5cfc75
M
30 if test -z "$SELFHOSTDNS_LAST_SLOT"; then
31 SELFHOSTDNS_LAST_SLOT=1
32 fi
33
ac0dd90c
M
34 rid=$(echo "$SELFHOSTDNS_MAP" | grep -Eoi "$domain:(\d+)" | tr -d "$domain:")
35
2982e994
M
36 if test -z "$rid"; then
37 if [ $SELFHOSTDNS_LAST_SLOT = "2" ]; then
38 rid=$SELFHOSTDNS_RID
39 SELFHOSTDNS_LAST_SLOT=1
40 else
41 rid=$SELFHOSTDNS_RID2
42 SELFHOSTDNS_LAST_SLOT=2
43 fi
cc5cfc75
M
44 fi
45
96d45cc3
A
46 if test -z "$rid"; then
47 _err "SELFHOSTDNS_RID and SELFHOSTDNS_RID2, or SELFHOSTDNS_MAP must be set"
48 return 1
49 fi
50
cc5cfc75
M
51 _info "Trying to add $txt on selfhost for rid: $rid"
52
53 data="?username=$SELFHOSTDNS_USERNAME&password=$SELFHOSTDNS_PASSWORD&rid=$rid&content=$txt"
54 response="$(_get "$SELFHOSTDNS_UPDATE_URL$data")"
55
56 if ! echo "$response" | grep "200 OK" >/dev/null; then
57 _err "Invalid response of acme-dns for selfhost"
58 return 1
59 fi
610c3cf6
A
60
61 # Now that we know the values are good, save them
62 _saveaccountconf_mutable SELFHOSTDNS_USERNAME "$SELFHOSTDNS_USERNAME"
63 _saveaccountconf_mutable SELFHOSTDNS_PASSWORD "$SELFHOSTDNS_PASSWORD"
64 # These values are domain dependent, so store them there
65 _savedeployconf SELFHOSTDNS_MAP "$SELFHOSTDNS_MAP"
66 _savedeployconf SELFHOSTDNS_RID "$SELFHOSTDNS_RID"
67 _savedeployconf SELFHOSTDNS_RID2 "$SELFHOSTDNS_RID2"
68 _savedeployconf SELFHOSTDNS_LAST_SLOT "$SELFHOSTDNS_LAST_SLOT"
cc5cfc75
M
69}
70
d6c68f1a 71dns_selfhost_rm() {
cc5cfc75
M
72 domain=$1
73 txt=$2
74 _debug fulldomain "$domain"
75 _debug txtvalue "$txt"
d6c68f1a 76 _info "Creating and removing of records is not supported by selfhost API, will not delete anything."
cc5cfc75 77}