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
a3f7ff90
Unverified
Commit
a3f7ff90
authored
Mar 24, 2018
by
Nils Sandmann
Browse files
Used e_grep_o instead grep -Po, dns_pdns_rm() now deletes only entry with matching txt value
parent
1f3f8a50
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_pdns.sh
View file @
a3f7ff90
...
...
@@ -69,15 +69,21 @@ dns_pdns_add() {
#fulldomain
dns_pdns_rm
()
{
fulldomain
=
$1
txtvalue
=
$2
if
[
-z
"
$PDNS_Ttl
"
]
;
then
PDNS_Ttl
=
"
$DEFAULT_PDNS_TTL
"
fi
_debug
"Detect root zone"
if
!
_get_root
"
$fulldomain
"
;
then
_err
"invalid domain"
return
1
fi
_debug _domain
"
$_domain
"
if
!
rm_record
"
$_domain
"
"
$fulldomain
"
;
then
if
!
rm_record
"
$_domain
"
"
$fulldomain
"
"
$txtvalue
"
;
then
return
1
fi
...
...
@@ -90,12 +96,10 @@ set_record() {
full
=
$2
new_challenge
=
$3
_pdns_rest
"GET"
"/api/v1/servers/
$PDNS_ServerId
/zones/
$root
"
_record_string
=
""
_build_record_string
"
$new_challenge
"
_existing
_
challenges
=
$(
echo
"
$response
"
| _normalizeJson |
grep
-Po
"
\"
name
\"
:
\"
$fulldomain
\\
K.*?}]"
|
grep
-Po
'content\":\"\\"\K[^\\]*'
)
_list
_existingchallenges
for
oldchallenge
in
$_existing_challenges
;
do
_record_string
=
"
${
_record_string
}
, "
_build_record_string
"
$oldchallenge
"
done
...
...
@@ -104,6 +108,10 @@ set_record() {
return
1
fi
if
!
notify_slaves
"
$root
"
;
then
return
1
fi
return
0
}
...
...
@@ -111,14 +119,37 @@ rm_record() {
_info
"Remove record"
root
=
$1
full
=
$2
txtvalue
=
$3
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
#Enumerate existing acme challenges
_list_existingchallenges
if
!
notify_slaves
"
$root
"
;
then
return
1
if
_contains
"
$_existing_challenges
"
"
$txtvalue
"
;
then
#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
return
0
...
...
@@ -192,5 +223,10 @@ _pdns_rest() {
}
_build_record_string
()
{
_record_string
=
"
${
_record_string
}
{
\"
content
\"
:
\"\\\"
$1
\\\"\"
,
\"
disabled
\"
: false}"
_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