Skip to content

Commit 5fe8a5e

Browse files
Myself5jaapmarcus
andauthored
hestia: don't upgrade DNS entries when theres no changes (hestiacp#2125)
* hestia: don't upgrade DNS entries when theres no changes * This prevents upgrading the DNS Serial for effectless changes which previously lead to serial overflows on specific setups. * Add exit code + Add new tests for v-change-dns-records * Change error code to exsits Removed duplicated check in v-change-record-id * Fix test Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 2ee38eb commit 5fe8a5e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
### Bugfixes
99

1010
- Disable /reset/ endpoint when POLICY_SYSTEM_PASSWORD_RESET = no
11+
- Prevent SOA count up after v-change-dns-records with no changes are made
1112

1213
## [1.4.17] - Service release
1314

bin/v-change-dns-record

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ check_hestia_demo_mode
6262
# Action #
6363
#----------------------------------------------------------#
6464

65+
# Make sure the variable for the optional parameter TTL is empty before parsing
66+
# We depend on that later on
67+
unset TTL
68+
6569
# Parsing domain config
6670
line=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
6771
parse_object_kv_list "$line"
6872

69-
if [ -z $type ]; then
73+
if [ -z "$type" ]; then
7074
type=$TYPE
7175
fi
7276

@@ -87,8 +91,11 @@ fi
8791
is_dns_fqnd "$TYPE" "$dvalue"
8892
is_dns_nameserver_valid "$domain" "$TYPE" "$dvalue"
8993

90-
# Deleting old record
91-
sed -i "/^ID='$id'/d" "$USER_DATA/dns/$domain.conf"
94+
if [[ "$RECORD" == "$record" ]] && [[ "$TYPE" == "$type" ]] && [[ "$PRIORITY" -eq "$priority" ]] \
95+
&& [[ "$VALUE" == "$dvalue" ]] && [[ "$SUSPENDED" == 'no' ]] && [[ "$TTL" -eq "$ttl" ]]; then
96+
echo "No pending changes in DNS entry."
97+
exit "$E_EXSIST"
98+
fi
9299

93100
# Generating timestamp
94101
time_n_date=$(date +'%T %F')
@@ -99,6 +106,9 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
99106
dns_rec="ID='$id' RECORD='$record' TYPE='$type' PRIORITY='$priority'"
100107
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
101108
[ -n "$ttl" ] && dns_rec="$dns_rec TTL='$ttl'"
109+
# Deleting old record
110+
sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf
111+
# Add new entry
102112
echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
103113

104114
# Sorting records

test/test.bats

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,30 @@ function check_ip_not_banned(){
10831083
refute_output
10841084
}
10851085

1086+
@test "DNS: Change DNS record" {
1087+
run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
1088+
assert_success
1089+
refute_output
1090+
}
1091+
1092+
@test "DNS: Change DNS record (no update)" {
1093+
run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
1094+
assert_failure $E_EXSIST
1095+
}
1096+
1097+
@test "DNS: Change DNS record id" {
1098+
run v-change-dns-record-id $user $domain 20 21
1099+
assert_success
1100+
refute_output
1101+
# Change back
1102+
run v-change-dns-record-id $user $domain 21 20
1103+
}
1104+
1105+
@test "DNS: Change DNS record id (no update)" {
1106+
run v-change-dns-record-id $user $domain 20 20
1107+
assert_failure $E_EXSIST
1108+
}
1109+
10861110
@test "DNS: Delete domain record" {
10871111
run v-delete-dns-record $user $domain 20
10881112
assert_success

0 commit comments

Comments
 (0)