You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							101 lines
						
					
					
						
							3.3 KiB
						
					
					
				
			
		
		
	
	
							101 lines
						
					
					
						
							3.3 KiB
						
					
					
				#!/bin/bash
 | 
						|
# info: change path for ftp user.
 | 
						|
# options: USER DOMAIN FTP_USER FTP_PATH
 | 
						|
#
 | 
						|
# example: v-change-web-domain-ftp-path admin example.com /home/admin/example.com
 | 
						|
#
 | 
						|
# This function changes ftp user path.
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                Variables & Functions                     #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# Argument definition
 | 
						|
user=$1
 | 
						|
domain=$2
 | 
						|
domain_idn=$2
 | 
						|
ftp_user=$3
 | 
						|
ftp_path=$4
 | 
						|
 | 
						|
# 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
 | 
						|
# shellcheck source=/usr/local/hestia/func/domain.sh
 | 
						|
source $HESTIA/func/domain.sh
 | 
						|
# load config file
 | 
						|
source_conf "$HESTIA/conf/hestia.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
 | 
						|
 | 
						|
# Perform verification if read-only mode is enabled
 | 
						|
check_hestia_demo_mode
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                       Action                             #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# MKDIR if path doesn't exist
 | 
						|
if [ ! -e "$ftp_path_a" ]; then
 | 
						|
	$BIN/v-add-fs-directory "$user" "$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
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                       Hestia                             #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# 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
 | 
						|
$BIN/v-log-action "$user" "Info" "Web" "FTP account path changed (User: $ftp_user@domain, Path: $ftp_path_a)."
 | 
						|
log_event "$OK" "$ARGUMENTS"
 | 
						|
 | 
						|
exit
 |