fetchAll(); if (empty($all)) { echo "{$R}Keine Großhändler konfiguriert.{$X}\n"; exit(1); } echo "\n{$B}{$C}Verfügbare Großhändler:{$X}\n\n"; foreach ($all as $sup) { echo " ID {$B}{$sup->id}{$X}: {$sup->label} ({$sup->ref})"; echo " | URL: {$sup->ids_url}"; echo " | ".($sup->active ? "{$G}Aktiv{$X}" : "{$R}Inaktiv{$X}"); echo " | ".($sup->testmode ? "{$Y}Testmodus{$X}" : "{$R}Live{$X}"); echo "\n"; } echo "\nAufruf: php test_connection.php \n\n"; exit(0); } // Supplier laden $result = $supplierObj->fetch($supplier_id); if ($result <= 0) { echo "{$R}Großhändler mit ID {$supplier_id} nicht gefunden.{$X}\n"; exit(1); } echo "\n{$B}{$C}================================================================{$X}\n"; echo "{$B}{$C} IDS Connect Verbindungstest: {$supplierObj->label}{$X}\n"; echo "{$B}{$C}================================================================{$X}\n\n"; echo "{$B}Konfiguration:{$X}\n"; echo " Referenz: {$supplierObj->ref}\n"; echo " Shop-URL: {$supplierObj->ids_url}\n"; echo " IDS-Version: {$supplierObj->ids_version}\n"; echo " Kundennr: {$supplierObj->ids_customer_no}\n"; echo " Benutzer: {$supplierObj->ids_username}\n"; echo " Passwort: ".(empty($supplierObj->ids_password) ? "{$R}NICHT GESETZT{$X}" : str_repeat('*', min(strlen($supplierObj->ids_password), 8)))."\n"; echo " Testmodus: ".($supplierObj->testmode ? "{$Y}Ja{$X}" : "{$R}Nein{$X}")."\n"; echo "\n"; if (empty($supplierObj->ids_password)) { echo "{$R}ABBRUCH: Kein Passwort konfiguriert. Bitte erst in der Großhändler-Konfiguration eingeben.{$X}\n\n"; exit(1); } // Test-Actions $actions = array('SV', 'LI'); foreach ($actions as $action) { echo "{$B}--- Test: Action {$action} ---{$X}\n\n"; // POST-Daten zusammenbauen (wie buildLaunchForm) $post_data = array( 'kndnr' => $supplierObj->ids_customer_no, 'name_kunde' => $supplierObj->ids_username, 'pw_kunde' => $supplierObj->ids_password, 'version' => $supplierObj->ids_version, 'action' => $action, 'hookurl' => 'http://localhost/dolibarr/custom/idsconnect/callback.php?token=test', ); echo " {$C}POST-Parameter:{$X}\n"; foreach ($post_data as $k => $v) { if ($k === 'pw_kunde') { echo " {$k} = ********\n"; } else { echo " {$k} = {$v}\n"; } } echo "\n"; echo " {$C}Sende POST an: {$supplierObj->ids_url}{$X}\n\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $supplierObj->ids_url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'IDS Connect Test / Dolibarr'); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $totalTime = curl_getinfo($ch, CURLINFO_TOTAL_TIME); $effectiveUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $redirectUrl = curl_getinfo($ch, CURLINFO_REDIRECT_URL); $curlError = curl_error($ch); $curlErrno = curl_errno($ch); curl_close($ch); if ($curlErrno) { echo " {$R}CURL-FEHLER #{$curlErrno}: {$curlError}{$X}\n"; echo "\n"; continue; } $headers = substr($response, 0, $headerSize); $body = substr($response, $headerSize); // HTTP-Status $statusColor = ($httpCode >= 200 && $httpCode < 400) ? $G : $R; echo " HTTP-Status: {$statusColor}{$httpCode}{$X}\n"; echo " Antwortzeit: {$totalTime}s\n"; if (!empty($redirectUrl)) { echo " Redirect zu: {$Y}{$redirectUrl}{$X}\n"; } // Response-Header anzeigen echo "\n {$C}Response-Header:{$X}\n"; $headerLines = explode("\r\n", trim($headers)); foreach ($headerLines as $hl) { if (!empty(trim($hl))) { echo " {$hl}\n"; } } // Response-Body echo "\n {$C}Response-Body"; $bodyLen = strlen($body); echo " ({$bodyLen} Bytes):{$X}\n"; if ($bodyLen > 0) { // Prüfen ob es HTML oder XML ist $trimmed = trim($body); if (strpos($trimmed, 'preserveWhiteSpace = false; $dom->formatOutput = true; if (@$dom->loadXML($trimmed)) { $formatted = $dom->saveXML(); foreach (explode("\n", $formatted) as $line) { echo " {$line}\n"; } } else { echo " ".$trimmed."\n"; } } elseif (strpos($trimmed, '<') === 0) { echo " {$Y}[HTML-Antwort - gekürzt auf 2000 Zeichen]{$X}\n"; echo " ".substr($trimmed, 0, 2000)."\n"; if ($bodyLen > 2000) { echo " {$Y}... ({$bodyLen} Bytes gesamt){$X}\n"; } } else { echo " ".$trimmed."\n"; } } else { echo " {$Y}(Leere Antwort){$X}\n"; } echo "\n"; } echo "{$B}{$C}================================================================{$X}\n"; echo "{$B}Test abgeschlossen.{$X}\n\n"; $db->close();