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
a6ecdbae
Unverified
Commit
a6ecdbae
authored
Aug 31, 2022
by
Marvo2011
Committed by
GitHub
Aug 31, 2022
Browse files
Merge pull request #7 from AlvinSchiller/dev
Dev - SELFHOSTDNS_MAP_LAST_USED_INTERNAL changes for readability
parents
f3e77a98
7a1f94bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_selfhost.sh
View file @
a6ecdbae
...
@@ -20,7 +20,7 @@ dns_selfhost_add() {
...
@@ -20,7 +20,7 @@ dns_selfhost_add() {
SELFHOSTDNS_MAP
=
"
${
SELFHOSTDNS_MAP
:-
$(
_readdomainconf SELFHOSTDNS_MAP
)
}
"
SELFHOSTDNS_MAP
=
"
${
SELFHOSTDNS_MAP
:-
$(
_readdomainconf SELFHOSTDNS_MAP
)
}
"
# Selfhost api can't dynamically add TXT record,
# Selfhost api can't dynamically add TXT record,
# so we have to store the last used RID of the domain to support a second RID for wildcard domains
# so we have to store the last used RID of the domain to support a second RID for wildcard domains
# (format: '
;
fulldomainA:lastRid
;;
fulldomainB:lastRid
;
...')
# (format: 'fulldomainA:lastRid
fulldomainB:lastRid
...')
SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=
$(
_readdomainconf SELFHOSTDNS_MAP_LAST_USED_INTERNAL
)
SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=
$(
_readdomainconf SELFHOSTDNS_MAP_LAST_USED_INTERNAL
)
if
[
-z
"
${
SELFHOSTDNS_USERNAME
:-}
"
]
||
[
-z
"
${
SELFHOSTDNS_PASSWORD
:-}
"
]
;
then
if
[
-z
"
${
SELFHOSTDNS_USERNAME
:-}
"
]
||
[
-z
"
${
SELFHOSTDNS_PASSWORD
:-}
"
]
;
then
...
@@ -44,23 +44,15 @@ dns_selfhost_add() {
...
@@ -44,23 +44,15 @@ dns_selfhost_add() {
rid2
=
$(
echo
"
$mapEntry
"
|
cut
-d
:
-f3
)
rid2
=
$(
echo
"
$mapEntry
"
|
cut
-d
:
-f3
)
# read last used rid domain
# read last used rid domain
lastUsedRidForDomainEntry
=
$(
echo
"
$SELFHOSTDNS_MAP_LAST_USED_INTERNAL
"
|
sed
-n
-E
"s/
.*(;
$fulldomain
:[[:digit:]]+
;
).*/
\
1
/p"
)
lastUsedRidForDomainEntry
=
$(
echo
"
$SELFHOSTDNS_MAP_LAST_USED_INTERNAL
"
|
sed
-n
-E
"s/
(^|^.*[[:space:]])(
$fulldomain
:[[:digit:]]+)
(
.*
)
/
\
2
/p"
)
_debug2 lastUsedRidForDomainEntry
"
$lastUsedRidForDomainEntry
"
_debug2 lastUsedRidForDomainEntry
"
$lastUsedRidForDomainEntry
"
lastUsedRidForDomain
=
$(
echo
"
$lastUsedRidForDomainEntry
"
|
tr
-d
";"
|
cut
-d
:
-f2
)
lastUsedRidForDomain
=
$(
echo
"
$lastUsedRidForDomainEntry
"
|
cut
-d
:
-f2
)
rid
=
"
$rid1
"
rid
=
"
$rid1
"
if
[
"
$lastUsedRidForDomain
"
=
"
$rid
"
]
&&
!
test
-z
"
$rid2
"
;
then
if
[
"
$lastUsedRidForDomain
"
=
"
$rid
"
]
&&
!
test
-z
"
$rid2
"
;
then
rid
=
"
$rid2
"
rid
=
"
$rid2
"
fi
fi
if
!
test
-z
"
$lastUsedRidForDomainEntry
"
;
then
# replace last used rid entry for domain
SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=
$(
echo
"
$SELFHOSTDNS_MAP_LAST_USED_INTERNAL
"
|
sed
-n
-E
"s/
$lastUsedRidForDomainEntry
/;
$fulldomain
:
$rid
;/p"
)
else
# add last used rid entry for domain
SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=
"
$SELFHOSTDNS_MAP_LAST_USED_INTERNAL
"";
$fulldomain
:
$rid
;"
fi
_info
"Trying to add
$txt
on selfhost for rid:
$rid
"
_info
"Trying to add
$txt
on selfhost for rid:
$rid
"
data
=
"?username=
$SELFHOSTDNS_USERNAME
&password=
$SELFHOSTDNS_PASSWORD
&rid=
$rid
&content=
$txt
"
data
=
"?username=
$SELFHOSTDNS_USERNAME
&password=
$SELFHOSTDNS_PASSWORD
&rid=
$rid
&content=
$txt
"
...
@@ -71,6 +63,20 @@ dns_selfhost_add() {
...
@@ -71,6 +63,20 @@ dns_selfhost_add() {
return
1
return
1
fi
fi
# write last used rid domain
newLastUsedRidForDomainEntry
=
"
$fulldomain
:
$rid
"
if
!
test
-z
"
$lastUsedRidForDomainEntry
"
;
then
# replace last used rid entry for domain
SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=
$(
echo
"
$SELFHOSTDNS_MAP_LAST_USED_INTERNAL
"
|
sed
-n
-E
"s/
$lastUsedRidForDomainEntry
/
$newLastUsedRidForDomainEntry
/p"
)
else
# add last used rid entry for domain
if
test
-z
"
$SELFHOSTDNS_MAP_LAST_USED_INTERNAL
"
;
then
SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=
"
$newLastUsedRidForDomainEntry
"
else
SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=
"
$SELFHOSTDNS_MAP_LAST_USED_INTERNAL
$newLastUsedRidForDomainEntry
"
fi
fi
# Now that we know the values are good, save them
# Now that we know the values are good, save them
_saveaccountconf_mutable SELFHOSTDNS_USERNAME
"
$SELFHOSTDNS_USERNAME
"
_saveaccountconf_mutable SELFHOSTDNS_USERNAME
"
$SELFHOSTDNS_USERNAME
"
_saveaccountconf_mutable SELFHOSTDNS_PASSWORD
"
$SELFHOSTDNS_PASSWORD
"
_saveaccountconf_mutable SELFHOSTDNS_PASSWORD
"
$SELFHOSTDNS_PASSWORD
"
...
...
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