mirror of
https://github.com/vrana/adminer.git
synced 2025-08-11 09:04:02 +02:00
Move Elastic drivers to plugins, driver for Elastic 7+ is the default
This commit is contained in:
13
adminer/elastic.php
Normal file
13
adminer/elastic.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
function adminer_object() {
|
||||||
|
include_once "../plugins/plugin.php";
|
||||||
|
include_once "../plugins/login-password-less.php";
|
||||||
|
include_once "../plugins/drivers/elastic.php";
|
||||||
|
include_once "../plugins/drivers/elastic5.php";
|
||||||
|
return new AdminerPlugin([
|
||||||
|
// TODO: inline the result of password_hash() so that the password is not visible in source codes
|
||||||
|
new AdminerLoginPasswordLess(password_hash("YOUR_PASSWORD_HERE", PASSWORD_DEFAULT)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
include "./index.php";
|
@@ -81,7 +81,6 @@ include "../adminer/drivers/pgsql.inc.php";
|
|||||||
include "../adminer/drivers/oracle.inc.php";
|
include "../adminer/drivers/oracle.inc.php";
|
||||||
include "../adminer/drivers/mssql.inc.php";
|
include "../adminer/drivers/mssql.inc.php";
|
||||||
include "../adminer/drivers/mongo.inc.php";
|
include "../adminer/drivers/mongo.inc.php";
|
||||||
include "../adminer/drivers/elastic.inc.php";
|
|
||||||
include "./include/adminer.inc.php";
|
include "./include/adminer.inc.php";
|
||||||
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
|
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
|
||||||
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
|
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
$drivers["elastic7"] = "Elasticsearch 7 (beta)";
|
add_driver("elastic", "Elasticsearch 7 (beta)");
|
||||||
|
|
||||||
if (isset($_GET["elastic7"])) {
|
if (isset($_GET["elastic"])) {
|
||||||
define("DRIVER", "elastic7");
|
define("DRIVER", "elastic");
|
||||||
|
|
||||||
if (function_exists('json_decode') && ini_bool('allow_url_fopen')) {
|
if (ini_bool('allow_url_fopen')) {
|
||||||
define("ELASTIC_DB_NAME", "elastic");
|
define("ELASTIC_DB_NAME", "elastic");
|
||||||
|
|
||||||
class Min_DB {
|
class Min_DB {
|
||||||
@@ -131,8 +131,6 @@ if (isset($_GET["elastic7"])) {
|
|||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
|
|
||||||
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
||||||
global $adminer;
|
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
if ($select != array("*")) {
|
if ($select != array("*")) {
|
||||||
$data["fields"] = $select;
|
$data["fields"] = $select;
|
||||||
@@ -187,7 +185,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
$search = $this->_conn->rootQuery($query, $data);
|
$search = $this->_conn->rootQuery($query, $data);
|
||||||
|
|
||||||
if ($print) {
|
if ($print) {
|
||||||
echo $adminer->selectQuery("$query: " . json_encode($data), $start, !$search);
|
echo adminer()->selectQuery("$query: " . json_encode($data), $start, !$search);
|
||||||
}
|
}
|
||||||
if (empty($search)) {
|
if (empty($search)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -274,11 +272,9 @@ if (isset($_GET["elastic7"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
global $adminer;
|
|
||||||
|
|
||||||
$connection = new Min_DB;
|
$connection = new Min_DB;
|
||||||
|
|
||||||
list($server, $username, $password) = $adminer->credentials();
|
list($server, $username, $password) = adminer()->credentials();
|
||||||
if ($password != "" && $connection->connect($server, $username, "")) {
|
if ($password != "" && $connection->connect($server, $username, "")) {
|
||||||
return lang('Database does not support password.');
|
return lang('Database does not support password.');
|
||||||
}
|
}
|
||||||
@@ -295,9 +291,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function logged_user() {
|
function logged_user() {
|
||||||
global $adminer;
|
$credentials = adminer()->credentials();
|
||||||
|
|
||||||
$credentials = $adminer->credentials();
|
|
||||||
|
|
||||||
return $credentials[1];
|
return $credentials[1];
|
||||||
}
|
}
|
||||||
@@ -323,9 +317,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function count_tables($databases) {
|
function count_tables($databases) {
|
||||||
global $connection;
|
$return = connection()->rootQuery('_aliases');
|
||||||
|
|
||||||
$return = $connection->rootQuery('_aliases');
|
|
||||||
if (empty($return)) {
|
if (empty($return)) {
|
||||||
return array(
|
return array(
|
||||||
ELASTIC_DB_NAME => 0
|
ELASTIC_DB_NAME => 0
|
||||||
@@ -338,9 +330,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function tables_list() {
|
function tables_list() {
|
||||||
global $connection;
|
$aliases = connection()->rootQuery('_aliases');
|
||||||
|
|
||||||
$aliases = $connection->rootQuery('_aliases');
|
|
||||||
if (empty($aliases)) {
|
if (empty($aliases)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
@@ -359,10 +349,8 @@ if (isset($_GET["elastic7"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function table_status($name = "", $fast = false) {
|
function table_status($name = "", $fast = false) {
|
||||||
global $connection;
|
$stats = connection()->rootQuery('_stats');
|
||||||
|
$aliases = connection()->rootQuery('_aliases');
|
||||||
$stats = $connection->rootQuery('_stats');
|
|
||||||
$aliases = $connection->rootQuery('_aliases');
|
|
||||||
|
|
||||||
if (empty($stats) || empty($aliases)) {
|
if (empty($stats) || empty($aliases)) {
|
||||||
return array();
|
return array();
|
||||||
@@ -427,9 +415,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
global $connection;
|
return h(connection()->error);
|
||||||
|
|
||||||
return h($connection->error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function information_schema() {
|
function information_schema() {
|
||||||
@@ -443,13 +429,11 @@ if (isset($_GET["elastic7"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fields($table) {
|
function fields($table) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$mappings = array();
|
$mappings = array();
|
||||||
$mapping = $connection->rootQuery("_mapping");
|
$mapping = connection()->rootQuery("_mapping");
|
||||||
|
|
||||||
if (!isset($mapping[$table])) {
|
if (!isset($mapping[$table])) {
|
||||||
$aliases = $connection->rootQuery('_aliases');
|
$aliases = connection()->rootQuery('_aliases');
|
||||||
|
|
||||||
foreach ($aliases as $index_name => $index) {
|
foreach ($aliases as $index_name => $index) {
|
||||||
foreach ($index["aliases"] as $alias_name => $alias) {
|
foreach ($index["aliases"] as $alias_name => $alias) {
|
||||||
@@ -530,9 +514,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function create_database($db) {
|
function create_database($db) {
|
||||||
global $connection;
|
return connection()->rootQuery(urlencode($db), null, 'PUT');
|
||||||
|
|
||||||
return $connection->rootQuery(urlencode($db), null, 'PUT');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove index
|
/** Remove index
|
||||||
@@ -540,9 +522,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function drop_databases($databases) {
|
function drop_databases($databases) {
|
||||||
global $connection;
|
return connection()->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
||||||
|
|
||||||
return $connection->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Alter type
|
/** Alter type
|
||||||
@@ -550,8 +530,6 @@ if (isset($_GET["elastic7"])) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$properties = array();
|
$properties = array();
|
||||||
foreach ($fields as $f) {
|
foreach ($fields as $f) {
|
||||||
$field_name = trim($f[1][0]);
|
$field_name = trim($f[1][0]);
|
||||||
@@ -565,7 +543,7 @@ if (isset($_GET["elastic7"])) {
|
|||||||
$properties = array('properties' => $properties);
|
$properties = array('properties' => $properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $connection->query("_mapping/{$name}", $properties, 'PUT');
|
return connection()->query("_mapping/{$name}", $properties, 'PUT');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Drop types
|
/** Drop types
|
||||||
@@ -573,20 +551,16 @@ if (isset($_GET["elastic7"])) {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function drop_tables($tables) {
|
function drop_tables($tables) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$return = true;
|
$return = true;
|
||||||
foreach ($tables as $table) { //! convert to bulk api
|
foreach ($tables as $table) { //! convert to bulk api
|
||||||
$return = $return && $connection->query(urlencode($table), null, 'DELETE');
|
$return = $return && connection()->query(urlencode($table), null, 'DELETE');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function last_id() {
|
function last_id() {
|
||||||
global $connection;
|
return connection()->last_id;
|
||||||
|
|
||||||
return $connection->last_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function driver_config() {
|
function driver_config() {
|
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
$drivers["elastic"] = "Elasticsearch (beta)";
|
add_driver("elastic5", "Elasticsearch 5 (beta)");
|
||||||
|
|
||||||
if (isset($_GET["elastic"])) {
|
if (isset($_GET["elastic5"])) {
|
||||||
define("DRIVER", "elastic");
|
define("DRIVER", "elastic5");
|
||||||
|
|
||||||
if (function_exists('json_decode') && ini_bool('allow_url_fopen')) {
|
if (ini_bool('allow_url_fopen')) {
|
||||||
class Min_DB {
|
class Min_DB {
|
||||||
var $extension = "JSON", $server_info, $errno, $error, $_url, $_db;
|
var $extension = "JSON", $server_info, $errno, $error, $_url, $_db;
|
||||||
|
|
||||||
@@ -119,8 +119,6 @@ if (isset($_GET["elastic"])) {
|
|||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
|
|
||||||
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
||||||
global $adminer;
|
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
if ($select != array("*")) {
|
if ($select != array("*")) {
|
||||||
$data["fields"] = $select;
|
$data["fields"] = $select;
|
||||||
@@ -175,7 +173,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
$search = $this->_conn->query($query, $data);
|
$search = $this->_conn->query($query, $data);
|
||||||
|
|
||||||
if ($print) {
|
if ($print) {
|
||||||
echo $adminer->selectQuery("$query: " . json_encode($data), $start, !$search);
|
echo adminer()->selectQuery("$query: " . json_encode($data), $start, !$search);
|
||||||
}
|
}
|
||||||
if (!$search) {
|
if (!$search) {
|
||||||
return false;
|
return false;
|
||||||
@@ -265,11 +263,9 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
global $adminer;
|
|
||||||
|
|
||||||
$connection = new Min_DB;
|
$connection = new Min_DB;
|
||||||
|
|
||||||
list($server, $username, $password) = $adminer->credentials();
|
list($server, $username, $password) = adminer()->credentials();
|
||||||
if ($password != "" && $connection->connect($server, $username, "")) {
|
if ($password != "" && $connection->connect($server, $username, "")) {
|
||||||
return lang('Database does not support password.');
|
return lang('Database does not support password.');
|
||||||
}
|
}
|
||||||
@@ -286,17 +282,13 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function logged_user() {
|
function logged_user() {
|
||||||
global $adminer;
|
$credentials = adminer()->credentials();
|
||||||
|
|
||||||
$credentials = $adminer->credentials();
|
|
||||||
|
|
||||||
return $credentials[1];
|
return $credentials[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_databases() {
|
function get_databases() {
|
||||||
global $connection;
|
$return = connection()->rootQuery('_aliases');
|
||||||
|
|
||||||
$return = $connection->rootQuery('_aliases');
|
|
||||||
if ($return) {
|
if ($return) {
|
||||||
$return = array_keys($return);
|
$return = array_keys($return);
|
||||||
sort($return, SORT_STRING);
|
sort($return, SORT_STRING);
|
||||||
@@ -322,11 +314,9 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function count_tables($databases) {
|
function count_tables($databases) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$result = $connection->query('_stats');
|
|
||||||
|
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
|
$result = connection()->query('_stats');
|
||||||
if ($result && $result['indices']) {
|
if ($result && $result['indices']) {
|
||||||
$indices = $result['indices'];
|
$indices = $result['indices'];
|
||||||
foreach ($indices as $indice => $stats) {
|
foreach ($indices as $indice => $stats) {
|
||||||
@@ -339,24 +329,20 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function tables_list() {
|
function tables_list() {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
if (min_version(7)) {
|
if (min_version(7)) {
|
||||||
return array('_doc' => 'table');
|
return array('_doc' => 'table');
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = $connection->query('_mapping');
|
$return = connection()->query('_mapping');
|
||||||
if ($return) {
|
if ($return) {
|
||||||
$return = array_fill_keys(array_keys($return[$connection->_db]["mappings"]), 'table');
|
$return = array_fill_keys(array_keys($return[connection()->_db]["mappings"]), 'table');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function table_status($name = "", $fast = false) {
|
function table_status($name = "", $fast = false) {
|
||||||
global $connection;
|
$search = connection()->query("_search", array(
|
||||||
|
|
||||||
$search = $connection->query("_search", array(
|
|
||||||
"size" => 0,
|
"size" => 0,
|
||||||
"aggregations" => array(
|
"aggregations" => array(
|
||||||
"count_by_type" => array(
|
"count_by_type" => array(
|
||||||
@@ -389,9 +375,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
global $connection;
|
return h(connection()->error);
|
||||||
|
|
||||||
return h($connection->error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function information_schema() {
|
function information_schema() {
|
||||||
@@ -407,21 +391,19 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fields($table) {
|
function fields($table) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$mappings = array();
|
$mappings = array();
|
||||||
|
|
||||||
if (min_version(7)) {
|
if (min_version(7)) {
|
||||||
$result = $connection->query("_mapping");
|
$result = connection()->query("_mapping");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$mappings = $result[$connection->_db]['mappings']['properties'];
|
$mappings = $result[connection()->_db]['mappings']['properties'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$result = $connection->query("$table/_mapping");
|
$result = connection()->query("$table/_mapping");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$mappings = $result[$table]['properties'];
|
$mappings = $result[$table]['properties'];
|
||||||
if (!$mappings) {
|
if (!$mappings) {
|
||||||
$mappings = $result[$connection->_db]['mappings'][$table]['properties'];
|
$mappings = $result[connection()->_db]['mappings'][$table]['properties'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,9 +472,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function create_database($db) {
|
function create_database($db) {
|
||||||
global $connection;
|
return connection()->rootQuery(urlencode($db), null, 'PUT');
|
||||||
|
|
||||||
return $connection->rootQuery(urlencode($db), null, 'PUT');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove index
|
/** Remove index
|
||||||
@@ -500,9 +480,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function drop_databases($databases) {
|
function drop_databases($databases) {
|
||||||
global $connection;
|
return connection()->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
||||||
|
|
||||||
return $connection->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Alter type
|
/** Alter type
|
||||||
@@ -510,8 +488,6 @@ if (isset($_GET["elastic"])) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$properties = array();
|
$properties = array();
|
||||||
foreach ($fields as $f) {
|
foreach ($fields as $f) {
|
||||||
$field_name = trim($f[1][0]);
|
$field_name = trim($f[1][0]);
|
||||||
@@ -524,8 +500,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
if (!empty($properties)) {
|
if (!empty($properties)) {
|
||||||
$properties = array('properties' => $properties);
|
$properties = array('properties' => $properties);
|
||||||
}
|
}
|
||||||
|
return connection()->query("_mapping/{$name}", $properties, 'PUT');
|
||||||
return $connection->query("_mapping/{$name}", $properties, 'PUT');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Drop types
|
/** Drop types
|
||||||
@@ -533,20 +508,16 @@ if (isset($_GET["elastic"])) {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function drop_tables($tables) {
|
function drop_tables($tables) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$return = true;
|
$return = true;
|
||||||
foreach ($tables as $table) { //! convert to bulk api
|
foreach ($tables as $table) { //! convert to bulk api
|
||||||
$return = $return && $connection->query(urlencode($table), null, 'DELETE');
|
$return = $return && connection()->query(urlencode($table), null, 'DELETE');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function last_id() {
|
function last_id() {
|
||||||
global $connection;
|
return connection()->last_id;
|
||||||
|
|
||||||
return $connection->last_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function driver_config() {
|
function driver_config() {
|
Reference in New Issue
Block a user