1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-07 23:27:17 +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) { if (!$result) {
echo "<p class='error'>" . error() . "\n"; echo "<p class='error'>" . error() . "\n";
} else { } else {
$connection2 = connect(); $connection2 = connect($adminer->credentials());
if (is_object($connection2)) { if (is_object($connection2)) {
$connection2->select_db(DB); $connection2->select_db(DB);
} }

View File

@@ -421,10 +421,10 @@ if (isset($_GET["mongo"])) {
return $credentials[1]; return $credentials[1];
} }
function connect() { function connect($credentials) {
global $adminer; global $adminer;
$connection = new Db; $connection = new Db;
list($server, $username, $password) = $adminer->credentials(); list($server, $username, $password) = $credentials;
if ($server == "") { if ($server == "") {
$server = "localhost:27017"; $server = "localhost:27017";

View File

@@ -280,15 +280,11 @@ if (isset($_GET["mssql"])) {
return ($_GET["ns"] != "" ? idf_escape($_GET["ns"]) . "." : "") . idf_escape($idf); return ($_GET["ns"] != "" ? idf_escape($_GET["ns"]) . "." : "") . idf_escape($idf);
} }
function connect() { function connect($credentials) {
global $adminer;
$connection = new Db; $connection = new Db;
$credentials = $adminer->credentials();
if ($credentials[0] == "") { if ($credentials[0] == "") {
$credentials[0] = "localhost:1433"; $credentials[0] = "localhost:1433";
} }
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
return $connection; return $connection;
} }

View File

@@ -421,12 +421,11 @@ if (!defined('Adminer\DRIVER')) {
} }
/** Connect to the database /** Connect to the database
* @param array [$server, $username, $password]
* @return mixed Db or string for error * @return mixed Db or string for error
*/ */
function connect() { function connect($credentials) {
global $adminer;
$connection = new Db; $connection = new Db;
$credentials = $adminer->credentials();
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
$connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5 $connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5
$connection->query("SET sql_quote_show_create = 1, autocommit = 1"); $connection->query("SET sql_quote_show_create = 1, autocommit = 1");

View File

@@ -211,10 +211,8 @@ if (isset($_GET["oracle"])) {
return idf_escape($idf); return idf_escape($idf);
} }
function connect() { function connect($credentials) {
global $adminer;
$connection = new Db; $connection = new Db;
$credentials = $adminer->credentials();
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
return $connection; return $connection;
} }

View File

@@ -312,10 +312,8 @@ if (isset($_GET["pgsql"])) {
return idf_escape($idf); return idf_escape($idf);
} }
function connect() { function connect($credentials) {
global $adminer;
$connection = new Db; $connection = new Db;
$credentials = $adminer->credentials();
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
if (min_version(9, 0, $connection)) { if (min_version(9, 0, $connection)) {
$connection->query("SET application_name = 'Adminer'"); $connection->query("SET application_name = 'Adminer'");

View File

@@ -190,9 +190,8 @@ if (isset($_GET["sqlite"])) {
return idf_escape($idf); return idf_escape($idf);
} }
function connect() { function connect($credentials) {
global $adminer; list(, , $password) = $credentials;
list(, , $password) = $adminer->credentials();
if ($password != "") { if ($password != "") {
return lang('Database does not support 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.')); auth_error(lang('Connecting to privileged ports is not allowed.'));
} }
check_invalid_login(); check_invalid_login();
$connection = connect(); $connection = connect($adminer->credentials());
$driver = new Driver($connection); $driver = new Driver($connection);
if ($adminer->operators === null) { if ($adminer->operators === null) {
$adminer->operators = $driver->operators; $adminer->operators = $driver->operators;

View File

@@ -1302,7 +1302,7 @@ function slow_query($query) {
$db = $adminer->database(); $db = $adminer->database();
$timeout = $adminer->queryTimeout(); $timeout = $adminer->queryTimeout();
$slow_query = $driver->slowQuery($query, $timeout); $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 $kill = $connection2->result(connection_id()); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
?> ?>
<script<?php echo nonce(); ?>> <script<?php echo nonce(); ?>>

View File

@@ -52,7 +52,7 @@ if (!$error && $_POST) {
$delimiter = ";"; $delimiter = ";";
$offset = 0; $offset = 0;
$empty = true; $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 != "") { if (is_object($connection2) && DB != "") {
$connection2->select_db(DB); $connection2->select_db(DB);
if ($_GET["ns"] != "") { if ($_GET["ns"] != "") {

View File

@@ -234,10 +234,9 @@ if (isset($_GET["clickhouse"])) {
return apply_queries("DROP TABLE", $tables); return apply_queries("DROP TABLE", $tables);
} }
function connect() { function connect($credentials) {
$adminer = adminer();
$connection = new Db; $connection = new Db;
list($server, $username, $password) = $adminer->credentials(); list($server, $username, $password) = $credentials;
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) { if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.'); return lang('Invalid server.');
} }

View File

@@ -286,10 +286,10 @@ if (isset($_GET["elastic"])) {
} }
} }
function connect() { function connect($credentials) {
$connection = new Db; $connection = new Db;
list($server, $username, $password) = adminer()->credentials(); list($server, $username, $password) = $credentials;
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) { if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.'); return lang('Invalid server.');
} }

View File

@@ -273,10 +273,10 @@ if (isset($_GET["elastic5"])) {
} }
} }
function connect() { function connect($credentials) {
$connection = new Db; $connection = new Db;
list($server, $username, $password) = adminer()->credentials(); list($server, $username, $password) = $credentials;
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) { if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.'); return lang('Invalid server.');
} }

View File

@@ -131,10 +131,8 @@ if (isset($_GET["firebird"])) {
return idf_escape($idf); return idf_escape($idf);
} }
function connect() { function connect($credentials) {
$adminer = adminer();
$connection = new Db; $connection = new Db;
$credentials = $adminer->credentials();
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
return $connection; return $connection;
} }

View File

@@ -251,9 +251,8 @@ if (isset($_GET["simpledb"])) {
function connect() { function connect($credentials) {
$adminer = adminer(); list($host, , $password) = $credentials;
list($host, , $password) = $adminer->credentials();
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $host)) { if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $host)) {
return lang('Invalid server.'); return lang('Invalid server.');
} }