1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 14:46:36 +02:00

Pass credentials to connect()

This commit is contained in:
Jakub Vrana
2025-03-07 12:03:29 +01:00
parent 95e6a65999
commit 9918f4155e
15 changed files with 22 additions and 36 deletions

View 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);
}

View 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";

View 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;
}

View 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");

View 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;
}

View 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'");

View 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.');
}

View 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;

View 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(); ?>>

View 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"] != "") {

View 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.');
}

View 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.');
}

View 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.');
}

View 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;
}

View 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.');
}