#!/bin/bash # info: delete web domain # options: user domain # # The call of function leads to the removal of domain and all its components # (statistics, folders contents, ssl certificates, etc.). This operation is # not fully supported by "undo" function, so the data recovery is possible # only with a help of reserve copy. #----------------------------------------------------------# # Variable&Function # #----------------------------------------------------------# # Argument defenition user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") # Importing variables source $VESTA/conf/vars.conf source $V_CONF/vesta.conf source $V_FUNC/shared.func source $V_FUNC/domain.func source $V_FUNC/ip.func #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# # Checking arg number check_args '2' "$#" 'user domain' # Checking argument format format_validation 'user' 'domain' # Checking web system is enabled is_system_enabled 'web' # Checking user is_user_valid # Checking user is active is_user_suspended # Checking domain exist is_web_domain_valid # Checking domain is not suspened is_domain_suspended 'web' #----------------------------------------------------------# # Action # #----------------------------------------------------------# # Get template name get_web_domain_values tpl_file="$V_WEBTPL/apache_$TPL.tpl" conf="$V_HOME/$user/conf/httpd.conf" # Deleting domain del_web_config # Checking ssl if [ "$SSL" = 'yes' ]; then tpl_file="$V_WEBTPL/apache_$TPL.stpl" conf="$V_HOME/$user/conf/shttpd.conf" del_web_config # Deleting certificates rm -f $V_HOME/$user/conf/ssl.$domain.* rm -f $V_USERS/$user/ssl/$domain.* fi # Checking nginx if [ ! -z "$NGINX" ]; then tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl" conf="$V_HOME/$user/conf/nginx.conf" del_web_config if [ "$SSL" = 'yes' ]; then proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;" tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl" conf="$V_HOME/$user/conf/snginx.conf" del_web_config fi fi # Checking stats if [ ! -z "$STATS" ] && [ "$STATS" != 'no' ]; then # Parsing pipe line line=$(grep -n "$STATS.$domain.conf" $V_QUEUE/stats.pipe | \ cut -f 1 -d : | head -n 1 ) # Deleting pipe command if [ ! -z "$line" ]; then sed -i "$line d" $V_QUEUE/stats.pipe fi # Deleteing config rm -f $V_HOME/$user/conf/$STATS.$domain.conf fi # Deleting directory rm -rf $V_HOME/$user/web/$domain # Deleting logs rm -rf /var/log/httpd/domains/$domain.log* rm -rf /var/log/httpd/domains/$domain.bytes rm -rf /var/log/httpd/domains/$domain.error* #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# # Deleting domain del_web_domain # Checking last ssl domain ssl_dom=$(grep "SSL='yes'" $V_USERS/$user/web.conf | wc -l) if [ "$ssl_dom" -eq '0' ]; then sed -i "s/ Include /#Include /" $V_HOME/$user/conf/httpd.conf fi # Checking last domain domains=$(wc -l $V_USERS/$user/web.conf|cut -f 1 -d ' ') if [ "$domains" -eq '0' ]; then conf='/etc/httpd/conf.d/vesta.conf' line=$(grep -n "$V_HOME/$user/conf/httpd.conf" $conf | cut -f 1 -d : ) if [ ! -z "$line" ]; then sed -i "$line d" $conf fi fi # Checking last nginx domain conf='/etc/nginx/conf.d/vesta_users.conf' last_nginx=$(grep -v "NGINX=''" $V_USERS/$user/web.conf) last_snginx=$(echo "$last_nginx" | grep "SSL='yes'") if [ -z "$last_snginx" ]; then sline=$(grep -n "$V_HOME/$user/conf/snginx.conf" $conf | cut -f 1 -d : ) if [ ! -z "$sline" ]; then sed -i "$sline d" $conf fi rm -f $V_HOME/$user/conf/snginx.conf fi if [ -z "$last_nginx" ]; then line=$(grep -n "$V_HOME/$user/conf/nginx.conf" $conf | cut -f 1 -d : ) if [ ! -z "$line" ]; then sed -i "$line d" $conf fi rm -f $V_HOME/$user/conf/nginx.conf fi # Decreasing ip value decrease_ip_value "$IP" # Decreasing domain value decrease_user_value "$user" '$U_WEB_DOMAINS' # Adding task to the vesta pipe restart_schedule 'web' # Logging log_history "$V_EVENT" log_event 'system' "$V_EVENT" exit