Skip to content

Commit 108259f

Browse files
committed
Add v-add-web-domain-ssl-force to create a 301 redirect from http to https.
1 parent 3b9ccba commit 108259f

File tree

200 files changed

+583
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+583
-196
lines changed

bin/v-add-web-domain-ssl-force

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
# info: adding ssl force to domain
3+
# options: USER DOMAIN
4+
#
5+
# The function forces SSL for the requested domain.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=$1
14+
domain=$2
15+
16+
# Includes
17+
source $HESTIA/func/main.sh
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '2' "$#" 'USER DOMAIN'
25+
is_format_valid 'user' 'domain' 'ssl_dir'
26+
is_object_valid 'user' 'USER' "$user"
27+
is_object_unsuspended 'user' 'USER' "$user"
28+
is_object_valid 'web' 'DOMAIN' "$domain"
29+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
30+
31+
32+
#----------------------------------------------------------#
33+
# Action #
34+
#----------------------------------------------------------#
35+
36+
# Load domain data
37+
eval $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
38+
39+
# Check if SSL is enabled
40+
if [ "$SSL" != 'yes' ]; then
41+
echo "Error: ssl is not enabled"
42+
exit $E_NOTEXIST
43+
fi
44+
45+
# Check if proxy is active
46+
if [ ! -z "$PROXY_SYSTEM" ] || [ ! -z "$PROXY" ]; then
47+
if ! grep --quiet "forcessl" $HESTIA/data/templates/web/nginx/default.tpl; then
48+
$BIN/v-update-web-templates
49+
fi
50+
forcessl="/home/$user/conf/web/forcessl.nginx.$domain.conf"
51+
else
52+
if ! grep --quiet "forcessl" $HESTIA/data/templates/web/nginx/default.tpl; then
53+
$BIN/v-update-web-templates
54+
fi
55+
forcessl="/home/$user/conf/web/forcessl.apache2.$domain.conf"
56+
fi
57+
58+
# Check if force ssl already exists
59+
if [ -f "$forcessl" ]; then
60+
echo "Error: rewrite already enabled"
61+
exit $E_EXIST
62+
fi
63+
64+
# Place rewrite commands
65+
if [ ! -z $PROXY ]; then
66+
echo 'return 301 https://$server_name$request_uri;' > $forcessl
67+
else
68+
echo 'RewriteEngine On' > $forcessl
69+
echo 'RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]' >> $forcessl
70+
fi
71+
72+
73+
#----------------------------------------------------------#
74+
# Hestia #
75+
#----------------------------------------------------------#
76+
77+
# Restarting web server
78+
$BIN/v-restart-web
79+
check_result $? "Web restart failed" >/dev/null
80+
81+
$BIN/v-restart-proxy
82+
check_result $? "Proxy restart failed" >/dev/null
83+
84+
exit

bin/v-delete-web-domain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ del_web_config "$WEB_SYSTEM" "$TPL.tpl"
6565
# Deleting SSL configuration and certificates
6666
if [ "$SSL" = 'yes' ]; then
6767
del_web_config "$WEB_SYSTEM" "$TPL.stpl"
68+
$BIN/v-delete-web-domain-ssl-force $user $domain
6869
rm -f $HOMEDIR/$user/conf/web/ssl.$domain.*
6970
rm -f $USER_DATA/ssl/$domain.*
7071
fi

bin/v-delete-web-domain-ssl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ rm -f $HOMEDIR/$user/conf/web/ssl.$domain.*
6161
mv $USER_DATA/ssl/$domain.* $tmpdir
6262
chown -R $user:$user $tmpdir
6363

64+
# Deleting force ssl
65+
$BIN/v-delete-web-domain-ssl-force $user $domain
66+
6467

6568
#----------------------------------------------------------#
6669
# Hestia #

bin/v-delete-web-domain-ssl-force

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# info: remove ssl force from domain
3+
# options: USER DOMAIN [RESTART]
4+
#
5+
# The function removes force SSL configurations.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=$1
14+
domain=$2
15+
restart=$3
16+
17+
# Includes
18+
source $HESTIA/func/main.sh
19+
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
check_args '2' "$#" 'USER DOMAIN'
26+
is_format_valid 'user' 'domain' 'ssl_dir'
27+
is_object_valid 'user' 'USER' "$user"
28+
is_object_unsuspended 'user' 'USER' "$user"
29+
is_object_valid 'web' 'DOMAIN' "$domain"
30+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
31+
32+
33+
#----------------------------------------------------------#
34+
# Action #
35+
#----------------------------------------------------------#
36+
37+
# Load domain data
38+
eval $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
39+
40+
# Remove forcessl configs
41+
rm -f /home/$user/conf/web/forcessl.*$domain*.conf
42+
43+
44+
#----------------------------------------------------------#
45+
# Hestia #
46+
#----------------------------------------------------------#
47+
48+
# Restart services if requested
49+
if [ ! -z "$restart" ]; then
50+
$BIN/v-restart-web
51+
check_result $? "Web restart failed" >/dev/null
52+
53+
$BIN/v-restart-proxy
54+
check_result $? "Proxy restart failed" >/dev/null
55+
fi
56+
57+
exit

install/debian/8/multiphp/apache2/PHP-56.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#SuexecUserGroup %user% %group%
1111
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
1212
CustomLog /var/log/%web_system%/domains/%domain%.log combined
13-
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
13+
14+
IncludeOptional %home%/%user%/conf/web/forcessl.apache2.%domain%.conf
15+
1416
<Directory %home%/%user%/web/%domain%/stats>
1517
AllowOverride All
1618
</Directory>

install/debian/8/multiphp/apache2/PHP-70.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#SuexecUserGroup %user% %group%
1111
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
1212
CustomLog /var/log/%web_system%/domains/%domain%.log combined
13-
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
13+
14+
IncludeOptional %home%/%user%/conf/web/forcessl.apache2.%domain%.conf
15+
1416
<Directory %home%/%user%/web/%domain%/stats>
1517
AllowOverride All
1618
</Directory>

install/debian/8/multiphp/apache2/PHP-71.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#SuexecUserGroup %user% %group%
1111
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
1212
CustomLog /var/log/%web_system%/domains/%domain%.log combined
13-
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
13+
14+
IncludeOptional %home%/%user%/conf/web/forcessl.apache2.%domain%.conf
15+
1416
<Directory %home%/%user%/web/%domain%/stats>
1517
AllowOverride All
1618
</Directory>

install/debian/8/multiphp/apache2/PHP-72.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#SuexecUserGroup %user% %group%
1111
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
1212
CustomLog /var/log/%web_system%/domains/%domain%.log combined
13-
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
13+
14+
IncludeOptional %home%/%user%/conf/web/forcessl.apache2.%domain%.conf
15+
1416
<Directory %home%/%user%/web/%domain%/stats>
1517
AllowOverride All
1618
</Directory>

install/debian/8/multiphp/apache2/PHP-73.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#SuexecUserGroup %user% %group%
1111
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
1212
CustomLog /var/log/%web_system%/domains/%domain%.log combined
13-
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
13+
14+
IncludeOptional %home%/%user%/conf/web/forcessl.apache2.%domain%.conf
15+
1416
<Directory %home%/%user%/web/%domain%/stats>
1517
AllowOverride All
1618
</Directory>

install/debian/8/multiphp/nginx/PHP-56.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ server {
55
index index.php index.html index.htm;
66
access_log /var/log/nginx/domains/%domain%.log combined;
77
access_log /var/log/nginx/domains/%domain%.bytes bytes;
8-
error_log /var/log/nginx/domains/%domain%.error.log error;
8+
9+
include %home%/%user%/conf/web/forcessl.nginx.%domain%.conf*;
910
1011
location / {
1112

0 commit comments

Comments
 (0)