Просмотр исходного кода

hestia: don't upgrade DNS entries when theres no changes (#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>
Christian Oder 4 лет назад
Родитель
Сommit
5fe8a5e408
3 измененных файлов с 38 добавлено и 3 удалено
  1. 1 0
      CHANGELOG.md
  2. 13 3
      bin/v-change-dns-record
  3. 24 0
      test/test.bats

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
 ### Bugfixes
 
 - Disable /reset/ endpoint when POLICY_SYSTEM_PASSWORD_RESET = no
+- Prevent SOA count up after v-change-dns-records with no changes are made
 
 ## [1.4.17] - Service release 
 

+ 13 - 3
bin/v-change-dns-record

@@ -62,11 +62,15 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Make sure the variable for the optional parameter TTL is empty before parsing
+# We depend on that later on
+unset TTL
+
 # Parsing domain config
 line=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
 parse_object_kv_list "$line"
 
-if [ -z $type ]; then
+if [ -z "$type" ]; then
     type=$TYPE
 fi
 
@@ -87,8 +91,11 @@ fi
 is_dns_fqnd "$TYPE" "$dvalue"
 is_dns_nameserver_valid "$domain" "$TYPE" "$dvalue"
 
-# Deleting old record
-sed -i "/^ID='$id'/d" "$USER_DATA/dns/$domain.conf"
+if [[ "$RECORD" == "$record" ]] && [[ "$TYPE" == "$type" ]] && [[ "$PRIORITY" -eq "$priority" ]] \
+        && [[ "$VALUE" == "$dvalue" ]] && [[ "$SUSPENDED" == 'no' ]] && [[ "$TTL" -eq "$ttl" ]]; then
+    echo "No pending changes in DNS entry."
+    exit "$E_EXSIST"
+fi
 
 # Generating timestamp
 time_n_date=$(date +'%T %F')
@@ -99,6 +106,9 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
 dns_rec="ID='$id' RECORD='$record' TYPE='$type' PRIORITY='$priority'"
 dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
 [ -n "$ttl" ] && dns_rec="$dns_rec TTL='$ttl'"
+# Deleting old record
+sed -i "/^ID='$id'/d" $USER_DATA/dns/$domain.conf
+# Add new entry
 echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
 
 # Sorting records

+ 24 - 0
test/test.bats

@@ -1083,6 +1083,30 @@ function check_ip_not_banned(){
     refute_output
 }
 
+@test "DNS: Change DNS record" {
+  run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
+  assert_success
+  refute_output
+}
+
+@test "DNS: Change DNS record (no update)" {
+  run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
+  assert_failure $E_EXSIST
+}
+
+@test "DNS: Change DNS record id" {
+  run v-change-dns-record-id $user $domain 20 21
+  assert_success
+  refute_output
+  # Change back
+  run v-change-dns-record-id $user $domain 21 20
+}
+
+@test "DNS: Change DNS record id (no update)" {
+  run v-change-dns-record-id  $user $domain 20 20
+  assert_failure $E_EXSIST
+}
+
 @test "DNS: Delete domain record" {
     run v-delete-dns-record $user $domain 20
     assert_success