function connect($server, $username, $password) {
preg_match('~^(https?://)?(.*)~', $server, $match);
- $this->_url = ($match[1] ? $match[1] : "http://") . "$username:$password@$match[2]";
+ $this->_url = ($match[1] ? $match[1] : "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query('SELECT 1');
return (bool) $return;
}
function connect() {
global $adminer;
$connection = new Min_DB;
- $credentials = $adminer->credentials();
- if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
+ list($server, $username, $password) = $adminer->credentials();
+ if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
+ return lang('Invalid server.');
+ }
+ if ($connection->connect($server, $username, $password)) {
return $connection;
}
return $connection->error;
* @return bool
*/
function connect($server, $username, $password) {
- $this->_url = build_http_url($server, $username, $password, "localhost", 9200);
-
+ preg_match('~^(https?://)?(.*)~', $server, $match);
+ $this->_url = ($match[1] ? $match[1] : "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query('');
- if (!$return) {
- return false;
+ if ($return) {
+ $this->server_info = $return['version']['number'];
}
-
- if (!isset($return['version']['number'])) {
- $this->error = lang('Invalid server or credentials.');
- return false;
- }
-
- $this->server_info = $return['version']['number'];
- return true;
+ return (bool) $return;
}
function select_db($database) {
$connection = new Min_DB;
list($server, $username, $password) = adminer()->credentials();
+ if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
+ return lang('Invalid server.');
+ }
if ($password != "" && $connection->connect($server, $username, "")) {
return lang('Database does not support password.');
}
function connect($server, $username, $password) {
preg_match('~^(https?://)?(.*)~', $server, $match);
- $this->_url = ($match[1] ? $match[1] : "http://") . "$username:$password@$match[2]";
+ $this->_url = ($match[1] ? $match[1] : "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query('');
if ($return) {
$this->server_info = $return['version']['number'];
$connection = new Min_DB;
list($server, $username, $password) = adminer()->credentials();
+ if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
+ return lang('Invalid server.');
+ }
if ($password != "" && $connection->connect($server, $username, "")) {
return lang('Database does not support password.');
}
function connect() {
global $adminer;
- list(, , $password) = $adminer->credentials();
+ list($host, , $password) = $adminer->credentials();
+ if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $host)) {
+ return lang('Invalid server.');
+ }
if ($password != "") {
return lang('Database does not support password.');
}