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

Call Plugins from Adminer class

This commit is contained in:
Jakub Vrana
2025-03-25 07:27:11 +01:00
parent 54f3437a6a
commit c169c55d70
2 changed files with 41 additions and 35 deletions

View File

@@ -111,15 +111,15 @@ class Adminer {
/** Print login form */ /** Print login form */
function loginForm(): void { function loginForm(): void {
global $drivers; global $drivers, $adminer;
echo "<table class='layout'>\n"; echo "<table class='layout'>\n";
// this is matched by compile.php // this is matched by compile.php
echo $this->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);")); echo $adminer->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);"));
echo $this->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">'); echo $adminer->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">');
// this is matched by compile.php // this is matched by compile.php
echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">' . script("qs('#username').form['auth[driver]'].onchange();")); echo $adminer->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">' . script("qs('#username').form['auth[driver]'].onchange();"));
echo $this->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">'); echo $adminer->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
echo $this->loginFormField('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">'); echo $adminer->loginFormField('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">');
echo "</table>\n"; echo "</table>\n";
echo "<p><input type='submit' value='" . lang('Login') . "'>\n"; echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
@@ -519,7 +519,7 @@ class Adminer {
* @return list<string> expressions to join by AND * @return list<string> expressions to join by AND
*/ */
function selectSearchProcess(array $fields, array $indexes): array { function selectSearchProcess(array $fields, array $indexes): array {
global $connection, $driver; global $connection, $driver, $adminer;
$return = array(); $return = array();
foreach ($indexes as $i => $index) { foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") { if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
@@ -536,14 +536,14 @@ class Adminer {
} elseif ($val["op"] == "SQL") { } elseif ($val["op"] == "SQL") {
$cond = " $val[val]"; // SQL injection $cond = " $val[val]"; // SQL injection
} elseif ($val["op"] == "LIKE %%") { } elseif ($val["op"] == "LIKE %%") {
$cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%"); $cond = " LIKE " . $adminer->processInput($fields[$val["col"]], "%$val[val]%");
} elseif ($val["op"] == "ILIKE %%") { } elseif ($val["op"] == "ILIKE %%") {
$cond = " ILIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%"); $cond = " ILIKE " . $adminer->processInput($fields[$val["col"]], "%$val[val]%");
} elseif ($val["op"] == "FIND_IN_SET") { } elseif ($val["op"] == "FIND_IN_SET") {
$prefix = "$val[op](" . q($val["val"]) . ", "; $prefix = "$val[op](" . q($val["val"]) . ", ";
$cond = ")"; $cond = ")";
} elseif (!preg_match('~NULL$~', $val["op"])) { } elseif (!preg_match('~NULL$~', $val["op"])) {
$cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]); $cond .= " " . $adminer->processInput($fields[$val["col"]], $val["val"]);
} }
if ($val["col"] != "") { if ($val["col"] != "") {
$return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $val, $fields[$val["col"]]) . $cond; $return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $val, $fields[$val["col"]]) . $cond;
@@ -938,8 +938,8 @@ class Adminer {
* @param string $missing can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema * @param string $missing can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
*/ */
function navigation(string $missing): void { function navigation(string $missing): void {
global $VERSION, $drivers, $connection; global $VERSION, $drivers, $connection, $adminer;
echo "<h1>" . $this->name() . " <span class='version'>$VERSION"; echo "<h1>" . $adminer->name() . " <span class='version'>$VERSION";
$new_version = $_COOKIE["adminer_version"]; $new_version = $_COOKIE["adminer_version"];
echo " <a href='https://www.adminer.org/#download'" . target_blank() . " id='version'>" . (version_compare($VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>"; echo " <a href='https://www.adminer.org/#download'" . target_blank() . " id='version'>" . (version_compare($VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>";
echo "</span></h1>\n"; echo "</span></h1>\n";
@@ -954,7 +954,7 @@ class Adminer {
if ($password !== null) { if ($password !== null) {
$dbs = $_SESSION["db"][$vendor][$server][$username]; $dbs = $_SESSION["db"][$vendor][$server][$username];
foreach (($dbs ? array_keys($dbs) : array("")) as $db) { foreach (($dbs ? array_keys($dbs) : array("")) as $db) {
$output .= "<li><a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>($name) " . h($username . ($server != "" ? "@" . $this->serverName($server) : "") . ($db != "" ? " - $db" : "")) . "</a>\n"; $output .= "<li><a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>($name) " . h($username . ($server != "" ? "@" . $adminer->serverName($server) : "") . ($db != "" ? " - $db" : "")) . "</a>\n";
} }
} }
} }
@@ -969,8 +969,8 @@ class Adminer {
$connection->select_db(DB); $connection->select_db(DB);
$tables = table_status('', true); $tables = table_status('', true);
} }
$this->syntaxHighlighting($tables); $adminer->syntaxHighlighting($tables);
$this->databasesPrint($missing); $adminer->databasesPrint($missing);
$actions = array(); $actions = array();
if (DB == "" || !$missing) { if (DB == "" || !$missing) {
if (support("sql")) { if (support("sql")) {
@@ -986,7 +986,7 @@ class Adminer {
echo ($actions ? "<p class='links'>\n" . implode("\n", $actions) . "\n" : ""); echo ($actions ? "<p class='links'>\n" . implode("\n", $actions) . "\n" : "");
if ($in_db) { if ($in_db) {
if ($tables) { if ($tables) {
$this->tablesPrint($tables); $adminer->tablesPrint($tables);
} else { } else {
echo "<p class='message'>" . lang('No tables.') . "</p>\n"; echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} }
@@ -1027,7 +1027,7 @@ class Adminer {
/** Print databases list in menu */ /** Print databases list in menu */
function databasesPrint(string $missing): void { function databasesPrint(string $missing): void {
global $adminer, $connection; global $adminer, $connection;
$databases = $this->databases(); $databases = $adminer->databases();
if (DB && $databases && !in_array(DB, $databases)) { if (DB && $databases && !in_array(DB, $databases)) {
array_unshift($databases, DB); array_unshift($databases, DB);
} }
@@ -1060,9 +1060,10 @@ class Adminer {
* @param TableStatus[] $tables result of table_status('', true) * @param TableStatus[] $tables result of table_status('', true)
*/ */
function tablesPrint(array $tables): void { function tablesPrint(array $tables): void {
global $adminer;
echo "<ul id='tables'>" . script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});"); echo "<ul id='tables'>" . script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
foreach ($tables as $table => $status) { foreach ($tables as $table => $status) {
$name = $this->tableName($status); $name = $adminer->tableName($status);
if ($name != "") { if ($name != "") {
echo '<li><a href="' . h(ME) . 'select=' . urlencode($table) . '"' echo '<li><a href="' . h(ME) . 'select=' . urlencode($table) . '"'
. bold($_GET["select"] == $table || $_GET["edit"] == $table, "select") . bold($_GET["select"] == $table || $_GET["edit"] == $table, "select")

View File

@@ -31,9 +31,9 @@ class Adminer {
} }
function database() { function database() {
global $connection; global $connection, $adminer;
if ($connection) { if ($connection) {
$databases = $this->databases(false); $databases = $adminer->databases(false);
return (!$databases return (!$databases
? get_val("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1)") // username without the database list ? get_val("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1)") // username without the database list
: $databases[(information_schema($databases[0]) ? 1 : 0)] // first available database : $databases[(information_schema($databases[0]) ? 1 : 0)] // first available database
@@ -76,9 +76,10 @@ class Adminer {
} }
function loginForm() { function loginForm() {
global $adminer;
echo "<table class='layout'>\n"; echo "<table class='layout'>\n";
echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', input_hidden("auth[driver]", "server") . '<input name="auth[username]" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">'); echo $adminer->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', input_hidden("auth[driver]", "server") . '<input name="auth[username]" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">');
echo $this->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">'); echo $adminer->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
echo "</table>\n"; echo "</table>\n";
echo "<p><input type='submit' value='" . lang('Login') . "'>\n"; echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
@@ -115,19 +116,20 @@ class Adminer {
} }
function backwardKeys($table, $tableName) { function backwardKeys($table, $tableName) {
global $adminer;
$return = array(); $return = array();
foreach ( foreach (
get_rows("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME get_rows("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
FROM information_schema.KEY_COLUMN_USAGE FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = " . q($this->database()) . " WHERE TABLE_SCHEMA = " . q($adminer->database()) . "
AND REFERENCED_TABLE_SCHEMA = " . q($this->database()) . " AND REFERENCED_TABLE_SCHEMA = " . q($adminer->database()) . "
AND REFERENCED_TABLE_NAME = " . q($table) . " AND REFERENCED_TABLE_NAME = " . q($table) . "
ORDER BY ORDINAL_POSITION", null, "") as $row ORDER BY ORDINAL_POSITION", null, "") as $row
) { ) {
$return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"]; $return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
} }
foreach ($return as $key => $val) { foreach ($return as $key => $val) {
$name = $this->tableName(table_status1($key, true)); $name = $adminer->tableName(table_status1($key, true));
if ($name != "") { if ($name != "") {
$search = preg_quote($tableName); $search = preg_quote($tableName);
$separator = "(:|\\s*-)?\\s+"; $separator = "(:|\\s*-)?\\s+";
@@ -350,7 +352,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
} }
function selectSearchProcess($fields, $indexes) { function selectSearchProcess($fields, $indexes) {
global $driver; global $driver, $adminer;
$return = array(); $return = array();
foreach ((array) $_GET["where"] as $key => $where) { foreach ((array) $_GET["where"] as $key => $where) {
$col = $where["col"]; $col = $where["col"];
@@ -365,7 +367,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
$conds[] = (in_array(0, $val) ? "$name IS NULL OR " : "") . "$name IN (" . implode(", ", array_map('intval', $val)) . ")"; $conds[] = (in_array(0, $val) ? "$name IS NULL OR " : "") . "$name IN (" . implode(", ", array_map('intval', $val)) . ")";
} else { } else {
$text_type = preg_match('~char|text|enum|set~', $field["type"]); $text_type = preg_match('~char|text|enum|set~', $field["type"]);
$value = $this->processInput($field, (!$op && $text_type && preg_match('~^[^%]+$~', $val) ? "%$val%" : $val)); $value = $adminer->processInput($field, (!$op && $text_type && preg_match('~^[^%]+$~', $val) ? "%$val%" : $val));
$conds[] = $driver->convertSearch($name, $where, $field) . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value" $conds[] = $driver->convertSearch($name, $where, $field) . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value"
: (in_array($op, $this->operators) || $op == "=" ? " $op $value" : (in_array($op, $this->operators) || $op == "=" ? " $op $value"
: ($text_type ? " LIKE $value" : ($text_type ? " LIKE $value"
@@ -420,6 +422,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
} }
function selectEmailProcess($where, $foreignKeys) { function selectEmailProcess($where, $foreignKeys) {
global $adminer;
if ($_POST["email_append"]) { if ($_POST["email_append"]) {
return true; return true;
} }
@@ -437,10 +440,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
. ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('Adminer\where_check', (array) $_POST["check"])) . "))") . ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('Adminer\where_check', (array) $_POST["check"])) . "))")
); );
$fields = fields($_GET["select"]); $fields = fields($_GET["select"]);
foreach ($this->rowDescriptions($rows, $foreignKeys) as $row) { foreach ($adminer->rowDescriptions($rows, $foreignKeys) as $row) {
$replace = array('{\\' => '{'); // allow literal {$name} $replace = array('{\\' => '{'); // allow literal {$name}
foreach ($matches[1] as $val) { foreach ($matches[1] as $val) {
$replace['{$' . "$val}"] = $this->editVal($row[$val], $fields[$val]); $replace['{$' . "$val}"] = $adminer->editVal($row[$val], $fields[$val]);
} }
$email = $row[$_POST["email_field"]]; $email = $row[$_POST["email_field"]];
if (is_mail($email) && send_mail($email, strtr($subject, $replace), strtr($message, $replace), $_POST["email_from"], $_FILES["email_files"])) { if (is_mail($email) && send_mail($email, strtr($subject, $replace), strtr($message, $replace), $_POST["email_from"], $_FILES["email_files"])) {
@@ -589,8 +592,8 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
} }
function navigation($missing) { function navigation($missing) {
global $VERSION; global $VERSION, $adminer;
echo "<h1>" . $this->name() . " <span class='version'>$VERSION"; echo "<h1>" . $adminer->name() . " <span class='version'>$VERSION";
$new_version = $_COOKIE["adminer_version"]; $new_version = $_COOKIE["adminer_version"];
echo " <a href='https://www.adminer.org/editor/#download'" . target_blank() . " id='version'>" . (version_compare($VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>"; echo " <a href='https://www.adminer.org/editor/#download'" . target_blank() . " id='version'>" . (version_compare($VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>";
echo "</span></h1>\n"; echo "</span></h1>\n";
@@ -610,13 +613,13 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
} }
} }
} else { } else {
$this->databasesPrint($missing); $adminer->databasesPrint($missing);
if ($missing != "db" && $missing != "ns") { if ($missing != "db" && $missing != "ns") {
$table_status = table_status('', true); $table_status = table_status('', true);
if (!$table_status) { if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "\n"; echo "<p class='message'>" . lang('No tables.') . "\n";
} else { } else {
$this->tablesPrint($table_status); $adminer->tablesPrint($table_status);
} }
} }
} }
@@ -629,11 +632,12 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
} }
function tablesPrint($tables) { function tablesPrint($tables) {
global $adminer;
echo "<ul id='tables'>"; echo "<ul id='tables'>";
echo script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});"); echo script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
foreach ($tables as $row) { foreach ($tables as $row) {
echo '<li>'; echo '<li>';
$name = $this->tableName($row); $name = $adminer->tableName($row);
if ($name != "") { // ignore tables without name if ($name != "") { // ignore tables without name
echo "<a href='" . h(ME) . 'select=' . urlencode($row["Name"]) . "'" echo "<a href='" . h(ME) . 'select=' . urlencode($row["Name"]) . "'"
. bold($_GET["select"] == $row["Name"] || $_GET["edit"] == $row["Name"], "select") . bold($_GET["select"] == $row["Name"] || $_GET["edit"] == $row["Name"], "select")
@@ -645,9 +649,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
} }
function _foreignColumn($foreignKeys, $column) { function _foreignColumn($foreignKeys, $column) {
global $adminer;
foreach ((array) $foreignKeys[$column] as $foreignKey) { foreach ((array) $foreignKeys[$column] as $foreignKey) {
if (count($foreignKey["source"]) == 1) { if (count($foreignKey["source"]) == 1) {
$name = $this->rowDescription($foreignKey["table"]); $name = $adminer->rowDescription($foreignKey["table"]);
if ($name != "") { if ($name != "") {
$id = idf_escape($foreignKey["target"][0]); $id = idf_escape($foreignKey["target"][0]);
return array($foreignKey["table"], $id, $name); return array($foreignKey["table"], $id, $name);