Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
e1628bcd
Unverified
Commit
e1628bcd
authored
Apr 01, 2018
by
neil
Committed by
GitHub
Apr 01, 2018
Browse files
Merge pull request #1429 from softcat/dev
Fixed DNSAPI for PowerDNS to support wildcard certificates
parents
6d5874fc
a3f7ff90
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_pdns.sh
View file @
e1628bcd
...
@@ -69,15 +69,21 @@ dns_pdns_add() {
...
@@ -69,15 +69,21 @@ dns_pdns_add() {
#fulldomain
#fulldomain
dns_pdns_rm
()
{
dns_pdns_rm
()
{
fulldomain
=
$1
fulldomain
=
$1
txtvalue
=
$2
if
[
-z
"
$PDNS_Ttl
"
]
;
then
PDNS_Ttl
=
"
$DEFAULT_PDNS_TTL
"
fi
_debug
"Detect root zone"
_debug
"Detect root zone"
if
!
_get_root
"
$fulldomain
"
;
then
if
!
_get_root
"
$fulldomain
"
;
then
_err
"invalid domain"
_err
"invalid domain"
return
1
return
1
fi
fi
_debug _domain
"
$_domain
"
_debug _domain
"
$_domain
"
if
!
rm_record
"
$_domain
"
"
$fulldomain
"
;
then
if
!
rm_record
"
$_domain
"
"
$fulldomain
"
"
$txtvalue
"
;
then
return
1
return
1
fi
fi
...
@@ -88,9 +94,16 @@ set_record() {
...
@@ -88,9 +94,16 @@ set_record() {
_info
"Adding record"
_info
"Adding record"
root
=
$1
root
=
$1
full
=
$2
full
=
$2
txtvalu
e
=
$3
new_challeng
e
=
$3
if
!
_pdns_rest
"PATCH"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
"
"{
\"
rrsets
\"
: [{
\"
changetype
\"
:
\"
REPLACE
\"
,
\"
name
\"
:
\"
$full
.
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
:
$PDNS_Ttl
,
\"
records
\"
: [{
\"
name
\"
:
\"
$full
.
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
content
\"
:
\"\\\"
$txtvalue
\\\"\"
,
\"
disabled
\"
: false,
\"
ttl
\"
:
$PDNS_Ttl
}]}]}"
;
then
_record_string
=
""
_build_record_string
"
$new_challenge
"
_list_existingchallenges
for
oldchallenge
in
$_existing_challenges
;
do
_build_record_string
"
$oldchallenge
"
done
if
!
_pdns_rest
"PATCH"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
"
"{
\"
rrsets
\"
: [{
\"
changetype
\"
:
\"
REPLACE
\"
,
\"
name
\"
:
\"
$full
.
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
:
$PDNS_Ttl
,
\"
records
\"
: [
$_record_string
]}]}"
;
then
_err
"Set txt record error."
_err
"Set txt record error."
return
1
return
1
fi
fi
...
@@ -106,14 +119,37 @@ rm_record() {
...
@@ -106,14 +119,37 @@ rm_record() {
_info
"Remove record"
_info
"Remove record"
root
=
$1
root
=
$1
full
=
$2
full
=
$2
txtvalue
=
$3
if
!
_pdns_rest
"PATCH"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
"
"{
\"
rrsets
\"
: [{
\"
changetype
\"
:
\"
DELETE
\"
,
\"
name
\"
:
\"
$full
.
\"
,
\"
type
\"
:
\"
TXT
\"
}]}"
;
then
#Enumerate existing acme challenges
_err
"Delete txt record error."
_list_existingchallenges
return
1
fi
if
!
notify_slaves
"
$root
"
;
then
if
_contains
"
$_existing_challenges
"
"
$txtvalue
"
;
then
return
1
#Delete all challenges (PowerDNS API does not allow to delete content)
if
!
_pdns_rest
"PATCH"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
"
"{
\"
rrsets
\"
: [{
\"
changetype
\"
:
\"
DELETE
\"
,
\"
name
\"
:
\"
$full
.
\"
,
\"
type
\"
:
\"
TXT
\"
}]}"
;
then
_err
"Delete txt record error."
return
1
fi
_record_string
=
""
#If the only existing challenge was the challenge to delete: nothing to do
if
!
[
"
$_existing_challenges
"
=
"
$txtvalue
"
]
;
then
for
oldchallenge
in
$_existing_challenges
;
do
#Build up the challenges to re-add, ommitting the one what should be deleted
if
!
[
"
$oldchallenge
"
=
"
$txtvalue
"
]
;
then
_build_record_string
"
$oldchallenge
"
fi
done
#Recreate the existing challenges
if
!
_pdns_rest
"PATCH"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
"
"{
\"
rrsets
\"
: [{
\"
changetype
\"
:
\"
REPLACE
\"
,
\"
name
\"
:
\"
$full
.
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
:
$PDNS_Ttl
,
\"
records
\"
: [
$_record_string
]}]}"
;
then
_err
"Set txt record error."
return
1
fi
fi
if
!
notify_slaves
"
$root
"
;
then
return
1
fi
else
_info
"Record not found, nothing to remove"
fi
fi
return
0
return
0
...
@@ -185,3 +221,12 @@ _pdns_rest() {
...
@@ -185,3 +221,12 @@ _pdns_rest() {
return
0
return
0
}
}
_build_record_string
()
{
_record_string
=
"
${
_record_string
:+
${
_record_string
}
,
}
{
\"
content
\"
:
\"\\\"
${
1
}
\\\"\"
,
\"
disabled
\"
: false}"
}
_list_existingchallenges
()
{
_pdns_rest
"GET"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
"
_existing_challenges
=
$(
echo
"
$response
"
| _normalizeJson | _egrep_o
"
\"
name
\"
:
\"
${
fulldomain
}
[^]]*}"
| _egrep_o
'content\":\"\\"[^\\]*'
|
sed
-n
's/^content":"\\"//p'
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment