forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-change-web-domain-ftp-path
More file actions
executable file
·94 lines (75 loc) · 2.86 KB
/
v-change-web-domain-ftp-path
File metadata and controls
executable file
·94 lines (75 loc) · 2.86 KB
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
93
94
#!/bin/bash
# info: change path for ftp user.
# options: USER DOMAIN FTP_USER FTP_PATH
#
# The function changes ftp user path.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
domain_idn=$2
ftp_user=$3
ftp_path=$4
# Includes
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/conf/vesta.conf
# Additional argument formatting
format_domain
format_domain_idn
# TODO: $domain_idn not used in this script - maybe $domain should be converted to $doman_idn ?
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '4' "$#" 'USER DOMAIN FTP_USER FTP_PATH'
is_format_valid 'user' 'domain' 'ftp_user'
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
get_domain_values 'web'
if [ -z "$(echo $FTP_USER | tr ':' '\n' | grep ^$ftp_user$)" ]; then
echo "Error: account $ftp_user doesn't exist"
log_event "$E_NOTEXIST" "$ARGUMENTS"
exit $E_NOTEXIST
fi
ftp_path_a=$(readlink -f "$HOMEDIR/$user/web/$domain/$ftp_path")
if [ -z "$(echo $ftp_path_a |grep $HOMEDIR/$user/web/$domain)" ]; then
echo "Error: absolute path $ftp_path_a is invalid"
log_event "$E_INVALID" "$ARGUMENTS"
exit $E_INVALID
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# MKDIR if path doesn't exist
if [ ! -e "$ftp_path_a" ]; then
mkdir -p "$ftp_path_a"
chown $user:$user "$ftp_path_a"
chmod 751 "$ftp_path_a"
fi
# Chaning ftp user path
pw_str=$(grep -n "^$ftp_user:" /etc/passwd)
str=$(echo "$pw_str" | cut -f 1 -d :)
old_path=$(echo "$pw_str" | cut -f 7 -d :)
sed -i "$str s%$old_path%$ftp_path_a%g" /etc/passwd
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Transforming absolute path to relative
ftp_path_r=$(echo $ftp_path_a |sed "s%$HOMEDIR/$user/web/$domain%%")
# Rebuilding FTP variables
position=$(echo $FTP_USER |tr ':' '\n' |grep -n '' |grep ":$ftp_user$" |\
cut -f 1 -d:)
ftp_path=$(echo $FTP_PATH |tr ':' '\n' |grep -n '' |\
sed -e "s%^$position:.*%$position:$ftp_path_r%" |\
cut -f 2 -d :| sed -e ':a;N;$!ba;s/\n/:/g')
# Updating config
update_object_value 'web' 'DOMAIN' "$domain" '$FTP_PATH' "$ftp_path"
# Logging
log_history "changed path to $ftp_path_a for $ftp_user@$domain"
log_event "$OK" "$ARGUMENTS"
exit