Fixed warnings on tables list page

This commit is contained in:
Lionel Laffineur 2023-12-03 18:16:07 +01:00
parent c4038f46ee
commit 4deb8a4085
5 changed files with 49 additions and 20 deletions

View file

@ -1,5 +1,13 @@
<?php
$tables_views = array_merge((array) $_POST["tables"], (array) $_POST["views"]);
if (isset($_POST["tables"]) && isset($_POST["views"])) {
$tables_views = array_merge((array) $_POST["tables"], (array) $_POST["views"]);
} elseif (isset($_POST["tables"])) {
$tables_views = (array)$_POST["tables"];
} elseif (isset($_POST["views"])) {
$tables_views = (array)$_POST["views"];
} else {
$tables_views = [];
}
if ($tables_views && !$error && !$_POST["search"]) {
$result = true;
@ -44,10 +52,10 @@ if ($tables_views && !$error && !$_POST["search"]) {
queries_redirect(substr(ME, 0, -1), $message, $result);
}
page_header(($_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema') . ": " . h($_GET["ns"])), $error, true);
page_header((isset($_GET["ns"]) === false || $_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema') . ": " . h($_GET["ns"])), $error, true);
if ($adminer->homepage()) {
if ($_GET["ns"] !== "") {
if (isset($_GET["ns"]) === false || $_GET["ns"] !== "") {
echo "<h3 id='tables-views'>" . lang('Tables and views') . "</h3>\n";
$tables_list = tables_list();
if (!$tables_list) {
@ -56,7 +64,7 @@ if ($adminer->homepage()) {
echo "<form action='' method='post'>\n";
if (support("table")) {
echo "<fieldset><legend>" . lang('Search data in tables') . " <span id='selected2'></span></legend><div>";
echo "<input type='search' name='query' value='" . h($_POST["query"]) . "'>";
echo "<input type='search' name='query' value='" . h((isset($_POST["query"]) && $_POST["query"] ? $_POST["query"] : "")) . "'>";
echo script("qsl('input').onkeydown = partialArg(bodyKeydown, 'search');", "");
echo " <input type='submit' name='search' value='" . lang('Search') . "'>\n";
if ($adminer->operator_regexp !== null) {
@ -64,7 +72,7 @@ if ($adminer->homepage()) {
echo doc_link(array('sql' => 'regexp.html', 'pgsql' => 'functions-matching.html#FUNCTIONS-POSIX-REGEXP')) . "</p>\n";
}
echo "</div></fieldset>\n";
if ($_POST["search"] && $_POST["query"] != "") {
if (isset($_POST["search"]) && $_POST["query"] != "") {
$_GET["where"][0]["op"] = $adminer->operator_regexp === null || empty($_POST['regexp']) ? "LIKE %%" : $adminer->operator_regexp;
search_tables();
}
@ -143,7 +151,7 @@ if ($adminer->homepage()) {
echo "<p>" . lang('Move to other database') . ": ";
echo ($databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '" autocapitalize="off">');
echo " <input type='submit' name='move' value='" . lang('Move') . "'>";
echo (support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'> " . checkbox("overwrite", 1, $_POST["overwrite"], lang('overwrite')) : "");
echo (support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'> " . checkbox("overwrite", 1, isset($_POST["overwrite"]), lang('overwrite')) : "");
echo "\n";
}
echo "<input type='hidden' name='all' value=''>"; // used by trCheck()

View file

@ -15,7 +15,11 @@ 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
if (strpos($server, ':') !== false) {
list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
} else {
$host = $server;
}
$ssl = $adminer->connectSsl();
if ($ssl) {
$this->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], '', '');

View file

@ -939,13 +939,13 @@ class Adminer {
*/
function homepage() {
$links = [];
if ($_GET["ns"] == "" && support("database")) {
if (isset($_GET["ns"]) && $_GET["ns"] == "" && support("database")) {
$links[] = '<a href="' . h(ME) . 'database=">' . lang('Alter database') . '</a>';
}
if (support("scheme")) {
$links[] = "<a href='" . h(ME) . "scheme='>" . ($_GET["ns"] != "" ? lang('Alter schema') : lang('Create schema')) . "</a>";
}
if ($_GET["ns"] !== "") {
if (isset($_GET["ns"]) && $_GET["ns"] !== "") {
$links[] = '<a href="' . h(ME) . 'schema=">' . lang('Database schema') . '</a>';
}
if (support("privileges")) {
@ -987,7 +987,7 @@ class Adminer {
}
} else {
$tables = array();
if ($_GET["ns"] !== "" && !$missing && DB != "") {
if (isset($_GET["ns"]) === false || $_GET["ns"] !== "" && !$missing && DB != "") {
$connection->select_db(DB);
$tables = table_status('', true);
}
@ -1024,13 +1024,13 @@ bodyLoad('<?php echo (is_object($connection) ? preg_replace('~^(\d\.?\d).*~s', '
$links[] = "<a href='" . h(ME) . "import='" . bold(isset($_GET["import"])) . ">" . lang('Import') . "</a>";
}
if (support("dump")) {
$links[] = "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Export') . "</a>";
$links[] = "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : (isset($_GET["select"]) && $_GET["select"] ? $_GET["select"] : "" )) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Export') . "</a>";
}
}
echo generate_linksbar($links);
if ($_GET["ns"] !== "" && !$missing && DB != "") {
echo generate_linksbar(['<a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . ">" . lang('Create table') . "</a>"]);
if (isset($_GET["ns"]) === false || $_GET["ns"] !== "" && !$missing && DB != "") {
echo generate_linksbar(['<a href="' . h(ME) . 'create="' . bold(isset($_GET["create"]) && $_GET["create"] === "") . ">" . lang('Create table') . "</a>"]);
if (!$tables) {
echo "<p class='message'>" . lang('No tables.') . "\n";
} else {
@ -1090,13 +1090,20 @@ bodyLoad('<?php echo (is_object($connection) ? preg_replace('~^(\d\.?\d).*~s', '
foreach ($tables as $table => $status) {
$name = $this->tableName($status);
if ($name != "") {
$array = [];
if (isset($_GET["table"])) $array[] = $_GET["table"];
if (isset($_GET["create"])) $array[] = $_GET["create"];
if (isset($_GET["indexes"])) $array[] = $_GET["indexes"];
if (isset($_GET["foreign"])) $array[] = $_GET["foreign"];
if (isset($_GET["trigger"])) $array[] = $_GET["trigger"];
if (isset($_GET["select"])) $array[] = $_GET["select"];
echo '<li><a href="' . h(ME) . 'select=' . urlencode($table) . '"'
. bold($_GET["select"] == $table || $_GET["edit"] == $table, "select")
. bold(isset($_GET["select"]) && $_GET["select"] == $table || isset($_GET["edit"]) && $_GET["edit"] == $table, "select")
. " title='" . lang('Select data') . "'>" . lang('select') . "</a> "
;
echo (support("table") || support("indexes")
? '<a href="' . h(ME) . 'table=' . urlencode($table) . '"'
. bold(in_array($table, array($_GET["table"], $_GET["create"], $_GET["indexes"], $_GET["foreign"], $_GET["trigger"], $_GET["select"])), (is_view($status) ? "view" : "structure"))
. bold(in_array($table, $array), (is_view($status) ? "view" : "structure"))
. " title='" . lang('Show structure') . "'>$name</a>"
: "<span>$name</span>"
) . "\n";

View file

@ -40,12 +40,17 @@ function add_invalid_login() {
function check_invalid_login() {
global $adminer;
$invalids = unserialize(@file_get_contents(get_temp_dir() . "/adminer.invalid")); // @ - may not exist
$filename = get_temp_dir() . "/adminer.invalid";
if (file_exists($filename)) {
$invalids = unserialize(file_get_contents(get_temp_dir() . "/adminer.invalid"));
} else {
$invalids = [];
}
$invalid = ($invalids ? $invalids[$adminer->bruteForceKey()] : array());
if ($invalid === null) {
return;
}
$next_attempt = ($invalid[1] > 29 ? $invalid[0] - time() : 0); // allow 30 invalid attempts
$next_attempt = (isset($invalid[1]) && $invalid[1] > 29 ? $invalid[0] - time() : 0); // allow 30 invalid attempts
if ($next_attempt > 0) { //! do the same with permanent login
auth_error(lang('Too many unsuccessful logins, try again in %d minute(s).', ceil($next_attempt / 60)));
}
@ -158,7 +163,12 @@ if (isset($_GET["username"]) && !class_exists("Min_DB")) {
stop_session(true);
if (isset($_GET["username"]) && is_string(get_password())) {
list($host, $port) = explode(":", SERVER, 2);
if (strpos(SERVER, ':') !== false) {
list($host, $port) = explode(":", SERVER, 2);
} else {
$host = SERVER;
$port = null;
}
if (preg_match('~^\s*([-+]?\d+)~', $port, $match) && ($match[1] < 1024 || $match[1] > 65535)) { // is_numeric('80#') would still connect to port 80
auth_error(lang('Connecting to privileged ports is not allowed.'));
}
@ -173,7 +183,7 @@ if (!is_object($connection) || ($login = $adminer->login($_GET["username"], get_
auth_error($error . (preg_match('~^ | $~', get_password()) ? '<br>' . lang('There is a space in the input password which might be the cause.') : ''));
}
if ($_POST["logout"] && $has_token && !verify_token()) {
if (isset($_POST["logout"]) && $_POST["logout"] && $has_token && !verify_token()) {
page_header(lang('Logout'), lang('Invalid CSRF token. Send the form again.'));
page_footer("db");
exit;

View file

@ -76,7 +76,7 @@ var thousandsSeparator = '<?php echo js_escape(lang(',')); ?>';
echo "$server\n";
} else {
echo "<a href='" . h($link) . "' accesskey='1' title='Alt+Shift+1'>$server</a> &raquo; ";
if ($_GET["ns"] != "" || (DB != "" && is_array($breadcrumb))) {
if ((isset($_GET["ns"]) && $_GET["ns"] != "") || (DB != "" && is_array($breadcrumb))) {
echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
}
if (is_array($breadcrumb)) {