mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-11-05 18:52:16 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9ab539be7 |
No files matched your search
@@ -104,6 +104,7 @@ 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();
|
||||||
|
$selected = array_values(array_filter($selected, function($path) { return $path !== ''; }));
|
||||||
if (!$selected) throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis auswählen.');
|
if (!$selected) throw new RuntimeException('Bitte mindestens ein Nextcloud-Verzeichnis auswählen.');
|
||||||
|
|
||||||
$roots = array();
|
$roots = array();
|
||||||
@@ -111,12 +112,9 @@ function bratonien_tools_nc_connector_create_webdav_placeholder_from_wizard()
|
|||||||
{
|
{
|
||||||
$fileid = isset($selected_ids[$path]) ? (int)$selected_ids[$path] : 0;
|
$fileid = isset($selected_ids[$path]) ? (int)$selected_ids[$path] : 0;
|
||||||
if ($fileid < 1) throw new RuntimeException('Für ein ausgewähltes Nextcloud-Verzeichnis fehlt die eindeutige Datei-ID.');
|
if ($fileid < 1) throw new RuntimeException('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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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'] = 'ok';
|
|
||||||
$state['api_error'] = '';
|
|
||||||
$state['step'] = 4;
|
|
||||||
bratonien_tools_nc_wizard_store($state);
|
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.');
|
return array('message'=>'WebDAV-Verzeichnisse wurden übernommen. Die Verbindung ist für den parallelen Testweg vorbereitet.');
|
||||||
}
|
|
||||||
|
|
||||||
bratonien_tools_nc_wizard_store($state);
|
|
||||||
return array('message'=>'WebDAV-Verzeichnisse wurden übernommen. Die Verbindung ist für den nächsten Einrichtungsschritt vorbereitet.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_nc_wizard_finish_dispatch()
|
function bratonien_tools_nc_wizard_finish_dispatch()
|
||||||
|
|||||||
@@ -6,18 +6,11 @@ if (!defined('PHPWG_ROOT_PATH'))
|
|||||||
|
|
||||||
if (isset($GLOBALS['template']) && is_object($GLOBALS['template']) && method_exists($GLOBALS['template'], 'func_combine_script'))
|
if (isset($GLOBALS['template']) && is_object($GLOBALS['template']) && method_exists($GLOBALS['template'], 'func_combine_script'))
|
||||||
{
|
{
|
||||||
$script_version = function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : '0.9.6.15';
|
|
||||||
$GLOBALS['template']->func_combine_script(array(
|
$GLOBALS['template']->func_combine_script(array(
|
||||||
'id'=>'bratonien_nc_connector_edit_v2',
|
'id'=>'bratonien_nc_connector_edit_v2',
|
||||||
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_edit_v2.js',
|
'path'=>BRATONIEN_TOOLS_PATH.'js/nc_connector_edit_v2.js',
|
||||||
'load'=>'footer',
|
'load'=>'footer',
|
||||||
'version'=>$script_version,
|
'version'=>function_exists('bratonien_tools_current_version') ? bratonien_tools_current_version() : '0.9.6.10',
|
||||||
));
|
|
||||||
$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,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-129
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
function escapeHtml(value) {
|
function escapeHtml(value) {
|
||||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
||||||
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,89 +78,6 @@
|
|||||||
+ '<button type="button" class="buttonLike" data-remove-storage>Entfernen</button></div>';
|
+ '<button type="button" class="buttonLike" data-remove-storage>Entfernen</button></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearValidation(form) {
|
|
||||||
[].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) {
|
function openEditor(id) {
|
||||||
var editDialog = dialog();
|
var editDialog = dialog();
|
||||||
var content = editDialog.querySelector('[data-edit-v2-content]');
|
var content = editDialog.querySelector('[data-edit-v2-content]');
|
||||||
@@ -215,7 +132,7 @@
|
|||||||
+ '<label class="bratonien-label">Maximale Wartezeit (Sek.)</label><input name="nc_max_wait_seconds" type="number" min="60" value="'+escapeHtml(legacy.max_wait_seconds)+'">'
|
+ '<label class="bratonien-label">Maximale Wartezeit (Sek.)</label><input name="nc_max_wait_seconds" type="number" min="60" value="'+escapeHtml(legacy.max_wait_seconds)+'">'
|
||||||
+ '<label class="bratonien-label">Vollprüfung nach (Sek.)</label><input name="nc_full_sync_seconds" type="number" min="300" value="'+escapeHtml(legacy.full_sync_seconds)+'">'
|
+ '<label class="bratonien-label">Vollprüfung nach (Sek.)</label><input name="nc_full_sync_seconds" type="number" min="300" value="'+escapeHtml(legacy.full_sync_seconds)+'">'
|
||||||
+ '</div></details>'
|
+ '</div></details>'
|
||||||
+ '<div class="bratonien-actions" style="margin-top:1rem"><button class="buttonLike" type="submit">Änderungen prüfen und speichern</button><button class="buttonLike" type="button" data-edit-v2-cancel>Abbrechen</button></div>'
|
+ '<div class="bratonien-actions" style="margin-top:1rem"><button class="buttonLike" type="submit" name="bratonien_tool" value="nc_connector_update_local">Änderungen prüfen und speichern</button><button class="buttonLike" type="button" data-edit-v2-cancel>Abbrechen</button></div>'
|
||||||
+ '</form>';
|
+ '</form>';
|
||||||
|
|
||||||
var form = content.querySelector('[data-edit-v2-form]');
|
var form = content.querySelector('[data-edit-v2-form]');
|
||||||
@@ -229,24 +146,18 @@
|
|||||||
var row = remove.closest('[data-storage-row]');
|
var row = remove.closest('[data-storage-row]');
|
||||||
if (row) row.remove();
|
if (row) row.remove();
|
||||||
});
|
});
|
||||||
form.addEventListener('submit', function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
submitEditor(form, editDialog);
|
|
||||||
});
|
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
content.innerHTML = '<p class="bratonien-main-cache__warning"><strong>Bearbeiten nicht möglich:</strong> '+escapeHtml(error.message || String(error))+'</p>';
|
content.innerHTML = '<p class="bratonien-main-cache__warning"><strong>Bearbeiten nicht möglich:</strong> '+escapeHtml(error.message || String(error))+'</p>';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildLocalActions(deleteForm, id, connectionData) {
|
function rebuildLocalActions(deleteForm, id) {
|
||||||
var actions = deleteForm.parentElement;
|
var actions = deleteForm.parentElement;
|
||||||
if (!actions) return;
|
if (!actions) return;
|
||||||
|
|
||||||
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
||||||
var migrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
var migrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
||||||
var editStart = form.querySelector('button[value="nc_connector_edit_start"]');
|
if (migrate) form.remove();
|
||||||
if (migrate || editStart) form.remove();
|
|
||||||
});
|
});
|
||||||
[].slice.call(actions.children).forEach(function (child) {
|
[].slice.call(actions.children).forEach(function (child) {
|
||||||
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
||||||
@@ -266,8 +177,7 @@
|
|||||||
info.textContent = 'WebDAV-Migration wird geprüft …';
|
info.textContent = 'WebDAV-Migration wird geprüft …';
|
||||||
actions.insertBefore(info, deleteForm);
|
actions.insertBefore(info, deleteForm);
|
||||||
|
|
||||||
var dataPromise = connectionData ? Promise.resolve(connectionData) : loadConnection(id);
|
loadConnection(id).then(function (data) {
|
||||||
dataPromise.then(function (data) {
|
|
||||||
var webdav = data.webdav || {};
|
var webdav = data.webdav || {};
|
||||||
if (webdav.migration_ready) {
|
if (webdav.migration_ready) {
|
||||||
info.remove();
|
info.remove();
|
||||||
@@ -281,44 +191,15 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
[].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) {
|
||||||
var deleteForm = deleteButton.closest('form');
|
var deleteForm = deleteButton.closest('form');
|
||||||
if (!deleteForm) return;
|
var card = deleteButton.closest('details');
|
||||||
|
if (!deleteForm || !card) return;
|
||||||
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
||||||
if (!idInput) return;
|
if (!idInput) return;
|
||||||
var id = idInput.value;
|
var text = card.textContent || '';
|
||||||
|
var isLocal = text.indexOf('bestehende Legacy-Konfiguration') !== -1;
|
||||||
loadConnection(id).then(function (data) {
|
if (isLocal) rebuildLocalActions(deleteForm, idInput.value);
|
||||||
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,217 +0,0 @@
|
|||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
function escapeHtml(value) {
|
|
||||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
|
||||||
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function fieldNodes(form, fieldName) {
|
|
||||||
return [].slice.call(form.querySelectorAll('[name="'+fieldName.replace(/"/g, '\\"')+'"]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearPickerErrors(form) {
|
|
||||||
[].slice.call(form.querySelectorAll('[data-source-picker-error]')).forEach(function (node) { node.remove(); });
|
|
||||||
[].slice.call(form.querySelectorAll('[data-source-picker-invalid="1"]')).forEach(function (field) {
|
|
||||||
field.removeAttribute('data-source-picker-invalid');
|
|
||||||
if (field.getAttribute('aria-invalid') === 'true') field.removeAttribute('aria-invalid');
|
|
||||||
field.style.borderColor = '';
|
|
||||||
field.style.boxShadow = '';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function showPickerError(form, data) {
|
|
||||||
clearPickerErrors(form);
|
|
||||||
var message = data && data.message ? data.message : 'Die Nextcloud-Ordnerauswahl konnte nicht gestartet werden.';
|
|
||||||
var fields = data && Array.isArray(data.fields) ? data.fields : [];
|
|
||||||
|
|
||||||
var summary = document.createElement('div');
|
|
||||||
summary.dataset.sourcePickerError = '1';
|
|
||||||
summary.className = 'bratonien-main-cache__warning';
|
|
||||||
summary.style.margin = '0 0 1rem';
|
|
||||||
summary.style.padding = '.75rem';
|
|
||||||
summary.style.border = '1px solid currentColor';
|
|
||||||
summary.innerHTML = '<strong>Ordnerauswahl nicht möglich:</strong> '+escapeHtml(message);
|
|
||||||
form.insertBefore(summary, form.firstChild);
|
|
||||||
|
|
||||||
var first = null;
|
|
||||||
fields.forEach(function (fieldName) {
|
|
||||||
fieldNodes(form, fieldName).forEach(function (field) {
|
|
||||||
field.dataset.sourcePickerInvalid = '1';
|
|
||||||
field.setAttribute('aria-invalid', 'true');
|
|
||||||
field.style.borderColor = '#d65a5a';
|
|
||||||
field.style.boxShadow = '0 0 0 1px #d65a5a';
|
|
||||||
if (!first) first = field;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (first) {
|
|
||||||
first.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
window.setTimeout(function () { first.focus(); }, 150);
|
|
||||||
} else {
|
|
||||||
summary.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function jsonResponse(response) {
|
|
||||||
return response.json().then(function (data) {
|
|
||||||
if (!response.ok || !data.ok) throw data;
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function startSourcePicker(form, button) {
|
|
||||||
clearPickerErrors(form);
|
|
||||||
if (!form.reportValidity()) return;
|
|
||||||
|
|
||||||
button.disabled = true;
|
|
||||||
var originalText = button.textContent;
|
|
||||||
button.textContent = 'Verbindung prüfen …';
|
|
||||||
|
|
||||||
var saveBody = new FormData(form);
|
|
||||||
fetch('plugins/bratonien_tools/nc-connector-edit-save.php', {
|
|
||||||
method:'POST',
|
|
||||||
credentials:'same-origin',
|
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'},
|
|
||||||
body:saveBody
|
|
||||||
})
|
|
||||||
.then(jsonResponse)
|
|
||||||
.then(function () {
|
|
||||||
button.textContent = 'Nextcloud-Ordner laden …';
|
|
||||||
var pickerBody = new FormData();
|
|
||||||
var token = form.querySelector('input[name="pwg_token"]');
|
|
||||||
var id = form.querySelector('input[name="connection_id"]');
|
|
||||||
pickerBody.append('pwg_token', token ? token.value : '');
|
|
||||||
pickerBody.append('connection_id', id ? id.value : '');
|
|
||||||
return fetch('plugins/bratonien_tools/nc-connector-source-picker-start.php', {
|
|
||||||
method:'POST',
|
|
||||||
credentials:'same-origin',
|
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'},
|
|
||||||
body:pickerBody
|
|
||||||
}).then(jsonResponse);
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
try {
|
|
||||||
sessionStorage.setItem('bratonienNcWizardMode', 'migrate');
|
|
||||||
sessionStorage.setItem('bratonienNcWizardOpen', '1');
|
|
||||||
} catch (e) {}
|
|
||||||
window.location.reload();
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
showPickerError(form, error && typeof error === 'object' ? error : {message:String(error), fields:[]});
|
|
||||||
button.disabled = false;
|
|
||||||
button.textContent = originalText;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function enhanceMigrationButtons(root) {
|
|
||||||
[].slice.call(root.querySelectorAll('button[value="nc_connector_migrate_start"]')).forEach(function (button) {
|
|
||||||
button.textContent = 'Nextcloud-Ordner auswählen & migrieren';
|
|
||||||
button.title = 'Die WebDAV-Quelle wird im Nextcloud-Ordnerbrowser ausgewählt. Der bestehende SMB-/Legacy-Speicher wird nicht als WebDAV-Quelle übernommen.';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function enhanceEditor(root) {
|
|
||||||
var form = root.querySelector('[data-edit-v2-form]');
|
|
||||||
if (!form || form.dataset.sourceUiEnhanced === '1') return;
|
|
||||||
form.dataset.sourceUiEnhanced = '1';
|
|
||||||
|
|
||||||
var headings = [].slice.call(form.querySelectorAll('h5'));
|
|
||||||
var webdavHeading = headings.find(function (node) {
|
|
||||||
return (node.textContent || '').trim() === 'Nextcloud / WebDAV';
|
|
||||||
});
|
|
||||||
var legacyHeading = headings.find(function (node) {
|
|
||||||
return (node.textContent || '').trim() === 'Bestehender Legacy-Weg';
|
|
||||||
});
|
|
||||||
var storageHeading = headings.find(function (node) {
|
|
||||||
return (node.textContent || '').trim() === 'Speicherorte';
|
|
||||||
});
|
|
||||||
var storageList = form.querySelector('[data-storage-list]');
|
|
||||||
var addStorage = form.querySelector('[data-add-storage]');
|
|
||||||
|
|
||||||
if (webdavHeading && !form.querySelector('[data-webdav-source-picker]')) {
|
|
||||||
var webdavGrid = webdavHeading.nextElementSibling;
|
|
||||||
while (webdavGrid && !webdavGrid.classList.contains('bratonien-form-grid')) webdavGrid = webdavGrid.nextElementSibling;
|
|
||||||
if (webdavGrid) {
|
|
||||||
var picker = document.createElement('div');
|
|
||||||
picker.dataset.webdavSourcePicker = '1';
|
|
||||||
picker.style.margin = '.8rem 0 1rem';
|
|
||||||
picker.innerHTML = '<p class="bratonien-base-note" style="margin:.25rem 0 .5rem"><strong>WebDAV-Quelle:</strong> Du musst keinen Pfad kennen. Die Ordner des oben eingetragenen Nextcloud-Benutzers werden automatisch geladen und können anschließend ausgewählt werden.</p>';
|
|
||||||
var button = document.createElement('button');
|
|
||||||
button.type = 'button';
|
|
||||||
button.className = 'buttonLike';
|
|
||||||
button.textContent = 'Nextcloud-Ordner automatisch auswählen';
|
|
||||||
button.addEventListener('click', function () { startSourcePicker(form, button); });
|
|
||||||
picker.appendChild(button);
|
|
||||||
webdavGrid.insertAdjacentElement('afterend', picker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (legacyHeading && !form.querySelector('[data-webdav-source-note]')) {
|
|
||||||
var note = document.createElement('p');
|
|
||||||
note.dataset.webdavSourceNote = '1';
|
|
||||||
note.className = 'bratonien-main-cache__warning';
|
|
||||||
note.innerHTML = '<strong>Wichtig:</strong> Der folgende SMB-/lokale Speicher gehört ausschließlich zum bisherigen Legacy-Fallback. Er wird <strong>nicht</strong> als WebDAV-Quelle übernommen.';
|
|
||||||
legacyHeading.insertAdjacentElement('beforebegin', note);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (storageHeading && storageList && addStorage) {
|
|
||||||
storageHeading.textContent = 'Legacy-Speicher (nur Fallback)';
|
|
||||||
|
|
||||||
var details = document.createElement('details');
|
|
||||||
details.dataset.legacyStorageTechnical = '1';
|
|
||||||
details.style.marginTop = '.75rem';
|
|
||||||
var summary = document.createElement('summary');
|
|
||||||
summary.textContent = 'Technische Legacy-Speicherzuordnung bearbeiten';
|
|
||||||
details.appendChild(summary);
|
|
||||||
|
|
||||||
var info = document.createElement('p');
|
|
||||||
info.className = 'bratonien-base-note';
|
|
||||||
info.textContent = 'Diese Felder betreffen nur den alten Fallback-Weg. Für WebDAV werden keine SMB-Adressen oder lokalen Mount-Pfade eingegeben.';
|
|
||||||
details.appendChild(info);
|
|
||||||
|
|
||||||
storageHeading.insertAdjacentElement('beforebegin', details);
|
|
||||||
details.appendChild(storageHeading);
|
|
||||||
details.appendChild(storageList);
|
|
||||||
details.appendChild(addStorage);
|
|
||||||
|
|
||||||
addStorage.textContent = 'Legacy-Speicher manuell hinzufügen';
|
|
||||||
addStorage.title = 'Nur für den alten Legacy-Fallback. WebDAV-Ordner werden im Nextcloud-Ordnerbrowser ausgewählt.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function enhance(root) {
|
|
||||||
if (!root || root.nodeType !== 1) return;
|
|
||||||
enhanceMigrationButtons(root);
|
|
||||||
if (root.matches && root.matches('#bratonien-nc-connection-edit-v2')) enhanceEditor(root);
|
|
||||||
var dialog = root.querySelector ? root.querySelector('#bratonien-nc-connection-edit-v2') : null;
|
|
||||||
if (dialog) enhanceEditor(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
function start() {
|
|
||||||
var section = document.getElementById('nc-connector');
|
|
||||||
if (!section) return;
|
|
||||||
|
|
||||||
enhance(section);
|
|
||||||
enhanceMigrationButtons(document);
|
|
||||||
|
|
||||||
var observer = new MutationObserver(function (mutations) {
|
|
||||||
mutations.forEach(function (mutation) {
|
|
||||||
[].slice.call(mutation.addedNodes || []).forEach(function (node) {
|
|
||||||
if (node && node.nodeType === 1) enhance(node);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
var dialog = document.getElementById('bratonien-nc-connection-edit-v2');
|
|
||||||
if (dialog) enhanceEditor(dialog);
|
|
||||||
enhanceMigrationButtons(document);
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.body, {childList:true, subtree:true});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start);
|
|
||||||
else start();
|
|
||||||
})();
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Bratonien Tools
|
Plugin Name: Bratonien Tools
|
||||||
Version: 0.9.6.18
|
Version: 0.9.6.10
|
||||||
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
Description: Erweiterbare Administrationswerkzeuge fuer die Bratonien-Piwigo-Installation.
|
||||||
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
Plugin URI: https://github.com/Terranom674/Piwigo_Bratonien_Tools
|
||||||
Author: Bratonien
|
Author: Bratonien
|
||||||
|
|||||||
@@ -1,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')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -165,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;
|
||||||
@@ -188,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);
|
||||||
|
|||||||
Reference in new issue
Block a user