/
v-change-user-ns
executable file
·88 lines (75 loc) · 2.54 KB
/
v-change-user-ns
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
#!/bin/bash
# info: change user nameservers
# options: USER NS1 NS2 [NS3] [NS4] [NS5] [NS6] [NS7] [NS8]
#
# example: v-change-user-ns ns1.domain.tld ns2.domain.tld
#
# This function for changing default nameservers for specific user.
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Argument definition
user=$1
ns1=$(echo $2 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns2=$(echo $3 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns3=$(echo $4 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns4=$(echo $5 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns5=$(echo $6 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns6=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns7=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g')
ns8=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g')
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking args
check_args '3' "$#" 'USER NS1 NS2 [NS3] [NS4] [NS5] [NS6] [NS7] [NS8]'
# Checking argument format
is_format_valid 'user' 'ns1' 'ns2'
ns="$ns1,$ns2"
if [ -n "$ns3" ]; then
is_format_valid 'ns3'
ns="$ns,$ns3"
fi
if [ -n "$ns4" ]; then
is_format_valid 'ns4'
ns="$ns,$ns4"
fi
if [ -n "$ns5" ]; then
is_format_valid 'ns5'
ns="$ns,$ns5"
fi
if [ -n "$ns6" ]; then
is_format_valid 'ns6'
ns="$ns,$ns6"
fi
if [ -n "$ns7" ]; then
is_format_valid 'ns7'
ns="$ns,$ns7"
fi
if [ -n "$ns8" ]; then
is_format_valid 'ns8'
ns="$ns,$ns8"
fi
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Changing ns values
update_user_value "$user" '$NS' "$ns"
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Logging
$BIN/v-log-action "$user" "Info" "DNS" "Updated DNS nameservers ($ns1 $ns2 $ns3 $ns4 $ns5 $ns6 $ns7 $ns8)."
log_event "$OK" "$ARGUMENTS"
exit