Skip to content

Commit d94cfe3

Browse files
author
Kristan Kenney
committed
Merge branch 'main' into feature/single-item-restore-cli
2 parents b0b697c + eef1173 commit d94cfe3

Some content is hidden

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

75 files changed

+1676
-1197
lines changed
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
2-
# info: Adding fast cgi nginx support
2+
# info: Add FastCGI nginx support
33
# options: USER DOMAIN [DEBUG]
44
# labels: hestia web
55
#
6-
# example: v-add-web-domain-fast-cgi-cache user domain.tld
6+
# example: v-add-fastcgi-cache user domain.tld
77
#
8-
# Function enables fast cgi support for Nginx
9-
# Add "yes" as last parameter append debug information to response headers
8+
# The function enables FastCGI cache for nginx
9+
# Add "yes" as last parameter to append debug information to response headers
1010

1111

1212
#----------------------------------------------------------#
@@ -45,16 +45,16 @@ check_hestia_demo_mode
4545
# Load domain data
4646
parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
4747

48-
# Check if web server is NGINX standalone
48+
# Check if nginx is not in proxy mode
4949
if [ "$WEB_SYSTEM" != 'nginx' ]; then
50-
echo "Error: NGINX not in Stand Alone mode"
50+
echo "Error: nginx is in proxy mode"
5151
exit $E_NOTEXIST
5252
fi
5353

54-
5554
if ! grep --quiet "forcessl" $HESTIA/data/templates/web/nginx/default.tpl; then
5655
$BIN/v-update-web-templates
5756
fi
57+
5858
fastcgi="$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf"
5959
no_cache='$no_cache'
6060
cookie_session='$cookie_session'
@@ -63,9 +63,11 @@ status='$upstream_cache_status'
6363

6464
cat << EOF > $fastcgi
6565
fastcgi_cache $domain;
66-
fastcgi_no_cache $no_cache;
66+
fastcgi_cache_valid 200 2m;
67+
fastcgi_cache_valid 301 302 10m;
68+
fastcgi_cache_valid 404 10m;
6769
fastcgi_cache_bypass $no_cache;
68-
fastcgi_cache_bypass $cookie_session $http_x_update;
70+
fastcgi_no_cache $no_cache;
6971
EOF
7072

7173
if [ ! -z "$debug" ]; then
@@ -75,18 +77,18 @@ fi
7577
chown root:$user $fastcgi
7678
chmod 640 $fastcgi
7779

78-
str="fastcgi_cache_path /var/cache/nginx/php-fpm/$domain levels=2"
79-
str="$str keys_zone=$domain:10m inactive=60m max_size=512m;"
80-
conf='/etc/nginx/conf.d/01_fast_cgi_caching_pool.conf'
81-
if [ -e "$conf" ]; then
80+
str="fastcgi_cache_path /var/cache/nginx/micro/$domain levels=1:2"
81+
str="$str keys_zone=$domain:10m max_size=512m inactive=30m;"
82+
conf='/etc/nginx/conf.d/fastcgi_cache_pool.conf'
83+
if [ -f "$conf" ]; then
8284
if [ -z "$(grep "=${domain}:" $conf)" ]; then
8385
echo "$str" >> $conf
8486
fi
8587
else
8688
echo "$str" >> $conf
8789
fi
8890

89-
mkdir -p /var/cache/nginx/php-fpm/$domain
91+
mkdir -p /var/cache/nginx/micro/$domain
9092

9193
#----------------------------------------------------------#
9294
# Hestia #
@@ -96,15 +98,15 @@ if [ -z "$FASTCGI" ]; then
9698
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
9799
fi
98100

99-
# Set FASTCGI flag to enabled
101+
# Set FastCGI cache flag to enabled
100102
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' 'yes'
101103

102104
# Restart web server
103105
$BIN/v-restart-web
104-
check_result $? "Web restart failed" > /dev/null
106+
check_result $? "Web server restart failed" > /dev/null
105107

106108
# Logging
107-
log_history "enabled fast cgi support for $domain"
109+
log_history "Enabled FastCGI cache for $domain"
108110
log_event "$OK" "$ARGUMENTS"
109111

110112
exit

bin/v-add-web-domain-redirect

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
# info: Adding force redirect to domain
3+
# options: USER DOMAIN REDIRECT HTTPCODE [RESTART]
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+
# example: v-add-web-domain-redirect user domain.tld different-domain.com 302
12+
#
13+
# Function creates a forced redirect to a domain
14+
15+
16+
#----------------------------------------------------------#
17+
# Variable&Function #
18+
#----------------------------------------------------------#
19+
20+
# Argument definition
21+
user=$1
22+
domain=$2
23+
redirect=$(echo $3 | idn);
24+
code=${4-301}
25+
restart=${5-no}
26+
27+
# Includes
28+
source $HESTIA/func/main.sh
29+
source $HESTIA/conf/hestia.conf
30+
31+
#----------------------------------------------------------#
32+
# Verifications #
33+
#----------------------------------------------------------#
34+
35+
check_args '3' "$#" 'USER DOMAIN REDIRECT [HTTP-CODE] [RESTART]'
36+
is_format_valid 'user' 'domain'
37+
is_number_format_valid "$code" "code"
38+
is_object_valid 'user' 'USER' "$user"
39+
is_object_unsuspended 'user' 'USER' "$user"
40+
is_object_valid 'web' 'DOMAIN' "$domain"
41+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
42+
43+
44+
scheme=0
45+
if [[ "$3" =~ http://|https:// ]]; then
46+
scheme=1
47+
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
48+
if ! [[ "$3" =~ $regex ]]; then
49+
echo "Invalid redirect"
50+
exit 2;
51+
fi
52+
else
53+
regex='[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
54+
if ! [[ "$3" =~ $regex ]]; then
55+
echo "Invalid redirect"
56+
exit 2;
57+
fi
58+
fi
59+
60+
# Perform verification if read-only mode is enabled
61+
check_hestia_demo_mode
62+
63+
64+
#----------------------------------------------------------#
65+
# Action #
66+
#----------------------------------------------------------#
67+
68+
# Check if proxy is active
69+
if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
70+
conf="$HOMEDIR/$user/conf/web/$domain/nginx.conf_redirect"
71+
sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
72+
fi
73+
# Insert redirect commands
74+
if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
75+
if [ "$scheme" = 1 ]; then
76+
echo " return $code $redirect\$request_uri;" > $conf
77+
if [ ! -e "$sconf" ]; then
78+
ln -s "$conf" "$sconf"
79+
fi
80+
else
81+
echo "if (\$host != \"$redirect\") {" > $conf
82+
echo " return $code \$scheme://$redirect\$request_uri;" >> $conf
83+
echo "}" >> $conf
84+
85+
if [ ! -e "$sconf" ]; then
86+
ln -s "$conf" "$sconf"
87+
fi
88+
fi
89+
else
90+
echo "Non supported please use .htaccess instead"
91+
exit 2;
92+
fi
93+
94+
#----------------------------------------------------------#
95+
# Hestia #
96+
#----------------------------------------------------------#
97+
98+
if [ -z "$REDIRECT" ]; then
99+
add_object_key "web" 'DOMAIN' "$domain" 'REDIRECT' 'U_DISK'
100+
add_object_key "web" 'DOMAIN' "$domain" 'REDIRECT_CODE' 'U_DISK'
101+
fi
102+
103+
update_object_value 'web' 'DOMAIN' "$domain" '$REDIRECT' "$redirect"
104+
update_object_value 'web' 'DOMAIN' "$domain" '$REDIRECT_CODE' "$code"
105+
106+
if [ "$restart" = "yes" ]; then
107+
# Restarting web server
108+
$BIN/v-restart-web $restart
109+
check_result $? "Web restart failed" >/dev/null
110+
111+
$BIN/v-restart-proxy $restart
112+
check_result $? "Proxy restart failed" >/dev/null
113+
fi
114+
115+
# Logging
116+
log_history "Enable forced redirect $domain"
117+
log_event "$OK" "$ARGUMENTS"
118+
119+
exit
Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/bin/bash
2-
# info: remove fast cgi nginx support
2+
# info: Remove FastCGI nginx support
33
# options: USER DOMAIN [RESTART]
44
# labels: hestia web
55
#
6-
# example: v-delete-web-domain-fast-cgi-cache user domain.tld
6+
# example: v-delete-fastcgi-cache user domain.tld
77
#
8-
# The function removes fast cgi cache.
8+
# The function enables FastCGI cache for nginx
9+
910

1011
#----------------------------------------------------------#
1112
# Variable&Function #
@@ -41,16 +42,25 @@ check_hestia_demo_mode
4142
# Load domain data
4243
parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
4344

44-
# Remove fast cgi configs
45+
# Remove FastCGI cache configuration
4546
if [ -f $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf ]; then
46-
rm -f $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf
47+
rm -rf $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf
48+
fi
49+
50+
conf='/etc/nginx/conf.d/fastcgi_cache_pool.conf'
51+
if [ -f "$conf" ]; then
52+
sed -i "/fastcgi_cache $domain;/d" $conf
53+
if [ ! -s "$conf" ]; then
54+
rm -rf $conf
55+
fi
4756
fi
4857

49-
# Delete cache folder on disabling
50-
if [ -d /var/cache/nginx/php-fpm/$domain ]; then
51-
rm -rf /var/cache/nginx/php-fpm/$domain
58+
# Delete FastCGI cache folder
59+
if [ -d /var/cache/nginx/micro/$domain ]; then
60+
rm -rf /var/cache/nginx/micro/$domain
5261
fi
5362

63+
5464
#----------------------------------------------------------#
5565
# Hestia #
5666
#----------------------------------------------------------#
@@ -62,14 +72,14 @@ fi
6272
# Set FASTCGI flag to disabled
6373
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' ''
6474

65-
# Restart services if requested
75+
# Restart web server
6676
if [ ! -z "$restart" ]; then
6777
$BIN/v-restart-web
68-
check_result $? "Web restart failed" >/dev/null
78+
check_result $? "Web server restart failed" > /dev/null
6979
fi
7080

7181
# Logging
72-
log_history "disabled fast cgi support for $domain"
82+
log_history "Disabled FastCGI cache for $domain"
7383
log_event "$OK" "$ARGUMENTS"
7484

7585
exit

bin/v-delete-web-domain-redirect

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# info: Delete force redirect to domain
3+
# options: USER DOMAIN [RESTART]
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+
restart=${3-no}
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 '2' "$#" 'USER DOMAIN [RESTART]'
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+
update_object_value 'web' 'DOMAIN' "$domain" '$REDIRECT_CODE' ""
62+
63+
if [ "$restart" = "yes" ]; then
64+
# Restarting web server
65+
$BIN/v-restart-web $restart
66+
check_result $? "Web restart failed" >/dev/null
67+
68+
$BIN/v-restart-proxy $restart
69+
check_result $? "Proxy restart failed" >/dev/null
70+
fi
71+
72+
# Logging
73+
log_history "Enable forced redirect $domain"
74+
log_event "$OK" "$ARGUMENTS"
75+
76+
exit

bin/v-generate-ssl-cert

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ cd $workdir
9292
openssl genrsa $KEY_SIZE > $domain.key 2>/dev/null
9393

9494
# Generate the CSR
95-
subj="/C=$country/ST=$state/localityName=$city/O=$org"
96-
subj="$subj/organizationalUnitName=$org_unit/commonName=$domain_idn"
97-
subj="$subj/emailAddress=$email"
95+
subj="/emailAddress=$email/C=$country/ST=$state/L=$city/O=$org"
96+
subj="$subj/OU=$org_unit/CN=$domain_idn"
97+
9898
if [ -z "$aliases" ]; then
9999
openssl req -sha256\
100100
-new \

bin/v-list-mail-domain-ssl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ if [ -e "$USER_DATA/ssl/mail.$domain.crt" ]; then
118118
crt=$(cat $USER_DATA/ssl/mail.$domain.crt |sed ':a;N;$!ba;s/\n/\\n/g')
119119

120120
info=$(openssl x509 -text -in $USER_DATA/ssl/mail.$domain.crt)
121-
subj=$(echo "$info" |grep Subject: |cut -f 2 -d =)
121+
subj=$(echo "$info" |grep Subject: |sed -e "s/\"//g" -e "s/.*= //")
122122
before=$(echo "$info" |grep Before: |sed -e "s/.*Before: //")
123123
after=$(echo "$info" |grep "After :" |sed -e "s/.*After : //")
124124
signature=$(echo "$info" |grep "Algorithm:" |head -n1 )

bin/v-list-web-domain

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ json_list() {
4545
"PROXY": "'$PROXY'",
4646
"PROXY_EXT": "'$PROXY_EXT'",
4747
"FASTCGI_CACHE": "'$FASTCGI_CACHE'",
48+
"REDIRECT": "'$REDIRECT'",
49+
"REDIRECT_CODE": "'$REDIRECT_CODE'",
4850
"CUSTOM_DOCROOT": "'$CUSTOM_DOCROOT'",
4951
"SUSPENDED": "'$SUSPENDED'",
5052
"TIME": "'$TIME'",

0 commit comments

Comments
 (0)