&1', $lines, $code); $output = implode("\n", $lines); return $code; }; $healthOutput = ''; if ($runScript($healthScript, $healthOutput) === 0) { return; } $repairOutput = ''; $repairCode = $runScript($repairScript, $repairOutput); if ($repairCode !== 0) { throw new RuntimeException( "Nie udało się naprawić konfiguracji phpMyAdmin.\n" . trim($repairOutput) ); } $healthAfterRepair = ''; if ($runScript($healthScript, $healthAfterRepair) !== 0) { throw new RuntimeException( "Konfiguracja phpMyAdmin nadal nie przechodzi health-check po repair.\n" . trim($healthAfterRepair) ); } }; if (!Http::isPost()) { $message = 'Nieprawidłowa metoda żądania.'; if ($rawMode) { echo "HTTP/1.1 405 Method Not Allowed\r\n"; echo "Content-Type: text/plain; charset=UTF-8\r\n\r\n"; echo $message; } else { http_response_code(405); header('Content-Type: text/plain; charset=UTF-8'); echo $message; } exit; } try { $ensurePhpMyAdminReady(); } catch (Throwable $e) { $message = 'Nie można przygotować phpMyAdmin: ' . $e->getMessage(); @error_log( sprintf( "[%s] PHPMYADMIN_PROVISION_FAIL user=%s remote=%s message=%s\n", date('c'), $ctx->daUser->username(), Http::server('REMOTE_ADDR'), $e->getMessage() ), 3, PLUGIN_ROOT . '/error.log' ); if ($rawMode) { echo "HTTP/1.1 500 Internal Server Error\r\n"; echo "Content-Type: text/plain; charset=UTF-8\r\n\r\n"; echo $message; } else { http_response_code(500); header('Content-Type: text/plain; charset=UTF-8'); echo $message; } exit; } if (!$ctx->settings->enableAdminer()) { $message = 'Integracja phpMyAdmin jest wyłączona na tym serwerze.'; if ($rawMode) { echo "HTTP/1.1 403 Forbidden\r\n"; echo "Content-Type: text/plain; charset=UTF-8\r\n\r\n"; echo $message; } else { http_response_code(403); header('Content-Type: text/plain; charset=UTF-8'); echo $message; } exit; } try { $ctx->requireCsrf('open_phpmyadmin_submit'); $requestedDb = trim($ctx->postString('adminer_db')); if ($requestedDb === '') { $requestedDb = null; } $sso = new PhpMyAdminSso($ctx->settings, $ctx->daUser, $ctx->mysql); $payload = $sso->issueLoginPayload($requestedDb); $target = (string)($payload['target'] ?? ''); if ($target === '') { throw new RuntimeException('Nie udało się przygotować danych sesji do phpMyAdmin.'); } if ($rawMode) { echo "HTTP/1.1 302 Found\r\n"; echo "Location: " . $target . "\r\n"; echo "Cache-Control: no-store, no-cache, must-revalidate\r\n"; echo "Pragma: no-cache\r\n\r\n"; } else { header('Location: ' . $target, true, 302); } exit; } catch (Throwable $e) { $message = 'Nie można otworzyć phpMyAdmin: ' . $e->getMessage(); @error_log( sprintf( "[%s] PHPMYADMIN_SSO_FAIL user=%s remote=%s message=%s\n", date('c'), $ctx->daUser->username(), Http::server('REMOTE_ADDR'), $e->getMessage() ), 3, PLUGIN_ROOT . '/error.log' ); if ($rawMode) { echo "HTTP/1.1 400 Bad Request\r\n"; echo "Content-Type: text/plain; charset=UTF-8\r\n\r\n"; echo $message; } else { http_response_code(400); header('Content-Type: text/plain; charset=UTF-8'); echo $message; } exit; } };