mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 21:04:33 +00:00
Compare commits
17 Commits
fix/09723-
...
fix/09728-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af129c8202 | ||
|
|
e8ef0a50e8 | ||
|
|
8641b37eeb | ||
|
|
ee40d2f159 | ||
|
|
2e8f733646 | ||
|
|
de39d5849a | ||
|
|
73707433c5 | ||
|
|
dbc5e27693 | ||
|
|
91f0d0cac1 | ||
|
|
2c1c7ff499 | ||
|
|
3a15c2d03d | ||
|
|
2acdbc65a2 | ||
|
|
8510d9faad | ||
|
|
f21f19bd30 | ||
|
|
29990aee4f | ||
|
|
9c551c8dfc | ||
|
|
e5bc260622 |
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Bratonien Tools
|
||||
Version: 0.9.7.23
|
||||
Version: 0.9.7.28
|
||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||
Author: Bratonien
|
||||
|
||||
0
runtime/lib/piwigo-sync.php
Executable file → Normal file
0
runtime/lib/piwigo-sync.php
Executable file → Normal file
@@ -4,7 +4,6 @@ set -Eeuo pipefail
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PIWIGO_ROOT_DEFAULT="${BRATONIEN_NC_PIWIGO_ROOT:-$(cd -- "$SCRIPT_DIR/../../.." && pwd)}"
|
||||
CONFIG_DIR="${BRATONIEN_NC_CONFIG_DIR:-/etc/bratonien-tools/nc-connector}"
|
||||
NATIVE_MODE="${BRATONIEN_NC_NATIVE:-0}"
|
||||
TARGET_CONNECTION_ID="${BRATONIEN_NC_CONNECTION_ID:-0}"
|
||||
GLOBAL_LOCK_DIR="${PIWIGO_ROOT_DEFAULT%/}/_data/bratonien-tools/nc-connector-scheduler"
|
||||
GLOBAL_LOCK_FILE="$GLOBAL_LOCK_DIR/worker.lock"
|
||||
@@ -55,25 +54,17 @@ write_route_status() {
|
||||
' "$ROUTE_STATUS_FILE" "$route" "$label" "$detail" "$success"
|
||||
}
|
||||
|
||||
if [[ "$NATIVE_MODE" != "1" ]]; then
|
||||
php "$SCRIPT_DIR/reconcile.php"
|
||||
fi
|
||||
# Legacy ist beendet. Der Runner bereitet ausschließlich die aktuelle WebDAV-Runtime vor.
|
||||
php "$SCRIPT_DIR/reconcile-webdav.php"
|
||||
php "$SCRIPT_DIR/cleanup-webdav-piwigo.php"
|
||||
if [[ "$NATIVE_MODE" != "1" ]]; then
|
||||
php "$SCRIPT_DIR/cleanup-stale.php"
|
||||
fi
|
||||
|
||||
configs=("$CONFIG_DIR"/connection-*.conf)
|
||||
webdav_configs=("$CONFIG_DIR"/webdav-connection-*.conf)
|
||||
|
||||
if [[ ${#configs[@]} -eq 0 && ${#webdav_configs[@]} -eq 0 ]]; then
|
||||
echo "Keine NC-Connector-Verbindungen konfiguriert."
|
||||
if [[ ${#webdav_configs[@]} -eq 0 ]]; then
|
||||
echo "Keine WebDAV-NC-Connector-Verbindungen konfiguriert."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
route_piwigo_root=""
|
||||
for candidate in "${webdav_configs[@]}" "${configs[@]}"; do
|
||||
for candidate in "${webdav_configs[@]}"; do
|
||||
[[ -f "$candidate" ]] || continue
|
||||
candidate_id="$(read_config_value CONNECTION_ID "$candidate")"
|
||||
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$candidate_id" != "$TARGET_CONNECTION_ID" ]]; then
|
||||
@@ -86,10 +77,8 @@ done
|
||||
ROUTE_STATUS_FILE="${route_piwigo_root%/}/_data/bratonien-tools/nc-connector-status/route-status.json"
|
||||
|
||||
failure_count=0
|
||||
webdav_count=0
|
||||
local_count=0
|
||||
summary_parts=()
|
||||
matched_count=0
|
||||
summary_parts=()
|
||||
|
||||
for config in "${webdav_configs[@]}"; do
|
||||
[[ -f "$config" ]] || continue
|
||||
@@ -106,7 +95,6 @@ for config in "${webdav_configs[@]}"; do
|
||||
fi
|
||||
|
||||
matched_count=$((matched_count + 1))
|
||||
webdav_count=$((webdav_count + 1))
|
||||
echo "NC Connector WebDAV #$connection_id: $name"
|
||||
output=""
|
||||
if output="$(env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh" 2>&1)"; then
|
||||
@@ -120,75 +108,21 @@ for config in "${webdav_configs[@]}"; do
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$NATIVE_MODE" != "1" ]]; then
|
||||
for config in "${configs[@]}"; do
|
||||
[[ -f "$config" ]] || continue
|
||||
name="$(basename "$config")"
|
||||
connection_id="0"
|
||||
if [[ "$name" =~ ^connection-([0-9]+)\.conf$ ]]; then
|
||||
connection_id="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
if [[ "$connection_id" -lt 1 ]]; then
|
||||
echo "NC Connector: $name besitzt keine gueltige Verbindungs-ID." >&2
|
||||
failure_count=$((failure_count + 1))
|
||||
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
||||
continue
|
||||
fi
|
||||
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$connection_id" != "$TARGET_CONNECTION_ID" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
matched_count=$((matched_count + 1))
|
||||
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
||||
[[ -n "$piwigo_root" ]] || piwigo_root="$PIWIGO_ROOT_DEFAULT"
|
||||
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
||||
if [[ -f "$tombstone_dir/deleted-$connection_id" ]]; then
|
||||
echo "NC Connector: Verbindung $connection_id wurde geloescht; Laufzeitdateien werden entfernt."
|
||||
rm -f -- "$CONFIG_DIR/connection-$connection_id.conf" \
|
||||
"$CONFIG_DIR/connection-$connection_id.db-password" \
|
||||
"$CONFIG_DIR/connection-$connection_id.piwigo-password" \
|
||||
"$CONFIG_DIR/connection-$connection_id.storages.tsv" \
|
||||
"$CONFIG_DIR/connection-$connection_id.roots.tsv"
|
||||
rm -f -- "$tombstone_dir/deleted-$connection_id"
|
||||
continue
|
||||
fi
|
||||
|
||||
local_count=$((local_count + 1))
|
||||
echo "NC Connector Local #$connection_id: $name"
|
||||
if env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync.sh"; then
|
||||
summary_parts+=("Local #$connection_id erfolgreich")
|
||||
else
|
||||
failure_count=$((failure_count + 1))
|
||||
summary_parts+=("Local #$connection_id fehlgeschlagen")
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$matched_count" -eq 0 ]]; then
|
||||
write_route_status "failed" "FEHLER - Verbindung #$TARGET_CONNECTION_ID" "Keine Laufzeitkonfiguration für Verbindung #$TARGET_CONNECTION_ID gefunden." "0"
|
||||
echo "NC Connector: keine Laufzeitkonfiguration für Verbindung #$TARGET_CONNECTION_ID gefunden." >&2
|
||||
write_route_status "failed" "FEHLER - Verbindung #$TARGET_CONNECTION_ID" "Keine WebDAV-Laufzeitkonfiguration für Verbindung #$TARGET_CONNECTION_ID gefunden." "0"
|
||||
echo "NC Connector: keine WebDAV-Laufzeitkonfiguration für Verbindung #$TARGET_CONNECTION_ID gefunden." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
summary_detail="$(IFS='; '; printf '%s' "${summary_parts[*]}")"
|
||||
[[ -n "$summary_detail" ]] || summary_detail="Keine Verbindung wurde ausgefuehrt."
|
||||
[[ -n "$summary_detail" ]] || summary_detail="Keine WebDAV-Verbindung wurde ausgefuehrt."
|
||||
|
||||
if [[ "$failure_count" -eq 0 ]]; then
|
||||
if [[ "$webdav_count" -gt 0 && "$local_count" -gt 0 ]]; then
|
||||
route="mixed"
|
||||
label="WebDAV + Local"
|
||||
elif [[ "$webdav_count" -gt 0 ]]; then
|
||||
route="webdav"
|
||||
label="WebDAV"
|
||||
else
|
||||
route="local"
|
||||
label="Local"
|
||||
fi
|
||||
write_route_status "$route" "$label" "$summary_detail" "1"
|
||||
echo "NC Connector: angeforderte Verbindung wurde erfolgreich verarbeitet."
|
||||
write_route_status "webdav" "WebDAV" "$summary_detail" "1"
|
||||
echo "NC Connector: WebDAV-Verbindung wurde erfolgreich verarbeitet."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
write_route_status "failed" "FEHLER - angeforderte Verbindung" "$summary_detail" "0"
|
||||
echo "NC Connector: die angeforderte Verbindung ist fehlgeschlagen." >&2
|
||||
write_route_status "failed" "FEHLER - WebDAV-Verbindung" "$summary_detail" "0"
|
||||
echo "NC Connector: die angeforderte WebDAV-Verbindung ist fehlgeschlagen." >&2
|
||||
exit 1
|
||||
|
||||
@@ -59,6 +59,10 @@ for target in (status_file, public_file):
|
||||
PY
|
||||
}
|
||||
|
||||
compact_output() {
|
||||
tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
||||
}
|
||||
|
||||
failure() {
|
||||
local code="$1" command="$2" line="$3"
|
||||
trap - ERR
|
||||
@@ -97,7 +101,7 @@ fi
|
||||
if [[ "$PLACEHOLDER_EXIT" -ne 0 ]]; then
|
||||
DETAIL="Exit-Code: $PLACEHOLDER_EXIT"
|
||||
if [[ -n "$PLACEHOLDER_OUTPUT" ]]; then
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$PLACEHOLDER_OUTPUT" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//')"
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$PLACEHOLDER_OUTPUT" | compact_output)"
|
||||
fi
|
||||
trap - ERR
|
||||
write_status error "WebDAV-Shadow-Tree fehlgeschlagen" "$DETAIL"
|
||||
@@ -118,7 +122,7 @@ fi
|
||||
if [[ "$SHADOW_EXIT" -ne 0 ]]; then
|
||||
DETAIL="Exit-Code: $SHADOW_EXIT"
|
||||
if [[ -n "$SHADOW_OUTPUT" ]]; then
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$SHADOW_OUTPUT" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//')"
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$SHADOW_OUTPUT" | compact_output)"
|
||||
fi
|
||||
trap - ERR
|
||||
write_status error "WebDAV-Shadow-Tree fehlgeschlagen" "$DETAIL"
|
||||
@@ -126,6 +130,28 @@ if [[ "$SHADOW_EXIT" -ne 0 ]]; then
|
||||
fi
|
||||
|
||||
trap - ERR
|
||||
PREVIEW_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-preview/connection-$CONNECTION_ID"
|
||||
PREVIEW_OUTPUT=""
|
||||
PREVIEW_EXIT=0
|
||||
if PREVIEW_OUTPUT="$(php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
||||
--mapping="$WEBDAV_MAPPING_FILE" \
|
||||
--base-url="$WEBDAV_BASE_URL" \
|
||||
--user="$WEBDAV_USER" \
|
||||
--password-file="$WEBDAV_PASSWORD_FILE" \
|
||||
--cache-dir="$PREVIEW_CACHE" 2>&1)"; then
|
||||
PREVIEW_EXIT=0
|
||||
else
|
||||
PREVIEW_EXIT=$?
|
||||
fi
|
||||
[[ -z "$PREVIEW_OUTPUT" ]] || printf '%s\n' "$PREVIEW_OUTPUT"
|
||||
if [[ "$PREVIEW_EXIT" -ne 0 ]]; then
|
||||
DETAIL="Exit-Code: $PREVIEW_EXIT"
|
||||
if [[ -n "$PREVIEW_OUTPUT" ]]; then
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$PREVIEW_OUTPUT" | compact_output)"
|
||||
fi
|
||||
write_status error "WebDAV-Vorschaubilder konnten beim Einlesen nicht erzeugt werden" "$DETAIL"
|
||||
exit "$PREVIEW_EXIT"
|
||||
fi
|
||||
|
||||
if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
||||
PIWIGO_OUTPUT=""
|
||||
@@ -143,7 +169,7 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
||||
if [[ "$PIWIGO_EXIT" -ne 0 ]]; then
|
||||
DETAIL="Exit-Code: $PIWIGO_EXIT"
|
||||
if [[ -n "$PIWIGO_OUTPUT" ]]; then
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$PIWIGO_OUTPUT" | tail -n 12 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//')"
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$PIWIGO_OUTPUT" | compact_output)"
|
||||
fi
|
||||
|
||||
if grep -qi 'Invalid username/password' <<<"$PIWIGO_OUTPUT"; then
|
||||
@@ -170,9 +196,28 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
||||
exit "$PIWIGO_EXIT"
|
||||
fi
|
||||
|
||||
DERIVATIVE_OUTPUT=""
|
||||
DERIVATIVE_EXIT=0
|
||||
if DERIVATIVE_OUTPUT="$(php "$SCRIPT_DIR/lib/build-webdav-derivatives.php" \
|
||||
--piwigo-root="$PIWIGO_ROOT" \
|
||||
--connection-id="$CONNECTION_ID" 2>&1)"; then
|
||||
DERIVATIVE_EXIT=0
|
||||
else
|
||||
DERIVATIVE_EXIT=$?
|
||||
fi
|
||||
[[ -z "$DERIVATIVE_OUTPUT" ]] || printf '%s\n' "$DERIVATIVE_OUTPUT"
|
||||
if [[ "$DERIVATIVE_EXIT" -ne 0 ]]; then
|
||||
DETAIL="Exit-Code: $DERIVATIVE_EXIT"
|
||||
if [[ -n "$DERIVATIVE_OUTPUT" ]]; then
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$DERIVATIVE_OUTPUT" | compact_output)"
|
||||
fi
|
||||
write_status error "Piwigo-Derivate für WebDAV-Bilder konnten nicht erzeugt werden" "$DETAIL"
|
||||
exit "$DERIVATIVE_EXIT"
|
||||
fi
|
||||
|
||||
if grep -q 'Piwigo-Synchronisierung per API erfolgreich' <<<"$PIWIGO_OUTPUT"; then
|
||||
write_status ok \
|
||||
"WebDAV eingelesen und Piwigo synchronisiert" \
|
||||
"WebDAV eingelesen, Piwigo synchronisiert und Derivate erzeugt" \
|
||||
"" \
|
||||
"api" \
|
||||
"ok" \
|
||||
@@ -181,7 +226,7 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
||||
"Fallback wurde nicht benötigt"
|
||||
elif grep -q 'Piwigo-Datenbanksynchronisierung per Benutzername/Passwort-Fallback erfolgreich' <<<"$PIWIGO_OUTPUT"; then
|
||||
write_status ok \
|
||||
"WebDAV eingelesen und Piwigo über Fallback synchronisiert" \
|
||||
"WebDAV eingelesen, Piwigo über Fallback synchronisiert und Derivate erzeugt" \
|
||||
"" \
|
||||
"fallback" \
|
||||
"not_used" \
|
||||
@@ -189,8 +234,8 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
||||
"ok" \
|
||||
"Benutzername/Passwort-Fallback erfolgreich"
|
||||
else
|
||||
write_status ok "WebDAV eingelesen und Piwigo synchronisiert"
|
||||
write_status ok "WebDAV eingelesen, Piwigo synchronisiert und Derivate erzeugt"
|
||||
fi
|
||||
else
|
||||
write_status ok "WebDAV eingelesen; Piwigo-Synchronisierung ist für diese Verbindung deaktiviert"
|
||||
write_status ok "WebDAV eingelesen und Vorschaubilder erzeugt; Piwigo-Synchronisierung ist für diese Verbindung deaktiviert"
|
||||
fi
|
||||
|
||||
@@ -52,6 +52,18 @@ if (!pwg_db_num_rows($access_result)) bratonien_tools_webdav_image_abort(403, 'K
|
||||
$source = bratonien_tools_webdav_image_source_info($image_id);
|
||||
if (!$source) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Quelle für dieses Bild gefunden.');
|
||||
|
||||
if (!empty($_GET['ajaxload']))
|
||||
{
|
||||
$preview = !empty($_GET['preview']);
|
||||
$final_url = bratonien_tools_webdav_image_url($image_id, $preview);
|
||||
if (!$final_url) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Bild-URL verfügbar.');
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store, max-age=0');
|
||||
echo json_encode(array('url'=>$final_url), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!empty($_GET['preview']))
|
||||
{
|
||||
$preview = bratonien_tools_webdav_preview_path($source);
|
||||
@@ -121,7 +133,7 @@ $options = array(
|
||||
CURLOPT_USERPWD => $user.':'.$password,
|
||||
CURLOPT_RETURNTRANSFER => false,
|
||||
CURLOPT_FAILONERROR => false,
|
||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.16',
|
||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.24',
|
||||
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
||||
{
|
||||
$length = strlen($line);
|
||||
|
||||
Reference in New Issue
Block a user