mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 22:14:33 +00:00
Compare commits
268 Commits
54a9c97525
...
fix/09720-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7dacdae56 | ||
|
|
15b489714b | ||
|
|
f3b52c55ef | ||
|
|
67c1e814c8 | ||
|
|
a5a8856e48 | ||
|
|
2af46d1820 | ||
|
|
e5d754fdab | ||
|
|
0adcc5ca54 | ||
|
|
61988db337 | ||
|
|
bdfea105cf | ||
|
|
6f64cb9fe6 | ||
|
|
65b068814f | ||
|
|
e58d2c700a | ||
|
|
afaea3b424 | ||
|
|
7a763ba62a | ||
|
|
31e29db7c2 | ||
|
|
ab116d29c2 | ||
|
|
46924db618 | ||
|
|
6e96b0adc3 | ||
|
|
b8f3ed44a3 | ||
|
|
cb3b2f258c | ||
|
|
ef1c1265a9 | ||
|
|
47d7000cc8 | ||
|
|
c358c157e4 | ||
|
|
1d62dc17e8 | ||
|
|
ad4c281fdc | ||
|
|
a43a15a9d3 | ||
|
|
31b8590e4a | ||
|
|
c772010137 | ||
|
|
d075d05708 | ||
|
|
a4fb7421f0 | ||
|
|
9da08b5d8e | ||
|
|
f28365b0ca | ||
|
|
fb6c1a03d2 | ||
|
|
98d0471683 | ||
|
|
63eba888f8 | ||
|
|
748b0e986d | ||
|
|
c1281ad077 | ||
|
|
bc0593642c | ||
|
|
9052076fd7 | ||
|
|
5772a59b55 | ||
|
|
84762154d6 | ||
|
|
1580c235a8 | ||
|
|
4aac5ca4a2 | ||
|
|
ab1f20beef | ||
|
|
f94a001006 | ||
|
|
3f64895f8e | ||
|
|
48f1eacce7 | ||
|
|
7c8c7ab98a | ||
|
|
ade38ff2d1 | ||
|
|
6a013fe875 | ||
|
|
c71112d94e | ||
|
|
7d97e1b515 | ||
|
|
47afbc7f43 | ||
|
|
706639a57e | ||
|
|
c7b14add33 | ||
|
|
f9e87df305 | ||
|
|
6ba5eb4d7f | ||
|
|
85369fa15e | ||
|
|
981ba6c18b | ||
|
|
77e20af977 | ||
|
|
e187c517da | ||
|
|
28e34d6c73 | ||
|
|
b8852310bd | ||
|
|
ae96fc2e3e | ||
|
|
ebf4fc7e74 | ||
|
|
d798b82ec7 | ||
|
|
9e282af1b4 | ||
|
|
d7628d1dac | ||
|
|
7e9c3ae05f | ||
|
|
b64e46a549 | ||
|
|
779ba80dfe | ||
|
|
ebbc183f87 | ||
|
|
f3b5002f4d | ||
|
|
6c393bbcfc | ||
|
|
829381676d | ||
|
|
6382cee491 | ||
|
|
69c3932e9b | ||
|
|
747a76c066 | ||
|
|
5024757136 | ||
|
|
5125d2e247 | ||
|
|
6607c4aefe | ||
|
|
32f2ceaaec | ||
|
|
5a5669d976 | ||
|
|
e4ab277cfc | ||
|
|
9e07cd8042 | ||
|
|
588f1fc100 | ||
|
|
a23fc81190 | ||
|
|
ff5af83e65 | ||
|
|
c61d8e32cc | ||
|
|
38c4955f70 | ||
|
|
5c217288a8 | ||
|
|
17c79ce8ab | ||
|
|
7746d26c9f | ||
|
|
d05ab28549 | ||
|
|
55b5be56b6 | ||
|
|
ba0b5af417 | ||
|
|
315af9641c | ||
|
|
77ae007a28 | ||
|
|
e5be2b3043 | ||
|
|
3fe9527537 | ||
|
|
fb1f12d608 | ||
|
|
017cbdbd3b | ||
|
|
9aaa1a47b3 | ||
|
|
fc3d855e5e | ||
|
|
4847d2ff11 | ||
|
|
0b405e9efb | ||
|
|
2c302b356d | ||
|
|
5c62dbd9be | ||
|
|
5f81cc9ce9 | ||
|
|
a5be16f88e | ||
|
|
6b082ba8b5 | ||
|
|
5396f50bc0 | ||
|
|
a54df74e67 | ||
|
|
986eb530d7 | ||
|
|
b9adcbddac | ||
|
|
bb434b9b02 | ||
|
|
aa5c2f7f0c | ||
|
|
aa803a4149 | ||
|
|
ad39b9f0d2 | ||
|
|
aa8beb3794 | ||
|
|
3ad6e9eb8e | ||
|
|
21118f6fb3 | ||
|
|
c23302197a | ||
|
|
d54aa482f7 | ||
|
|
25133bc895 | ||
|
|
62cc1af8bf | ||
|
|
cf300bc5c3 | ||
|
|
0dde87cda0 | ||
|
|
17a76c4de2 | ||
|
|
2366f6366c | ||
|
|
43780cb9a3 | ||
|
|
7b915c310a | ||
|
|
6df469ab7a | ||
|
|
55294643b4 | ||
|
|
0f3c78f02c | ||
|
|
d80163a704 | ||
|
|
9e57c4ea3d | ||
|
|
30f1c0af18 | ||
|
|
00d14db57d | ||
|
|
6e52ba824c | ||
|
|
a1bac43150 | ||
|
|
06646ea37f | ||
|
|
8f2b22a376 | ||
|
|
2122ab88ac | ||
|
|
babe95fae3 | ||
|
|
14a83be190 | ||
|
|
a1d2163aab | ||
|
|
a0606b2553 | ||
|
|
9543af50d8 | ||
|
|
4af1972353 | ||
|
|
0e7070fb04 | ||
|
|
ba53bfebe9 | ||
|
|
4b2fc93e3d | ||
|
|
e356d43e5b | ||
|
|
980efc6700 | ||
|
|
a814c18d18 | ||
|
|
6737c8989d | ||
|
|
2e308867ad | ||
|
|
1d3768b051 | ||
|
|
cfea5546de | ||
|
|
8c30edc0ee | ||
|
|
76a182af82 | ||
|
|
21e046cf37 | ||
|
|
7728e368db | ||
|
|
074aa8d99a | ||
|
|
030634c39d | ||
|
|
dea1a0ffb2 | ||
|
|
3a3539e55b | ||
|
|
49e74a019b | ||
|
|
f2f7d39b22 | ||
|
|
2c5bcf6ba2 | ||
|
|
2d29cfacfe | ||
|
|
c5e1b33c2f | ||
|
|
675ccd1df8 | ||
|
|
aefbe76595 | ||
|
|
65cbc0060f | ||
|
|
5dce180217 | ||
|
|
25ee22b1ef | ||
|
|
992ddd3b9b | ||
|
|
0f85958dff | ||
|
|
82af31435e | ||
|
|
462197fc78 | ||
|
|
cb445c3f04 | ||
|
|
e1306c110c | ||
|
|
bbae8ac984 | ||
|
|
5a7f72b24e | ||
|
|
09027322ef | ||
|
|
a38152108c | ||
|
|
036f2a51e6 | ||
|
|
8cabeb3079 | ||
|
|
0767c4fd8f | ||
|
|
de649235ff | ||
|
|
3896933081 | ||
|
|
72a3267ed3 | ||
|
|
99479d5d03 | ||
|
|
51089c3446 | ||
|
|
c8d846f289 | ||
|
|
2603a8929c | ||
|
|
afd8620859 | ||
|
|
72db8b48eb | ||
|
|
1a0f8c61e8 | ||
|
|
d4e3e7faab | ||
|
|
03e92b74a7 | ||
|
|
88c787c956 | ||
|
|
3f5f8dc4b4 | ||
|
|
495edbbb70 | ||
|
|
3d5e6c82ea | ||
|
|
ae815bc077 | ||
|
|
936a1cf3c4 | ||
|
|
ff0c1e0bec | ||
|
|
a047fc0d83 | ||
|
|
2029059720 | ||
|
|
1eca236509 | ||
|
|
e464668343 | ||
|
|
47813b0b0e | ||
|
|
26af1b3019 | ||
|
|
b1b75676a8 | ||
|
|
12880b6c41 | ||
|
|
32abc7250d | ||
|
|
76de2b037c | ||
|
|
e2e82162c6 | ||
|
|
7a9eb1baa6 | ||
|
|
e800f11f64 | ||
|
|
4808f08590 | ||
|
|
6fd89df5d0 | ||
|
|
99126088e7 | ||
|
|
e53a3848bb | ||
|
|
0f0c71acaf | ||
|
|
9847690f50 | ||
|
|
a2f5dc3919 | ||
|
|
cd3bf7c8ee | ||
|
|
79ea403555 | ||
|
|
33783dd30f | ||
|
|
ca6a5cf96f | ||
|
|
62ada617fb | ||
|
|
898f9b1bc9 | ||
|
|
5b48e1f6f2 | ||
|
|
fdf4584028 | ||
|
|
880744a8b7 | ||
|
|
2ed84ad089 | ||
|
|
60c0a51f01 | ||
|
|
84d263b16b | ||
|
|
94c81789ed | ||
|
|
e3b1f06be3 | ||
|
|
15a3ceb01c | ||
|
|
0f5812a179 | ||
|
|
377b29a127 | ||
|
|
d9696172c5 | ||
|
|
3f2a85fb0b | ||
|
|
c882ba994b | ||
|
|
cd2c9e350b | ||
|
|
394f375e91 | ||
|
|
3b1ccd99a5 | ||
|
|
04d88cd40f | ||
|
|
a4f953551c | ||
|
|
b4161471ca | ||
|
|
71fdadb7f8 | ||
|
|
98134b5ab8 | ||
|
|
5f82f2ad71 | ||
|
|
494f8bf192 | ||
|
|
c46f9bb5bd | ||
|
|
992cb55714 | ||
|
|
46782ea9a3 | ||
|
|
d03410c9ef | ||
|
|
aa2a6e4c02 | ||
|
|
ebdd77fb0a | ||
|
|
6c36aaeb8a |
1
.ci-trigger-0977
Normal file
1
.ci-trigger-0977
Normal file
@@ -0,0 +1 @@
|
||||
0.9.7.7
|
||||
33
.github/workflows/lint.yml
vendored
33
.github/workflows/lint.yml
vendored
@@ -5,8 +5,12 @@ on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
syntax:
|
||||
php-syntax:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php-version: ['8.2', '8.3', '8.4', '8.5']
|
||||
steps:
|
||||
- name: Repository auschecken
|
||||
uses: actions/checkout@v4
|
||||
@@ -14,7 +18,7 @@ jobs:
|
||||
- name: PHP installieren
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.2'
|
||||
php-version: ${{ matrix.php-version }}
|
||||
coverage: none
|
||||
|
||||
- name: PHP Syntax pruefen
|
||||
@@ -25,6 +29,31 @@ jobs:
|
||||
php -l "$file"
|
||||
done < <(find . -type f -name '*.php' -print0)
|
||||
|
||||
- name: Doppelte Bratonien-Funktionen pruefen
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
duplicates="$(grep -RhoE 'function[[:space:]]+bratonien_tools_[A-Za-z0-9_]+' --include='*.php' . | awk '{print $2}' | sort | uniq -d || true)"
|
||||
if [[ -n "$duplicates" ]]; then
|
||||
echo "Doppelte globale Bratonien-Funktionen gefunden:" >&2
|
||||
printf '%s\n' "$duplicates" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
script-syntax:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Repository auschecken
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Admin JavaScript Syntax pruefen
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
sed -n '/<script>/,/<\/script>/p' template/admin_tabs.tpl | sed '1d;$d' > /tmp/bratonien-admin-tabs.js
|
||||
node --check /tmp/bratonien-admin-tabs.js
|
||||
node --check js/nc_connector_edit_v2.js
|
||||
|
||||
- name: Python Syntax pruefen
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
95
admin.php
95
admin.php
@@ -9,6 +9,74 @@ check_status(ACCESS_ADMINISTRATOR);
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/tool_registry.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_system.inc.php');
|
||||
|
||||
function bratonien_tools_nc_connector_admin_connections(array $connections)
|
||||
{
|
||||
$by_id = array();
|
||||
foreach ($connections as $connection)
|
||||
{
|
||||
$by_id[(int)$connection['id']] = $connection;
|
||||
}
|
||||
|
||||
$hidden_legacy_ids = array();
|
||||
$logical_remote = array();
|
||||
foreach ($connections as $connection)
|
||||
{
|
||||
if ((string)($connection['adapter'] ?? '') !== 'remote') continue;
|
||||
$migration = isset($connection['config']['migration']) && is_array($connection['config']['migration'])
|
||||
? $connection['config']['migration']
|
||||
: array();
|
||||
if ((string)($migration['role'] ?? '') !== 'webdav-primary-candidate') continue;
|
||||
|
||||
$legacy_id = (int)($migration['legacy_fallback_connection_id'] ?? 0);
|
||||
if ($legacy_id < 1 || empty($by_id[$legacy_id]) || (string)$by_id[$legacy_id]['adapter'] !== 'local') continue;
|
||||
|
||||
$legacy = $by_id[$legacy_id];
|
||||
$hidden_legacy_ids[$legacy_id] = true;
|
||||
$connection['logical_connection'] = true;
|
||||
$connection['legacy_fallback_connection_id'] = $legacy_id;
|
||||
$connection['enabled'] = !empty($connection['enabled']) || !empty($legacy['enabled']);
|
||||
if ($connection['enabled']) $connection['takeover_state'] = 'active';
|
||||
$connection['fallback_stored'] = !empty($connection['fallback_stored']) || !empty($legacy['fallback_stored']);
|
||||
if (trim((string)$connection['name']) === '') $connection['name'] = (string)$legacy['name'];
|
||||
$logical_remote[(int)$connection['id']] = $connection;
|
||||
}
|
||||
|
||||
$visible = array();
|
||||
foreach ($connections as $connection)
|
||||
{
|
||||
$id = (int)$connection['id'];
|
||||
if (isset($hidden_legacy_ids[$id])) continue;
|
||||
if (isset($logical_remote[$id])) $connection = $logical_remote[$id];
|
||||
$visible[] = $connection;
|
||||
}
|
||||
|
||||
return $visible;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_admin_last_status(array $connection)
|
||||
{
|
||||
$latest = bratonien_tools_nc_connector_connection_last_status($connection);
|
||||
$legacy_id = (int)($connection['legacy_fallback_connection_id'] ?? 0);
|
||||
if ($legacy_id < 1)
|
||||
{
|
||||
return $latest;
|
||||
}
|
||||
|
||||
$legacy = bratonien_tools_nc_connector_connection($legacy_id, false);
|
||||
if (!$legacy)
|
||||
{
|
||||
return $latest;
|
||||
}
|
||||
|
||||
$legacy_status = bratonien_tools_nc_connector_connection_last_status($legacy);
|
||||
if ((int)($legacy_status['timestamp'] ?? 0) > (int)($latest['timestamp'] ?? 0))
|
||||
{
|
||||
return $legacy_status;
|
||||
}
|
||||
|
||||
return $latest;
|
||||
}
|
||||
|
||||
$tools = bratonien_tools_get_tools();
|
||||
$messages = array();
|
||||
$errors = array();
|
||||
@@ -94,6 +162,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['bratonien_tool']))
|
||||
);
|
||||
|
||||
$redirect_url = get_root_url().'admin.php?page=plugin-'.BRATONIEN_TOOLS_ID;
|
||||
$wizard_action = strpos($tool_id, 'nc_connector_wizard_') === 0
|
||||
|| $tool_id === 'nc_connector_migrate_start'
|
||||
|| $tool_id === 'nc_connector_edit_start';
|
||||
if ($wizard_action)
|
||||
{
|
||||
$wizard_closed = $tool_id === 'nc_connector_wizard_reset'
|
||||
|| ($tool_id === 'nc_connector_wizard_finish' && empty($errors));
|
||||
if (($tool_id === 'nc_connector_migrate_start' || $tool_id === 'nc_connector_edit_start') && !empty($errors))
|
||||
{
|
||||
$wizard_closed = true;
|
||||
}
|
||||
$redirect_url .= '&nc_wizard='.($wizard_closed ? 'closed' : 'open');
|
||||
}
|
||||
if (!headers_sent())
|
||||
{
|
||||
header('Location: '.$redirect_url, true, 303);
|
||||
@@ -115,9 +196,17 @@ $asset_environment = bratonien_tools_get_asset_environment();
|
||||
$album_shares = bratonien_tools_get_album_shares();
|
||||
$private_albums = bratonien_tools_get_private_albums();
|
||||
$nc_connector = bratonien_tools_nc_connector_status();
|
||||
$nc_connector_runtime_connections = $nc_connector['connections'];
|
||||
$nc_connector['connections'] = bratonien_tools_nc_connector_admin_connections($nc_connector_runtime_connections);
|
||||
$nc_connector['connection_count'] = count($nc_connector['connections']);
|
||||
$nc_connector['active_count'] = 0;
|
||||
foreach ($nc_connector['connections'] as $visible_connection)
|
||||
{
|
||||
if (!empty($visible_connection['enabled'])) $nc_connector['active_count']++;
|
||||
}
|
||||
foreach ($nc_connector['connections'] as &$nc_connection)
|
||||
{
|
||||
$nc_connection['last_sync'] = bratonien_tools_nc_connector_connection_last_status($nc_connection);
|
||||
$nc_connection['last_sync'] = bratonien_tools_nc_connector_admin_last_status($nc_connection);
|
||||
$nc_connection['display_name'] = $nc_connection['name'];
|
||||
|
||||
$storage_lines = array();
|
||||
@@ -166,7 +255,7 @@ $nc_system_defaults = array(
|
||||
);
|
||||
$nc_connector['system'] = array_merge(
|
||||
$nc_system_defaults,
|
||||
bratonien_tools_nc_connector_system_status($nc_connector['connections'])
|
||||
bratonien_tools_nc_connector_system_status($nc_connector_runtime_connections)
|
||||
);
|
||||
$album_lock_page_number = isset($_GET['br_album_page']) ? max(1, (int)$_GET['br_album_page']) : 1;
|
||||
$album_lock_search = isset($_GET['br_album_search']) ? trim((string)$_GET['br_album_search']) : '';
|
||||
@@ -292,4 +381,4 @@ $admin_content .= $template->parse('asset_manager_admin_content', true);
|
||||
$admin_content .= $template->parse('album_shares_admin_content', true);
|
||||
$admin_content .= $template->parse('nc_connector_admin_content', true);
|
||||
$admin_content .= $template->parse('system_admin_content', true);
|
||||
$template->assign('ADMIN_CONTENT', $admin_content);
|
||||
$template->assign('ADMIN_CONTENT', $admin_content);
|
||||
@@ -5,6 +5,11 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_create_local_api_first()
|
||||
{
|
||||
throw new RuntimeException('Neue Verbindungen über die alte lokale PostgreSQL-/Storage-Struktur sind ab 0.9.6.2 gesperrt. Bestehende lokale Verbindungen bleiben für die schrittweise Migration weiterhin aktiv. Neue Verbindungen müssen über den WebDAV-Assistenten angelegt werden.');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_create_local_api_first_legacy()
|
||||
{
|
||||
$required = array(
|
||||
'nc_name' => 'Name',
|
||||
|
||||
@@ -4,49 +4,84 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_webdav_site_id(array $connection)
|
||||
function bratonien_tools_nc_connector_db_prefix_from_absolute($path)
|
||||
{
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
if ((string)($connection['adapter'] ?? '') !== 'remote') return 0;
|
||||
if ((string)($config['source_mode'] ?? '') !== 'webdav-placeholder') return 0;
|
||||
$path = rtrim(str_replace('\\', '/', (string)$path), '/');
|
||||
$piwigo_root = rtrim(str_replace('\\', '/', PHPWG_ROOT_PATH), '/');
|
||||
if ($path === '' || strpos($path, $piwigo_root.'/') !== 0) return '';
|
||||
|
||||
$gallery_root = rtrim((string)($config['parallel_gallery_root'] ?? ''), '/');
|
||||
$piwigo_root = rtrim(PHPWG_ROOT_PATH, '/');
|
||||
if ($gallery_root === '' || strpos($gallery_root, $piwigo_root.'/') !== 0) return 0;
|
||||
$relative = ltrim(substr($path, strlen($piwigo_root)), '/');
|
||||
return $relative === '' ? '' : './'.rtrim($relative, '/').'/';
|
||||
}
|
||||
|
||||
$relative = ltrim(substr($gallery_root, strlen($piwigo_root)), '/');
|
||||
if ($relative === '') return 0;
|
||||
$site_url = './'.rtrim($relative, '/').'/';
|
||||
function bratonien_tools_nc_connector_owned_db_prefixes(array $connection)
|
||||
{
|
||||
$id = (int)($connection['id'] ?? 0);
|
||||
if ($id < 1) return array();
|
||||
|
||||
$result = pwg_query(
|
||||
"SELECT id FROM ".SITES_TABLE.
|
||||
" WHERE galleries_url='".pwg_db_real_escape_string($site_url)."' LIMIT 1"
|
||||
$prefixes = array(
|
||||
'./_data/bratonien-tools/nc-webdav-gallery/connection-'.$id.'/',
|
||||
'./_data/bratonien-tools/nc-webdav-source/connection-'.$id.'/',
|
||||
'./galleries/bratonien-webdav-'.$id.'/',
|
||||
);
|
||||
if (!pwg_db_num_rows($result)) return 0;
|
||||
|
||||
$row = pwg_db_fetch_assoc($result);
|
||||
return (int)$row['id'];
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$configured = bratonien_tools_nc_connector_db_prefix_from_absolute($config['parallel_gallery_root'] ?? '');
|
||||
if ($configured !== '') $prefixes[] = $configured;
|
||||
|
||||
return array_values(array_unique($prefixes));
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_owned_site_urls(array $connection)
|
||||
{
|
||||
$id = (int)($connection['id'] ?? 0);
|
||||
if ($id < 1) return array();
|
||||
|
||||
$urls = array(
|
||||
'./_data/bratonien-tools/nc-webdav-gallery/connection-'.$id.'/',
|
||||
'./galleries/bratonien-webdav-'.$id.'/',
|
||||
);
|
||||
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$configured = bratonien_tools_nc_connector_db_prefix_from_absolute($config['parallel_gallery_root'] ?? '');
|
||||
if ($configured !== '') $urls[] = $configured;
|
||||
|
||||
return array_values(array_unique($urls));
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connection)
|
||||
{
|
||||
$site_id = bratonien_tools_nc_connector_webdav_site_id($connection);
|
||||
if ($site_id < 1) return array('site_id'=>0, 'images'=>0);
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
$prefixes = bratonien_tools_nc_connector_owned_db_prefixes($connection);
|
||||
if (!$prefixes) return array('sites'=>0, 'images'=>0);
|
||||
|
||||
$where = array();
|
||||
foreach ($prefixes as $prefix)
|
||||
{
|
||||
$escaped = pwg_db_real_escape_string(addcslashes($prefix, '_%\\'));
|
||||
$where[] = "path LIKE '".$escaped."%' ESCAPE '\\\\'";
|
||||
}
|
||||
|
||||
$image_rows = array();
|
||||
$query = '
|
||||
SELECT DISTINCT i.id, i.path, i.representative_ext
|
||||
FROM '.IMAGES_TABLE.' AS i
|
||||
LEFT JOIN '.CATEGORIES_TABLE.' AS sc ON sc.id = i.storage_category_id
|
||||
LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
|
||||
LEFT JOIN '.CATEGORIES_TABLE.' AS vc ON vc.id = ic.category_id
|
||||
WHERE sc.site_id = '.$site_id.' OR vc.site_id = '.$site_id.'
|
||||
;';
|
||||
$result = pwg_query($query);
|
||||
$result = pwg_query(
|
||||
'SELECT id, path, representative_ext FROM '.IMAGES_TABLE.
|
||||
' WHERE '.implode(' OR ', $where)
|
||||
);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$path = (string)$row['path'];
|
||||
$owned = false;
|
||||
foreach ($prefixes as $prefix)
|
||||
{
|
||||
if (strpos($path, $prefix) === 0)
|
||||
{
|
||||
$owned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$owned) continue;
|
||||
|
||||
$row['id'] = (int)$row['id'];
|
||||
$image_rows[$row['id']] = $row;
|
||||
}
|
||||
@@ -63,31 +98,33 @@ SELECT DISTINCT i.id, i.path, i.representative_ext
|
||||
}
|
||||
}
|
||||
|
||||
delete_site($site_id);
|
||||
|
||||
if ($image_rows)
|
||||
{
|
||||
$ids = array_keys($image_rows);
|
||||
$remaining = query2array(
|
||||
'SELECT id FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', array_map('intval', $ids)).')',
|
||||
null,
|
||||
'id'
|
||||
delete_elements(array_map('intval', array_keys($image_rows)), false);
|
||||
}
|
||||
|
||||
$site_count = 0;
|
||||
foreach (bratonien_tools_nc_connector_owned_site_urls($connection) as $site_url)
|
||||
{
|
||||
$result = pwg_query(
|
||||
"SELECT id FROM ".SITES_TABLE.
|
||||
" WHERE galleries_url='".pwg_db_real_escape_string($site_url)."'"
|
||||
);
|
||||
if ($remaining)
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
delete_elements(array_map('intval', $remaining), false);
|
||||
delete_site((int)$row['id']);
|
||||
$site_count++;
|
||||
}
|
||||
}
|
||||
|
||||
update_category('all');
|
||||
invalidate_user_cache(true);
|
||||
return array('site_id'=>$site_id, 'images'=>count($image_rows));
|
||||
return array('sites'=>$site_count, 'images'=>count($image_rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a connector connection from Piwigo without depending on the web
|
||||
* server being allowed to write into root-owned runtime directories.
|
||||
* WebDAV-managed Piwigo records are removed before the connection itself so
|
||||
* deleted remote content cannot remain visible or addressable in Piwigo.
|
||||
* Delete exactly the connection selected by the user.
|
||||
* No other connector record is implicitly removed.
|
||||
*/
|
||||
function bratonien_tools_nc_connector_delete_safe()
|
||||
{
|
||||
@@ -98,7 +135,7 @@ function bratonien_tools_nc_connector_delete_safe()
|
||||
throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||
}
|
||||
|
||||
$cleanup = array('site_id'=>0, 'images'=>0);
|
||||
$cleanup = array('sites'=>0, 'images'=>0);
|
||||
if (
|
||||
(string)($connection['adapter'] ?? '') === 'remote'
|
||||
&& (string)($connection['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
||||
@@ -112,24 +149,14 @@ function bratonien_tools_nc_connector_delete_safe()
|
||||
|
||||
$status_dir = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-connector-status';
|
||||
$public_status = $status_dir.'/connection-'.$id.'.json';
|
||||
if (is_file($public_status))
|
||||
{
|
||||
@unlink($public_status);
|
||||
}
|
||||
if (is_file($public_status)) @unlink($public_status);
|
||||
|
||||
if (is_dir($status_dir) || @mkdir($status_dir, 0755, true))
|
||||
{
|
||||
@file_put_contents($status_dir.'/deleted-'.$id, date('c')."\n", LOCK_EX);
|
||||
}
|
||||
|
||||
if ((int)$cleanup['site_id'] > 0)
|
||||
{
|
||||
return array(
|
||||
'message'=>'Connector-Verbindung wurde gelöscht. Die zugehörigen Piwigo-Alben und '.(int)$cleanup['images'].' Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert. Laufzeit- und Vorschaudaten werden automatisch bereinigt.',
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'message'=>'Connector-Verbindung wurde gelöscht. Verbliebene Laufzeitdateien werden vor dem nächsten Connector-Lauf automatisch entfernt. Quelldateien blieben unverändert.',
|
||||
'message'=>'Verbindung wurde gelöscht. '.(int)$cleanup['images'].' eindeutig zu dieser Verbindung gehörende Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert.',
|
||||
);
|
||||
}
|
||||
|
||||
348
include/nc_connector_edit.inc.php
Normal file
348
include/nc_connector_edit.inc.php
Normal file
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
if (!defined('PHPWG_ROOT_PATH'))
|
||||
{
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_migration_state(array $connection)
|
||||
{
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||
$missing = array();
|
||||
|
||||
if (trim((string)($config['nextcloud_url'] ?? '')) === '') $missing[] = 'Nextcloud-Adresse';
|
||||
if (trim((string)($credentials['nextcloud_user'] ?? '')) === '') $missing[] = 'Nextcloud-Benutzer';
|
||||
if ((string)($credentials['nextcloud_password'] ?? '') === '') $missing[] = 'Nextcloud-Passwort';
|
||||
|
||||
$api_id = trim((string)($credentials['api_key_id'] ?? ''));
|
||||
$api_secret = trim((string)($credentials['api_key_secret'] ?? ''));
|
||||
$fallback_user = trim((string)($credentials['piwigo_user'] ?? ''));
|
||||
$fallback_password = (string)($credentials['piwigo_password'] ?? '');
|
||||
$api_complete = $api_id !== '' && $api_secret !== '';
|
||||
$fallback_complete = $fallback_user !== '' && $fallback_password !== '';
|
||||
|
||||
if (($api_id === '') !== ($api_secret === '')) $missing[] = 'vollstaendiger Piwigo-API-Zugang';
|
||||
if (!$api_complete && !$fallback_complete) $missing[] = 'Piwigo-API oder Benutzer/Passwort-Fallback';
|
||||
|
||||
return array(
|
||||
'ready'=>!$missing,
|
||||
'missing'=>$missing,
|
||||
'api_available'=>$api_complete,
|
||||
'fallback_available'=>$fallback_complete,
|
||||
);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_validate_nextcloud_access($base_url, $username, $password)
|
||||
{
|
||||
$base_url = bratonien_tools_nc_wizard_normalize_url($base_url);
|
||||
$username = trim((string)$username);
|
||||
$password = (string)$password;
|
||||
if ($username === '' || $password === '') throw new RuntimeException('Nextcloud-Benutzer und Passwort werden benoetigt.');
|
||||
|
||||
$status_response = bratonien_tools_nc_wizard_http($base_url.'/status.php');
|
||||
if ($status_response['status'] < 200 || $status_response['status'] >= 300)
|
||||
{
|
||||
throw new RuntimeException('Die Nextcloud-Adresse konnte nicht bestaetigt werden.');
|
||||
}
|
||||
$status = json_decode((string)$status_response['body'], true);
|
||||
if (!is_array($status) || empty($status['installed']))
|
||||
{
|
||||
throw new RuntimeException('Unter dieser Adresse wurde keine installierte Nextcloud erkannt.');
|
||||
}
|
||||
|
||||
$user_response = bratonien_tools_nc_wizard_http(
|
||||
$base_url.'/ocs/v2.php/cloud/user?format=json',
|
||||
$username,
|
||||
$password,
|
||||
array('OCS-APIRequest: true')
|
||||
);
|
||||
if ($user_response['status'] === 401 || $user_response['status'] === 403)
|
||||
{
|
||||
throw new RuntimeException('Nextcloud hat Benutzername oder Passwort abgelehnt.');
|
||||
}
|
||||
if ($user_response['status'] < 200 || $user_response['status'] >= 300)
|
||||
{
|
||||
throw new RuntimeException('Nextcloud ist erreichbar, aber der Benutzerzugang konnte nicht geprueft werden.');
|
||||
}
|
||||
$user_data = bratonien_tools_nc_wizard_ocs_data($user_response['body']);
|
||||
$resolved = trim((string)($user_data['id'] ?? $username));
|
||||
|
||||
return array(
|
||||
'base_url'=>$base_url,
|
||||
'username'=>$resolved !== '' ? $resolved : $username,
|
||||
);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_validate_scoped_api($api_key_id, $api_key_secret)
|
||||
{
|
||||
$api_key_id = trim((string)$api_key_id);
|
||||
$api_key_secret = trim((string)$api_key_secret);
|
||||
if ($api_key_id === '' || $api_key_secret === '')
|
||||
{
|
||||
throw new RuntimeException('Piwigo-API-Schluessel-ID und API-Geheimnis werden benoetigt.');
|
||||
}
|
||||
|
||||
$status = bratonien_tools_nc_connector_piwigo_api_request($api_key_id, $api_key_secret, 'pwg.session.getStatus');
|
||||
if (!is_array($status)) throw new RuntimeException('Piwigo hat keinen auswertbaren API-Benutzerstatus geliefert.');
|
||||
$role = strtolower(trim((string)($status['status'] ?? '')));
|
||||
if (!in_array($role, array('admin','webmaster'), true))
|
||||
{
|
||||
throw new RuntimeException('Der API-Key funktioniert, gehoert aber keinem Piwigo-Administrator/Webmaster.');
|
||||
}
|
||||
|
||||
$method_result = bratonien_tools_nc_connector_piwigo_api_request($api_key_id, $api_key_secret, 'reflection.getMethodList');
|
||||
$method_map = array();
|
||||
bratonien_tools_nc_connector_collect_method_names($method_result, $method_map);
|
||||
$required = array('bratonien.nc.syncProductive', 'bratonien.nc.syncOrphans');
|
||||
$missing = array_values(array_diff($required, array_keys($method_map)));
|
||||
if ($missing)
|
||||
{
|
||||
throw new RuntimeException('Der API-Key ist gueltig, aber benoetigte Bratonien-Sync-Methoden fehlen: '.implode(', ', $missing).'.');
|
||||
}
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection(array $connection, $mode)
|
||||
{
|
||||
$id = (int)$connection['id'];
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||
|
||||
$base_url = trim((string)($config['nextcloud_url'] ?? ''));
|
||||
$username = trim((string)($credentials['nextcloud_user'] ?? ''));
|
||||
if ($username === '')
|
||||
{
|
||||
$username = trim((string)($config['nextcloud_access_user'] ?? $config['access_user'] ?? ''));
|
||||
}
|
||||
$password = (string)($credentials['nextcloud_password'] ?? '');
|
||||
|
||||
$roots = isset($config['roots']) && is_array($config['roots']) ? array_values($config['roots']) : array();
|
||||
$selected = array();
|
||||
$selected_ids = array();
|
||||
foreach ($roots as $root)
|
||||
{
|
||||
$path = trim((string)($root['webdav_path'] ?? ''), '/');
|
||||
$fileid = (int)($root['fileid'] ?? 0);
|
||||
if ($fileid < 1) continue;
|
||||
$selected[] = $path;
|
||||
$selected_ids[$path] = $fileid;
|
||||
}
|
||||
|
||||
$state = bratonien_tools_nc_wizard_state();
|
||||
$state = array_merge($state, array(
|
||||
'editing_connection_id'=>$id,
|
||||
'editing_adapter'=>(string)$connection['adapter'],
|
||||
'editing_mode'=>(string)$mode,
|
||||
'connection_name'=>(string)$connection['name'],
|
||||
'host_input'=>$base_url,
|
||||
'base_url'=>$base_url,
|
||||
'username'=>$username,
|
||||
'_password'=>$password,
|
||||
'_fallback_user'=>(string)($credentials['piwigo_user'] ?? ''),
|
||||
'_fallback_password'=>(string)($credentials['piwigo_password'] ?? ''),
|
||||
'_api_key_id'=>(string)($credentials['api_key_id'] ?? ''),
|
||||
'_api_key_secret'=>(string)($credentials['api_key_secret'] ?? ''),
|
||||
'api_status'=>trim((string)($credentials['api_key_id'] ?? '')) !== '' && trim((string)($credentials['api_key_secret'] ?? '')) !== '' ? 'ok' : 'pending',
|
||||
'roots'=>$roots,
|
||||
'directory_selected'=>$selected,
|
||||
'directory_selected_fileids'=>$selected_ids,
|
||||
'source_mode'=>'webdav-placeholder',
|
||||
'transport'=>'webdav',
|
||||
));
|
||||
|
||||
if ($base_url !== '' && $username !== '' && $password !== '')
|
||||
{
|
||||
$state['step'] = 2;
|
||||
$state['scan_ok'] = true;
|
||||
$state['technical_stage'] = 'mounts';
|
||||
$state['technical_source'] = 'WebDAV';
|
||||
$state['technical_error'] = '';
|
||||
$state['technical_complete'] = false;
|
||||
$state['directory_selection_ready'] = true;
|
||||
$state['directory_path'] = '';
|
||||
$state['directory_parent'] = '';
|
||||
$state['directory_children'] = array();
|
||||
$state['directory_current_fileid'] = 0;
|
||||
|
||||
try
|
||||
{
|
||||
bratonien_tools_nc_wizard_refresh_directory_state($state, '');
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$state['step'] = 1;
|
||||
$state['scan_ok'] = false;
|
||||
$state['technical_error'] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$state['step'] = 1;
|
||||
$state['scan_ok'] = false;
|
||||
}
|
||||
|
||||
bratonien_tools_nc_wizard_store($state);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_edit_start()
|
||||
{
|
||||
$id = (int)($_POST['connection_id'] ?? 0);
|
||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$is_webdav = (string)$connection['adapter'] === 'remote'
|
||||
&& (string)($config['source_mode'] ?? '') === 'webdav-placeholder';
|
||||
if (!$is_webdav)
|
||||
{
|
||||
throw new RuntimeException('Diese Legacy-Verbindung wird direkt bearbeitet. Eine WebDAV-Migration ist eine separate Aktion.');
|
||||
}
|
||||
|
||||
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'update');
|
||||
return array('message'=>'Verbindung #'.$id.' wurde zum Bearbeiten geoeffnet.');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_migrate_start()
|
||||
{
|
||||
$id = (int)($_POST['connection_id'] ?? 0);
|
||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||
if ((string)$connection['adapter'] !== 'local')
|
||||
{
|
||||
throw new RuntimeException('Nur eine Legacy-Verbindung kann auf WebDAV migriert werden.');
|
||||
}
|
||||
|
||||
$migration = bratonien_tools_nc_connector_migration_state($connection);
|
||||
if (empty($migration['ready']))
|
||||
{
|
||||
throw new RuntimeException('Die WebDAV-Migration ist noch nicht bereit. Unter Bearbeiten fehlen: '.implode(', ', $migration['missing']).'.');
|
||||
}
|
||||
|
||||
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'migrate');
|
||||
return array('message'=>'Die WebDAV-Migration fuer Verbindung #'.$id.' wurde geoeffnet. Die bestehende Legacy-Verbindung bleibt bis zum erfolgreichen Umstieg unveraendert.');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_update_local_friendly()
|
||||
{
|
||||
$id = (int)($_POST['connection_id'] ?? 0);
|
||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||
if ((string)$connection['adapter'] !== 'local') throw new RuntimeException('Diese Bearbeitung ist nur fuer Legacy-Verbindungen vorgesehen.');
|
||||
|
||||
$name = trim((string)($_POST['connection_name'] ?? ''));
|
||||
if ($name === '') throw new RuntimeException('Bitte einen Namen fuer die Verbindung angeben.');
|
||||
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$host = trim((string)($_POST['nc_host'] ?? ''));
|
||||
$port = (int)($_POST['nc_port'] ?? 5432);
|
||||
$database = trim((string)($_POST['nc_database'] ?? ''));
|
||||
$user = trim((string)($_POST['nc_user'] ?? ''));
|
||||
$gallery_root = rtrim(trim((string)($_POST['nc_gallery_root'] ?? '')), '/');
|
||||
$source_view = trim((string)($_POST['nc_source_view'] ?? ''));
|
||||
$activity_view = trim((string)($_POST['nc_activity_view'] ?? ''));
|
||||
|
||||
if ($host === '') throw new RuntimeException('Datenbank-Server fehlt.');
|
||||
if ($port < 1 || $port > 65535) throw new RuntimeException('Der Datenbank-Port ist ungueltig.');
|
||||
if ($database === '') throw new RuntimeException('Datenbankname fehlt.');
|
||||
if ($user === '') throw new RuntimeException('Reader-Benutzer fehlt.');
|
||||
if ($gallery_root === '' || $gallery_root[0] !== '/') throw new RuntimeException('Der Piwigo-Galerieordner muss ein absoluter Pfad sein.');
|
||||
if ($source_view === '' || $activity_view === '') throw new RuntimeException('Die gespeicherten Datenbankansichten duerfen nicht leer sein.');
|
||||
bratonien_tools_nc_connector_view_name($source_view);
|
||||
bratonien_tools_nc_connector_view_name($activity_view);
|
||||
|
||||
$storage_ids = isset($_POST['nc_storage_id']) && is_array($_POST['nc_storage_id']) ? $_POST['nc_storage_id'] : array();
|
||||
$storage_prefixes = isset($_POST['nc_source_prefix']) && is_array($_POST['nc_source_prefix']) ? $_POST['nc_source_prefix'] : array();
|
||||
$storage_mounts = isset($_POST['nc_local_mount']) && is_array($_POST['nc_local_mount']) ? $_POST['nc_local_mount'] : array();
|
||||
$storages = array();
|
||||
$count = max(count($storage_ids), count($storage_prefixes), count($storage_mounts));
|
||||
for ($index = 0; $index < $count; $index++)
|
||||
{
|
||||
$storage_id = trim((string)($storage_ids[$index] ?? ''));
|
||||
$prefix = trim((string)($storage_prefixes[$index] ?? ''), '/');
|
||||
$mount = rtrim(trim((string)($storage_mounts[$index] ?? '')), '/');
|
||||
if ($storage_id === '' && $prefix === '' && $mount === '') continue;
|
||||
if ($storage_id === '') throw new RuntimeException('Bei einem Speicherort fehlt die Storage-ID.');
|
||||
if ($mount === '' || $mount[0] !== '/') throw new RuntimeException('Bei einem Speicherort fehlt ein gueltiger lokaler Pfad.');
|
||||
$storages[] = array('storage_id'=>$storage_id, 'source_prefix'=>$prefix, 'local_mount'=>$mount);
|
||||
}
|
||||
if (!$storages) throw new RuntimeException('Mindestens ein Speicherort muss vorhanden sein.');
|
||||
|
||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||
$new_db_password = (string)($_POST['nc_db_password'] ?? '');
|
||||
if ($new_db_password !== '') $credentials['db_password'] = $new_db_password;
|
||||
if (trim((string)($credentials['db_password'] ?? '')) === '') throw new RuntimeException('Fuer die Legacy-Verbindung ist kein Datenbankpasswort gespeichert.');
|
||||
|
||||
$nextcloud_url = trim((string)($_POST['nc_nextcloud_url'] ?? ($config['nextcloud_url'] ?? '')));
|
||||
$nextcloud_user = trim((string)($_POST['nc_nextcloud_user'] ?? ($credentials['nextcloud_user'] ?? '')));
|
||||
$new_nextcloud_password = (string)($_POST['nc_nextcloud_password'] ?? '');
|
||||
if ($new_nextcloud_password !== '') $credentials['nextcloud_password'] = $new_nextcloud_password;
|
||||
$nextcloud_password = (string)($credentials['nextcloud_password'] ?? '');
|
||||
|
||||
$api_key_id = trim((string)($_POST['nc_connection_api_key_id'] ?? ($credentials['api_key_id'] ?? '')));
|
||||
$new_api_secret = trim((string)($_POST['nc_connection_api_key_secret'] ?? ''));
|
||||
$old_api_id = trim((string)($credentials['api_key_id'] ?? ''));
|
||||
if ($api_key_id !== $old_api_id && $new_api_secret === '')
|
||||
{
|
||||
throw new RuntimeException('Wenn die API-Schluessel-ID geaendert wird, muss auch das API-Geheimnis neu eingegeben werden.');
|
||||
}
|
||||
if ($new_api_secret !== '') $credentials['api_key_secret'] = $new_api_secret;
|
||||
$api_key_secret = trim((string)($credentials['api_key_secret'] ?? ''));
|
||||
|
||||
if (($nextcloud_url === '' || $nextcloud_user === '' || $nextcloud_password === '') && ($nextcloud_url !== '' || $nextcloud_user !== '' || $nextcloud_password !== ''))
|
||||
{
|
||||
throw new RuntimeException('Nextcloud-Adresse, Nextcloud-Benutzer und Nextcloud-Passwort muessen fuer WebDAV gemeinsam vollstaendig sein.');
|
||||
}
|
||||
if (($api_key_id === '') !== ($api_key_secret === ''))
|
||||
{
|
||||
throw new RuntimeException('Piwigo-API-Schluessel-ID und API-Geheimnis muessen gemeinsam vollstaendig sein.');
|
||||
}
|
||||
|
||||
if ($nextcloud_url !== '')
|
||||
{
|
||||
$validated_nc = bratonien_tools_nc_connector_validate_nextcloud_access($nextcloud_url, $nextcloud_user, $nextcloud_password);
|
||||
$nextcloud_url = $validated_nc['base_url'];
|
||||
$nextcloud_user = $validated_nc['username'];
|
||||
$credentials['nextcloud_user'] = $nextcloud_user;
|
||||
}
|
||||
if ($api_key_id !== '')
|
||||
{
|
||||
bratonien_tools_nc_connector_validate_scoped_api($api_key_id, $api_key_secret);
|
||||
$credentials['api_key_id'] = $api_key_id;
|
||||
}
|
||||
|
||||
$config['host'] = $host;
|
||||
$config['port'] = (string)$port;
|
||||
$config['database'] = $database;
|
||||
$config['user'] = $user;
|
||||
$config['source_view'] = $source_view;
|
||||
$config['activity_view'] = $activity_view;
|
||||
$config['gallery_root'] = $gallery_root;
|
||||
$config['quiet_seconds'] = max(0, (int)($_POST['nc_quiet_seconds'] ?? ($config['quiet_seconds'] ?? 120)));
|
||||
$config['max_wait_seconds'] = max(60, (int)($_POST['nc_max_wait_seconds'] ?? ($config['max_wait_seconds'] ?? 900)));
|
||||
$config['full_sync_seconds'] = max(300, (int)($_POST['nc_full_sync_seconds'] ?? ($config['full_sync_seconds'] ?? 86400)));
|
||||
$config['storages'] = $storages;
|
||||
if ($nextcloud_url !== '')
|
||||
{
|
||||
$config['nextcloud_url'] = $nextcloud_url;
|
||||
$config['access_user'] = $nextcloud_user;
|
||||
$config['nextcloud_access_user'] = $nextcloud_user;
|
||||
}
|
||||
$config['piwigo_auth'] = 'connection-scoped';
|
||||
$config['api_enabled'] = $api_key_id !== '' && $api_key_secret !== '';
|
||||
unset($config['verification']);
|
||||
|
||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($config_json)) throw new RuntimeException('Connector-Konfiguration konnte nicht serialisiert werden.');
|
||||
$secret_payload = json_encode($credentials, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($secret_payload)) throw new RuntimeException('Connector-Zugangsdaten konnten nicht serialisiert werden.');
|
||||
$secret_blob = bratonien_tools_nc_connector_encrypt_secret($secret_payload);
|
||||
|
||||
$table = bratonien_tools_nc_connector_table();
|
||||
$now = date('Y-m-d H:i:s');
|
||||
pwg_query("UPDATE `$table` SET name='".pwg_db_real_escape_string($name)."', config_json='".pwg_db_real_escape_string($config_json)."', secret_blob='".pwg_db_real_escape_string($secret_blob)."', updated='".pwg_db_real_escape_string($now)."' WHERE id=".$id." LIMIT 1");
|
||||
|
||||
$updated = bratonien_tools_nc_connector_connection($id, true);
|
||||
$migration = $updated ? bratonien_tools_nc_connector_migration_state($updated) : array('ready'=>false);
|
||||
return array(
|
||||
'message'=>'Verbindung #'.$id.' wurde gespeichert. '.(!empty($migration['ready']) ? 'Die WebDAV-Migration ist jetzt bereit.' : 'Die WebDAV-Migration ist noch nicht vollstaendig vorbereitet.'),
|
||||
);
|
||||
}
|
||||
210
include/nc_connector_scheduler.inc.php
Normal file
210
include/nc_connector_scheduler.inc.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
if (!defined('PHPWG_ROOT_PATH'))
|
||||
{
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_paths()
|
||||
{
|
||||
$base = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools';
|
||||
return array(
|
||||
'base'=>$base,
|
||||
'runtime'=>$base.'/nc-connector-runtime',
|
||||
'state_root'=>$base.'/nc-connector-state',
|
||||
'scheduler'=>$base.'/nc-connector-scheduler',
|
||||
'state'=>$base.'/nc-connector-scheduler/state.json',
|
||||
'trigger_lock'=>$base.'/nc-connector-scheduler/trigger.lock',
|
||||
'worker_lock'=>$base.'/nc-connector-scheduler/worker.lock',
|
||||
'log'=>$base.'/nc-connector-scheduler/last-worker.log',
|
||||
'status_root'=>$base.'/nc-connector-status',
|
||||
);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_interval()
|
||||
{
|
||||
global $conf;
|
||||
$interval = isset($conf['bratonien_nc_scheduler_interval']) ? (int)$conf['bratonien_nc_scheduler_interval'] : 60;
|
||||
return max(60, $interval);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_ensure_dirs()
|
||||
{
|
||||
foreach (bratonien_tools_nc_scheduler_paths() as $key=>$path)
|
||||
{
|
||||
if (in_array($key, array('state','trigger_lock','worker_lock','log'), true)) continue;
|
||||
if (!is_dir($path) && !@mkdir($path, 0750, true) && !is_dir($path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_read_state()
|
||||
{
|
||||
$paths = bratonien_tools_nc_scheduler_paths();
|
||||
if (!is_readable($paths['state'])) return array();
|
||||
$decoded = json_decode((string)@file_get_contents($paths['state']), true);
|
||||
return is_array($decoded) ? $decoded : array();
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_write_state(array $state)
|
||||
{
|
||||
$paths = bratonien_tools_nc_scheduler_paths();
|
||||
if (!bratonien_tools_nc_scheduler_ensure_dirs()) return false;
|
||||
$json = json_encode($state, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
if (!is_string($json)) return false;
|
||||
$tmp = $paths['state'].'.tmp';
|
||||
if (@file_put_contents($tmp, $json."\n", LOCK_EX) === false) return false;
|
||||
@chmod($tmp, 0640);
|
||||
return @rename($tmp, $paths['state']);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_write_connection_status($connection_id, $state, $message)
|
||||
{
|
||||
$connection_id = (int)$connection_id;
|
||||
if ($connection_id < 1) return false;
|
||||
$paths = bratonien_tools_nc_scheduler_paths();
|
||||
if (!bratonien_tools_nc_scheduler_ensure_dirs()) return false;
|
||||
$target = $paths['status_root'].'/connection-'.$connection_id.'.json';
|
||||
$existing = array();
|
||||
if (is_readable($target))
|
||||
{
|
||||
$decoded = json_decode((string)@file_get_contents($target), true);
|
||||
if (is_array($decoded)) $existing = $decoded;
|
||||
}
|
||||
$existing['state'] = (string)$state;
|
||||
$existing['message'] = (string)$message;
|
||||
$existing['timestamp'] = time();
|
||||
$existing['connection_id'] = $connection_id;
|
||||
$json = json_encode($existing, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
if (!is_string($json)) return false;
|
||||
$tmp = $target.'.tmp';
|
||||
if (@file_put_contents($tmp, $json."\n", LOCK_EX) === false) return false;
|
||||
@chmod($tmp, 0644);
|
||||
return @rename($tmp, $target);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_install()
|
||||
{
|
||||
if (!bratonien_tools_nc_scheduler_ensure_dirs()) return false;
|
||||
$state = bratonien_tools_nc_scheduler_read_state();
|
||||
if (empty($state['next_due']))
|
||||
{
|
||||
$state['next_due'] = time();
|
||||
$state['enabled'] = true;
|
||||
$state['mode'] = 'piwigo-native';
|
||||
bratonien_tools_nc_scheduler_write_state($state);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_php_binary()
|
||||
{
|
||||
foreach (array('/usr/bin/php', '/usr/local/bin/php', PHP_BINARY) as $candidate)
|
||||
{
|
||||
if (is_string($candidate) && $candidate !== '' && is_executable($candidate)) return $candidate;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_spawn($force = false, $connection_id = 0)
|
||||
{
|
||||
$connection_id = max(0, (int)$connection_id);
|
||||
$paths = bratonien_tools_nc_scheduler_paths();
|
||||
if (!bratonien_tools_nc_scheduler_ensure_dirs())
|
||||
{
|
||||
throw new RuntimeException('Der native NC-Scheduler kann sein Laufzeitverzeichnis nicht anlegen.');
|
||||
}
|
||||
|
||||
$lock = @fopen($paths['trigger_lock'], 'c+');
|
||||
if (!is_resource($lock) || !@flock($lock, LOCK_EX | LOCK_NB))
|
||||
{
|
||||
if (is_resource($lock)) fclose($lock);
|
||||
return array('started'=>false, 'message'=>'Ein NC-Abgleich wird bereits vorbereitet.');
|
||||
}
|
||||
|
||||
$state = bratonien_tools_nc_scheduler_read_state();
|
||||
$now = time();
|
||||
$next_due = (int)($state['next_due'] ?? 0);
|
||||
if (!$force && $next_due > $now)
|
||||
{
|
||||
@flock($lock, LOCK_UN);
|
||||
fclose($lock);
|
||||
return array('started'=>false, 'message'=>'Der nächste NC-Abgleich ist noch nicht fällig.');
|
||||
}
|
||||
|
||||
$php = bratonien_tools_nc_scheduler_php_binary();
|
||||
if ($php === '')
|
||||
{
|
||||
@flock($lock, LOCK_UN);
|
||||
fclose($lock);
|
||||
throw new RuntimeException('Kein ausführbares PHP-CLI für den nativen NC-Scheduler gefunden.');
|
||||
}
|
||||
|
||||
$state['enabled'] = true;
|
||||
$state['mode'] = 'piwigo-native';
|
||||
$state['state'] = 'queued';
|
||||
$state['message'] = $connection_id > 0 ? 'NC-Abgleich für Verbindung #'.$connection_id.' wurde angefordert.' : 'NC-Abgleich für alle Verbindungen wurde angefordert.';
|
||||
$state['queued_at'] = $now;
|
||||
$state['timestamp'] = $now;
|
||||
$state['connection_id'] = $connection_id;
|
||||
$state['next_due'] = $now + bratonien_tools_nc_scheduler_interval();
|
||||
bratonien_tools_nc_scheduler_write_state($state);
|
||||
if ($connection_id > 0)
|
||||
{
|
||||
bratonien_tools_nc_scheduler_write_connection_status($connection_id, 'queued', 'Abgleich wurde angefordert.');
|
||||
}
|
||||
|
||||
$runner = BRATONIEN_TOOLS_PATH.'runtime/native-runner.php';
|
||||
$runner_args = $connection_id > 0 ? ' --connection-id='.escapeshellarg((string)$connection_id) : '';
|
||||
$command = escapeshellarg($php).' '.escapeshellarg($runner).$runner_args.' >> '.escapeshellarg($paths['log']).' 2>&1 &';
|
||||
$spec = array(
|
||||
0=>array('file','/dev/null','r'),
|
||||
1=>array('file','/dev/null','a'),
|
||||
2=>array('file','/dev/null','a'),
|
||||
);
|
||||
$process = function_exists('proc_open') ? @proc_open(array('/bin/sh','-c',$command), $spec, $pipes) : false;
|
||||
$exit = is_resource($process) ? proc_close($process) : 1;
|
||||
|
||||
@flock($lock, LOCK_UN);
|
||||
fclose($lock);
|
||||
|
||||
if ($exit !== 0)
|
||||
{
|
||||
$state = bratonien_tools_nc_scheduler_read_state();
|
||||
$state['state'] = 'error';
|
||||
$state['message'] = 'Der native NC-Abgleich konnte nicht gestartet werden.';
|
||||
$state['timestamp'] = time();
|
||||
bratonien_tools_nc_scheduler_write_state($state);
|
||||
if ($connection_id > 0)
|
||||
{
|
||||
bratonien_tools_nc_scheduler_write_connection_status($connection_id, 'error', 'Abgleich konnte nicht gestartet werden.');
|
||||
}
|
||||
throw new RuntimeException('Der native NC-Abgleich konnte nicht gestartet werden.');
|
||||
}
|
||||
|
||||
return array('started'=>true, 'message'=>$connection_id > 0 ? 'Abgleich für Verbindung #'.$connection_id.' wurde angefordert.' : 'Abgleich für alle Verbindungen wurde angefordert.');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_scheduler_tick()
|
||||
{
|
||||
$state = bratonien_tools_nc_scheduler_read_state();
|
||||
if (isset($state['enabled']) && !$state['enabled']) return;
|
||||
$next_due = (int)($state['next_due'] ?? 0);
|
||||
if ($next_due > time()) return;
|
||||
|
||||
try
|
||||
{
|
||||
bratonien_tools_nc_scheduler_spawn(false, 0);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$state = bratonien_tools_nc_scheduler_read_state();
|
||||
$state['state'] = 'error';
|
||||
$state['message'] = $e->getMessage();
|
||||
$state['timestamp'] = time();
|
||||
$state['next_due'] = time() + bratonien_tools_nc_scheduler_interval();
|
||||
bratonien_tools_nc_scheduler_write_state($state);
|
||||
}
|
||||
}
|
||||
@@ -4,109 +4,13 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_systemctl_value(array $args)
|
||||
{
|
||||
if (!function_exists('proc_open'))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$command = array_merge(array('/usr/bin/systemctl'), $args);
|
||||
$spec = array(
|
||||
0 => array('file', '/dev/null', 'r'),
|
||||
1 => array('pipe', 'w'),
|
||||
2 => array('pipe', 'w'),
|
||||
);
|
||||
$environment = array_merge($_ENV, array('LC_ALL'=>'C', 'LANG'=>'C'));
|
||||
$process = @proc_open($command, $spec, $pipes, null, $environment);
|
||||
if (!is_resource($process))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
$stdout = stream_get_contents($pipes[1]);
|
||||
stream_get_contents($pipes[2]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
$exit = proc_close($process);
|
||||
return $exit === 0 ? trim((string)$stdout) : '';
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_parse_systemd_time($value)
|
||||
{
|
||||
$value = trim((string)$value);
|
||||
if ($value === '' || strtolower($value) === 'n/a')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
$parsed = strtotime($value);
|
||||
return $parsed === false ? 0 : (int)$parsed;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_monotonic_to_timestamp($value)
|
||||
{
|
||||
$value = trim((string)$value);
|
||||
if ($value === '' || $value === '0' || strtolower($value) === 'n/a')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (preg_match('/^([0-9]+)(?:us)?$/', $value, $matches))
|
||||
{
|
||||
$next_boot_seconds = ((float)$matches[1]) / 1000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$uptime_raw = @file_get_contents('/proc/uptime');
|
||||
if (!is_string($uptime_raw) || !preg_match('/^([0-9]+(?:\.[0-9]+)?)/', trim($uptime_raw), $uptime_match))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$remaining = $next_boot_seconds - (float)$uptime_match[1];
|
||||
if ($remaining < -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int)round(time() + max(0, $remaining));
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_next_from_timer_list($timer)
|
||||
{
|
||||
$line = bratonien_tools_nc_connector_systemctl_value(array(
|
||||
'list-timers', '--all', '--no-pager', '--no-legend', $timer,
|
||||
));
|
||||
if ($line === '')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$first_line = trim((string)strtok($line, "\n"));
|
||||
if (preg_match('/^(\S+\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+\S+)/', $first_line, $matches))
|
||||
{
|
||||
$parsed = strtotime($matches[1]);
|
||||
return $parsed === false ? 0 : (int)$parsed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_scheduler.inc.php');
|
||||
|
||||
function bratonien_tools_nc_connector_connection_last_status(array $connection)
|
||||
{
|
||||
$empty = array(
|
||||
'timestamp'=>0,
|
||||
'label'=>'Nicht verfügbar',
|
||||
'state'=>'',
|
||||
'message'=>'',
|
||||
'auth_mode'=>'',
|
||||
'api_state'=>'',
|
||||
'api_message'=>'',
|
||||
'fallback_state'=>'',
|
||||
'fallback_message'=>'',
|
||||
'error_detail'=>'',
|
||||
'timestamp'=>0,'label'=>'Nicht verfügbar','state'=>'','message'=>'','auth_mode'=>'',
|
||||
'api_state'=>'','api_message'=>'','fallback_state'=>'','fallback_message'=>'','error_detail'=>'',
|
||||
);
|
||||
|
||||
$connection_id = (int)($connection['id'] ?? 0);
|
||||
@@ -114,42 +18,25 @@ function bratonien_tools_nc_connector_connection_last_status(array $connection)
|
||||
if ($connection_id > 0)
|
||||
{
|
||||
$candidates[] = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-connector-status/connection-'.$connection_id.'.json';
|
||||
$candidates[] = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-connector-state/connection-'.$connection_id.'/connector-status.json';
|
||||
}
|
||||
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$state_dir = rtrim((string)($config['state_dir'] ?? ''), '/');
|
||||
if ($state_dir === '' && $connection_id > 0)
|
||||
{
|
||||
$state_dir = '/var/lib/bratonien-tools/nc-connector/connection-'.$connection_id;
|
||||
}
|
||||
if ($state_dir !== '')
|
||||
{
|
||||
$candidates[] = $state_dir.'/connector-status.json';
|
||||
}
|
||||
if ($state_dir !== '') $candidates[] = $state_dir.'/connector-status.json';
|
||||
|
||||
$decoded = null;
|
||||
foreach ($candidates as $candidate)
|
||||
foreach (array_unique($candidates) as $candidate)
|
||||
{
|
||||
if (!is_readable($candidate))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!is_readable($candidate)) continue;
|
||||
$value = json_decode((string)@file_get_contents($candidate), true);
|
||||
if (is_array($value))
|
||||
{
|
||||
$decoded = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!is_array($decoded))
|
||||
{
|
||||
return $empty;
|
||||
if (is_array($value)) { $decoded = $value; break; }
|
||||
}
|
||||
if (!is_array($decoded)) return $empty;
|
||||
|
||||
$timestamp = (int)($decoded['timestamp'] ?? 0);
|
||||
$api = isset($decoded['api']) && is_array($decoded['api']) ? $decoded['api'] : array();
|
||||
$fallback = isset($decoded['fallback']) && is_array($decoded['fallback']) ? $decoded['fallback'] : array();
|
||||
|
||||
return array(
|
||||
'timestamp'=>$timestamp,
|
||||
'label'=>$timestamp > 0 ? date('d.m.Y H:i:s', $timestamp) : 'Nicht verfügbar',
|
||||
@@ -166,73 +53,88 @@ function bratonien_tools_nc_connector_connection_last_status(array $connection)
|
||||
|
||||
function bratonien_tools_nc_connector_last_status(array $connections)
|
||||
{
|
||||
$latest = array('timestamp'=>0, 'state'=>'', 'message'=>'', 'auth_mode'=>'', 'api_state'=>'', 'api_message'=>'', 'fallback_state'=>'', 'fallback_message'=>'', 'error_detail'=>'');
|
||||
|
||||
$latest = array('timestamp'=>0,'state'=>'','message'=>'','auth_mode'=>'','api_state'=>'','api_message'=>'','fallback_state'=>'','fallback_message'=>'','error_detail'=>'');
|
||||
foreach ($connections as $connection)
|
||||
{
|
||||
if (empty($connection['enabled']) || (string)($connection['takeover_state'] ?? '') !== 'active')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($connection['enabled'])) continue;
|
||||
$status = bratonien_tools_nc_connector_connection_last_status($connection);
|
||||
if ((int)$status['timestamp'] >= (int)$latest['timestamp'])
|
||||
{
|
||||
$latest = $status;
|
||||
}
|
||||
if ((int)$status['timestamp'] >= (int)$latest['timestamp']) $latest = $status;
|
||||
}
|
||||
|
||||
return $latest;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_system_status(array $connections = array())
|
||||
{
|
||||
$timer = 'bratonien-nc-connector.timer';
|
||||
$service = 'bratonien-nc-connector.service';
|
||||
|
||||
$next_realtime_raw = bratonien_tools_nc_connector_systemctl_value(array('show', $timer, '--property=NextElapseUSecRealtime', '--value'));
|
||||
$next_timestamp = bratonien_tools_nc_connector_parse_systemd_time($next_realtime_raw);
|
||||
|
||||
if ($next_timestamp <= 0)
|
||||
{
|
||||
$next_monotonic_raw = bratonien_tools_nc_connector_systemctl_value(array('show', $timer, '--property=NextElapseUSecMonotonic', '--value'));
|
||||
$next_timestamp = bratonien_tools_nc_connector_monotonic_to_timestamp($next_monotonic_raw);
|
||||
}
|
||||
|
||||
if ($next_timestamp <= 0)
|
||||
{
|
||||
$next_timestamp = bratonien_tools_nc_connector_next_from_timer_list($timer);
|
||||
}
|
||||
|
||||
$active = bratonien_tools_nc_connector_systemctl_value(array('is-active', $timer));
|
||||
$enabled = bratonien_tools_nc_connector_systemctl_value(array('is-enabled', $timer));
|
||||
|
||||
$scheduler = bratonien_tools_nc_scheduler_read_state();
|
||||
$enabled = !isset($scheduler['enabled']) || !empty($scheduler['enabled']);
|
||||
$scheduler_state = (string)($scheduler['state'] ?? '');
|
||||
$running = $scheduler_state === 'running';
|
||||
$queued = $scheduler_state === 'queued';
|
||||
$started = (int)($scheduler['started_at'] ?? 0);
|
||||
$next = (int)($scheduler['next_due'] ?? 0);
|
||||
$last = bratonien_tools_nc_connector_last_status($connections);
|
||||
if ($last['timestamp'] <= 0)
|
||||
|
||||
if ($next > 0)
|
||||
{
|
||||
$last_raw = bratonien_tools_nc_connector_systemctl_value(array('show', $service, '--property=ExecMainExitTimestamp', '--value'));
|
||||
$last['timestamp'] = bratonien_tools_nc_connector_parse_systemd_time($last_raw);
|
||||
$next_label = date('d.m.Y H:i:s', $next).' (beim nächsten Piwigo-Aufruf)';
|
||||
}
|
||||
else
|
||||
{
|
||||
$next_label = 'Beim nächsten Piwigo-Aufruf';
|
||||
}
|
||||
|
||||
$scheduler_timestamp = (int)($scheduler['timestamp'] ?? 0);
|
||||
if ($scheduler_timestamp > (int)$last['timestamp'])
|
||||
{
|
||||
$last['timestamp'] = $scheduler_timestamp;
|
||||
$last['state'] = $scheduler_state;
|
||||
$last['message'] = (string)($scheduler['message'] ?? '');
|
||||
if ($scheduler_state === 'error')
|
||||
{
|
||||
$detail = trim((string)($scheduler['stderr'] ?? ''));
|
||||
if ($detail === '') $detail = trim((string)($scheduler['stdout'] ?? ''));
|
||||
$last['error_detail'] = $detail;
|
||||
}
|
||||
}
|
||||
elseif ((int)$last['timestamp'] <= 0 && !empty($scheduler['finished_at']))
|
||||
{
|
||||
$last['timestamp'] = (int)$scheduler['finished_at'];
|
||||
$last['state'] = $scheduler_state;
|
||||
$last['message'] = (string)($scheduler['message'] ?? '');
|
||||
if ((string)$last['state'] === 'error')
|
||||
{
|
||||
$detail = trim((string)($scheduler['stderr'] ?? ''));
|
||||
if ($detail === '') $detail = trim((string)($scheduler['stdout'] ?? ''));
|
||||
$last['error_detail'] = $detail;
|
||||
}
|
||||
}
|
||||
|
||||
$current_label = 'Kein Lauf aktiv';
|
||||
if ($queued) $current_label = 'Abgleich angefordert';
|
||||
if ($running) $current_label = $started > 0 ? 'Läuft seit '.date('d.m.Y H:i:s', $started) : 'Läuft gerade';
|
||||
|
||||
return array(
|
||||
'timer_name' => $timer,
|
||||
'timer_active' => $active === 'active',
|
||||
'timer_enabled' => $enabled === 'enabled',
|
||||
'last_run_timestamp' => (int)$last['timestamp'],
|
||||
'last_run_label' => $last['timestamp'] > 0 ? date('d.m.Y H:i:s', (int)$last['timestamp']) : 'Nicht verfügbar',
|
||||
'last_run_state' => (string)$last['state'],
|
||||
'last_run_message' => (string)$last['message'],
|
||||
'last_run_auth_mode' => (string)$last['auth_mode'],
|
||||
'last_run_api_state' => (string)$last['api_state'],
|
||||
'last_run_api_message' => (string)$last['api_message'],
|
||||
'last_run_fallback_state' => (string)$last['fallback_state'],
|
||||
'last_run_fallback_message' => (string)$last['fallback_message'],
|
||||
'last_run_error_detail' => (string)$last['error_detail'],
|
||||
'next_run_timestamp' => $next_timestamp,
|
||||
'next_run_label' => $next_timestamp > 0 ? date('d.m.Y H:i:s', $next_timestamp) : 'Nicht verfügbar',
|
||||
'legacy_runtime_exists' => is_dir('/opt/piwigo-sync'),
|
||||
'legacy_config_exists' => is_dir('/etc/piwigo-sync'),
|
||||
'legacy_service_exists' => is_file('/etc/systemd/system/piwigo-sync.service'),
|
||||
'legacy_timer_exists' => is_file('/etc/systemd/system/piwigo-sync.timer'),
|
||||
'timer_name'=>'Piwigo nativer NC-Scheduler',
|
||||
'timer_active'=>$enabled,
|
||||
'timer_enabled'=>$enabled,
|
||||
'service_active'=>$running || $queued,
|
||||
'current_run_timestamp'=>$queued ? (int)($scheduler['queued_at'] ?? 0) : $started,
|
||||
'current_run_label'=>$current_label,
|
||||
'last_run_timestamp'=>(int)$last['timestamp'],
|
||||
'last_run_label'=>(int)$last['timestamp'] > 0 ? date('d.m.Y H:i:s', (int)$last['timestamp']) : 'Nicht verfügbar',
|
||||
'last_run_state'=>(string)$last['state'],
|
||||
'last_run_message'=>(string)$last['message'],
|
||||
'last_run_auth_mode'=>(string)$last['auth_mode'],
|
||||
'last_run_api_state'=>(string)$last['api_state'],
|
||||
'last_run_api_message'=>(string)$last['api_message'],
|
||||
'last_run_fallback_state'=>(string)$last['fallback_state'],
|
||||
'last_run_fallback_message'=>(string)$last['fallback_message'],
|
||||
'last_run_error_detail'=>(string)$last['error_detail'],
|
||||
'next_run_timestamp'=>$next,
|
||||
'next_run_label'=>$next_label,
|
||||
'legacy_runtime_exists'=>is_dir('/opt/piwigo-sync'),
|
||||
'legacy_config_exists'=>is_dir('/etc/piwigo-sync'),
|
||||
'legacy_service_exists'=>is_file('/etc/systemd/system/piwigo-sync.service'),
|
||||
'legacy_timer_exists'=>is_file('/etc/systemd/system/piwigo-sync.timer'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
<?php
|
||||
if (!defined('PHPWG_ROOT_PATH'))
|
||||
{
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlled handover preparation for verified NC Connector connections.
|
||||
*
|
||||
* This phase intentionally does not stop, disable or modify the legacy
|
||||
* piwigo-sync service. It only marks a verified Connector connection as ready
|
||||
* for a later controlled takeover. The marker can be rolled back at any time.
|
||||
*/
|
||||
|
||||
function bratonien_tools_nc_connector_ensure_takeover_state()
|
||||
{
|
||||
bratonien_tools_nc_connector_ensure_table();
|
||||
$table = bratonien_tools_nc_connector_table();
|
||||
pwg_query("ALTER TABLE `$table` MODIFY takeover_state enum('imported','verified','ready','active','disabled') NOT NULL DEFAULT 'imported'");
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_prepare_takeover()
|
||||
{
|
||||
$id = isset($_POST['connection_id']) ? (int)$_POST['connection_id'] : 0;
|
||||
$connection = bratonien_tools_nc_connector_connection($id, false);
|
||||
if (!$connection)
|
||||
{
|
||||
throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||
}
|
||||
if ($connection['takeover_state'] !== 'verified')
|
||||
{
|
||||
throw new RuntimeException('Nur eine erfolgreich verifizierte Verbindung kann fuer die Uebergabe vorbereitet werden.');
|
||||
}
|
||||
|
||||
$config = $connection['config'];
|
||||
$verification = isset($config['verification']) && is_array($config['verification'])
|
||||
? $config['verification']
|
||||
: array();
|
||||
if (empty($verification['ok']))
|
||||
{
|
||||
throw new RuntimeException('Die gespeicherte Verifikation ist nicht erfolgreich. Bitte die Verbindung erneut pruefen.');
|
||||
}
|
||||
|
||||
$config['takeover'] = array(
|
||||
'prepared_at' => date('Y-m-d H:i:s'),
|
||||
'legacy_sync_untouched' => true,
|
||||
'connector_enabled' => false,
|
||||
'first_run' => array(
|
||||
'status' => 'pending',
|
||||
'finished_at' => null,
|
||||
'detail' => '',
|
||||
),
|
||||
);
|
||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($config_json))
|
||||
{
|
||||
throw new RuntimeException('Uebergabestatus konnte nicht gespeichert werden.');
|
||||
}
|
||||
|
||||
bratonien_tools_nc_connector_ensure_takeover_state();
|
||||
$table = bratonien_tools_nc_connector_table();
|
||||
$now = date('Y-m-d H:i:s');
|
||||
pwg_query("UPDATE `$table` SET
|
||||
takeover_state = 'ready',
|
||||
enabled = 0,
|
||||
config_json = '".pwg_db_real_escape_string($config_json)."',
|
||||
updated = '".pwg_db_real_escape_string($now)."'
|
||||
WHERE id = ".(int)$connection['id']);
|
||||
|
||||
return array(
|
||||
'message' => 'Die verifizierte Nextcloud-Verbindung ist jetzt fuer die kontrollierte Uebergabe vorbereitet. Der Connector wurde noch nicht aktiviert und der Legacy-Sync bleibt unveraendert Produktionsverbindung.',
|
||||
);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_connector_cancel_takeover()
|
||||
{
|
||||
$id = isset($_POST['connection_id']) ? (int)$_POST['connection_id'] : 0;
|
||||
$connection = bratonien_tools_nc_connector_connection($id, false);
|
||||
if (!$connection)
|
||||
{
|
||||
throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||
}
|
||||
if ($connection['takeover_state'] !== 'ready')
|
||||
{
|
||||
throw new RuntimeException('Diese Verbindung befindet sich nicht in der Uebergabevorbereitung.');
|
||||
}
|
||||
|
||||
$config = $connection['config'];
|
||||
if (isset($config['takeover']))
|
||||
{
|
||||
unset($config['takeover']);
|
||||
}
|
||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($config_json))
|
||||
{
|
||||
throw new RuntimeException('Uebergabestatus konnte nicht zurueckgesetzt werden.');
|
||||
}
|
||||
|
||||
bratonien_tools_nc_connector_ensure_takeover_state();
|
||||
$table = bratonien_tools_nc_connector_table();
|
||||
$now = date('Y-m-d H:i:s');
|
||||
pwg_query("UPDATE `$table` SET
|
||||
takeover_state = 'verified',
|
||||
enabled = 0,
|
||||
config_json = '".pwg_db_real_escape_string($config_json)."',
|
||||
updated = '".pwg_db_real_escape_string($now)."'
|
||||
WHERE id = ".(int)$connection['id']);
|
||||
|
||||
return array(
|
||||
'message' => 'Die Uebergabevorbereitung wurde zurueckgenommen. Die Verbindung bleibt verifiziert und deaktiviert; der Legacy-Sync bleibt unveraendert aktiv.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the outcome of a Connector sync run during takeover.
|
||||
*
|
||||
* Both "changed" and "no_changes" are successful results. Only "error"
|
||||
* represents a failed run and may trigger rollback of a controlled handover.
|
||||
*/
|
||||
function bratonien_tools_nc_connector_takeover_result($status, $detail = '')
|
||||
{
|
||||
$status = trim((string)$status);
|
||||
if (!in_array($status, array('changed', 'no_changes', 'error'), true))
|
||||
{
|
||||
throw new RuntimeException('Unbekannter Connector-Laufstatus: '.$status);
|
||||
}
|
||||
|
||||
return array(
|
||||
'status' => $status,
|
||||
'success' => $status !== 'error',
|
||||
'changed' => $status === 'changed',
|
||||
'finished_at' => date('Y-m-d H:i:s'),
|
||||
'detail' => (string)$detail,
|
||||
);
|
||||
}
|
||||
@@ -5,10 +5,8 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a disabled WebDAV-backed connector beside the existing local modes.
|
||||
*
|
||||
* This deliberately does not activate, migrate or modify any existing
|
||||
* connection. It only persists the data required for the parallel WebDAV path.
|
||||
* Create or update one independent WebDAV connector connection.
|
||||
* No migration pair, successor or implicit legacy fallback is created.
|
||||
*/
|
||||
function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
{
|
||||
@@ -16,7 +14,7 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
|
||||
if (empty($state['scan_ok']) || empty($state['technical_complete']))
|
||||
{
|
||||
throw new RuntimeException('Die WebDAV-Verbindung wurde im Assistenten noch nicht vollständig vorbereitet.');
|
||||
throw new RuntimeException('Die WebDAV-Verbindung wurde im Assistenten noch nicht vollstaendig vorbereitet.');
|
||||
}
|
||||
|
||||
$base_url = rtrim(trim((string)($state['base_url'] ?? '')), '/');
|
||||
@@ -24,7 +22,7 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
$password = (string)($state['_password'] ?? '');
|
||||
if ($base_url === '' || $username === '' || $password === '')
|
||||
{
|
||||
throw new RuntimeException('Für den WebDAV-Testpfad fehlen Nextcloud-Adresse oder Zugangsdaten.');
|
||||
throw new RuntimeException('Fuer den WebDAV-Zugang fehlen Nextcloud-Adresse oder Zugangsdaten.');
|
||||
}
|
||||
|
||||
$selected = isset($state['directory_selected']) && is_array($state['directory_selected'])
|
||||
@@ -33,17 +31,26 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
$selected_ids = isset($state['directory_selected_fileids']) && is_array($state['directory_selected_fileids'])
|
||||
? $state['directory_selected_fileids']
|
||||
: array();
|
||||
$selected = array_values(array_filter($selected, function($path) { return $path !== ''; }));
|
||||
if (!$selected) throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis für den WebDAV-Testpfad auswählen.');
|
||||
|
||||
if (!$selected)
|
||||
{
|
||||
$selected = array('');
|
||||
}
|
||||
|
||||
$roots = array();
|
||||
foreach ($selected as $path)
|
||||
{
|
||||
$fileid = isset($selected_ids[$path]) ? (int)$selected_ids[$path] : 0;
|
||||
if ($fileid < 1) throw new RuntimeException('Für ein ausgewähltes Nextcloud-Verzeichnis fehlt die eindeutige Datei-ID.');
|
||||
if ($fileid < 1)
|
||||
{
|
||||
throw new RuntimeException('Fuer ein ausgewaehltes Nextcloud-Verzeichnis fehlt die eindeutige Datei-ID.');
|
||||
}
|
||||
$display_name = $path === ''
|
||||
? (trim((string)($state['display_name'] ?? '')) !== '' ? trim((string)$state['display_name']) : $username)
|
||||
: basename($path);
|
||||
$roots[] = array(
|
||||
'fileid'=>$fileid,
|
||||
'display_name'=>basename($path),
|
||||
'display_name'=>$display_name,
|
||||
'webdav_path'=>$path,
|
||||
);
|
||||
}
|
||||
@@ -59,6 +66,19 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
$fallback_password = (string)($state['_fallback_password'] ?? '');
|
||||
$api_enabled = $api_key_id !== '' && $api_key_secret !== '';
|
||||
|
||||
$editing_id = (int)($state['editing_connection_id'] ?? 0);
|
||||
$editing_mode = (string)($state['editing_mode'] ?? '');
|
||||
$editing_connection = $editing_id > 0 ? bratonien_tools_nc_connector_connection($editing_id, false) : null;
|
||||
$editing_remote = $editing_connection
|
||||
&& (string)$editing_connection['adapter'] === 'remote'
|
||||
&& (string)($editing_connection['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
||||
&& $editing_mode === 'update';
|
||||
|
||||
if ($editing_mode === 'migrate')
|
||||
{
|
||||
throw new RuntimeException('Die Migrationsfunktion wurde entfernt. Bitte eine normale WebDAV-Verbindung anlegen.');
|
||||
}
|
||||
|
||||
$config = array(
|
||||
'origin'=>'native',
|
||||
'source_mode'=>'webdav-placeholder',
|
||||
@@ -73,11 +93,23 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
'quiet_seconds'=>120,
|
||||
'max_wait_seconds'=>900,
|
||||
'full_sync_seconds'=>86400,
|
||||
'parallel_test'=>true,
|
||||
'piwigo_auth'=>'connection-scoped',
|
||||
'api_enabled'=>$api_enabled,
|
||||
);
|
||||
|
||||
if ($editing_remote)
|
||||
{
|
||||
$old_config = is_array($editing_connection['config'] ?? null) ? $editing_connection['config'] : array();
|
||||
foreach (array('state_dir','status_file','parallel_gallery_root','source_fingerprint','runtime') as $preserve)
|
||||
{
|
||||
if (array_key_exists($preserve, $old_config)) $config[$preserve] = $old_config[$preserve];
|
||||
}
|
||||
foreach (array('quiet_seconds','max_wait_seconds','full_sync_seconds') as $preserve)
|
||||
{
|
||||
if (isset($old_config[$preserve])) $config[$preserve] = (int)$old_config[$preserve];
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array('product'=>'nextcloud_product', 'version'=>'nextcloud_version') as $state_key=>$config_key)
|
||||
{
|
||||
$value = trim((string)($state[$state_key] ?? ''));
|
||||
@@ -96,15 +128,31 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($secret_payload)) throw new RuntimeException('WebDAV-Zugangsdaten konnten nicht serialisiert werden.');
|
||||
|
||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($config_json)) throw new RuntimeException('WebDAV-Konfiguration konnte nicht serialisiert werden.');
|
||||
|
||||
bratonien_tools_nc_connector_ensure_table();
|
||||
$table = bratonien_tools_nc_connector_table();
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$connection_key = 'webdav-'.bin2hex(random_bytes(12));
|
||||
$secret_blob = bratonien_tools_nc_connector_encrypt_secret($secret_payload);
|
||||
|
||||
if ($editing_remote)
|
||||
{
|
||||
$config['state_dir'] = trim((string)($config['state_dir'] ?? '')) !== '' ? $config['state_dir'] : '/var/lib/bratonien-tools/nc-connector/connection-'.$editing_id;
|
||||
$config['status_file'] = trim((string)($config['status_file'] ?? '')) !== '' ? $config['status_file'] : $config['state_dir'].'/connector-status.json';
|
||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($config_json)) throw new RuntimeException('WebDAV-Konfiguration konnte nicht serialisiert werden.');
|
||||
|
||||
pwg_query("UPDATE `$table` SET name='".pwg_db_real_escape_string($name)."', config_json='".pwg_db_real_escape_string($config_json)."', secret_blob='".pwg_db_real_escape_string($secret_blob)."', updated='".pwg_db_real_escape_string($now)."' WHERE id=".$editing_id." AND adapter='remote' LIMIT 1");
|
||||
unset($_SESSION['bratonien_nc_wizard']);
|
||||
|
||||
return array(
|
||||
'connection_id'=>$editing_id,
|
||||
'message'=>'WebDAV-Verbindung wurde gespeichert.',
|
||||
);
|
||||
}
|
||||
|
||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($config_json)) throw new RuntimeException('WebDAV-Konfiguration konnte nicht serialisiert werden.');
|
||||
|
||||
$connection_key = 'webdav-'.bin2hex(random_bytes(12));
|
||||
pwg_query("INSERT INTO `$table` (connection_key,name,adapter,enabled,takeover_state,config_json,secret_blob,created,updated) VALUES ('"
|
||||
.pwg_db_real_escape_string($connection_key)."','"
|
||||
.pwg_db_real_escape_string($name)."','remote',0,'disabled','"
|
||||
@@ -114,20 +162,18 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||
.pwg_db_real_escape_string($now)."')");
|
||||
|
||||
$id = (int)pwg_db_insert_id();
|
||||
if ($id < 1) throw new RuntimeException('Die WebDAV-Testverbindung konnte nicht eindeutig angelegt werden.');
|
||||
if ($id < 1) throw new RuntimeException('Die WebDAV-Verbindung konnte nicht eindeutig angelegt werden.');
|
||||
|
||||
$config['state_dir'] = '/var/lib/bratonien-tools/nc-connector/connection-'.$id;
|
||||
$config['status_file'] = $config['state_dir'].'/connector-status.json';
|
||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (!is_string($config_json))
|
||||
{
|
||||
pwg_query("DELETE FROM `$table` WHERE id=".$id." LIMIT 1");
|
||||
throw new RuntimeException('Die WebDAV-Testverbindung konnte nach dem Anlegen nicht serialisiert werden.');
|
||||
}
|
||||
pwg_query("UPDATE `$table` SET config_json='".pwg_db_real_escape_string($config_json)."' WHERE id=".$id." LIMIT 1");
|
||||
if (!is_string($config_json)) throw new RuntimeException('WebDAV-Konfiguration konnte nach dem Anlegen nicht serialisiert werden.');
|
||||
pwg_query("UPDATE `$table` SET config_json='".pwg_db_real_escape_string($config_json)."' WHERE id=".$id." AND adapter='remote' LIMIT 1");
|
||||
|
||||
unset($_SESSION['bratonien_nc_wizard']);
|
||||
|
||||
return array(
|
||||
'connection_id'=>$id,
|
||||
'message'=>'Parallele WebDAV-Testverbindung wurde deaktiviert angelegt. Bestehende Verbindungen blieben unverändert.',
|
||||
'message'=>'WebDAV-Verbindung wurde angelegt.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function bratonien_tools_nc_wizard_scan_webdav_first()
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = bratonien_tools_nc_wizard_http($candidate_url.'/status.php');
|
||||
$response = bratonien_tools_nc_transport_http($candidate_url.'/status.php');
|
||||
if ($response['status'] < 200 || $response['status'] >= 300) continue;
|
||||
$candidate_status = json_decode($response['body'], true);
|
||||
if (!is_array($candidate_status) || empty($candidate_status['installed'])) continue;
|
||||
@@ -44,7 +44,7 @@ function bratonien_tools_nc_wizard_scan_webdav_first()
|
||||
throw new RuntimeException('Unter dieser Adresse konnte keine Nextcloud erreicht werden. HTTP und HTTPS wurden automatisch geprüft.');
|
||||
}
|
||||
|
||||
$user_response = bratonien_tools_nc_wizard_http(
|
||||
$user_response = bratonien_tools_nc_transport_http(
|
||||
$base_url.'/ocs/v2.php/cloud/user?format=json',
|
||||
$username,
|
||||
$password,
|
||||
@@ -104,7 +104,7 @@ function bratonien_tools_nc_wizard_scan_webdav_first()
|
||||
'api_error'=>'',
|
||||
));
|
||||
|
||||
bratonien_tools_nc_wizard_refresh_directory_state($state, '');
|
||||
bratonien_tools_nc_transport_refresh_directory_state($state, '');
|
||||
bratonien_tools_nc_wizard_store($state);
|
||||
|
||||
return array('message'=>'Nextcloud und WebDAV wurden bestätigt. Jetzt können die Verzeichnisse des angemeldeten Benutzers ausgewählt werden.');
|
||||
@@ -126,7 +126,6 @@ function bratonien_tools_nc_wizard_save_sources_dispatch()
|
||||
$selected = isset($state['directory_selected']) && is_array($state['directory_selected'])
|
||||
? array_values(array_unique(array_map(function($path) { return trim((string)$path, '/'); }, $state['directory_selected'])))
|
||||
: array();
|
||||
$selected = array_values(array_filter($selected, function($path) { return $path !== ''; }));
|
||||
if (!$selected)
|
||||
{
|
||||
throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis auswählen.');
|
||||
@@ -143,9 +142,12 @@ function bratonien_tools_nc_wizard_save_sources_dispatch()
|
||||
{
|
||||
throw new RuntimeException('Für eine Auswahl fehlt die eindeutige Nextcloud-Datei-ID. Bitte das Verzeichnis erneut auswählen.');
|
||||
}
|
||||
$display_name = $path === ''
|
||||
? (trim((string)($state['display_name'] ?? '')) !== '' ? trim((string)$state['display_name']) : (string)$state['username'])
|
||||
: basename($path);
|
||||
$roots[] = array(
|
||||
'fileid'=>$fileid,
|
||||
'display_name'=>basename($path),
|
||||
'display_name'=>$display_name,
|
||||
'webdav_path'=>$path,
|
||||
);
|
||||
}
|
||||
@@ -156,9 +158,35 @@ function bratonien_tools_nc_wizard_save_sources_dispatch()
|
||||
$state['technical_source'] = 'WebDAV-Verzeichnisse ausgewählt';
|
||||
$state['technical_error'] = '';
|
||||
$state['directory_selection_ready'] = false;
|
||||
bratonien_tools_nc_wizard_store($state);
|
||||
|
||||
return array('message'=>'WebDAV-Verzeichnisse wurden übernommen. Die Verbindung ist für den parallelen Testweg vorbereitet.');
|
||||
if ((string)($state['editing_mode'] ?? '') === 'migrate')
|
||||
{
|
||||
$editing_id = (int)($state['editing_connection_id'] ?? 0);
|
||||
$connection = $editing_id > 0 ? bratonien_tools_nc_connector_connection($editing_id, true) : null;
|
||||
if (!$connection || (string)$connection['adapter'] !== 'local')
|
||||
{
|
||||
throw new RuntimeException('Die zu migrierende Legacy-Verbindung ist nicht mehr verfügbar.');
|
||||
}
|
||||
|
||||
$migration = bratonien_tools_nc_connector_migration_state($connection);
|
||||
if (empty($migration['ready']))
|
||||
{
|
||||
throw new RuntimeException('Die WebDAV-Migration kann noch nicht abgeschlossen werden. Es fehlen: '.implode(', ', $migration['missing']).'.');
|
||||
}
|
||||
|
||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||
$state['_api_key_id'] = (string)($credentials['api_key_id'] ?? '');
|
||||
$state['_api_key_secret'] = (string)($credentials['api_key_secret'] ?? '');
|
||||
$state['api_status'] = !empty($migration['api_available']) ? 'ok' : 'skipped';
|
||||
$state['api_error'] = '';
|
||||
$state['step'] = 4;
|
||||
bratonien_tools_nc_wizard_store($state);
|
||||
|
||||
return array('message'=>'WebDAV-Quelle wurde übernommen. Mit „Migration starten“ wird jetzt der WebDAV-Nachfolger angelegt; die Legacy-Verbindung bleibt als Fallback erhalten.');
|
||||
}
|
||||
|
||||
bratonien_tools_nc_wizard_store($state);
|
||||
return array('message'=>'WebDAV-Verzeichnisse wurden übernommen. Die Verbindung ist für den nächsten Einrichtungsschritt vorbereitet.');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_wizard_finish_dispatch()
|
||||
|
||||
340
include/nc_transport.inc.php
Normal file
340
include/nc_transport.inc.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
function bratonien_tools_nc_transport_host($url)
|
||||
{
|
||||
$host = trim((string)parse_url((string)$url, PHP_URL_HOST));
|
||||
if ($host === '') throw new RuntimeException('Die Nextcloud-Adresse enthält keinen gültigen Hostnamen oder keine IP-Adresse.');
|
||||
return trim($host, '[]');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_scheme($url)
|
||||
{
|
||||
$scheme = strtolower(trim((string)parse_url((string)$url, PHP_URL_SCHEME)));
|
||||
if (!in_array($scheme, array('http','https'), true)) throw new RuntimeException('Nextcloud muss per HTTP oder HTTPS angesprochen werden.');
|
||||
return $scheme;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_is_ip($host)
|
||||
{
|
||||
return filter_var(trim((string)$host, '[]'), FILTER_VALIDATE_IP) !== false;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_public_ip($host)
|
||||
{
|
||||
static $cache = array();
|
||||
|
||||
$host = strtolower(trim((string)$host, '[]'));
|
||||
if ($host === '') throw new RuntimeException('Für die Nextcloud-Verbindung fehlt der Hostname.');
|
||||
if (bratonien_tools_nc_transport_is_ip($host)) return $host;
|
||||
if (isset($cache[$host])) return $cache[$host];
|
||||
if (!function_exists('curl_init')) throw new RuntimeException('Der öffentliche DNS-Abgleich benötigt PHP-cURL.');
|
||||
|
||||
$providers = array(
|
||||
array('host'=>'dns.google', 'ips'=>array('8.8.8.8','8.8.4.4'), 'url'=>'https://dns.google/resolve?name='.rawurlencode($host).'&type=A'),
|
||||
array('host'=>'cloudflare-dns.com', 'ips'=>array('1.1.1.1','1.0.0.1'), 'url'=>'https://cloudflare-dns.com/dns-query?name='.rawurlencode($host).'&type=A'),
|
||||
);
|
||||
|
||||
foreach ($providers as $provider)
|
||||
{
|
||||
foreach ($provider['ips'] as $resolver_ip)
|
||||
{
|
||||
$ch = curl_init($provider['url']);
|
||||
$options = array(
|
||||
CURLOPT_RETURNTRANSFER=>true,
|
||||
CURLOPT_FOLLOWLOCATION=>false,
|
||||
CURLOPT_CONNECTTIMEOUT=>5,
|
||||
CURLOPT_TIMEOUT=>10,
|
||||
CURLOPT_HTTPHEADER=>array('Accept: application/dns-json'),
|
||||
CURLOPT_USERAGENT=>'Bratonien-Tools-DNS/0.9.7.1',
|
||||
);
|
||||
if (defined('CURLOPT_RESOLVE'))
|
||||
{
|
||||
$options[CURLOPT_RESOLVE] = array($provider['host'].':443:'.$resolver_ip);
|
||||
}
|
||||
curl_setopt_array($ch, $options);
|
||||
$body = curl_exec($ch);
|
||||
$errno = curl_errno($ch);
|
||||
$status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($body === false || $errno !== 0 || $status < 200 || $status >= 300) continue;
|
||||
|
||||
$decoded = json_decode((string)$body, true);
|
||||
if (!is_array($decoded) || !isset($decoded['Answer']) || !is_array($decoded['Answer'])) continue;
|
||||
foreach ($decoded['Answer'] as $answer)
|
||||
{
|
||||
if ((int)($answer['type'] ?? 0) !== 1) continue;
|
||||
$ip = trim((string)($answer['data'] ?? ''));
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) continue;
|
||||
return $cache[$host] = $ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException('Für '.$host.' konnte keine öffentliche IPv4-Adresse ermittelt werden.');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_resolve_entry($url)
|
||||
{
|
||||
$scheme = bratonien_tools_nc_transport_scheme($url);
|
||||
$host = bratonien_tools_nc_transport_host($url);
|
||||
if (bratonien_tools_nc_transport_is_ip($host)) return null;
|
||||
|
||||
$port = (int)parse_url((string)$url, PHP_URL_PORT);
|
||||
if ($port < 1) $port = $scheme === 'https' ? 443 : 80;
|
||||
$ip = bratonien_tools_nc_transport_public_ip($host);
|
||||
return $host.':'.$port.':'.$ip;
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_apply_curl(array &$options, $url)
|
||||
{
|
||||
$entry = bratonien_tools_nc_transport_resolve_entry($url);
|
||||
if ($entry !== null)
|
||||
{
|
||||
if (!defined('CURLOPT_RESOLVE')) throw new RuntimeException('Diese cURL-Version unterstützt keine direkte Host-zu-IP-Zuordnung.');
|
||||
$options[CURLOPT_RESOLVE] = array($entry);
|
||||
}
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_http($url, $username = '', $password = '', array $headers = array())
|
||||
{
|
||||
if (!function_exists('curl_init')) throw new RuntimeException('Der Server kann Nextcloud derzeit nicht per HTTP prüfen.');
|
||||
|
||||
$ch = curl_init($url);
|
||||
$options = array(
|
||||
CURLOPT_RETURNTRANSFER=>true,
|
||||
CURLOPT_FOLLOWLOCATION=>true,
|
||||
CURLOPT_MAXREDIRS=>3,
|
||||
CURLOPT_CONNECTTIMEOUT=>8,
|
||||
CURLOPT_TIMEOUT=>15,
|
||||
CURLOPT_HTTPHEADER=>array_merge(array('Accept: application/json'), $headers),
|
||||
CURLOPT_USERAGENT=>'Bratonien-Tools-NC-Wizard/0.9.7.1',
|
||||
);
|
||||
bratonien_tools_nc_transport_apply_curl($options, $url);
|
||||
|
||||
if ($username !== '')
|
||||
{
|
||||
$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
|
||||
$options[CURLOPT_USERPWD] = $username.':'.$password;
|
||||
}
|
||||
|
||||
curl_setopt_array($ch, $options);
|
||||
$body = curl_exec($ch);
|
||||
$errno = curl_errno($ch);
|
||||
$error = curl_error($ch);
|
||||
$status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($body === false || $errno !== 0)
|
||||
{
|
||||
throw new RuntimeException('Verbindung fehlgeschlagen'.($error !== '' ? ': '.$error : '.'));
|
||||
}
|
||||
|
||||
return array('status'=>$status, 'body'=>(string)$body);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_webdav_list(array $state, $path = '')
|
||||
{
|
||||
if (empty($state['scan_ok']) || trim((string)$state['base_url']) === '' || trim((string)$state['username']) === '' || (string)$state['_password'] === '')
|
||||
{
|
||||
throw new RuntimeException('Die Nextcloud-Sitzung des Assistenten ist nicht vollständig.');
|
||||
}
|
||||
if (!function_exists('curl_init')) throw new RuntimeException('cURL ist für die Verzeichnisauswahl nicht verfügbar.');
|
||||
|
||||
$path = trim((string)$path, '/');
|
||||
if ($path !== '' && preg_match('#(^|/)\.\.(/|$)#', $path)) throw new RuntimeException('Ungültiger Verzeichnispfad.');
|
||||
|
||||
$segments = $path === '' ? array() : array_map('rawurlencode', explode('/', $path));
|
||||
$user = rawurlencode((string)$state['username']);
|
||||
$url = rtrim((string)$state['base_url'], '/').'/remote.php/dav/files/'.$user.'/'.implode('/', $segments);
|
||||
if (substr($url, -1) !== '/') $url .= '/';
|
||||
|
||||
$body = '<?xml version="1.0"?><d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"><d:prop><d:resourcetype/><d:displayname/><oc:fileid/></d:prop></d:propfind>';
|
||||
$ch = curl_init($url);
|
||||
$options = array(
|
||||
CURLOPT_RETURNTRANSFER=>true,
|
||||
CURLOPT_CUSTOMREQUEST=>'PROPFIND',
|
||||
CURLOPT_POSTFIELDS=>$body,
|
||||
CURLOPT_HTTPHEADER=>array('Depth: 1','Content-Type: application/xml; charset=utf-8'),
|
||||
CURLOPT_HTTPAUTH=>CURLAUTH_BASIC,
|
||||
CURLOPT_USERPWD=>(string)$state['username'].':'.(string)$state['_password'],
|
||||
CURLOPT_CONNECTTIMEOUT=>8,
|
||||
CURLOPT_TIMEOUT=>20,
|
||||
);
|
||||
bratonien_tools_nc_transport_apply_curl($options, $url);
|
||||
curl_setopt_array($ch, $options);
|
||||
$response = curl_exec($ch);
|
||||
$errno = curl_errno($ch);
|
||||
$error = curl_error($ch);
|
||||
$status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response === false || $errno !== 0) throw new RuntimeException('Nextcloud-Verzeichnisse konnten nicht geladen werden'.($error !== '' ? ': '.$error : '.'));
|
||||
if ($status === 401 || $status === 403) throw new RuntimeException('Nextcloud hat den Zugriff auf dieses Verzeichnis abgelehnt.');
|
||||
if ($status !== 207) throw new RuntimeException('Nextcloud-Verzeichnisabfrage antwortete mit HTTP '.$status.'.');
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
$xml = simplexml_load_string((string)$response);
|
||||
if ($xml === false) throw new RuntimeException('Nextcloud hat eine ungültige WebDAV-Antwort geliefert.');
|
||||
$xml->registerXPathNamespace('d', 'DAV:');
|
||||
$xml->registerXPathNamespace('oc', 'http://owncloud.org/ns');
|
||||
|
||||
$children = array();
|
||||
$fileids = array();
|
||||
$current_fileid = 0;
|
||||
$base_path = (string)parse_url($url, PHP_URL_PATH);
|
||||
|
||||
foreach ($xml->xpath('//d:response') as $item)
|
||||
{
|
||||
$item->registerXPathNamespace('d', 'DAV:');
|
||||
$item->registerXPathNamespace('oc', 'http://owncloud.org/ns');
|
||||
$hrefs = $item->xpath('d:href');
|
||||
$collections = $item->xpath('d:propstat/d:prop/d:resourcetype/d:collection');
|
||||
$ids = $item->xpath('d:propstat/d:prop/oc:fileid');
|
||||
if (!$hrefs || !$collections || !$ids) continue;
|
||||
|
||||
$fileid = (int)trim((string)$ids[0]);
|
||||
if ($fileid < 1) continue;
|
||||
$href = rawurldecode((string)$hrefs[0]);
|
||||
$href_path = (string)parse_url($href, PHP_URL_PATH);
|
||||
|
||||
if (rtrim($href_path, '/') === rtrim($base_path, '/'))
|
||||
{
|
||||
$current_fileid = $fileid;
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = basename(rtrim($href_path, '/'));
|
||||
if ($name === '') continue;
|
||||
$child_path = $path === '' ? $name : $path.'/'.$name;
|
||||
$children[$child_path] = $name;
|
||||
$fileids[$child_path] = $fileid;
|
||||
}
|
||||
natcasesort($children);
|
||||
|
||||
if ($current_fileid < 1) throw new RuntimeException('Nextcloud hat für das aktuelle Verzeichnis keine eindeutige Datei-ID geliefert.');
|
||||
|
||||
$parent = '';
|
||||
if ($path !== '')
|
||||
{
|
||||
$parts = explode('/', $path);
|
||||
array_pop($parts);
|
||||
$parent = implode('/', $parts);
|
||||
}
|
||||
|
||||
return array(
|
||||
'current'=>$path,
|
||||
'parent'=>$parent,
|
||||
'children'=>$children,
|
||||
'current_fileid'=>$current_fileid,
|
||||
'fileids'=>$fileids,
|
||||
);
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_refresh_directory_state(array &$state, $path = null)
|
||||
{
|
||||
if ($path === null) $path = (string)($state['directory_path'] ?? '');
|
||||
$listing = bratonien_tools_nc_transport_webdav_list($state, $path);
|
||||
$state['directory_path'] = (string)$listing['current'];
|
||||
$state['directory_parent'] = (string)$listing['parent'];
|
||||
$state['directory_children'] = (array)$listing['children'];
|
||||
$state['directory_current_fileid'] = (int)$listing['current_fileid'];
|
||||
$state['directory_fileids'] = (array)$listing['fileids'];
|
||||
if (!isset($state['directory_selected']) || !is_array($state['directory_selected'])) $state['directory_selected'] = array();
|
||||
if (!isset($state['directory_selected_fileids']) || !is_array($state['directory_selected_fileids'])) $state['directory_selected_fileids'] = array();
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_wizard_directory_browse()
|
||||
{
|
||||
$state = bratonien_tools_nc_wizard_state();
|
||||
if ((int)$state['step'] !== 2 || (string)$state['technical_stage'] !== 'mounts' || empty($state['directory_selection_ready'])) throw new RuntimeException('Die Verzeichnisauswahl ist in diesem Fenster nicht verfügbar.');
|
||||
$path = trim((string)($_POST['nc_wizard_directory_path'] ?? ''), '/');
|
||||
bratonien_tools_nc_transport_refresh_directory_state($state, $path);
|
||||
bratonien_tools_nc_wizard_store($state);
|
||||
return array('message'=>'Verzeichnis geöffnet.');
|
||||
}
|
||||
|
||||
function bratonien_tools_nc_transport_edit_start()
|
||||
{
|
||||
$id = (int)($_POST['connection_id'] ?? 0);
|
||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||
|
||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||
$is_webdav = (string)$connection['adapter'] === 'remote'
|
||||
&& (string)($config['source_mode'] ?? '') === 'webdav-placeholder';
|
||||
if (!$is_webdav) return bratonien_tools_nc_connector_edit_start();
|
||||
|
||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||
$base_url = trim((string)($config['nextcloud_url'] ?? ''));
|
||||
$username = trim((string)($credentials['nextcloud_user'] ?? ''));
|
||||
if ($username === '') $username = trim((string)($config['nextcloud_access_user'] ?? $config['access_user'] ?? ''));
|
||||
$password = (string)($credentials['nextcloud_password'] ?? '');
|
||||
|
||||
$roots = isset($config['roots']) && is_array($config['roots']) ? array_values($config['roots']) : array();
|
||||
$selected = array();
|
||||
$selected_ids = array();
|
||||
foreach ($roots as $root)
|
||||
{
|
||||
$path = trim((string)($root['webdav_path'] ?? ''), '/');
|
||||
$fileid = (int)($root['fileid'] ?? 0);
|
||||
if ($fileid < 1) continue;
|
||||
$selected[] = $path;
|
||||
$selected_ids[$path] = $fileid;
|
||||
}
|
||||
|
||||
$state = bratonien_tools_nc_wizard_state();
|
||||
$state = array_merge($state, array(
|
||||
'editing_connection_id'=>$id,
|
||||
'editing_adapter'=>(string)$connection['adapter'],
|
||||
'editing_mode'=>'update',
|
||||
'connection_name'=>(string)$connection['name'],
|
||||
'host_input'=>$base_url,
|
||||
'base_url'=>$base_url,
|
||||
'username'=>$username,
|
||||
'_password'=>$password,
|
||||
'_fallback_user'=>(string)($credentials['piwigo_user'] ?? ''),
|
||||
'_fallback_password'=>(string)($credentials['piwigo_password'] ?? ''),
|
||||
'_api_key_id'=>(string)($credentials['api_key_id'] ?? ''),
|
||||
'_api_key_secret'=>(string)($credentials['api_key_secret'] ?? ''),
|
||||
'api_status'=>trim((string)($credentials['api_key_id'] ?? '')) !== '' && trim((string)($credentials['api_key_secret'] ?? '')) !== '' ? 'ok' : 'pending',
|
||||
'roots'=>$roots,
|
||||
'directory_selected'=>$selected,
|
||||
'directory_selected_fileids'=>$selected_ids,
|
||||
'source_mode'=>'webdav-placeholder',
|
||||
'transport'=>'webdav',
|
||||
));
|
||||
|
||||
if ($base_url !== '' && $username !== '' && $password !== '')
|
||||
{
|
||||
$state['step'] = 2;
|
||||
$state['scan_ok'] = true;
|
||||
$state['technical_stage'] = 'mounts';
|
||||
$state['technical_source'] = 'WebDAV';
|
||||
$state['technical_error'] = '';
|
||||
$state['technical_complete'] = false;
|
||||
$state['directory_selection_ready'] = true;
|
||||
$state['directory_path'] = '';
|
||||
$state['directory_parent'] = '';
|
||||
$state['directory_children'] = array();
|
||||
$state['directory_current_fileid'] = 0;
|
||||
|
||||
try
|
||||
{
|
||||
bratonien_tools_nc_transport_refresh_directory_state($state, '');
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$state['step'] = 1;
|
||||
$state['scan_ok'] = false;
|
||||
$state['technical_error'] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$state['step'] = 1;
|
||||
$state['scan_ok'] = false;
|
||||
}
|
||||
|
||||
bratonien_tools_nc_wizard_store($state);
|
||||
return array('message'=>'Verbindung #'.$id.' wurde zum Bearbeiten geöffnet.');
|
||||
}
|
||||
@@ -4,6 +4,17 @@ if (!defined('PHPWG_ROOT_PATH'))
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
|
||||
if (isset($GLOBALS['template']) && is_object($GLOBALS['template']) && method_exists($GLOBALS['template'], 'func_combine_script'))
|
||||
{
|
||||
$script_version = function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : '0.9.7.1';
|
||||
$GLOBALS['template']->func_combine_script(array(
|
||||
'id'=>'bratonien_nc_connector_edit_v2',
|
||||
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_edit_v2.js',
|
||||
'load'=>'footer',
|
||||
'version'=>$script_version,
|
||||
));
|
||||
}
|
||||
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'tools/image_cache.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'tools/watermark.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'tools/watermark_profiles.inc.php');
|
||||
@@ -17,7 +28,6 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/album_shares.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/album_lock.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_manage.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_takeover.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_auth.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_create_api.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_piwigo_api.inc.php');
|
||||
@@ -30,6 +40,25 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_generic_scope.inc.php'
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_delete_safe.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_webdav.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_wizard_webdav_flow.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_edit.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_transport.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_scheduler.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_system.inc.php');
|
||||
|
||||
function bratonien_tools_nc_connector_run_now()
|
||||
{
|
||||
$connection_id = isset($_POST['connection_id']) ? max(0, (int)$_POST['connection_id']) : 0;
|
||||
if ($connection_id > 0)
|
||||
{
|
||||
$connection = bratonien_tools_nc_connector_connection($connection_id, false);
|
||||
if (!$connection)
|
||||
{
|
||||
throw new RuntimeException('Die ausgewählte Verbindung existiert nicht.');
|
||||
}
|
||||
}
|
||||
$result = bratonien_tools_nc_scheduler_spawn(true, $connection_id);
|
||||
return array('message'=>(string)($result['message'] ?? ($connection_id > 0 ? 'Abgleich wurde gestartet.' : 'Abgleich für alle Verbindungen wurde gestartet.')));
|
||||
}
|
||||
|
||||
function bratonien_tools_get_tools()
|
||||
{
|
||||
@@ -54,14 +83,16 @@ function bratonien_tools_get_tools()
|
||||
'album_share_create' => array('handler' => 'bratonien_tools_create_album_share'),
|
||||
'album_share_regenerate_link' => array('handler' => 'bratonien_tools_regenerate_album_share_link'),
|
||||
'album_share_revoke' => array('handler' => 'bratonien_tools_revoke_album_share'),
|
||||
'nc_connector_create_local' => array('handler' => 'bratonien_tools_nc_connector_create_local_api_first'),
|
||||
'nc_connector_create_webdav_parallel' => array('handler' => 'bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard'),
|
||||
'nc_connector_edit_start' => array('handler' => 'bratonien_tools_nc_transport_edit_start'),
|
||||
'nc_connector_update_local' => array('handler' => 'bratonien_tools_nc_connector_update_local_friendly'),
|
||||
'nc_connector_delete' => array('handler' => 'bratonien_tools_nc_connector_delete_safe'),
|
||||
'nc_connector_update_name' => array('handler' => 'bratonien_tools_nc_connector_update_name'),
|
||||
'nc_connector_update_technical' => array('handler' => 'bratonien_tools_nc_connector_update_technical'),
|
||||
'nc_connector_run_now' => array('handler' => 'bratonien_tools_nc_connector_run_now'),
|
||||
'nc_connector_wizard_scan' => array('handler' => 'bratonien_tools_nc_wizard_scan_webdav_first'),
|
||||
'nc_connector_wizard_save_technical' => array('handler' => 'bratonien_tools_nc_wizard_save_technical_flow'),
|
||||
'nc_connector_wizard_directory_browse' => array('handler' => 'bratonien_tools_nc_wizard_directory_browse'),
|
||||
'nc_connector_wizard_directory_browse' => array('handler' => 'bratonien_tools_nc_transport_wizard_directory_browse'),
|
||||
'nc_connector_wizard_directory_add' => array('handler' => 'bratonien_tools_nc_wizard_directory_add'),
|
||||
'nc_connector_wizard_directory_remove' => array('handler' => 'bratonien_tools_nc_wizard_directory_remove'),
|
||||
'nc_connector_wizard_save_mounts' => array('handler' => 'bratonien_tools_nc_wizard_save_sources_dispatch'),
|
||||
@@ -71,10 +102,7 @@ function bratonien_tools_get_tools()
|
||||
'nc_connector_wizard_finish' => array('handler' => 'bratonien_tools_nc_wizard_finish_dispatch'),
|
||||
'nc_connector_wizard_back' => array('handler' => 'bratonien_tools_nc_wizard_back'),
|
||||
'nc_connector_wizard_reset' => array('handler' => 'bratonien_tools_nc_wizard_reset'),
|
||||
'nc_connector_import_legacy' => array('handler' => 'bratonien_tools_nc_connector_import_legacy'),
|
||||
'nc_connector_verify' => array('handler' => 'bratonien_tools_nc_connector_verify_connection_scoped'),
|
||||
'nc_connector_prepare_takeover' => array('handler' => 'bratonien_tools_nc_connector_prepare_takeover'),
|
||||
'nc_connector_cancel_takeover' => array('handler' => 'bratonien_tools_nc_connector_cancel_takeover'),
|
||||
'nc_connector_piwigo_api_test' => array('handler' => 'bratonien_tools_nc_connector_piwigo_api_test'),
|
||||
'nc_connector_piwigo_api_delete' => array('handler' => 'bratonien_tools_nc_connector_api_delete'),
|
||||
'nc_connector_fallback_save' => array('handler' => 'bratonien_tools_nc_connector_fallback_save_scoped'),
|
||||
|
||||
@@ -8,8 +8,17 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/watermark_base.inc.php');
|
||||
|
||||
function bratonien_tools_watermark_engine_enabled()
|
||||
{
|
||||
static $initialized = false;
|
||||
static $enabled = false;
|
||||
|
||||
if ($initialized)
|
||||
{
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
$config = bratonien_tools_get_watermark_engine_config();
|
||||
$enabled = !empty($config['enabled']);
|
||||
$initialized = true;
|
||||
|
||||
// Piwigo recalculates use_watermark for custom derivatives from the native
|
||||
// watermark file itself. Therefore an active Bratonien engine must keep the
|
||||
|
||||
59
js/nc_connector_edit_v2.js
Normal file
59
js/nc_connector_edit_v2.js
Normal file
@@ -0,0 +1,59 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function restoreRunNowButtons() {
|
||||
var section = document.getElementById('nc-connector');
|
||||
if (!section) return;
|
||||
|
||||
var connectionCard = null;
|
||||
var headings = section.querySelectorAll('h4');
|
||||
for (var i = 0; i < headings.length; i++) {
|
||||
if ((headings[i].textContent || '').trim() === 'Bestehende Verbindungen') {
|
||||
connectionCard = headings[i].closest('.bratonien-card');
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!connectionCard) return;
|
||||
|
||||
var details = connectionCard.querySelectorAll(':scope > details');
|
||||
details.forEach(function (detail) {
|
||||
var actions = detail.querySelector('.bratonien-actions');
|
||||
if (!actions || actions.querySelector('[value="nc_connector_run_now"]')) return;
|
||||
|
||||
var connectionInput = detail.querySelector('input[name="connection_id"]');
|
||||
var tokenInput = detail.querySelector('input[name="pwg_token"]');
|
||||
if (!connectionInput || !tokenInput) return;
|
||||
|
||||
var form = document.createElement('form');
|
||||
form.method = 'post';
|
||||
|
||||
var token = document.createElement('input');
|
||||
token.type = 'hidden';
|
||||
token.name = 'pwg_token';
|
||||
token.value = tokenInput.value;
|
||||
form.appendChild(token);
|
||||
|
||||
var connection = document.createElement('input');
|
||||
connection.type = 'hidden';
|
||||
connection.name = 'connection_id';
|
||||
connection.value = connectionInput.value;
|
||||
form.appendChild(connection);
|
||||
|
||||
var button = document.createElement('button');
|
||||
button.className = 'buttonLike';
|
||||
button.type = 'submit';
|
||||
button.name = 'bratonien_tool';
|
||||
button.value = 'nc_connector_run_now';
|
||||
button.textContent = 'Jetzt abgleichen';
|
||||
form.appendChild(button);
|
||||
|
||||
actions.insertBefore(form, actions.firstChild);
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', restoreRunNowButtons);
|
||||
} else {
|
||||
restoreRunNowButtons();
|
||||
}
|
||||
})();
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Bratonien Tools
|
||||
Version: 0.9.6.1
|
||||
Version: 0.9.7.20
|
||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||
Author: Bratonien
|
||||
@@ -24,6 +24,7 @@ require_once(BRATONIEN_TOOLS_PATH . 'include/album_shares.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_ws.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_orphan_ws.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_productive_ws.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_scheduler.inc.php');
|
||||
|
||||
add_event_handler('get_admin_plugin_menu_links', 'bratonien_tools_admin_menu');
|
||||
add_event_handler('get_derivative_url', 'bratonien_tools_filter_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL, 4);
|
||||
|
||||
@@ -8,6 +8,7 @@ require_once(dirname(__FILE__) . '/include/album_shares.inc.php');
|
||||
require_once(dirname(__FILE__) . '/include/database.class.php');
|
||||
require_once(dirname(__FILE__) . '/tools/watermark_profiles.inc.php');
|
||||
require_once(dirname(__FILE__) . '/include/dependencies.inc.php');
|
||||
require_once(dirname(__FILE__) . '/include/nc_connector_scheduler.inc.php');
|
||||
|
||||
class bratonien_tools_maintain extends PluginMaintain
|
||||
{
|
||||
@@ -18,9 +19,14 @@ class bratonien_tools_maintain extends PluginMaintain
|
||||
|
||||
$dependency_messages = array();
|
||||
bratonien_tools_ensure_dependencies($dependency_messages);
|
||||
if (!bratonien_tools_nc_scheduler_install())
|
||||
{
|
||||
$dependency_messages[] = 'Der native NC-Scheduler konnte sein Piwigo-Laufzeitverzeichnis nicht anlegen.';
|
||||
}
|
||||
|
||||
if (function_exists('conf_update_param'))
|
||||
{
|
||||
conf_update_param('bratonien_nc_scheduler_interval', 60);
|
||||
conf_update_param('bratonien_dependency_status', json_encode(array(
|
||||
'checked_at' => time(),
|
||||
'messages' => $dependency_messages,
|
||||
|
||||
@@ -36,6 +36,11 @@ $latest = array(
|
||||
'api'=>array('state'=>'not_run','message'=>''),
|
||||
'fallback'=>array('state'=>'not_run','message'=>''),
|
||||
'error_detail'=>'',
|
||||
'route'=>'',
|
||||
'route_label'=>'Noch kein Datenweg erfasst',
|
||||
'route_timestamp'=>0,
|
||||
'route_time_label'=>'Nicht verfügbar',
|
||||
'route_detail'=>'',
|
||||
);
|
||||
|
||||
if (is_dir($dir))
|
||||
@@ -57,6 +62,54 @@ if (is_dir($dir))
|
||||
$latest['connection_file'] = basename($file);
|
||||
}
|
||||
}
|
||||
|
||||
$route_file = $dir.'/route-status.json';
|
||||
if (is_readable($route_file))
|
||||
{
|
||||
$route = json_decode((string)@file_get_contents($route_file), true);
|
||||
if (is_array($route))
|
||||
{
|
||||
$route_name = (string)($route['route'] ?? '');
|
||||
$route_timestamp = (int)($route['timestamp'] ?? 0);
|
||||
$route_label = (string)($route['label'] ?? '');
|
||||
|
||||
if ($route_name === 'webdav')
|
||||
{
|
||||
$route_label = 'WEBDAV PRIMÄR';
|
||||
}
|
||||
elseif ($route_name === 'legacy_fallback')
|
||||
{
|
||||
$route_label = 'LEGACY-FALLBACK AKTIV';
|
||||
}
|
||||
elseif ($route_name === 'failed')
|
||||
{
|
||||
$route_label = 'FEHLER - KEIN ERFOLGREICHER DATENWEG';
|
||||
}
|
||||
elseif ($route_label === '')
|
||||
{
|
||||
$route_label = 'UNBEKANNTER DATENWEG';
|
||||
}
|
||||
|
||||
$route_detail = trim((string)($route['detail'] ?? ''));
|
||||
$latest['route'] = $route_name;
|
||||
$latest['route_label'] = $route_label;
|
||||
$latest['route_timestamp'] = $route_timestamp;
|
||||
$latest['route_time_label'] = $route_timestamp > 0 ? date('d.m.Y H:i:s', $route_timestamp) : 'Nicht verfügbar';
|
||||
$latest['route_detail'] = $route_detail;
|
||||
|
||||
$base_message = trim((string)($latest['message'] ?? ''));
|
||||
$message_parts = array($route_label);
|
||||
if ($route_name !== 'webdav' && $route_detail !== '')
|
||||
{
|
||||
$message_parts[] = $route_detail;
|
||||
}
|
||||
if ($base_message !== '')
|
||||
{
|
||||
$message_parts[] = $base_message;
|
||||
}
|
||||
$latest['message'] = implode(' · ', $message_parts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)$latest['timestamp'] > 0)
|
||||
|
||||
7
runtime/build-webdav-media.sh
Normal file
7
runtime/build-webdav-media.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
# Seit 0.9.7.20 greift der NC Connector nicht mehr in Piwigos Bild-/Derivatlogik ein.
|
||||
# Der Shadowtree dient nur der Piwigo-Synchronisation; die Bild-URL wird zur Laufzeit
|
||||
# ueber den bestehenden WebDAV-URL-Hook auf Nextcloud aufgeloest.
|
||||
exit 0
|
||||
142
runtime/cleanup-missing-webdav-images.php
Normal file
142
runtime/cleanup-missing-webdav-images.php
Normal file
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
if (PHP_SAPI !== 'cli')
|
||||
{
|
||||
fwrite(STDERR, "CLI only\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$options = getopt('', array('piwigo-root:', 'connection-id:'));
|
||||
$piwigo_root = rtrim((string)($options['piwigo-root'] ?? ''), '/');
|
||||
$connection_id = (int)($options['connection-id'] ?? 0);
|
||||
if ($piwigo_root === '' || $connection_id < 1)
|
||||
{
|
||||
fwrite(STDERR, "Parameter --piwigo-root und --connection-id werden benoetigt.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$db_config = $piwigo_root.'/local/config/database.inc.php';
|
||||
if (!is_readable($db_config))
|
||||
{
|
||||
fwrite(STDERR, "Piwigo-Datenbankkonfiguration ist nicht lesbar.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$conf = array();
|
||||
$prefixeTable = 'piwigo_';
|
||||
require $db_config;
|
||||
foreach (array('db_host','db_user','db_password','db_base') as $key)
|
||||
{
|
||||
if (!isset($conf[$key]))
|
||||
{
|
||||
fwrite(STDERR, "Piwigo-Datenbankkonfiguration ist unvollstaendig: $key\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
$db = new mysqli($conf['db_host'], $conf['db_user'], $conf['db_password'], $conf['db_base']);
|
||||
if ($db->connect_errno)
|
||||
{
|
||||
fwrite(STDERR, "Piwigo-Datenbank ist nicht erreichbar: ".$db->connect_error."\n");
|
||||
exit(1);
|
||||
}
|
||||
$db->set_charset('utf8mb4');
|
||||
|
||||
$table = $prefixeTable.'bratonien_tools_nc_connections';
|
||||
$result = $db->query('SELECT config_json FROM `'.$table.'` WHERE id='.$connection_id.' LIMIT 1');
|
||||
if (!$result || !$result->num_rows)
|
||||
{
|
||||
fwrite(STDERR, "Connector-Verbindung #$connection_id wurde nicht gefunden.\n");
|
||||
exit(1);
|
||||
}
|
||||
$config = json_decode((string)$result->fetch_assoc()['config_json'], true);
|
||||
if (!is_array($config) || (string)($config['source_mode'] ?? '') !== 'webdav-placeholder')
|
||||
{
|
||||
echo "Keine WebDAV-Bereinigung erforderlich.\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$prefixes = array(
|
||||
'./_data/bratonien-tools/nc-webdav-gallery/connection-'.$connection_id.'/',
|
||||
'./_data/bratonien-tools/nc-webdav-source/connection-'.$connection_id.'/',
|
||||
'./galleries/bratonien-webdav-'.$connection_id.'/',
|
||||
);
|
||||
|
||||
$gallery_root = rtrim(str_replace('\\', '/', (string)($config['parallel_gallery_root'] ?? '')), '/');
|
||||
$normalized_piwigo_root = rtrim(str_replace('\\', '/', $piwigo_root), '/');
|
||||
if ($gallery_root !== '' && strpos($gallery_root, $normalized_piwigo_root.'/') === 0)
|
||||
{
|
||||
$relative = ltrim(substr($gallery_root, strlen($normalized_piwigo_root)), '/');
|
||||
if ($relative !== '') $prefixes[] = './'.rtrim($relative, '/').'/';
|
||||
}
|
||||
$prefixes = array_values(array_unique($prefixes));
|
||||
|
||||
$where = array();
|
||||
foreach ($prefixes as $prefix)
|
||||
{
|
||||
$escaped = $db->real_escape_string(addcslashes($prefix, "_%\\"));
|
||||
$where[] = "path LIKE '{$escaped}%' ESCAPE '\\\\'";
|
||||
}
|
||||
|
||||
$images_table = $prefixeTable.'images';
|
||||
$rows = $db->query("SELECT id, path FROM `{$images_table}` WHERE ".implode(' OR ', $where));
|
||||
if (!$rows)
|
||||
{
|
||||
fwrite(STDERR, "Connector-Bilder konnten nicht gelesen werden: ".$db->error."\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$missing_ids = array();
|
||||
while ($row = $rows->fetch_assoc())
|
||||
{
|
||||
$path = (string)$row['path'];
|
||||
$owned = false;
|
||||
foreach ($prefixes as $prefix)
|
||||
{
|
||||
if (strpos($path, $prefix) === 0)
|
||||
{
|
||||
$owned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$owned) continue;
|
||||
|
||||
$absolute = $piwigo_root.'/'.ltrim(preg_replace('#^\./#', '', $path), '/');
|
||||
if (!is_file($absolute))
|
||||
{
|
||||
$missing_ids[] = (int)$row['id'];
|
||||
}
|
||||
}
|
||||
$db->close();
|
||||
|
||||
if (!$missing_ids)
|
||||
{
|
||||
echo "WebDAV-Bereinigung: keine fehlenden Piwigo-Bilder.\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Dieser Prozess wird ausschliesslich nach einem erfolgreich abgeschlossenen
|
||||
// WebDAV-Aufbau und erfolgreicher Piwigo-Synchronisierung gestartet. Eine
|
||||
// nicht erreichbare Verbindung kann deshalb niemals ueber diesen Pfad Bilder
|
||||
// entfernen.
|
||||
define('PHPWG_ROOT_PATH', $piwigo_root.'/');
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
$_SERVER['SERVER_PORT'] = '80';
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$_SERVER['REQUEST_URI'] = '/';
|
||||
$_SERVER['SCRIPT_NAME'] = '/plugins/bratonien_tools/runtime/cleanup-missing-webdav-images.php';
|
||||
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
|
||||
$_SERVER['QUERY_STRING'] = '';
|
||||
$_SERVER['HTTPS'] = 'off';
|
||||
|
||||
require_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
$deleted = delete_elements(array_values(array_unique(array_map('intval', $missing_ids))), false);
|
||||
update_category('all');
|
||||
invalidate_user_cache(true);
|
||||
|
||||
echo 'WebDAV-Bereinigung: '.(int)$deleted." nicht mehr freigegebene/vorhandene Bilder aus Piwigo entfernt.\n";
|
||||
@@ -47,24 +47,31 @@ function bratonien_cleanup_tree($path, $allowed_root)
|
||||
@rmdir($path);
|
||||
}
|
||||
|
||||
function bratonien_webdav_site_images($site_id)
|
||||
function bratonien_connection_id_from_owned_path($path)
|
||||
{
|
||||
$rows = array();
|
||||
$query = '
|
||||
SELECT DISTINCT i.id, i.path, i.representative_ext
|
||||
FROM '.IMAGES_TABLE.' AS i
|
||||
LEFT JOIN '.CATEGORIES_TABLE.' AS sc ON sc.id = i.storage_category_id
|
||||
LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
|
||||
LEFT JOIN '.CATEGORIES_TABLE.' AS vc ON vc.id = ic.category_id
|
||||
WHERE sc.site_id = '.(int)$site_id.' OR vc.site_id = '.(int)$site_id.'
|
||||
;';
|
||||
$result = pwg_query($query);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
$path = (string)$path;
|
||||
foreach (array(
|
||||
'#^\./_data/bratonien-tools/nc-webdav-gallery/connection-([0-9]+)/#',
|
||||
'#^\./_data/bratonien-tools/nc-webdav-source/connection-([0-9]+)/#',
|
||||
'#^\./galleries/bratonien-webdav-([0-9]+)/#',
|
||||
) as $pattern)
|
||||
{
|
||||
$row['id'] = (int)$row['id'];
|
||||
$rows[$row['id']] = $row;
|
||||
if (preg_match($pattern, $path, $match)) return (int)$match[1];
|
||||
}
|
||||
return $rows;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function bratonien_connection_id_from_site_url($url)
|
||||
{
|
||||
$url = (string)$url;
|
||||
foreach (array(
|
||||
'#^\./_data/bratonien-tools/nc-webdav-gallery/connection-([0-9]+)/$#',
|
||||
'#^\./galleries/bratonien-webdav-([0-9]+)/$#',
|
||||
) as $pattern)
|
||||
{
|
||||
if (preg_match($pattern, $url, $match)) return (int)$match[1];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -84,24 +91,24 @@ try
|
||||
}
|
||||
}
|
||||
|
||||
$site_prefix = './_data/bratonien-tools/nc-webdav-gallery/connection-';
|
||||
$result = pwg_query(
|
||||
"SELECT id, galleries_url FROM ".SITES_TABLE.
|
||||
" WHERE galleries_url LIKE '".pwg_db_real_escape_string($site_prefix)."%'"
|
||||
);
|
||||
|
||||
$removed_sites = 0;
|
||||
$removed_images = 0;
|
||||
while ($site = pwg_db_fetch_assoc($result))
|
||||
$stale_by_connection = array();
|
||||
$result = pwg_query(
|
||||
"SELECT id, path, representative_ext FROM ".IMAGES_TABLE.
|
||||
" WHERE path LIKE './_data/bratonien-tools/nc-webdav-gallery/connection-%'".
|
||||
" OR path LIKE './_data/bratonien-tools/nc-webdav-source/connection-%'".
|
||||
" OR path LIKE './galleries/bratonien-webdav-%'"
|
||||
);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$site_id = (int)$site['id'];
|
||||
$site_url = (string)$site['galleries_url'];
|
||||
if (!preg_match('#^\./_data/bratonien-tools/nc-webdav-gallery/connection-([0-9]+)/$#', $site_url, $match)) continue;
|
||||
|
||||
$connection_id = (int)$match[1];
|
||||
$connection_id = bratonien_connection_id_from_owned_path($row['path'] ?? '');
|
||||
if ($connection_id < 1 || isset($active[$connection_id])) continue;
|
||||
$row['id'] = (int)$row['id'];
|
||||
$stale_by_connection[$connection_id][$row['id']] = $row;
|
||||
}
|
||||
|
||||
$images = bratonien_webdav_site_images($site_id);
|
||||
foreach ($stale_by_connection as $connection_id=>$images)
|
||||
{
|
||||
foreach ($images as $row)
|
||||
{
|
||||
try
|
||||
@@ -114,48 +121,60 @@ try
|
||||
}
|
||||
}
|
||||
|
||||
delete_site($site_id);
|
||||
|
||||
if ($images)
|
||||
{
|
||||
$ids = array_keys($images);
|
||||
$remaining = query2array(
|
||||
'SELECT id FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', array_map('intval', $ids)).')',
|
||||
null,
|
||||
'id'
|
||||
);
|
||||
if ($remaining)
|
||||
{
|
||||
delete_elements(array_map('intval', $remaining), false);
|
||||
}
|
||||
}
|
||||
|
||||
$removed_sites++;
|
||||
delete_elements(array_map('intval', array_keys($images)), false);
|
||||
$removed_images += count($images);
|
||||
echo 'NC WebDAV: entferne verwaiste Piwigo-Site '.$site_id.' für gelöschte Verbindung '.$connection_id.".\n";
|
||||
echo 'NC WebDAV: entferne '.count($images).' verwaiste Bilder der gelöschten Verbindung '.$connection_id.".\n";
|
||||
}
|
||||
|
||||
$gallery_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-webdav-gallery';
|
||||
$source_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-webdav-source';
|
||||
$preview_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-webdav-preview';
|
||||
$removed_sites = 0;
|
||||
$result = pwg_query('SELECT id, galleries_url FROM '.SITES_TABLE);
|
||||
$stale_sites = array();
|
||||
while ($site = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$connection_id = bratonien_connection_id_from_site_url($site['galleries_url'] ?? '');
|
||||
if ($connection_id < 1 || isset($active[$connection_id])) continue;
|
||||
$stale_sites[] = array('id'=>(int)$site['id'], 'connection_id'=>$connection_id);
|
||||
}
|
||||
|
||||
foreach ($stale_sites as $site)
|
||||
{
|
||||
delete_site($site['id']);
|
||||
$removed_sites++;
|
||||
echo 'NC WebDAV: entferne verwaiste Piwigo-Site '.$site['id'].' der gelöschten Verbindung '.$site['connection_id'].".\n";
|
||||
}
|
||||
|
||||
$stale_connection_ids = array_unique(array_merge(
|
||||
array_map('intval', array_keys($stale_by_connection)),
|
||||
array_map(function($site) { return (int)$site['connection_id']; }, $stale_sites)
|
||||
));
|
||||
|
||||
$gallery_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-webdav-gallery';
|
||||
$source_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-webdav-source';
|
||||
$preview_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-webdav-preview';
|
||||
$legacy_root = PHPWG_ROOT_PATH.'galleries';
|
||||
$state_root = '/var/lib/bratonien-tools/nc-connector';
|
||||
$status_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-status';
|
||||
|
||||
foreach ($stale_connection_ids as $connection_id)
|
||||
{
|
||||
if ($connection_id < 1) continue;
|
||||
bratonien_cleanup_tree($gallery_root.'/connection-'.$connection_id, $gallery_root);
|
||||
bratonien_cleanup_tree($source_root.'/connection-'.$connection_id, $source_root);
|
||||
bratonien_cleanup_tree($preview_root.'/connection-'.$connection_id, $preview_root);
|
||||
|
||||
$state_root = '/var/lib/bratonien-tools/nc-connector';
|
||||
bratonien_cleanup_tree($legacy_root.'/bratonien-webdav-'.$connection_id, $legacy_root);
|
||||
bratonien_cleanup_tree($state_root.'/connection-'.$connection_id, $state_root);
|
||||
|
||||
foreach (glob('/etc/bratonien-tools/nc-connector/webdav-connection-'.$connection_id.'.*') ?: array() as $file)
|
||||
{
|
||||
@unlink($file);
|
||||
}
|
||||
|
||||
$status_root = PHPWG_ROOT_PATH.'_data/bratonien-tools/nc-connector-status';
|
||||
@unlink($status_root.'/connection-'.$connection_id.'.json');
|
||||
@unlink($status_root.'/deleted-'.$connection_id);
|
||||
}
|
||||
|
||||
if ($removed_sites > 0)
|
||||
if ($removed_sites > 0 || $removed_images > 0)
|
||||
{
|
||||
update_category('all');
|
||||
invalidate_user_cache(true);
|
||||
}
|
||||
|
||||
|
||||
0
runtime/lib/build-webdav-derivatives.php
Normal file → Executable file
0
runtime/lib/build-webdav-derivatives.php
Normal file → Executable file
92
runtime/lib/build_webdav_placeholder_source.py
Normal file → Executable file
92
runtime/lib/build_webdav_placeholder_source.py
Normal file → Executable file
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build a placeholder-backed local source tree from Nextcloud WebDAV.
|
||||
|
||||
This is intentionally additive: it does not replace the existing local-storage
|
||||
connector path. It creates only tiny placeholder files plus a metadata mapping;
|
||||
no Nextcloud original media is downloaded.
|
||||
This creates only tiny placeholder files plus a metadata mapping; no Nextcloud
|
||||
original media is downloaded. The authenticated Nextcloud user is never used as
|
||||
an album name.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -14,6 +14,7 @@ import getpass
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import ssl
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -21,13 +22,12 @@ import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import xml.etree.ElementTree as ET
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path, PurePosixPath
|
||||
|
||||
DAV = "DAV:"
|
||||
OC = "http://owncloud.org/ns"
|
||||
SUPPORTED_IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp"}
|
||||
# 1x1 transparent GIF, 34 bytes. The filename keeps the remote extension;
|
||||
# the placeholder exists only so Piwigo can discover the logical image entry.
|
||||
PLACEHOLDER = base64.b64decode("R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==")
|
||||
|
||||
|
||||
@@ -54,9 +54,37 @@ def safe_local_name(name: str) -> str:
|
||||
return name
|
||||
|
||||
|
||||
@contextmanager
|
||||
def pinned_resolution(host: str, ip: str):
|
||||
host = host.strip("[]").lower()
|
||||
ip = ip.strip("[]")
|
||||
if not host or not ip or host == ip:
|
||||
yield
|
||||
return
|
||||
|
||||
original = socket.getaddrinfo
|
||||
|
||||
def resolve(name, port, family=0, type=0, proto=0, flags=0):
|
||||
normalized = str(name).strip("[]").lower()
|
||||
if normalized == host:
|
||||
return original(ip, port, family, type, proto, flags)
|
||||
return original(name, port, family, type, proto, flags)
|
||||
|
||||
socket.getaddrinfo = resolve
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
socket.getaddrinfo = original
|
||||
|
||||
|
||||
class WebDavClient:
|
||||
def __init__(self, base_url: str, user: str, password: str, timeout: int = 30) -> None:
|
||||
def __init__(self, base_url: str, user: str, password: str, timeout: int = 30, connect_ip: str = "") -> None:
|
||||
self.base_url = base_url.rstrip("/")
|
||||
parsed = urllib.parse.urlparse(self.base_url)
|
||||
if parsed.scheme not in {"http", "https"} or not parsed.hostname:
|
||||
fail("Nextcloud base URL must use HTTP or HTTPS and contain a host")
|
||||
self.host = parsed.hostname.strip("[]")
|
||||
self.connect_ip = connect_ip.strip("[]") or self.host
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.timeout = timeout
|
||||
@@ -86,9 +114,10 @@ class WebDavClient:
|
||||
request.add_header("Depth", "1")
|
||||
request.add_header("Content-Type", "application/xml; charset=utf-8")
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=self.timeout, context=self.context) as response:
|
||||
status = response.status
|
||||
payload = response.read()
|
||||
with pinned_resolution(self.host, self.connect_ip):
|
||||
with urllib.request.urlopen(request, timeout=self.timeout, context=self.context) as response:
|
||||
status = response.status
|
||||
payload = response.read()
|
||||
except urllib.error.HTTPError as error:
|
||||
if error.code in {401, 403}:
|
||||
fail("Nextcloud rejected the WebDAV credentials or directory access")
|
||||
@@ -98,14 +127,14 @@ class WebDavClient:
|
||||
if status != 207:
|
||||
fail(f"Nextcloud PROPFIND returned HTTP {status}")
|
||||
|
||||
base_path = urllib.parse.unquote(urllib.parse.urlparse(url).path).rstrip("/")
|
||||
current: dict[str, object] | None = None
|
||||
children: list[dict[str, object]] = []
|
||||
try:
|
||||
root = ET.fromstring(payload)
|
||||
except ET.ParseError as error:
|
||||
raise RuntimeError("Nextcloud returned invalid WebDAV XML") from error
|
||||
|
||||
base_path = urllib.parse.unquote(urllib.parse.urlparse(url).path).rstrip("/")
|
||||
current: dict[str, object] | None = None
|
||||
children: list[dict[str, object]] = []
|
||||
for response in root.findall(f"{{{DAV}}}response"):
|
||||
href = response.findtext(f"{{{DAV}}}href", default="")
|
||||
href_path = urllib.parse.unquote(urllib.parse.urlparse(href).path).rstrip("/")
|
||||
@@ -148,13 +177,7 @@ def link_placeholder(seed: Path, target: Path) -> None:
|
||||
target.write_bytes(PLACEHOLDER)
|
||||
|
||||
|
||||
def build_root(
|
||||
client: WebDavClient,
|
||||
remote_root: str,
|
||||
local_root: Path,
|
||||
seed: Path,
|
||||
mapping: dict[str, dict[str, object]],
|
||||
) -> tuple[int, int, int]:
|
||||
def build_root(client: WebDavClient, remote_root: str, local_root: Path, seed: Path, mapping: dict[str, dict[str, object]]) -> tuple[int, int, int]:
|
||||
files = 0
|
||||
folders = 0
|
||||
skipped = 0
|
||||
@@ -221,6 +244,7 @@ def atomic_text(path: Path, text: str) -> None:
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--base-url", required=True)
|
||||
parser.add_argument("--connect-ip", default="", help="IP address used for the TCP connection while preserving the URL host for HTTP Host and TLS SNI")
|
||||
parser.add_argument("--user", required=True)
|
||||
parser.add_argument("--password-file", type=Path)
|
||||
parser.add_argument("--root", action="append", required=True, help="WebDAV path relative to the authenticated user's files root")
|
||||
@@ -249,26 +273,40 @@ def main() -> int:
|
||||
shutil.rmtree(staging)
|
||||
staging.mkdir(parents=True)
|
||||
|
||||
client = WebDavClient(args.base_url, args.user, password, max(1, args.timeout))
|
||||
client = WebDavClient(args.base_url, args.user, password, max(1, args.timeout), args.connect_ip)
|
||||
mapping: dict[str, dict[str, object]] = {}
|
||||
manifest: list[str] = []
|
||||
total_files = total_folders = total_skipped = 0
|
||||
used_names: set[str] = set()
|
||||
used_fileids: set[int] = set()
|
||||
|
||||
for remote_root_raw in args.root:
|
||||
remote_root = validate_relative(remote_root_raw)
|
||||
current, _ = client.list_collection(remote_root)
|
||||
current, root_children = client.list_collection(remote_root)
|
||||
fileid = int(current["fileid"])
|
||||
display = str(current.get("display_name", "")).strip() or (PurePosixPath(remote_root).name if remote_root else args.user)
|
||||
local_name = f"root-{fileid}"
|
||||
if local_name in used_names:
|
||||
if fileid in used_fileids:
|
||||
fail(f"duplicate selected Nextcloud root fileid: {fileid}")
|
||||
used_names.add(local_name)
|
||||
used_fileids.add(fileid)
|
||||
local_name = f"root-{fileid}"
|
||||
local_root = staging / local_name
|
||||
files, folders, skipped = build_root(client, remote_root, local_root, seed, mapping)
|
||||
total_files += files
|
||||
total_folders += folders
|
||||
total_skipped += skipped
|
||||
|
||||
if remote_root == "":
|
||||
for child in sorted(root_children, key=lambda item: str(item.get("display_name", "")).casefold()):
|
||||
name = safe_local_name(str(child.get("display_name", "")))
|
||||
child_fileid = int(child.get("fileid", 0))
|
||||
if child_fileid < 1:
|
||||
fail(f"Nextcloud returned no stable fileid for root child {name!r}")
|
||||
child_path = source_dir / local_name / name
|
||||
if bool(child.get("is_dir")):
|
||||
manifest.append(f"webdav:{child_fileid}\tfolder\t{name}\t{child_path}")
|
||||
elif Path(name).suffix.lower() in SUPPORTED_IMAGE_EXTENSIONS:
|
||||
manifest.append(f"webdav:{child_fileid}\tfile\t{name}\t{child_path}")
|
||||
continue
|
||||
|
||||
display = str(current.get("display_name", "")).strip() or PurePosixPath(remote_root).name
|
||||
manifest.append(f"webdav:{fileid}\tfolder\t{display}\t{source_dir / local_name}")
|
||||
|
||||
if previous.exists():
|
||||
@@ -297,6 +335,7 @@ def main() -> int:
|
||||
atomic_json(args.mapping, {
|
||||
"version": 1,
|
||||
"base_url": args.base_url.rstrip("/"),
|
||||
"connect_ip": client.connect_ip,
|
||||
"user": args.user,
|
||||
"files": final_mapping,
|
||||
})
|
||||
@@ -305,6 +344,7 @@ def main() -> int:
|
||||
"files": total_files,
|
||||
"folders": total_folders,
|
||||
"skipped": total_skipped,
|
||||
"connect_ip": client.connect_ip,
|
||||
"source_dir": str(source_dir),
|
||||
"manifest": str(args.manifest),
|
||||
"mapping": str(args.mapping),
|
||||
|
||||
0
runtime/lib/piwigo-sync.php
Normal file → Executable file
0
runtime/lib/piwigo-sync.php
Normal file → Executable file
@@ -6,6 +6,8 @@ if (PHP_SAPI !== 'cli')
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require_once(dirname(__DIR__, 2).'/include/nc_transport.inc.php');
|
||||
|
||||
const BRATONIEN_WEBDAV_PREVIEW_VERSION = 2;
|
||||
const BRATONIEN_WEBDAV_PREVIEW_MAX_EDGE = 4096;
|
||||
const BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY = 88;
|
||||
@@ -24,7 +26,7 @@ function quote_webdav_path($path)
|
||||
function fetch_remote_blob($url, $user, $password)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, array(
|
||||
$options = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => false,
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
@@ -32,8 +34,10 @@ function fetch_remote_blob($url, $user, $password)
|
||||
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
||||
CURLOPT_USERPWD => $user.':'.$password,
|
||||
CURLOPT_FAILONERROR => false,
|
||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Precache/0.9.6.1',
|
||||
));
|
||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Precache/0.9.7.16',
|
||||
);
|
||||
bratonien_tools_nc_transport_apply_curl($options, $url);
|
||||
curl_setopt_array($ch, $options);
|
||||
$body = curl_exec($ch);
|
||||
$errno = curl_errno($ch);
|
||||
$error = curl_error($ch);
|
||||
@@ -48,12 +52,11 @@ function fetch_remote_blob($url, $user, $password)
|
||||
|
||||
function preview_extension_for_entry(array $entry)
|
||||
{
|
||||
$content_type = strtolower(trim((string)($entry['content_type'] ?? '')));
|
||||
$path = strtolower((string)($entry['webdav_path'] ?? ''));
|
||||
if ($content_type === 'image/png' || preg_match('/\.png$/', $path))
|
||||
{
|
||||
return 'png';
|
||||
}
|
||||
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
if ($extension === 'png') return 'png';
|
||||
if ($extension === 'gif') return 'gif';
|
||||
if ($extension === 'webp') return 'webp';
|
||||
return 'jpg';
|
||||
}
|
||||
|
||||
@@ -64,7 +67,7 @@ function preview_target_for_entry($cache_dir, $key, array $entry)
|
||||
|
||||
function remove_other_preview_format($cache_dir, $key, $keep_target)
|
||||
{
|
||||
foreach (array('jpg', 'png', 'webp') as $ext)
|
||||
foreach (array('jpg', 'png', 'gif', 'webp') as $ext)
|
||||
{
|
||||
$candidate = $cache_dir.'/'.$key.'.'.$ext;
|
||||
if ($candidate !== $keep_target && is_file($candidate)) @unlink($candidate);
|
||||
@@ -86,13 +89,19 @@ function write_preview_imagick($blob, $target, $extension)
|
||||
{
|
||||
$image->setImageFormat('png');
|
||||
}
|
||||
elseif ($extension === 'gif')
|
||||
{
|
||||
$image->setImageFormat('gif');
|
||||
}
|
||||
elseif ($extension === 'webp')
|
||||
{
|
||||
$image->setImageFormat('webp');
|
||||
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||
}
|
||||
else
|
||||
{
|
||||
$image->setImageBackgroundColor('white');
|
||||
if (method_exists($image, 'mergeImageLayers'))
|
||||
{
|
||||
$image = $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
|
||||
}
|
||||
if (method_exists($image, 'mergeImageLayers')) $image = $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
|
||||
$image->setImageFormat('jpeg');
|
||||
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
||||
$image->setImageCompressionQuality(BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||
@@ -127,7 +136,7 @@ function write_preview_gd($blob, $target, $extension)
|
||||
|
||||
try
|
||||
{
|
||||
if ($extension === 'png')
|
||||
if (in_array($extension, array('png', 'gif', 'webp'), true))
|
||||
{
|
||||
imagealphablending($preview, false);
|
||||
imagesavealpha($preview, true);
|
||||
@@ -145,10 +154,12 @@ function write_preview_gd($blob, $target, $extension)
|
||||
fail_preview('GD konnte das Preview nicht skalieren.');
|
||||
}
|
||||
|
||||
$written = $extension === 'png'
|
||||
? imagepng($preview, $target, 6)
|
||||
: imagejpeg($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||
if (!$written) fail_preview('GD konnte das Preview nicht schreiben.');
|
||||
if ($extension === 'png') $written = imagepng($preview, $target, 6);
|
||||
elseif ($extension === 'gif') $written = function_exists('imagegif') ? imagegif($preview, $target) : false;
|
||||
elseif ($extension === 'webp') $written = function_exists('imagewebp') ? imagewebp($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY) : false;
|
||||
else $written = imagejpeg($preview, $target, BRATONIEN_WEBDAV_PREVIEW_JPEG_QUALITY);
|
||||
|
||||
if (!$written) fail_preview('GD konnte das Preview im Format '.$extension.' nicht schreiben.');
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -164,7 +175,7 @@ function write_preview_gd($blob, $target, $extension)
|
||||
function write_preview($blob, $target, $extension)
|
||||
{
|
||||
$dir = dirname($target);
|
||||
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) fail_preview('Preview-Verzeichnis konnte nicht angelegt werden.');
|
||||
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) fail_preview('Preview-Verzeichnis konnte nicht angelegt werden.');
|
||||
|
||||
if (class_exists('Imagick'))
|
||||
{
|
||||
@@ -186,7 +197,48 @@ function write_preview($blob, $target, $extension)
|
||||
@unlink($target);
|
||||
fail_preview('Das erzeugte Preview ist ungültig.');
|
||||
}
|
||||
@chmod($target, 0644);
|
||||
@chmod($target, 0664);
|
||||
}
|
||||
|
||||
function local_source_is_hydrated($source_path, $preview)
|
||||
{
|
||||
if (!is_file($source_path) || !is_readable($source_path)) return false;
|
||||
$source_size = @getimagesize($source_path);
|
||||
$preview_size = @getimagesize($preview);
|
||||
if (!is_array($source_size) || !is_array($preview_size)) return false;
|
||||
if ((int)$source_size[0] !== (int)$preview_size[0] || (int)$source_size[1] !== (int)$preview_size[1]) return false;
|
||||
$source_bytes = @filesize($source_path);
|
||||
$preview_bytes = @filesize($preview);
|
||||
return $source_bytes !== false && $preview_bytes !== false && (int)$source_bytes === (int)$preview_bytes;
|
||||
}
|
||||
|
||||
function hydrate_local_source($source_path, $preview)
|
||||
{
|
||||
$normalized = str_replace('\\', '/', (string)$source_path);
|
||||
if (!preg_match('#/nc-webdav-source/connection-[0-9]+/root-[0-9]+/#', $normalized))
|
||||
{
|
||||
fail_preview('Unsicherer lokaler Connector-Quellpfad: '.$source_path);
|
||||
}
|
||||
if (!is_file($preview) || !is_readable($preview)) fail_preview('Preview für lokale Quelle fehlt: '.$preview);
|
||||
if (local_source_is_hydrated($source_path, $preview)) return false;
|
||||
|
||||
$dir = dirname($source_path);
|
||||
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) fail_preview('Lokales Connector-Verzeichnis konnte nicht angelegt werden: '.$dir);
|
||||
|
||||
$tmp = $source_path.'.bratonien-next-'.getmypid();
|
||||
if (!@copy($preview, $tmp)) fail_preview('Preview konnte nicht in lokale Piwigo-Quelle kopiert werden: '.$source_path);
|
||||
@chmod($tmp, 0664);
|
||||
$mtime = @filemtime($preview);
|
||||
if ($mtime) @touch($tmp, $mtime);
|
||||
if (!@rename($tmp, $source_path))
|
||||
{
|
||||
@unlink($tmp);
|
||||
fail_preview('Lokale Piwigo-Quelle konnte nicht ersetzt werden: '.$source_path);
|
||||
}
|
||||
clearstatcache(true, $source_path);
|
||||
$size = @getimagesize($source_path);
|
||||
if (!is_array($size) || empty($size[0]) || empty($size[1])) fail_preview('Lokale Piwigo-Quelle ist nach dem Ersetzen ungültig: '.$source_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -208,8 +260,8 @@ try
|
||||
$mapping = json_decode((string)file_get_contents($mapping_file), true);
|
||||
if (!is_array($mapping) || !isset($mapping['files']) || !is_array($mapping['files'])) fail_preview('WebDAV-Mapping ist ungültig.');
|
||||
|
||||
if (!is_dir($cache_dir) && !mkdir($cache_dir, 0755, true) && !is_dir($cache_dir)) fail_preview('Preview-Cache konnte nicht angelegt werden.');
|
||||
@chmod($cache_dir, 0755);
|
||||
if (!is_dir($cache_dir) && !mkdir($cache_dir, 0775, true) && !is_dir($cache_dir)) fail_preview('Preview-Cache konnte nicht angelegt werden.');
|
||||
@chmod($cache_dir, 2775);
|
||||
|
||||
$state_file = $cache_dir.'/state.json';
|
||||
$old_state = array();
|
||||
@@ -222,9 +274,10 @@ try
|
||||
$new_state = array();
|
||||
$generated = 0;
|
||||
$cached = 0;
|
||||
$hydrated = 0;
|
||||
$errors = 0;
|
||||
|
||||
foreach ($mapping['files'] as $entry)
|
||||
foreach ($mapping['files'] as $local_path=>$entry)
|
||||
{
|
||||
if (!is_array($entry) || (string)($entry['kind'] ?? '') !== 'file') continue;
|
||||
$webdav_path = trim((string)($entry['webdav_path'] ?? ''), '/');
|
||||
@@ -241,26 +294,29 @@ try
|
||||
'version' => BRATONIEN_WEBDAV_PREVIEW_VERSION,
|
||||
);
|
||||
|
||||
$old = $old_state[$key] ?? null;
|
||||
if (
|
||||
is_file($target)
|
||||
&& is_array($old)
|
||||
&& (string)($old['etag'] ?? '') === $etag
|
||||
&& (string)($old['format'] ?? '') === $extension
|
||||
&& (int)($old['version'] ?? 0) === BRATONIEN_WEBDAV_PREVIEW_VERSION
|
||||
)
|
||||
{
|
||||
$cached++;
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$url = $base_url.'/remote.php/dav/files/'.rawurlencode($user).'/'.quote_webdav_path($webdav_path);
|
||||
$blob = fetch_remote_blob($url, $user, $password);
|
||||
write_preview($blob, $target, $extension);
|
||||
remove_other_preview_format($cache_dir, $key, $target);
|
||||
$generated++;
|
||||
$old = $old_state[$key] ?? null;
|
||||
$valid_cached = is_file($target)
|
||||
&& is_array($old)
|
||||
&& (string)($old['etag'] ?? '') === $etag
|
||||
&& (string)($old['format'] ?? '') === $extension
|
||||
&& (int)($old['version'] ?? 0) === BRATONIEN_WEBDAV_PREVIEW_VERSION;
|
||||
|
||||
if (!$valid_cached)
|
||||
{
|
||||
$url = $base_url.'/remote.php/dav/files/'.rawurlencode($user).'/'.quote_webdav_path($webdav_path);
|
||||
$blob = fetch_remote_blob($url, $user, $password);
|
||||
write_preview($blob, $target, $extension);
|
||||
remove_other_preview_format($cache_dir, $key, $target);
|
||||
$generated++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$cached++;
|
||||
}
|
||||
|
||||
if (hydrate_local_source((string)$local_path, $target)) $hydrated++;
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
@@ -273,14 +329,14 @@ try
|
||||
{
|
||||
if (!is_file($file) || basename($file) === 'state.json') continue;
|
||||
$name = basename($file);
|
||||
if (!preg_match('/^([a-f0-9]{40})\.(jpg|png|webp)$/', $name, $m)) continue;
|
||||
if (!preg_match('/^([a-f0-9]{40})\.(jpg|png|gif|webp)$/', $name, $m)) continue;
|
||||
if (!isset($new_state[$m[1]])) @unlink($file);
|
||||
}
|
||||
|
||||
file_put_contents($state_file, json_encode($new_state, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)."\n", LOCK_EX);
|
||||
@chmod($state_file, 0644);
|
||||
@chmod($state_file, 0664);
|
||||
|
||||
echo 'WebDAV-Previews: erzeugt='.$generated.' vorhanden='.$cached.' fehler='.$errors."\n";
|
||||
echo 'WebDAV-Previews: erzeugt='.$generated.' vorhanden='.$cached.' lokale_quellen='.$hydrated.' fehler='.$errors."\n";
|
||||
exit($errors > 0 ? 1 : 0);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
|
||||
24
runtime/lib/resolve-nextcloud-target.php
Normal file
24
runtime/lib/resolve-nextcloud-target.php
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
if (PHP_SAPI !== 'cli')
|
||||
{
|
||||
fwrite(STDERR, "CLI only\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require_once(dirname(__DIR__, 2).'/include/nc_transport.inc.php');
|
||||
|
||||
try
|
||||
{
|
||||
if ($argc !== 2) throw new RuntimeException('Aufruf: resolve-nextcloud-target.php <nextcloud-url>');
|
||||
$url = rtrim(trim((string)$argv[1]), '/');
|
||||
bratonien_tools_nc_transport_scheme($url);
|
||||
$host = bratonien_tools_nc_transport_host($url);
|
||||
echo bratonien_tools_nc_transport_public_ip($host)."\n";
|
||||
exit(0);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
fwrite(STDERR, $e->getMessage()."\n");
|
||||
exit(1);
|
||||
}
|
||||
0
runtime/lib/shadow_tree.py
Normal file → Executable file
0
runtime/lib/shadow_tree.py
Normal file → Executable file
108
runtime/native-runner.php
Normal file
108
runtime/native-runner.php
Normal file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
if (PHP_SAPI !== 'cli')
|
||||
{
|
||||
fwrite(STDERR, "CLI only\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$options = getopt('', array('connection-id::'));
|
||||
$connectionId = isset($options['connection-id']) ? (int)$options['connection-id'] : 0;
|
||||
|
||||
$pluginRoot = dirname(__DIR__);
|
||||
$piwigoRoot = dirname($pluginRoot, 2);
|
||||
$base = rtrim($piwigoRoot, '/').'/_data/bratonien-tools';
|
||||
$schedulerDir = $base.'/nc-connector-scheduler';
|
||||
$stateFile = $schedulerDir.'/state.json';
|
||||
$runtimeDir = $base.'/nc-connector-runtime';
|
||||
$stateRoot = $base.'/nc-connector-state';
|
||||
|
||||
function native_scheduler_state($path)
|
||||
{
|
||||
if (!is_readable($path)) return array();
|
||||
$decoded = json_decode((string)@file_get_contents($path), true);
|
||||
return is_array($decoded) ? $decoded : array();
|
||||
}
|
||||
|
||||
function native_scheduler_write($path, array $state)
|
||||
{
|
||||
$json = json_encode($state, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
if (!is_string($json)) return false;
|
||||
$tmp = $path.'.tmp';
|
||||
if (@file_put_contents($tmp, $json."\n", LOCK_EX) === false) return false;
|
||||
@chmod($tmp, 0640);
|
||||
return @rename($tmp, $path);
|
||||
}
|
||||
|
||||
foreach (array($schedulerDir, $runtimeDir, $stateRoot) as $dir)
|
||||
{
|
||||
if (!is_dir($dir) && !@mkdir($dir, 0750, true) && !is_dir($dir))
|
||||
{
|
||||
fwrite(STDERR, "Runtime-Verzeichnis konnte nicht angelegt werden: {$dir}\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
$state = native_scheduler_state($stateFile);
|
||||
$state['enabled'] = true;
|
||||
$state['mode'] = 'piwigo-native';
|
||||
$state['state'] = 'running';
|
||||
$state['message'] = $connectionId > 0 ? 'NC-Abgleich für Verbindung #'.$connectionId.' läuft.' : 'NC-Abgleich läuft.';
|
||||
$state['started_at'] = time();
|
||||
$state['timestamp'] = time();
|
||||
$state['connection_id'] = $connectionId;
|
||||
native_scheduler_write($stateFile, $state);
|
||||
|
||||
$env = $_ENV;
|
||||
$env['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin';
|
||||
$env['BRATONIEN_NC_NATIVE'] = '1';
|
||||
$env['BRATONIEN_NC_PIWIGO_ROOT'] = $piwigoRoot;
|
||||
$env['BRATONIEN_NC_CONFIG_DIR'] = $runtimeDir;
|
||||
$env['BRATONIEN_NC_STATE_ROOT'] = $stateRoot;
|
||||
$env['BRATONIEN_NC_CONNECTION_ID'] = (string)$connectionId;
|
||||
$env['LC_ALL'] = 'C';
|
||||
$env['LANG'] = 'C';
|
||||
|
||||
$bash = is_executable('/usr/bin/bash') ? '/usr/bin/bash' : '/bin/bash';
|
||||
$command = array($bash, $pluginRoot.'/runtime/run-all.sh');
|
||||
$spec = array(
|
||||
0=>array('file','/dev/null','r'),
|
||||
1=>array('pipe','w'),
|
||||
2=>array('pipe','w'),
|
||||
);
|
||||
$process = @proc_open($command, $spec, $pipes, null, $env);
|
||||
$stdout = '';
|
||||
$stderr = '';
|
||||
$exit = 1;
|
||||
if (is_resource($process))
|
||||
{
|
||||
$stdout = (string)stream_get_contents($pipes[1]);
|
||||
$stderr = (string)stream_get_contents($pipes[2]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
$exit = proc_close($process);
|
||||
}
|
||||
else
|
||||
{
|
||||
$stderr = 'run-all.sh konnte nicht gestartet werden.';
|
||||
}
|
||||
|
||||
$state = native_scheduler_state($stateFile);
|
||||
$state['enabled'] = true;
|
||||
$state['mode'] = 'piwigo-native';
|
||||
$state['state'] = $exit === 0 ? 'success' : 'error';
|
||||
$state['message'] = $exit === 0
|
||||
? ($connectionId > 0 ? 'NC-Abgleich für Verbindung #'.$connectionId.' erfolgreich abgeschlossen.' : 'NC-Abgleich erfolgreich abgeschlossen.')
|
||||
: ($connectionId > 0 ? 'NC-Abgleich für Verbindung #'.$connectionId.' fehlgeschlagen.' : 'NC-Abgleich fehlgeschlagen.');
|
||||
$state['timestamp'] = time();
|
||||
$state['finished_at'] = time();
|
||||
$state['exit_code'] = $exit;
|
||||
$state['connection_id'] = $connectionId;
|
||||
$state['stdout'] = trim($stdout);
|
||||
$state['stderr'] = trim($stderr);
|
||||
if (empty($state['next_due']) || (int)$state['next_due'] < time())
|
||||
{
|
||||
$state['next_due'] = time() + 60;
|
||||
}
|
||||
native_scheduler_write($stateFile, $state);
|
||||
exit($exit === 0 ? 0 : 1);
|
||||
@@ -78,8 +78,11 @@ function webdav_source_fingerprint($baseUrl, $user, array $roots)
|
||||
$pluginRoot = dirname(__DIR__);
|
||||
$piwigoRoot = dirname($pluginRoot, 2);
|
||||
$dbConfig = $piwigoRoot.'/local/config/database.inc.php';
|
||||
$configDir = '/etc/bratonien-tools/nc-connector';
|
||||
$stateRoot = '/var/lib/bratonien-tools/nc-connector';
|
||||
$nativeMode = getenv('BRATONIEN_NC_NATIVE') === '1';
|
||||
$configDir = trim((string)getenv('BRATONIEN_NC_CONFIG_DIR'));
|
||||
if ($configDir === '') $configDir = $nativeMode ? rtrim($piwigoRoot, '/').'/_data/bratonien-tools/nc-connector-runtime' : '/etc/bratonien-tools/nc-connector';
|
||||
$stateRoot = trim((string)getenv('BRATONIEN_NC_STATE_ROOT'));
|
||||
if ($stateRoot === '') $stateRoot = $nativeMode ? rtrim($piwigoRoot, '/').'/_data/bratonien-tools/nc-connector-state' : '/var/lib/bratonien-tools/nc-connector';
|
||||
$publicSourceRoot = rtrim($piwigoRoot, '/').'/_data/bratonien-tools/nc-webdav-source';
|
||||
$publicGalleryRoot = rtrim($piwigoRoot, '/').'/_data/bratonien-tools/nc-webdav-gallery';
|
||||
$legacyGalleryRoot = rtrim($piwigoRoot, '/').'/galleries';
|
||||
@@ -107,11 +110,12 @@ try
|
||||
$rows = $db->query("SELECT id,name,adapter,config_json,secret_blob FROM `{$table}` ORDER BY id DESC");
|
||||
if (!$rows) fail_webdav_reconcile('Connector-Verbindungen konnten nicht gelesen werden: '.$db->error);
|
||||
|
||||
foreach (array($configDir=>$configDir, $publicSourceRoot=>$publicSourceRoot, $publicGalleryRoot=>$publicGalleryRoot) as $dir=>$unused)
|
||||
foreach (array($configDir, $stateRoot, $publicSourceRoot, $publicGalleryRoot) as $dir)
|
||||
{
|
||||
if (!is_dir($dir) && !mkdir($dir, $dir === $configDir ? 0700 : 0755, true)) fail_webdav_reconcile('Runtime-Verzeichnis konnte nicht angelegt werden: '.$dir);
|
||||
if (!is_dir($dir) && !mkdir($dir, $dir === $configDir ? 0700 : 0750, true)) fail_webdav_reconcile('Runtime-Verzeichnis konnte nicht angelegt werden: '.$dir);
|
||||
}
|
||||
@chmod($configDir, 0700);
|
||||
@chmod($stateRoot, 0750);
|
||||
@chmod($publicSourceRoot, 0755);
|
||||
@chmod($publicGalleryRoot, 0755);
|
||||
|
||||
@@ -125,7 +129,6 @@ try
|
||||
if (!is_array($config)) $config = array();
|
||||
if ((string)$row['adapter'] !== 'remote') continue;
|
||||
if ((string)($config['source_mode'] ?? '') !== 'webdav-placeholder') continue;
|
||||
if (empty($config['parallel_test'])) continue;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -151,7 +154,7 @@ try
|
||||
$seenFingerprints[$fingerprint] = $id;
|
||||
$known[$id] = true;
|
||||
|
||||
$stateDir = rtrim((string)($config['state_dir'] ?? ''), '/');
|
||||
$stateDir = $nativeMode ? $stateRoot.'/connection-'.$id : rtrim((string)($config['state_dir'] ?? ''), '/');
|
||||
if ($stateDir === '') $stateDir = $stateRoot.'/connection-'.$id;
|
||||
if (!is_dir($stateDir) && !mkdir($stateDir, 0750, true)) fail_webdav_reconcile('State-Verzeichnis konnte nicht angelegt werden.');
|
||||
@chmod($stateDir, 0750);
|
||||
@@ -164,8 +167,6 @@ try
|
||||
}
|
||||
if (!is_dir($galleryRoot) && !mkdir($galleryRoot, 0755, true)) fail_webdav_reconcile('WebDAV-Galeriebereich konnte nicht angelegt werden.');
|
||||
@chmod($galleryRoot, 0755);
|
||||
|
||||
// Alte technische Wrapper unter ./galleries duerfen nicht als Piwigo-Alben auftauchen.
|
||||
webdav_remove_generated_tree($legacyDefault, $legacyGalleryRoot);
|
||||
|
||||
$sourceDir = $publicSourceRoot.'/connection-'.$id;
|
||||
@@ -189,8 +190,9 @@ try
|
||||
{
|
||||
$path = trim((string)($root['webdav_path'] ?? ''), '/');
|
||||
$display = trim((string)($root['display_name'] ?? ''));
|
||||
if ($path === '' || $display === '' || preg_match('/[\t\r\n]/', $path.$display)) fail_webdav_reconcile('Eine gespeicherte WebDAV-Wurzel ist ungueltig.');
|
||||
$rootLines[] = $path."\t".$display;
|
||||
$runtimePath = $path === '' ? '/' : $path;
|
||||
if ($display === '' || preg_match('/[\t\r\n]/', $runtimePath.$display)) fail_webdav_reconcile('Eine gespeicherte WebDAV-Wurzel ist ungueltig.');
|
||||
$rootLines[] = $runtimePath."\t".$display;
|
||||
}
|
||||
file_put_contents($rootsPath, implode("\n", $rootLines)."\n", LOCK_EX);
|
||||
@chmod($rootsPath, 0600);
|
||||
@@ -215,21 +217,23 @@ try
|
||||
file_put_contents($configPath, implode("\n", $lines)."\n", LOCK_EX);
|
||||
@chmod($configPath, 0600);
|
||||
|
||||
unset($config['migration'], $config['parallel_test']);
|
||||
$config['state_dir'] = $stateDir;
|
||||
$config['status_file'] = $statusFile;
|
||||
$config['parallel_gallery_root'] = $galleryRoot;
|
||||
$config['source_fingerprint'] = $fingerprint;
|
||||
$config['runtime'] = array(
|
||||
'mode'=>'parallel-webdav',
|
||||
'mode'=>$nativeMode ? 'piwigo-native-webdav' : 'webdav',
|
||||
'config'=>$configPath,
|
||||
'piwigo_sync_enabled'=>true,
|
||||
'reconciled_at'=>date('Y-m-d H:i:s'),
|
||||
);
|
||||
$json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (is_string($json))
|
||||
if (!is_string($json)) fail_webdav_reconcile('WebDAV-Runtime-Konfiguration konnte nicht serialisiert werden.');
|
||||
$escaped = $db->real_escape_string($json);
|
||||
if (!$db->query("UPDATE `{$table}` SET config_json='{$escaped}' WHERE id={$id} AND adapter='remote' LIMIT 1"))
|
||||
{
|
||||
$escaped = $db->real_escape_string($json);
|
||||
$db->query("UPDATE `{$table}` SET config_json='{$escaped}' WHERE id={$id} LIMIT 1");
|
||||
fail_webdav_reconcile('WebDAV-Runtime-Status konnte nicht gespeichert werden: '.$db->error);
|
||||
}
|
||||
}
|
||||
catch (Throwable $e)
|
||||
|
||||
36
runtime/repair-webdav-cache-permissions.sh
Normal file
36
runtime/repair-webdav-cache-permissions.sh
Normal file
@@ -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)."
|
||||
@@ -1,32 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
CONFIG_DIR="/etc/bratonien-tools/nc-connector"
|
||||
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"
|
||||
mkdir -p -- "$GLOBAL_LOCK_DIR"
|
||||
exec 8>"$GLOBAL_LOCK_FILE"
|
||||
if ! flock -n 8; then
|
||||
echo "NC Connector: ein Lauf ist bereits aktiv."
|
||||
exit 0
|
||||
fi
|
||||
shopt -s nullglob
|
||||
|
||||
if ! php "$SCRIPT_DIR/reconcile.php"; then
|
||||
echo "NC Connector: gespeicherte lokale Verbindungen konnten nicht mit der Runtime abgeglichen werden." >&2
|
||||
if [[ ! "$TARGET_CONNECTION_ID" =~ ^[0-9]+$ ]]; then
|
||||
echo "NC Connector: ungültige Ziel-Verbindungs-ID: $TARGET_CONNECTION_ID" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! php "$SCRIPT_DIR/reconcile-webdav.php"; then
|
||||
echo "NC Connector: WebDAV-Testverbindungen konnten nicht mit der parallelen Runtime abgeglichen werden." >&2
|
||||
exit 1
|
||||
fi
|
||||
read_config_value() {
|
||||
local key="$1"
|
||||
local file="$2"
|
||||
local value
|
||||
value="$(sed -n "s/^${key}=//p" "$file" | tail -n 1)"
|
||||
value="${value%\"}"
|
||||
value="${value#\"}"
|
||||
value="${value%\'}"
|
||||
value="${value#\'}"
|
||||
printf '%s' "$value"
|
||||
}
|
||||
|
||||
# Nach dem Reconcile kennt Piwigo alle noch aktiven WebDAV-Verbindungen. Jetzt
|
||||
# werden Sites, Alben, Bilddatensaetze und Derivate geloeschter Verbindungen
|
||||
# entfernt. Das erfasst auch Verbindungen, die bereits vor diesem Update
|
||||
# geloescht wurden.
|
||||
if ! php "$SCRIPT_DIR/cleanup-webdav-piwigo.php"; then
|
||||
echo "NC Connector: Piwigo-Inhalte geloeschter WebDAV-Verbindungen konnten nicht bereinigt werden." >&2
|
||||
exit 1
|
||||
fi
|
||||
write_route_status() {
|
||||
local route="$1"
|
||||
local label="$2"
|
||||
local detail="$3"
|
||||
local success="$4"
|
||||
[[ -n "${ROUTE_STATUS_FILE:-}" ]] || return 0
|
||||
mkdir -p -- "$(dirname -- "$ROUTE_STATUS_FILE")"
|
||||
php -r '
|
||||
$payload = array(
|
||||
"timestamp" => time(),
|
||||
"route" => (string)$argv[2],
|
||||
"label" => (string)$argv[3],
|
||||
"detail" => (string)$argv[4],
|
||||
"fallback_used" => false,
|
||||
"success" => $argv[5] === "1"
|
||||
);
|
||||
$json = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
if (!is_string($json) || file_put_contents($argv[1], $json.PHP_EOL, LOCK_EX) === false) exit(1);
|
||||
@chmod($argv[1], 0644);
|
||||
' "$ROUTE_STATUS_FILE" "$route" "$label" "$detail" "$success"
|
||||
}
|
||||
|
||||
if ! php "$SCRIPT_DIR/cleanup-stale.php"; then
|
||||
echo "NC Connector: verwaiste Laufzeitdateien konnten nicht bereinigt werden." >&2
|
||||
exit 1
|
||||
if [[ "$NATIVE_MODE" != "1" ]]; then
|
||||
php "$SCRIPT_DIR/reconcile.php"
|
||||
fi
|
||||
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)
|
||||
@@ -37,51 +72,123 @@ if [[ ${#configs[@]} -eq 0 && ${#webdav_configs[@]} -eq 0 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
result=0
|
||||
|
||||
# WebDAV zuerst: Der parallele Shadow Tree muss bereits vollständig stehen,
|
||||
# bevor der weiterhin produktive lokale Weg seine normale Piwigo-
|
||||
# Dateisynchronisierung ausführt. So wird der neue Baum im selben Minutenlauf
|
||||
# sichtbar, ohne dass der WebDAV-Zweig selbst eine zweite globale Piwigo-
|
||||
# Synchronisierung startet.
|
||||
for config in "${webdav_configs[@]}"; do
|
||||
name="$(basename "$config")"
|
||||
echo "NC Connector WebDAV parallel: $name"
|
||||
if ! env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh"; then
|
||||
result=1
|
||||
route_piwigo_root=""
|
||||
for candidate in "${webdav_configs[@]}" "${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
|
||||
continue
|
||||
fi
|
||||
route_piwigo_root="$(read_config_value PIWIGO_ROOT "$candidate")"
|
||||
[[ -n "$route_piwigo_root" ]] && break
|
||||
done
|
||||
[[ -n "$route_piwigo_root" ]] || route_piwigo_root="$PIWIGO_ROOT_DEFAULT"
|
||||
ROUTE_STATUS_FILE="${route_piwigo_root%/}/_data/bratonien-tools/nc-connector-status/route-status.json"
|
||||
|
||||
for config in "${configs[@]}"; do
|
||||
failure_count=0
|
||||
webdav_count=0
|
||||
local_count=0
|
||||
summary_parts=()
|
||||
matched_count=0
|
||||
|
||||
for config in "${webdav_configs[@]}"; do
|
||||
[[ -f "$config" ]] || continue
|
||||
name="$(basename "$config")"
|
||||
connection_id=""
|
||||
if [[ "$name" =~ ^connection-([0-9]+)\.conf$ ]]; then
|
||||
connection_id="${BASH_REMATCH[1]}"
|
||||
connection_id="$(read_config_value CONNECTION_ID "$config")"
|
||||
if [[ ! "$connection_id" =~ ^[0-9]+$ ]] || [[ "$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
|
||||
|
||||
piwigo_root="$(sed -n 's/^PIWIGO_ROOT=//p' "$config" | tail -n 1)"
|
||||
piwigo_root="${piwigo_root%\"}"
|
||||
piwigo_root="${piwigo_root#\"}"
|
||||
piwigo_root="${piwigo_root%\'}"
|
||||
piwigo_root="${piwigo_root#\'}"
|
||||
[[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo"
|
||||
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
||||
|
||||
if [[ -n "$connection_id" && -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"
|
||||
if [[ "$TARGET_CONNECTION_ID" -gt 0 && "$connection_id" != "$TARGET_CONNECTION_ID" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "NC Connector lokal: $name"
|
||||
if ! env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync.sh"; then
|
||||
result=1
|
||||
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
|
||||
[[ -z "$output" ]] || printf '%s\n' "$output"
|
||||
summary_parts+=("WebDAV #$connection_id erfolgreich")
|
||||
else
|
||||
code=$?
|
||||
[[ -z "$output" ]] || printf '%s\n' "$output" >&2
|
||||
failure_count=$((failure_count + 1))
|
||||
summary_parts+=("WebDAV #$connection_id fehlgeschlagen (Exit $code)")
|
||||
fi
|
||||
done
|
||||
|
||||
exit "$result"
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
summary_detail="$(IFS='; '; printf '%s' "${summary_parts[*]}")"
|
||||
[[ -n "$summary_detail" ]] || summary_detail="Keine 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."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
write_route_status "failed" "FEHLER - angeforderte Verbindung" "$summary_detail" "0"
|
||||
echo "NC Connector: die angeforderte Verbindung ist fehlgeschlagen." >&2
|
||||
exit 1
|
||||
|
||||
@@ -59,10 +59,6 @@ for target in (status_file, public_file):
|
||||
PY
|
||||
}
|
||||
|
||||
compact_output() {
|
||||
tail -n 12 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
||||
}
|
||||
|
||||
failure() {
|
||||
local code="$1" command="$2" line="$3"
|
||||
trap - ERR
|
||||
@@ -79,8 +75,12 @@ done < "$WEBDAV_ROOTS_FILE"
|
||||
|
||||
[[ ${#ROOT_ARGS[@]} -gt 0 ]] || { write_status error "Keine WebDAV-Wurzeln konfiguriert"; exit 1; }
|
||||
|
||||
WEBDAV_CONNECT_IP="$(php "$SCRIPT_DIR/lib/resolve-nextcloud-target.php" "$WEBDAV_BASE_URL")"
|
||||
[[ -n "$WEBDAV_CONNECT_IP" ]] || { write_status error "Nextcloud-Zieladresse konnte nicht ermittelt werden"; exit 1; }
|
||||
|
||||
python3 "$SCRIPT_DIR/lib/build_webdav_placeholder_source.py" \
|
||||
--base-url "$WEBDAV_BASE_URL" \
|
||||
--connect-ip "$WEBDAV_CONNECT_IP" \
|
||||
--user "$WEBDAV_USER" \
|
||||
--password-file "$WEBDAV_PASSWORD_FILE" \
|
||||
"${ROOT_ARGS[@]}" \
|
||||
@@ -94,28 +94,6 @@ python3 "$SCRIPT_DIR/lib/shadow_tree.py" \
|
||||
--state "$SHADOW_MAP_FILE"
|
||||
|
||||
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=""
|
||||
@@ -133,7 +111,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" | compact_output)"
|
||||
DETAIL+="; Ausgabe: $(printf '%s\n' "$PIWIGO_OUTPUT" | tail -n 12 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//')"
|
||||
fi
|
||||
|
||||
if grep -qi 'Invalid username/password' <<<"$PIWIGO_OUTPUT"; then
|
||||
@@ -160,28 +138,9 @@ 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, Piwigo synchronisiert und Derivate erzeugt" \
|
||||
"WebDAV eingelesen und Piwigo synchronisiert" \
|
||||
"" \
|
||||
"api" \
|
||||
"ok" \
|
||||
@@ -190,7 +149,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, Piwigo über Fallback synchronisiert und Derivate erzeugt" \
|
||||
"WebDAV eingelesen und Piwigo über Fallback synchronisiert" \
|
||||
"" \
|
||||
"fallback" \
|
||||
"not_used" \
|
||||
@@ -198,8 +157,8 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
||||
"ok" \
|
||||
"Benutzername/Passwort-Fallback erfolgreich"
|
||||
else
|
||||
write_status ok "WebDAV eingelesen, Piwigo synchronisiert und Derivate erzeugt"
|
||||
write_status ok "WebDAV eingelesen und Piwigo synchronisiert"
|
||||
fi
|
||||
else
|
||||
write_status ok "WebDAV eingelesen und Vorschaubilder erzeugt; Registrierung erfolgt über den bestehenden produktiven Piwigo-Sync"
|
||||
write_status ok "WebDAV eingelesen; Piwigo-Synchronisierung ist für diese Verbindung deaktiviert"
|
||||
fi
|
||||
|
||||
@@ -48,12 +48,27 @@
|
||||
var openButton=document.getElementById('bratonien-nc-wizard-open');
|
||||
var closeButton=document.getElementById('bratonien-nc-wizard-close');
|
||||
var storageKey='bratonienNcWizardOpen';
|
||||
var modeKey='bratonienNcWizardMode';
|
||||
var resetBusy=false;
|
||||
|
||||
function token(){var input=section.querySelector('input[name="pwg_token"]');return input?input.value:'';}
|
||||
function setOpen(value){try{if(value)sessionStorage.setItem(storageKey,'1');else sessionStorage.removeItem(storageKey);}catch(e){}}
|
||||
function setMode(value){try{if(value)sessionStorage.setItem(modeKey,value);else sessionStorage.removeItem(modeKey);}catch(e){}}
|
||||
function mode(){try{return sessionStorage.getItem(modeKey)||'';}catch(e){return '';}}
|
||||
function applyMode(){
|
||||
if(!dialog)return;
|
||||
var heading=dialog.querySelector('h4');
|
||||
var finish=dialog.querySelector('button[value="nc_connector_wizard_finish"]');
|
||||
if(mode()==='edit'){
|
||||
if(heading)heading.textContent='Verbindung bearbeiten';
|
||||
if(finish)finish.textContent='Änderungen speichern';
|
||||
}else{
|
||||
if(heading)heading.textContent='Neue Verbindung';
|
||||
if(finish)finish.textContent='Verbindung anlegen';
|
||||
}
|
||||
}
|
||||
function showWizard(){
|
||||
setOpen(true);
|
||||
setOpen(true);applyMode();
|
||||
if(!dialog)return;
|
||||
if(typeof dialog.showModal==='function'&&!dialog.open)dialog.showModal();
|
||||
else dialog.setAttribute('open','open');
|
||||
@@ -65,13 +80,13 @@
|
||||
return fetch(window.location.href,{method:'POST',credentials:'same-origin',cache:'no-store',headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},body:body.toString()});
|
||||
}
|
||||
function closeAfterReset(){
|
||||
if(resetBusy)return;resetBusy=true;setOpen(false);
|
||||
if(resetBusy)return;resetBusy=true;setOpen(false);setMode('');
|
||||
resetServer().catch(function(){}).finally(function(){resetBusy=false;if(dialog){if(typeof dialog.close==='function'&&dialog.open)dialog.close();else dialog.removeAttribute('open');}});
|
||||
}
|
||||
|
||||
if(openButton){
|
||||
openButton.addEventListener('click',function(event){
|
||||
event.preventDefault();event.stopImmediatePropagation();showWizard();
|
||||
event.preventDefault();event.stopImmediatePropagation();setMode('');showWizard();
|
||||
},true);
|
||||
}
|
||||
if(closeButton){
|
||||
@@ -81,14 +96,29 @@
|
||||
dialog.addEventListener('cancel',function(event){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();},true);
|
||||
dialog.addEventListener('click',function(event){if(event.target===dialog){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();}},true);
|
||||
|
||||
// Every wizard POST explicitly preserves the open state before the
|
||||
// browser leaves the page. Validation errors therefore return to the
|
||||
// same wizard step instead of closing/resetting the dialog.
|
||||
[].slice.call(dialog.querySelectorAll('form[data-bratonien-wizard-form]')).forEach(function(form){
|
||||
form.addEventListener('submit',function(){setOpen(true);},true);
|
||||
form.addEventListener('submit',function(event){
|
||||
var submitter=event.submitter;
|
||||
setOpen(true);
|
||||
if(submitter&&submitter.hasAttribute('data-bratonien-wizard-end')){
|
||||
setOpen(false);
|
||||
if(submitter.value==='nc_connector_wizard_reset'||submitter.value==='nc_connector_wizard_finish')setMode('');
|
||||
}
|
||||
},true);
|
||||
});
|
||||
|
||||
[].slice.call(section.querySelectorAll('form')).forEach(function(form){
|
||||
var editButton=form.querySelector('button[value="nc_connector_edit_start"]');
|
||||
if(!editButton)return;
|
||||
form.addEventListener('submit',function(event){
|
||||
if(event.submitter&&event.submitter.value==='nc_connector_edit_start'){
|
||||
setMode('edit');setOpen(true);
|
||||
}
|
||||
},true);
|
||||
});
|
||||
|
||||
try{if(sessionStorage.getItem(storageKey)==='1')showWizard();}catch(e){}
|
||||
applyMode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ if (!defined('BRATONIEN_TOOLS_PATH'))
|
||||
define('BRATONIEN_TOOLS_PATH', PHPWG_ROOT_PATH.'plugins/'.BRATONIEN_TOOLS_ID.'/');
|
||||
}
|
||||
require_once(BRATONIEN_TOOLS_PATH.'include/webdav_image_runtime.inc.php');
|
||||
require_once(BRATONIEN_TOOLS_PATH.'include/nc_transport.inc.php');
|
||||
|
||||
function bratonien_tools_webdav_image_abort($status, $message)
|
||||
{
|
||||
@@ -120,7 +121,7 @@ $options = array(
|
||||
CURLOPT_USERPWD => $user.':'.$password,
|
||||
CURLOPT_RETURNTRANSFER => false,
|
||||
CURLOPT_FAILONERROR => false,
|
||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.6.1',
|
||||
CURLOPT_USERAGENT => 'Bratonien-Tools-WebDAV-Image/0.9.7.16',
|
||||
CURLOPT_HEADERFUNCTION => function($ch, $line)
|
||||
{
|
||||
$length = strlen($line);
|
||||
@@ -147,6 +148,7 @@ $options = array(
|
||||
return strlen($data);
|
||||
},
|
||||
);
|
||||
bratonien_tools_nc_transport_apply_curl($options, $url);
|
||||
if (!empty($_SERVER['HTTP_RANGE']))
|
||||
{
|
||||
$range = trim((string)$_SERVER['HTTP_RANGE']);
|
||||
|
||||
Reference in New Issue
Block a user