Skip to content

Commit 5458c49

Browse files
committed
added SSL CA-bundle support
1 parent 8fe4b05 commit 5458c49

32 files changed

+159
-429
lines changed

bin/v_add_sys_user_ssl

Lines changed: 0 additions & 58 deletions
This file was deleted.

bin/v_add_web_domain

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ increase_user_value "$user" '$U_WEB_DOMAINS'
198198

199199
# Defining domain variables
200200
v_str="DOMAIN='$domain'"
201-
v_str="$v_str IP='$ip'"
201+
v_str="$v_str IP='$ip' IP6=''"
202202
v_str="$v_str U_DISK='0'"
203203
v_str="$v_str U_BANDWIDTH='0'"
204204
v_str="$v_str TPL='$template'"
205205
v_str="$v_str ALIAS='$aliases'"
206206
v_str="$v_str $template_data" # Inserting PHP, CGI and ELOG keys
207207
v_str="$v_str STATS='' STATS_AUTH=''"
208-
v_str="$v_str SSL='' SSL_HOME=''"
208+
v_str="$v_str SSL='no' SSL_HOME='single'"
209209
v_str="$v_str NGINX='' NGINX_EXT='' SUSPEND='no' DATE='$V_DATE'"
210210

211211
# Registering domain

bin/v_add_web_domain_alias

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ upd_web_domain_values
8282
del_web_config
8383
add_web_config
8484

85-
if [ ! -z "$SSL" ]; then
85+
if [ "$SSL" = 'yes' ]; then
8686
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
8787
conf="$V_HOME/$user/conf/shttpd.conf"
8888
del_web_config
@@ -96,7 +96,7 @@ if [ ! -z "$NGINX" ]; then
9696
del_web_config
9797
add_web_config
9898

99-
if [ ! -z "$SSL" ]; then
99+
if [ "$SSL" = 'yes' ]; then
100100
proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
101101
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
102102
conf="$V_HOME/$user/conf/snginx.conf"

bin/v_add_web_domain_cgi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ del_web_config
6464
add_web_config
6565

6666
# Checking ssl
67-
if [ ! -z "$SSL" ]; then
67+
if [ "$SSL" = 'yes' ]; then
6868
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
6969
conf="$V_HOME/$user/conf/shttpd.conf"
7070
del_web_config

bin/v_add_web_domain_elog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ del_web_config
6464
add_web_config
6565

6666
# Checking ssl
67-
if [ ! -z "$SSL" ]; then
67+
if [ "$SSL" = 'yes' ]; then
6868
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
6969
conf="$V_HOME/$user/conf/shttpd.conf"
7070
del_web_config
@@ -78,7 +78,7 @@ if [ ! -z "$NGINX" ]; then
7878
del_web_config
7979
add_web_config
8080

81-
if [ ! -z "$SSL" ]; then
81+
if [ "$SSL" = 'yes' ]; then
8282
proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
8383
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
8484
conf="$V_HOME/$user/conf/snginx.conf"

bin/v_add_web_domain_nginx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ conf="$V_HOME/$user/conf/nginx.conf"
6868
upd_web_domain_values
6969
add_web_config
7070

71-
if [ ! -z "$SSL" ]; then
71+
if [ "$SSL" = 'yes' ]; then
7272
proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
7373
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
7474
conf="$V_HOME/$user/conf/snginx.conf"

bin/v_add_web_domain_ssl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
user=$1
1010
domain=$(idn -t --quiet -u "$2" )
1111
domain_idn=$(idn -t --quiet -a "$domain")
12-
ssl=$3
12+
ssl_dir=$3
1313
ssl_home=${4-single}
1414

1515
# Importing variables
@@ -25,10 +25,10 @@ source $V_FUNC/ip.func
2525
#----------------------------------------------------------#
2626

2727
# Checking arg number
28-
check_args '3' "$#" 'user domain ssl [sslhome]'
28+
check_args '3' "$#" 'user domain ssl_dir [ssl_home]'
2929

3030
# Checking argument format
31-
format_validation 'user' 'domain' 'ssl'
31+
format_validation 'user' 'domain' 'ssl_dir'
3232

3333
# Checking web system is enabled
3434
is_system_enabled 'web'
@@ -59,12 +59,20 @@ is_web_domain_cert_valid
5959
# Action #
6060
#----------------------------------------------------------#
6161

62+
# Adding certificate to user data directory
63+
cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.crt
64+
cp -f $ssl_dir/$domain.key $V_USERS/$user/ssl/$domain.key
65+
cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.pem
66+
if [ -e "$ssl_dir/$domain.ca" ]; then
67+
cp -f $ssl_dir/$domain.ca $V_USERS/$user/ssl/$domain.ca
68+
cat $V_USERS/$user/ssl/$domain.ca >> $V_USERS/$user/ssl/$domain.pem
69+
fi
70+
6271
# Parsing domain values
6372
get_web_domain_values
6473
conf="$V_HOME/$user/conf/shttpd.conf"
6574
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
66-
SSL=$ssl
67-
SSL_HOME=$ssl_home
75+
SSL_HOME="$ssl_home"
6876

6977
# Checking ip ownership
7078
is_sys_ip_owner
@@ -76,8 +84,12 @@ upd_web_domain_values
7684
add_web_config
7785

7886
# Adding certificate to user dir
79-
cp -f $V_USERS/$user/ssl/$SSL.crt $ssl_cert
80-
cp -f $V_USERS/$user/ssl/$SSL.key $ssl_key
87+
cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/ssl.$domain.crt
88+
cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/ssl.$domain.key
89+
cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/ssl.$domain.pem
90+
if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
91+
cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/ssl.$domain.ca
92+
fi
8193

8294
# Running template trigger
8395
if [ -x $V_WEBTPL/apache_$template.sh ]; then
@@ -115,8 +127,8 @@ fi
115127
increase_user_value "$user" '$U_WEB_SSL'
116128

117129
# Adding ssl values
118-
update_web_domain_value '$SSL' "$SSL"
119130
update_web_domain_value '$SSL_HOME' "$SSL_HOME"
131+
update_web_domain_value '$SSL' 'yes'
120132

121133
# Logging
122134
log_history "$V_EVENT" "v_del_web_domain_ssl $user $domain"

bin/v_backup_sys_user

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -100,31 +100,6 @@ if [ -e "$V_USERS/$user/backup.excludes" ]; then
100100
cp -r $V_USERS/$user/backup.excludes $tmpdir/vesta/
101101
fi
102102

103-
if [ -e "$V_USERS/$user/cron.conf" ]; then
104-
echo -e "$(date "+%F %T") cron.conf"
105-
cp -r $V_USERS/$user/cron.conf $tmpdir/vesta/
106-
fi
107-
108-
if [ -e "$V_USERS/$user/db.conf" ]; then
109-
echo -e "$(date "+%F %T") db.conf"
110-
cp -r $V_USERS/$user/db.conf $tmpdir/vesta/
111-
fi
112-
113-
if [ -e "$V_USERS/$user/dns.conf" ]; then
114-
echo -e "$(date "+%F %T") dns.conf"
115-
cp -r $V_USERS/$user/dns.conf $tmpdir/vesta/
116-
fi
117-
118-
if [ -e "$V_USERS/$user/mail.conf" ]; then
119-
echo -e "$(date "+%F %T") mail.conf"
120-
cp -r $V_USERS/$user/mail.conf $tmpdir/vesta/
121-
fi
122-
123-
124-
if [ -e "$V_USERS/$user/web.conf" ]; then
125-
echo -e "$(date "+%F %T") web.conf"
126-
cp -r $V_USERS/$user/web.conf $tmpdir/vesta/
127-
fi
128103

129104
echo
130105

@@ -205,7 +180,7 @@ then
205180
sed -n "$top_line,$bottom_line p" $conf > conf/httpd.conf
206181

207182
# SSL check
208-
if [ ! -z "$SSL" ]; then
183+
if [ "$SSL" = 'yes' ]; then
209184
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
210185
conf="$V_HOME/$user/conf/shttpd.conf"
211186
get_web_config_brds
@@ -221,7 +196,7 @@ then
221196
sed -n "$top_line,$bottom_line p" $conf > conf/nginx.conf
222197

223198
# SSL check
224-
if [ ! -z "$SSL" ] ; then
199+
if [ "$SSL" = 'yes' ] ; then
225200
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
226201
conf="$V_HOME/$user/conf/snginx.conf"
227202
get_web_config_brds
@@ -235,8 +210,8 @@ then
235210
done
236211

237212
# SSL Certificates
238-
if [ ! -z "$SSL" ] ; then
239-
cp $V_HOME/$user/conf/$SSL.* ssl/
213+
if [ "$SSL" = 'yes' ] ; then
214+
cp $V_HOME/$user/conf/ssl.$domain.* ssl/
240215
fi
241216

242217
tar -rf $tmpdir/web/$domain/$domain.tar conf ssl
@@ -353,23 +328,6 @@ then
353328
echo
354329
fi
355330

356-
# SSL CERTIFICATES
357-
if [ ! -z "$WEB_SSL" ] && [ "$WEB_SSL" != 'no' ] && [ "$SSL" != '*' ]; then
358-
echo "-- SSL --"
359-
mkdir $tmpdir/ssl
360-
361-
# Backingup ssl certificates
362-
cert_list=$(ls $V_USERS/$user/ssl/ | grep ".crt" |\
363-
sed -e "s/\.crt$//" |\
364-
tr '\n' ' ' |\
365-
sed -e 's/ $//' )
366-
for cert in $cert_list; do
367-
echo -e "$(date "+%F %T") $cert"
368-
cp $V_USERS/$user/ssl/$cert.* $tmpdir/ssl/
369-
done
370-
echo
371-
fi
372-
373331
# Get backup size
374332
size="$(du -shm $tmpdir | cut -f 1)"
375333

@@ -539,7 +497,6 @@ backup_str="$backup_str WEB='${web_list// /,}'"
539497
backup_str="$backup_str DNS='${dns_list// /,}'"
540498
backup_str="$backup_str MAIL='${mail_list// /,}'"
541499
backup_str="$backup_str DB='${db_list// /,}'"
542-
backup_str="$backup_str SSL='${cert_list// /,}'"
543500
backup_str="$backup_str CRON='$cron_list'"
544501
echo "$backup_str" >> $V_USERS/$user/backup.conf
545502

bin/v_change_web_domain_ip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ new=$ip
6161
replace_web_config
6262

6363
# Checking ssl
64-
if [ ! -z "$SSL" ]; then
64+
if [ "$SSL" = 'yes' ]; then
6565
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
6666
conf="$V_HOME/$user/conf/shttpd.conf"
6767
replace_web_config
@@ -75,7 +75,7 @@ if [ ! -z "$NGINX" ]; then
7575
fi
7676

7777
# Checking nginx
78-
if [ ! -z "$SSL" ] && [ ! -z "$NGINX" ]; then
78+
if [ "$SSL" = 'yes' ] && [ ! -z "$NGINX" ]; then
7979
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
8080
conf="$V_HOME/$user/conf/snginx.conf"
8181
replace_web_config

bin/v_change_web_domain_sslcert

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
user=$1
1010
domain=$(idn -t --quiet -u "$2" )
1111
domain_idn=$(idn -t --quiet -a "$domain")
12-
ssl=$3
12+
ssl_dir=$3
1313

1414
# Importing variables
1515
source $VESTA/conf/vars.conf
@@ -54,53 +54,39 @@ is_web_domain_cert_valid
5454
# Action #
5555
#----------------------------------------------------------#
5656

57-
# Parsing domain values
58-
get_web_domain_values
59-
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
60-
conf="$V_HOME/$user/conf/shttpd.conf"
61-
old_ssl="$SSL"
62-
SSL="$ssl"
63-
64-
# Preparing domain values for the template substitution
65-
upd_web_domain_values
66-
67-
# Recreating vhost
68-
del_web_config
69-
add_web_config
70-
71-
# Checking nginx
72-
if [ ! -z "$NGINX" ]; then
73-
proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
74-
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
75-
conf="$V_HOME/$user/conf/snginx.conf"
76-
del_web_config
77-
add_web_config
57+
# Deleting old certificate
58+
tmpdir=$(mktemp -p $V_HOME/$user/web/$domain/private -d)
59+
rm -f $V_HOME/$user/conf/ssl.$domain.*
60+
mv $V_USERS/$user/ssl/$domain.* $tmpdir
61+
chown -R $user:$user $tmpdir
62+
63+
# Adding new certificate to user data directory
64+
cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.crt
65+
cp -f $ssl_dir/$domain.key $V_USERS/$user/ssl/$domain.key
66+
cp -f $ssl_dir/$domain.crt $V_USERS/$user/ssl/$domain.pem
67+
if [ -e "$ssl_dir/$domain.ca" ]; then
68+
cp -f $ssl_dir/$domain.ca $V_USERS/$user/ssl/$domain.ca
69+
cat $V_USERS/$user/ssl/$domain.ca >> $V_USERS/$user/ssl/$domain.pem
7870
fi
7971

8072
# Adding new certificate to user dir
81-
cp -f $V_USERS/$user/ssl/$SSL.crt $ssl_cert
82-
cp -f $V_USERS/$user/ssl/$SSL.key $ssl_key
83-
84-
# Deleting old certificate
85-
check_cert=$(grep "SSL='$old_ssl'" $V_USERS/$user/web.conf |wc -l)
86-
if [ "$check_cert" -lt 2 ]; then
87-
rm -f $V_HOME/$user/conf/$old_ssl.crt
88-
rm -f $V_HOME/$user/conf/$old_ssl.key
73+
cp -f $V_USERS/$user/ssl/$domain.crt $V_HOME/$user/conf/ssl.$domain.crt
74+
cp -f $V_USERS/$user/ssl/$domain.key $V_HOME/$user/conf/ssl.$domain.key
75+
cp -f $V_USERS/$user/ssl/$domain.pem $V_HOME/$user/conf/ssl.$domain.pem
76+
if [ -e "$V_USERS/$user/ssl/$domain.ca" ]; then
77+
cp -f $V_USERS/$user/ssl/$domain.ca $V_HOME/$user/conf/ssl.$domain.ca
8978
fi
9079

9180

9281
#----------------------------------------------------------#
9382
# Vesta #
9483
#----------------------------------------------------------#
9584

96-
# Adding sslcert in config
97-
update_web_domain_value '$SSL' "$SSL"
98-
9985
# Adding task to the vesta pipe
10086
restart_schedule 'web'
10187

10288
# Logging
103-
log_history "$V_EVENT" "$V_SCRIPT $user $domain $old_ssl"
89+
log_history "$V_EVENT" "$V_SCRIPT $user $domain $tmpdir"
10490
log_event 'system' "$V_EVENT"
10591

10692
exit

0 commit comments

Comments
 (0)