Refactor v-fix-website-permissions to introduce conditional checks for PHP and symlink ownership adjustments, allowing for more flexible permission management based on configuration files.

This commit is contained in:
Peca 2025-08-07 18:29:11 +02:00
commit 5008c2c778

View file

@ -68,15 +68,45 @@ if [ -z "$SKIP_OWNERSHIP_CHECK" ] && [ -f "public_html/index.php" ]; then
fi fi
fi fi
echo "Updating permissions for /home/$USER/web/$domain/"
echo "Updating permissions for /home/$USER/web/$domain/public_html/" php_chmod_allowed=1
if [ -f "/home/php_chmod_disabled" ]; then
php_chmod_allowed=0
fi
if [ -f "/home/$USER/php_chmod_disabled" ]; then
php_chmod_allowed=0
fi
if [ -f "/home/$USER/web/php_chmod_disabled" ]; then
php_chmod_allowed=0
fi
if [ -f "/home/$USER/web/$domain/php_chmod_disabled" ]; then
php_chmod_allowed=0
fi
# === General files and directories permissions ===
if [ "$php_chmod_allowed" -eq 1 ]; then
# New way of fixing permissions
# Fixing permissions # Fixing permissions
find public_html/ -type d ! -perm 755 -exec chmod 755 {} + find public_html/ -type d ! -perm 755 -exec chmod 755 {} +
find public_html/ -type f ! \( -name "*.php" -o -name "*.env" \) ! -perm 644 -exec chmod 644 {} + find public_html/ -type f ! \( -name "*.php" -o -name "*.env" \) ! -perm 644 -exec chmod 644 {} +
# Fixing ownership # Fixing ownership
find public_html/ -type d ! -user $USER -exec chown $USER:$USER {} + find public_html/ -type d ! -user $USER -exec chown $USER:$USER {} +
find public_html/ -type f ! \( -name "*.php" -o -name "*.env" \) ! -user $USER -exec chown $USER:$USER {} + find public_html/ -type f ! \( -name "*.php" -o -name "*.env" \) ! -user $USER -exec chown $USER:$USER {} +
else
# Old way of fixing permissions
# Fixing permissions
find public_html/ -type d ! -perm 755 -exec chmod 755 {} +
find public_html/ -type f ! -perm 644 -exec chmod 644 {} +
# Fixing ownership
find public_html/ -type d ! -user $USER -exec chown $USER:$USER {} +
find public_html/ -type f ! -user $USER -exec chown $USER:$USER {} +
fi
# === PHP and .env permissions ===
if [ "$php_chmod_allowed" -eq 1 ]; then
php_chmod="600" php_chmod="600"
if [ "$WEB_SYSTEM" = 'nginx' ]; then if [ "$WEB_SYSTEM" = 'nginx' ]; then
@ -102,6 +132,26 @@ echo "= Setting chmod $php_chmod for all .php and .env files"
find -type f \( -name "*.php" -o -name "*.env" \) ! -perm $php_chmod -exec chmod $php_chmod {} + find -type f \( -name "*.php" -o -name "*.env" \) ! -perm $php_chmod -exec chmod $php_chmod {} +
# Fixing ownership # Fixing ownership
find -type f \( -name "*.php" -o -name "*.env" \) ! -user $USER -exec chown $USER:$USER {} + find -type f \( -name "*.php" -o -name "*.env" \) ! -user $USER -exec chown $USER:$USER {} +
fi
# === Symlinks ownership ===
symlink_chown_allowed=1
if [ -f "/home/symlink_chown_disabled" ]; then
symlink_chown_allowed=0
fi
if [ -f "/home/$USER/symlink_chown_disabled" ]; then
symlink_chown_allowed=0
fi
if [ -f "/home/$USER/web/symlink_chown_disabled" ]; then
symlink_chown_allowed=0
fi
if [ -f "/home/$USER/web/$domain/symlink_chown_disabled" ]; then
symlink_chown_allowed=0
fi
if [ "$symlink_chown_allowed" -eq 1 ]; then
find -type l ! -user $USER -exec chown -h $USER:$USER {} +
fi
#----------------------------------------------------------# #----------------------------------------------------------#
# Vesta # # Vesta #