fix(restore): nextcloud config.php patching for redis host and trusted_domains

Erstlauf 2026-06-03 scheiterte mit 503: Redis-Host war noch auf dem
produktiven 'nextcloud-redis' statt 'restoretest-nextcloud-redis', und
trusted_domains enthielt kein 127.0.0.1 (Nextcloud blockt mit
"Access through untrusted domain").

Ursache: das sed-Pattern fuer Redis versuchte den ganzen Array-Block
einzeilig zu ersetzen, traf aber das PHP-Mehrzeilenformat nicht. Und
das trusted_domains-sed fand das Schliessmuster nicht zuverlaessig.

Fix:
- Redis-Host separat per sed patchen (nur den 'host'-Wert im Block)
- trusted_domains per PHP-CLI rewrite (robuster als sed auf PHP-Arrays)
- Fallback auf sed fuer Hosts ohne php

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 10:34:30 +02:00
parent f473fbaa8b
commit 6f0e6f0d5a
+22 -4
View File
@@ -142,14 +142,32 @@ if [ -f "$CONFIG_PHP" ]; then
-e "s|'dbpassword'.*|'dbpassword' => 'restoretest-nextcloud-db',|" \
-e "s|'dbname'.*|'dbname' => 'nextcloud',|" \
-e "s|'dbport'.*|'dbport' => '',|" \
-e "s|'redis'.*=>.*array.*|'redis' => array( 'host' => 'restoretest-nextcloud-redis', 'port' => 6379 ),|" \
"$CONFIG_PHP"
# trusted_domains: 127.0.0.1 hinzufuegen, damit der Smoke-Endpunkt akzeptiert wird
# Nextcloud prueft trusted_domains und blockt sonst mit "Access through untrusted domain"
# Redis-Host patchen. Die config.php hat ein verschachteltes Array:
# 'redis' => array( 'host' => 'nextcloud-redis', ... )
# Wir ersetzen nur den Host-Wert innerhalb des redis-Blocks.
sed -i "s|'host' => 'nextcloud-redis'|'host' => 'restoretest-nextcloud-redis'|g" "$CONFIG_PHP"
# trusted_domains: 127.0.0.1 hinzufuegen, damit der Smoke-Endpunkt akzeptiert wird.
# Nextcloud prueft trusted_domains und blockt sonst mit "Access through untrusted domain" (503).
# Wir fuegen per PHP-Code-Injection am Ende der config eine zweite trusted_domain hinzu.
# Das ist robuster als den Array-Block per sed zu finden.
php -r "
\$f = '$CONFIG_PHP';
\$c = file_get_contents(\$f);
if (strpos(\$c, \"'127.0.0.1'\") === false) {
include \$f;
\$CONFIG['trusted_domains'][] = '127.0.0.1';
\$out = '<?php' . PHP_EOL . '\$CONFIG = ' . var_export(\$CONFIG, true) . ';' . PHP_EOL;
file_put_contents(\$f, \$out);
}
" 2>/dev/null || {
# Fallback: wenn php nicht auf dem Host ist, per sed versuchen
if ! grep -q "127.0.0.1" "$CONFIG_PHP"; then
sed -i "/trusted_domains/,/)/s|);| 999 => '127.0.0.1',\n);|" "$CONFIG_PHP" || true
sed -i "/'trusted_domains'/,/^ )/s|^ )| 99 => '127.0.0.1',\n )|" "$CONFIG_PHP" || true
fi
}
config_patched="ok"
else