mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-11-14 04:58:24 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa039f2cda | ||
|
|
5772a59b55 | ||
|
|
84762154d6 | ||
|
|
1580c235a8 | ||
|
|
4aac5ca4a2 | ||
|
|
ab1f20beef | ||
|
|
f94a001006 | ||
|
|
3f64895f8e | ||
|
|
48f1eacce7 |
No files matched your search
@@ -1,8 +1,7 @@
|
|||||||
name: Syntax Check
|
name: Syntax Check
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_dispatch:
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
php-syntax:
|
php-syntax:
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.7.13
|
Version: 0.9.7.15
|
||||||
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,5 +1,6 @@
|
|||||||
#!/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; }
|
||||||
@@ -22,6 +23,38 @@ 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" \
|
||||||
@@ -33,3 +66,5 @@ 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
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#!/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)."
|
||||||
+30
-5
@@ -20,6 +20,20 @@ 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);
|
||||||
@@ -28,6 +42,11 @@ 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;
|
||||||
@@ -74,17 +93,12 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +129,17 @@ 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));
|
||||||
|
|||||||
+24
-2
@@ -19,6 +19,18 @@ 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);
|
||||||
@@ -52,7 +64,17 @@ 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.');
|
||||||
|
|
||||||
if (!empty($_GET['preview']))
|
$preview_requested = !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)
|
||||||
@@ -121,7 +143,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.1',
|
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.15',
|
||||||
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
||||||
{
|
{
|
||||||
$length = strlen($line);
|
$length = strlen($line);
|
||||||
|
|||||||
Reference in new issue
Block a user