mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 22:14:33 +00:00
Compare commits
70 Commits
fix/root-s
...
temp-noop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
14
.github/workflows/lint.yml
vendored
14
.github/workflows/lint.yml
vendored
@@ -5,8 +5,12 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
syntax:
|
php-syntax:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
php-version: ['8.2', '8.3', '8.4', '8.5']
|
||||||
steps:
|
steps:
|
||||||
- name: Repository auschecken
|
- name: Repository auschecken
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -14,7 +18,7 @@ jobs:
|
|||||||
- name: PHP installieren
|
- name: PHP installieren
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: '8.2'
|
php-version: ${{ matrix.php-version }}
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
- name: PHP Syntax pruefen
|
- name: PHP Syntax pruefen
|
||||||
@@ -36,6 +40,12 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
script-syntax:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Repository auschecken
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Admin JavaScript Syntax pruefen
|
- name: Admin JavaScript Syntax pruefen
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
93
admin.php
93
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/tool_registry.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_system.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();
|
$tools = bratonien_tools_get_tools();
|
||||||
$messages = array();
|
$messages = array();
|
||||||
$errors = 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;
|
$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())
|
if (!headers_sent())
|
||||||
{
|
{
|
||||||
header('Location: '.$redirect_url, true, 303);
|
header('Location: '.$redirect_url, true, 303);
|
||||||
@@ -115,9 +196,17 @@ $asset_environment = bratonien_tools_get_asset_environment();
|
|||||||
$album_shares = bratonien_tools_get_album_shares();
|
$album_shares = bratonien_tools_get_album_shares();
|
||||||
$private_albums = bratonien_tools_get_private_albums();
|
$private_albums = bratonien_tools_get_private_albums();
|
||||||
$nc_connector = bratonien_tools_nc_connector_status();
|
$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)
|
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'];
|
$nc_connection['display_name'] = $nc_connection['name'];
|
||||||
|
|
||||||
$storage_lines = array();
|
$storage_lines = array();
|
||||||
@@ -166,7 +255,7 @@ $nc_system_defaults = array(
|
|||||||
);
|
);
|
||||||
$nc_connector['system'] = array_merge(
|
$nc_connector['system'] = array_merge(
|
||||||
$nc_system_defaults,
|
$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_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']) : '';
|
$album_lock_search = isset($_GET['br_album_search']) ? trim((string)$_GET['br_album_search']) : '';
|
||||||
|
|||||||
@@ -36,14 +36,7 @@ function bratonien_tools_nc_connector_remove_webdav_piwigo_content(array $connec
|
|||||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||||
|
|
||||||
$image_rows = array();
|
$image_rows = array();
|
||||||
$query = '
|
$query = '\nSELECT DISTINCT i.id, i.path, i.representative_ext\n FROM '.IMAGES_TABLE.' AS i\n LEFT JOIN '.CATEGORIES_TABLE.' AS sc ON sc.id = i.storage_category_id\n LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id\n LEFT JOIN '.CATEGORIES_TABLE.' AS vc ON vc.id = ic.category_id\n WHERE sc.site_id = '.$site_id.' OR vc.site_id = '.$site_id.'\n;';
|
||||||
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($query);
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
{
|
{
|
||||||
@@ -84,10 +77,8 @@ SELECT DISTINCT i.id, i.path, i.representative_ext
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a connector connection from Piwigo without depending on the web
|
* Delete exactly the connection selected by the user.
|
||||||
* server being allowed to write into root-owned runtime directories.
|
* No other connector record is implicitly removed.
|
||||||
* WebDAV-managed Piwigo records are removed before the connection itself so
|
|
||||||
* deleted remote content cannot remain visible or addressable in Piwigo.
|
|
||||||
*/
|
*/
|
||||||
function bratonien_tools_nc_connector_delete_safe()
|
function bratonien_tools_nc_connector_delete_safe()
|
||||||
{
|
{
|
||||||
@@ -112,10 +103,7 @@ function bratonien_tools_nc_connector_delete_safe()
|
|||||||
|
|
||||||
$status_dir = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-connector-status';
|
$status_dir = rtrim(PHPWG_ROOT_PATH, '/').'/_data/bratonien-tools/nc-connector-status';
|
||||||
$public_status = $status_dir.'/connection-'.$id.'.json';
|
$public_status = $status_dir.'/connection-'.$id.'.json';
|
||||||
if (is_file($public_status))
|
if (is_file($public_status)) @unlink($public_status);
|
||||||
{
|
|
||||||
@unlink($public_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dir($status_dir) || @mkdir($status_dir, 0755, true))
|
if (is_dir($status_dir) || @mkdir($status_dir, 0755, true))
|
||||||
{
|
{
|
||||||
@@ -125,11 +113,11 @@ function bratonien_tools_nc_connector_delete_safe()
|
|||||||
if ((int)$cleanup['site_id'] > 0)
|
if ((int)$cleanup['site_id'] > 0)
|
||||||
{
|
{
|
||||||
return array(
|
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.',
|
'message'=>'Verbindung wurde gelöscht. Die zugehörigen Piwigo-Alben und '.(int)$cleanup['images'].' Bilder wurden aus Piwigo entfernt. Nextcloud-Dateien blieben unverändert.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
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. Verbliebene Laufzeitdaten werden automatisch bereinigt. Quelldateien blieben unverändert.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,22 @@ function bratonien_tools_nc_connector_migration_state(array $connection)
|
|||||||
if (trim((string)($config['nextcloud_url'] ?? '')) === '') $missing[] = 'Nextcloud-Adresse';
|
if (trim((string)($config['nextcloud_url'] ?? '')) === '') $missing[] = 'Nextcloud-Adresse';
|
||||||
if (trim((string)($credentials['nextcloud_user'] ?? '')) === '') $missing[] = 'Nextcloud-Benutzer';
|
if (trim((string)($credentials['nextcloud_user'] ?? '')) === '') $missing[] = 'Nextcloud-Benutzer';
|
||||||
if ((string)($credentials['nextcloud_password'] ?? '') === '') $missing[] = 'Nextcloud-Passwort';
|
if ((string)($credentials['nextcloud_password'] ?? '') === '') $missing[] = 'Nextcloud-Passwort';
|
||||||
if (trim((string)($credentials['api_key_id'] ?? '')) === '') $missing[] = 'Piwigo-API-Schluessel-ID';
|
|
||||||
if (trim((string)($credentials['api_key_secret'] ?? '')) === '') $missing[] = 'Piwigo-API-Geheimnis';
|
$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(
|
return array(
|
||||||
'ready'=>!$missing,
|
'ready'=>!$missing,
|
||||||
'missing'=>$missing,
|
'missing'=>$missing,
|
||||||
|
'api_available'=>$api_complete,
|
||||||
|
'fallback_available'=>$fallback_complete,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +122,7 @@ function bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection(arra
|
|||||||
{
|
{
|
||||||
$path = trim((string)($root['webdav_path'] ?? ''), '/');
|
$path = trim((string)($root['webdav_path'] ?? ''), '/');
|
||||||
$fileid = (int)($root['fileid'] ?? 0);
|
$fileid = (int)($root['fileid'] ?? 0);
|
||||||
if ($path === '' || $fileid < 1) continue;
|
if ($fileid < 1) continue;
|
||||||
$selected[] = $path;
|
$selected[] = $path;
|
||||||
$selected_ids[$path] = $fileid;
|
$selected_ids[$path] = $fileid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ function bratonien_tools_nc_connector_last_status(array $connections)
|
|||||||
|
|
||||||
foreach ($connections as $connection)
|
foreach ($connections as $connection)
|
||||||
{
|
{
|
||||||
if (empty($connection['enabled']) || (string)($connection['takeover_state'] ?? '') !== 'active')
|
if (empty($connection['enabled']))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -190,6 +190,13 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
|
|||||||
$timer = 'bratonien-nc-connector.timer';
|
$timer = 'bratonien-nc-connector.timer';
|
||||||
$service = 'bratonien-nc-connector.service';
|
$service = 'bratonien-nc-connector.service';
|
||||||
|
|
||||||
|
$active = bratonien_tools_nc_connector_systemctl_value(array('is-active', $timer));
|
||||||
|
$enabled = bratonien_tools_nc_connector_systemctl_value(array('is-enabled', $timer));
|
||||||
|
$service_active_raw = bratonien_tools_nc_connector_systemctl_value(array('is-active', $service));
|
||||||
|
$service_active = in_array($service_active_raw, array('active', 'activating'), true);
|
||||||
|
$service_started_raw = bratonien_tools_nc_connector_systemctl_value(array('show', $service, '--property=ActiveEnterTimestamp', '--value'));
|
||||||
|
$service_started_timestamp = bratonien_tools_nc_connector_parse_systemd_time($service_started_raw);
|
||||||
|
|
||||||
$next_realtime_raw = bratonien_tools_nc_connector_systemctl_value(array('show', $timer, '--property=NextElapseUSecRealtime', '--value'));
|
$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);
|
$next_timestamp = bratonien_tools_nc_connector_parse_systemd_time($next_realtime_raw);
|
||||||
|
|
||||||
@@ -204,9 +211,6 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
|
|||||||
$next_timestamp = bratonien_tools_nc_connector_next_from_timer_list($timer);
|
$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));
|
|
||||||
|
|
||||||
$last = bratonien_tools_nc_connector_last_status($connections);
|
$last = bratonien_tools_nc_connector_last_status($connections);
|
||||||
if ($last['timestamp'] <= 0)
|
if ($last['timestamp'] <= 0)
|
||||||
{
|
{
|
||||||
@@ -214,10 +218,32 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
|
|||||||
$last['timestamp'] = bratonien_tools_nc_connector_parse_systemd_time($last_raw);
|
$last['timestamp'] = bratonien_tools_nc_connector_parse_systemd_time($last_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($next_timestamp > 0)
|
||||||
|
{
|
||||||
|
$next_label = date('d.m.Y H:i:s', $next_timestamp);
|
||||||
|
}
|
||||||
|
elseif ($service_active && $active === 'active' && $enabled === 'enabled')
|
||||||
|
{
|
||||||
|
$next_label = 'Nach Abschluss des aktuellen Laufs';
|
||||||
|
}
|
||||||
|
elseif ($active === 'active' && $enabled === 'enabled')
|
||||||
|
{
|
||||||
|
$next_label = 'Wird von systemd neu geplant';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$next_label = 'Nicht verfügbar';
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'timer_name' => $timer,
|
'timer_name' => $timer,
|
||||||
'timer_active' => $active === 'active',
|
'timer_active' => $active === 'active',
|
||||||
'timer_enabled' => $enabled === 'enabled',
|
'timer_enabled' => $enabled === 'enabled',
|
||||||
|
'service_active' => $service_active,
|
||||||
|
'current_run_timestamp' => $service_started_timestamp,
|
||||||
|
'current_run_label' => $service_active
|
||||||
|
? ($service_started_timestamp > 0 ? 'Läuft seit '.date('d.m.Y H:i:s', $service_started_timestamp) : 'Läuft gerade')
|
||||||
|
: 'Kein Lauf aktiv',
|
||||||
'last_run_timestamp' => (int)$last['timestamp'],
|
'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_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_state' => (string)$last['state'],
|
||||||
@@ -229,7 +255,7 @@ function bratonien_tools_nc_connector_system_status(array $connections = array()
|
|||||||
'last_run_fallback_message' => (string)$last['fallback_message'],
|
'last_run_fallback_message' => (string)$last['fallback_message'],
|
||||||
'last_run_error_detail' => (string)$last['error_detail'],
|
'last_run_error_detail' => (string)$last['error_detail'],
|
||||||
'next_run_timestamp' => $next_timestamp,
|
'next_run_timestamp' => $next_timestamp,
|
||||||
'next_run_label' => $next_timestamp > 0 ? date('d.m.Y H:i:s', $next_timestamp) : 'Nicht verfügbar',
|
'next_run_label' => $next_label,
|
||||||
'legacy_runtime_exists' => is_dir('/opt/piwigo-sync'),
|
'legacy_runtime_exists' => is_dir('/opt/piwigo-sync'),
|
||||||
'legacy_config_exists' => is_dir('/etc/piwigo-sync'),
|
'legacy_config_exists' => is_dir('/etc/piwigo-sync'),
|
||||||
'legacy_service_exists' => is_file('/etc/systemd/system/piwigo-sync.service'),
|
'legacy_service_exists' => is_file('/etc/systemd/system/piwigo-sync.service'),
|
||||||
|
|||||||
@@ -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,81 +5,8 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the only existing local connector as migration fallback.
|
* Create or update one independent WebDAV connector connection.
|
||||||
*/
|
* No migration pair, successor or implicit legacy fallback is created.
|
||||||
function bratonien_tools_nc_connector_single_local_fallback()
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_connector_ensure_table();
|
|
||||||
$table = bratonien_tools_nc_connector_table();
|
|
||||||
$result = pwg_query("SELECT id, enabled, takeover_state, config_json FROM `$table` WHERE adapter='local' ORDER BY id");
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
|
||||||
{
|
|
||||||
$rows[] = $row;
|
|
||||||
if (count($rows) > 1) return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($rows) !== 1) return null;
|
|
||||||
|
|
||||||
$row = $rows[0];
|
|
||||||
$config = json_decode((string)$row['config_json'], true);
|
|
||||||
if (!is_array($config)) $config = array();
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'id'=>(int)$row['id'],
|
|
||||||
'enabled'=>(bool)$row['enabled'],
|
|
||||||
'takeover_state'=>(string)$row['takeover_state'],
|
|
||||||
'config'=>$config,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Link a WebDAV connection with the single existing local fallback.
|
|
||||||
*/
|
|
||||||
function bratonien_tools_nc_connector_pair_migration_fallback($webdav_id, array &$webdav_config, $now)
|
|
||||||
{
|
|
||||||
$legacy = bratonien_tools_nc_connector_single_local_fallback();
|
|
||||||
if (!$legacy) return null;
|
|
||||||
|
|
||||||
$legacy_id = (int)$legacy['id'];
|
|
||||||
if ($legacy_id < 1 || $legacy_id === (int)$webdav_id) return null;
|
|
||||||
|
|
||||||
$webdav_config['migration'] = array(
|
|
||||||
'role'=>'webdav-primary-candidate',
|
|
||||||
'legacy_fallback_connection_id'=>$legacy_id,
|
|
||||||
'fallback_policy'=>'keep-running',
|
|
||||||
'paired_at'=>(string)$now,
|
|
||||||
'cutover_state'=>'parallel',
|
|
||||||
);
|
|
||||||
|
|
||||||
$legacy_config = $legacy['config'];
|
|
||||||
$legacy_config['migration'] = array(
|
|
||||||
'role'=>'legacy-fallback',
|
|
||||||
'webdav_successor_connection_id'=>(int)$webdav_id,
|
|
||||||
'fallback_policy'=>'keep-running',
|
|
||||||
'paired_at'=>(string)$now,
|
|
||||||
'cutover_state'=>'parallel',
|
|
||||||
);
|
|
||||||
|
|
||||||
$legacy_json = json_encode($legacy_config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
||||||
if (!is_string($legacy_json))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Die bestehende Verbindung konnte nicht als Migrations-Fallback markiert werden.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$table = bratonien_tools_nc_connector_table();
|
|
||||||
pwg_query("UPDATE `$table` SET config_json='".pwg_db_real_escape_string($legacy_json)."', updated='".pwg_db_real_escape_string((string)$now)."' WHERE id=".$legacy_id." LIMIT 1");
|
|
||||||
|
|
||||||
return $legacy_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create or update a WebDAV-backed connector from the user-facing wizard.
|
|
||||||
*
|
|
||||||
* Remote connections are updated in place. When the editor was opened for a
|
|
||||||
* legacy connection, a WebDAV successor is created and the legacy connection
|
|
||||||
* stays available as fallback.
|
|
||||||
*/
|
*/
|
||||||
function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
||||||
{
|
{
|
||||||
@@ -87,7 +14,7 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
|
|
||||||
if (empty($state['scan_ok']) || empty($state['technical_complete']))
|
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'] ?? '')), '/');
|
$base_url = rtrim(trim((string)($state['base_url'] ?? '')), '/');
|
||||||
@@ -95,7 +22,7 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
$password = (string)($state['_password'] ?? '');
|
$password = (string)($state['_password'] ?? '');
|
||||||
if ($base_url === '' || $username === '' || $password === '')
|
if ($base_url === '' || $username === '' || $password === '')
|
||||||
{
|
{
|
||||||
throw new RuntimeException('Für den WebDAV-Zugang 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'])
|
$selected = isset($state['directory_selected']) && is_array($state['directory_selected'])
|
||||||
@@ -104,13 +31,20 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
$selected_ids = isset($state['directory_selected_fileids']) && is_array($state['directory_selected_fileids'])
|
$selected_ids = isset($state['directory_selected_fileids']) && is_array($state['directory_selected_fileids'])
|
||||||
? $state['directory_selected_fileids']
|
? $state['directory_selected_fileids']
|
||||||
: array();
|
: array();
|
||||||
if (!$selected) throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis auswählen.');
|
|
||||||
|
if (!$selected)
|
||||||
|
{
|
||||||
|
$selected = array('');
|
||||||
|
}
|
||||||
|
|
||||||
$roots = array();
|
$roots = array();
|
||||||
foreach ($selected as $path)
|
foreach ($selected as $path)
|
||||||
{
|
{
|
||||||
$fileid = isset($selected_ids[$path]) ? (int)$selected_ids[$path] : 0;
|
$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 === ''
|
$display_name = $path === ''
|
||||||
? (trim((string)($state['display_name'] ?? '')) !== '' ? trim((string)$state['display_name']) : $username)
|
? (trim((string)($state['display_name'] ?? '')) !== '' ? trim((string)$state['display_name']) : $username)
|
||||||
: basename($path);
|
: basename($path);
|
||||||
@@ -140,6 +74,11 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
&& (string)($editing_connection['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
&& (string)($editing_connection['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
||||||
&& $editing_mode === 'update';
|
&& $editing_mode === 'update';
|
||||||
|
|
||||||
|
if ($editing_mode === 'migrate')
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Die Migrationsfunktion wurde entfernt. Bitte eine normale WebDAV-Verbindung anlegen.');
|
||||||
|
}
|
||||||
|
|
||||||
$config = array(
|
$config = array(
|
||||||
'origin'=>'native',
|
'origin'=>'native',
|
||||||
'source_mode'=>'webdav-placeholder',
|
'source_mode'=>'webdav-placeholder',
|
||||||
@@ -154,7 +93,6 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
'quiet_seconds'=>120,
|
'quiet_seconds'=>120,
|
||||||
'max_wait_seconds'=>900,
|
'max_wait_seconds'=>900,
|
||||||
'full_sync_seconds'=>86400,
|
'full_sync_seconds'=>86400,
|
||||||
'parallel_test'=>true,
|
|
||||||
'piwigo_auth'=>'connection-scoped',
|
'piwigo_auth'=>'connection-scoped',
|
||||||
'api_enabled'=>$api_enabled,
|
'api_enabled'=>$api_enabled,
|
||||||
);
|
);
|
||||||
@@ -162,7 +100,7 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
if ($editing_remote)
|
if ($editing_remote)
|
||||||
{
|
{
|
||||||
$old_config = is_array($editing_connection['config'] ?? null) ? $editing_connection['config'] : array();
|
$old_config = is_array($editing_connection['config'] ?? null) ? $editing_connection['config'] : array();
|
||||||
foreach (array('state_dir','status_file','parallel_gallery_root','source_fingerprint','runtime','migration') as $preserve)
|
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];
|
if (array_key_exists($preserve, $old_config)) $config[$preserve] = $old_config[$preserve];
|
||||||
}
|
}
|
||||||
@@ -202,12 +140,12 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
$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.');
|
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." LIMIT 1");
|
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']);
|
unset($_SESSION['bratonien_nc_wizard']);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'connection_id'=>$editing_id,
|
'connection_id'=>$editing_id,
|
||||||
'message'=>'WebDAV-Verbindung #'.$editing_id.' wurde gespeichert. Der nächste Connector-Lauf verwendet die neuen Einstellungen.',
|
'message'=>'WebDAV-Verbindung wurde gespeichert.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,36 +164,14 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
$id = (int)pwg_db_insert_id();
|
$id = (int)pwg_db_insert_id();
|
||||||
if ($id < 1) throw new RuntimeException('Die WebDAV-Verbindung konnte nicht eindeutig angelegt werden.');
|
if ($id < 1) throw new RuntimeException('Die WebDAV-Verbindung konnte nicht eindeutig angelegt werden.');
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$config['state_dir'] = '/var/lib/bratonien-tools/nc-connector/connection-'.$id;
|
$config['state_dir'] = '/var/lib/bratonien-tools/nc-connector/connection-'.$id;
|
||||||
$config['status_file'] = $config['state_dir'].'/connector-status.json';
|
$config['status_file'] = $config['state_dir'].'/connector-status.json';
|
||||||
$legacy_fallback_id = bratonien_tools_nc_connector_pair_migration_fallback($id, $config, $now);
|
|
||||||
|
|
||||||
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
$config_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
if (!is_string($config_json))
|
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");
|
||||||
throw new RuntimeException('Die WebDAV-Verbindung 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");
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
pwg_query("DELETE FROM `$table` WHERE id=".$id." LIMIT 1");
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($_SESSION['bratonien_nc_wizard']);
|
unset($_SESSION['bratonien_nc_wizard']);
|
||||||
|
|
||||||
if ($legacy_fallback_id !== null)
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'connection_id'=>$id,
|
|
||||||
'legacy_fallback_connection_id'=>$legacy_fallback_id,
|
|
||||||
'message'=>'WebDAV-Nachfolger wurde angelegt. Die bestehende lokale Verbindung #'.$legacy_fallback_id.' bleibt als Fallback erhalten.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'connection_id'=>$id,
|
'connection_id'=>$id,
|
||||||
'message'=>'WebDAV-Verbindung wurde angelegt.',
|
'message'=>'WebDAV-Verbindung wurde angelegt.',
|
||||||
|
|||||||
@@ -158,9 +158,35 @@ function bratonien_tools_nc_wizard_save_sources_dispatch()
|
|||||||
$state['technical_source'] = 'WebDAV-Verzeichnisse ausgewählt';
|
$state['technical_source'] = 'WebDAV-Verzeichnisse ausgewählt';
|
||||||
$state['technical_error'] = '';
|
$state['technical_error'] = '';
|
||||||
$state['directory_selection_ready'] = false;
|
$state['directory_selection_ready'] = false;
|
||||||
|
|
||||||
|
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);
|
bratonien_tools_nc_wizard_store($state);
|
||||||
|
|
||||||
return array('message'=>'WebDAV-Verzeichnisse wurden übernommen. Die Verbindung ist für den parallelen Testweg vorbereitet.');
|
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()
|
function bratonien_tools_nc_wizard_finish_dispatch()
|
||||||
|
|||||||
@@ -6,19 +6,13 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
|
|
||||||
if (isset($GLOBALS['template']) && is_object($GLOBALS['template']) && method_exists($GLOBALS['template'], 'func_combine_script'))
|
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.6.15';
|
$script_version = function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : '0.9.6.27';
|
||||||
$GLOBALS['template']->func_combine_script(array(
|
$GLOBALS['template']->func_combine_script(array(
|
||||||
'id'=>'bratonien_nc_connector_edit_v2',
|
'id'=>'bratonien_nc_connector_edit_v2',
|
||||||
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_edit_v2.js',
|
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_edit_v2.js',
|
||||||
'load'=>'footer',
|
'load'=>'footer',
|
||||||
'version'=>$script_version,
|
'version'=>$script_version,
|
||||||
));
|
));
|
||||||
$GLOBALS['template']->func_combine_script(array(
|
|
||||||
'id'=>'bratonien_nc_connector_source_ui',
|
|
||||||
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_source_ui.js',
|
|
||||||
'load'=>'footer',
|
|
||||||
'version'=>$script_version,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'tools/image_cache.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'tools/image_cache.inc.php');
|
||||||
@@ -34,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/album_lock.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector.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_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_auth.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_create_api.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');
|
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_piwigo_api.inc.php');
|
||||||
@@ -48,6 +41,58 @@ 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_webdav.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_wizard_webdav_flow.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_connector_edit.inc.php');
|
||||||
|
require_once(BRATONIEN_TOOLS_PATH . 'include/nc_connector_system.inc.php');
|
||||||
|
|
||||||
|
function bratonien_tools_nc_connector_run_now()
|
||||||
|
{
|
||||||
|
$service = 'bratonien-nc-connector.service';
|
||||||
|
$active = bratonien_tools_nc_connector_systemctl_value(array('is-active', $service));
|
||||||
|
if ($active === 'active' || $active === 'activating')
|
||||||
|
{
|
||||||
|
return array('message'=>'Der NC-Abgleich läuft bereits.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('proc_open'))
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Der NC-Abgleich konnte nicht gestartet werden: proc_open ist nicht verfügbar.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$commands = array(
|
||||||
|
array('/usr/bin/sudo', '-n', '/usr/bin/systemctl', 'start', '--no-block', $service),
|
||||||
|
array('/usr/bin/systemctl', 'start', '--no-block', $service),
|
||||||
|
);
|
||||||
|
$last_error = '';
|
||||||
|
|
||||||
|
foreach ($commands as $command)
|
||||||
|
{
|
||||||
|
if (!is_executable($command[0]))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$spec = array(
|
||||||
|
0=>array('file','/dev/null','r'),
|
||||||
|
1=>array('pipe','w'),
|
||||||
|
2=>array('pipe','w'),
|
||||||
|
);
|
||||||
|
$process = @proc_open($command, $spec, $pipes, null, array_merge($_ENV, array('LC_ALL'=>'C','LANG'=>'C')));
|
||||||
|
if (!is_resource($process))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$stdout = trim((string)stream_get_contents($pipes[1]));
|
||||||
|
$stderr = trim((string)stream_get_contents($pipes[2]));
|
||||||
|
fclose($pipes[1]);
|
||||||
|
fclose($pipes[2]);
|
||||||
|
$exit = proc_close($process);
|
||||||
|
if ($exit === 0)
|
||||||
|
{
|
||||||
|
return array('message'=>'NC-Abgleich wurde gestartet.');
|
||||||
|
}
|
||||||
|
$last_error = $stderr !== '' ? $stderr : $stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException('Der NC-Abgleich konnte nicht gestartet werden'.($last_error !== '' ? ': '.$last_error : '.'));
|
||||||
|
}
|
||||||
|
|
||||||
function bratonien_tools_get_tools()
|
function bratonien_tools_get_tools()
|
||||||
{
|
{
|
||||||
@@ -72,14 +117,13 @@ function bratonien_tools_get_tools()
|
|||||||
'album_share_create' => array('handler' => 'bratonien_tools_create_album_share'),
|
'album_share_create' => array('handler' => 'bratonien_tools_create_album_share'),
|
||||||
'album_share_regenerate_link' => array('handler' => 'bratonien_tools_regenerate_album_share_link'),
|
'album_share_regenerate_link' => array('handler' => 'bratonien_tools_regenerate_album_share_link'),
|
||||||
'album_share_revoke' => array('handler' => 'bratonien_tools_revoke_album_share'),
|
'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_create_webdav_parallel' => array('handler' => 'bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard'),
|
||||||
'nc_connector_edit_start' => array('handler' => 'bratonien_tools_nc_connector_edit_start'),
|
'nc_connector_edit_start' => array('handler' => 'bratonien_tools_nc_connector_edit_start'),
|
||||||
'nc_connector_migrate_start' => array('handler' => 'bratonien_tools_nc_connector_migrate_start'),
|
|
||||||
'nc_connector_update_local' => array('handler' => 'bratonien_tools_nc_connector_update_local_friendly'),
|
'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_delete' => array('handler' => 'bratonien_tools_nc_connector_delete_safe'),
|
||||||
'nc_connector_update_name' => array('handler' => 'bratonien_tools_nc_connector_update_name'),
|
'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_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_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_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_wizard_directory_browse'),
|
||||||
@@ -92,10 +136,7 @@ function bratonien_tools_get_tools()
|
|||||||
'nc_connector_wizard_finish' => array('handler' => 'bratonien_tools_nc_wizard_finish_dispatch'),
|
'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_back' => array('handler' => 'bratonien_tools_nc_wizard_back'),
|
||||||
'nc_connector_wizard_reset' => array('handler' => 'bratonien_tools_nc_wizard_reset'),
|
'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_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_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_piwigo_api_delete' => array('handler' => 'bratonien_tools_nc_connector_api_delete'),
|
||||||
'nc_connector_fallback_save' => array('handler' => 'bratonien_tools_nc_connector_fallback_save_scoped'),
|
'nc_connector_fallback_save' => array('handler' => 'bratonien_tools_nc_connector_fallback_save_scoped'),
|
||||||
|
|||||||
@@ -2,48 +2,53 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function ready(callback) {
|
function ready(callback) {
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', callback);
|
||||||
document.addEventListener('DOMContentLoaded', function () { window.setTimeout(callback, 0); });
|
else callback();
|
||||||
} else {
|
|
||||||
window.setTimeout(callback, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ready(function () {
|
ready(function () {
|
||||||
var section = document.getElementById('nc-connector');
|
var section = document.getElementById('nc-connector');
|
||||||
if (!section) return;
|
if (!section) return;
|
||||||
|
|
||||||
var pwgTokenInput = section.querySelector('input[name="pwg_token"]');
|
var tokenInput = section.querySelector('input[name="pwg_token"]');
|
||||||
var pwgToken = pwgTokenInput ? pwgTokenInput.value : '';
|
var pwgToken = tokenInput ? tokenInput.value : '';
|
||||||
var modeKey = 'bratonienNcWizardMode';
|
|
||||||
|
var technicalButton = document.getElementById('bratonien-nc-technical-open');
|
||||||
|
if (technicalButton) technicalButton.remove();
|
||||||
|
var technicalCreate = document.getElementById('bratonien-nc-technical-create');
|
||||||
|
if (technicalCreate) technicalCreate.remove();
|
||||||
|
|
||||||
|
var statusHeading = Array.prototype.find.call(section.querySelectorAll('h4'), function (heading) {
|
||||||
|
return heading.textContent.trim() === 'Status';
|
||||||
|
});
|
||||||
|
var statusCard = statusHeading ? statusHeading.closest('.bratonien-card') : null;
|
||||||
|
if (statusCard && pwgToken && !statusCard.querySelector('[data-nc-run-now]')) {
|
||||||
|
var runForm = document.createElement('form');
|
||||||
|
runForm.method = 'post';
|
||||||
|
runForm.className = 'bratonien-actions';
|
||||||
|
runForm.style.marginTop = '1rem';
|
||||||
|
runForm.setAttribute('data-nc-run-now', '1');
|
||||||
|
runForm.innerHTML = '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
||||||
|
+ '<button class="buttonLike" type="submit" name="bratonien_tool" value="nc_connector_run_now">Jetzt abgleichen</button>';
|
||||||
|
runForm.addEventListener('submit', function () {
|
||||||
|
var button = runForm.querySelector('button');
|
||||||
|
if (button) {
|
||||||
|
button.disabled = true;
|
||||||
|
button.textContent = 'Abgleich wird gestartet …';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
statusCard.appendChild(runForm);
|
||||||
|
}
|
||||||
|
|
||||||
function escapeHtml(value) {
|
function escapeHtml(value) {
|
||||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
||||||
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setMode(value) {
|
|
||||||
try { sessionStorage.setItem(modeKey, value); } catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function postForm(label, tool, id, mode) {
|
|
||||||
var form = document.createElement('form');
|
|
||||||
form.method = 'post';
|
|
||||||
form.style.display = 'inline';
|
|
||||||
form.dataset.ncV2Action = tool;
|
|
||||||
form.innerHTML = '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
|
||||||
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(id)+'">'
|
|
||||||
+ '<button class="buttonLike" type="submit" name="bratonien_tool" value="'+escapeHtml(tool)+'">'+escapeHtml(label)+'</button>';
|
|
||||||
if (mode) form.addEventListener('submit', function () { setMode(mode); }, true);
|
|
||||||
return form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadConnection(id) {
|
function loadConnection(id) {
|
||||||
return fetch('plugins/bratonien_tools/nc-connector-edit-data.php?connection_id='+encodeURIComponent(id)+'&_='+Date.now(), {
|
return fetch('plugins/bratonien_tools/nc-connector-edit-data.php?connection_id='+encodeURIComponent(id)+'&_='+Date.now(), {
|
||||||
credentials:'same-origin',
|
credentials:'same-origin', cache:'no-store', headers:{'Accept':'application/json'}
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'}
|
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
return response.json().then(function (data) {
|
return response.json().then(function (data) {
|
||||||
if (!response.ok) throw new Error(data.error || ('HTTP '+response.status));
|
if (!response.ok) throw new Error(data.error || ('HTTP '+response.status));
|
||||||
@@ -52,6 +57,16 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createPostForm(label, tool, id) {
|
||||||
|
var form = document.createElement('form');
|
||||||
|
form.method = 'post';
|
||||||
|
form.style.display = 'inline';
|
||||||
|
form.innerHTML = '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
||||||
|
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(id)+'">'
|
||||||
|
+ '<button class="buttonLike" type="submit" name="bratonien_tool" value="'+escapeHtml(tool)+'">'+escapeHtml(label)+'</button>';
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
function dialog() {
|
function dialog() {
|
||||||
var node = document.getElementById('bratonien-nc-connection-edit-v2');
|
var node = document.getElementById('bratonien-nc-connection-edit-v2');
|
||||||
if (node) return node;
|
if (node) return node;
|
||||||
@@ -60,11 +75,11 @@
|
|||||||
node.className = 'bratonien-edit-dialog';
|
node.className = 'bratonien-edit-dialog';
|
||||||
node.innerHTML = '<div class="bratonien-edit-dialog__body">'
|
node.innerHTML = '<div class="bratonien-edit-dialog__body">'
|
||||||
+ '<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem">'
|
+ '<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem">'
|
||||||
+ '<div><h4 style="margin:0">Verbindung bearbeiten</h4><p class="bratonien-base-note" style="margin:.35rem 0 0">Alle Daten dieser Verbindung werden hier gepflegt. Eine Migration ist ein eigener Vorgang.</p></div>'
|
+ '<div><h4 style="margin:0">Verbindung bearbeiten</h4><p class="bratonien-base-note" style="margin:.35rem 0 0">Die Einstellungen gelten nur für diese Verbindung.</p></div>'
|
||||||
+ '<button type="button" class="buttonLike" data-edit-v2-close>Schließen</button></div>'
|
+ '<button type="button" class="buttonLike" data-edit-close>Schließen</button></div>'
|
||||||
+ '<div data-edit-v2-content style="margin-top:1rem"></div></div>';
|
+ '<div data-edit-content style="margin-top:1rem"></div></div>';
|
||||||
document.body.appendChild(node);
|
document.body.appendChild(node);
|
||||||
node.querySelector('[data-edit-v2-close]').addEventListener('click', function () { node.close(); });
|
node.querySelector('[data-edit-close]').addEventListener('click', function () { node.close(); });
|
||||||
node.addEventListener('click', function (event) { if (event.target === node) node.close(); });
|
node.addEventListener('click', function (event) { if (event.target === node) node.close(); });
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -78,127 +93,68 @@
|
|||||||
+ '<button type="button" class="buttonLike" data-remove-storage>Entfernen</button></div>';
|
+ '<button type="button" class="buttonLike" data-remove-storage>Entfernen</button></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearValidation(form) {
|
function showError(form, data) {
|
||||||
[].slice.call(form.querySelectorAll('[aria-invalid="true"]')).forEach(function (field) {
|
var old = form.querySelector('[data-edit-error]');
|
||||||
field.removeAttribute('aria-invalid');
|
if (old) old.remove();
|
||||||
field.style.borderColor = '';
|
var box = document.createElement('div');
|
||||||
field.style.boxShadow = '';
|
box.dataset.editError = '1';
|
||||||
});
|
box.className = 'bratonien-main-cache__warning';
|
||||||
[].slice.call(form.querySelectorAll('[data-edit-v2-field-error]')).forEach(function (node) { node.remove(); });
|
box.style.margin = '0 0 1rem';
|
||||||
var box = form.querySelector('[data-edit-v2-error-summary]');
|
box.textContent = (data && data.message) ? data.message : 'Die Verbindung konnte nicht gespeichert werden.';
|
||||||
if (box) box.remove();
|
form.insertBefore(box, form.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fieldNodes(form, fieldName) {
|
function submitLocal(form, editDialog) {
|
||||||
return [].slice.call(form.querySelectorAll('[name="'+fieldName.replace(/"/g, '\\"')+'"]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function showValidation(form, data) {
|
|
||||||
clearValidation(form);
|
|
||||||
var message = (data && data.message) ? data.message : 'Die Verbindung konnte nicht gespeichert werden.';
|
|
||||||
var summary = document.createElement('div');
|
|
||||||
summary.dataset.editV2ErrorSummary = '1';
|
|
||||||
summary.className = 'bratonien-main-cache__warning';
|
|
||||||
summary.style.margin = '0 0 1rem';
|
|
||||||
summary.style.padding = '.75rem';
|
|
||||||
summary.style.border = '1px solid currentColor';
|
|
||||||
summary.innerHTML = '<strong>Speichern fehlgeschlagen:</strong> '+escapeHtml(message);
|
|
||||||
form.insertBefore(summary, form.firstChild);
|
|
||||||
|
|
||||||
var first = null;
|
|
||||||
var fields = data && Array.isArray(data.fields) ? data.fields : [];
|
|
||||||
fields.forEach(function (fieldName) {
|
|
||||||
fieldNodes(form, fieldName).forEach(function (field) {
|
|
||||||
field.setAttribute('aria-invalid', 'true');
|
|
||||||
field.style.borderColor = '#d65a5a';
|
|
||||||
field.style.boxShadow = '0 0 0 1px #d65a5a';
|
|
||||||
if (!first) first = field;
|
|
||||||
var note = document.createElement('span');
|
|
||||||
note.dataset.editV2FieldError = '1';
|
|
||||||
note.className = 'bratonien-main-cache__warning';
|
|
||||||
note.style.display = 'block';
|
|
||||||
note.style.marginTop = '.25rem';
|
|
||||||
note.textContent = message;
|
|
||||||
field.insertAdjacentElement('afterend', note);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (first) {
|
|
||||||
first.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
window.setTimeout(function () { first.focus(); }, 150);
|
|
||||||
} else {
|
|
||||||
summary.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitEditor(form, editDialog) {
|
|
||||||
clearValidation(form);
|
|
||||||
if (!form.reportValidity()) return;
|
if (!form.reportValidity()) return;
|
||||||
|
var button = form.querySelector('button[type="submit"]');
|
||||||
var submit = form.querySelector('button[type="submit"]');
|
if (button) button.disabled = true;
|
||||||
if (submit) submit.disabled = true;
|
|
||||||
|
|
||||||
var body = new FormData(form);
|
|
||||||
fetch('plugins/bratonien_tools/nc-connector-edit-save.php', {
|
fetch('plugins/bratonien_tools/nc-connector-edit-save.php', {
|
||||||
method:'POST',
|
method:'POST', credentials:'same-origin', cache:'no-store', headers:{'Accept':'application/json'}, body:new FormData(form)
|
||||||
credentials:'same-origin',
|
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'},
|
|
||||||
body:body
|
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
return response.json().then(function (data) {
|
return response.json().then(function (data) {
|
||||||
if (!response.ok || !data.ok) {
|
if (!response.ok || !data.ok) { showError(form, data); return; }
|
||||||
showValidation(form, data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editDialog.close();
|
editDialog.close();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
showValidation(form, {message:error.message || String(error), fields:[]});
|
showError(form, {message:error.message || String(error)});
|
||||||
}).finally(function () {
|
}).finally(function () {
|
||||||
if (submit) submit.disabled = false;
|
if (button) button.disabled = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEditor(id) {
|
function openLocalEditor(id) {
|
||||||
var editDialog = dialog();
|
var editDialog = dialog();
|
||||||
var content = editDialog.querySelector('[data-edit-v2-content]');
|
var content = editDialog.querySelector('[data-edit-content]');
|
||||||
content.innerHTML = '<p class="bratonien-base-note">Verbindung wird geladen …</p>';
|
content.innerHTML = '<p class="bratonien-base-note">Verbindung wird geladen …</p>';
|
||||||
if (typeof editDialog.showModal === 'function') editDialog.showModal();
|
if (typeof editDialog.showModal === 'function') editDialog.showModal();
|
||||||
else editDialog.setAttribute('open', 'open');
|
else editDialog.setAttribute('open', 'open');
|
||||||
|
|
||||||
loadConnection(id).then(function (data) {
|
loadConnection(id).then(function (data) {
|
||||||
if (data.adapter !== 'local') throw new Error('Diese Ansicht ist nur für die bestehende Legacy-Verbindung vorgesehen.');
|
if (data.adapter !== 'local') throw new Error('Diese Verbindung wird über den WebDAV-Assistenten bearbeitet.');
|
||||||
var legacy = data.legacy || {};
|
var legacy = data.legacy || {};
|
||||||
var webdav = data.webdav || {};
|
var webdav = data.webdav || {};
|
||||||
var storages = Array.isArray(legacy.storages) ? legacy.storages : [];
|
var storages = Array.isArray(legacy.storages) ? legacy.storages : [];
|
||||||
var rows = storages.map(storageRow).join('') || storageRow({});
|
var rows = storages.map(storageRow).join('') || storageRow({});
|
||||||
var migrationText = webdav.migration_ready
|
|
||||||
? '<strong>Bereit.</strong> Nextcloud-Zugang und verbindungseigener Piwigo-API-Key sind vollständig gespeichert.'
|
|
||||||
: '<strong>Noch nicht bereit.</strong> Es fehlen: '+escapeHtml((webdav.migration_missing || []).join(', ') || 'WebDAV-Zugangsdaten')+'.';
|
|
||||||
|
|
||||||
content.innerHTML = '<form method="post" data-edit-v2-form>'
|
content.innerHTML = '<form method="post" data-edit-form>'
|
||||||
+ '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
+ '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
||||||
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(data.id)+'">'
|
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(data.id)+'">'
|
||||||
+ '<h5>Verbindung</h5><div class="bratonien-form-grid">'
|
+ '<h5>Verbindung</h5><div class="bratonien-form-grid">'
|
||||||
+ '<label class="bratonien-label">Name</label><input name="connection_name" value="'+escapeHtml(data.name)+'" required>'
|
+ '<label class="bratonien-label">Name</label><input name="connection_name" value="'+escapeHtml(data.name)+'" required>'
|
||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<h5 style="margin-top:1.2rem">Nextcloud / WebDAV</h5>'
|
+ '<h5 style="margin-top:1.2rem">Nextcloud</h5><div class="bratonien-form-grid">'
|
||||||
+ '<p class="bratonien-base-note">Diese Angaben werden für den neuen WebDAV-Weg benötigt und gehören zu genau dieser Verbindung.</p>'
|
+ '<label class="bratonien-label">Nextcloud-Adresse</label><input name="nc_nextcloud_url" value="'+escapeHtml(webdav.nextcloud_url || '')+'">'
|
||||||
+ '<div class="bratonien-form-grid">'
|
|
||||||
+ '<label class="bratonien-label">Nextcloud-Adresse</label><input name="nc_nextcloud_url" value="'+escapeHtml(webdav.nextcloud_url || '')+'" placeholder="https://cloud.example.de">'
|
|
||||||
+ '<label class="bratonien-label">Nextcloud-Benutzer</label><input name="nc_nextcloud_user" value="'+escapeHtml(webdav.nextcloud_user || '')+'" autocomplete="username">'
|
+ '<label class="bratonien-label">Nextcloud-Benutzer</label><input name="nc_nextcloud_user" value="'+escapeHtml(webdav.nextcloud_user || '')+'" autocomplete="username">'
|
||||||
+ '<label class="bratonien-label">Nextcloud-Passwort</label><input name="nc_nextcloud_password" type="password" autocomplete="current-password" placeholder="'+(webdav.has_nextcloud_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
+ '<label class="bratonien-label">Nextcloud-Passwort</label><input name="nc_nextcloud_password" type="password" autocomplete="current-password" placeholder="'+(webdav.has_nextcloud_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<h5 style="margin-top:1.2rem">Piwigo API dieser Verbindung</h5>'
|
+ '<h5 style="margin-top:1.2rem">Piwigo-Zugang</h5><div class="bratonien-form-grid">'
|
||||||
+ '<p class="bratonien-base-note">Der API-Key wird verbindungseigen gespeichert und beim Speichern geprüft.</p>'
|
|
||||||
+ '<div class="bratonien-form-grid">'
|
|
||||||
+ '<label class="bratonien-label">API-Schlüssel-ID</label><input name="nc_connection_api_key_id" value="'+escapeHtml(webdav.api_key_id || '')+'" autocomplete="off">'
|
+ '<label class="bratonien-label">API-Schlüssel-ID</label><input name="nc_connection_api_key_id" value="'+escapeHtml(webdav.api_key_id || '')+'" autocomplete="off">'
|
||||||
+ '<label class="bratonien-label">API-Geheimnis</label><input name="nc_connection_api_key_secret" type="password" autocomplete="new-password" placeholder="'+(webdav.has_api_key_secret ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
+ '<label class="bratonien-label">API-Geheimnis</label><input name="nc_connection_api_key_secret" type="password" autocomplete="new-password" placeholder="'+(webdav.has_api_key_secret ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
||||||
|
+ '<label class="bratonien-label">Fallback-Benutzer</label><input name="nc_fallback_user" value="'+escapeHtml(webdav.fallback_user || '')+'" autocomplete="username">'
|
||||||
|
+ '<label class="bratonien-label">Fallback-Passwort</label><input name="nc_fallback_password" type="password" autocomplete="current-password" placeholder="'+(webdav.has_fallback_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<p class="bratonien-base-note"><strong>WebDAV-Migration:</strong> '+migrationText+'</p>'
|
+ '<h5 style="margin-top:1.2rem">Lokaler Connector</h5><div class="bratonien-form-grid">'
|
||||||
+ '<h5 style="margin-top:1.2rem">Bestehender Legacy-Weg</h5><div class="bratonien-form-grid">'
|
|
||||||
+ '<label class="bratonien-label">Datenbank-Server</label><input name="nc_host" value="'+escapeHtml(legacy.host)+'" required>'
|
+ '<label class="bratonien-label">Datenbank-Server</label><input name="nc_host" value="'+escapeHtml(legacy.host)+'" required>'
|
||||||
+ '<label class="bratonien-label">Port</label><input name="nc_port" type="number" min="1" max="65535" value="'+escapeHtml(legacy.port || 5432)+'" required>'
|
+ '<label class="bratonien-label">Port</label><input name="nc_port" type="number" min="1" max="65535" value="'+escapeHtml(legacy.port || 5432)+'" required>'
|
||||||
+ '<label class="bratonien-label">Datenbank</label><input name="nc_database" value="'+escapeHtml(legacy.database)+'" required>'
|
+ '<label class="bratonien-label">Datenbank</label><input name="nc_database" value="'+escapeHtml(legacy.database)+'" required>'
|
||||||
@@ -207,7 +163,7 @@
|
|||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<h5 style="margin-top:1.2rem">Speicherorte</h5><div data-storage-list>'+rows+'</div>'
|
+ '<h5 style="margin-top:1.2rem">Speicherorte</h5><div data-storage-list>'+rows+'</div>'
|
||||||
+ '<button type="button" class="buttonLike" data-add-storage>Speicherort hinzufügen</button>'
|
+ '<button type="button" class="buttonLike" data-add-storage>Speicherort hinzufügen</button>'
|
||||||
+ '<details style="margin-top:1rem"><summary>Erweiterte Legacy-Einstellungen</summary><div class="bratonien-form-grid" style="margin-top:.75rem">'
|
+ '<details style="margin-top:1rem"><summary>Erweiterte Einstellungen</summary><div class="bratonien-form-grid" style="margin-top:.75rem">'
|
||||||
+ '<label class="bratonien-label">Source-View</label><input name="nc_source_view" value="'+escapeHtml(legacy.source_view)+'" required>'
|
+ '<label class="bratonien-label">Source-View</label><input name="nc_source_view" value="'+escapeHtml(legacy.source_view)+'" required>'
|
||||||
+ '<label class="bratonien-label">Activity-View</label><input name="nc_activity_view" value="'+escapeHtml(legacy.activity_view)+'" required>'
|
+ '<label class="bratonien-label">Activity-View</label><input name="nc_activity_view" value="'+escapeHtml(legacy.activity_view)+'" required>'
|
||||||
+ '<label class="bratonien-label">Piwigo-Galerieordner</label><input name="nc_gallery_root" value="'+escapeHtml(legacy.gallery_root)+'" required>'
|
+ '<label class="bratonien-label">Piwigo-Galerieordner</label><input name="nc_gallery_root" value="'+escapeHtml(legacy.gallery_root)+'" required>'
|
||||||
@@ -215,108 +171,64 @@
|
|||||||
+ '<label class="bratonien-label">Maximale Wartezeit (Sek.)</label><input name="nc_max_wait_seconds" type="number" min="60" value="'+escapeHtml(legacy.max_wait_seconds)+'">'
|
+ '<label class="bratonien-label">Maximale Wartezeit (Sek.)</label><input name="nc_max_wait_seconds" type="number" min="60" value="'+escapeHtml(legacy.max_wait_seconds)+'">'
|
||||||
+ '<label class="bratonien-label">Vollprüfung nach (Sek.)</label><input name="nc_full_sync_seconds" type="number" min="300" value="'+escapeHtml(legacy.full_sync_seconds)+'">'
|
+ '<label class="bratonien-label">Vollprüfung nach (Sek.)</label><input name="nc_full_sync_seconds" type="number" min="300" value="'+escapeHtml(legacy.full_sync_seconds)+'">'
|
||||||
+ '</div></details>'
|
+ '</div></details>'
|
||||||
+ '<div class="bratonien-actions" style="margin-top:1rem"><button class="buttonLike" type="submit">Änderungen prüfen und speichern</button><button class="buttonLike" type="button" data-edit-v2-cancel>Abbrechen</button></div>'
|
+ '<div class="bratonien-actions" style="margin-top:1rem"><button class="buttonLike" type="submit">Änderungen prüfen und speichern</button><button class="buttonLike" type="button" data-cancel>Abbrechen</button></div>'
|
||||||
+ '</form>';
|
+ '</form>';
|
||||||
|
|
||||||
var form = content.querySelector('[data-edit-v2-form]');
|
var form = content.querySelector('[data-edit-form]');
|
||||||
form.querySelector('[data-edit-v2-cancel]').addEventListener('click', function () { editDialog.close(); });
|
form.querySelector('[data-cancel]').addEventListener('click', function () { editDialog.close(); });
|
||||||
form.querySelector('[data-add-storage]').addEventListener('click', function () {
|
form.querySelector('[data-add-storage]').addEventListener('click', function () {
|
||||||
form.querySelector('[data-storage-list]').insertAdjacentHTML('beforeend', storageRow({}));
|
form.querySelector('[data-storage-list]').insertAdjacentHTML('beforeend', storageRow({}));
|
||||||
});
|
});
|
||||||
form.addEventListener('click', function (event) {
|
form.addEventListener('click', function (event) {
|
||||||
var remove = event.target.closest('[data-remove-storage]');
|
var remove = event.target.closest('[data-remove-storage]');
|
||||||
if (!remove) return;
|
if (remove) {
|
||||||
var row = remove.closest('[data-storage-row]');
|
var row = remove.closest('[data-storage-row]');
|
||||||
if (row) row.remove();
|
if (row) row.remove();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
form.addEventListener('submit', function (event) {
|
form.addEventListener('submit', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
submitLocal(form, editDialog);
|
||||||
submitEditor(form, editDialog);
|
|
||||||
});
|
});
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
content.innerHTML = '<p class="bratonien-main-cache__warning"><strong>Bearbeiten nicht möglich:</strong> '+escapeHtml(error.message || String(error))+'</p>';
|
content.innerHTML = '<p class="bratonien-main-cache__warning"><strong>Bearbeiten nicht möglich:</strong> '+escapeHtml(error.message || String(error))+'</p>';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildLocalActions(deleteForm, id, connectionData) {
|
|
||||||
var actions = deleteForm.parentElement;
|
|
||||||
if (!actions) return;
|
|
||||||
|
|
||||||
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
|
||||||
var migrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
|
||||||
var editStart = form.querySelector('button[value="nc_connector_edit_start"]');
|
|
||||||
if (migrate || editStart) form.remove();
|
|
||||||
});
|
|
||||||
[].slice.call(actions.children).forEach(function (child) {
|
|
||||||
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
|
||||||
if (child.dataset && child.dataset.ncMigrationInfo) child.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
var edit = document.createElement('button');
|
|
||||||
edit.type = 'button';
|
|
||||||
edit.className = 'buttonLike';
|
|
||||||
edit.textContent = 'Bearbeiten';
|
|
||||||
edit.addEventListener('click', function () { openEditor(id); });
|
|
||||||
actions.insertBefore(edit, deleteForm);
|
|
||||||
|
|
||||||
var info = document.createElement('span');
|
|
||||||
info.dataset.ncMigrationInfo = '1';
|
|
||||||
info.className = 'bratonien-base-note';
|
|
||||||
info.textContent = 'WebDAV-Migration wird geprüft …';
|
|
||||||
actions.insertBefore(info, deleteForm);
|
|
||||||
|
|
||||||
var dataPromise = connectionData ? Promise.resolve(connectionData) : loadConnection(id);
|
|
||||||
dataPromise.then(function (data) {
|
|
||||||
var webdav = data.webdav || {};
|
|
||||||
if (webdav.migration_ready) {
|
|
||||||
info.remove();
|
|
||||||
actions.insertBefore(postForm('Auf WebDAV migrieren', 'nc_connector_migrate_start', id, 'migrate'), deleteForm);
|
|
||||||
} else {
|
|
||||||
var missing = (webdav.migration_missing || []).join(', ');
|
|
||||||
info.textContent = 'WebDAV-Migration noch nicht bereit: '+(missing || 'Zugangsdaten fehlen')+'. Zuerst „Bearbeiten“.';
|
|
||||||
}
|
|
||||||
}).catch(function (error) {
|
|
||||||
info.textContent = 'WebDAV-Migration kann nicht geprüft werden: '+(error.message || String(error));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function rebuildRemoteActions(deleteForm, id) {
|
|
||||||
var actions = deleteForm.parentElement;
|
|
||||||
if (!actions) return;
|
|
||||||
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
|
||||||
var oldEdit = form.querySelector('button[value="nc_connector_edit_start"]');
|
|
||||||
var oldMigrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
|
||||||
if (oldEdit || oldMigrate) form.remove();
|
|
||||||
});
|
|
||||||
[].slice.call(actions.children).forEach(function (child) {
|
|
||||||
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
|
||||||
if (child.dataset && child.dataset.ncMigrationInfo) child.remove();
|
|
||||||
});
|
|
||||||
actions.insertBefore(postForm('Bearbeiten', 'nc_connector_edit_start', id, 'edit'), deleteForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
[].slice.call(section.querySelectorAll('button[value="nc_connector_edit_start"]')).forEach(function (button) {
|
[].slice.call(section.querySelectorAll('button[value="nc_connector_edit_start"]')).forEach(function (button) {
|
||||||
var form = button.closest('form');
|
var form = button.closest('form');
|
||||||
if (form) form.remove();
|
if (form) form.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[].slice.call(section.querySelectorAll('button[value="nc_connector_migrate_start"]')).forEach(function (button) {
|
||||||
|
var form = button.closest('form');
|
||||||
|
if (form) form.remove();
|
||||||
|
});
|
||||||
|
|
||||||
[].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) {
|
[].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) {
|
||||||
var deleteForm = deleteButton.closest('form');
|
var deleteForm = deleteButton.closest('form');
|
||||||
if (!deleteForm) return;
|
if (!deleteForm || !deleteForm.parentElement) return;
|
||||||
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
||||||
if (!idInput) return;
|
if (!idInput) return;
|
||||||
var id = idInput.value;
|
var id = idInput.value;
|
||||||
|
var actions = deleteForm.parentElement;
|
||||||
|
|
||||||
loadConnection(id).then(function (data) {
|
loadConnection(id).then(function (data) {
|
||||||
if (data.adapter === 'local') rebuildLocalActions(deleteForm, id, data);
|
var edit;
|
||||||
else rebuildRemoteActions(deleteForm, id);
|
if (data.adapter === 'local') {
|
||||||
|
edit = document.createElement('button');
|
||||||
|
edit.type = 'button';
|
||||||
|
edit.className = 'buttonLike';
|
||||||
|
edit.textContent = 'Bearbeiten';
|
||||||
|
edit.addEventListener('click', function () { openLocalEditor(id); });
|
||||||
|
} else {
|
||||||
|
edit = createPostForm('Bearbeiten', 'nc_connector_edit_start', id);
|
||||||
|
}
|
||||||
|
actions.insertBefore(edit, deleteForm);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
var actions = deleteForm.parentElement;
|
|
||||||
if (!actions) return;
|
|
||||||
var info = document.createElement('span');
|
var info = document.createElement('span');
|
||||||
info.className = 'bratonien-main-cache__warning';
|
info.className = 'bratonien-main-cache__warning';
|
||||||
info.textContent = 'Verbindungstyp konnte nicht geladen werden: '+(error.message || String(error));
|
info.textContent = 'Verbindung konnte nicht geladen werden: '+(error.message || String(error));
|
||||||
actions.insertBefore(info, deleteForm);
|
actions.insertBefore(info, deleteForm);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,217 +0,0 @@
|
|||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
function escapeHtml(value) {
|
|
||||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
|
||||||
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function fieldNodes(form, fieldName) {
|
|
||||||
return [].slice.call(form.querySelectorAll('[name="'+fieldName.replace(/"/g, '\\"')+'"]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearPickerErrors(form) {
|
|
||||||
[].slice.call(form.querySelectorAll('[data-source-picker-error]')).forEach(function (node) { node.remove(); });
|
|
||||||
[].slice.call(form.querySelectorAll('[data-source-picker-invalid="1"]')).forEach(function (field) {
|
|
||||||
field.removeAttribute('data-source-picker-invalid');
|
|
||||||
if (field.getAttribute('aria-invalid') === 'true') field.removeAttribute('aria-invalid');
|
|
||||||
field.style.borderColor = '';
|
|
||||||
field.style.boxShadow = '';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function showPickerError(form, data) {
|
|
||||||
clearPickerErrors(form);
|
|
||||||
var message = data && data.message ? data.message : 'Die Nextcloud-Ordnerauswahl konnte nicht gestartet werden.';
|
|
||||||
var fields = data && Array.isArray(data.fields) ? data.fields : [];
|
|
||||||
|
|
||||||
var summary = document.createElement('div');
|
|
||||||
summary.dataset.sourcePickerError = '1';
|
|
||||||
summary.className = 'bratonien-main-cache__warning';
|
|
||||||
summary.style.margin = '0 0 1rem';
|
|
||||||
summary.style.padding = '.75rem';
|
|
||||||
summary.style.border = '1px solid currentColor';
|
|
||||||
summary.innerHTML = '<strong>Ordnerauswahl nicht möglich:</strong> '+escapeHtml(message);
|
|
||||||
form.insertBefore(summary, form.firstChild);
|
|
||||||
|
|
||||||
var first = null;
|
|
||||||
fields.forEach(function (fieldName) {
|
|
||||||
fieldNodes(form, fieldName).forEach(function (field) {
|
|
||||||
field.dataset.sourcePickerInvalid = '1';
|
|
||||||
field.setAttribute('aria-invalid', 'true');
|
|
||||||
field.style.borderColor = '#d65a5a';
|
|
||||||
field.style.boxShadow = '0 0 0 1px #d65a5a';
|
|
||||||
if (!first) first = field;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (first) {
|
|
||||||
first.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
window.setTimeout(function () { first.focus(); }, 150);
|
|
||||||
} else {
|
|
||||||
summary.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function jsonResponse(response) {
|
|
||||||
return response.json().then(function (data) {
|
|
||||||
if (!response.ok || !data.ok) throw data;
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function startSourcePicker(form, button) {
|
|
||||||
clearPickerErrors(form);
|
|
||||||
if (!form.reportValidity()) return;
|
|
||||||
|
|
||||||
button.disabled = true;
|
|
||||||
var originalText = button.textContent;
|
|
||||||
button.textContent = 'Verbindung prüfen …';
|
|
||||||
|
|
||||||
var saveBody = new FormData(form);
|
|
||||||
fetch('plugins/bratonien_tools/nc-connector-edit-save.php', {
|
|
||||||
method:'POST',
|
|
||||||
credentials:'same-origin',
|
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'},
|
|
||||||
body:saveBody
|
|
||||||
})
|
|
||||||
.then(jsonResponse)
|
|
||||||
.then(function () {
|
|
||||||
button.textContent = 'Nextcloud-Ordner laden …';
|
|
||||||
var pickerBody = new FormData();
|
|
||||||
var token = form.querySelector('input[name="pwg_token"]');
|
|
||||||
var id = form.querySelector('input[name="connection_id"]');
|
|
||||||
pickerBody.append('pwg_token', token ? token.value : '');
|
|
||||||
pickerBody.append('connection_id', id ? id.value : '');
|
|
||||||
return fetch('plugins/bratonien_tools/nc-connector-source-picker-start.php', {
|
|
||||||
method:'POST',
|
|
||||||
credentials:'same-origin',
|
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'},
|
|
||||||
body:pickerBody
|
|
||||||
}).then(jsonResponse);
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
try {
|
|
||||||
sessionStorage.setItem('bratonienNcWizardMode', 'migrate');
|
|
||||||
sessionStorage.setItem('bratonienNcWizardOpen', '1');
|
|
||||||
} catch (e) {}
|
|
||||||
window.location.reload();
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
showPickerError(form, error && typeof error === 'object' ? error : {message:String(error), fields:[]});
|
|
||||||
button.disabled = false;
|
|
||||||
button.textContent = originalText;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function enhanceMigrationButtons(root) {
|
|
||||||
[].slice.call(root.querySelectorAll('button[value="nc_connector_migrate_start"]')).forEach(function (button) {
|
|
||||||
button.textContent = 'Nextcloud-Ordner auswählen & migrieren';
|
|
||||||
button.title = 'Die WebDAV-Quelle wird im Nextcloud-Ordnerbrowser ausgewählt. Der bestehende SMB-/Legacy-Speicher wird nicht als WebDAV-Quelle übernommen.';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function enhanceEditor(root) {
|
|
||||||
var form = root.querySelector('[data-edit-v2-form]');
|
|
||||||
if (!form || form.dataset.sourceUiEnhanced === '1') return;
|
|
||||||
form.dataset.sourceUiEnhanced = '1';
|
|
||||||
|
|
||||||
var headings = [].slice.call(form.querySelectorAll('h5'));
|
|
||||||
var webdavHeading = headings.find(function (node) {
|
|
||||||
return (node.textContent || '').trim() === 'Nextcloud / WebDAV';
|
|
||||||
});
|
|
||||||
var legacyHeading = headings.find(function (node) {
|
|
||||||
return (node.textContent || '').trim() === 'Bestehender Legacy-Weg';
|
|
||||||
});
|
|
||||||
var storageHeading = headings.find(function (node) {
|
|
||||||
return (node.textContent || '').trim() === 'Speicherorte';
|
|
||||||
});
|
|
||||||
var storageList = form.querySelector('[data-storage-list]');
|
|
||||||
var addStorage = form.querySelector('[data-add-storage]');
|
|
||||||
|
|
||||||
if (webdavHeading && !form.querySelector('[data-webdav-source-picker]')) {
|
|
||||||
var webdavGrid = webdavHeading.nextElementSibling;
|
|
||||||
while (webdavGrid && !webdavGrid.classList.contains('bratonien-form-grid')) webdavGrid = webdavGrid.nextElementSibling;
|
|
||||||
if (webdavGrid) {
|
|
||||||
var picker = document.createElement('div');
|
|
||||||
picker.dataset.webdavSourcePicker = '1';
|
|
||||||
picker.style.margin = '.8rem 0 1rem';
|
|
||||||
picker.innerHTML = '<p class="bratonien-base-note" style="margin:.25rem 0 .5rem"><strong>WebDAV-Quelle:</strong> Du musst keinen Pfad kennen. Die Ordner des oben eingetragenen Nextcloud-Benutzers werden automatisch geladen und können anschließend ausgewählt werden.</p>';
|
|
||||||
var button = document.createElement('button');
|
|
||||||
button.type = 'button';
|
|
||||||
button.className = 'buttonLike';
|
|
||||||
button.textContent = 'Nextcloud-Ordner automatisch auswählen';
|
|
||||||
button.addEventListener('click', function () { startSourcePicker(form, button); });
|
|
||||||
picker.appendChild(button);
|
|
||||||
webdavGrid.insertAdjacentElement('afterend', picker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (legacyHeading && !form.querySelector('[data-webdav-source-note]')) {
|
|
||||||
var note = document.createElement('p');
|
|
||||||
note.dataset.webdavSourceNote = '1';
|
|
||||||
note.className = 'bratonien-main-cache__warning';
|
|
||||||
note.innerHTML = '<strong>Wichtig:</strong> Der folgende SMB-/lokale Speicher gehört ausschließlich zum bisherigen Legacy-Fallback. Er wird <strong>nicht</strong> als WebDAV-Quelle übernommen.';
|
|
||||||
legacyHeading.insertAdjacentElement('beforebegin', note);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (storageHeading && storageList && addStorage) {
|
|
||||||
storageHeading.textContent = 'Legacy-Speicher (nur Fallback)';
|
|
||||||
|
|
||||||
var details = document.createElement('details');
|
|
||||||
details.dataset.legacyStorageTechnical = '1';
|
|
||||||
details.style.marginTop = '.75rem';
|
|
||||||
var summary = document.createElement('summary');
|
|
||||||
summary.textContent = 'Technische Legacy-Speicherzuordnung bearbeiten';
|
|
||||||
details.appendChild(summary);
|
|
||||||
|
|
||||||
var info = document.createElement('p');
|
|
||||||
info.className = 'bratonien-base-note';
|
|
||||||
info.textContent = 'Diese Felder betreffen nur den alten Fallback-Weg. Für WebDAV werden keine SMB-Adressen oder lokalen Mount-Pfade eingegeben.';
|
|
||||||
details.appendChild(info);
|
|
||||||
|
|
||||||
storageHeading.insertAdjacentElement('beforebegin', details);
|
|
||||||
details.appendChild(storageHeading);
|
|
||||||
details.appendChild(storageList);
|
|
||||||
details.appendChild(addStorage);
|
|
||||||
|
|
||||||
addStorage.textContent = 'Legacy-Speicher manuell hinzufügen';
|
|
||||||
addStorage.title = 'Nur für den alten Legacy-Fallback. WebDAV-Ordner werden im Nextcloud-Ordnerbrowser ausgewählt.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function enhance(root) {
|
|
||||||
if (!root || root.nodeType !== 1) return;
|
|
||||||
enhanceMigrationButtons(root);
|
|
||||||
if (root.matches && root.matches('#bratonien-nc-connection-edit-v2')) enhanceEditor(root);
|
|
||||||
var dialog = root.querySelector ? root.querySelector('#bratonien-nc-connection-edit-v2') : null;
|
|
||||||
if (dialog) enhanceEditor(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
function start() {
|
|
||||||
var section = document.getElementById('nc-connector');
|
|
||||||
if (!section) return;
|
|
||||||
|
|
||||||
enhance(section);
|
|
||||||
enhanceMigrationButtons(document);
|
|
||||||
|
|
||||||
var observer = new MutationObserver(function (mutations) {
|
|
||||||
mutations.forEach(function (mutation) {
|
|
||||||
[].slice.call(mutation.addedNodes || []).forEach(function (node) {
|
|
||||||
if (node && node.nodeType === 1) enhance(node);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
var dialog = document.getElementById('bratonien-nc-connection-edit-v2');
|
|
||||||
if (dialog) enhanceEditor(dialog);
|
|
||||||
enhanceMigrationButtons(document);
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.body, {childList:true, subtree:true});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start);
|
|
||||||
else start();
|
|
||||||
})();
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.6.17
|
Version: 0.9.6.27
|
||||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||||
Author: Bratonien
|
Author: Bratonien
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ if (!function_exists('is_admin') || !is_admin())
|
|||||||
require_once(BRATONIEN_TOOLS_PATH.'include/nc_connector.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_manage.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH.'include/nc_connector_connection_scope.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH.'include/nc_connector_connection_scope.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH.'include/nc_connector_edit.inc.php');
|
|
||||||
|
|
||||||
$id = (int)($_GET['connection_id'] ?? 0);
|
$id = (int)($_GET['connection_id'] ?? 0);
|
||||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||||
@@ -40,19 +39,13 @@ if (!$connection)
|
|||||||
|
|
||||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
$credentials = array();
|
$credentials = array();
|
||||||
$migration = array('ready'=>false, 'missing'=>array());
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||||
if ((string)$connection['adapter'] === 'local')
|
|
||||||
{
|
|
||||||
$migration = bratonien_tools_nc_connector_migration_state($connection);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
$credentials = array();
|
$credentials = array();
|
||||||
$migration = array('ready'=>false, 'missing'=>array('gespeicherte Zugangsdaten konnten nicht gelesen werden'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$storages = array();
|
$storages = array();
|
||||||
@@ -92,8 +85,8 @@ $payload = array(
|
|||||||
'has_nextcloud_password'=>(string)($credentials['nextcloud_password'] ?? '') !== '',
|
'has_nextcloud_password'=>(string)($credentials['nextcloud_password'] ?? '') !== '',
|
||||||
'api_key_id'=>(string)($credentials['api_key_id'] ?? ''),
|
'api_key_id'=>(string)($credentials['api_key_id'] ?? ''),
|
||||||
'has_api_key_secret'=>trim((string)($credentials['api_key_secret'] ?? '')) !== '',
|
'has_api_key_secret'=>trim((string)($credentials['api_key_secret'] ?? '')) !== '',
|
||||||
'migration_ready'=>!empty($migration['ready']),
|
'fallback_user'=>(string)($credentials['piwigo_user'] ?? ''),
|
||||||
'migration_missing'=>array_values((array)($migration['missing'] ?? array())),
|
'has_fallback_password'=>(string)($credentials['piwigo_password'] ?? '') !== '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -258,7 +258,45 @@ try
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$fallback_user = trim((string)($_POST['nc_fallback_user'] ?? ($credentials['piwigo_user'] ?? '')));
|
||||||
|
$submitted_fallback_password = (string)($_POST['nc_fallback_password'] ?? '');
|
||||||
|
$fallback_password = $submitted_fallback_password !== '' ? $submitted_fallback_password : (string)($credentials['piwigo_password'] ?? '');
|
||||||
|
if (($fallback_user === '') !== ($fallback_password === ''))
|
||||||
|
{
|
||||||
|
bratonien_tools_nc_edit_fail(
|
||||||
|
'Fallback-Benutzer und Fallback-Passwort müssen gemeinsam vollständig sein.',
|
||||||
|
array('nc_fallback_user','nc_fallback_password'),
|
||||||
|
'Piwigo-Fallback'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($fallback_user !== '')
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bratonien_tools_nc_connector_validate_fallback_credentials($fallback_user, $fallback_password);
|
||||||
|
}
|
||||||
|
catch (Throwable $e)
|
||||||
|
{
|
||||||
|
bratonien_tools_nc_edit_fail(
|
||||||
|
'Der Piwigo-Fallback wurde abgelehnt: '.$e->getMessage(),
|
||||||
|
array('nc_fallback_user','nc_fallback_password'),
|
||||||
|
'Piwigo-Fallback'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$result = bratonien_tools_nc_connector_update_local_friendly();
|
$result = bratonien_tools_nc_connector_update_local_friendly();
|
||||||
|
|
||||||
|
if (array_key_exists('nc_fallback_user', $_POST) || array_key_exists('nc_fallback_password', $_POST))
|
||||||
|
{
|
||||||
|
$updated = bratonien_tools_nc_connector_connection($id, true);
|
||||||
|
if (!$updated) throw new RuntimeException('Die Verbindung konnte nach dem Speichern nicht erneut geladen werden.');
|
||||||
|
$updated_credentials = bratonien_tools_nc_connector_scoped_secret($updated);
|
||||||
|
$updated_credentials['piwigo_user'] = $fallback_user;
|
||||||
|
$updated_credentials['piwigo_password'] = $fallback_password;
|
||||||
|
bratonien_tools_nc_connector_store_scoped_secret($id, $updated, $updated_credentials);
|
||||||
|
}
|
||||||
|
|
||||||
bratonien_tools_nc_edit_json(200, array(
|
bratonien_tools_nc_edit_json(200, array(
|
||||||
'ok'=>true,
|
'ok'=>true,
|
||||||
'message'=>(string)($result['message'] ?? 'Verbindung wurde gespeichert.'),
|
'message'=>(string)($result['message'] ?? 'Verbindung wurde gespeichert.'),
|
||||||
@@ -302,6 +340,12 @@ catch (Throwable $e)
|
|||||||
$add('nc_connection_api_key_id');
|
$add('nc_connection_api_key_id');
|
||||||
$add('nc_connection_api_key_secret');
|
$add('nc_connection_api_key_secret');
|
||||||
}
|
}
|
||||||
|
if (stripos($message, 'Fallback') !== false)
|
||||||
|
{
|
||||||
|
$stage = 'Piwigo-Fallback';
|
||||||
|
$add('nc_fallback_user');
|
||||||
|
$add('nc_fallback_password');
|
||||||
|
}
|
||||||
|
|
||||||
bratonien_tools_nc_edit_fail(
|
bratonien_tools_nc_edit_fail(
|
||||||
$message,
|
$message,
|
||||||
|
|||||||
35
runtime/build-webdav-media.sh
Normal file
35
runtime/build-webdav-media.sh
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
CONFIG_FILE="${PIWIGO_CONFIG:-}"
|
||||||
|
[[ -n "$CONFIG_FILE" && -r "$CONFIG_FILE" ]] || { echo "WebDAV-Konfiguration fehlt: ${CONFIG_FILE:-<leer>}" >&2; exit 1; }
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$CONFIG_FILE"
|
||||||
|
|
||||||
|
: "${PIWIGO_ROOT:?PIWIGO_ROOT fehlt}"
|
||||||
|
: "${CONNECTION_ID:?CONNECTION_ID fehlt}"
|
||||||
|
: "${WEBDAV_BASE_URL:?WEBDAV_BASE_URL fehlt}"
|
||||||
|
: "${WEBDAV_USER:?WEBDAV_USER fehlt}"
|
||||||
|
: "${WEBDAV_PASSWORD_FILE:?WEBDAV_PASSWORD_FILE fehlt}"
|
||||||
|
: "${WEBDAV_MAPPING_FILE:?WEBDAV_MAPPING_FILE fehlt}"
|
||||||
|
: "${STATE_DIR:?STATE_DIR fehlt}"
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
LOCK_FILE="$STATE_DIR/webdav-media.lock"
|
||||||
|
mkdir -p -- "$STATE_DIR"
|
||||||
|
exec 9>"$LOCK_FILE"
|
||||||
|
flock -n 9 || exit 0
|
||||||
|
|
||||||
|
PREVIEW_CACHE="$PIWIGO_ROOT/_data/bratonien-tools/nc-webdav-preview/connection-$CONNECTION_ID"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
php "$SCRIPT_DIR/lib/build-webdav-derivatives.php" \
|
||||||
|
--piwigo-root="$PIWIGO_ROOT" \
|
||||||
|
--connection-id="$CONNECTION_ID"
|
||||||
@@ -107,7 +107,7 @@ try
|
|||||||
$rows = $db->query("SELECT id,name,adapter,config_json,secret_blob FROM `{$table}` ORDER BY id DESC");
|
$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);
|
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, $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 : 0755, true)) fail_webdav_reconcile('Runtime-Verzeichnis konnte nicht angelegt werden: '.$dir);
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,6 @@ try
|
|||||||
if (!is_array($config)) $config = array();
|
if (!is_array($config)) $config = array();
|
||||||
if ((string)$row['adapter'] !== 'remote') continue;
|
if ((string)$row['adapter'] !== 'remote') continue;
|
||||||
if ((string)($config['source_mode'] ?? '') !== 'webdav-placeholder') continue;
|
if ((string)($config['source_mode'] ?? '') !== 'webdav-placeholder') continue;
|
||||||
if (empty($config['parallel_test'])) continue;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -164,8 +163,6 @@ try
|
|||||||
}
|
}
|
||||||
if (!is_dir($galleryRoot) && !mkdir($galleryRoot, 0755, true)) fail_webdav_reconcile('WebDAV-Galeriebereich konnte nicht angelegt werden.');
|
if (!is_dir($galleryRoot) && !mkdir($galleryRoot, 0755, true)) fail_webdav_reconcile('WebDAV-Galeriebereich konnte nicht angelegt werden.');
|
||||||
@chmod($galleryRoot, 0755);
|
@chmod($galleryRoot, 0755);
|
||||||
|
|
||||||
// Alte technische Wrapper unter ./galleries duerfen nicht als Piwigo-Alben auftauchen.
|
|
||||||
webdav_remove_generated_tree($legacyDefault, $legacyGalleryRoot);
|
webdav_remove_generated_tree($legacyDefault, $legacyGalleryRoot);
|
||||||
|
|
||||||
$sourceDir = $publicSourceRoot.'/connection-'.$id;
|
$sourceDir = $publicSourceRoot.'/connection-'.$id;
|
||||||
@@ -189,8 +186,9 @@ try
|
|||||||
{
|
{
|
||||||
$path = trim((string)($root['webdav_path'] ?? ''), '/');
|
$path = trim((string)($root['webdav_path'] ?? ''), '/');
|
||||||
$display = trim((string)($root['display_name'] ?? ''));
|
$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.');
|
$runtimePath = $path === '' ? '/' : $path;
|
||||||
$rootLines[] = $path."\t".$display;
|
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);
|
file_put_contents($rootsPath, implode("\n", $rootLines)."\n", LOCK_EX);
|
||||||
@chmod($rootsPath, 0600);
|
@chmod($rootsPath, 0600);
|
||||||
@@ -215,21 +213,23 @@ try
|
|||||||
file_put_contents($configPath, implode("\n", $lines)."\n", LOCK_EX);
|
file_put_contents($configPath, implode("\n", $lines)."\n", LOCK_EX);
|
||||||
@chmod($configPath, 0600);
|
@chmod($configPath, 0600);
|
||||||
|
|
||||||
|
unset($config['migration'], $config['parallel_test']);
|
||||||
$config['state_dir'] = $stateDir;
|
$config['state_dir'] = $stateDir;
|
||||||
$config['status_file'] = $statusFile;
|
$config['status_file'] = $statusFile;
|
||||||
$config['parallel_gallery_root'] = $galleryRoot;
|
$config['parallel_gallery_root'] = $galleryRoot;
|
||||||
$config['source_fingerprint'] = $fingerprint;
|
$config['source_fingerprint'] = $fingerprint;
|
||||||
$config['runtime'] = array(
|
$config['runtime'] = array(
|
||||||
'mode'=>'parallel-webdav',
|
'mode'=>'webdav',
|
||||||
'config'=>$configPath,
|
'config'=>$configPath,
|
||||||
'piwigo_sync_enabled'=>true,
|
'piwigo_sync_enabled'=>true,
|
||||||
'reconciled_at'=>date('Y-m-d H:i:s'),
|
'reconciled_at'=>date('Y-m-d H:i:s'),
|
||||||
);
|
);
|
||||||
$json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
$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);
|
$escaped = $db->real_escape_string($json);
|
||||||
$db->query("UPDATE `{$table}` SET config_json='{$escaped}' WHERE id={$id} LIMIT 1");
|
if (!$db->query("UPDATE `{$table}` SET config_json='{$escaped}' WHERE id={$id} AND adapter='remote' LIMIT 1"))
|
||||||
|
{
|
||||||
|
fail_webdav_reconcile('WebDAV-Runtime-Status konnte nicht gespeichert werden: '.$db->error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
|
|||||||
@@ -17,104 +17,32 @@ read_config_value() {
|
|||||||
printf '%s' "$value"
|
printf '%s' "$value"
|
||||||
}
|
}
|
||||||
|
|
||||||
compact_text() {
|
|
||||||
printf '%s\n' "$1" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
|
||||||
}
|
|
||||||
|
|
||||||
read_webdav_failure_detail() {
|
|
||||||
local config="$1"
|
|
||||||
local captured_output="${2:-}"
|
|
||||||
local connection_id piwigo_root status_file status_detail
|
|
||||||
|
|
||||||
connection_id="$(read_config_value CONNECTION_ID "$config")"
|
|
||||||
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
|
||||||
[[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo"
|
|
||||||
|
|
||||||
status_detail=""
|
|
||||||
if [[ -n "$connection_id" ]]; then
|
|
||||||
status_file="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status/connection-${connection_id}.json"
|
|
||||||
if [[ -r "$status_file" ]]; then
|
|
||||||
status_detail="$(php -r '
|
|
||||||
$file = $argv[1];
|
|
||||||
$data = json_decode((string)@file_get_contents($file), true);
|
|
||||||
if (!is_array($data)) exit(0);
|
|
||||||
$message = trim((string)($data["message"] ?? ""));
|
|
||||||
$detail = trim((string)($data["error_detail"] ?? ""));
|
|
||||||
$parts = array();
|
|
||||||
if ($message !== "") $parts[] = $message;
|
|
||||||
if ($detail !== "") $parts[] = $detail;
|
|
||||||
if ($parts) {
|
|
||||||
$text = preg_replace("/\\s+/u", " ", implode(" - ", $parts));
|
|
||||||
echo trim((string)$text);
|
|
||||||
}
|
|
||||||
' "$status_file")"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$captured_output" ]]; then
|
|
||||||
captured_output="$(compact_text "$captured_output")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$status_detail" && -n "$captured_output" ]]; then
|
|
||||||
printf '%s' "$status_detail | Prozessausgabe: $captured_output"
|
|
||||||
elif [[ -n "$status_detail" ]]; then
|
|
||||||
printf '%s' "$status_detail"
|
|
||||||
elif [[ -n "$captured_output" ]]; then
|
|
||||||
printf '%s' "$captured_output"
|
|
||||||
elif [[ -z "$connection_id" ]]; then
|
|
||||||
printf '%s' 'WebDAV-Prozess wurde gestartet, aber die Verbindungs-ID fehlt in der Runtime-Konfiguration.'
|
|
||||||
else
|
|
||||||
printf '%s' "WebDAV-Prozess fuer Verbindung ${connection_id} endete mit Fehler, lieferte aber weder Statusdatei noch Prozessausgabe."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
write_route_status() {
|
write_route_status() {
|
||||||
local route="$1"
|
local route="$1"
|
||||||
local label="$2"
|
local label="$2"
|
||||||
local detail="$3"
|
local detail="$3"
|
||||||
local fallback_used="$4"
|
local success="$4"
|
||||||
local success="$5"
|
|
||||||
|
|
||||||
[[ -n "${ROUTE_STATUS_FILE:-}" ]] || return 0
|
[[ -n "${ROUTE_STATUS_FILE:-}" ]] || return 0
|
||||||
mkdir -p -- "$(dirname -- "$ROUTE_STATUS_FILE")"
|
mkdir -p -- "$(dirname -- "$ROUTE_STATUS_FILE")"
|
||||||
|
|
||||||
php -r '
|
php -r '
|
||||||
$payload = array(
|
$payload = array(
|
||||||
"timestamp" => time(),
|
"timestamp" => time(),
|
||||||
"route" => (string)$argv[2],
|
"route" => (string)$argv[2],
|
||||||
"label" => (string)$argv[3],
|
"label" => (string)$argv[3],
|
||||||
"detail" => (string)$argv[4],
|
"detail" => (string)$argv[4],
|
||||||
"fallback_used" => $argv[5] === "1",
|
"fallback_used" => false,
|
||||||
"success" => $argv[6] === "1"
|
"success" => $argv[5] === "1"
|
||||||
);
|
);
|
||||||
$json = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
$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) {
|
if (!is_string($json) || file_put_contents($argv[1], $json.PHP_EOL, LOCK_EX) === false) exit(1);
|
||||||
fwrite(STDERR, "Route-Status konnte nicht geschrieben werden.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
@chmod($argv[1], 0644);
|
@chmod($argv[1], 0644);
|
||||||
' "$ROUTE_STATUS_FILE" "$route" "$label" "$detail" "$fallback_used" "$success"
|
' "$ROUTE_STATUS_FILE" "$route" "$label" "$detail" "$success"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! php "$SCRIPT_DIR/reconcile.php"; then
|
php "$SCRIPT_DIR/reconcile.php"
|
||||||
echo "NC Connector: gespeicherte lokale Verbindungen konnten nicht mit der Runtime abgeglichen werden." >&2
|
php "$SCRIPT_DIR/reconcile-webdav.php"
|
||||||
exit 1
|
php "$SCRIPT_DIR/cleanup-webdav-piwigo.php"
|
||||||
fi
|
php "$SCRIPT_DIR/cleanup-stale.php"
|
||||||
|
|
||||||
if ! php "$SCRIPT_DIR/reconcile-webdav.php"; then
|
|
||||||
echo "NC Connector: WebDAV-Verbindungen konnten nicht mit der Runtime abgeglichen werden." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if ! php "$SCRIPT_DIR/cleanup-stale.php"; then
|
|
||||||
echo "NC Connector: verwaiste Laufzeitdateien konnten nicht bereinigt werden." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
configs=("$CONFIG_DIR"/connection-*.conf)
|
configs=("$CONFIG_DIR"/connection-*.conf)
|
||||||
webdav_configs=("$CONFIG_DIR"/webdav-connection-*.conf)
|
webdav_configs=("$CONFIG_DIR"/webdav-connection-*.conf)
|
||||||
@@ -133,72 +61,54 @@ done
|
|||||||
[[ -n "$route_piwigo_root" ]] || route_piwigo_root="/var/www/piwigo"
|
[[ -n "$route_piwigo_root" ]] || route_piwigo_root="/var/www/piwigo"
|
||||||
ROUTE_STATUS_FILE="${route_piwigo_root%/}/_data/bratonien-tools/nc-connector-status/route-status.json"
|
ROUTE_STATUS_FILE="${route_piwigo_root%/}/_data/bratonien-tools/nc-connector-status/route-status.json"
|
||||||
|
|
||||||
webdav_success=0
|
failure_count=0
|
||||||
webdav_failed=0
|
webdav_count=0
|
||||||
webdav_failure_detail=""
|
local_count=0
|
||||||
|
summary_parts=()
|
||||||
|
|
||||||
if [[ ${#webdav_configs[@]} -eq 0 ]]; then
|
|
||||||
webdav_failed=1
|
|
||||||
webdav_failure_detail="Keine WebDAV-Runtime-Verbindung ist konfiguriert. Es existiert aktuell nur die Legacy-Verbindung; deshalb kann WebDAV nicht primaer laufen."
|
|
||||||
echo "NC Connector: $webdav_failure_detail" >&2
|
|
||||||
else
|
|
||||||
for config in "${webdav_configs[@]}"; do
|
for config in "${webdav_configs[@]}"; do
|
||||||
|
[[ -f "$config" ]] || continue
|
||||||
name="$(basename "$config")"
|
name="$(basename "$config")"
|
||||||
echo "NC Connector WebDAV primaer: $name"
|
connection_id="$(read_config_value CONNECTION_ID "$config")"
|
||||||
webdav_output=""
|
if [[ ! "$connection_id" =~ ^[0-9]+$ ]] || [[ "$connection_id" -lt 1 ]]; then
|
||||||
if webdav_output="$(env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh" 2>&1)"; then
|
echo "NC Connector: $name besitzt keine gueltige Verbindungs-ID." >&2
|
||||||
webdav_success=1
|
failure_count=$((failure_count + 1))
|
||||||
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output"
|
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
else
|
||||||
webdav_exit=$?
|
code=$?
|
||||||
webdav_failed=1
|
[[ -z "$output" ]] || printf '%s\n' "$output" >&2
|
||||||
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output" >&2
|
failure_count=$((failure_count + 1))
|
||||||
webdav_failure_detail="$(read_webdav_failure_detail "$config" "$webdav_output")"
|
summary_parts+=("WebDAV #$connection_id fehlgeschlagen (Exit $code)")
|
||||||
webdav_failure_detail="Exit-Code ${webdav_exit}: ${webdav_failure_detail}"
|
|
||||||
echo "NC Connector: WebDAV-Lauf fehlgeschlagen: $webdav_failure_detail" >&2
|
|
||||||
echo "NC Connector: Legacy-Fallback bleibt verfuegbar." >&2
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$webdav_success" -eq 1 ]]; then
|
|
||||||
write_route_status \
|
|
||||||
"webdav" \
|
|
||||||
"WebDAV (primaer)" \
|
|
||||||
"WebDAV erfolgreich. Legacy-Fallback wurde in diesem Lauf nicht ausgefuehrt." \
|
|
||||||
"0" \
|
|
||||||
"1"
|
|
||||||
echo "NC Connector: WebDAV erfolgreich; Legacy-Verbindung wird in diesem Lauf nicht ausgefuehrt."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${#configs[@]} -eq 0 ]]; then
|
|
||||||
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV ist fehlgeschlagen; Ursache konnte nicht ermittelt werden."
|
|
||||||
write_route_status \
|
|
||||||
"failed" \
|
|
||||||
"FEHLER - kein Datenweg" \
|
|
||||||
"WebDAV-Fehler: $webdav_failure_detail Keine Legacy-Fallback-Verbindung vorhanden." \
|
|
||||||
"0" \
|
|
||||||
"0"
|
|
||||||
echo "NC Connector: WebDAV ist fehlgeschlagen und es ist keine Legacy-Fallback-Verbindung vorhanden." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "NC Connector: kein erfolgreicher WebDAV-Lauf; Legacy-Fallback wird ausgefuehrt."
|
|
||||||
legacy_result=0
|
|
||||||
|
|
||||||
for config in "${configs[@]}"; do
|
for config in "${configs[@]}"; do
|
||||||
|
[[ -f "$config" ]] || continue
|
||||||
name="$(basename "$config")"
|
name="$(basename "$config")"
|
||||||
connection_id=""
|
connection_id="0"
|
||||||
if [[ "$name" =~ ^connection-([0-9]+)\.conf$ ]]; then
|
if [[ "$name" =~ ^connection-([0-9]+)\.conf$ ]]; then
|
||||||
connection_id="${BASH_REMATCH[1]}"
|
connection_id="${BASH_REMATCH[1]}"
|
||||||
fi
|
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
|
||||||
|
|
||||||
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
||||||
[[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo"
|
[[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo"
|
||||||
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
||||||
|
if [[ -f "$tombstone_dir/deleted-$connection_id" ]]; then
|
||||||
if [[ -n "$connection_id" && -f "$tombstone_dir/deleted-$connection_id" ]]; then
|
|
||||||
echo "NC Connector: Verbindung $connection_id wurde geloescht; Laufzeitdateien werden entfernt."
|
echo "NC Connector: Verbindung $connection_id wurde geloescht; Laufzeitdateien werden entfernt."
|
||||||
rm -f -- "$CONFIG_DIR/connection-$connection_id.conf" \
|
rm -f -- "$CONFIG_DIR/connection-$connection_id.conf" \
|
||||||
"$CONFIG_DIR/connection-$connection_id.db-password" \
|
"$CONFIG_DIR/connection-$connection_id.db-password" \
|
||||||
@@ -209,33 +119,35 @@ for config in "${configs[@]}"; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "NC Connector Legacy-Fallback: $name"
|
local_count=$((local_count + 1))
|
||||||
if ! env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync.sh"; then
|
echo "NC Connector Local #$connection_id: $name"
|
||||||
legacy_result=1
|
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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$legacy_result" -eq 0 ]]; then
|
summary_detail="$(IFS='; '; printf '%s' "${summary_parts[*]}")"
|
||||||
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; Ursache konnte nicht ermittelt werden."
|
[[ -n "$summary_detail" ]] || summary_detail="Keine Verbindung wurde ausgefuehrt."
|
||||||
write_route_status \
|
|
||||||
"legacy_fallback" \
|
if [[ "$failure_count" -eq 0 ]]; then
|
||||||
"LEGACY-FALLBACK AKTIV" \
|
if [[ "$webdav_count" -gt 0 && "$local_count" -gt 0 ]]; then
|
||||||
"WebDAV-Fehler: $webdav_failure_detail Legacy-Fallback wurde erfolgreich ausgefuehrt." \
|
route="mixed"
|
||||||
"1" \
|
label="WebDAV + Local"
|
||||||
"1"
|
elif [[ "$webdav_count" -gt 0 ]]; then
|
||||||
echo "NC Connector: Legacy-Fallback erfolgreich."
|
route="webdav"
|
||||||
|
label="WebDAV"
|
||||||
|
else
|
||||||
|
route="local"
|
||||||
|
label="Local"
|
||||||
|
fi
|
||||||
|
write_route_status "$route" "$label" "$summary_detail" "1"
|
||||||
|
echo "NC Connector: alle Verbindungen wurden erfolgreich verarbeitet."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; Ursache konnte nicht ermittelt werden."
|
write_route_status "failed" "FEHLER - mindestens eine Verbindung" "$summary_detail" "0"
|
||||||
write_route_status \
|
echo "NC Connector: mindestens eine Verbindung ist fehlgeschlagen." >&2
|
||||||
"failed" \
|
|
||||||
"FEHLER - WebDAV und Fallback" \
|
|
||||||
"WebDAV-Fehler: $webdav_failure_detail Legacy-Fallback ist ebenfalls fehlgeschlagen." \
|
|
||||||
"1" \
|
|
||||||
"0"
|
|
||||||
|
|
||||||
if [[ "$webdav_failed" -eq 1 ]]; then
|
|
||||||
echo "NC Connector: WebDAV und Legacy-Fallback sind fehlgeschlagen." >&2
|
|
||||||
fi
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -59,10 +59,6 @@ for target in (status_file, public_file):
|
|||||||
PY
|
PY
|
||||||
}
|
}
|
||||||
|
|
||||||
compact_output() {
|
|
||||||
tail -n 12 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
|
||||||
}
|
|
||||||
|
|
||||||
failure() {
|
failure() {
|
||||||
local code="$1" command="$2" line="$3"
|
local code="$1" command="$2" line="$3"
|
||||||
trap - ERR
|
trap - ERR
|
||||||
@@ -94,28 +90,6 @@ python3 "$SCRIPT_DIR/lib/shadow_tree.py" \
|
|||||||
--state "$SHADOW_MAP_FILE"
|
--state "$SHADOW_MAP_FILE"
|
||||||
|
|
||||||
trap - ERR
|
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
|
if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
||||||
PIWIGO_OUTPUT=""
|
PIWIGO_OUTPUT=""
|
||||||
@@ -133,7 +107,7 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
|||||||
if [[ "$PIWIGO_EXIT" -ne 0 ]]; then
|
if [[ "$PIWIGO_EXIT" -ne 0 ]]; then
|
||||||
DETAIL="Exit-Code: $PIWIGO_EXIT"
|
DETAIL="Exit-Code: $PIWIGO_EXIT"
|
||||||
if [[ -n "$PIWIGO_OUTPUT" ]]; then
|
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
|
fi
|
||||||
|
|
||||||
if grep -qi 'Invalid username/password' <<<"$PIWIGO_OUTPUT"; then
|
if grep -qi 'Invalid username/password' <<<"$PIWIGO_OUTPUT"; then
|
||||||
@@ -160,28 +134,21 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
|||||||
exit "$PIWIGO_EXIT"
|
exit "$PIWIGO_EXIT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DERIVATIVE_OUTPUT=""
|
MEDIA_UNIT="bratonien-nc-media-${CONNECTION_ID}-$(date +%s)"
|
||||||
DERIVATIVE_EXIT=0
|
if ! systemd-run \
|
||||||
if DERIVATIVE_OUTPUT="$(php "$SCRIPT_DIR/lib/build-webdav-derivatives.php" \
|
--quiet \
|
||||||
--piwigo-root="$PIWIGO_ROOT" \
|
--collect \
|
||||||
--connection-id="$CONNECTION_ID" 2>&1)"; then
|
--unit="$MEDIA_UNIT" \
|
||||||
DERIVATIVE_EXIT=0
|
--property=RuntimeMaxSec=30min \
|
||||||
else
|
--setenv="PIWIGO_CONFIG=$CONFIG_FILE" \
|
||||||
DERIVATIVE_EXIT=$?
|
/usr/bin/env bash "$SCRIPT_DIR/build-webdav-media.sh"; then
|
||||||
fi
|
write_status error "Bildaufbereitung konnte nicht im Hintergrund gestartet werden"
|
||||||
[[ -z "$DERIVATIVE_OUTPUT" ]] || printf '%s\n' "$DERIVATIVE_OUTPUT"
|
exit 1
|
||||||
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
|
fi
|
||||||
|
|
||||||
if grep -q 'Piwigo-Synchronisierung per API erfolgreich' <<<"$PIWIGO_OUTPUT"; then
|
if grep -q 'Piwigo-Synchronisierung per API erfolgreich' <<<"$PIWIGO_OUTPUT"; then
|
||||||
write_status ok \
|
write_status ok \
|
||||||
"WebDAV eingelesen, Piwigo synchronisiert und Derivate erzeugt" \
|
"WebDAV eingelesen und Piwigo synchronisiert; Bildaufbereitung läuft im Hintergrund" \
|
||||||
"" \
|
"" \
|
||||||
"api" \
|
"api" \
|
||||||
"ok" \
|
"ok" \
|
||||||
@@ -190,7 +157,7 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
|||||||
"Fallback wurde nicht benötigt"
|
"Fallback wurde nicht benötigt"
|
||||||
elif grep -q 'Piwigo-Datenbanksynchronisierung per Benutzername/Passwort-Fallback erfolgreich' <<<"$PIWIGO_OUTPUT"; then
|
elif grep -q 'Piwigo-Datenbanksynchronisierung per Benutzername/Passwort-Fallback erfolgreich' <<<"$PIWIGO_OUTPUT"; then
|
||||||
write_status ok \
|
write_status ok \
|
||||||
"WebDAV eingelesen, Piwigo über Fallback synchronisiert und Derivate erzeugt" \
|
"WebDAV eingelesen und Piwigo über Fallback synchronisiert; Bildaufbereitung läuft im Hintergrund" \
|
||||||
"" \
|
"" \
|
||||||
"fallback" \
|
"fallback" \
|
||||||
"not_used" \
|
"not_used" \
|
||||||
@@ -198,8 +165,8 @@ if [[ "${PIWIGO_SYNC_ENABLED:-0}" == "1" ]]; then
|
|||||||
"ok" \
|
"ok" \
|
||||||
"Benutzername/Passwort-Fallback erfolgreich"
|
"Benutzername/Passwort-Fallback erfolgreich"
|
||||||
else
|
else
|
||||||
write_status ok "WebDAV eingelesen, Piwigo synchronisiert und Derivate erzeugt"
|
write_status ok "WebDAV eingelesen und Piwigo synchronisiert; Bildaufbereitung läuft im Hintergrund"
|
||||||
fi
|
fi
|
||||||
else
|
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
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user