mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 11:44:31 +00:00
0.9.6.9: Verbindung bearbeiten und Migration trennen
* 0.9.6.9 separate edit and migration flows * 0.9.6.9 register separate edit and migration actions * 0.9.6.9 add safe connection edit data endpoint * 0.9.6.9 make connection editing explicit and in-place * Bump version to 0.9.6.9 * 0.9.6.9 catch duplicate functions and admin JavaScript syntax
This commit is contained in:
18
.github/workflows/lint.yml
vendored
18
.github/workflows/lint.yml
vendored
@@ -25,6 +25,24 @@ jobs:
|
|||||||
php -l "$file"
|
php -l "$file"
|
||||||
done < <(find . -type f -name '*.php' -print0)
|
done < <(find . -type f -name '*.php' -print0)
|
||||||
|
|
||||||
|
- name: Doppelte Bratonien-Funktionen pruefen
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
duplicates="$(grep -RhoE 'function[[:space:]]+bratonien_tools_[A-Za-z0-9_]+' --include='*.php' . | awk '{print $2}' | sort | uniq -d || true)"
|
||||||
|
if [[ -n "$duplicates" ]]; then
|
||||||
|
echo "Doppelte globale Bratonien-Funktionen gefunden:" >&2
|
||||||
|
printf '%s\n' "$duplicates" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Admin JavaScript Syntax pruefen
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
sed -n '/<script>/,/<\/script>/p' template/admin_tabs.tpl | sed '1d;$d' > /tmp/bratonien-admin-tabs.js
|
||||||
|
node --check /tmp/bratonien-admin-tabs.js
|
||||||
|
|
||||||
- name: Python Syntax pruefen
|
- name: Python Syntax pruefen
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -4,22 +4,9 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
die('Hacking attempt!');
|
die('Hacking attempt!');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection(array $connection, $mode)
|
||||||
* Start the normal WebDAV wizard with the values of an existing connection.
|
|
||||||
*
|
|
||||||
* Remote/WebDAV connections are edited in place. A legacy/local connection is
|
|
||||||
* intentionally not mutated: the wizard prepares its WebDAV successor while
|
|
||||||
* the existing connection remains available as fallback.
|
|
||||||
*/
|
|
||||||
function bratonien_tools_nc_connector_edit_start()
|
|
||||||
{
|
{
|
||||||
$id = (int)($_POST['connection_id'] ?? 0);
|
$id = (int)$connection['id'];
|
||||||
$connection = bratonien_tools_nc_connector_connection($id, true);
|
|
||||||
if (!$connection)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||||
|
|
||||||
@@ -43,14 +30,11 @@ function bratonien_tools_nc_connector_edit_start()
|
|||||||
$selected_ids[$path] = $fileid;
|
$selected_ids[$path] = $fileid;
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_remote = (string)$connection['adapter'] === 'remote'
|
|
||||||
&& (string)($config['source_mode'] ?? '') === 'webdav-placeholder';
|
|
||||||
|
|
||||||
$state = bratonien_tools_nc_wizard_state();
|
$state = bratonien_tools_nc_wizard_state();
|
||||||
$state = array_merge($state, array(
|
$state = array_merge($state, array(
|
||||||
'editing_connection_id'=>$id,
|
'editing_connection_id'=>$id,
|
||||||
'editing_adapter'=>(string)$connection['adapter'],
|
'editing_adapter'=>(string)$connection['adapter'],
|
||||||
'editing_mode'=>$is_remote ? 'update' : 'migrate',
|
'editing_mode'=>(string)$mode,
|
||||||
'connection_name'=>(string)$connection['name'],
|
'connection_name'=>(string)$connection['name'],
|
||||||
'host_input'=>$base_url,
|
'host_input'=>$base_url,
|
||||||
'base_url'=>$base_url,
|
'base_url'=>$base_url,
|
||||||
@@ -100,10 +84,112 @@ function bratonien_tools_nc_connector_edit_start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bratonien_tools_nc_wizard_store($state);
|
bratonien_tools_nc_wizard_store($state);
|
||||||
|
}
|
||||||
return array(
|
|
||||||
'message'=>$is_remote
|
function bratonien_tools_nc_connector_edit_start()
|
||||||
? 'Verbindung #'.$id.' wurde zum Bearbeiten geöffnet.'
|
{
|
||||||
: 'Verbindung #'.$id.' wird im Assistenten auf WebDAV vorbereitet. Die bestehende Legacy-Verbindung bleibt dabei als Fallback erhalten.',
|
$id = (int)($_POST['connection_id'] ?? 0);
|
||||||
);
|
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||||
|
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||||
|
|
||||||
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
|
$is_webdav = (string)$connection['adapter'] === 'remote'
|
||||||
|
&& (string)($config['source_mode'] ?? '') === 'webdav-placeholder';
|
||||||
|
if (!$is_webdav)
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Diese Legacy-Verbindung wird direkt bearbeitet. Eine WebDAV-Migration ist eine separate Aktion.');
|
||||||
|
}
|
||||||
|
|
||||||
|
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'update');
|
||||||
|
return array('message'=>'Verbindung #'.$id.' wurde zum Bearbeiten geöffnet.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bratonien_tools_nc_connector_migrate_start()
|
||||||
|
{
|
||||||
|
$id = (int)($_POST['connection_id'] ?? 0);
|
||||||
|
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||||
|
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||||
|
if ((string)$connection['adapter'] !== 'local')
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Nur eine Legacy-Verbindung kann auf WebDAV migriert werden.');
|
||||||
|
}
|
||||||
|
|
||||||
|
bratonien_tools_nc_connector_prepare_webdav_wizard_from_connection($connection, 'migrate');
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
$id = (int)($_POST['connection_id'] ?? 0);
|
||||||
|
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||||
|
if (!$connection) throw new RuntimeException('Connector-Verbindung wurde nicht gefunden.');
|
||||||
|
if ((string)$connection['adapter'] !== 'local') throw new RuntimeException('Diese Bearbeitung ist nur für Legacy-Verbindungen vorgesehen.');
|
||||||
|
|
||||||
|
$name = trim((string)($_POST['connection_name'] ?? ''));
|
||||||
|
if ($name === '') throw new RuntimeException('Bitte einen Namen für die Verbindung angeben.');
|
||||||
|
|
||||||
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
|
$host = trim((string)($_POST['nc_host'] ?? ''));
|
||||||
|
$port = (int)($_POST['nc_port'] ?? 5432);
|
||||||
|
$database = trim((string)($_POST['nc_database'] ?? ''));
|
||||||
|
$user = trim((string)($_POST['nc_user'] ?? ''));
|
||||||
|
$gallery_root = rtrim(trim((string)($_POST['nc_gallery_root'] ?? '')), '/');
|
||||||
|
$source_view = trim((string)($_POST['nc_source_view'] ?? ''));
|
||||||
|
$activity_view = trim((string)($_POST['nc_activity_view'] ?? ''));
|
||||||
|
|
||||||
|
if ($host === '') throw new RuntimeException('Datenbank-Server fehlt.');
|
||||||
|
if ($port < 1 || $port > 65535) throw new RuntimeException('Der Datenbank-Port ist ungültig.');
|
||||||
|
if ($database === '') throw new RuntimeException('Datenbankname fehlt.');
|
||||||
|
if ($user === '') throw new RuntimeException('Reader-Benutzer fehlt.');
|
||||||
|
if ($gallery_root === '' || $gallery_root[0] !== '/') throw new RuntimeException('Der Piwigo-Galerieordner muss ein absoluter Pfad sein.');
|
||||||
|
if ($source_view === '' || $activity_view === '') throw new RuntimeException('Die gespeicherten Datenbankansichten dürfen nicht leer sein.');
|
||||||
|
bratonien_tools_nc_connector_view_name($source_view);
|
||||||
|
bratonien_tools_nc_connector_view_name($activity_view);
|
||||||
|
|
||||||
|
$storage_ids = isset($_POST['nc_storage_id']) && is_array($_POST['nc_storage_id']) ? $_POST['nc_storage_id'] : array();
|
||||||
|
$storage_prefixes = isset($_POST['nc_source_prefix']) && is_array($_POST['nc_source_prefix']) ? $_POST['nc_source_prefix'] : array();
|
||||||
|
$storage_mounts = isset($_POST['nc_local_mount']) && is_array($_POST['nc_local_mount']) ? $_POST['nc_local_mount'] : array();
|
||||||
|
$storages = array();
|
||||||
|
$count = max(count($storage_ids), count($storage_prefixes), count($storage_mounts));
|
||||||
|
for ($index = 0; $index < $count; $index++)
|
||||||
|
{
|
||||||
|
$storage_id = trim((string)($storage_ids[$index] ?? ''));
|
||||||
|
$prefix = trim((string)($storage_prefixes[$index] ?? ''), '/');
|
||||||
|
$mount = rtrim(trim((string)($storage_mounts[$index] ?? '')), '/');
|
||||||
|
if ($storage_id === '' && $prefix === '' && $mount === '') continue;
|
||||||
|
if ($storage_id === '') throw new RuntimeException('Bei einem Speicherort fehlt die Storage-ID.');
|
||||||
|
if ($mount === '' || $mount[0] !== '/') throw new RuntimeException('Bei einem Speicherort fehlt ein gültiger lokaler Pfad.');
|
||||||
|
$storages[] = array('storage_id'=>$storage_id, 'source_prefix'=>$prefix, 'local_mount'=>$mount);
|
||||||
|
}
|
||||||
|
if (!$storages) throw new RuntimeException('Mindestens ein Speicherort muss vorhanden sein.');
|
||||||
|
|
||||||
|
$config['host'] = $host;
|
||||||
|
$config['port'] = (string)$port;
|
||||||
|
$config['database'] = $database;
|
||||||
|
$config['user'] = $user;
|
||||||
|
$config['source_view'] = $source_view;
|
||||||
|
$config['activity_view'] = $activity_view;
|
||||||
|
$config['gallery_root'] = $gallery_root;
|
||||||
|
$config['quiet_seconds'] = max(0, (int)($_POST['nc_quiet_seconds'] ?? ($config['quiet_seconds'] ?? 120)));
|
||||||
|
$config['max_wait_seconds'] = max(60, (int)($_POST['nc_max_wait_seconds'] ?? ($config['max_wait_seconds'] ?? 900)));
|
||||||
|
$config['full_sync_seconds'] = max(300, (int)($_POST['nc_full_sync_seconds'] ?? ($config['full_sync_seconds'] ?? 86400)));
|
||||||
|
$config['storages'] = $storages;
|
||||||
|
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);
|
||||||
|
if (!is_string($config_json)) throw new RuntimeException('Connector-Konfiguration konnte nicht serialisiert werden.');
|
||||||
|
$secret_payload = json_encode($credentials, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
if (!is_string($secret_payload)) throw new RuntimeException('Connector-Zugangsdaten konnten nicht serialisiert werden.');
|
||||||
|
$secret_blob = bratonien_tools_nc_connector_encrypt_secret($secret_payload);
|
||||||
|
|
||||||
|
$table = bratonien_tools_nc_connector_table();
|
||||||
|
$now = date('Y-m-d H:i:s');
|
||||||
|
pwg_query("UPDATE `$table` SET name='".pwg_db_real_escape_string($name)."', config_json='".pwg_db_real_escape_string($config_json)."', secret_blob='".pwg_db_real_escape_string($secret_blob)."', updated='".pwg_db_real_escape_string($now)."' WHERE id=".$id." LIMIT 1");
|
||||||
|
|
||||||
|
return array('message'=>'Verbindung #'.$id.' wurde gespeichert. Die neuen Werte gelten ab dem nächsten Connector-Lauf.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ function bratonien_tools_get_tools()
|
|||||||
'nc_connector_create_local' => array('handler' => 'bratonien_tools_nc_connector_create_local_api_first'),
|
'nc_connector_create_local' => array('handler' => 'bratonien_tools_nc_connector_create_local_api_first'),
|
||||||
'nc_connector_create_webdav_parallel' => array('handler' => 'bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard'),
|
'nc_connector_create_webdav_parallel' => array('handler' => 'bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard'),
|
||||||
'nc_connector_edit_start' => array('handler' => 'bratonien_tools_nc_connector_edit_start'),
|
'nc_connector_edit_start' => array('handler' => 'bratonien_tools_nc_connector_edit_start'),
|
||||||
|
'nc_connector_migrate_start' => array('handler' => 'bratonien_tools_nc_connector_migrate_start'),
|
||||||
|
'nc_connector_update_local' => array('handler' => 'bratonien_tools_nc_connector_update_local_friendly'),
|
||||||
'nc_connector_delete' => array('handler' => 'bratonien_tools_nc_connector_delete_safe'),
|
'nc_connector_delete' => array('handler' => 'bratonien_tools_nc_connector_delete_safe'),
|
||||||
'nc_connector_update_name' => array('handler' => 'bratonien_tools_nc_connector_update_name'),
|
'nc_connector_update_name' => array('handler' => 'bratonien_tools_nc_connector_update_name'),
|
||||||
'nc_connector_update_technical' => array('handler' => 'bratonien_tools_nc_connector_update_technical'),
|
'nc_connector_update_technical' => array('handler' => 'bratonien_tools_nc_connector_update_technical'),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.6.8
|
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
|
||||||
|
|||||||
84
nc-connector-edit-data.php
Normal file
84
nc-connector-edit-data.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?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');
|
||||||
|
|
||||||
|
if (!defined('BRATONIEN_TOOLS_PATH'))
|
||||||
|
{
|
||||||
|
http_response_code(404);
|
||||||
|
echo json_encode(array('error'=>'Bratonien Tools ist nicht aktiv.'));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (!function_exists('is_admin') || !is_admin())
|
||||||
|
{
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(array('error'=>'Administratorrechte erforderlich.'));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_connection_scope.inc.php');
|
||||||
|
|
||||||
|
$id = (int)($_GET['connection_id'] ?? 0);
|
||||||
|
$connection = bratonien_tools_nc_connector_connection($id, true);
|
||||||
|
if (!$connection)
|
||||||
|
{
|
||||||
|
http_response_code(404);
|
||||||
|
echo json_encode(array('error'=>'Connector-Verbindung wurde nicht gefunden.'));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array();
|
||||||
|
$credentials = array();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$credentials = bratonien_tools_nc_connector_scoped_secret($connection);
|
||||||
|
}
|
||||||
|
catch (Throwable $e)
|
||||||
|
{
|
||||||
|
$credentials = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$storages = array();
|
||||||
|
foreach ((array)($config['storages'] ?? array()) as $storage)
|
||||||
|
{
|
||||||
|
$storages[] = array(
|
||||||
|
'storage_id'=>(string)($storage['storage_id'] ?? ''),
|
||||||
|
'source_prefix'=>(string)($storage['source_prefix'] ?? ''),
|
||||||
|
'local_mount'=>(string)($storage['local_mount'] ?? ''),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = array(
|
||||||
|
'id'=>(int)$connection['id'],
|
||||||
|
'name'=>(string)$connection['name'],
|
||||||
|
'adapter'=>(string)$connection['adapter'],
|
||||||
|
'enabled'=>(bool)$connection['enabled'],
|
||||||
|
'takeover_state'=>(string)$connection['takeover_state'],
|
||||||
|
'source_mode'=>(string)($config['source_mode'] ?? ''),
|
||||||
|
'legacy'=>array(
|
||||||
|
'host'=>(string)($config['host'] ?? ''),
|
||||||
|
'port'=>(string)($config['port'] ?? '5432'),
|
||||||
|
'database'=>(string)($config['database'] ?? ''),
|
||||||
|
'user'=>(string)($config['user'] ?? ''),
|
||||||
|
'has_db_password'=>trim((string)($credentials['db_password'] ?? '')) !== '',
|
||||||
|
'source_view'=>(string)($config['source_view'] ?? ''),
|
||||||
|
'activity_view'=>(string)($config['activity_view'] ?? ''),
|
||||||
|
'gallery_root'=>(string)($config['gallery_root'] ?? ''),
|
||||||
|
'quiet_seconds'=>(int)($config['quiet_seconds'] ?? 120),
|
||||||
|
'max_wait_seconds'=>(int)($config['max_wait_seconds'] ?? 900),
|
||||||
|
'full_sync_seconds'=>(int)($config['full_sync_seconds'] ?? 86400),
|
||||||
|
'storages'=>$storages,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
@@ -9,7 +9,13 @@
|
|||||||
.bratonien-tab-panel { width:100%; max-width:none; margin-left:0 !important; margin-right:0 !important; }
|
.bratonien-tab-panel { width:100%; max-width:none; margin-left:0 !important; margin-right:0 !important; }
|
||||||
.bratonien-tab-panel[hidden] { display:none !important; }
|
.bratonien-tab-panel[hidden] { display:none !important; }
|
||||||
.bratonien-card { margin-left:0; margin-right:0; }
|
.bratonien-card { margin-left:0; margin-right:0; }
|
||||||
@media (max-width:760px) { .bratonien-tabs{gap:5px}.bratonien-tab{border-bottom:1px solid rgba(255,255,255,.16);border-radius:4px;margin-bottom:0;padding:9px 11px} }
|
.bratonien-edit-dialog { width:min(920px,calc(100vw - 3rem)); max-height:88vh; overflow:auto; background:#444; color:inherit; border:1px solid #777; border-radius:4px; padding:0; box-shadow:0 18px 60px rgba(0,0,0,.55); }
|
||||||
|
.bratonien-edit-dialog::backdrop { background:rgba(0,0,0,.55); }
|
||||||
|
.bratonien-edit-dialog__body { padding:1.25rem 1.5rem; }
|
||||||
|
.bratonien-storage-row { display:grid; grid-template-columns:minmax(120px,.7fr) minmax(150px,1fr) minmax(240px,1.5fr) auto; gap:.5rem; align-items:end; margin:.5rem 0; }
|
||||||
|
.bratonien-storage-row label { display:flex; flex-direction:column; gap:.25rem; }
|
||||||
|
.bratonien-storage-row input { width:100%; box-sizing:border-box; }
|
||||||
|
@media (max-width:760px) { .bratonien-tabs{gap:5px}.bratonien-tab{border-bottom:1px solid rgba(255,255,255,.16);border-radius:4px;margin-bottom:0;padding:9px 11px}.bratonien-storage-row{grid-template-columns:1fr} }
|
||||||
</style>
|
</style>
|
||||||
<div id="bratonien-tabs-anchor"></div>
|
<div id="bratonien-tabs-anchor"></div>
|
||||||
<script>
|
<script>
|
||||||
@@ -48,12 +54,31 @@
|
|||||||
var openButton=document.getElementById('bratonien-nc-wizard-open');
|
var openButton=document.getElementById('bratonien-nc-wizard-open');
|
||||||
var closeButton=document.getElementById('bratonien-nc-wizard-close');
|
var closeButton=document.getElementById('bratonien-nc-wizard-close');
|
||||||
var storageKey='bratonienNcWizardOpen';
|
var storageKey='bratonienNcWizardOpen';
|
||||||
|
var modeKey='bratonienNcWizardMode';
|
||||||
var resetBusy=false;
|
var resetBusy=false;
|
||||||
|
|
||||||
function token(){var input=section.querySelector('input[name="pwg_token"]');return input?input.value:'';}
|
function token(){var input=section.querySelector('input[name="pwg_token"]');return input?input.value:'';}
|
||||||
function setOpen(value){try{if(value)sessionStorage.setItem(storageKey,'1');else sessionStorage.removeItem(storageKey);}catch(e){}}
|
function setOpen(value){try{if(value)sessionStorage.setItem(storageKey,'1');else sessionStorage.removeItem(storageKey);}catch(e){}}
|
||||||
|
function mode(){try{return sessionStorage.getItem(modeKey)||'';}catch(e){return '';}}
|
||||||
|
function clearMode(){try{sessionStorage.removeItem(modeKey);}catch(e){}}
|
||||||
|
function applyMode(){
|
||||||
|
if(!dialog)return;
|
||||||
|
var current=mode();
|
||||||
|
var heading=dialog.querySelector('h4');
|
||||||
|
var finish=dialog.querySelector('button[value="nc_connector_wizard_finish"]');
|
||||||
|
if(current==='edit'){
|
||||||
|
if(heading)heading.textContent='Verbindung bearbeiten';
|
||||||
|
if(finish)finish.textContent='Änderungen speichern';
|
||||||
|
}else if(current==='migrate'){
|
||||||
|
if(heading)heading.textContent='Auf WebDAV migrieren';
|
||||||
|
if(finish)finish.textContent='Migration starten';
|
||||||
|
}else{
|
||||||
|
if(heading)heading.textContent='Neue Verbindung';
|
||||||
|
if(finish)finish.textContent='Verbindung anlegen';
|
||||||
|
}
|
||||||
|
}
|
||||||
function showWizard(){
|
function showWizard(){
|
||||||
setOpen(true);
|
setOpen(true);applyMode();
|
||||||
if(!dialog)return;
|
if(!dialog)return;
|
||||||
if(typeof dialog.showModal==='function'&&!dialog.open)dialog.showModal();
|
if(typeof dialog.showModal==='function'&&!dialog.open)dialog.showModal();
|
||||||
else dialog.setAttribute('open','open');
|
else dialog.setAttribute('open','open');
|
||||||
@@ -65,29 +90,13 @@
|
|||||||
return fetch(window.location.href,{method:'POST',credentials:'same-origin',cache:'no-store',headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},body:body.toString()});
|
return fetch(window.location.href,{method:'POST',credentials:'same-origin',cache:'no-store',headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},body:body.toString()});
|
||||||
}
|
}
|
||||||
function closeAfterReset(){
|
function closeAfterReset(){
|
||||||
if(resetBusy)return;resetBusy=true;setOpen(false);
|
if(resetBusy)return;resetBusy=true;setOpen(false);clearMode();
|
||||||
resetServer().catch(function(){}).finally(function(){resetBusy=false;if(dialog){if(typeof dialog.close==='function'&&dialog.open)dialog.close();else dialog.removeAttribute('open');}});
|
resetServer().catch(function(){}).finally(function(){resetBusy=false;if(dialog){if(typeof dialog.close==='function'&&dialog.open)dialog.close();else dialog.removeAttribute('open');}});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every stored connection gets the same user-facing edit action. The edit
|
|
||||||
// action opens the normal WebDAV wizard; users never have to edit raw JSON,
|
|
||||||
// runtime paths or database rows.
|
|
||||||
[].slice.call(section.querySelectorAll('form')).forEach(function(deleteForm){
|
|
||||||
var tool=deleteForm.querySelector('button[name="bratonien_tool"][value="nc_connector_delete"]');
|
|
||||||
var idInput=deleteForm.querySelector('input[name="connection_id"]');
|
|
||||||
if(!tool||!idInput)return;
|
|
||||||
var actionRow=deleteForm.parentElement;if(!actionRow||actionRow.querySelector('[data-nc-edit-connection="'+idInput.value+'"]'))return;
|
|
||||||
var editForm=document.createElement('form');editForm.method='post';editForm.setAttribute('data-nc-edit-connection',idInput.value);
|
|
||||||
var tokenInput=document.createElement('input');tokenInput.type='hidden';tokenInput.name='pwg_token';tokenInput.value=token();editForm.appendChild(tokenInput);
|
|
||||||
var connectionInput=document.createElement('input');connectionInput.type='hidden';connectionInput.name='connection_id';connectionInput.value=idInput.value;editForm.appendChild(connectionInput);
|
|
||||||
var editButton=document.createElement('button');editButton.className='buttonLike';editButton.type='submit';editButton.name='bratonien_tool';editButton.value='nc_connector_edit_start';editButton.textContent='Bearbeiten';editForm.appendChild(editButton);
|
|
||||||
editForm.addEventListener('submit',function(){setOpen(true);},true);
|
|
||||||
actionRow.insertBefore(editForm,deleteForm);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(openButton){
|
if(openButton){
|
||||||
openButton.addEventListener('click',function(event){
|
openButton.addEventListener('click',function(event){
|
||||||
event.preventDefault();event.stopImmediatePropagation();showWizard();
|
event.preventDefault();event.stopImmediatePropagation();clearMode();showWizard();
|
||||||
},true);
|
},true);
|
||||||
}
|
}
|
||||||
if(closeButton){
|
if(closeButton){
|
||||||
@@ -97,12 +106,110 @@
|
|||||||
dialog.addEventListener('cancel',function(event){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();},true);
|
dialog.addEventListener('cancel',function(event){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();},true);
|
||||||
dialog.addEventListener('click',function(event){if(event.target===dialog){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();}},true);
|
dialog.addEventListener('click',function(event){if(event.target===dialog){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();}},true);
|
||||||
[].slice.call(dialog.querySelectorAll('form[data-bratonien-wizard-form]')).forEach(function(form){
|
[].slice.call(dialog.querySelectorAll('form[data-bratonien-wizard-form]')).forEach(function(form){
|
||||||
form.addEventListener('submit',function(){setOpen(true);},true);
|
form.addEventListener('submit',function(event){
|
||||||
|
var submitter=event.submitter;
|
||||||
|
setOpen(true);
|
||||||
|
if(submitter&&submitter.hasAttribute('data-bratonien-wizard-end')){
|
||||||
|
setOpen(false);
|
||||||
|
if(submitter.value==='nc_connector_wizard_reset')clearMode();
|
||||||
|
}
|
||||||
|
},true);
|
||||||
});
|
});
|
||||||
try{if(sessionStorage.getItem(storageKey)==='1')showWizard();}catch(e){}
|
try{if(sessionStorage.getItem(storageKey)==='1')showWizard();}catch(e){}
|
||||||
|
applyMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initNCConnectionEditing(){
|
||||||
|
var section=document.getElementById('nc-connector');if(!section)return;
|
||||||
|
var modeKey='bratonienNcWizardMode';
|
||||||
|
var pwgTokenInput=section.querySelector('input[name="pwg_token"]');
|
||||||
|
var pwgToken=pwgTokenInput?pwgTokenInput.value:'';
|
||||||
|
|
||||||
|
function setMode(value){try{sessionStorage.setItem(modeKey,value);}catch(e){}}
|
||||||
|
function makePostButton(label,tool,id,modeValue){
|
||||||
|
var form=document.createElement('form');form.method='post';form.style.display='inline';
|
||||||
|
var token=document.createElement('input');token.type='hidden';token.name='pwg_token';token.value=pwgToken;form.appendChild(token);
|
||||||
|
var connection=document.createElement('input');connection.type='hidden';connection.name='connection_id';connection.value=String(id);form.appendChild(connection);
|
||||||
|
var button=document.createElement('button');button.type='submit';button.className='buttonLike';button.name='bratonien_tool';button.value=tool;button.textContent=label;
|
||||||
|
if(modeValue)form.addEventListener('submit',function(){setMode(modeValue);});
|
||||||
|
form.appendChild(button);return form;
|
||||||
|
}
|
||||||
|
function escapeHtml(value){return String(value==null?'':value).replace(/[&<>"']/g,function(c){return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];});}
|
||||||
|
function localEditorDialog(){
|
||||||
|
var dialog=document.getElementById('bratonien-nc-local-edit-dialog');
|
||||||
|
if(dialog)return dialog;
|
||||||
|
dialog=document.createElement('dialog');dialog.id='bratonien-nc-local-edit-dialog';dialog.className='bratonien-edit-dialog';
|
||||||
|
dialog.innerHTML='<div class="bratonien-edit-dialog__body"><div style="display:flex;align-items:center;justify-content:space-between;gap:1rem"><div><h4 style="margin:0">Verbindung bearbeiten</h4><p class="bratonien-base-note" style="margin:.35rem 0 0">Bestehende Legacy-Verbindung. Änderungen werden in derselben Verbindung gespeichert.</p></div><button type="button" class="buttonLike" data-local-edit-close>Schließen</button></div><div data-local-edit-content style="margin-top:1rem"></div></div>';
|
||||||
|
document.body.appendChild(dialog);
|
||||||
|
dialog.querySelector('[data-local-edit-close]').addEventListener('click',function(){dialog.close();});
|
||||||
|
dialog.addEventListener('click',function(event){if(event.target===dialog)dialog.close();});
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
function storageRow(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 openLocalEditor(id){
|
||||||
|
var dialog=localEditorDialog();
|
||||||
|
var content=dialog.querySelector('[data-local-edit-content]');
|
||||||
|
content.innerHTML='<p class="bratonien-base-note">Verbindung wird geladen …</p>';
|
||||||
|
if(typeof dialog.showModal==='function')dialog.showModal();else dialog.setAttribute('open','open');
|
||||||
|
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;});})
|
||||||
|
.then(function(data){
|
||||||
|
if(data.adapter!=='local')throw new Error('Diese Verbindung ist keine Legacy-Verbindung.');
|
||||||
|
var legacy=data.legacy||{};var storages=Array.isArray(legacy.storages)?legacy.storages:[];
|
||||||
|
var rows=storages.map(storageRow).join('');
|
||||||
|
if(!rows)rows=storageRow({});
|
||||||
|
content.innerHTML='<form method="post" data-local-edit-form>'+
|
||||||
|
'<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'+
|
||||||
|
'<input type="hidden" name="connection_id" value="'+escapeHtml(data.id)+'">'+
|
||||||
|
'<div class="bratonien-form-grid">'+
|
||||||
|
'<label class="bratonien-label">Name</label><input name="connection_name" value="'+escapeHtml(data.name)+'" required>'+
|
||||||
|
'<label class="bratonien-label">Datenbank-Server</label><input name="nc_host" value="'+escapeHtml(legacy.host)+'" required>'+
|
||||||
|
'<label class="bratonien-label">Port</label><input name="nc_port" type="number" min="1" max="65535" value="'+escapeHtml(legacy.port||5432)+'" required>'+
|
||||||
|
'<label class="bratonien-label">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="leer = unverändert">'+
|
||||||
|
'</div>'+
|
||||||
|
'<h5 style="margin-top:1rem">Speicherorte</h5><p class="bratonien-base-note">Jeder Speicherort wird einzeln bearbeitet. Es ist kein Pipe-/Textformat erforderlich.</p><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" name="bratonien_tool" value="nc_connector_update_local">Änderungen speichern</button><button class="buttonLike" type="button" data-local-edit-cancel>Abbrechen</button></div></form>';
|
||||||
|
var form=content.querySelector('[data-local-edit-form]');
|
||||||
|
form.querySelector('[data-local-edit-cancel]').addEventListener('click',function(){dialog.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){var row=remove.closest('[data-storage-row]');if(row)row.remove();}});
|
||||||
|
})
|
||||||
|
.catch(function(error){content.innerHTML='<p class="bratonien-main-cache__warning"><strong>Bearbeiten nicht möglich:</strong> '+escapeHtml(error.message||String(error))+'</p>';});
|
||||||
|
}
|
||||||
|
|
||||||
|
[].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');var card=deleteButton.closest('details');if(!deleteForm||!card)return;
|
||||||
|
var idInput=deleteForm.querySelector('input[name="connection_id"]');if(!idInput)return;var id=idInput.value;
|
||||||
|
var actions=deleteForm.parentElement;if(!actions)return;
|
||||||
|
var text=card.textContent||'';var isLocal=text.indexOf('bestehende Legacy-Konfiguration')!==-1;
|
||||||
|
if(isLocal){
|
||||||
|
var edit=document.createElement('button');edit.type='button';edit.className='buttonLike';edit.textContent='Bearbeiten';edit.addEventListener('click',function(){openLocalEditor(id);});actions.insertBefore(edit,deleteForm);
|
||||||
|
actions.insertBefore(makePostButton('Auf WebDAV migrieren','nc_connector_migrate_start',id,'migrate'),deleteForm);
|
||||||
|
}else{
|
||||||
|
actions.insertBefore(makePostButton('Bearbeiten','nc_connector_edit_start',id,'edit'),deleteForm);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function initNCConnectorPolling(){
|
function initNCConnectorPolling(){
|
||||||
var section=document.getElementById('nc-connector');if(!section)return;
|
var section=document.getElementById('nc-connector');if(!section)return;
|
||||||
var endpoint='plugins/bratonien_tools/nc-connector-status.php';
|
var endpoint='plugins/bratonien_tools/nc-connector-status.php';
|
||||||
@@ -155,7 +262,7 @@
|
|||||||
poll();schedule();
|
poll();schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initAll(){initBratonienTabs();initNCWizardLifecycle();initNCConnectorPolling();}
|
function initAll(){initBratonienTabs();initNCWizardLifecycle();initNCConnectionEditing();initNCConnectorPolling();}
|
||||||
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',initAll);else initAll();
|
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',initAll);else initAll();
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user