forked from outroll/vesta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv-rebuild-dns-domains
executable file
·92 lines (71 loc) · 2.15 KB
/
v-rebuild-dns-domains
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# info: rebuild dns domains
# options: USER [RESTART]
#
# The function rebuilds DNS configuration files.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
restart=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/func/rebuild.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER [RESTART]'
validate_format 'user'
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
if [ "$DNS_SYSTEM" = 'remote' ]; then
exit
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
user_domains=0
user_records=0
suspended_dns=0
conf="$USER_DATA/dns.conf"
# Defining user name servers
ns=$(get_user_value '$NS')
i=1
for nameserver in ${ns//,/ };do
eval ns$i="$nameserver"
i=$((i + 1))
done
# Get dns config path
if [ -e '/etc/named.conf' ]; then
dns_conf='/etc/named.conf'
fi
if [ -e '/etc/bind/named.conf' ]; then
dns_conf='/etc/bind/named.conf'
fi
# Remove old user's zone
sed -i "/\/$user\/conf\/dns/d" $dns_conf
# Starting loop
for domain in $(search_objects 'dns' 'DOMAIN' "*" 'DOMAIN'); do
rebuild_dns_domain_conf
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating counters
update_user_value "$user" '$U_DNS_DOMAINS' "$user_domains"
update_user_value "$user" '$U_DNS_RECORDS' "$user_records"
update_user_value "$user" '$SUSPENDED_DNS' "$suspended_dns"
# Restart named
if [ "$restart" != 'no' ]; then
$BIN/v-restart-dns
if [ $? -ne 0 ]; then
exit $E_RESTART
fi
fi
# Logging
log_event "$OK" "$EVENT"
exit