Skip to content

Commit 559a982

Browse files
author
Kristan Kenney
committed
Merge branch 'main' into feature/user-roles
2 parents 223ae17 + 9e66853 commit 559a982

18 files changed

+277
-78
lines changed

bin/v-add-fastcgi-cache

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#!/bin/bash
2-
# info: Add FastCGI nginx support
3-
# options: USER DOMAIN [DEBUG]
2+
# info: Enable FastCGI cache for nginx
3+
# options: USER DOMAIN [DURATION] [DEBUG] [RESTART]
44
# labels: hestia web
55
#
6-
# example: v-add-fastcgi-cache user domain.tld
6+
# example: v-add-fastcgi-cache user domain.tld 30m
77
#
88
# The function enables FastCGI cache for nginx
9+
# Acceptable values for duration is time in seconds (10s) minutes (10m) or days (10d)
910
# Add "yes" as last parameter to append debug information to response headers
1011

11-
1212
#----------------------------------------------------------#
1313
# Variable&Function #
1414
#----------------------------------------------------------#
1515

1616
# Argument definition
1717
user=$1
1818
domain=$2
19-
debug=$3
19+
duration=${3-2m}
20+
debug=${4-no}
21+
restart=${5-no}
2022

2123
# Includes
2224
# shellcheck source=/usr/local/hestia/func/main.sh
@@ -36,6 +38,16 @@ is_object_unsuspended 'user' 'USER' "$user"
3638
is_object_valid 'web' 'DOMAIN' "$domain"
3739
is_object_unsuspended 'web' 'DOMAIN' "$domain"
3840

41+
if ! [[ "$duration" =~ ^[0-9].*[s|m|d]$ ]]; then
42+
echo "Invalid duration";
43+
exit 2;
44+
fi
45+
46+
if [[ "$duration" =~ ^[0].*[s|m|d]$ ]]; then
47+
echo "Invalid duration";
48+
exit 2;
49+
fi
50+
3951
# Perform verification if read-only mode is enabled
4052
check_hestia_demo_mode
4153

@@ -47,7 +59,7 @@ check_hestia_demo_mode
4759
# Load domain data
4860
parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
4961

50-
# Check if nginx is not in proxy mode
62+
# Check that nginx is not in proxy mode
5163
if [ "$WEB_SYSTEM" != 'nginx' ]; then
5264
echo "Error: nginx is in proxy mode"
5365
exit $E_NOTEXIST
@@ -65,7 +77,7 @@ status='$upstream_cache_status'
6577

6678
cat << EOF > $fastcgi
6779
fastcgi_cache $domain;
68-
fastcgi_cache_valid 200 2m;
80+
fastcgi_cache_valid 200 $duration;
6981
fastcgi_cache_valid 301 302 10m;
7082
fastcgi_cache_valid 404 10m;
7183
fastcgi_cache_bypass $no_cache;
@@ -96,16 +108,22 @@ mkdir -p /var/cache/nginx/micro/$domain
96108
# Hestia #
97109
#----------------------------------------------------------#
98110

99-
if [ -z "$FASTCGI" ]; then
111+
if [ -z "$FASTCGI_CACHE" ]; then
100112
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
101113
fi
114+
if [ -z "$FASTCGI_DURATION" ]; then
115+
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_DURATION' 'ALIAS'
116+
fi
102117

103118
# Set FastCGI cache flag to enabled
104119
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' 'yes'
120+
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_DURATION' "$duration"
105121

106-
# Restart web server
107-
$BIN/v-restart-web
108-
check_result $? "Web server restart failed" > /dev/null
122+
if [ "$restart" = "yes" ]; then
123+
# Restart web server
124+
$BIN/v-restart-web
125+
check_result $? "Web server restart failed" > /dev/null
126+
fi
109127

110128
# Logging
111129
$BIN/v-log-action "$user" "Info" "Web" "FastCGI cache enabled (Domain: $domain)."

bin/v-change-sys-port

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,8 @@ check_hestia_demo_mode
5858
# Get original port
5959
ORIGINAL_PORT=$(cat $HESTIA/nginx/conf/nginx.conf | grep "listen" | sed 's/[^0-9]*//g')
6060

61-
# Check if system variable is set
62-
if [ ! -n "$BACKEND_PORT" ]; then
63-
echo "BACKEND_PORT='$port'" >> $HESTIA/conf/hestia.conf
64-
source $HESTIA/conf/hestia.conf
65-
fi
66-
67-
# Check if port is different to hestia.conf
68-
if [ ! "$BACKEND_PORT" = "$PORT" ]; then
69-
sed -i s/BACKEND_PORT=\'$BACKEND_PORT\'/BACKEND_PORT=\'$PORT\'/g $HESTIA/conf/hestia.conf
70-
fi
61+
# Set new port in config via v-change-sys-config-value
62+
$HESTIA/bin/v-change-sys-config-value "BACKEND_PORT" $PORT
7163

7264
# Check if port is different to nginx.conf
7365
if [ "$ORIGINAL_PORT" = "$PORT" ]; then

bin/v-delete-fastcgi-cache

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
2-
# info: Remove FastCGI nginx support
2+
# info: Disable FastCGI cache for nginx
33
# options: USER DOMAIN [RESTART]
44
# labels: hestia web
55
#
66
# example: v-delete-fastcgi-cache user domain.tld
77
#
8-
# The function enables FastCGI cache for nginx
8+
# The function disables FastCGI cache for nginx
99

1010

1111
#----------------------------------------------------------#
@@ -51,7 +51,7 @@ fi
5151

5252
conf='/etc/nginx/conf.d/fastcgi_cache_pool.conf'
5353
if [ -f "$conf" ]; then
54-
sed -i "/fastcgi_cache $domain;/d" $conf
54+
sed -i "/ keys_zone=$domain/d" $conf
5555
if [ ! -s "$conf" ]; then
5656
rm -rf $conf
5757
fi
@@ -68,11 +68,15 @@ fi
6868
#----------------------------------------------------------#
6969

7070
if [ -z "$FASTCGI_CACHE" ]; then
71-
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
71+
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
72+
fi
73+
if [ -z "$FASTCGI_DURATION" ]; then
74+
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_DURATION' 'ALIAS'
7275
fi
7376

74-
# Set FASTCGI flag to disabled
75-
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' ''
77+
# Set FastCGI cache flag to disabled
78+
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' 'no'
79+
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_DURATION' '0s'
7680

7781
# Restart web server
7882
if [ ! -z "$restart" ]; then

bin/v-delete-web-domain

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ if [ "$SSL" = 'yes' ]; then
8181
rm -f $USER_DATA/ssl/$domain.*
8282
fi
8383

84+
if [ "$FASTCGI_CACHE" = "yes" ]; then
85+
# make sure no trails left behind
86+
$BIN/v-delete-fastcgi-cache $user $domain
87+
fi
88+
8489
# Deleting domain from web.conf
8590
sed -i "/DOMAIN='$domain'/ d" $USER_DATA/web.conf
8691

@@ -111,7 +116,6 @@ rm -f /var/log/$WEB_SYSTEM/domains/$domain.error*
111116
rm -rf $HOMEDIR/$user/web/$domain
112117
rm -rf $HOMEDIR/$user/conf/web/$domain
113118

114-
115119
#----------------------------------------------------------#
116120
# Hestia #
117121
#----------------------------------------------------------#

bin/v-list-web-domain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ json_list() {
4646
"PROXY": "'$PROXY'",
4747
"PROXY_EXT": "'$PROXY_EXT'",
4848
"FASTCGI_CACHE": "'$FASTCGI_CACHE'",
49+
"FASTCGI_DURATION": "'$FASTCGI_DURATION'",
4950
"REDIRECT": "'$REDIRECT'",
5051
"REDIRECT_CODE": "'$REDIRECT_CODE'",
5152
"CUSTOM_DOCROOT": "'$CUSTOM_DOCROOT'",

bin/v-restore-user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ if [ "$web" != 'no' ] && [ ! -z "$WEB_SYSTEM" ]; then
314314
str="DOMAIN='$domain' IP='$IP' IP6='$IP6' ALIAS='$ALIAS'"
315315
str="$str CUSTOM_DOCROOT='$CUSTOM_DOCROOT' CUSTOM_PHPROOT='$CUSTOM_PHPROOT'"
316316
str="$str REDIRECT='$REDIRECT' REDIRECT_CODE='$REDIRECT_CODE'"
317-
str="$str FASTCGI_CACHE='$FASTCGI_CACHE' FASTCGI_CACHE_LENGTH='$FASTCGI_CACHE_LENGTH'"
317+
str="$str FASTCGI_CACHE='$FASTCGI_CACHE' FASTCGI_DURATION='$FASTCGI_DURATION'"
318318
str="$str TPL='$TPL' SSL='$SSL' SSL_HOME='$SSL_HOME'"
319319
str="$str LETSENCRYPT='$LETSENCRYPT' FTP_USER='$FTP_USER'"
320320
str="$str FTP_MD5='$FTP_MD5' BACKEND='$BACKEND' PROXY='$PROXY'"

bin/v-update-sys-hestia-git

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ BUILD_DIR='/tmp/hestiacp-src'
7272
DEB_DIR="$BUILD_DIR/debs"
7373
INSTALL_DIR='/usr/local/hestia'
7474
ARCHIVE_DIR="${BUILD_DIR}/archive"
75+
architecture="$(uname -m)"
76+
if [ $architecture == 'aarch64' ]; then
77+
BUILD_ARCH='arm64'
78+
else
79+
BUILD_ARCH='amd64'
80+
fi
7581

7682
# Set command variables
7783
fork=$1
@@ -81,7 +87,6 @@ flags=$4
8187

8288
# Set Version for compiling
8389
BUILD_VER=$(curl -s https://raw.githubusercontent.com/$fork/hestiacp/$branch/src/deb/hestia/control | grep "Version:" | cut -d' ' -f2)
84-
BUILD_ARCH='amd64'
8590
HESTIA_V="${BUILD_VER}_${BUILD_ARCH}"
8691
NGINX_V=$(curl -s https://raw.githubusercontent.com/$fork/hestiacp/$branch/src/deb/nginx/control |grep "Version:" |cut -d' ' -f2)
8792
OPENSSL_V='1.1.1g'
@@ -234,6 +239,9 @@ if [ "$NGINX_B" = true ] ; then
234239
# Download control, postinst and postrm files
235240
cd DEBIAN
236241
download_file $GIT_REP/nginx/control
242+
if [ "$BUILD_ARCH" != "amd64" ]; then
243+
sed -i "s/amd64/${BUILD_ARCH}/g" "control"
244+
fi
237245
download_file $GIT_REP/nginx/copyright
238246
download_file $GIT_REP/nginx/postinst
239247
download_file $GIT_REP/nginx/postrm
@@ -296,14 +304,31 @@ if [ "$PHP_B" = true ] ; then
296304
cd php-$PHP_V
297305

298306
# Configure PHP
299-
./configure --prefix=/usr/local/hestia/php \
307+
if [ $BUILD_ARCH = 'amd64' ]; then
308+
./configure --prefix=/usr/local/hestia/php \
300309
--enable-fpm \
301310
--with-fpm-user=admin \
302311
--with-fpm-group=admin \
303312
--with-libdir=lib/x86_64-linux-gnu \
304313
--with-mysqli \
314+
--with-gettext \
305315
--with-curl \
316+
--with-zip \
317+
--with-gmp \
306318
--enable-mbstring
319+
else
320+
./configure --prefix=/usr/local/hestia/php \
321+
--enable-fpm \
322+
--with-fpm-user=admin \
323+
--with-fpm-group=admin \
324+
--with-libdir=lib/aarch64-linux-gnu \
325+
--with-mysqli \
326+
--with-gettext \
327+
--with-curl \
328+
--with-zip \
329+
--with-gmp \
330+
--enable-mbstring
331+
fi
307332

308333
# Create the files and install them
309334
make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
@@ -319,6 +344,9 @@ if [ "$PHP_B" = true ] ; then
319344
# Download control, postinst and postrm files
320345
cd DEBIAN
321346
download_file $GIT_REP/php/control
347+
if [ "$BUILD_ARCH" != "amd64" ]; then
348+
sed -i "s/amd64/${BUILD_ARCH}/g" "control"
349+
fi
322350
download_file $GIT_REP/php/copyright
323351

324352
# Move php directory
@@ -375,6 +403,9 @@ if [ "$HESTIA_B" = true ] ; then
375403
# Download control, postinst and postrm files
376404
cd DEBIAN
377405
download_file $GIT_REP/hestia/control
406+
if [ "$BUILD_ARCH" != "amd64" ]; then
407+
sed -i "s/amd64/${BUILD_ARCH}/g" "control"
408+
fi
378409
download_file $GIT_REP/hestia/copyright
379410
download_file $GIT_REP/hestia/postinst
380411

func/main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ is_service_format_valid() {
937937
}
938938

939939
is_hash_format_valid() {
940-
if ! [[ "$1" =~ ^[_A-Za-z0-9]{1,32}$ ]]; then
940+
if ! [[ "$1" =~ ^[-_A-Za-z0-9]{1,32}$ ]]; then
941941
check_result $E_INVALID "invalid $2 format :: $1"
942942
fi
943943
}

func/rebuild.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ rebuild_web_domain_conf() {
297297
$BIN/v-delete-web-domain-ssl-hsts $user $domain no yes
298298
$BIN/v-add-web-domain-ssl-hsts $user $domain yes yes
299299
fi
300+
if [ "$FASTCGI_CACHE" = 'yes' ]; then
301+
$BIN/v-delete-fastcgi-cache $user $domain
302+
$BIN/v-add-fastcgi-cache $user $domain "$FASTCGI_DURATION"
303+
fi
300304

301305
# Adding proxy configuration
302306
if [ ! -z "$PROXY_SYSTEM" ] && [ ! -z "$PROXY" ]; then

func/syshealth.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function syshealth_update_web_config_format() {
4545
# WEB DOMAINS
4646
# Create array of known keys in configuration file
4747
system="web"
48-
known_keys=(DOMAIN IP IP6 CUSTOM_DOCROOT CUSTOM_PHPROOT FASTCGI_CACHE FASTCGI_LENGTH ALIAS TPL SSL SSL_FORCE SSL_HOME LETSENCRYPT FTP_USER FTP_MD5 FTP_PATH BACKEND PROXY PROXY_EXT STATS STATS_USER STATS_CRYPT SUSPENDED TIME DATE)
48+
known_keys=(DOMAIN IP IP6 CUSTOM_DOCROOT CUSTOM_PHPROOT FASTCGI_CACHE FASTCGI_DURATION ALIAS TPL SSL SSL_FORCE SSL_HOME LETSENCRYPT FTP_USER FTP_MD5 FTP_PATH BACKEND PROXY PROXY_EXT STATS STATS_USER STATS_CRYPT SUSPENDED TIME DATE)
4949
write_kv_config_file
5050
unset system
5151
unset known_keys
@@ -236,8 +236,9 @@ function syshealth_repair_system_config() {
236236

237237
# Backend port
238238
if [ -z "$BACKEND_PORT" ]; then
239-
echo "[ ! ] Adding missing variable to hestia.conf: BACKEND_PORT ('8083')"
240-
$BIN/v-change-sys-port '8083' >/dev/null 2>&1
239+
ORIGINAL_PORT=$(cat $HESTIA/nginx/conf/nginx.conf | grep "listen" | sed 's/[^0-9]*//g')
240+
echo "[ ! ] Adding missing variable to hestia.conf: BACKEND_PORT ('$ORIGINAL_PORT')"
241+
$HESTIA/bin/v-change-sys-config-value 'BACKEND_PORT' $PORT
241242
fi
242243

243244
# Upgrade: Send email notification

0 commit comments

Comments
 (0)