Skip to content

Commit 71820dd

Browse files
committed
Allow the selection of cache lenght
1 parent ac85a04 commit 71820dd

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

bin/v-add-fastcgi-cache

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#!/bin/bash
22
# info: Add FastCGI nginx support
3-
# options: USER DOMAIN [DEBUG]
3+
# options: USER DOMAIN [LENTGH] [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+
# For Length only use 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+
length=${3-30m}
20+
debug=${4-no}
21+
restart=${5-no}
2022

2123
# Includes
2224
source $HESTIA/func/main.sh
@@ -34,6 +36,10 @@ is_object_unsuspended 'user' 'USER' "$user"
3436
is_object_valid 'web' 'DOMAIN' "$domain"
3537
is_object_unsuspended 'web' 'DOMAIN' "$domain"
3638

39+
if ! [[ "$length" =~ ^[0-9].*[s|m|d]$ ]]; then
40+
echo "Invalid length";
41+
exit 2;
42+
fi
3743
# Perform verification if read-only mode is enabled
3844
check_hestia_demo_mode
3945

@@ -94,16 +100,21 @@ mkdir -p /var/cache/nginx/micro/$domain
94100
# Hestia #
95101
#----------------------------------------------------------#
96102

97-
if [ -z "$FASTCGI" ]; then
103+
if [ -z "$FASTCGI_CACHE" ]; then
98104
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
99105
fi
106+
if [ -z "$FASTCGI_LENGTH" ]; then
107+
add_object_key "web" 'DOMAIN' "$domain" '$FASTCGI_LENGTH' 'ALIAS'
108+
fi
100109

101110
# Set FastCGI cache flag to enabled
102111
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' 'yes'
103112

104-
# Restart web server
105-
$BIN/v-restart-web
106-
check_result $? "Web server restart failed" > /dev/null
113+
if [ "$restart" = "yes"]; then
114+
# Restart web server
115+
$BIN/v-restart-web
116+
check_result $? "Web server restart failed" > /dev/null
117+
fi
107118

108119
# Logging
109120
log_history "Enabled FastCGI cache for $domain"

web/edit/web/index.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
$v_ssl_home = $data[$v_domain]['SSL_HOME'];
6969
$v_backend_template = $data[$v_domain]['BACKEND'];
7070
$v_nginx_cache = $data[$v_domain]['FASTCGI_CACHE'];
71+
$v_nginx_cache_length = $data[$v_domain]['FASTCGI_CACHE_LENGTH'];
72+
if(empty($v_nginx_cache_length)){
73+
$v_nginx_cache_length = '30m';
74+
}
7175
$v_proxy = $data[$v_domain]['PROXY'];
7276
$v_proxy_template = $data[$v_domain]['PROXY'];
7377
$v_proxy_ext = str_replace(',', ', ', $data[$v_domain]['PROXY_EXT']);
@@ -329,11 +333,14 @@
329333
}
330334

331335
// Enable/Disable nginx cache
332-
if (($_SESSION['WEB_SYSTEM'] == 'nginx') && ($v_nginx_cache != $_POST['v_nginx_cache'] ) && (empty($_SESSION['error_msg']))) {
336+
if (($_SESSION['WEB_SYSTEM'] == 'nginx') && ($v_nginx_cache != $_POST['v_nginx_cache'] ) && ($v_nginx_cache_length != $_POST['v_nginx_cache_length'] && $_POST['v_nginx_cache'] = "yes" ) && (empty($_SESSION['error_msg']))) {
333337
if ( $_POST['v_nginx_cache'] == 'yes' ) {
334-
exec (HESTIA_CMD."v-add-fastcgi-cache ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
335-
check_return_code($return_var,$output);
336-
unset($output);
338+
if (!empty ($_POST['v_nginx_cache_length'])){
339+
echo $_POST['v_nginx_cache_length'] = "30m";
340+
}
341+
exec (HESTIA_CMD."v-add-fastcgi-cache ".$v_username." ".escapeshellarg($v_domain).' '. escapeshellarg($_POST['v_nginx_cache_length']) , $output, $return_var);
342+
check_return_code($return_var,$output);
343+
unset($output);
337344
} else {
338345
exec (HESTIA_CMD."v-delete-fastcgi-cache ".$v_username." ".escapeshellarg($v_domain), $output, $return_var);
339346
check_return_code($return_var,$output);

web/js/pages/edit_web.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ $(function() {
241241

242242
if(select.val() != 'yes'){
243243
$('#v-clear-cache').hide();
244+
$('#v_nginx_cache_length').hide();
244245
} else {
245246
$('#v-clear-cache').show();
247+
$('#v_nginx_cache_length').show();
246248
}
247249
});
248250

web/templates/admin/edit_web.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,18 @@
397397
<option value="yes" <?php if ( $v_nginx_cache == "yes") { echo 'selected'; }?>><?php echo _('Yes');?></option>
398398
</select>
399399
</td>
400+
</tr>
401+
<tr>
402+
<td class="step-left">
403+
<table id="v_nginx_cache_length" style="display:<?php if ($v_nginx_cache != 'yes' ) { echo 'none';} else {echo 'block';}?> ;" >
404+
<td class="vst-text input-label">
405+
<?php print _('Cache length'); ?> <span class="optional"><?=_('For example: 30s, 10m or 1d');?>
406+
</td>
407+
<tr>
408+
<td><input type="text" size="20" class="vst-input" name="v_nginx_cache_length" value="<?=htmlentities(trim($v_nginx_cache_length, "'"))?>"></td>
409+
</tr>
410+
</table>
411+
</td>
400412
</tr>
401413
<?php } ?>
402414
<?php if (!empty($_SESSION['WEB_BACKEND'])) { ?>

web/templates/user/edit_web.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,18 @@
397397
<option value="yes" <?php if ( $v_nginx_cache == "yes") { echo 'selected'; }?>><?php echo _('Yes');?></option>
398398
</select>
399399
</td>
400+
</tr>
401+
<tr>
402+
<td class="step-left">
403+
<table id="v_nginx_cache_length" style="display:<?php if ($v_nginx_cache == 'no' ) { echo 'none';} else {echo 'block';}?> ;" >
404+
<td class="vst-text input-label">
405+
<?php print _('Cache length'); ?> <span class="optional"><?=_('For example: 30s, 10m or 1d');?>
406+
</td>
407+
<tr>
408+
<td><input type="text" size="20" class="vst-input" name="v_nginx_cache_length" value="<?=htmlentities(trim($v_nginx_cache_length, "'"))?>"></td>
409+
</tr>
410+
</table>
411+
</td>
400412
</tr>
401413
<?php } ?>
402414
<?php if (!empty($_SESSION['WEB_BACKEND'])) { ?>

0 commit comments

Comments
 (0)