forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-add-web-domain-ssl-force
More file actions
79 lines (61 loc) · 2.24 KB
/
v-add-web-domain-ssl-force
File metadata and controls
79 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# info: Adding force SSL for a domain
# options: USER DOMAIN
#
# The function forces SSL for the requested domain.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
domain=$2
# Includes
source $HESTIA/func/main.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER DOMAIN'
is_format_valid 'user' 'domain' 'ssl_dir'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Load domain data
eval $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
# Check if SSL is enabled
if [ "$SSL" != 'yes' ]; then
echo "Error: SSL is not enabled"
exit $E_NOTEXIST
fi
# Check if proxy is active
if [ ! -z "$PROXY_SYSTEM" ] || [ ! -z "$PROXY" ]; then
if ! grep --quiet "forcessl" $HESTIA/data/templates/web/nginx/default.tpl; then
$BIN/v-update-web-templates
fi
forcessl="/home/$user/conf/web/forcessl.nginx.$domain.conf"
else
if ! grep --quiet "forcessl" $HESTIA/data/templates/web/nginx/default.tpl; then
$BIN/v-update-web-templates
fi
forcessl="/home/$user/conf/web/forcessl.apache2.$domain.conf"
fi
# Insert redirect commands
if [ ! -z $PROXY ]; then
echo 'return 301 https://$server_name$request_uri;' > $forcessl
else
echo 'RewriteEngine On' > $forcessl
echo 'RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]' >> $forcessl
fi
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Restart web server
$BIN/v-restart-web
check_result $? "Web restart failed" > /dev/null
# Restart proxy
$BIN/v-restart-proxy
check_result $? "Proxy restart failed" > /dev/null
exit