Skip to content

Commit 95bf510

Browse files
authored
Allow users to create own document error / skeleton and do not overwrite them with updating (hestiacp#3622)
* Allow Skeleton not being synced Allow users to create default templates for new clients * Rename POLICY_SYNC_ERROR to POLICY_SYNC_ERROR_DOCUMENTS * Fix error in regex * Fix broken check * Check if changes work * Add missing grep * Limit grep to 1 * fix shell check error * fix issue when update runs more then once * Set to true instead of yes
1 parent 311a884 commit 95bf510

File tree

6 files changed

+124
-36
lines changed

6 files changed

+124
-36
lines changed

bin/v-update-web-templates

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ fi
4545
for webtpl_folder in $(ls $HESTIA_INSTALL_DIR/templates/web/* -d 2> /dev/null | egrep -v '/(nginx)$'); do
4646
cp -rf "${webtpl_folder}" "${WEBTPL}/"
4747
done
48+
4849
# Skeleton, Unassinged and Suspended
49-
for webtpl_folder in $(ls $HESTIA_COMMON_DIR/templates/web/* -d 2> /dev/null); do
50-
cp -rf "${webtpl_folder}" "${WEBTPL}/"
51-
done
50+
if [ "$POLICY_SYNC_SKELETON" != "no" ]; then
51+
for webtpl_folder in $(ls $HESTIA_COMMON_DIR/templates/web/* -d 2> /dev/null); do
52+
cp -rf "${webtpl_folder}" "${WEBTPL}/"
53+
done
54+
fi
5255

5356
versions_list=$(ls -d /etc/php/*)
5457
for php_ver in $versions_list; do

func/rebuild.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,23 @@ rebuild_web_domain_conf() {
248248

249249
# Rebuilding domain directories
250250
if [ -d "$HOMEDIR/$user/web/$domain/document_errors" ]; then
251-
$BIN/v-delete-fs-directory "$user" "$HOMEDIR/$user/web/$domain/document_errors"
251+
if [ "$POLICY_SYNC_ERROR_DOCUMENTS" != "no" ]; then
252+
$BIN/v-delete-fs-directory "$user" "$HOMEDIR/$user/web/$domain/document_errors"
253+
fi
252254
fi
253255

254256
if [ ! -d $HOMEDIR/$user/web/$domain ]; then
255257
mkdir $HOMEDIR/$user/web/$domain
256258
fi
257259
chown --no-dereference $user:$user $HOMEDIR/$user/web/$domain
258260
$BIN/v-add-fs-directory "$user" "$HOMEDIR/$user/web/$domain/public_html"
259-
$BIN/v-add-fs-directory "$user" "$HOMEDIR/$user/web/$domain/document_errors"
261+
if [ ! -d "$HOMEDIR/$user/web/$domain/document_errors" ]; then
262+
$BIN/v-add-fs-directory "$user" "$HOMEDIR/$user/web/$domain/document_errors"
263+
# Propagating html skeleton
264+
if [ -d "$WEBTPL/skel/document_errors/" ]; then
265+
user_exec cp -r "$WEBTPL/skel/document_errors/" "$HOMEDIR/$user/web/$domain/"
266+
fi
267+
fi
260268
$BIN/v-add-fs-directory "$user" "$HOMEDIR/$user/web/$domain/cgi-bin"
261269
$BIN/v-add-fs-directory "$user" "$HOMEDIR/$user/web/$domain/private"
262270
$BIN/v-add-fs-directory "$user" "$HOMEDIR/$user/web/$domain/stats"
@@ -277,11 +285,6 @@ rebuild_web_domain_conf() {
277285
ln -f -s /var/log/$WEB_SYSTEM/domains/$domain.error.log .
278286
cd /
279287

280-
# Propagating html skeleton
281-
if [ -d "$WEBTPL/skel/document_errors/" ]; then
282-
user_exec cp -r "$WEBTPL/skel/document_errors/" "$HOMEDIR/$user/web/$domain/"
283-
fi
284-
285288
# Set ownership
286289
chown --no-dereference $user:$user \
287290
$HOMEDIR/$user/web/$domain \

func/syshealth.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,16 @@ function syshealth_repair_system_config() {
512512
$BIN/v-change-sys-config-value "HIDE_DOCS" "no"
513513
fi
514514

515+
if [[ -z $(check_key_exists 'POLICY_SYNC_ERROR_DOCUMENTS') ]]; then
516+
echo "[ ! ] Adding missing variable to hestia.conf: POLICY_SYNC_ERROR_DOCUMENTS ('yes')"
517+
$BIN/v-change-sys-config-value "HIDE_DOCS" "no"
518+
fi
519+
520+
if [[ -z $(check_key_exists 'POLICY_SYNC_SKELETON') ]]; then
521+
echo "[ ! ] Adding missing variable to hestia.conf: POLICY_SYNC_SKELETON ('yes')"
522+
$BIN/v-change-sys-config-value "HIDE_DOCS" "no"
523+
fi
524+
515525
touch $HESTIA/conf/hestia.conf.new
516526
while IFS='= ' read -r lhs rhs; do
517527
if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then

install/upgrade/versions/1.8.0.sh

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
####### You can use \n within the string to create new lines. #######
1818
#######################################################################################
1919

20-
upgrade_config_set_value 'UPGRADE_UPDATE_WEB_TEMPLATES' 'false'
20+
upgrade_config_set_value 'UPGRADE_UPDATE_WEB_TEMPLATES' 'true'
2121
upgrade_config_set_value 'UPGRADE_UPDATE_DNS_TEMPLATES' 'false'
2222
upgrade_config_set_value 'UPGRADE_UPDATE_MAIL_TEMPLATES' 'false'
23-
upgrade_config_set_value 'UPGRADE_REBUILD_USERS' 'false'
23+
upgrade_config_set_value 'UPGRADE_REBUILD_USERS' 'true'
2424
upgrade_config_set_value 'UPGRADE_UPDATE_FILEMANAGER_CONFIG' 'false'
2525

2626
if [ "$IMAP_SYSTEM" = "dovecot" ]; then
@@ -37,15 +37,15 @@ fi
3737

3838
if [ -f /etc/fail2ban/jail.local ]; then
3939
# Add phpmyadmin rule
40-
if ! -qw "^[phpmyadmin-auth]$" /etc/fail2ban/jail.local 2> /dev/null; then
40+
if ! grep -qw "^[phpmyadmin-auth]$" /etc/fail2ban/jail.local 2> /dev/null; then
4141
sed -i '/\[recidive\]/i [phpmyadmin-auth]\nenabled = true\nfilter = phpmyadmin-syslog\naction = hestia[name=WEB]\nlogpath = /var/log/auth.log\nmaxretry = 5\n' /etc/fail2ban/jail.local
4242
fi
4343
fi
4444

4545
if [ "$MAIL_SYSTEM" = "exim4" ]; then
4646
echo "[ * ] Disable SMTPUTF8 for Exim for now"
47-
if grep -qw "^smtputf8_advertise_hosts =" /etc/exim4/exim4.conf.template 2> /dev/null; then
48-
sed -i "/^domainlist local_domains = dsearch;\/etc\/exim4\/domains\/i smtputf8_advertise_hosts =" /etc/exim4/exim4.conf.template
47+
if ! grep -qw "^smtputf8_advertise_hosts =" /etc/exim4/exim4.conf.template 2> /dev/null; then
48+
sed -i "/^domainlist local_domains = dsearch;\/etc\/exim4\/domains/i smtputf8_advertise_hosts =" /etc/exim4/exim4.conf.template
4949
fi
5050
fi
5151

@@ -56,30 +56,32 @@ echo '[ * ] Enable the "Enhanced and Optimized TLS" feature...'
5656
os_release="$(lsb_release -s -i | tr "[:upper:]" "[:lower:]")-$(lsb_release -s -r)"
5757
tls13_ciphers="TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384"
5858

59-
if [ "$os_release" = "debian-10" ] || [ "$os_release" = "debian-11" ]; then
60-
sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
61-
elif [ "$os_release" = "debian-12" ]; then
62-
if ! grep -qw "^ssl_conf = ssl_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
63-
sed -i '/providers = provider_sect$/a ssl_conf = ssl_sect' /etc/ssl/openssl.cnf
64-
fi
65-
66-
if ! grep -qw "^[ssl_sect]$" /etc/ssl/openssl.cnf 2> /dev/null; then
67-
sed -i '$a \\n[ssl_sect]\nsystem_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
68-
elif grep -qw "^system_default = system_default_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
59+
if ! grep -qw "^[hestia_openssl_sect]$" /etc/ssl/openssl.cnf 2> /dev/null; then
60+
if [ "$os_release" = "debian-10" ] || [ "$os_release" = "debian-11" ]; then
6961
sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
70-
fi
71-
elif [ "$os_release" = "ubuntu-20.04" ]; then
72-
if ! grep -qw "^openssl_conf = default_conf$" /etc/ssl/openssl.cnf 2> /dev/null; then
73-
sed -i '/^oid_section = new_oids$/a \\n# System default\nopenssl_conf = default_conf' /etc/ssl/openssl.cnf
74-
fi
62+
elif [ "$os_release" = "debian-12" ]; then
63+
if ! grep -qw "^ssl_conf = ssl_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
64+
sed -i '/providers = provider_sect$/a ssl_conf = ssl_sect' /etc/ssl/openssl.cnf
65+
fi
7566

76-
if ! grep -qw "^[default_conf]$" /etc/ssl/openssl.cnf 2> /dev/null; then
77-
sed -i '$a [default_conf]\nssl_conf = ssl_sect\n\n[ssl_sect]\nsystem_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
78-
elif grep -qw "^system_default = system_default_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
67+
if ! grep -qw "^[ssl_sect]$" /etc/ssl/openssl.cnf 2> /dev/null; then
68+
sed -i '$a \\n[ssl_sect]\nsystem_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
69+
elif grep -qw "^system_default = system_default_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
70+
sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
71+
fi
72+
elif [ "$os_release" = "ubuntu-20.04" ]; then
73+
if ! grep -qw "^openssl_conf = default_conf$" /etc/ssl/openssl.cnf 2> /dev/null; then
74+
sed -i '/^oid_section = new_oids$/a \\n# System default\nopenssl_conf = default_conf' /etc/ssl/openssl.cnf
75+
fi
76+
77+
if ! grep -qw "^[default_conf]$" /etc/ssl/openssl.cnf 2> /dev/null; then
78+
sed -i '$a [default_conf]\nssl_conf = ssl_sect\n\n[ssl_sect]\nsystem_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
79+
elif grep -qw "^system_default = system_default_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
80+
sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
81+
fi
82+
elif [ "$os_release" = "ubuntu-22.04" ]; then
7983
sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
8084
fi
81-
elif [ "$os_release" = "ubuntu-22.04" ]; then
82-
sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
8385
fi
8486

8587
# Update server configuration files
@@ -150,7 +152,8 @@ if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
150152
echo -e "[ ! ] Manual action required, please view:\n[ - ] $HESTIA_BACKUP/message.log"
151153
add_upgrade_message "Manual Action Required [IMPORTANT]\n\nTo enable the \"Enhanced and Optimized TLS\" feature, we must update the NGINX configuration file (/etc/nginx/nginx.conf).\n\nBut for unknown reason or you edited it, may not be fully apply all the changes in this upgrade.\n\nPlease follow the default configuration file to sync it:\n$HESTIA_INSTALL_DIR/nginx/nginx.conf\n\nBacked up configuration file:\n$HESTIA_BACKUP/conf/nginx/nginx.conf\n\nLearn more:\nhttps://github.com/hestiacp/hestiacp/pull/3555"
152154
"$BIN"/v-add-user-notification admin "IMPORTANT: Manual Action Required" 'To enable the <b>Enhanced and Optimized TLS</b> feature, we must update the NGINX configuration file (/etc/nginx/nginx.conf).<br><br>But for unknown reason or you edited it, may not be fully apply all the changes in this upgrade.<br><br>Please follow the default configuration file to sync it:<br>'"$HESTIA_INSTALL_DIR"'/nginx/nginx.conf<br><br>Backed up configuration file:<br>'"$HESTIA_BACKUP"'/conf/nginx/nginx.conf<br><br>Visit PR <a href="https://github.com/hestiacp/hestiacp/pull/3555" target="_blank">#3555</a> on GitHub to learn more.'
153-
sed -i "s/""$(grep "IMPORTANT: Manual Action Required" "$HESTIA"/data/users/admin/notifications.conf | awk '{print $1}')""/NID='1'/" "$HESTIA"/data/users/admin/notifications.conf
155+
156+
sed -i "s/""$(grep -m 1 "IMPORTANT: Manual Action Required" "$HESTIA"/data/users/admin/notifications.conf | awk '{print $1}')""/NID='1'/" "$HESTIA"/data/users/admin/notifications.conf
154157

155158
cp -f /etc/nginx/nginx.conf /etc/nginx/nginx.conf-staging
156159

web/edit/server/index.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,41 @@
15651565
}
15661566
}
15671567

1568+
if (empty($_SESSION["error_msg"])) {
1569+
if ($_POST["v_policy_sync_error_documents"] != $_SESSION["POLICY_SYNC_ERROR_DOCUMENTS"]) {
1570+
exec(
1571+
HESTIA_CMD .
1572+
"v-change-sys-config-value POLICY_SYNC_ERROR_DOCUMENTS " .
1573+
quoteshellarg($_POST["v_policy_sync_error_documents"]),
1574+
$output,
1575+
$return_var,
1576+
);
1577+
check_return_code($return_var, $output);
1578+
unset($output);
1579+
if (empty($_SESSION["error_msg"])) {
1580+
$v_policy_system_hide_services = $_POST["v_policy_sync_error_documents"];
1581+
}
1582+
$v_security_adv = "yes";
1583+
}
1584+
}
1585+
if (empty($_SESSION["error_msg"])) {
1586+
if ($_POST["v_policy_sync_skeleton"] != $_SESSION["POLICY_SYNC_SKELETON"]) {
1587+
exec(
1588+
HESTIA_CMD .
1589+
"v-change-sys-config-value POLICY_SYNC_SKELETON " .
1590+
quoteshellarg($_POST["v_policy_sync_skeleton"]),
1591+
$output,
1592+
$return_var,
1593+
);
1594+
check_return_code($return_var, $output);
1595+
unset($output);
1596+
if (empty($_SESSION["error_msg"])) {
1597+
$v_policy_system_hide_services = $_POST["v_policy_sync_skeleton"];
1598+
}
1599+
$v_security_adv = "yes";
1600+
}
1601+
}
1602+
15681603
// Change login style
15691604
if (empty($_SESSION["error_msg"])) {
15701605
if ($_POST["v_login_style"] != $_SESSION["LOGIN_STYLE"]) {

web/templates/pages/edit_server.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,40 @@ class="form-select"
12501250
</option>
12511251
</select>
12521252
</div>
1253+
<div class="u-mb10">
1254+
<label for="v_policy_sync_error_documents" class="form-label">
1255+
<?= _("Sync Error document templates on user rebuild") ?>
1256+
</label>
1257+
<select
1258+
class="form-select"
1259+
name="v_policy_sync_error_documents"
1260+
id="v_policy_sync_error_documents"
1261+
>
1262+
<option value="yes">
1263+
<?= _("Yes") ?>
1264+
</option>
1265+
<option value="no" <?= $_SESSION["POLICY_SYNC_ERROR_DOCUMENTS"] == "no" ? "selected" : "" ?>>
1266+
<?= _("No") ?>
1267+
</option>
1268+
</select>
1269+
</div>
1270+
<div class="u-mb10">
1271+
<label for="v_policy_sync_skeleton" class="form-label">
1272+
<?= _("Sync Skeleton templates") ?>
1273+
</label>
1274+
<select
1275+
class="form-select"
1276+
name="v_policy_sync_skeleton"
1277+
id="v_policy_sync_skeleton"
1278+
>
1279+
<option value="yes">
1280+
<?= _("Yes") ?>
1281+
</option>
1282+
<option value="no" <?= $_SESSION["POLICY_SYNC_SKELETON"] == "no" ? "selected" : "" ?>>
1283+
<?= _("No") ?>
1284+
</option>
1285+
</select>
1286+
</div>
12531287
<div class="u-mb10">
12541288
<label for="v_policy_user_view_logs" class="form-label">
12551289
<?= _("Allow users to view action and login history logs") ?>

0 commit comments

Comments
 (0)