1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-11 17:14:07 +02:00

PostgreSQL: Allow to set connection's sslmode with AdminerLoginSsl plugin

Thanks to wodka (https://github.com/vrana/adminer/pull/427/files)
This commit is contained in:
Peter Knut
2024-09-17 17:56:12 +02:00
committed by Jakub Vrana
parent dfb33a323d
commit 1f97968e65
3 changed files with 17 additions and 7 deletions

View File

@@ -20,6 +20,10 @@ if (isset($_GET["pgsql"])) {
$db = $adminer->database(); $db = $adminer->database();
set_error_handler(array($this, '_error')); set_error_handler(array($this, '_error'));
$this->_string = "host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' user='" . addcslashes($username, "'\\") . "' password='" . addcslashes($password, "'\\") . "'"; $this->_string = "host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' user='" . addcslashes($username, "'\\") . "' password='" . addcslashes($password, "'\\") . "'";
$ssl = $adminer->connectSsl();
if (isset($ssl["mode"])) {
$this->_string .= " sslmode='" . $ssl["mode"] . "'";
}
$this->_link = @pg_connect("$this->_string dbname='" . ($db != "" ? addcslashes($db, "'\\") : "postgres") . "'", PGSQL_CONNECT_FORCE_NEW); $this->_link = @pg_connect("$this->_string dbname='" . ($db != "" ? addcslashes($db, "'\\") : "postgres") . "'", PGSQL_CONNECT_FORCE_NEW);
if (!$this->_link && $db != "") { if (!$this->_link && $db != "") {
// try to connect directly with database for performance // try to connect directly with database for performance
@@ -149,8 +153,13 @@ if (isset($_GET["pgsql"])) {
function connect($server, $username, $password) { function connect($server, $username, $password) {
global $adminer; global $adminer;
$db = $adminer->database(); $db = $adminer->database();
$this->dsn("pgsql:host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' client_encoding=utf8 dbname='" . ($db != "" ? addcslashes($db, "'\\") : "postgres") . "'", $username, $password); //! client_encoding is supported since 9.1 but we can't yet use min_version here //! client_encoding is supported since 9.1, but we can't yet use min_version here
//! connect without DB in case of an error $dsn = "pgsql:host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' client_encoding=utf8 dbname='" . ($db != "" ? addcslashes($db, "'\\") : "postgres") . "'";
$ssl = $adminer->connectSsl();
if (isset($ssl["mode"])) {
$dsn .= " sslmode='" . $ssl["mode"] . "'";
}
$this->dsn($dsn, $username, $password);
return true; return true;
} }

View File

@@ -1,6 +1,7 @@
Adminer 4.16.0-dev: Adminer 4.16.0-dev:
MySQL: Fix saving bit(64) values (bug #839) MySQL: Fix saving bit(64) values (bug #839)
PostgreSQL: Preserve whitespace in EXPLAIN (bug #827) PostgreSQL: Preserve whitespace in EXPLAIN (bug #827)
PostgreSQL: Support SSL
SQLite: Fix altering forign keys (bug #841) SQLite: Fix altering forign keys (bug #841)
MS SQL: Foreign keys in non-default schema (bug #833) MS SQL: Foreign keys in non-default schema (bug #833)
Oracle: Include tables granted by other user Oracle: Include tables granted by other user

View File

@@ -1,6 +1,6 @@
<?php <?php
/** Connect to MySQL using SSL /** Connect to MySQL or PostgreSQL using SSL
* @link https://www.adminer.org/plugins/#use * @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/ * @author Jakub Vrana, https://www.vrana.cz/
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
@@ -11,7 +11,7 @@ class AdminerLoginSsl {
var $ssl; var $ssl;
/** /**
* @param array array("key" => filename, "cert" => filename, "ca" => filename) * @param array MySQL: ["key" => filename, "cert" => filename, "ca" => filename], PostgresSQL: ["mode" => sslmode]
*/ */
function __construct($ssl) { function __construct($ssl) {
$this->ssl = $ssl; $this->ssl = $ssl;