]> git.joonet.de Git - adminer.git/commitdiff
Pass credentials to connect()
authorJakub Vrana <jakub@vrana.cz>
Fri, 7 Mar 2025 11:03:29 +0000 (12:03 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 7 Mar 2025 11:03:29 +0000 (12:03 +0100)
15 files changed:
adminer/call.inc.php
adminer/drivers/mongo.inc.php
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/auth.inc.php
adminer/include/functions.inc.php
adminer/sql.inc.php
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/elastic5.php
plugins/drivers/firebird.php
plugins/drivers/simpledb.php

index 33f4cd787acb1d2510e3ad2eb5f149757713a818..1800ee1621a04eb4eecd676a970e1a940437f8ae 100644 (file)
@@ -40,7 +40,7 @@ if (!$error && $_POST) {
        if (!$result) {
                echo "<p class='error'>" . error() . "\n";
        } else {
-               $connection2 = connect();
+               $connection2 = connect($adminer->credentials());
                if (is_object($connection2)) {
                        $connection2->select_db(DB);
                }
index a64f214bcd9abb9e624958c95fc7ad4392fa4f64..ebacdc1f522c8b05edd1fd8bb24444ef0688c640 100644 (file)
@@ -421,10 +421,10 @@ if (isset($_GET["mongo"])) {
                return $credentials[1];
        }
 
-       function connect() {
+       function connect($credentials) {
                global $adminer;
                $connection = new Db;
-               list($server, $username, $password) = $adminer->credentials();
+               list($server, $username, $password) = $credentials;
 
                if ($server == "") {
                        $server = "localhost:27017";
index ea7067bdcedc28f9f3d6a28977f1729e57b4769c..6c97323aac829c1b89a873323aeff4e49e19d0a1 100644 (file)
@@ -280,15 +280,11 @@ if (isset($_GET["mssql"])) {
                return ($_GET["ns"] != "" ? idf_escape($_GET["ns"]) . "." : "") . idf_escape($idf);
        }
 
-       function connect() {
-               global $adminer;
+       function connect($credentials) {
                $connection = new Db;
-               $credentials = $adminer->credentials();
-
                if ($credentials[0] == "") {
                        $credentials[0] = "localhost:1433";
                }
-
                if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
                        return $connection;
                }
index 78df8232c62c8baca2e57238deddf4b8df0850f9..6878f101f659f3a4c9872331e3daf262e0e3d00c 100644 (file)
@@ -421,12 +421,11 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** Connect to the database
+       * @param array [$server, $username, $password]
        * @return mixed Db or string for error
        */
-       function connect() {
-               global $adminer;
+       function connect($credentials) {
                $connection = new Db;
-               $credentials = $adminer->credentials();
                if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
                        $connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5
                        $connection->query("SET sql_quote_show_create = 1, autocommit = 1");
index 009c8a992ed6a708c9a05de40f1bb77df9549e4c..86f52e513a09ba27534a5f6a8da3aa23e8ffd814 100644 (file)
@@ -211,10 +211,8 @@ if (isset($_GET["oracle"])) {
                return idf_escape($idf);
        }
 
-       function connect() {
-               global $adminer;
+       function connect($credentials) {
                $connection = new Db;
-               $credentials = $adminer->credentials();
                if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
                        return $connection;
                }
index cf9f63c61ed22124c2df2393a17c3e3e59c8037f..354b61927efad61853cae2fb03aac8b85dfba888 100644 (file)
@@ -312,10 +312,8 @@ if (isset($_GET["pgsql"])) {
                return idf_escape($idf);
        }
 
-       function connect() {
-               global $adminer;
+       function connect($credentials) {
                $connection = new Db;
-               $credentials = $adminer->credentials();
                if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
                        if (min_version(9, 0, $connection)) {
                                $connection->query("SET application_name = 'Adminer'");
index 8d0e10d65dbd02857c25cd2c795ca33f0a297ec3..ee75d48d769cc0223386b1bc6ad0eab79325ad78 100644 (file)
@@ -190,9 +190,8 @@ if (isset($_GET["sqlite"])) {
                return idf_escape($idf);
        }
 
-       function connect() {
-               global $adminer;
-               list(, , $password) = $adminer->credentials();
+       function connect($credentials) {
+               list(, , $password) = $credentials;
                if ($password != "") {
                        return lang('Database does not support password.');
                }
index 965b54f8adef8c40a90b3600fe718af126c70af0..9244d28dfae9cd27f1be491b179b21dec62caa4d 100644 (file)
@@ -163,7 +163,7 @@ if (isset($_GET["username"]) && is_string(get_password())) {
                auth_error(lang('Connecting to privileged ports is not allowed.'));
        }
        check_invalid_login();
-       $connection = connect();
+       $connection = connect($adminer->credentials());
        $driver = new Driver($connection);
        if ($adminer->operators === null) {
                $adminer->operators = $driver->operators;
index 18734af91b338df0bce369922d7940e2ed3cbe28..c386aa6b5a6d426b21f5109058d5343262a86026 100644 (file)
@@ -1302,7 +1302,7 @@ function slow_query($query) {
        $db = $adminer->database();
        $timeout = $adminer->queryTimeout();
        $slow_query = $driver->slowQuery($query, $timeout);
-       if (!$slow_query && support("kill") && is_object($connection2 = connect()) && ($db == "" || $connection2->select_db($db))) {
+       if (!$slow_query && support("kill") && is_object($connection2 = connect($adminer->credentials())) && ($db == "" || $connection2->select_db($db))) {
                $kill = $connection2->result(connection_id()); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
                ?>
 <script<?php echo nonce(); ?>>
index 28884a7f83c5f9216481cbe6921a56c0c52481c9..593cd63f753d626b27c29361bf421cc30636ae69 100644 (file)
@@ -52,7 +52,7 @@ if (!$error && $_POST) {
                $delimiter = ";";
                $offset = 0;
                $empty = true;
-               $connection2 = connect(); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error
+               $connection2 = connect($adminer->credentials()); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error
                if (is_object($connection2) && DB != "") {
                        $connection2->select_db(DB);
                        if ($_GET["ns"] != "") {
index ae6854f183cc89574c7b4a3ac407b7845302ebf8..b1ab464799ad812012a0c3486602d440e8957803 100644 (file)
@@ -234,10 +234,9 @@ if (isset($_GET["clickhouse"])) {
                return apply_queries("DROP TABLE", $tables);
        }
 
-       function connect() {
-               $adminer = adminer();
+       function connect($credentials) {
                $connection = new Db;
-               list($server, $username, $password) = $adminer->credentials();
+               list($server, $username, $password) = $credentials;
                if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
                        return lang('Invalid server.');
                }
index 465cedb33abe2755159b7d676245e963d2b7e0dd..151b23321ebe682d488f450a615dd57e5f5aa7c7 100644 (file)
@@ -286,10 +286,10 @@ if (isset($_GET["elastic"])) {
                }
        }
 
-       function connect() {
+       function connect($credentials) {
                $connection = new Db;
 
-               list($server, $username, $password) = adminer()->credentials();
+               list($server, $username, $password) = $credentials;
                if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
                        return lang('Invalid server.');
                }
index f2301dfffdb30318c7d35fe4691ed86b12a81bbb..ca53692990fdd577cd45692db34eaf9adaaf7838 100644 (file)
@@ -273,10 +273,10 @@ if (isset($_GET["elastic5"])) {
                }
        }
 
-       function connect() {
+       function connect($credentials) {
                $connection = new Db;
 
-               list($server, $username, $password) = adminer()->credentials();
+               list($server, $username, $password) = $credentials;
                if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
                        return lang('Invalid server.');
                }
index e2c7309a5ad2f923f8f282b6a6dbdc309a12297c..2e22084dec830aecf5f4437403a113172dc07d07 100644 (file)
@@ -131,10 +131,8 @@ if (isset($_GET["firebird"])) {
                return idf_escape($idf);
        }
 
-       function connect() {
-               $adminer = adminer();
+       function connect($credentials) {
                $connection = new Db;
-               $credentials = $adminer->credentials();
                if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
                        return $connection;
                }
index 241d17741604d6b4797541fab6bacc6a80d3fed4..36cfb8204bfae95bd255d6d2759f2129f896ed1c 100644 (file)
@@ -251,9 +251,8 @@ if (isset($_GET["simpledb"])) {
 
 
 
-       function connect() {
-               $adminer = adminer();
-               list($host, , $password) = $adminer->credentials();
+       function connect($credentials) {
+               list($host, , $password) = $credentials;
                if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $host)) {
                        return lang('Invalid server.');
                }