Fix 404 error
parent
7a67004c56
commit
87bc4168ba
|
|
@ -148,16 +148,18 @@ if [ -f "$VHOST_CONFIG" ]; then
|
||||||
# If rules are not already in place, add them.
|
# If rules are not already in place, add them.
|
||||||
if ! sudo grep -qF "$MARKER" "$VHOST_CONFIG"; then
|
if ! sudo grep -qF "$MARKER" "$VHOST_CONFIG"; then
|
||||||
|
|
||||||
# Remove any existing rewrite block to ensure a clean state.
|
# Ensure xmlstarlet is installed, as it's the safest way to edit XML.
|
||||||
sudo sed -i '/\s*<rewrite>/,/<\/rewrite>/d' "$VHOST_CONFIG"
|
if ! command -v xmlstarlet &> /dev/null; then
|
||||||
|
echo "xmlstarlet not found. Installing for safe XML editing..." >&2
|
||||||
|
if ! sudo dnf install -y xmlstarlet; then
|
||||||
|
echo "FATAL: Failed to install xmlstarlet. Cannot safely modify vhost." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Define the new rewrite block using a temporary file to avoid escaping issues.
|
# Define the new rules content. Note the lack of indentation.
|
||||||
REWRITE_TMP=$(mktemp)
|
# xmlstarlet will handle the formatting.
|
||||||
cat > "$REWRITE_TMP" <<'EOF'
|
NEW_RULES_CONTENT=$(cat <<'EOF'
|
||||||
<rewrite>
|
|
||||||
<enable>1</enable>
|
|
||||||
<logLevel>0</logLevel>
|
|
||||||
<rules>
|
|
||||||
# PMA Gateway Security Rules
|
# PMA Gateway Security Rules
|
||||||
# Allow access to the gateway scripts themselves
|
# Allow access to the gateway scripts themselves
|
||||||
RewriteCond %{REQUEST_URI} ^/access-db-.*\.php$
|
RewriteCond %{REQUEST_URI} ^/access-db-.*\.php$
|
||||||
|
|
@ -165,14 +167,19 @@ if [ -f "$VHOST_CONFIG" ]; then
|
||||||
# For all other requests, block if the security cookie is not present
|
# For all other requests, block if the security cookie is not present
|
||||||
RewriteCond %{HTTP_COOKIE} !pma_access_granted
|
RewriteCond %{HTTP_COOKIE} !pma_access_granted
|
||||||
RewriteRule .* - [F,L]
|
RewriteRule .* - [F,L]
|
||||||
</rules>
|
|
||||||
</rewrite>
|
|
||||||
EOF
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
# Use awk to insert the new block before the </vhssl> tag for robustness
|
# Use xmlstarlet to atomically update the rewrite block in-place.
|
||||||
sudo awk -v r="$(cat $REWRITE_TMP)" '{if (/\s*<vhssl>/) print r} {print}' "$VHOST_CONFIG" | sudo tee "$VHOST_CONFIG" > /dev/null
|
# This is far safer than sed/awk for structured XML.
|
||||||
|
if ! sudo xmlstarlet ed -L \
|
||||||
|
-u "//virtualHostConfig/rewrite/enable" -v "1" \
|
||||||
|
-u "//virtualHostConfig/rewrite/rules" -v "$NEW_RULES_CONTENT" \
|
||||||
|
"$VHOST_CONFIG"; then
|
||||||
|
echo "FATAL: xmlstarlet failed to update $VHOST_CONFIG." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
rm -f "$REWRITE_TMP"
|
|
||||||
NEEDS_RESTART=1
|
NEEDS_RESTART=1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue