mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 18:44:30 +00:00
Compare commits
6 Commits
fix/nc-ui-
...
fix/connec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecde2c7edd | ||
|
|
d7ef7efe43 | ||
|
|
a8ec0859da | ||
|
|
528a23b4dd | ||
|
|
fea3332ff0 | ||
|
|
039fb5160c |
16
.github/workflows/lint.yml
vendored
16
.github/workflows/lint.yml
vendored
@@ -5,12 +5,8 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
php-syntax:
|
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
|
||||||
@@ -18,7 +14,7 @@ jobs:
|
|||||||
- name: PHP installieren
|
- name: PHP installieren
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php-version }}
|
php-version: '8.2'
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
- name: PHP Syntax pruefen
|
- name: PHP Syntax pruefen
|
||||||
@@ -40,20 +36,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: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
sed -n '/<script>/,/<\/script>/p' template/admin_tabs.tpl | sed '1d;$d' > /tmp/bratonien-admin-tabs.js
|
sed -n '/<script>/,/<\/script>/p' template/admin_tabs.tpl | sed '1d;$d' > /tmp/bratonien-admin-tabs.js
|
||||||
node --check /tmp/bratonien-admin-tabs.js
|
node --check /tmp/bratonien-admin-tabs.js
|
||||||
node --check js/nc_connector_edit_v2.js
|
|
||||||
node --check js/nc_connector_source_ui.js
|
|
||||||
|
|
||||||
- name: Python Syntax pruefen
|
- name: Python Syntax pruefen
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -4,103 +4,6 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
die('Hacking attempt!');
|
die('Hacking attempt!');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_migration_state(array $connection)
|
|
||||||
{
|
|
||||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
|
||||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
|
||||||
$missing = array();
|
|
||||||
|
|
||||||
if (trim((string)($config['nextcloud_url'] ?? '')) === '') $missing[] = 'Nextcloud-Adresse';
|
|
||||||
if (trim((string)($credentials['nextcloud_user'] ?? '')) === '') $missing[] = 'Nextcloud-Benutzer';
|
|
||||||
if ((string)($credentials['nextcloud_password'] ?? '') === '') $missing[] = 'Nextcloud-Passwort';
|
|
||||||
|
|
||||||
$api_id = trim((string)($credentials['api_key_id'] ?? ''));
|
|
||||||
$api_secret = trim((string)($credentials['api_key_secret'] ?? ''));
|
|
||||||
$fallback_user = trim((string)($credentials['piwigo_user'] ?? ''));
|
|
||||||
$fallback_password = (string)($credentials['piwigo_password'] ?? '');
|
|
||||||
$api_complete = $api_id !== '' && $api_secret !== '';
|
|
||||||
$fallback_complete = $fallback_user !== '' && $fallback_password !== '';
|
|
||||||
|
|
||||||
if (($api_id === '') !== ($api_secret === '')) $missing[] = 'vollstaendiger Piwigo-API-Zugang';
|
|
||||||
if (!$api_complete && !$fallback_complete) $missing[] = 'Piwigo-API oder Benutzer/Passwort-Fallback';
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'ready'=>!$missing,
|
|
||||||
'missing'=>$missing,
|
|
||||||
'api_available'=>$api_complete,
|
|
||||||
'fallback_available'=>$fallback_complete,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_validate_nextcloud_access($base_url, $username, $password)
|
|
||||||
{
|
|
||||||
$base_url = bratonien_tools_nc_wizard_normalize_url($base_url);
|
|
||||||
$username = trim((string)$username);
|
|
||||||
$password = (string)$password;
|
|
||||||
if ($username === '' || $password === '') throw new RuntimeException('Nextcloud-Benutzer und Passwort werden benoetigt.');
|
|
||||||
|
|
||||||
$status_response = bratonien_tools_nc_wizard_http($base_url.'/status.php');
|
|
||||||
if ($status_response['status'] < 200 || $status_response['status'] >= 300)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Die Nextcloud-Adresse konnte nicht bestaetigt werden.');
|
|
||||||
}
|
|
||||||
$status = json_decode((string)$status_response['body'], true);
|
|
||||||
if (!is_array($status) || empty($status['installed']))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Unter dieser Adresse wurde keine installierte Nextcloud erkannt.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$user_response = bratonien_tools_nc_wizard_http(
|
|
||||||
$base_url.'/ocs/v2.php/cloud/user?format=json',
|
|
||||||
$username,
|
|
||||||
$password,
|
|
||||||
array('OCS-APIRequest: true')
|
|
||||||
);
|
|
||||||
if ($user_response['status'] === 401 || $user_response['status'] === 403)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Nextcloud hat Benutzername oder Passwort abgelehnt.');
|
|
||||||
}
|
|
||||||
if ($user_response['status'] < 200 || $user_response['status'] >= 300)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Nextcloud ist erreichbar, aber der Benutzerzugang konnte nicht geprueft werden.');
|
|
||||||
}
|
|
||||||
$user_data = bratonien_tools_nc_wizard_ocs_data($user_response['body']);
|
|
||||||
$resolved = trim((string)($user_data['id'] ?? $username));
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'base_url'=>$base_url,
|
|
||||||
'username'=>$resolved !== '' ? $resolved : $username,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_validate_scoped_api($api_key_id, $api_key_secret)
|
|
||||||
{
|
|
||||||
$api_key_id = trim((string)$api_key_id);
|
|
||||||
$api_key_secret = trim((string)$api_key_secret);
|
|
||||||
if ($api_key_id === '' || $api_key_secret === '')
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Piwigo-API-Schluessel-ID und API-Geheimnis werden benoetigt.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$status = bratonien_tools_nc_connector_piwigo_api_request($api_key_id, $api_key_secret, 'pwg.session.getStatus');
|
|
||||||
if (!is_array($status)) throw new RuntimeException('Piwigo hat keinen auswertbaren API-Benutzerstatus geliefert.');
|
|
||||||
$role = strtolower(trim((string)($status['status'] ?? '')));
|
|
||||||
if (!in_array($role, array('admin','webmaster'), true))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Der API-Key funktioniert, gehoert aber keinem Piwigo-Administrator/Webmaster.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$method_result = bratonien_tools_nc_connector_piwigo_api_request($api_key_id, $api_key_secret, 'reflection.getMethodList');
|
|
||||||
$method_map = array();
|
|
||||||
bratonien_tools_nc_connector_collect_method_names($method_result, $method_map);
|
|
||||||
$required = array('bratonien.nc.syncProductive', 'bratonien.nc.syncOrphans');
|
|
||||||
$missing = array_values(array_diff($required, array_keys($method_map)));
|
|
||||||
if ($missing)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Der API-Key ist gueltig, aber benoetigte Bratonien-Sync-Methoden fehlen: '.implode(', ', $missing).'.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection(array $connection, $mode)
|
function bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection(array $connection, $mode)
|
||||||
{
|
{
|
||||||
$id = (int)$connection['id'];
|
$id = (int)$connection['id'];
|
||||||
@@ -122,7 +25,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 ($fileid < 1) continue;
|
if ($path === '' || $fileid < 1) continue;
|
||||||
$selected[] = $path;
|
$selected[] = $path;
|
||||||
$selected_ids[$path] = $fileid;
|
$selected_ids[$path] = $fileid;
|
||||||
}
|
}
|
||||||
@@ -198,7 +101,7 @@ function bratonien_tools_nc_connector_edit_start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'update');
|
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'update');
|
||||||
return array('message'=>'Verbindung #'.$id.' wurde zum Bearbeiten geoeffnet.');
|
return array('message'=>'Verbindung #'.$id.' wurde zum Bearbeiten geöffnet.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_migrate_start()
|
function bratonien_tools_nc_connector_migrate_start()
|
||||||
@@ -211,14 +114,8 @@ function bratonien_tools_nc_connector_migrate_start()
|
|||||||
throw new RuntimeException('Nur eine Legacy-Verbindung kann auf WebDAV migriert werden.');
|
throw new RuntimeException('Nur eine Legacy-Verbindung kann auf WebDAV migriert werden.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$migration = bratonien_tools_nc_connector_migration_state($connection);
|
|
||||||
if (empty($migration['ready']))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Die WebDAV-Migration ist noch nicht bereit. Unter Bearbeiten fehlen: '.implode(', ', $migration['missing']).'.');
|
|
||||||
}
|
|
||||||
|
|
||||||
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'migrate');
|
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'migrate');
|
||||||
return array('message'=>'Die WebDAV-Migration fuer Verbindung #'.$id.' wurde geoeffnet. Die bestehende Legacy-Verbindung bleibt bis zum erfolgreichen Umstieg unveraendert.');
|
return array('message'=>'Die WebDAV-Migration für Verbindung #'.$id.' wurde geöffnet. Die bestehende Legacy-Verbindung bleibt bis zum erfolgreichen Umstieg unverändert.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_connector_update_local_friendly()
|
function bratonien_tools_nc_connector_update_local_friendly()
|
||||||
@@ -226,10 +123,10 @@ function bratonien_tools_nc_connector_update_local_friendly()
|
|||||||
$id = (int)($_POST['connection_id'] ?? 0);
|
$id = (int)($_POST['connection_id'] ?? 0);
|
||||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||||
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||||
if ((string)$connection['adapter'] !== 'local') throw new RuntimeException('Diese Bearbeitung ist nur fuer Legacy-Verbindungen vorgesehen.');
|
if ((string)$connection['adapter'] !== 'local') throw new RuntimeException('Diese Bearbeitung ist nur für Legacy-Verbindungen vorgesehen.');
|
||||||
|
|
||||||
$name = trim((string)($_POST['connection_name'] ?? ''));
|
$name = trim((string)($_POST['connection_name'] ?? ''));
|
||||||
if ($name === '') throw new RuntimeException('Bitte einen Namen fuer die Verbindung angeben.');
|
if ($name === '') throw new RuntimeException('Bitte einen Namen für die Verbindung angeben.');
|
||||||
|
|
||||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
$host = trim((string)($_POST['nc_host'] ?? ''));
|
$host = trim((string)($_POST['nc_host'] ?? ''));
|
||||||
@@ -241,11 +138,11 @@ function bratonien_tools_nc_connector_update_local_friendly()
|
|||||||
$activity_view = trim((string)($_POST['nc_activity_view'] ?? ''));
|
$activity_view = trim((string)($_POST['nc_activity_view'] ?? ''));
|
||||||
|
|
||||||
if ($host === '') throw new RuntimeException('Datenbank-Server fehlt.');
|
if ($host === '') throw new RuntimeException('Datenbank-Server fehlt.');
|
||||||
if ($port < 1 || $port > 65535) throw new RuntimeException('Der Datenbank-Port ist ungueltig.');
|
if ($port < 1 || $port > 65535) throw new RuntimeException('Der Datenbank-Port ist ungültig.');
|
||||||
if ($database === '') throw new RuntimeException('Datenbankname fehlt.');
|
if ($database === '') throw new RuntimeException('Datenbankname fehlt.');
|
||||||
if ($user === '') throw new RuntimeException('Reader-Benutzer fehlt.');
|
if ($user === '') throw new RuntimeException('Reader-Benutzer fehlt.');
|
||||||
if ($gallery_root === '' || $gallery_root[0] !== '/') throw new RuntimeException('Der Piwigo-Galerieordner muss ein absoluter Pfad sein.');
|
if ($gallery_root === '' || $gallery_root[0] !== '/') throw new RuntimeException('Der Piwigo-Galerieordner muss ein absoluter Pfad sein.');
|
||||||
if ($source_view === '' || $activity_view === '') throw new RuntimeException('Die gespeicherten Datenbankansichten duerfen nicht leer sein.');
|
if ($source_view === '' || $activity_view === '') throw new RuntimeException('Die gespeicherten Datenbankansichten dürfen nicht leer sein.');
|
||||||
bratonien_tools_nc_connector_view_name($source_view);
|
bratonien_tools_nc_connector_view_name($source_view);
|
||||||
bratonien_tools_nc_connector_view_name($activity_view);
|
bratonien_tools_nc_connector_view_name($activity_view);
|
||||||
|
|
||||||
@@ -261,54 +158,11 @@ function bratonien_tools_nc_connector_update_local_friendly()
|
|||||||
$mount = rtrim(trim((string)($storage_mounts[$index] ?? '')), '/');
|
$mount = rtrim(trim((string)($storage_mounts[$index] ?? '')), '/');
|
||||||
if ($storage_id === '' && $prefix === '' && $mount === '') continue;
|
if ($storage_id === '' && $prefix === '' && $mount === '') continue;
|
||||||
if ($storage_id === '') throw new RuntimeException('Bei einem Speicherort fehlt die Storage-ID.');
|
if ($storage_id === '') throw new RuntimeException('Bei einem Speicherort fehlt die Storage-ID.');
|
||||||
if ($mount === '' || $mount[0] !== '/') throw new RuntimeException('Bei einem Speicherort fehlt ein gueltiger lokaler Pfad.');
|
if ($mount === '' || $mount[0] !== '/') throw new RuntimeException('Bei einem Speicherort fehlt ein gültiger lokaler Pfad.');
|
||||||
$storages[] = array('storage_id'=>$storage_id, 'source_prefix'=>$prefix, 'local_mount'=>$mount);
|
$storages[] = array('storage_id'=>$storage_id, 'source_prefix'=>$prefix, 'local_mount'=>$mount);
|
||||||
}
|
}
|
||||||
if (!$storages) throw new RuntimeException('Mindestens ein Speicherort muss vorhanden sein.');
|
if (!$storages) throw new RuntimeException('Mindestens ein Speicherort muss vorhanden sein.');
|
||||||
|
|
||||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
|
||||||
$new_db_password = (string)($_POST['nc_db_password'] ?? '');
|
|
||||||
if ($new_db_password !== '') $credentials['db_password'] = $new_db_password;
|
|
||||||
if (trim((string)($credentials['db_password'] ?? '')) === '') throw new RuntimeException('Fuer die Legacy-Verbindung ist kein Datenbankpasswort gespeichert.');
|
|
||||||
|
|
||||||
$nextcloud_url = trim((string)($_POST['nc_nextcloud_url'] ?? ($config['nextcloud_url'] ?? '')));
|
|
||||||
$nextcloud_user = trim((string)($_POST['nc_nextcloud_user'] ?? ($credentials['nextcloud_user'] ?? '')));
|
|
||||||
$new_nextcloud_password = (string)($_POST['nc_nextcloud_password'] ?? '');
|
|
||||||
if ($new_nextcloud_password !== '') $credentials['nextcloud_password'] = $new_nextcloud_password;
|
|
||||||
$nextcloud_password = (string)($credentials['nextcloud_password'] ?? '');
|
|
||||||
|
|
||||||
$api_key_id = trim((string)($_POST['nc_connection_api_key_id'] ?? ($credentials['api_key_id'] ?? '')));
|
|
||||||
$new_api_secret = trim((string)($_POST['nc_connection_api_key_secret'] ?? ''));
|
|
||||||
$old_api_id = trim((string)($credentials['api_key_id'] ?? ''));
|
|
||||||
if ($api_key_id !== $old_api_id && $new_api_secret === '')
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Wenn die API-Schluessel-ID geaendert wird, muss auch das API-Geheimnis neu eingegeben werden.');
|
|
||||||
}
|
|
||||||
if ($new_api_secret !== '') $credentials['api_key_secret'] = $new_api_secret;
|
|
||||||
$api_key_secret = trim((string)($credentials['api_key_secret'] ?? ''));
|
|
||||||
|
|
||||||
if (($nextcloud_url === '' || $nextcloud_user === '' || $nextcloud_password === '') && ($nextcloud_url !== '' || $nextcloud_user !== '' || $nextcloud_password !== ''))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Nextcloud-Adresse, Nextcloud-Benutzer und Nextcloud-Passwort muessen fuer WebDAV gemeinsam vollstaendig sein.');
|
|
||||||
}
|
|
||||||
if (($api_key_id === '') !== ($api_key_secret === ''))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Piwigo-API-Schluessel-ID und API-Geheimnis muessen gemeinsam vollstaendig sein.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($nextcloud_url !== '')
|
|
||||||
{
|
|
||||||
$validated_nc = bratonien_tools_nc_connector_validate_nextcloud_access($nextcloud_url, $nextcloud_user, $nextcloud_password);
|
|
||||||
$nextcloud_url = $validated_nc['base_url'];
|
|
||||||
$nextcloud_user = $validated_nc['username'];
|
|
||||||
$credentials['nextcloud_user'] = $nextcloud_user;
|
|
||||||
}
|
|
||||||
if ($api_key_id !== '')
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_connector_validate_scoped_api($api_key_id, $api_key_secret);
|
|
||||||
$credentials['api_key_id'] = $api_key_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$config['host'] = $host;
|
$config['host'] = $host;
|
||||||
$config['port'] = (string)$port;
|
$config['port'] = (string)$port;
|
||||||
$config['database'] = $database;
|
$config['database'] = $database;
|
||||||
@@ -320,16 +174,13 @@ function bratonien_tools_nc_connector_update_local_friendly()
|
|||||||
$config['max_wait_seconds'] = max(60, (int)($_POST['nc_max_wait_seconds'] ?? ($config['max_wait_seconds'] ?? 900)));
|
$config['max_wait_seconds'] = max(60, (int)($_POST['nc_max_wait_seconds'] ?? ($config['max_wait_seconds'] ?? 900)));
|
||||||
$config['full_sync_seconds'] = max(300, (int)($_POST['nc_full_sync_seconds'] ?? ($config['full_sync_seconds'] ?? 86400)));
|
$config['full_sync_seconds'] = max(300, (int)($_POST['nc_full_sync_seconds'] ?? ($config['full_sync_seconds'] ?? 86400)));
|
||||||
$config['storages'] = $storages;
|
$config['storages'] = $storages;
|
||||||
if ($nextcloud_url !== '')
|
|
||||||
{
|
|
||||||
$config['nextcloud_url'] = $nextcloud_url;
|
|
||||||
$config['access_user'] = $nextcloud_user;
|
|
||||||
$config['nextcloud_access_user'] = $nextcloud_user;
|
|
||||||
}
|
|
||||||
$config['piwigo_auth'] = 'connection-scoped';
|
|
||||||
$config['api_enabled'] = $api_key_id !== '' && $api_key_secret !== '';
|
|
||||||
unset($config['verification']);
|
unset($config['verification']);
|
||||||
|
|
||||||
|
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||||
|
$new_db_password = (string)($_POST['nc_db_password'] ?? '');
|
||||||
|
if ($new_db_password !== '') $credentials['db_password'] = $new_db_password;
|
||||||
|
if (trim((string)($credentials['db_password'] ?? '')) === '') throw new RuntimeException('Für die Legacy-Verbindung ist kein Datenbankpasswort gespeichert.');
|
||||||
|
|
||||||
$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('Connector-Konfiguration konnte nicht serialisiert werden.');
|
if (!is_string($config_json)) throw new RuntimeException('Connector-Konfiguration konnte nicht serialisiert werden.');
|
||||||
$secret_payload = json_encode($credentials, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
$secret_payload = json_encode($credentials, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
@@ -340,9 +191,5 @@ function bratonien_tools_nc_connector_update_local_friendly()
|
|||||||
$now = date('Y-m-d H:i:s');
|
$now = date('Y-m-d H:i:s');
|
||||||
pwg_query("UPDATE `$table` SET name='".pwg_db_real_escape_string($name)."', config_json='".pwg_db_real_escape_string($config_json)."', secret_blob='".pwg_db_real_escape_string($secret_blob)."', updated='".pwg_db_real_escape_string($now)."' WHERE id=".$id." LIMIT 1");
|
pwg_query("UPDATE `$table` SET name='".pwg_db_real_escape_string($name)."', config_json='".pwg_db_real_escape_string($config_json)."', secret_blob='".pwg_db_real_escape_string($secret_blob)."', updated='".pwg_db_real_escape_string($now)."' WHERE id=".$id." LIMIT 1");
|
||||||
|
|
||||||
$updated = bratonien_tools_nc_connector_connection($id, true);
|
return array('message'=>'Verbindung #'.$id.' wurde gespeichert. Die neuen Werte gelten ab dem nächsten Connector-Lauf.');
|
||||||
$migration = $updated ? bratonien_tools_nc_connector_migration_state($updated) : array('ready'=>false);
|
|
||||||
return array(
|
|
||||||
'message'=>'Verbindung #'.$id.' wurde gespeichert. '.(!empty($migration['ready']) ? 'Die WebDAV-Migration ist jetzt bereit.' : 'Die WebDAV-Migration ist noch nicht vollstaendig vorbereitet.'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,25 +5,46 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link a WebDAV successor with the exact legacy connection selected for migration.
|
* Return the only existing local connector as migration fallback.
|
||||||
* The caller must execute this inside the same transaction that creates the successor.
|
|
||||||
*/
|
*/
|
||||||
function bratonien_tools_nc_connector_pair_migration_fallback($legacy_id, $webdav_id, array &$webdav_config, $now)
|
function bratonien_tools_nc_connector_single_local_fallback()
|
||||||
{
|
{
|
||||||
$legacy_id = (int)$legacy_id;
|
bratonien_tools_nc_connector_ensure_table();
|
||||||
$webdav_id = (int)$webdav_id;
|
$table = bratonien_tools_nc_connector_table();
|
||||||
if ($legacy_id < 1 || $webdav_id < 1 || $legacy_id === $webdav_id)
|
$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))
|
||||||
{
|
{
|
||||||
throw new RuntimeException('Die Migrationszuordnung ist ungueltig.');
|
$rows[] = $row;
|
||||||
|
if (count($rows) > 1) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$legacy = bratonien_tools_nc_connector_connection($legacy_id, false);
|
if (count($rows) !== 1) return null;
|
||||||
if (!$legacy || (string)$legacy['adapter'] !== 'local')
|
|
||||||
{
|
$row = $rows[0];
|
||||||
throw new RuntimeException('Die ausgewaehlte Legacy-Verbindung fuer die Migration ist nicht mehr verfuegbar.');
|
$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;
|
||||||
|
|
||||||
$legacy_config = isset($legacy['config']) && is_array($legacy['config']) ? $legacy['config'] : array();
|
|
||||||
$webdav_config['migration'] = array(
|
$webdav_config['migration'] = array(
|
||||||
'role'=>'webdav-primary-candidate',
|
'role'=>'webdav-primary-candidate',
|
||||||
'legacy_fallback_connection_id'=>$legacy_id,
|
'legacy_fallback_connection_id'=>$legacy_id,
|
||||||
@@ -31,9 +52,11 @@ function bratonien_tools_nc_connector_pair_migration_fallback($legacy_id, $webda
|
|||||||
'paired_at'=>(string)$now,
|
'paired_at'=>(string)$now,
|
||||||
'cutover_state'=>'parallel',
|
'cutover_state'=>'parallel',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$legacy_config = $legacy['config'];
|
||||||
$legacy_config['migration'] = array(
|
$legacy_config['migration'] = array(
|
||||||
'role'=>'legacy-fallback',
|
'role'=>'legacy-fallback',
|
||||||
'webdav_successor_connection_id'=>$webdav_id,
|
'webdav_successor_connection_id'=>(int)$webdav_id,
|
||||||
'fallback_policy'=>'keep-running',
|
'fallback_policy'=>'keep-running',
|
||||||
'paired_at'=>(string)$now,
|
'paired_at'=>(string)$now,
|
||||||
'cutover_state'=>'parallel',
|
'cutover_state'=>'parallel',
|
||||||
@@ -46,7 +69,7 @@ function bratonien_tools_nc_connector_pair_migration_fallback($legacy_id, $webda
|
|||||||
}
|
}
|
||||||
|
|
||||||
$table = bratonien_tools_nc_connector_table();
|
$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." AND adapter='local' LIMIT 1");
|
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;
|
return $legacy_id;
|
||||||
}
|
}
|
||||||
@@ -54,8 +77,9 @@ function bratonien_tools_nc_connector_pair_migration_fallback($legacy_id, $webda
|
|||||||
/**
|
/**
|
||||||
* Create or update a WebDAV-backed connector from the user-facing wizard.
|
* Create or update a WebDAV-backed connector from the user-facing wizard.
|
||||||
*
|
*
|
||||||
* Remote connections are updated in place. A legacy connection is paired only
|
* Remote connections are updated in place. When the editor was opened for a
|
||||||
* when the wizard was explicitly opened in migration mode for that connection.
|
* 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()
|
||||||
{
|
{
|
||||||
@@ -63,7 +87,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 vollstaendig vorbereitet.');
|
throw new RuntimeException('Die WebDAV-Verbindung wurde im Assistenten noch nicht vollständig vorbereitet.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$base_url = rtrim(trim((string)($state['base_url'] ?? '')), '/');
|
$base_url = rtrim(trim((string)($state['base_url'] ?? '')), '/');
|
||||||
@@ -71,7 +95,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('Fuer den WebDAV-Zugang fehlen Nextcloud-Adresse oder Zugangsdaten.');
|
throw new RuntimeException('Für 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'])
|
||||||
@@ -80,19 +104,17 @@ 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 auswaehlen.');
|
$selected = array_values(array_filter($selected, function($path) { return $path !== ''; }));
|
||||||
|
if (!$selected) throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis auswählen.');
|
||||||
|
|
||||||
$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('Fuer ein ausgewaehltes Nextcloud-Verzeichnis fehlt die eindeutige Datei-ID.');
|
if ($fileid < 1) throw new RuntimeException('Für ein ausgewähltes Nextcloud-Verzeichnis fehlt die eindeutige Datei-ID.');
|
||||||
$display_name = $path === ''
|
|
||||||
? (trim((string)($state['display_name'] ?? '')) !== '' ? trim((string)$state['display_name']) : $username)
|
|
||||||
: basename($path);
|
|
||||||
$roots[] = array(
|
$roots[] = array(
|
||||||
'fileid'=>$fileid,
|
'fileid'=>$fileid,
|
||||||
'display_name'=>$display_name,
|
'display_name'=>basename($path),
|
||||||
'webdav_path'=>$path,
|
'webdav_path'=>$path,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -115,14 +137,6 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
&& (string)$editing_connection['adapter'] === 'remote'
|
&& (string)$editing_connection['adapter'] === 'remote'
|
||||||
&& (string)($editing_connection['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
&& (string)($editing_connection['config']['source_mode'] ?? '') === 'webdav-placeholder'
|
||||||
&& $editing_mode === 'update';
|
&& $editing_mode === 'update';
|
||||||
$migrating_legacy = $editing_connection
|
|
||||||
&& (string)$editing_connection['adapter'] === 'local'
|
|
||||||
&& $editing_mode === 'migrate';
|
|
||||||
|
|
||||||
if ($editing_mode === 'migrate' && !$migrating_legacy)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Die fuer die Migration ausgewaehlte Legacy-Verbindung ist nicht mehr verfuegbar.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = array(
|
$config = array(
|
||||||
'origin'=>'native',
|
'origin'=>'native',
|
||||||
@@ -186,12 +200,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." AND adapter='remote' 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." 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 naechste Connector-Lauf verwendet die neuen Einstellungen.',
|
'message'=>'WebDAV-Verbindung #'.$editing_id.' wurde gespeichert. Der nächste Connector-Lauf verwendet die neuen Einstellungen.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,41 +213,33 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
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.');
|
||||||
|
|
||||||
$connection_key = 'webdav-'.bin2hex(random_bytes(12));
|
$connection_key = 'webdav-'.bin2hex(random_bytes(12));
|
||||||
$legacy_fallback_id = null;
|
pwg_query("INSERT INTO `$table` (connection_key,name,adapter,enabled,takeover_state,config_json,secret_blob,created,updated) VALUES ('"
|
||||||
$id = 0;
|
.pwg_db_real_escape_string($connection_key)."','"
|
||||||
|
.pwg_db_real_escape_string($name)."','remote',0,'disabled','"
|
||||||
|
.pwg_db_real_escape_string($config_json)."','"
|
||||||
|
.pwg_db_real_escape_string($secret_blob)."','"
|
||||||
|
.pwg_db_real_escape_string($now)."','"
|
||||||
|
.pwg_db_real_escape_string($now)."')");
|
||||||
|
|
||||||
|
$id = (int)pwg_db_insert_id();
|
||||||
|
if ($id < 1) throw new RuntimeException('Die WebDAV-Verbindung konnte nicht eindeutig angelegt werden.');
|
||||||
|
|
||||||
pwg_query('START TRANSACTION');
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pwg_query("INSERT INTO `$table` (connection_key,name,adapter,enabled,takeover_state,config_json,secret_blob,created,updated) VALUES ('"
|
|
||||||
.pwg_db_real_escape_string($connection_key)."','"
|
|
||||||
.pwg_db_real_escape_string($name)."','remote',0,'disabled','"
|
|
||||||
.pwg_db_real_escape_string($config_json)."','"
|
|
||||||
.pwg_db_real_escape_string($secret_blob)."','"
|
|
||||||
.pwg_db_real_escape_string($now)."','"
|
|
||||||
.pwg_db_real_escape_string($now)."')");
|
|
||||||
|
|
||||||
$id = (int)pwg_db_insert_id();
|
|
||||||
if ($id < 1) throw new RuntimeException('Die WebDAV-Verbindung konnte nicht eindeutig angelegt werden.');
|
|
||||||
|
|
||||||
$config['state_dir'] = '/var/lib/bratonien-tools/nc-connector/connection-'.$id;
|
$config['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';
|
||||||
if ($migrating_legacy)
|
$legacy_fallback_id = bratonien_tools_nc_connector_pair_migration_fallback($id, $config, $now);
|
||||||
{
|
|
||||||
$legacy_fallback_id = bratonien_tools_nc_connector_pair_migration_fallback($editing_id, $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('Die WebDAV-Verbindung konnte nach dem Anlegen nicht serialisiert werden.');
|
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." AND adapter='remote' LIMIT 1");
|
pwg_query("UPDATE `$table` SET config_json='".pwg_db_real_escape_string($config_json)."' WHERE id=".$id." LIMIT 1");
|
||||||
pwg_query('COMMIT');
|
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
{
|
{
|
||||||
pwg_query('ROLLBACK');
|
pwg_query("DELETE FROM `$table` WHERE id=".$id." LIMIT 1");
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ function bratonien_tools_nc_wizard_save_sources_dispatch()
|
|||||||
$selected = isset($state['directory_selected']) && is_array($state['directory_selected'])
|
$selected = isset($state['directory_selected']) && is_array($state['directory_selected'])
|
||||||
? array_values(array_unique(array_map(function($path) { return trim((string)$path, '/'); }, $state['directory_selected'])))
|
? array_values(array_unique(array_map(function($path) { return trim((string)$path, '/'); }, $state['directory_selected'])))
|
||||||
: array();
|
: array();
|
||||||
|
$selected = array_values(array_filter($selected, function($path) { return $path !== ''; }));
|
||||||
if (!$selected)
|
if (!$selected)
|
||||||
{
|
{
|
||||||
throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis auswählen.');
|
throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis auswählen.');
|
||||||
@@ -142,12 +143,9 @@ function bratonien_tools_nc_wizard_save_sources_dispatch()
|
|||||||
{
|
{
|
||||||
throw new RuntimeException('Für eine Auswahl fehlt die eindeutige Nextcloud-Datei-ID. Bitte das Verzeichnis erneut auswählen.');
|
throw new RuntimeException('Für eine Auswahl fehlt die eindeutige Nextcloud-Datei-ID. Bitte das Verzeichnis erneut auswählen.');
|
||||||
}
|
}
|
||||||
$display_name = $path === ''
|
|
||||||
? (trim((string)($state['display_name'] ?? '')) !== '' ? trim((string)$state['display_name']) : (string)$state['username'])
|
|
||||||
: basename($path);
|
|
||||||
$roots[] = array(
|
$roots[] = array(
|
||||||
'fileid'=>$fileid,
|
'fileid'=>$fileid,
|
||||||
'display_name'=>$display_name,
|
'display_name'=>basename($path),
|
||||||
'webdav_path'=>$path,
|
'webdav_path'=>$path,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -158,35 +156,9 @@ 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);
|
|
||||||
|
|
||||||
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);
|
bratonien_tools_nc_wizard_store($state);
|
||||||
return array('message'=>'WebDAV-Verzeichnisse wurden übernommen. Die Verbindung ist für den nächsten Einrichtungsschritt vorbereitet.');
|
|
||||||
|
return array('message'=>'WebDAV-Verzeichnisse wurden übernommen. Die Verbindung ist für den parallelen Testweg vorbereitet.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_wizard_finish_dispatch()
|
function bratonien_tools_nc_wizard_finish_dispatch()
|
||||||
|
|||||||
@@ -4,23 +4,6 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
die('Hacking attempt!');
|
die('Hacking attempt!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($GLOBALS['template']) && is_object($GLOBALS['template']) && method_exists($GLOBALS['template'], 'func_combine_script'))
|
|
||||||
{
|
|
||||||
$script_version = function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : '0.9.6.15';
|
|
||||||
$GLOBALS['template']->func_combine_script(array(
|
|
||||||
'id'=>'bratonien_nc_connector_edit_v2',
|
|
||||||
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_edit_v2.js',
|
|
||||||
'load'=>'footer',
|
|
||||||
'version'=>$script_version,
|
|
||||||
));
|
|
||||||
$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');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'tools/watermark.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'tools/watermark.inc.php');
|
||||||
require_once(BRATONIEN_TOOLS_PATH . 'tools/watermark_profiles.inc.php');
|
require_once(BRATONIEN_TOOLS_PATH . 'tools/watermark_profiles.inc.php');
|
||||||
|
|||||||
@@ -1,324 +0,0 @@
|
|||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
function ready(callback) {
|
|
||||||
if (document.readyState === 'loading') {
|
|
||||||
document.addEventListener('DOMContentLoaded', function () { window.setTimeout(callback, 0); });
|
|
||||||
} else {
|
|
||||||
window.setTimeout(callback, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ready(function () {
|
|
||||||
var section = document.getElementById('nc-connector');
|
|
||||||
if (!section) return;
|
|
||||||
|
|
||||||
var pwgTokenInput = section.querySelector('input[name="pwg_token"]');
|
|
||||||
var pwgToken = pwgTokenInput ? pwgTokenInput.value : '';
|
|
||||||
var modeKey = 'bratonienNcWizardMode';
|
|
||||||
|
|
||||||
function escapeHtml(value) {
|
|
||||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (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) {
|
|
||||||
return fetch('plugins/bratonien_tools/nc-connector-edit-data.php?connection_id='+encodeURIComponent(id)+'&_='+Date.now(), {
|
|
||||||
credentials:'same-origin',
|
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'}
|
|
||||||
}).then(function (response) {
|
|
||||||
return response.json().then(function (data) {
|
|
||||||
if (!response.ok) throw new Error(data.error || ('HTTP '+response.status));
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function dialog() {
|
|
||||||
var node = document.getElementById('bratonien-nc-connection-edit-v2');
|
|
||||||
if (node) return node;
|
|
||||||
node = document.createElement('dialog');
|
|
||||||
node.id = 'bratonien-nc-connection-edit-v2';
|
|
||||||
node.className = 'bratonien-edit-dialog';
|
|
||||||
node.innerHTML = '<div class="bratonien-edit-dialog__body">'
|
|
||||||
+ '<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>'
|
|
||||||
+ '<button type="button" class="buttonLike" data-edit-v2-close>Schließen</button></div>'
|
|
||||||
+ '<div data-edit-v2-content style="margin-top:1rem"></div></div>';
|
|
||||||
document.body.appendChild(node);
|
|
||||||
node.querySelector('[data-edit-v2-close]').addEventListener('click', function () { node.close(); });
|
|
||||||
node.addEventListener('click', function (event) { if (event.target === node) node.close(); });
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
function storageRow(storage) {
|
|
||||||
storage = storage || {};
|
|
||||||
return '<div class="bratonien-storage-row" data-storage-row>'
|
|
||||||
+ '<label>Storage-ID<input name="nc_storage_id[]" value="'+escapeHtml(storage.storage_id || '')+'" required></label>'
|
|
||||||
+ '<label>Quellordner<input name="nc_source_prefix[]" value="'+escapeHtml(storage.source_prefix || '')+'" placeholder="optional"></label>'
|
|
||||||
+ '<label>Lokaler Speicherpfad<input name="nc_local_mount[]" value="'+escapeHtml(storage.local_mount || '')+'" required></label>'
|
|
||||||
+ '<button type="button" class="buttonLike" data-remove-storage>Entfernen</button></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearValidation(form) {
|
|
||||||
[].slice.call(form.querySelectorAll('[aria-invalid="true"]')).forEach(function (field) {
|
|
||||||
field.removeAttribute('aria-invalid');
|
|
||||||
field.style.borderColor = '';
|
|
||||||
field.style.boxShadow = '';
|
|
||||||
});
|
|
||||||
[].slice.call(form.querySelectorAll('[data-edit-v2-field-error]')).forEach(function (node) { node.remove(); });
|
|
||||||
var box = form.querySelector('[data-edit-v2-error-summary]');
|
|
||||||
if (box) box.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
function fieldNodes(form, fieldName) {
|
|
||||||
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;
|
|
||||||
|
|
||||||
var submit = form.querySelector('button[type="submit"]');
|
|
||||||
if (submit) submit.disabled = true;
|
|
||||||
|
|
||||||
var body = 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:body
|
|
||||||
}).then(function (response) {
|
|
||||||
return response.json().then(function (data) {
|
|
||||||
if (!response.ok || !data.ok) {
|
|
||||||
showValidation(form, data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editDialog.close();
|
|
||||||
window.location.reload();
|
|
||||||
});
|
|
||||||
}).catch(function (error) {
|
|
||||||
showValidation(form, {message:error.message || String(error), fields:[]});
|
|
||||||
}).finally(function () {
|
|
||||||
if (submit) submit.disabled = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function openEditor(id) {
|
|
||||||
var editDialog = dialog();
|
|
||||||
var content = editDialog.querySelector('[data-edit-v2-content]');
|
|
||||||
content.innerHTML = '<p class="bratonien-base-note">Verbindung wird geladen …</p>';
|
|
||||||
if (typeof editDialog.showModal === 'function') editDialog.showModal();
|
|
||||||
else editDialog.setAttribute('open', 'open');
|
|
||||||
|
|
||||||
loadConnection(id).then(function (data) {
|
|
||||||
if (data.adapter !== 'local') throw new Error('Diese Ansicht ist nur für die bestehende Legacy-Verbindung vorgesehen.');
|
|
||||||
var legacy = data.legacy || {};
|
|
||||||
var webdav = data.webdav || {};
|
|
||||||
var storages = Array.isArray(legacy.storages) ? legacy.storages : [];
|
|
||||||
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>'
|
|
||||||
+ '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
|
||||||
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(data.id)+'">'
|
|
||||||
+ '<h5>Verbindung</h5><div class="bratonien-form-grid">'
|
|
||||||
+ '<label class="bratonien-label">Name</label><input name="connection_name" value="'+escapeHtml(data.name)+'" required>'
|
|
||||||
+ '</div>'
|
|
||||||
+ '<h5 style="margin-top:1.2rem">Nextcloud / WebDAV</h5>'
|
|
||||||
+ '<p class="bratonien-base-note">Diese Angaben werden für den neuen WebDAV-Weg benötigt und gehören zu genau dieser Verbindung.</p>'
|
|
||||||
+ '<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-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>'
|
|
||||||
+ '<h5 style="margin-top:1.2rem">Piwigo API dieser Verbindung</h5>'
|
|
||||||
+ '<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-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')+'">'
|
|
||||||
+ '</div>'
|
|
||||||
+ '<p class="bratonien-base-note"><strong>WebDAV-Migration:</strong> '+migrationText+'</p>'
|
|
||||||
+ '<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">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">Reader-Benutzer</label><input name="nc_user" value="'+escapeHtml(legacy.user)+'" required>'
|
|
||||||
+ '<label class="bratonien-label">Reader-Passwort</label><input name="nc_db_password" type="password" autocomplete="new-password" placeholder="'+(legacy.has_db_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
|
||||||
+ '</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>'
|
|
||||||
+ '<details style="margin-top:1rem"><summary>Erweiterte Legacy-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">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">Ruhezeit (Sek.)</label><input name="nc_quiet_seconds" type="number" min="0" value="'+escapeHtml(legacy.quiet_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)+'">'
|
|
||||||
+ '</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>'
|
|
||||||
+ '</form>';
|
|
||||||
|
|
||||||
var form = content.querySelector('[data-edit-v2-form]');
|
|
||||||
form.querySelector('[data-edit-v2-cancel]').addEventListener('click', function () { editDialog.close(); });
|
|
||||||
form.querySelector('[data-add-storage]').addEventListener('click', function () {
|
|
||||||
form.querySelector('[data-storage-list]').insertAdjacentHTML('beforeend', storageRow({}));
|
|
||||||
});
|
|
||||||
form.addEventListener('click', function (event) {
|
|
||||||
var remove = event.target.closest('[data-remove-storage]');
|
|
||||||
if (!remove) return;
|
|
||||||
var row = remove.closest('[data-storage-row]');
|
|
||||||
if (row) row.remove();
|
|
||||||
});
|
|
||||||
form.addEventListener('submit', function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
submitEditor(form, editDialog);
|
|
||||||
});
|
|
||||||
}).catch(function (error) {
|
|
||||||
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) {
|
|
||||||
var form = button.closest('form');
|
|
||||||
if (form) form.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
[].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) {
|
|
||||||
var deleteForm = deleteButton.closest('form');
|
|
||||||
if (!deleteForm) return;
|
|
||||||
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
|
||||||
if (!idInput) return;
|
|
||||||
var id = idInput.value;
|
|
||||||
|
|
||||||
loadConnection(id).then(function (data) {
|
|
||||||
if (data.adapter === 'local') rebuildLocalActions(deleteForm, id, data);
|
|
||||||
else rebuildRemoteActions(deleteForm, id);
|
|
||||||
}).catch(function (error) {
|
|
||||||
var actions = deleteForm.parentElement;
|
|
||||||
if (!actions) return;
|
|
||||||
var info = document.createElement('span');
|
|
||||||
info.className = 'bratonien-main-cache__warning';
|
|
||||||
info.textContent = 'Verbindungstyp konnte nicht geladen werden: '+(error.message || String(error));
|
|
||||||
actions.insertBefore(info, deleteForm);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
@@ -1,219 +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) {
|
|
||||||
var label = 'Nextcloud-Ordner auswählen & migrieren';
|
|
||||||
var title = 'Die WebDAV-Quelle wird im Nextcloud-Ordnerbrowser ausgewählt. Der bestehende SMB-/Legacy-Speicher wird nicht als WebDAV-Quelle übernommen.';
|
|
||||||
[].slice.call(root.querySelectorAll('button[value="nc_connector_migrate_start"]')).forEach(function (button) {
|
|
||||||
if (button.textContent !== label) button.textContent = label;
|
|
||||||
if (button.title !== title) button.title = title;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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.20
|
Version: 0.9.6.9
|
||||||
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();
|
||||||
@@ -86,15 +79,6 @@ $payload = array(
|
|||||||
'full_sync_seconds'=>(int)($config['full_sync_seconds'] ?? 86400),
|
'full_sync_seconds'=>(int)($config['full_sync_seconds'] ?? 86400),
|
||||||
'storages'=>$storages,
|
'storages'=>$storages,
|
||||||
),
|
),
|
||||||
'webdav'=>array(
|
|
||||||
'nextcloud_url'=>(string)($config['nextcloud_url'] ?? ''),
|
|
||||||
'nextcloud_user'=>(string)($credentials['nextcloud_user'] ?? $config['nextcloud_access_user'] ?? $config['access_user'] ?? ''),
|
|
||||||
'has_nextcloud_password'=>(string)($credentials['nextcloud_password'] ?? '') !== '',
|
|
||||||
'api_key_id'=>(string)($credentials['api_key_id'] ?? ''),
|
|
||||||
'has_api_key_secret'=>trim((string)($credentials['api_key_secret'] ?? '')) !== '',
|
|
||||||
'migration_ready'=>!empty($migration['ready']),
|
|
||||||
'migration_missing'=>array_values((array)($migration['missing'] ?? array())),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
|||||||
@@ -1,312 +0,0 @@
|
|||||||
<?php
|
|
||||||
$piwigo_root = realpath(dirname(__DIR__, 2));
|
|
||||||
if ($piwigo_root === false)
|
|
||||||
{
|
|
||||||
http_response_code(500);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
define('PHPWG_ROOT_PATH', rtrim($piwigo_root, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR);
|
|
||||||
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
|
||||||
header('Cache-Control: no-store, max-age=0');
|
|
||||||
|
|
||||||
function bratonien_tools_nc_edit_json($status, array $payload)
|
|
||||||
{
|
|
||||||
http_response_code((int)$status);
|
|
||||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_nc_edit_fail($message, array $fields = array(), $stage = '', $detail = '')
|
|
||||||
{
|
|
||||||
$visible = trim((string)$message);
|
|
||||||
if ($stage !== '') $visible = 'Bereich: '.$stage.' — '.$visible;
|
|
||||||
if ($detail !== '') $visible .= ' Technische Ursache: '.$detail;
|
|
||||||
|
|
||||||
bratonien_tools_nc_edit_json(422, array(
|
|
||||||
'ok'=>false,
|
|
||||||
'message'=>$visible,
|
|
||||||
'stage'=>(string)$stage,
|
|
||||||
'detail'=>(string)$detail,
|
|
||||||
'fields'=>array_values(array_unique($fields)),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_nc_edit_probe($url, $username = '', $password = '', array $headers = array())
|
|
||||||
{
|
|
||||||
if (!function_exists('curl_init'))
|
|
||||||
{
|
|
||||||
return array('ok'=>false, 'http'=>0, 'errno'=>-1, 'error'=>'cURL ist in PHP nicht verfügbar.', 'body'=>'');
|
|
||||||
}
|
|
||||||
|
|
||||||
$ch = curl_init($url);
|
|
||||||
$options = array(
|
|
||||||
CURLOPT_RETURNTRANSFER=>true,
|
|
||||||
CURLOPT_FOLLOWLOCATION=>true,
|
|
||||||
CURLOPT_MAXREDIRS=>3,
|
|
||||||
CURLOPT_CONNECTTIMEOUT=>8,
|
|
||||||
CURLOPT_TIMEOUT=>15,
|
|
||||||
CURLOPT_HTTPHEADER=>array_merge(array('Accept: application/json'), $headers),
|
|
||||||
CURLOPT_USERAGENT=>'Bratonien-Tools-NC-Editor/'.(function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : 'dev'),
|
|
||||||
);
|
|
||||||
if ($username !== '')
|
|
||||||
{
|
|
||||||
$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
|
|
||||||
$options[CURLOPT_USERPWD] = $username.':'.$password;
|
|
||||||
}
|
|
||||||
curl_setopt_array($ch, $options);
|
|
||||||
$body = curl_exec($ch);
|
|
||||||
$errno = curl_errno($ch);
|
|
||||||
$error = curl_error($ch);
|
|
||||||
$http = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'ok'=>$body !== false && $errno === 0,
|
|
||||||
'http'=>$http,
|
|
||||||
'errno'=>$errno,
|
|
||||||
'error'=>$error,
|
|
||||||
'body'=>$body === false ? '' : (string)$body,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!defined('BRATONIEN_TOOLS_PATH'))
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_json(404, array('ok'=>false, 'message'=>'Bratonien Tools ist nicht aktiv.', 'fields'=>array()));
|
|
||||||
}
|
|
||||||
if (!function_exists('is_admin') || !is_admin())
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_json(403, array('ok'=>false, 'message'=>'Administratorrechte erforderlich.', 'fields'=>array()));
|
|
||||||
}
|
|
||||||
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST')
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_json(405, array('ok'=>false, 'message'=>'Nur POST ist erlaubt.', 'fields'=>array()));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
check_pwg_token();
|
|
||||||
require_once(BRATONIEN_TOOLS_PATH.'include/tool_registry.inc.php');
|
|
||||||
|
|
||||||
$id = (int)($_POST['connection_id'] ?? 0);
|
|
||||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
|
||||||
if (!$connection)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_fail('Die zu bearbeitende Verbindung wurde nicht gefunden.', array(), 'Verbindung');
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
|
||||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
|
||||||
|
|
||||||
$nextcloud_input = trim((string)($_POST['nc_nextcloud_url'] ?? ($config['nextcloud_url'] ?? '')));
|
|
||||||
$nextcloud_user = trim((string)($_POST['nc_nextcloud_user'] ?? ($credentials['nextcloud_user'] ?? '')));
|
|
||||||
$submitted_nc_password = (string)($_POST['nc_nextcloud_password'] ?? '');
|
|
||||||
$nextcloud_password = $submitted_nc_password !== '' ? $submitted_nc_password : (string)($credentials['nextcloud_password'] ?? '');
|
|
||||||
|
|
||||||
$has_any_nextcloud = $nextcloud_input !== '' || $nextcloud_user !== '' || $nextcloud_password !== '';
|
|
||||||
if ($has_any_nextcloud)
|
|
||||||
{
|
|
||||||
$missing = array();
|
|
||||||
if ($nextcloud_input === '') $missing[] = 'nc_nextcloud_url';
|
|
||||||
if ($nextcloud_user === '') $missing[] = 'nc_nextcloud_user';
|
|
||||||
if ($nextcloud_password === '') $missing[] = 'nc_nextcloud_password';
|
|
||||||
if ($missing)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Die WebDAV-Daten sind unvollständig. Adresse, Benutzer und Passwort werden gemeinsam benötigt.',
|
|
||||||
$missing,
|
|
||||||
'Nextcloud / WebDAV'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$candidate_urls = bratonien_tools_nc_wizard_candidate_urls($nextcloud_input);
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_fail($e->getMessage(), array('nc_nextcloud_url'), 'Nextcloud / WebDAV');
|
|
||||||
}
|
|
||||||
|
|
||||||
$nextcloud_url = '';
|
|
||||||
$last_probe = null;
|
|
||||||
$last_status_url = '';
|
|
||||||
foreach ($candidate_urls as $candidate_url)
|
|
||||||
{
|
|
||||||
$status_url = $candidate_url.'/status.php';
|
|
||||||
$probe = bratonien_tools_nc_edit_probe($status_url);
|
|
||||||
$last_probe = $probe;
|
|
||||||
$last_status_url = $status_url;
|
|
||||||
|
|
||||||
if (!$probe['ok'] || $probe['http'] < 200 || $probe['http'] >= 300)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$status = json_decode($probe['body'], true);
|
|
||||||
if (!is_array($status) || empty($status['installed']))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nextcloud_url = $candidate_url;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($nextcloud_url === '')
|
|
||||||
{
|
|
||||||
$attempts = array();
|
|
||||||
foreach ($candidate_urls as $candidate_url)
|
|
||||||
{
|
|
||||||
$attempts[] = $candidate_url.'/status.php';
|
|
||||||
}
|
|
||||||
if (is_array($last_probe) && !$last_probe['ok'])
|
|
||||||
{
|
|
||||||
$technical = $last_probe['errno'] >= 0
|
|
||||||
? 'cURL '.$last_probe['errno'].($last_probe['error'] !== '' ? ': '.$last_probe['error'] : '')
|
|
||||||
: $last_probe['error'];
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Die Nextcloud-Adresse ist vom Piwigo-Server aus nicht erreichbar. Ohne angegebenes Protokoll wurden HTTPS und HTTP geprüft.',
|
|
||||||
array('nc_nextcloud_url'),
|
|
||||||
'Nextcloud / WebDAV – Erreichbarkeit',
|
|
||||||
$technical.' · Geprüft: '.implode(' ; ', $attempts)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Unter der angegebenen Adresse wurde keine erreichbare installierte Nextcloud gefunden. Ohne angegebenes Protokoll wurden HTTPS und HTTP geprüft.',
|
|
||||||
array('nc_nextcloud_url'),
|
|
||||||
'Nextcloud / WebDAV – Erkennung',
|
|
||||||
'Geprüft: '.implode(' ; ', $attempts).($last_probe ? ' · Letzter HTTP-Status: '.$last_probe['http'] : '')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$_POST['nc_nextcloud_url'] = $nextcloud_url;
|
|
||||||
|
|
||||||
$user_url = $nextcloud_url.'/ocs/v2.php/cloud/user?format=json';
|
|
||||||
$user_probe = bratonien_tools_nc_edit_probe($user_url, $nextcloud_user, $nextcloud_password, array('OCS-APIRequest: true'));
|
|
||||||
if (!$user_probe['ok'])
|
|
||||||
{
|
|
||||||
$technical = $user_probe['errno'] >= 0
|
|
||||||
? 'cURL '.$user_probe['errno'].($user_probe['error'] !== '' ? ': '.$user_probe['error'] : '')
|
|
||||||
: $user_probe['error'];
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Die Nextcloud-Anmeldung konnte technisch nicht geprüft werden.',
|
|
||||||
array('nc_nextcloud_url','nc_nextcloud_user','nc_nextcloud_password'),
|
|
||||||
'Nextcloud / WebDAV – Anmeldung',
|
|
||||||
$technical.' · Ziel: '.$user_url
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ($user_probe['http'] === 401 || $user_probe['http'] === 403)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Nextcloud hat Benutzername oder Passwort abgelehnt.',
|
|
||||||
array('nc_nextcloud_user','nc_nextcloud_password'),
|
|
||||||
'Nextcloud / WebDAV – Anmeldung',
|
|
||||||
'HTTP '.$user_probe['http']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ($user_probe['http'] < 200 || $user_probe['http'] >= 300)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Nextcloud ist erreichbar, aber die Benutzerprüfung wurde vom Server abgelehnt.',
|
|
||||||
array('nc_nextcloud_user','nc_nextcloud_password'),
|
|
||||||
'Nextcloud / WebDAV – Anmeldung',
|
|
||||||
'HTTP '.$user_probe['http'].' · Ziel: '.$user_url
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_wizard_ocs_data($user_probe['body']);
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Nextcloud antwortet auf die Benutzerprüfung, die Antwort ist aber nicht gültig: '.$e->getMessage(),
|
|
||||||
array('nc_nextcloud_user','nc_nextcloud_password'),
|
|
||||||
'Nextcloud / WebDAV – Anmeldung'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$api_key_id = trim((string)($_POST['nc_connection_api_key_id'] ?? ($credentials['api_key_id'] ?? '')));
|
|
||||||
$submitted_api_secret = trim((string)($_POST['nc_connection_api_key_secret'] ?? ''));
|
|
||||||
$api_key_secret = $submitted_api_secret !== '' ? $submitted_api_secret : trim((string)($credentials['api_key_secret'] ?? ''));
|
|
||||||
if (($api_key_id === '') !== ($api_key_secret === ''))
|
|
||||||
{
|
|
||||||
$missing = $api_key_id === '' ? array('nc_connection_api_key_id') : array('nc_connection_api_key_secret');
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'API-Schlüssel-ID und API-Geheimnis müssen gemeinsam vollständig sein.',
|
|
||||||
$missing,
|
|
||||||
'Piwigo API'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ($api_key_id !== '')
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_connector_validate_scoped_api($api_key_id, $api_key_secret);
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
'Der Piwigo-API-Zugang konnte nicht bestätigt werden: '.$e->getMessage(),
|
|
||||||
array('nc_connection_api_key_id','nc_connection_api_key_secret'),
|
|
||||||
'Piwigo API'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = bratonien_tools_nc_connector_update_local_friendly();
|
|
||||||
bratonien_tools_nc_edit_json(200, array(
|
|
||||||
'ok'=>true,
|
|
||||||
'message'=>(string)($result['message'] ?? 'Verbindung wurde gespeichert.'),
|
|
||||||
'fields'=>array(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
$message = trim($e->getMessage());
|
|
||||||
if ($message === '') $message = 'Die Verbindung konnte nicht gespeichert werden.';
|
|
||||||
|
|
||||||
$fields = array();
|
|
||||||
$stage = 'Verbindung';
|
|
||||||
$add = function($name) use (&$fields)
|
|
||||||
{
|
|
||||||
if (!in_array($name, $fields, true)) $fields[] = $name;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (stripos($message, 'Name') !== false && stripos($message, 'Datenbankname') === false) $add('connection_name');
|
|
||||||
if (stripos($message, 'Datenbank-Server') !== false) { $add('nc_host'); $stage = 'Legacy-Datenbank'; }
|
|
||||||
if (stripos($message, 'Datenbank-Port') !== false) { $add('nc_port'); $stage = 'Legacy-Datenbank'; }
|
|
||||||
if (stripos($message, 'Datenbankname') !== false) { $add('nc_database'); $stage = 'Legacy-Datenbank'; }
|
|
||||||
if (stripos($message, 'Reader-Benutzer') !== false) { $add('nc_user'); $stage = 'Legacy-Datenbank'; }
|
|
||||||
if (stripos($message, 'Datenbankpasswort') !== false) { $add('nc_db_password'); $stage = 'Legacy-Datenbank'; }
|
|
||||||
if (stripos($message, 'Storage-ID') !== false) { $add('nc_storage_id[]'); $stage = 'Speicherorte'; }
|
|
||||||
if (stripos($message, 'lokaler Pfad') !== false || stripos($message, 'Speicherort') !== false) { $add('nc_local_mount[]'); $stage = 'Speicherorte'; }
|
|
||||||
if (stripos($message, 'Galerieordner') !== false) { $add('nc_gallery_root'); $stage = 'Erweiterte Legacy-Einstellungen'; }
|
|
||||||
if (stripos($message, 'Datenbankansichten') !== false || stripos($message, 'Source-View') !== false) { $add('nc_source_view'); $stage = 'Erweiterte Legacy-Einstellungen'; }
|
|
||||||
if (stripos($message, 'Datenbankansichten') !== false || stripos($message, 'Activity-View') !== false) { $add('nc_activity_view'); $stage = 'Erweiterte Legacy-Einstellungen'; }
|
|
||||||
|
|
||||||
if (stripos($message, 'Nextcloud') !== false)
|
|
||||||
{
|
|
||||||
$stage = 'Nextcloud / WebDAV';
|
|
||||||
if (stripos($message, 'Adresse') !== false) $add('nc_nextcloud_url');
|
|
||||||
if (stripos($message, 'Benutzer') !== false) $add('nc_nextcloud_user');
|
|
||||||
if (stripos($message, 'Passwort') !== false) $add('nc_nextcloud_password');
|
|
||||||
}
|
|
||||||
if (stripos($message, 'API') !== false)
|
|
||||||
{
|
|
||||||
$stage = 'Piwigo API';
|
|
||||||
$add('nc_connection_api_key_id');
|
|
||||||
$add('nc_connection_api_key_secret');
|
|
||||||
}
|
|
||||||
|
|
||||||
bratonien_tools_nc_edit_fail(
|
|
||||||
$message,
|
|
||||||
$fields,
|
|
||||||
$stage,
|
|
||||||
'Interne Prüfung: '.get_class($e)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
<?php
|
|
||||||
$piwigo_root = realpath(dirname(__DIR__, 2));
|
|
||||||
if ($piwigo_root === false)
|
|
||||||
{
|
|
||||||
http_response_code(500);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
define('PHPWG_ROOT_PATH', rtrim($piwigo_root, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR);
|
|
||||||
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
|
||||||
header('Cache-Control: no-store, max-age=0');
|
|
||||||
|
|
||||||
function bratonien_tools_nc_source_picker_json($status, array $payload)
|
|
||||||
{
|
|
||||||
http_response_code((int)$status);
|
|
||||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_nc_source_picker_fail($message, array $fields = array())
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_source_picker_json(422, array(
|
|
||||||
'ok'=>false,
|
|
||||||
'message'=>(string)$message,
|
|
||||||
'fields'=>array_values(array_unique($fields)),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!defined('BRATONIEN_TOOLS_PATH'))
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_source_picker_json(404, array('ok'=>false, 'message'=>'Bratonien Tools ist nicht aktiv.', 'fields'=>array()));
|
|
||||||
}
|
|
||||||
if (!function_exists('is_admin') || !is_admin())
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_source_picker_json(403, array('ok'=>false, 'message'=>'Administratorrechte erforderlich.', 'fields'=>array()));
|
|
||||||
}
|
|
||||||
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST')
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_source_picker_json(405, array('ok'=>false, 'message'=>'Nur POST ist erlaubt.', 'fields'=>array()));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
check_pwg_token();
|
|
||||||
require_once(BRATONIEN_TOOLS_PATH.'include/tool_registry.inc.php');
|
|
||||||
|
|
||||||
$id = (int)($_POST['connection_id'] ?? 0);
|
|
||||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
|
||||||
if (!$connection)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_source_picker_fail('Die zu bearbeitende Verbindung wurde nicht gefunden.');
|
|
||||||
}
|
|
||||||
if ((string)$connection['adapter'] !== 'local')
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_source_picker_fail('Die automatische Migrationsauswahl ist nur für die bestehende Legacy-Verbindung vorgesehen.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
|
||||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
|
||||||
|
|
||||||
$base_url = trim((string)($config['nextcloud_url'] ?? ''));
|
|
||||||
$username = trim((string)($credentials['nextcloud_user'] ?? ''));
|
|
||||||
$password = (string)($credentials['nextcloud_password'] ?? '');
|
|
||||||
|
|
||||||
$missing = array();
|
|
||||||
if ($base_url === '') $missing[] = 'nc_nextcloud_url';
|
|
||||||
if ($username === '') $missing[] = 'nc_nextcloud_user';
|
|
||||||
if ($password === '') $missing[] = 'nc_nextcloud_password';
|
|
||||||
if ($missing)
|
|
||||||
{
|
|
||||||
bratonien_tools_nc_source_picker_fail(
|
|
||||||
'Für die automatische Ordnerauswahl müssen Nextcloud-Adresse, Benutzer und Passwort gespeichert sein.',
|
|
||||||
$missing
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'migrate');
|
|
||||||
|
|
||||||
$state = bratonien_tools_nc_wizard_state();
|
|
||||||
if ((int)($state['step'] ?? 0) !== 2 || empty($state['scan_ok']) || empty($state['directory_selection_ready']))
|
|
||||||
{
|
|
||||||
$detail = trim((string)($state['technical_error'] ?? ''));
|
|
||||||
bratonien_tools_nc_source_picker_fail(
|
|
||||||
$detail !== '' ? 'Die Nextcloud-Ordner konnten nicht geladen werden: '.$detail : 'Die Nextcloud-Ordner konnten nicht geladen werden.',
|
|
||||||
array('nc_nextcloud_url','nc_nextcloud_user','nc_nextcloud_password')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bratonien_tools_nc_source_picker_json(200, array(
|
|
||||||
'ok'=>true,
|
|
||||||
'message'=>'Nextcloud-Ordner wurden geladen. Die Auswahl wird geöffnet.',
|
|
||||||
'fields'=>array(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
catch (Throwable $e)
|
|
||||||
{
|
|
||||||
$message = trim($e->getMessage());
|
|
||||||
if ($message === '') $message = 'Die Nextcloud-Ordnerauswahl konnte nicht vorbereitet werden.';
|
|
||||||
bratonien_tools_nc_source_picker_fail(
|
|
||||||
$message,
|
|
||||||
array('nc_nextcloud_url','nc_nextcloud_user','nc_nextcloud_password')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -134,17 +134,6 @@ try
|
|||||||
if ($baseUrl === '') fail_webdav_reconcile('Nextcloud-Adresse fehlt.');
|
if ($baseUrl === '') fail_webdav_reconcile('Nextcloud-Adresse fehlt.');
|
||||||
if (!$roots) fail_webdav_reconcile('Keine WebDAV-Wurzeln gespeichert.');
|
if (!$roots) fail_webdav_reconcile('Keine WebDAV-Wurzeln gespeichert.');
|
||||||
|
|
||||||
$migration = isset($config['migration']) && is_array($config['migration']) ? $config['migration'] : array();
|
|
||||||
$legacyFallbackId = 0;
|
|
||||||
if ((string)($migration['role'] ?? '') === 'webdav-primary-candidate')
|
|
||||||
{
|
|
||||||
$legacyFallbackId = (int)($migration['legacy_fallback_connection_id'] ?? 0);
|
|
||||||
if ($legacyFallbackId < 1 || $legacyFallbackId === $id)
|
|
||||||
{
|
|
||||||
fail_webdav_reconcile('Die gespeicherte Migrationszuordnung zur Legacy-Verbindung ist ungueltig.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$credentials = decrypt_webdav_credentials((string)$row['secret_blob'], $hexKey);
|
$credentials = decrypt_webdav_credentials((string)$row['secret_blob'], $hexKey);
|
||||||
$user = trim($credentials['nextcloud_user']);
|
$user = trim($credentials['nextcloud_user']);
|
||||||
$password = $credentials['nextcloud_password'];
|
$password = $credentials['nextcloud_password'];
|
||||||
@@ -176,6 +165,7 @@ 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;
|
||||||
@@ -199,9 +189,8 @@ 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'] ?? ''));
|
||||||
$runtimePath = $path === '' ? '/' : $path;
|
if ($path === '' || $display === '' || preg_match('/[\t\r\n]/', $path.$display)) fail_webdav_reconcile('Eine gespeicherte WebDAV-Wurzel ist ungueltig.');
|
||||||
if ($display === '' || preg_match('/[\t\r\n]/', $runtimePath.$display)) fail_webdav_reconcile('Eine gespeicherte WebDAV-Wurzel ist ungueltig.');
|
$rootLines[] = $path."\t".$display;
|
||||||
$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);
|
||||||
@@ -209,7 +198,6 @@ try
|
|||||||
$lines = array(
|
$lines = array(
|
||||||
'PIWIGO_ROOT='.webdav_shell_value($piwigoRoot),
|
'PIWIGO_ROOT='.webdav_shell_value($piwigoRoot),
|
||||||
'CONNECTION_ID='.$id,
|
'CONNECTION_ID='.$id,
|
||||||
'MIGRATION_LEGACY_CONNECTION_ID='.$legacyFallbackId,
|
|
||||||
'SOURCE_MODE=webdav-placeholder',
|
'SOURCE_MODE=webdav-placeholder',
|
||||||
'WEBDAV_BASE_URL='.webdav_shell_value($baseUrl),
|
'WEBDAV_BASE_URL='.webdav_shell_value($baseUrl),
|
||||||
'WEBDAV_USER='.webdav_shell_value($user),
|
'WEBDAV_USER='.webdav_shell_value($user),
|
||||||
@@ -235,15 +223,13 @@ try
|
|||||||
'mode'=>'parallel-webdav',
|
'mode'=>'parallel-webdav',
|
||||||
'config'=>$configPath,
|
'config'=>$configPath,
|
||||||
'piwigo_sync_enabled'=>true,
|
'piwigo_sync_enabled'=>true,
|
||||||
'legacy_fallback_connection_id'=>$legacyFallbackId,
|
|
||||||
'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)) fail_webdav_reconcile('WebDAV-Runtime-Konfiguration konnte nicht serialisiert werden.');
|
if (is_string($json))
|
||||||
$escaped = $db->real_escape_string($json);
|
|
||||||
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);
|
$escaped = $db->real_escape_string($json);
|
||||||
|
$db->query("UPDATE `{$table}` SET config_json='{$escaped}' WHERE id={$id} LIMIT 1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable $e)
|
catch (Throwable $e)
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ CONFIG_DIR="/etc/bratonien-tools/nc-connector"
|
|||||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
declare -A webdav_success_for_legacy=()
|
|
||||||
declare -A webdav_failure_for_legacy=()
|
|
||||||
declare -A legacy_seen=()
|
|
||||||
|
|
||||||
read_config_value() {
|
read_config_value() {
|
||||||
local key="$1"
|
local key="$1"
|
||||||
local file="$2"
|
local file="$2"
|
||||||
@@ -21,15 +17,6 @@ read_config_value() {
|
|||||||
printf '%s' "$value"
|
printf '%s' "$value"
|
||||||
}
|
}
|
||||||
|
|
||||||
numeric_connection_id() {
|
|
||||||
local value="${1:-}"
|
|
||||||
if [[ "$value" =~ ^[0-9]+$ ]]; then
|
|
||||||
printf '%s' "$value"
|
|
||||||
else
|
|
||||||
printf '0'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
compact_text() {
|
compact_text() {
|
||||||
printf '%s\n' "$1" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
printf '%s\n' "$1" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
||||||
}
|
}
|
||||||
@@ -146,76 +133,72 @@ 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_count=0
|
webdav_success=0
|
||||||
webdav_failure_count=0
|
webdav_failed=0
|
||||||
legacy_run_count=0
|
webdav_failure_detail=""
|
||||||
legacy_failure_count=0
|
|
||||||
fallback_used=0
|
|
||||||
unpaired_webdav_failure=0
|
|
||||||
summary_parts=()
|
|
||||||
|
|
||||||
for config in "${webdav_configs[@]}"; do
|
if [[ ${#webdav_configs[@]} -eq 0 ]]; then
|
||||||
name="$(basename "$config")"
|
webdav_failed=1
|
||||||
connection_id="$(numeric_connection_id "$(read_config_value CONNECTION_ID "$config")")"
|
webdav_failure_detail="Keine WebDAV-Runtime-Verbindung ist konfiguriert. Es existiert aktuell nur die Legacy-Verbindung; deshalb kann WebDAV nicht primaer laufen."
|
||||||
legacy_id="$(numeric_connection_id "$(read_config_value MIGRATION_LEGACY_CONNECTION_ID "$config")")"
|
echo "NC Connector: $webdav_failure_detail" >&2
|
||||||
|
else
|
||||||
if [[ "$connection_id" -lt 1 ]]; then
|
for config in "${webdav_configs[@]}"; do
|
||||||
echo "NC Connector: $name besitzt keine gueltige WebDAV-Verbindungs-ID." >&2
|
name="$(basename "$config")"
|
||||||
webdav_failure_count=$((webdav_failure_count + 1))
|
echo "NC Connector WebDAV primaer: $name"
|
||||||
unpaired_webdav_failure=1
|
webdav_output=""
|
||||||
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
if webdav_output="$(env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh" 2>&1)"; then
|
||||||
continue
|
webdav_success=1
|
||||||
fi
|
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output"
|
||||||
|
|
||||||
echo "NC Connector WebDAV #$connection_id: $name"
|
|
||||||
webdav_output=""
|
|
||||||
if webdav_output="$(env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh" 2>&1)"; then
|
|
||||||
webdav_success_count=$((webdav_success_count + 1))
|
|
||||||
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output"
|
|
||||||
if [[ "$legacy_id" -gt 0 ]]; then
|
|
||||||
webdav_success_for_legacy["$legacy_id"]="$connection_id"
|
|
||||||
summary_parts+=("WebDAV #$connection_id erfolgreich; Legacy #$legacy_id uebersprungen")
|
|
||||||
else
|
else
|
||||||
summary_parts+=("WebDAV #$connection_id erfolgreich")
|
webdav_exit=$?
|
||||||
|
webdav_failed=1
|
||||||
|
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output" >&2
|
||||||
|
webdav_failure_detail="$(read_webdav_failure_detail "$config" "$webdav_output")"
|
||||||
|
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
|
||||||
else
|
done
|
||||||
webdav_exit=$?
|
fi
|
||||||
webdav_failure_count=$((webdav_failure_count + 1))
|
|
||||||
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output" >&2
|
|
||||||
webdav_failure_detail="$(read_webdav_failure_detail "$config" "$webdav_output")"
|
|
||||||
webdav_failure_detail="Exit-Code ${webdav_exit}: ${webdav_failure_detail}"
|
|
||||||
echo "NC Connector: WebDAV #$connection_id fehlgeschlagen: $webdav_failure_detail" >&2
|
|
||||||
|
|
||||||
if [[ "$legacy_id" -gt 0 ]]; then
|
if [[ "$webdav_success" -eq 1 ]]; then
|
||||||
webdav_failure_for_legacy["$legacy_id"]="$webdav_failure_detail"
|
write_route_status \
|
||||||
echo "NC Connector: Nur Legacy-Verbindung #$legacy_id ist fuer diesen WebDAV-Lauf als Fallback vorgesehen." >&2
|
"webdav" \
|
||||||
else
|
"WebDAV (primaer)" \
|
||||||
unpaired_webdav_failure=1
|
"WebDAV erfolgreich. Legacy-Fallback wurde in diesem Lauf nicht ausgefuehrt." \
|
||||||
summary_parts+=("WebDAV #$connection_id fehlgeschlagen ohne Legacy-Fallback")
|
"0" \
|
||||||
fi
|
"1"
|
||||||
fi
|
echo "NC Connector: WebDAV erfolgreich; Legacy-Verbindung wird in diesem Lauf nicht ausgefuehrt."
|
||||||
done
|
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
|
||||||
name="$(basename "$config")"
|
name="$(basename "$config")"
|
||||||
connection_id="0"
|
connection_id=""
|
||||||
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 Legacy-Verbindungs-ID." >&2
|
|
||||||
legacy_failure_count=$((legacy_failure_count + 1))
|
|
||||||
summary_parts+=("$name: ungueltige Legacy-Verbindungs-ID")
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
legacy_seen["$connection_id"]=1
|
|
||||||
|
|
||||||
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" \
|
||||||
@@ -226,68 +209,33 @@ for config in "${configs[@]}"; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${webdav_success_for_legacy[$connection_id]:-}" ]]; then
|
echo "NC Connector Legacy-Fallback: $name"
|
||||||
echo "NC Connector: Legacy #$connection_id wird nicht ausgefuehrt, weil der zugeordnete WebDAV-Nachfolger #${webdav_success_for_legacy[$connection_id]} erfolgreich war."
|
if ! env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync.sh"; then
|
||||||
continue
|
legacy_result=1
|
||||||
fi
|
|
||||||
|
|
||||||
legacy_run_count=$((legacy_run_count + 1))
|
|
||||||
if [[ -n "${webdav_failure_for_legacy[$connection_id]:-}" ]]; then
|
|
||||||
echo "NC Connector Legacy-Fallback #$connection_id nach WebDAV-Fehler: $name"
|
|
||||||
fallback_used=1
|
|
||||||
else
|
|
||||||
echo "NC Connector Legacy #$connection_id: $name"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync.sh"; then
|
|
||||||
if [[ -n "${webdav_failure_for_legacy[$connection_id]:-}" ]]; then
|
|
||||||
summary_parts+=("WebDAV fuer Legacy #$connection_id fehlgeschlagen; Legacy-Fallback erfolgreich")
|
|
||||||
else
|
|
||||||
summary_parts+=("Legacy #$connection_id erfolgreich")
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
legacy_failure_count=$((legacy_failure_count + 1))
|
|
||||||
summary_parts+=("Legacy #$connection_id fehlgeschlagen")
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for legacy_id in "${!webdav_failure_for_legacy[@]}"; do
|
if [[ "$legacy_result" -eq 0 ]]; then
|
||||||
if [[ -z "${legacy_seen[$legacy_id]:-}" ]]; then
|
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; Ursache konnte nicht ermittelt werden."
|
||||||
echo "NC Connector: WebDAV fuer Legacy #$legacy_id ist fehlgeschlagen, aber die zugeordnete Legacy-Runtime fehlt." >&2
|
write_route_status \
|
||||||
legacy_failure_count=$((legacy_failure_count + 1))
|
"legacy_fallback" \
|
||||||
summary_parts+=("Fallback #$legacy_id fehlt")
|
"LEGACY-FALLBACK AKTIV" \
|
||||||
fi
|
"WebDAV-Fehler: $webdav_failure_detail Legacy-Fallback wurde erfolgreich ausgefuehrt." \
|
||||||
done
|
"1" \
|
||||||
|
"1"
|
||||||
summary_detail="$(IFS='; '; printf '%s' "${summary_parts[*]}")"
|
echo "NC Connector: Legacy-Fallback erfolgreich."
|
||||||
[[ -n "$summary_detail" ]] || summary_detail="Keine Connector-Route wurde ausgefuehrt."
|
|
||||||
|
|
||||||
if [[ "$unpaired_webdav_failure" -eq 0 && "$legacy_failure_count" -eq 0 ]]; then
|
|
||||||
if [[ "$fallback_used" -eq 1 ]]; then
|
|
||||||
route="mixed_fallback"
|
|
||||||
label="MIGRATION - FALLBACK AKTIV"
|
|
||||||
elif [[ "$webdav_success_count" -gt 0 && "$legacy_run_count" -gt 0 ]]; then
|
|
||||||
route="mixed"
|
|
||||||
label="WebDAV + Legacy"
|
|
||||||
elif [[ "$webdav_success_count" -gt 0 ]]; then
|
|
||||||
route="webdav"
|
|
||||||
label="WebDAV"
|
|
||||||
else
|
|
||||||
route="legacy"
|
|
||||||
label="Legacy"
|
|
||||||
fi
|
|
||||||
|
|
||||||
write_route_status "$route" "$label" "$summary_detail" "$fallback_used" "1"
|
|
||||||
echo "NC Connector: alle erforderlichen 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 \
|
write_route_status \
|
||||||
"failed" \
|
"failed" \
|
||||||
"FEHLER - mindestens eine Verbindung" \
|
"FEHLER - WebDAV und Fallback" \
|
||||||
"$summary_detail" \
|
"WebDAV-Fehler: $webdav_failure_detail Legacy-Fallback ist ebenfalls fehlgeschlagen." \
|
||||||
"$fallback_used" \
|
"1" \
|
||||||
"0"
|
"0"
|
||||||
|
|
||||||
echo "NC Connector: mindestens eine erforderliche Verbindung ist fehlgeschlagen." >&2
|
if [[ "$webdav_failed" -eq 1 ]]; then
|
||||||
|
echo "NC Connector: WebDAV und Legacy-Fallback sind fehlgeschlagen." >&2
|
||||||
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user