#!/bin/bash # info: rebuild dns domains # options: USER [RESTART] # # The function rebuilds web configuration files. #----------------------------------------------------------# # Variable&Function # #----------------------------------------------------------# # Argument defenition user=$1 restart=$2 # Includes source $VESTA/func/main.sh source $VESTA/func/domain.sh source $VESTA/func/ip.sh source $VESTA/func/rebuild.sh source $VESTA/conf/vesta.conf #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# check_args '1' "$#" 'USER [RESTART]' validate_format 'user' is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM' is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" #----------------------------------------------------------# # Action # #----------------------------------------------------------# user_domains=0 user_ssl=0 user_aliases=0 suspended_web=0 conf=$USER_DATA/web.conf fields='$DOMAIN' nohead=1 domain_counter=0 # Adding log directory mkdir -p /var/log/$WEB_SYSTEM/domains chmod 771 /var/log/$WEB_SYSTEM/domains # Clean up old config rm -f $HOMEDIR/$user/conf/tmp_*.conf # Starting loop for domain in $(shell_list); do template=$(get_object_value 'web' 'DOMAIN' "$domain" '$BACKEND') if [ ! -z "$WEB_BACKEND" ]; then $BIN/v-add-web-domain-backend $user $domain $template fi ((++ domain_counter)) rebuild_web_domain_conf done # Touch vesta configs web_conf="/etc/$WEB_SYSTEM/conf.d/vesta.conf" touch $web_conf if [ ! -z "$PROXY_SYSTEM" ]; then proxy_conf="/etc/$PROXY_SYSTEM/conf.d/vesta.conf" touch $proxy_conf fi # Checking if there is at least 1 domain if [ "$domain_counter" -lt 1 ]; then # Deleting web configs rm -f $HOMEDIR/$user/conf/web/* sed -i "/.*\/$user\/.*$WEB_SYSTEM.conf/d" $web_conf if [ ! -z "$PROXY_SYSTEM" ]; then sed -i "/.*\/$user\/.*$PROXY_SYSTEM.conf/d" $proxy_conf fi else # Clean web configs sed -i "/.*\/$user\/.*.conf/d" $web_conf if [ ! -z "$PROXY_SYSTEM" ]; then sed -i "/.*\/$user\/.*.conf/d" $proxy_conf fi # Renaming tmp config tmp_conf="$HOMEDIR/$user/conf/web/tmp_$WEB_SYSTEM.conf" conf="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.conf" mv $tmp_conf $conf # Checking include web_include=$(grep "$conf" $web_conf ) if [ -z "$web_include" ] && [ "$WEB_SYSTEM" != 'nginx' ]; then echo "Include $conf" >> $web_conf fi if [ -z "$web_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then echo "include $conf;" >> $web_conf fi # Checking SSL if [ "$ssl_change" = 'yes' ]; then tmp_conf="$HOMEDIR/$user/conf/web/tmp_s$WEB_SYSTEM.conf" conf="$HOMEDIR/$user/conf/web/s$WEB_SYSTEM.conf" mv $tmp_conf $conf ssl_include=$(grep "$conf" $web_conf ) if [ -z "$ssl_include" ] && [ "$WEB_SYSTEM" != 'nginx' ]; then echo "Include $conf" >> $web_conf fi if [ -z "$ssl_include" ] && [ "$WEB_SYSTEM" = 'nginx' ]; then echo "include $conf;" >> $web_conf fi fi # Checking proxy if [ ! -z "$PROXY_SYSTEM" ]; then if [ "$proxy_change" = 'yes' ]; then tmp_conf="$HOMEDIR/$user/conf/web/tmp_$PROXY_SYSTEM.conf" conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf" mv $tmp_conf $conf proxy_include=$(grep "$conf" $proxy_conf ) if [ -z "$proxy_include" ]; then echo "include $conf;" >> $proxy_conf fi else conf="$HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf" sed -i "/.*\/$user\/.*$PROXY_SYSTEM.conf/d" $proxy_conf rm -f $HOMEDIR/$user/conf/web/$PROXY_SYSTEM.conf fi # Checking SSL proxy if [ "$proxy_change" = 'yes' ] && [ "$ssl_change" = 'yes' ]; then tmp_conf="$HOMEDIR/$user/conf/web/tmp_s$PROXY_SYSTEM.conf" conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf" mv $tmp_conf $conf proxy_include=$(grep "$conf" $proxy_conf ) if [ -z "$proxy_include" ]; then echo "include $conf;" >> $proxy_conf fi else conf="$HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf" sed -i "/.*\/$user\/.*s$PROXY_SYSTEM.conf/d" $proxy_conf rm -f $HOMEDIR/$user/conf/web/s$PROXY_SYSTEM.conf fi fi fi #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# # Updating counters update_user_value "$user" '$SUSPENDED_WEB' "$suspended_web" update_user_value "$user" '$U_WEB_DOMAINS' "$user_domains" update_user_value "$user" '$U_WEB_SSL' "$user_ssl" update_user_value "$user" '$U_WEB_ALIASES' "$user_aliases" # Restarting web server if [ "$restart" != 'no' ]; then $BIN/v-restart-web check_result $? "Web restart failed" >/dev/null if [ ! -z "$PROXY_SYSTEM" ]; then $BIN/v-restart-proxy check_result $? "Proxy restart failed" >/dev/null fi fi # Logging log_event "$OK" "$EVENT" exit