mirror of
https://github.com/serghey-rodin/vesta.git
synced 2024-12-03 19:00:24 -08:00
89 lines
2.7 KiB
Bash
Executable File
89 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# info: delete webdomain ftp account
|
|
# options: USER DOMAIN FTP_USER
|
|
#
|
|
# The function deletes additional ftp account.
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Variable&Function #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
user=$1
|
|
domain=$2
|
|
domain_idn=$2
|
|
ftp_user=$3
|
|
|
|
# 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 '3' "$#" 'USER DOMAIN FTP_USER'
|
|
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
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Deleting ftp user
|
|
/usr/sbin/userdel $ftp_user >> /dev/null 2>&1
|
|
if [ "$?" != 0 ]; then
|
|
sed -i "/^$ftp_user:/d" /etc/passwd
|
|
sed -i "/^$ftp_user:/d" /etc/shadow
|
|
fi
|
|
|
|
# Deleting sftp jail
|
|
if [ ! -z "$SFTPJAIL_KEY" ]; then
|
|
$BINv-delete-user-sftp-jail $ftp_user
|
|
fi
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
# Rebuilding FTP variables
|
|
position=$(echo $FTP_USER |tr ':' '\n' |grep -n '' |grep ":$ftp_user$" |\
|
|
cut -f 1 -d:)
|
|
ftp_user=$(echo $FTP_USER |tr ':' '\n' |grep -n '' |grep -v "^$position:" |\
|
|
cut -f 2 -d :| sed -e "/^$/d"| sed -e ':a;N;$!ba;s/\n/:/g')
|
|
ftp_md5=$(echo $FTP_MD5 |tr ':' '\n' |grep -n '' |grep -v "^$position:" |\
|
|
cut -f 2 -d :| sed -e ':a;N;$!ba;s/\n/:/g')
|
|
ftp_path=$(echo $FTP_PATH |tr ':' '\n' |grep -n '' |grep -v "^$position:" |\
|
|
cut -f 2 -d :| sed -e ':a;N;$!ba;s/\n/:/g')
|
|
|
|
# Update config
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$FTP_USER' "$ftp_user"
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$FTP_MD5' "$ftp_md5"
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$FTP_PATH' "$ftp_path"
|
|
|
|
# Logging
|
|
log_history "deleted ftp account ${3} for $domain"
|
|
log_event "$OK" "$ARGUMENTS"
|
|
|
|
exit
|