Report real WebDAV failure cause and missing WebDAV configuration

This commit is contained in:
Terranom674
2026-08-19 13:04:36 +02:00
parent b4161471ca
commit a4f953551c

View File

@@ -17,41 +17,55 @@ read_config_value() {
printf '%s' "$value" printf '%s' "$value"
} }
compact_text() {
printf '%s\n' "$1" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
}
read_webdav_failure_detail() { read_webdav_failure_detail() {
local config="$1" local config="$1"
local connection_id piwigo_root status_file local captured_output="${2:-}"
local connection_id piwigo_root status_file status_detail
connection_id="$(read_config_value CONNECTION_ID "$config")" connection_id="$(read_config_value CONNECTION_ID "$config")"
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")" piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
[[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo" [[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo"
if [[ -z "$connection_id" ]]; then status_detail=""
printf '%s' 'WebDAV-Lauf fehlgeschlagen; Verbindungs-ID konnte nicht ermittelt werden.' if [[ -n "$connection_id" ]]; then
return 0 status_file="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status/connection-${connection_id}.json"
if [[ -r "$status_file" ]]; then
status_detail="$(php -r '
$file = $argv[1];
$data = json_decode((string)@file_get_contents($file), true);
if (!is_array($data)) exit(0);
$message = trim((string)($data["message"] ?? ""));
$detail = trim((string)($data["error_detail"] ?? ""));
$parts = array();
if ($message !== "") $parts[] = $message;
if ($detail !== "") $parts[] = $detail;
if ($parts) {
$text = preg_replace("/\\s+/u", " ", implode(" - ", $parts));
echo trim((string)$text);
}
' "$status_file")"
fi
fi fi
status_file="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status/connection-${connection_id}.json" if [[ -n "$captured_output" ]]; then
if [[ ! -r "$status_file" ]]; then captured_output="$(compact_text "$captured_output")"
printf '%s' "WebDAV-Lauf fehlgeschlagen; Detailstatus fuer Verbindung ${connection_id} ist nicht lesbar."
return 0
fi fi
php -r ' if [[ -n "$status_detail" && -n "$captured_output" ]]; then
$file = $argv[1]; printf '%s' "$status_detail | Prozessausgabe: $captured_output"
$data = json_decode((string)@file_get_contents($file), true); elif [[ -n "$status_detail" ]]; then
if (!is_array($data)) { printf '%s' "$status_detail"
echo "WebDAV-Lauf fehlgeschlagen; Detailstatus ist ungueltig."; elif [[ -n "$captured_output" ]]; then
exit(0); printf '%s' "$captured_output"
} elif [[ -z "$connection_id" ]]; then
$message = trim((string)($data["message"] ?? "")); printf '%s' 'WebDAV-Prozess wurde gestartet, aber die Verbindungs-ID fehlt in der Runtime-Konfiguration.'
$detail = trim((string)($data["error_detail"] ?? "")); else
$parts = array(); printf '%s' "WebDAV-Prozess fuer Verbindung ${connection_id} endete mit Fehler, lieferte aber weder Statusdatei noch Prozessausgabe."
if ($message !== "") $parts[] = $message; fi
if ($detail !== "") $parts[] = $detail;
if (!$parts) $parts[] = "WebDAV-Lauf fehlgeschlagen; kein Fehlerdetail gespeichert.";
$text = preg_replace("/\\s+/u", " ", implode(" - ", $parts));
echo trim((string)$text);
' "$status_file"
} }
write_route_status() { write_route_status() {
@@ -123,18 +137,29 @@ webdav_success=0
webdav_failed=0 webdav_failed=0
webdav_failure_detail="" webdav_failure_detail=""
for config in "${webdav_configs[@]}"; do if [[ ${#webdav_configs[@]} -eq 0 ]]; then
name="$(basename "$config")" webdav_failed=1
echo "NC Connector WebDAV primaer: $name" webdav_failure_detail="Keine WebDAV-Runtime-Verbindung ist konfiguriert. Es existiert aktuell nur die Legacy-Verbindung; deshalb kann WebDAV nicht primaer laufen."
if env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh"; then echo "NC Connector: $webdav_failure_detail" >&2
webdav_success=1 else
else for config in "${webdav_configs[@]}"; do
webdav_failed=1 name="$(basename "$config")"
webdav_failure_detail="$(read_webdav_failure_detail "$config")" echo "NC Connector WebDAV primaer: $name"
echo "NC Connector: WebDAV-Lauf fehlgeschlagen: $webdav_failure_detail" >&2 webdav_output=""
echo "NC Connector: Legacy-Fallback bleibt verfuegbar." >&2 if webdav_output="$(env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh" 2>&1)"; then
fi webdav_success=1
done [[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output"
else
webdav_exit=$?
webdav_failed=1
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output" >&2
webdav_failure_detail="$(read_webdav_failure_detail "$config" "$webdav_output")"
webdav_failure_detail="Exit-Code ${webdav_exit}: ${webdav_failure_detail}"
echo "NC Connector: WebDAV-Lauf fehlgeschlagen: $webdav_failure_detail" >&2
echo "NC Connector: Legacy-Fallback bleibt verfuegbar." >&2
fi
done
fi
if [[ "$webdav_success" -eq 1 ]]; then if [[ "$webdav_success" -eq 1 ]]; then
write_route_status \ write_route_status \
@@ -148,7 +173,7 @@ if [[ "$webdav_success" -eq 1 ]]; then
fi fi
if [[ ${#configs[@]} -eq 0 ]]; then if [[ ${#configs[@]} -eq 0 ]]; then
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV ist fehlgeschlagen; kein Detailstatus verfuegbar." [[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV ist fehlgeschlagen; Ursache konnte nicht ermittelt werden."
write_route_status \ write_route_status \
"failed" \ "failed" \
"FEHLER - kein Datenweg" \ "FEHLER - kein Datenweg" \
@@ -191,7 +216,7 @@ for config in "${configs[@]}"; do
done done
if [[ "$legacy_result" -eq 0 ]]; then if [[ "$legacy_result" -eq 0 ]]; then
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; kein Detailstatus verfuegbar." [[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; Ursache konnte nicht ermittelt werden."
write_route_status \ write_route_status \
"legacy_fallback" \ "legacy_fallback" \
"LEGACY-FALLBACK AKTIV" \ "LEGACY-FALLBACK AKTIV" \
@@ -202,7 +227,7 @@ if [[ "$legacy_result" -eq 0 ]]; then
exit 0 exit 0
fi fi
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; kein Detailstatus verfuegbar." [[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; Ursache konnte nicht ermittelt werden."
write_route_status \ write_route_status \
"failed" \ "failed" \
"FEHLER - WebDAV und Fallback" \ "FEHLER - WebDAV und Fallback" \