Skip to content

Commit fe71ef2

Browse files
committed
improved dns nameservers section
1 parent d66f301 commit fe71ef2

19 files changed

+138
-90
lines changed

bin/v_add_dns_domain

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add dns domain
3-
# options: user domain ip [template] [exp] [soa] [ttl]
3+
# options: user domain ip [template] [ns1] [ns2] [ns3] [ns4]
44
#
55
# The function adds DNS zone with records defined in the template. If the exp
66
# argument isn't stated, the expiration date value will be set to next year.
@@ -21,10 +21,11 @@ domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
2121
domain_idn=$(idn -t --quiet -a "$domain")
2222
ip=$3
2323
template=$4
24-
next_year=$(date +%F -d "+ 1 year")
25-
exp=${5-$next_year}
26-
soa=$6
27-
ttl=${7-14400}
24+
ns1=$5
25+
ns2=$6
26+
ns3=$7
27+
ns4=$8
28+
restart=$9
2829

2930
# Includes
3031
source $VESTA/conf/vesta.conf
@@ -36,8 +37,8 @@ source $VESTA/func/domain.sh
3637
# Verifications #
3738
#----------------------------------------------------------#
3839

39-
check_args '3' "$#" 'user domain ip [template] [exp] [soa] [ttl]'
40-
validate_format 'user' 'domain' 'ip' 'exp' 'ttl'
40+
check_args '3' "$#" 'user domain ip [template] [ns1] [ns2] [ns3] [ns4]'
41+
validate_format 'user' 'domain' 'ip'
4142
is_system_enabled "$DNS_SYSTEM"
4243
is_object_valid 'user' 'USER' "$user"
4344
is_object_unsuspended 'user' 'USER' "$user"
@@ -51,23 +52,42 @@ else
5152
is_dns_template_valid
5253
fi
5354

55+
if [ ! -z "$ns1" ]; then
56+
ns1=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
57+
validate_format 'ns1'
58+
fi
59+
if [ ! -z "$ns2" ]; then
60+
ns2=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
61+
validate_format 'ns2'
62+
fi
63+
64+
if [ ! -z "$ns3" ]; then
65+
ns3=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
66+
validate_format 'ns3'
67+
fi
68+
if [ ! -z "$ns4" ]; then
69+
ns4=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
70+
validate_format 'ns4'
71+
fi
72+
5473

5574
#----------------------------------------------------------#
5675
# Action #
5776
#----------------------------------------------------------#
5877

5978
# Defining variables
60-
i=1
61-
ns=$(get_user_value '$NS')
62-
for nameserver in ${ns//,/ };do
63-
eval ns$i=$nameserver
64-
(( ++i))
65-
done
66-
67-
# Define soa
68-
if [ -z "$soa" ]; then
69-
soa="$ns1"
79+
if [ -z $ns2 ]; then
80+
i=1
81+
ns=$(get_user_value '$NS')
82+
for nameserver in ${ns//,/ };do
83+
eval ns$i=$nameserver
84+
(( ++i))
85+
done
7086
fi
87+
soa="$ns1"
88+
exp=$(date +%F -d "+ 1 year")
89+
ttl=14400
90+
7191

7292
# Adding zone to dns dir
7393
cat $DNSTPL/$template.tpl |\
@@ -78,10 +98,6 @@ cat $DNSTPL/$template.tpl |\
7898
-e "s/%ns2%/$ns2/g" \
7999
-e "s/%ns3%/$ns3/g" \
80100
-e "s/%ns4%/$ns4/g" \
81-
-e "s/%ns5%/$ns5/g" \
82-
-e "s/%ns6%/$ns6/g" \
83-
-e "s/%ns7%/$ns7/g" \
84-
-e "s/%ns8%/$ns8/g" \
85101
-e "s/%time%/$TIME/g" \
86102
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
87103
chmod 660 $USER_DATA/dns/$domain.conf
@@ -116,7 +132,9 @@ increase_user_value "$user" '$U_DNS_DOMAINS'
116132
increase_user_value "$user" '$U_DNS_RECORDS' "$records"
117133

118134
# Restart named
119-
$BIN/v_restart_dns "$EVENT"
135+
if [ "$restart" != 'no' ]; then
136+
$BIN/v_restart_dns "$EVENT"
137+
fi
120138

121139
# Logging
122140
log_history "$EVENT"

bin/v_add_dns_domain_record

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ domain=$(idn -t --quiet -u "$2" )
1818
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
1919
domain_idn=$(idn -t --quiet -a "$domain")
2020
record=$(idn -t --quiet -u "$3" )
21-
record=$(echo $record | tr '[:upper:]' '[:lower:]')
21+
record=$(echo "$record" | tr '[:upper:]' '[:lower:]')
2222
rtype=$(echo "$4"| tr '[:lower:]' '[:upper:]')
2323
dvalue=$(idn -t --quiet -u "$5" )
24-
dvalue=$(echo $dvalue | tr '[:upper:]' '[:lower:]')
24+
dvalue=$(echo "$dvalue" | tr '[:upper:]' '[:lower:]')
2525
priority=$6
2626
id=$7
2727

bin/v_change_dns_domain_exp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ is_object_unsuspended 'dns' 'DOMAIN' "$domain"
4242
update_object_value 'dns' 'DOMAIN' "$domain" '$EXP' "$exp"
4343

4444

45-
4645
#----------------------------------------------------------#
4746
# Vesta #
4847
#----------------------------------------------------------#

bin/v_change_dns_domain_soa

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ user=$1
1515
domain=$(idn -t --quiet -u "$2" )
1616
domain_idn=$(idn -t --quiet -a "$domain")
1717
soa=$(echo $3 | sed -e 's/\.*$//g' -e 's/^\.*//g')
18+
restart=$4
1819

1920
# Includes
2021
source $VESTA/conf/vesta.conf
@@ -51,7 +52,9 @@ update_domain_zone
5152
#----------------------------------------------------------#
5253

5354
# Restart named
54-
$BIN/v_restart_dns "$EVENT"
55+
if [ "$restart" != 'no' ]; then
56+
$BIN/v_restart_dns "$EVENT"
57+
fi
5558

5659
# Logging
5760
log_history "$EVENT"

bin/v_change_dns_domain_tpl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ cat $DNSTPL/$template.tpl |\
6363
-e "s/%ns2%/$ns2/g" \
6464
-e "s/%ns3%/$ns3/g" \
6565
-e "s/%ns4%/$ns4/g" \
66-
-e "s/%ns5%/$ns5/g" \
67-
-e "s/%ns6%/$ns6/g" \
68-
-e "s/%ns7%/$ns7/g" \
69-
-e "s/%ns8%/$ns8/g" \
7066
-e "s/%time%/$TIME/g" \
7167
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
7268

bin/v_change_dns_domain_ttl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ user=$1
1414
domain=$(idn -t --quiet -u "$2" )
1515
domain_idn=$(idn -t --quiet -a "$domain")
1616
ttl=$3
17+
restart=$4
1718

1819
# Includes
1920
source $VESTA/conf/vesta.conf
@@ -50,7 +51,9 @@ update_domain_zone
5051
#----------------------------------------------------------#
5152

5253
# Restart named
53-
$BIN/v_restart_dns "$EVENT"
54+
if [ "$restart" != 'no' ]; then
55+
$BIN/v_restart_dns "$EVENT"
56+
fi
5457

5558
# Logging
5659
log_history "$EVENT"

bin/v_change_user_ns

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: change user nameservers
3-
# options: user ns1 ns2 [ns3] [ns4] [ns5] [ns6] [ns7] [ns8]
3+
# options: user ns1 ns2 [ns3] [ns4]
44
#
55
# The function for changing default nameservers for speciefic user.
66

@@ -15,10 +15,6 @@ ns1=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
1515
ns2=$(echo $3 | sed -e 's/\.*$//g' -e 's/^\.*//g')
1616
ns3=$4
1717
ns4=$5
18-
ns5=$6
19-
ns6=$7
20-
ns7=$8
21-
ns8=$9
2218

2319
# Includes
2420
source $VESTA/conf/vesta.conf
@@ -30,7 +26,7 @@ source $VESTA/func/main.sh
3026
#----------------------------------------------------------#
3127

3228
# Checking args
33-
check_args '3' "$#" 'user ns1 ns2 [ns3] [ns4] [ns5] [ns6] [ns7] [ns8]'
29+
check_args '3' "$#" 'user ns1 ns2 [ns3] [ns4]'
3430

3531
# Checking argument format
3632
validate_format 'user' 'ns1' 'ns2'
@@ -42,22 +38,6 @@ if [ ! -z "$ns4" ]; then
4238
ns4=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
4339
validate_format 'ns4'
4440
fi
45-
if [ ! -z "$ns5" ]; then
46-
ns5=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
47-
validate_format 'ns5'
48-
fi
49-
if [ ! -z "$ns6" ]; then
50-
ns6=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
51-
validate_format 'ns6'
52-
fi
53-
if [ ! -z "$ns7" ]; then
54-
ns7=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
55-
validate_format 'ns7'
56-
fi
57-
if [ ! -z "$ns8" ]; then
58-
ns8=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g')
59-
validate_format 'ns8'
60-
fi
6141

6242
is_object_valid 'user' 'USER' "$user"
6343
is_object_unsuspended 'user' 'USER' "$user"
@@ -68,7 +48,7 @@ is_object_unsuspended 'user' 'USER' "$user"
6848
#----------------------------------------------------------#
6949

7050
# Merging values
71-
ns="$ns1,$ns2,$ns3,$ns4,$ns5,$ns6,$ns7,$ns8"
51+
ns="$ns1,$ns2,$ns3,$ns4"
7252
ns=$(echo "$ns"|sed -e "s/,,//g" -e "s/,$//")
7353

7454
# Changing ns values

bin/v_get_user_value

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,4 @@ echo "$value"
4242
# Vesta #
4343
#----------------------------------------------------------#
4444

45-
# Logging
46-
log_event "$OK" "$EVENT"
47-
4845
exit

bin/v_rebuild_dns_domains

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ for domain in $(search_objects 'dns' 'DOMAIN' "*" 'DOMAIN'); do
7171
-e "s/%ns2%/$ns2/g" \
7272
-e "s/%ns3%/$ns3/g" \
7373
-e "s/%ns4%/$ns4/g" \
74-
-e "s/%ns5%/$ns5/g" \
75-
-e "s/%ns6%/$ns6/g" \
76-
-e "s/%ns7%/$ns7/g" \
77-
-e "s/%ns8%/$ns8/g" \
7874
-e "s/%time%/$TIME/g" \
7975
-e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf
8076
fi

func/main.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,6 @@ validate_format(){
734734
ns2) validate_format_domain "$arg" ;;
735735
ns3) validate_format_domain "$arg" ;;
736736
ns4) validate_format_domain "$arg" ;;
737-
ns5) validate_format_domain "$arg" ;;
738-
ns6) validate_format_domain "$arg" ;;
739-
ns7) validate_format_domain "$arg" ;;
740-
ns8) validate_format_domain "$arg" ;;
741737
package) validate_format_username "$arg" "$arg_name" ;;
742738
password) validate_format_password "$arg" ;;
743739
port) validate_format_int "$arg" ;;

0 commit comments

Comments
 (0)