Skip to content

Commit f91be28

Browse files
committed
Improve handling of dns records without explicit TTL values
Fix usage of missing 'rtype' var in v-change-dns-record Update changelog
1 parent 394c7e5 commit f91be28

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

CHANGELOG.md

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

44
## [CURRENT] - Development
55
### Features
6+
- Added support for configuring individual TTL per DNS record. Thanks to @jaapmarcus
67

78
### Bugfixes
89
- Disable Apache2 Server Status Module by default.

bin/v-add-dns-record

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,10 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
101101

102102
# Adding record
103103
zone="$USER_DATA/dns/$domain.conf"
104-
if [ "$ttl" == '' ]; then
105-
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
106-
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
107-
echo "$dns_rec" >> $zone;
108-
else
109-
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
110-
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date' TTL='$ttl'"
111-
echo "$dns_rec" >> $zone
112-
fi
104+
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
105+
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
106+
[ ! -z "$ttl" ] && dns_rec="$dns_rec TTL='$ttl'"
107+
echo "$dns_rec" >> $zone;
113108
chmod 660 $zone
114109

115110
# Sorting records

bin/v-change-dns-record

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,10 @@ time=$(echo "$time_n_date" |cut -f 1 -d \ )
8484
date=$(echo "$time_n_date" |cut -f 2 -d \ )
8585

8686
# Adding record
87-
zone="$USER_DATA/dns/$domain.conf"
88-
if [ "$ttl" == '' ]; then
89-
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
90-
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
91-
echo "$dns_rec" >> $zone;
92-
else
93-
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
94-
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date' TTL='$ttl'"
95-
echo "$dns_rec" >> $zone
96-
fi
87+
dns_rec="ID='$id' RECORD='$record' TYPE='$type' PRIORITY='$priority'"
88+
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
89+
[ ! -z "$ttl" ] && dns_rec="$dns_rec TTL='$ttl'"
90+
echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
9791

9892
# Sorting records
9993
sort_dns_records

bin/v-list-dns-records

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ json_list() {
2424
objects=$(grep ID $USER_DATA/dns/$domain.conf |wc -l)
2525
echo "{"
2626
while read str; do
27+
unset TTL
2728
parse_object_kv_list "$str"
29+
[ -z "$TTL" ] && TTL="$zone_ttl"
2830
VALUE=$(echo "$VALUE" |sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
2931
echo -n ' "'$ID'": {
3032
"RECORD": "'$RECORD'",
@@ -53,7 +55,9 @@ shell_list() {
5355
echo "ID^RECORD^TYPE^VALUE^DATE^TTL"
5456
echo "--^------^----^-----^----^----"
5557
while read str; do
58+
unset TTL
5659
parse_object_kv_list "$str"
60+
[ -z "$TTL" ] && TTL="$zone_ttl"
5761
echo "$ID^$RECORD^$TYPE^${VALUE:0:30}^$DATE^$TTL"
5862
done < <(cat $USER_DATA/dns/$domain.conf)
5963
}
@@ -62,7 +66,9 @@ shell_list() {
6266
plain_list() {
6367
IFS=$'\n'
6468
while read str; do
69+
unset TTL
6570
parse_object_kv_list "$str"
71+
[ -z "$TTL" ] && TTL="$zone_ttl"
6672
VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
6773
echo -ne "$ID\t$RECORD\t$TYPE\t$PRIORITY\t$VALUE\t"
6874
echo -e "$SUSPENDED\t$TIME\t$DATE\t$TTL"
@@ -74,7 +80,9 @@ csv_list() {
7480
IFS=$'\n'
7581
echo "ID,RECORD,TYPE,PRIORITY,VALUE,SUSPENDED,TIME,DATE,TTL"
7682
while read str; do
83+
unset TTL
7784
parse_object_kv_list "$str"
85+
[ -z "$TTL" ] && TTL="$zone_ttl"
7886
VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
7987
echo -n "$ID,$RECORD,$TYPE,$PRIORITY,\"$VALUE\","
8088
echo "$SUSPENDED,$TIME,$DATE,$TTL"
@@ -96,6 +104,8 @@ is_object_valid 'dns' 'DOMAIN' "$domain"
96104
# Action #
97105
#----------------------------------------------------------#
98106

107+
zone_ttl="$(get_object_value 'dns' 'DOMAIN' "$domain" '$TTL')"
108+
99109
# Listing data
100110
case $format in
101111
json) json_list ;;

func/domain.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ is_dns_domain_new() {
436436
update_domain_zone() {
437437
domain_param=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
438438
parse_object_kv_list "$domain_param"
439+
local zone_ttl="$TTL"
439440
SOA=$(idn --quiet -a -t "$SOA")
440441
if [ -z "$SERIAL" ]; then
441442
SERIAL=$(date +'%Y%m%d01')
@@ -456,11 +457,15 @@ update_domain_zone() {
456457
" > $zn_conf
457458
fields='$RECORD\t$TTL\tIN\t$TYPE\t$PRIORITY\t$VALUE'
458459
while read line ; do
460+
unset TTL
459461
IFS=$'\n'
460462
for key in $(echo $line|sed "s/' /'\n/g"); do
461463
eval ${key%%=*}="${key#*=}"
462464
done
463465

466+
# inherit zone TTL if record lacks explicit TTL value
467+
[ -z "$TTL" ] && TTL="$zone_ttl"
468+
464469
RECORD=$(idn --quiet -a -t "$RECORD")
465470
if [ "$TYPE" = 'CNAME' ] || [ "$TYPE" = 'MX' ]; then
466471
VALUE=$(idn --quiet -a -t "$VALUE")

0 commit comments

Comments
 (0)