Skip to content

Commit 394c7e5

Browse files
authored
Feature DNS TTL hestiacp#494 (hestiacp#788)
* individual TTL value per dns record hestiacp#494 * Adding check valid format TTL, TTL prints now in edit record * Removed unwanted echo and enters * Removed empty return * Check if ttl is present Added check if ttl is present. If no TTL is present default values are used. For remote syncing zone="$USER_DATA/dns/$domain.conf" is used
1 parent c2eacdc commit 394c7e5

File tree

8 files changed

+67
-22
lines changed

8 files changed

+67
-22
lines changed

bin/v-add-dns-record

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add dns record
3-
# options: USER DOMAIN RECORD TYPE VALUE [PRIORITY] [ID] [RESTART]
3+
# options: USER DOMAIN RECORD TYPE VALUE [PRIORITY] [ID] [RESTART] [TTL]
44
#
55
# The call is used for adding new DNS record. Complex records of TXT, MX and
66
# SRV types can be used by a filling in the 'value' argument. The function also
@@ -23,6 +23,8 @@ dvalue=$(idn -t --quiet -u "$5" )
2323
priority=$6
2424
id=$7
2525
restart=$8
26+
ttl=$9
27+
2628
if [ -z "$priority" ]; then
2729
priority=10
2830
fi
@@ -69,7 +71,7 @@ format_domain_idn
6971
# Verifications #
7072
#----------------------------------------------------------#
7173

72-
check_args '5' "$#" 'USER DOMAIN RECORD TYPE VALUE [PRIORITY] [ID] [RESTART]'
74+
check_args '5' "$#" 'USER DOMAIN RECORD TYPE VALUE [PRIORITY] [ID] [RESTART] [TTL]'
7375
is_format_valid 'user' 'domain' 'record' 'rtype' 'dvalue'
7476
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
7577
is_object_valid 'user' 'USER' "$user"
@@ -82,6 +84,7 @@ is_format_valid 'id'
8284
is_object_new "dns/$domain" 'ID' "$id"
8385
is_dns_fqnd "$rtype" "$dvalue"
8486
is_dns_nameserver_valid "$domain" "$rtype" "$dvalue"
87+
is_format_valid 'ttl'
8588

8689
# Perform verification if read-only mode is enabled
8790
check_hestia_demo_mode
@@ -98,9 +101,15 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
98101

99102
# Adding record
100103
zone="$USER_DATA/dns/$domain.conf"
101-
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
102-
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
103-
echo "$dns_rec" >> $zone
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
104113
chmod 660 $zone
105114

106115
# Sorting records

bin/v-change-dns-record

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: change dns domain record
3-
# options: USER DOMAIN ID VALUE [PRIORITY] [RESTART]
3+
# options: USER DOMAIN ID VALUE [PRIORITY] [RESTART] [TTL]
44
#
55
# The function for changing DNS record.
66

@@ -19,6 +19,7 @@ type=$5
1919
dvalue=$(idn -t --quiet -u "$6" )
2020
priority=$7
2121
restart=$8
22+
ttl=$9
2223

2324
# Includes
2425
source $HESTIA/func/main.sh
@@ -35,14 +36,15 @@ format_domain_idn
3536
# Verifications #
3637
#----------------------------------------------------------#
3738

38-
check_args '6' "$#" 'USER DOMAIN ID RECORD TYPE VALUE [PRIORITY] [RESTART]'
39+
check_args '6' "$#" 'USER DOMAIN ID RECORD TYPE VALUE [PRIORITY] [RESTART] [TTL]'
3940
is_format_valid 'user' 'domain' 'id' 'record' 'type' 'dvalue'
4041
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
4142
is_object_valid 'user' 'USER' "$user"
4243
is_object_unsuspended 'user' 'USER' "$user"
4344
is_object_valid 'dns' 'DOMAIN' "$domain"
4445
is_object_unsuspended 'dns' 'DOMAIN' "$domain"
4546
is_object_valid "dns/$domain" 'ID' "$id"
47+
is_format_valid 'ttl'
4648

4749
# Perform verification if read-only mode is enabled
4850
check_hestia_demo_mode
@@ -82,9 +84,16 @@ time=$(echo "$time_n_date" |cut -f 1 -d \ )
8284
date=$(echo "$time_n_date" |cut -f 2 -d \ )
8385

8486
# Adding record
85-
dns_rec="ID='$id' RECORD='$record' TYPE='$type' PRIORITY='$priority'"
86-
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$time' DATE='$date'"
87-
echo "$dns_rec" >> $USER_DATA/dns/$domain.conf
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
8897

8998
# Sorting records
9099
sort_dns_records

bin/v-list-dns-records

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ json_list() {
3434
"ID": "'$ID'",
3535
"SUSPENDED": "'$SUSPENDED'",
3636
"TIME": "'$TIME'",
37-
"DATE": "'$DATE'"
37+
"DATE": "'$DATE'",
38+
"TTL": "'$TTL'"
3839
}'
3940
if [ "$i" -lt "$objects" ]; then
4041
echo ','
@@ -49,11 +50,11 @@ json_list() {
4950
# SHELL list function
5051
shell_list() {
5152
IFS=$'\n'
52-
echo "ID^RECORD^TYPE^VALUE^DATE"
53-
echo "--^------^----^-----^----"
53+
echo "ID^RECORD^TYPE^VALUE^DATE^TTL"
54+
echo "--^------^----^-----^----^----"
5455
while read str; do
5556
parse_object_kv_list "$str"
56-
echo "$ID^$RECORD^$TYPE^${VALUE:0:30}^$DATE"
57+
echo "$ID^$RECORD^$TYPE^${VALUE:0:30}^$DATE^$TTL"
5758
done < <(cat $USER_DATA/dns/$domain.conf)
5859
}
5960

@@ -64,19 +65,19 @@ plain_list() {
6465
parse_object_kv_list "$str"
6566
VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
6667
echo -ne "$ID\t$RECORD\t$TYPE\t$PRIORITY\t$VALUE\t"
67-
echo -e "$SUSPENDED\t$TIME\t$DATE"
68+
echo -e "$SUSPENDED\t$TIME\t$DATE\t$TTL"
6869
done < <(cat $USER_DATA/dns/$domain.conf)
6970
}
7071

7172
# CSV list function
7273
csv_list() {
7374
IFS=$'\n'
74-
echo "ID,RECORD,TYPE,PRIORITY,VALUE,SUSPENDED,TIME,DATE"
75+
echo "ID,RECORD,TYPE,PRIORITY,VALUE,SUSPENDED,TIME,DATE,TTL"
7576
while read str; do
7677
parse_object_kv_list "$str"
7778
VALUE=$(echo "$VALUE" |sed -e "s/%quote%/\\'/g")
7879
echo -n "$ID,$RECORD,$TYPE,$PRIORITY,\"$VALUE\","
79-
echo "$SUSPENDED,$TIME,$DATE"
80+
echo "$SUSPENDED,$TIME,$DATE,$TTL"
8081
done < <(cat $USER_DATA/dns/$domain.conf)
8182
}
8283

web/add/dns/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@
122122
$v_type = escapeshellarg($_POST['v_type']);
123123
$v_val = escapeshellarg($_POST['v_val']);
124124
$v_priority = escapeshellarg($_POST['v_priority']);
125+
$v_ttl = escapeshellarg($_POST['v_ttl']);
125126

126127
// Add dns record
127128
if (empty($_SESSION['error_msg'])) {
128-
exec (HESTIA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
129+
exec (HESTIA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority." '' false ".$v_ttl, $output, $return_var);
129130
check_return_code($return_var,$output);
130131
unset($output);
131132
$v_type = $_POST['v_type'];

web/edit/dns/index.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
}
7979
$v_date = $data[$v_record_id]['DATE'];
8080
$v_time = $data[$v_record_id]['TIME'];
81+
$v_ttl = $data[$v_record_id]['TTL'];
8182
}
8283

8384
// Check POST request for dns domain
@@ -161,12 +162,13 @@
161162
$v_record_id = escapeshellarg($_POST['v_record_id']);
162163

163164
// Change dns record
164-
if (($v_rec != $_POST['v_rec']) || ($v_type != $_POST['v_type']) || ($v_val != $_POST['v_val']) || ($v_priority != $_POST['v_priority']) && (empty($_SESSION['error_msg']))) {
165+
if (($v_rec != $_POST['v_rec']) || ($v_type != $_POST['v_type']) || ($v_val != $_POST['v_val']) || ($v_priority != $_POST['v_priority']) || ($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
165166
$v_rec = escapeshellarg($_POST['v_rec']);
166167
$v_type = escapeshellarg($_POST['v_type']);
167168
$v_val = escapeshellarg($_POST['v_val']);
168169
$v_priority = escapeshellarg($_POST['v_priority']);
169-
exec (HESTIA_CMD."v-change-dns-record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
170+
$v_ttl = escapeshellarg($_POST['v_ttl']);
171+
exec (HESTIA_CMD."v-change-dns-record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority." false ".$v_ttl, $output, $return_var);
170172
check_return_code($return_var,$output);
171173
$v_rec = $_POST['v_rec'];
172174
$v_type = $_POST['v_type'];

web/templates/admin/add_dns_rec.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@
120120
<input type="text" size="20" class="vst-input" name="v_priority" value="<?=htmlentities(trim($v_priority, "'"))?>">
121121
</td>
122122
</tr>
123+
<tr>
124+
<td class="vst-text input-label">
125+
<?php print __('TTL');?> <span class="optional">(<?php print __('optional');?>)</span>
126+
</td>
127+
</tr>
128+
<tr>
129+
<td>
130+
<input type="text" size="20" class="vst-input" name="v_ttl" value="<?=htmlentities(trim($v_ttl, "'"))?>">
131+
</td>
132+
</tr>
123133
</table>
124134
<table class="data-col2">
125135
</table>

web/templates/admin/edit_dns_rec.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@
130130
<input type="text" size="20" class="vst-input" name="v_priority" value="<?=htmlentities(trim($v_priority, "'"))?>">
131131
</td>
132132
</tr>
133+
<tr>
134+
<td class="vst-text input-label">
135+
<?php print __('TTL');?> <span class="optional">(<?=__('optional');?>)</span>
136+
</td>
137+
</tr>
138+
<tr>
139+
<td>
140+
<input type="text" size="20" class="vst-input" name="v_ttl" value="<?=htmlentities(trim($v_ttl, "'"))?>">
141+
</td>
142+
</tr>
133143
<tr>
134144
<td class="vst-text input-label">
135145
<?php print __('Record Number');?> <span class="optional">(<?=__('internal');?>)</span>

web/templates/admin/list_dns_rec.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
<div class="clearfix l-unit__stat-col--left compact text-right"><b>&nbsp;</b></div>
4848
<div class="clearfix l-unit__stat-col--left compact text-center"><b><?php print __('Type');?></b></div>
4949
<div class="clearfix l-unit__stat-col--left compact"><b><?php print __('Priority');?></b></div>
50-
<div class="clearfix l-unit__stat-col--left wide-7"><b><?php print __('IP or Value');?></b></div>
50+
<div class="clearfix l-unit__stat-col--left compact"><b><?php print __('TTL');?></b></div>
51+
<div class="clearfix l-unit__stat-col--left wide-6"><b><?php print __('IP or Value');?></b></div>
5152
</div>
5253
</div>
5354

@@ -92,7 +93,9 @@
9293
<!-- END QUICK ACTION TOOLBAR AREA -->
9394
<div class="clearfix l-unit__stat-col--left compact text-center"><b><?=$data[$key]['TYPE']?></b></div>
9495
<div class="clearfix l-unit__stat-col--left compact"><?=$data[$key]['PRIORITY']?>&nbsp;</div>
95-
<div class="clearfix l-unit__stat-col--left wide-7"><?=htmlspecialchars($data[$key]['VALUE'], ENT_QUOTES, 'UTF-8')?></div>
96+
<div class="clearfix l-unit__stat-col--left compact"><?php if($data[$key]['TTL'] == ''){ echo __('Default'); }else{ echo $data[$key]['TTL'];} ?></div>
97+
98+
<div class="clearfix l-unit__stat-col--left wide-6"><?=htmlspecialchars($data[$key]['VALUE'], ENT_QUOTES, 'UTF-8')?></div>
9699
</div>
97100
</div>
98101
<?}?>

0 commit comments

Comments
 (0)