From 38a8e76fee55e2f138cc30ca2f0ea71a5edafb44 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Tue, 18 Aug 2026 08:34:19 +0200 Subject: [PATCH] Fix Nextcloud OCS success handling in connection wizard --- include/nc_connector_wizard.inc.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/include/nc_connector_wizard.inc.php b/include/nc_connector_wizard.inc.php index f923759..8a851f7 100644 --- a/include/nc_connector_wizard.inc.php +++ b/include/nc_connector_wizard.inc.php @@ -152,14 +152,29 @@ function bratonien_tools_nc_wizard_http($url, $username = '', $password = '', ar function bratonien_tools_nc_wizard_ocs_data($body) { $decoded = json_decode((string)$body, true); - if (!is_array($decoded)) + if (!is_array($decoded) || !isset($decoded['ocs']) || !is_array($decoded['ocs'])) { - throw new RuntimeException('Nextcloud hat keine gültige JSON-Antwort geliefert.'); + throw new RuntimeException('Nextcloud hat keine gültige OCS-Antwort geliefert.'); } - if (isset($decoded['ocs']['meta']['statuscode']) && (int)$decoded['ocs']['meta']['statuscode'] !== 100) + $meta = isset($decoded['ocs']['meta']) && is_array($decoded['ocs']['meta']) + ? $decoded['ocs']['meta'] + : array(); + $status = strtolower(trim((string)($meta['status'] ?? ''))); + $status_code = isset($meta['statuscode']) ? (int)$meta['statuscode'] : 0; + + // OCS API v1 commonly reports 100 for success, OCS API v2 commonly 200. + // Some Nextcloud versions additionally expose meta.status="ok". Treat all + // documented success forms as success instead of turning message "OK" into + // an error. + $success = $status === 'ok' || in_array($status_code, array(100, 200), true); + if (!$success) { - $message = (string)($decoded['ocs']['meta']['message'] ?? 'Nextcloud hat die Anfrage abgelehnt.'); + $message = trim((string)($meta['message'] ?? '')); + if ($message === '' || strtolower($message) === 'ok') + { + $message = 'Nextcloud hat die Anfrage abgelehnt.'; + } throw new RuntimeException($message); }