Skip to content

Commit c1e0837

Browse files
committed
Add support for redirect
1 parent 6f9034e commit c1e0837

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

bin/v-add-web-domain-redirect

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# info: Adding force redirect to domain
3+
# options: USER DOMAIN REDIRECT [CUSTOM]
4+
# labels: hestia web
5+
#
6+
# example: v-add-web-domain-redirect user domain.tld domain.tld
7+
# example: v-add-web-domain-redirect user domain.tld www.domain.tld
8+
# example: v-add-web-domain-redirect user domain.tld shop.domain.tld
9+
# example: v-add-web-domain-redirect user domain.tld different-domain.com
10+
# example: v-add-web-domain-redirect user domain.tld shop.different-domain.com
11+
#
12+
# Function creates a forced redirect to a domain
13+
14+
15+
#----------------------------------------------------------#
16+
# Variable&Function #
17+
#----------------------------------------------------------#
18+
19+
# Argument definition
20+
user=$1
21+
domain=$2
22+
redirect=$3
23+
24+
25+
# Includes
26+
source $HESTIA/func/main.sh
27+
source $HESTIA/conf/hestia.conf
28+
29+
30+
#----------------------------------------------------------#
31+
# Verifications #
32+
#----------------------------------------------------------#
33+
34+
check_args '3' "$#" 'USER DOMAIN REDIRECT'
35+
is_format_valid 'user' 'domain'
36+
is_object_valid 'user' 'USER' "$user"
37+
is_object_unsuspended 'user' 'USER' "$user"
38+
is_object_valid 'web' 'DOMAIN' "$domain"
39+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
40+
41+
# Perform verification if read-only mode is enabled
42+
check_hestia_demo_mode
43+
44+
45+
#----------------------------------------------------------#
46+
# Action #
47+
#----------------------------------------------------------#
48+
49+
50+
51+
# Check if proxy is active
52+
if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
53+
conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
54+
sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
55+
fi
56+
# Insert redirect commands
57+
if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
58+
echo "if (\$host != \"$redirect\") {" > $conf
59+
echo " return 301 \$scheme://$redirect\$request_uri;" >> $conf
60+
echo "}" >> $conf
61+
62+
if [ ! -e "$sconf" ]; then
63+
ln -s "$conf" "$sconf"
64+
fi
65+
else
66+
echo "Non supported please use .htaccess instead"
67+
exit 2;
68+
fi
69+
70+
#----------------------------------------------------------#
71+
# Hestia #
72+
#----------------------------------------------------------#
73+
74+
if [ -z "$REDIRECT" ]; then
75+
add_object_key "web" 'DOMAIN' "$domain" 'REDIRECT' 'TIME'
76+
fi
77+
78+
update_object_value 'web' 'DOMAIN' "$domain" '$REDIRECT' "$redirect"
79+
80+
# Restart web server
81+
$BIN/v-restart-web
82+
check_result $? "Web restart failed" > /dev/null
83+
84+
# Logging
85+
log_history "Enable forced redirect $domain"
86+
log_event "$OK" "$ARGUMENTS"
87+
88+
exit

bin/v-delete-we-domain-redirect

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
# info: Delete force redirect to domain
3+
# options: USER DOMAIN REDIRECT [CUSTOM]
4+
# labels: hestia web
5+
#
6+
# example: v-add-web-domain-redirect user domain.tld
7+
#
8+
# Function delete a forced redirect to a domain
9+
10+
11+
#----------------------------------------------------------#
12+
# Variable&Function #
13+
#----------------------------------------------------------#
14+
15+
# Argument definition
16+
user=$1
17+
domain=$2
18+
redirect=$3
19+
20+
21+
# Includes
22+
source $HESTIA/func/main.sh
23+
source $HESTIA/conf/hestia.conf
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
check_args '3' "$#" 'USER DOMAIN REDIRECT'
31+
is_format_valid 'user' 'domain'
32+
is_object_valid 'user' 'USER' "$user"
33+
is_object_unsuspended 'user' 'USER' "$user"
34+
is_object_valid 'web' 'DOMAIN' "$domain"
35+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
36+
37+
# Perform verification if read-only mode is enabled
38+
check_hestia_demo_mode
39+
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
45+
46+
47+
# Check if proxy is active
48+
if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
49+
rm $HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
50+
rm $HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
51+
else
52+
echo "Non supported please use .htaccess instead"
53+
exit 2;
54+
fi
55+
56+
#----------------------------------------------------------#
57+
# Hestia #
58+
#----------------------------------------------------------#
59+
60+
update_object_value 'web' 'DOMAIN' "$domain" '$REDIRECT' ""
61+
62+
# Restart web server
63+
$BIN/v-restart-web
64+
check_result $? "Web restart failed" > /dev/null
65+
66+
# Logging
67+
log_history "Enable forced redirect $domain"
68+
log_event "$OK" "$ARGUMENTS"
69+
70+
exit

0 commit comments

Comments
 (0)