mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-11-16 05:28:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ecbf26bfd |
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.7.15
|
Version: 0.9.7.13
|
||||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||||
Author: Bratonien
|
Author: Bratonien
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
umask 0002
|
|
||||||
|
|
||||||
CONFIG_FILE="${PIWIGO_CONFIG:-}"
|
CONFIG_FILE="${PIWIGO_CONFIG:-}"
|
||||||
[[ -n "$CONFIG_FILE" && -r "$CONFIG_FILE" ]] || { echo "WebDAV-Konfiguration fehlt: ${CONFIG_FILE:-<leer>}" >&2; exit 1; }
|
[[ -n "$CONFIG_FILE" && -r "$CONFIG_FILE" ]] || { echo "WebDAV-Konfiguration fehlt: ${CONFIG_FILE:-<leer>}" >&2; exit 1; }
|
||||||
@@ -23,38 +22,6 @@ exec 9>"$LOCK_FILE"
|
|||||||
flock -n 9 || exit 0
|
flock -n 9 || exit 0
|
||||||
|
|
||||||
PREVIEW_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-preview/connection-$CONNECTION_ID"
|
PREVIEW_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-preview/connection-$CONNECTION_ID"
|
||||||
SOURCE_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-gallery/connection-$CONNECTION_ID"
|
|
||||||
DERIVATIVE_CACHE="$PIWIGO_ROOT/_data/i/_data/bratonien-tools/nc-webdav-gallery/connection-$CONNECTION_ID"
|
|
||||||
PIWIGO_DATA="$PIWIGO_ROOT/_data"
|
|
||||||
|
|
||||||
normalize_connector_cache_permissions() {
|
|
||||||
[[ -d "$PIWIGO_DATA" ]] || return 0
|
|
||||||
|
|
||||||
local data_uid data_gid current_uid path
|
|
||||||
data_uid="$(stat -c '%u' "$PIWIGO_DATA")"
|
|
||||||
data_gid="$(stat -c '%g' "$PIWIGO_DATA")"
|
|
||||||
current_uid="$(id -u)"
|
|
||||||
|
|
||||||
for path in "$SOURCE_CACHE" "$PREVIEW_CACHE" "$DERIVATIVE_CACHE"; do
|
|
||||||
[[ -e "$path" ]] || continue
|
|
||||||
|
|
||||||
if [[ "$current_uid" -eq 0 ]]; then
|
|
||||||
chown -R "$data_uid:$data_gid" -- "$path"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! find "$path" -type d -exec chmod 2775 {} + 2>/dev/null; then
|
|
||||||
echo "Hinweis: Verzeichnisrechte konnten ohne Root-Rechte nicht vollständig repariert werden: $path" >&2
|
|
||||||
fi
|
|
||||||
if ! find "$path" -type f -exec chmod 0664 {} + 2>/dev/null; then
|
|
||||||
echo "Hinweis: Dateirechte konnten ohne Root-Rechte nicht vollständig repariert werden: $path" >&2
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Altbestände aus früheren root/systemd-Läufen werden repariert, sobald dieser
|
|
||||||
# Lauf mit ausreichenden Rechten ausgeführt wird. Bei normalen Webserver-Läufen
|
|
||||||
# werden zumindest alle eigenen Dateien gruppenschreibbar gehalten.
|
|
||||||
normalize_connector_cache_permissions
|
|
||||||
|
|
||||||
php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
||||||
--mapping="$WEBDAV_MAPPING_FILE" \
|
--mapping="$WEBDAV_MAPPING_FILE" \
|
||||||
@@ -66,5 +33,3 @@ php "$SCRIPT_DIR/lib/precache-webdav-previews.php" \
|
|||||||
php "$SCRIPT_DIR/lib/build-webdav-derivatives.php" \
|
php "$SCRIPT_DIR/lib/build-webdav-derivatives.php" \
|
||||||
--piwigo-root="$PIWIGO_ROOT" \
|
--piwigo-root="$PIWIGO_ROOT" \
|
||||||
--connection-id="$CONNECTION_ID"
|
--connection-id="$CONNECTION_ID"
|
||||||
|
|
||||||
normalize_connector_cache_permissions
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -Eeuo pipefail
|
|
||||||
|
|
||||||
PIWIGO_ROOT="${1:-/var/www/piwigo}"
|
|
||||||
PIWIGO_ROOT="${PIWIGO_ROOT%/}"
|
|
||||||
DATA_DIR="$PIWIGO_ROOT/_data"
|
|
||||||
|
|
||||||
[[ -d "$DATA_DIR" ]] || { echo "Piwigo-_data wurde nicht gefunden: $DATA_DIR" >&2; exit 1; }
|
|
||||||
[[ "$(id -u)" -eq 0 ]] || { echo "Die Reparatur muss als root ausgeführt werden." >&2; exit 1; }
|
|
||||||
|
|
||||||
DATA_UID="$(stat -c '%u' "$DATA_DIR")"
|
|
||||||
DATA_GID="$(stat -c '%g' "$DATA_DIR")"
|
|
||||||
|
|
||||||
PATHS=(
|
|
||||||
"$DATA_DIR/bratonien-tools/nc-webdav-gallery"
|
|
||||||
"$DATA_DIR/bratonien-tools/nc-webdav-preview"
|
|
||||||
"$DATA_DIR/i/_data/bratonien-tools/nc-webdav-gallery"
|
|
||||||
"$DATA_DIR/i/bratonien-watermark"
|
|
||||||
)
|
|
||||||
|
|
||||||
found=0
|
|
||||||
for path in "${PATHS[@]}"; do
|
|
||||||
[[ -e "$path" ]] || continue
|
|
||||||
found=1
|
|
||||||
echo "Repariere: $path"
|
|
||||||
chown -R "$DATA_UID:$DATA_GID" -- "$path"
|
|
||||||
find "$path" -type d -exec chmod 2775 {} +
|
|
||||||
find "$path" -type f -exec chmod 0664 {} +
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ "$found" -eq 0 ]]; then
|
|
||||||
echo "Keine Bratonien-Cache-Verzeichnisse gefunden."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Bratonien-Cache-Rechte wurden an $DATA_DIR angeglichen (UID $DATA_UID, GID $DATA_GID)."
|
|
||||||
+5
-30
@@ -20,20 +20,6 @@ function bratonien_tools_webdav_derivative_abort($status, $message)
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_webdav_derivative_ajax_response($url)
|
|
||||||
{
|
|
||||||
http_response_code(200);
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
|
||||||
header('Cache-Control: no-store, max-age=0');
|
|
||||||
echo json_encode(array('url'=>(string)$url), JSON_UNESCAPED_SLASHES);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_webdav_derivative_binary_url($image_id, $type)
|
|
||||||
{
|
|
||||||
return get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/webdav-derivative.php?id='.(int)$image_id.'&type='.rawurlencode((string)$type);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_webdav_derivative_fallback($image_id)
|
function bratonien_tools_webdav_derivative_fallback($image_id)
|
||||||
{
|
{
|
||||||
$url = bratonien_tools_webdav_image_url((int)$image_id, false);
|
$url = bratonien_tools_webdav_image_url((int)$image_id, false);
|
||||||
@@ -42,11 +28,6 @@ function bratonien_tools_webdav_derivative_fallback($image_id)
|
|||||||
bratonien_tools_webdav_derivative_abort(404, 'WebDAV-Bildquelle ist nicht verfuegbar.');
|
bratonien_tools_webdav_derivative_abort(404, 'WebDAV-Bildquelle ist nicht verfuegbar.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_GET['ajaxload']) && (string)$_GET['ajaxload'] === 'true')
|
|
||||||
{
|
|
||||||
bratonien_tools_webdav_derivative_ajax_response($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
header('Cache-Control: no-store');
|
header('Cache-Control: no-store');
|
||||||
header('Location: '.$url, true, 302);
|
header('Location: '.$url, true, 302);
|
||||||
exit;
|
exit;
|
||||||
@@ -93,12 +74,17 @@ if (!$info)
|
|||||||
$preview = bratonien_tools_webdav_preview_path($info);
|
$preview = bratonien_tools_webdav_preview_path($info);
|
||||||
if (!$preview || !is_file($preview) || !is_readable($preview))
|
if (!$preview || !is_file($preview) || !is_readable($preview))
|
||||||
{
|
{
|
||||||
|
// Altbestand kann noch keinen vorbereiteten Preview-Cache besitzen. Der
|
||||||
|
// fokussierte Fotorama-Request darf dann nicht mit 404 enden, weil Fotorama
|
||||||
|
// den fehlgeschlagenen Frame sonst nicht erneut laedt. Stattdessen wird nur
|
||||||
|
// fuer dieses angeforderte Bild auf die echte WebDAV-Quelle ausgewichen.
|
||||||
bratonien_tools_webdav_derivative_fallback($image_id);
|
bratonien_tools_webdav_derivative_fallback($image_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$derivative = new DerivativeImage($params, $src);
|
$derivative = new DerivativeImage($params, $src);
|
||||||
if ($derivative->same_as_source())
|
if ($derivative->same_as_source())
|
||||||
{
|
{
|
||||||
|
// Niemals die lokale Connector-Platzhalterquelle ausliefern.
|
||||||
bratonien_tools_webdav_derivative_fallback($image_id);
|
bratonien_tools_webdav_derivative_fallback($image_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,17 +115,6 @@ if (!bratonien_tools_webdav_derivative_matches_preview($target, $params, $image_
|
|||||||
bratonien_tools_webdav_derivative_fallback($image_id);
|
bratonien_tools_webdav_derivative_fallback($image_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Piwigos thumbnails.loader.js fordert nicht gecachte Derivate mit
|
|
||||||
// ?ajaxload=true an und erwartet JSON {"url":"..."}. Erst diese URL wird
|
|
||||||
// danach als echtes Bild geladen. Binärdaten an dieser Stelle führen direkt
|
|
||||||
// zum Piwigo-Fehlersymbol.
|
|
||||||
if (isset($_GET['ajaxload']) && (string)$_GET['ajaxload'] === 'true')
|
|
||||||
{
|
|
||||||
bratonien_tools_webdav_derivative_ajax_response(
|
|
||||||
bratonien_tools_webdav_derivative_binary_url($image_id, $type)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$size = @filesize($target);
|
$size = @filesize($target);
|
||||||
$mtime = @filemtime($target) ?: time();
|
$mtime = @filemtime($target) ?: time();
|
||||||
$etag = sha1($target.'|'.$mtime.'|'.($size ?: 0));
|
$etag = sha1($target.'|'.$mtime.'|'.($size ?: 0));
|
||||||
|
|||||||
+2
-24
@@ -19,18 +19,6 @@ function bratonien_tools_webdav_image_abort($status, $message)
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_webdav_image_ajax_response($image_id, $preview)
|
|
||||||
{
|
|
||||||
$url = get_root_url().'plugins/'.BRATONIEN_TOOLS_ID.'/webdav-image.php?id='.(int)$image_id;
|
|
||||||
if ($preview) $url .= '&preview=1';
|
|
||||||
|
|
||||||
http_response_code(200);
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
|
||||||
header('Cache-Control: no-store, max-age=0');
|
|
||||||
echo json_encode(array('url'=>$url), JSON_UNESCAPED_SLASHES);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_webdav_image_decrypt_secret($blob, $hex_key)
|
function bratonien_tools_webdav_image_decrypt_secret($blob, $hex_key)
|
||||||
{
|
{
|
||||||
$hex_key = trim((string)$hex_key);
|
$hex_key = trim((string)$hex_key);
|
||||||
@@ -64,17 +52,7 @@ if (!pwg_db_num_rows($access_result)) bratonien_tools_webdav_image_abort(403, 'K
|
|||||||
$source = bratonien_tools_webdav_image_source_info($image_id);
|
$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 (!$source) bratonien_tools_webdav_image_abort(404, 'Keine WebDAV-Quelle für dieses Bild gefunden.');
|
||||||
|
|
||||||
$preview_requested = !empty($_GET['preview']);
|
if (!empty($_GET['preview']))
|
||||||
|
|
||||||
// Piwigos Standard-Lader erwartet bei ?ajaxload=true JSON und lädt erst die
|
|
||||||
// darin enthaltene URL als Bild. Binärdaten in diesem Request werden als
|
|
||||||
// Ladefehler behandelt und durch errors_small.png ersetzt.
|
|
||||||
if (isset($_GET['ajaxload']) && (string)$_GET['ajaxload'] === 'true')
|
|
||||||
{
|
|
||||||
bratonien_tools_webdav_image_ajax_response($image_id, $preview_requested);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($preview_requested)
|
|
||||||
{
|
{
|
||||||
$preview = bratonien_tools_webdav_preview_path($source);
|
$preview = bratonien_tools_webdav_preview_path($source);
|
||||||
if ($preview)
|
if ($preview)
|
||||||
@@ -143,7 +121,7 @@ $options = array(
|
|||||||
CURLOPT_USERPWD => $user.':'.$password,
|
CURLOPT_USERPWD => $user.':'.$password,
|
||||||
CURLOPT_RETURNTRANSFER => false,
|
CURLOPT_RETURNTRANSFER => false,
|
||||||
CURLOPT_FAILONERROR => false,
|
CURLOPT_FAILONERROR => false,
|
||||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.15',
|
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.1',
|
||||||
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
||||||
{
|
{
|
||||||
$length = strlen($line);
|
$length = strlen($line);
|
||||||
|
|||||||
Reference in new issue
Block a user