Import postgresql plugin
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
return static function (AppContext $ctx): void {
|
||||
$rawMode = defined('DA_POSTGRESQL_RAW_MODE') && DA_POSTGRESQL_RAW_MODE === true;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!$ctx->settings->enableAdminer()) {
|
||||
$message = 'Integracja Adminera 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_adminer_submit');
|
||||
$requestedDb = trim($ctx->postString('adminer_db'));
|
||||
if ($requestedDb === '') {
|
||||
$requestedDb = null;
|
||||
}
|
||||
$sso = new AdminerSso($ctx->settings, $ctx->daUser, $ctx->pg);
|
||||
$target = $sso->issueLoginUrl($requestedDb);
|
||||
$safeTarget = htmlspecialchars($target, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
|
||||
if ($rawMode) {
|
||||
echo "HTTP/1.1 200 OK\r\n";
|
||||
echo "Content-Type: text/html; charset=UTF-8\r\n";
|
||||
echo "Cache-Control: no-store, no-cache, must-revalidate\r\n";
|
||||
echo "Pragma: no-cache\r\n\r\n";
|
||||
echo '<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="refresh" content="0;url=' . $safeTarget . '">';
|
||||
echo '<script>(function(){var u=' . json_encode($target, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ';try{if(window.top&&window.top!==window){window.top.location.replace(u);return;}}catch(e){}window.location.replace(u);}());</script>';
|
||||
echo '</head><body>Przekierowanie do Adminera... <a href="' . $safeTarget . '">Kliknij tutaj</a></body></html>';
|
||||
} else {
|
||||
header('Location: ' . $target, true, 302);
|
||||
}
|
||||
exit;
|
||||
} catch (Throwable $e) {
|
||||
$message = 'Nie można otworzyć Adminera: ' . $e->getMessage();
|
||||
@error_log(
|
||||
sprintf(
|
||||
"[%s] ADMINER_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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user