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

Support connecting to MySQL via SSL

This commit is contained in:
Jakub Vrana
2018-02-07 12:13:58 +01:00
parent cac523402a
commit 42eec7d728
7 changed files with 64 additions and 4 deletions

View File

@@ -14,15 +14,21 @@ if (!defined("DRIVER")) {
}
function connect($server = "", $username = "", $password = "", $database = null, $port = null, $socket = null) {
global $adminer;
mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4
list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
$ssl = $adminer->connectSsl();
if ($ssl) {
$this->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], '', '');
}
$return = @$this->real_connect(
($server != "" ? $host : ini_get("mysqli.default_host")),
($server . $username != "" ? $username : ini_get("mysqli.default_user")),
($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")),
$database,
(is_numeric($port) ? $port : ini_get("mysqli.default_port")),
(!is_numeric($port) ? $port : $socket)
(!is_numeric($port) ? $port : $socket),
($ssl ? 64 : 0) // 64 - MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT (not available before PHP 5.6.16)
);
return $return;
}
@@ -223,7 +229,22 @@ if (!defined("DRIVER")) {
var $extension = "PDO_MySQL";
function connect($server, $username, $password) {
$this->dsn("mysql:charset=utf8;host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\\d)~', ';port=\\1', $server)), $username, $password);
global $adminer;
$options = array();
$ssl = $adminer->connectSsl();
if ($ssl) {
$options = array(
PDO::MYSQL_ATTR_SSL_KEY => $ssl['key'],
PDO::MYSQL_ATTR_SSL_CERT => $ssl['cert'],
PDO::MYSQL_ATTR_SSL_CA => $ssl['ca'],
);
}
$this->dsn(
"mysql:charset=utf8;host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\\d)~', ';port=\\1', $server)),
$username,
$password,
$options
);
return true;
}