Skip to content

Commit 31cf0b0

Browse files
committed
new funcion del_web_domain_nginx
1 parent 0c30b54 commit 31cf0b0

File tree

5 files changed

+123
-22
lines changed

5 files changed

+123
-22
lines changed

bin/v_change_web_domain_tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
5757
conf="$V_HOME/$user/conf/httpd.conf"
5858

5959
# Deleting domain
60-
httpd_del_config
60+
del_web_config
6161

6262
# Checking ssl
6363
cert=$(get_web_domain_value '$SSL_CERT')
@@ -68,7 +68,7 @@ if [ ! -z "$cert" ]; then
6868
conf="$V_HOME/$user/conf/shttpd.conf"
6969

7070
# Deleting domain
71-
httpd_del_config
71+
del_web_config
7272
fi
7373

7474
# Defining variables for template replace

bin/v_del_web_domain

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
5454
conf="$V_HOME/$user/conf/httpd.conf"
5555

5656
# Deleting domain
57-
httpd_del_config
58-
57+
del_web_config
58+
exit
5959
# Checking ssl
6060
cert=$(get_web_domain_value '$SSL_CERT')
6161
if [ ! -z "$cert" ]; then
@@ -65,7 +65,7 @@ if [ ! -z "$cert" ]; then
6565
conf="$V_HOME/$user/conf/shttpd.conf"
6666

6767
# Deleting domain
68-
httpd_del_config
68+
del_web_config
6969
fi
7070

7171
# Checking stats

bin/v_del_web_domain_nginx

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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

bin/v_del_web_domain_ssl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
5555
conf="$V_HOME/$user/conf/shttpd.conf"
5656

5757
# Deleting domain
58-
httpd_del_config
58+
del_web_config
5959

6060

6161
#----------------------------------------------------------#
@@ -71,10 +71,10 @@ update_web_domain_value '$SSL_HOME' ''
7171
update_web_domain_value '$SSL_CERT' ''
7272

7373
# Checking last ssl domain
74-
ssl_dom=$(grep "SSL='yes'" $V_USERS/$user/web_domains.conf | wc -l)
74+
ssl_dom=$(grep -v "SSL_CERT=''" $V_USERS/$user/web_domains.conf)
7575
main_conf='/etc/httpd/conf.d/vesta.conf'
7676
conf="$V_HOME/$user/conf/shttpd.conf"
77-
if [ "$ssl_dom" -eq '0' ]; then
77+
if [ -z "$ssl_dom" ]; then
7878
sed -i "/Include ${conf////\/}/d" $main_conf
7979
rm -f $conf
8080
fi

func/domain_func.sh

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,30 +459,26 @@ is_dns_domain_value_exist() {
459459
}
460460

461461

462-
httpd_del_config() {
463-
# Get ServerName line
464-
serv_line=$(grep -n 'ServerName %domain_idn%' "$tpl_file" |cut -f 1 -d :)
462+
del_web_config() {
463+
# Get servername line in template
464+
serv_line=$(grep -ni 'Name %domain_idn%' "$tpl_file" |cut -f 1 -d :)
465465

466-
# Get tpl_file last line
466+
# Get last template line
467467
last_line=$(wc -l $tpl_file|cut -f 1 -d ' ')
468468

469-
# Get before line
470-
bfr_line=$((serv_line - 1))
471-
472-
# Parsing httpd.conf
473-
str=$(grep -B $bfr_line -n "ServerName $domain_idn" $conf |\
474-
grep '<VirtualHost')
469+
# Parsing config
470+
str=$(grep -ni "Name $domain_idn" $conf | cut -f 1 -d :)
475471

476472
# Checking result
477-
if [ -z "$str" ] || [ -z "$serv_line" ] || [ -z "$bfr_line" ]; then
473+
if [ -z "$str" ] || [ -z "$serv_line" ]; then
478474
echo "Error: httpd parsing error"
479475
log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
480476
exit $E_PARSE_ERROR
481477
fi
482478

483-
# String number
484-
top_line=$(echo $str | sed -e "s/-/+/" | cut -f 1 -d '+')
485-
bottom_line=$((top_line + last_line - 1))
479+
# Deleting lines from config
480+
top_line=$((str - serv_line + 1))
481+
bottom_line=$((top_line + last_line -1))
486482
sed -i "$top_line,$bottom_line d" $conf
487483
}
488484

0 commit comments

Comments
 (0)