]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Allow to set connection's sslmode with AdminerLoginSsl plugin
authorPeter Knut <peter@pematon.com>
Tue, 17 Sep 2024 15:56:12 +0000 (17:56 +0200)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Feb 2025 17:54:24 +0000 (18:54 +0100)
Thanks to wodka (https://github.com/vrana/adminer/pull/427/files)

adminer/drivers/pgsql.inc.php
changes.txt
plugins/login-ssl.php

index 3f4852a2479b1d76c6ced1f6af611984e75f5586..1f922216fba74e7fb22d6c4b5cda4267dc39d73a 100644 (file)
@@ -20,6 +20,10 @@ if (isset($_GET["pgsql"])) {
                                $db = $adminer->database();
                                set_error_handler(array($this, '_error'));
                                $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);
                                if (!$this->_link && $db != "") {
                                        // try to connect directly with database for performance
@@ -149,8 +153,13 @@ if (isset($_GET["pgsql"])) {
                        function connect($server, $username, $password) {
                                global $adminer;
                                $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
-                               //! connect without DB in case of an error
+                               //! client_encoding is supported since 9.1, but we can't yet use min_version here
+                               $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;
                        }
 
index 7e5f3af131e2b7651e3ba3c1642f58da49312479..072f05253d0950f6e877b7cf4349af3a8a946add 100644 (file)
@@ -1,6 +1,7 @@
 Adminer 4.16.0-dev:
 MySQL: Fix saving bit(64) values (bug #839)
 PostgreSQL: Preserve whitespace in EXPLAIN (bug #827)
+PostgreSQL: Support SSL
 SQLite: Fix altering forign keys (bug #841)
 MS SQL: Foreign keys in non-default schema (bug #833)
 Oracle: Include tables granted by other user
index 0114965fcb189553fd8b90b3d724802892525448..294b5dbf6596685293ec078873adfa3c6b18bdaf 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-/** Connect to MySQL using SSL
+/** Connect to MySQL or PostgreSQL using SSL
 * @link https://www.adminer.org/plugins/#use
 * @author Jakub Vrana, https://www.vrana.cz/
 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
@@ -9,14 +9,14 @@
 class AdminerLoginSsl {
        /** @access protected */
        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) {
                $this->ssl = $ssl;
        }
-       
+
        function connectSsl() {
                return $this->ssl;
        }