|
| 1 | +#!/bin/bash |
| 2 | +# info: deliting web domain nginx config |
| 3 | + |
| 4 | +#----------------------------------------------------------# |
| 5 | +# Variable&Function # |
| 6 | +#----------------------------------------------------------# |
| 7 | + |
| 8 | +# Argument defenition |
| 9 | +user="$1" |
| 10 | +domain=$(idn -t --quiet -u "$2" ) |
| 11 | +domain_idn=$(idn -t --quiet -a "$domain") |
| 12 | + |
| 13 | +# Importing variables |
| 14 | +source $VESTA/conf/vars.conf |
| 15 | +source $V_FUNC/shared_func.sh |
| 16 | +source $V_FUNC/domain_func.sh |
| 17 | + |
| 18 | + |
| 19 | +#----------------------------------------------------------# |
| 20 | +# Verifications # |
| 21 | +#----------------------------------------------------------# |
| 22 | + |
| 23 | +# Checking arg number |
| 24 | +check_args '2' "$#" 'user domain' |
| 25 | + |
| 26 | +# Checking argument format |
| 27 | +format_validation 'user' 'domain' |
| 28 | + |
| 29 | +# Checking web system is enabled |
| 30 | +is_system_enabled 'web' |
| 31 | + |
| 32 | +# Checking user |
| 33 | +is_user_valid |
| 34 | + |
| 35 | +# Checking user is active |
| 36 | +is_user_suspended |
| 37 | + |
| 38 | +# Checking domain exist |
| 39 | +is_web_domain_valid |
| 40 | + |
| 41 | +# Checking domain is not suspened |
| 42 | +is_domain_suspended 'web_domains' |
| 43 | + |
| 44 | +# Checking ssl is added |
| 45 | +is_web_domain_value_exist '$NGINX' |
| 46 | + |
| 47 | + |
| 48 | +#----------------------------------------------------------# |
| 49 | +# Action # |
| 50 | +#----------------------------------------------------------# |
| 51 | + |
| 52 | +# Get domain values |
| 53 | +tpl_name=$(get_web_domain_value '$NGINX') |
| 54 | +tpl_file="$V_WEBTPL/ngingx_vhost_$tpl_name.tpl" |
| 55 | +conf="$V_HOME/$user/conf/nginx.conf" |
| 56 | +ext=$(get_web_domain_value '$NGINX_EXT' ) |
| 57 | + |
| 58 | +# Deleting domain |
| 59 | +del_web_config |
| 60 | + |
| 61 | +# Checking ssl |
| 62 | +cert=$(get_web_domain_value '$SSL_CERT') |
| 63 | +if [ ! -z "$cert" ]; then |
| 64 | + tpl_file="$V_WEBTPL/ngingx_vhost_$tpl_name.stpl" |
| 65 | + conf="$V_HOME/$user/conf/snginx.conf" |
| 66 | + del_web_config |
| 67 | +fi |
| 68 | + |
| 69 | + |
| 70 | +#----------------------------------------------------------# |
| 71 | +# Vesta # |
| 72 | +#----------------------------------------------------------# |
| 73 | + |
| 74 | +# Deleting nginx keys |
| 75 | +update_web_domain_value '$NGINX' '' |
| 76 | +update_web_domain_value '$NGINX_EXT' '' |
| 77 | + |
| 78 | +# Checking last nginx domain |
| 79 | +conf='/etc/nginx/conf.d/vesta_users.conf' |
| 80 | +last_nginx=$(grep -v "NGINX=''" $V_USERS/$user/web_domains.conf) |
| 81 | +last_snginx=$(echo "$last_nginx" | grep -v "SSL_CERT=''") |
| 82 | +if [ -z "$last_snginx" ]; then |
| 83 | + sline=$(grep -n "$V_HOME/$user/conf/snginx.conf" $conf | cut -f 1 -d : ) |
| 84 | + if [ ! -z "$sline" ]; then |
| 85 | + sed -i "$sline d" $conf |
| 86 | + fi |
| 87 | + rm -f $V_HOME/$user/conf/snginx.conf |
| 88 | +fi |
| 89 | + |
| 90 | +if [ -z "$last_nginx" ]; then |
| 91 | + line=$(grep -n "$V_HOME/$user/conf/nginx.conf" $conf | cut -f 1 -d : ) |
| 92 | + if [ ! -z "$line" ]; then |
| 93 | + sed -i "$line d" $conf |
| 94 | + fi |
| 95 | + rm -f $V_HOME/$user/conf/nginx.conf |
| 96 | +fi |
| 97 | + |
| 98 | +# Adding task to the vesta pipe |
| 99 | +restart_schedule 'web' |
| 100 | + |
| 101 | +# Logging |
| 102 | +log_history "$V_EVENT" "v_add_web_domain_nginx $user $domain $tpl_name $ext" |
| 103 | +log_event 'system' "$V_EVENT" |
| 104 | + |
| 105 | +exit $OK |
0 commit comments