function messageQuery($query) { //! doesn't work with sql.inc.php $connection = connection(); $result = $connection->query('SHOW MASTER STATUS'); if ($result) { restart_session(); $_SESSION["master"] = $result->fetch_assoc(); } }
function prepareForm() { global $REPDATA; $newSession = true; $REPDATA = new_repdata(); if (isset($_SESSION["reportID"])) { // check if session has expired... if (isset($_REQUEST["clearReport"]) || isset($_SESSION['LAST_ACTIVITY']) && time() - $_SESSION['LAST_ACTIVITY'] > 1800) { restart_session(); } else { $newSession = false; } } if ($newSession) { db_prepareNewReport(); } else { // reportId should be in session & it's valid $REPDATA["id"] = $_SESSION["reportID"]; db_checkOrphan(); // make sure this is not somehow orphaned report id db_loadReport($REPDATA["id"]); // load other stuff from db ? ... TODO } }
$id = "export-{$commands}"; $export = ", <a href='#{$id}' onclick=\"return !toggle('{$id}');\">" . lang('Export') . "</a><span id='{$id}' class='hidden'>: " . html_select("output", $adminer->dumpOutput(), $adminer_export["output"]) . " " . html_select("format", $dump_format, $adminer_export["format"]) . "<input type='hidden' name='query' value='" . h($q) . "'>" . " <input type='submit' name='export' value='" . lang('Export') . "'><input type='hidden' name='token' value='{$token}'></span>\n"; if ($connection2 && preg_match("~^({$space}|\\()*SELECT\\b~isU", $q) && ($explain = explain($connection2, $q))) { $id = "explain-{$commands}"; echo ", <a href='#{$id}' onclick=\"return !toggle('{$id}');\">EXPLAIN</a>{$export}"; echo "<div id='{$id}' class='hidden'>\n"; select($explain, $connection2, $orgtables); echo "</div>\n"; } else { echo $export; } echo "</form>\n"; } } else { if (preg_match("~^{$space}*(CREATE|DROP|ALTER){$space}+(DATABASE|SCHEMA)\\b~isU", $q)) { restart_session(); set_session("dbs", null); // clear cache stop_session(); } if (!$_POST["only_errors"]) { echo "<p class='message' title='" . h($connection->info) . "'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "{$time}\n"; } } $start = microtime(true); } while ($connection->next_result()); $line += substr_count($q . $found, "\n"); $query = substr($query, $offset); $offset = 0; } }
/** Query printed after execution in the message * @param string executed query * @param string elapsed time * @return string */ function messageQuery($query, $time) { global $jush; restart_session(); $history =& get_session("queries"); $id = "sql-" . count($history[$_GET["db"]]); if (strlen($query) > 1000000.0) { $query = preg_replace('~[\\x80-\\xFF]+$~', '', substr($query, 0, 1000000.0)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment } $history[$_GET["db"]][] = array($query, time(), $time); // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"] return " <span class='time'>" . @date("H:i:s") . "</span> <a href='#{$id}' onclick=\"return !toggle('{$id}');\">" . lang('SQL command') . "</a>" . "<div id='{$id}' class='hidden'><pre><code class='jush-{$jush}'>" . shorten_utf8($query, 1000) . '</code></pre>' . ($time ? " <span class='time'>({$time})</span>" : '') . (support("sql") ? '<p><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a>' : '') . '</div>'; }
/** Send Location header and exit * @param string null to only set a message * @param string * @return null */ function redirect($location, $message = null) { if ($message !== null) { restart_session(); $_SESSION["messages"][preg_replace('~^[^?]*~', '', $location !== null ? $location : $_SERVER["REQUEST_URI"])][] = $message; } if ($location !== null) { if ($location == "") { $location = "."; } header("Location: {$location}"); exit; } }
/** Print HTML header * @param string used in title, breadcrumb and heading, should be HTML escaped * @param string * @param mixed array("key" => "link", "key2" => array("link", "desc")), null for nothing, false for driver only, true for driver and server * @param string used after colon in title and heading, should be HTML escaped * @return null */ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") { global $LANG, $VERSION, $adminer, $drivers, $jush; page_headers(); if (is_ajax() && $error) { page_messages($error); exit; } $title_all = $title . ($title2 != "" ? ": {$title2}" : ""); $title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name()); ?> <!DOCTYPE html> <html lang="<?php echo $LANG; ?> " dir="<?php echo lang('ltr'); ?> "> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <meta name="robots" content="noindex"> <meta name="referrer" content="origin-when-crossorigin"> <title><?php echo $title_page; ?> </title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous"> <!-- Custom Fonts --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> <link rel="stylesheet" type="text/css" href="../adminer/static/default.css"> <script type="text/javascript" src="../adminer/static/functions.js"></script> <script type="text/javascript" src="static/editing.js"></script> <?php if ($adminer->head()) { ?> <link rel="shortcut icon" type="image/x-icon" href="../adminer/static/favicon.ico"> <link rel="apple-touch-icon" href="../adminer/static/favicon.ico"> <?php if (file_exists("adminer.css")) { ?> <link rel="stylesheet" type="text/css" href="adminer.cssBORRAME"> <?php } } ?> <body class="<?php echo lang('ltr'); ?> nojs" onkeydown="bodyKeydown(event);" onclick="bodyClick(event);"<?php echo isset($_COOKIE["adminer_version"]) ? "" : " onload=\"verifyVersion('{$VERSION}');\""; ?> > <script type="text/javascript"> document.body.className = document.body.className.replace(/ nojs/, ' js'); var offlineMessage = '<?php echo js_escape(lang('You are offline.')); ?> '; </script> <div id="help" class="jush-<?php echo $jush; ?> jsonly hidden" onmouseover="helpOpen = 1;" onmouseout="helpMouseout(this, event);"></div> <div id="content"> <?php if ($breadcrumb !== null) { $link = substr(preg_replace('~\\b(username|db|ns)=[^&]*&~', '', ME), 0, -1); echo '<p id="breadcrumb"><a href="' . h($link ? $link : ".") . '">' . $drivers[DRIVER] . '</a> » '; $link = substr(preg_replace('~\\b(db|ns)=[^&]*&~', '', ME), 0, -1); $server = SERVER != "" ? h(SERVER) : lang('Server'); if ($breadcrumb === false) { echo "{$server}\n"; } else { echo "<a href='" . ($link ? h($link) : ".") . "' accesskey='1' title='Alt+Shift+1'>{$server}</a> » "; if ($_GET["ns"] != "" || DB != "" && is_array($breadcrumb)) { echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> » '; } if (is_array($breadcrumb)) { if ($_GET["ns"] != "") { echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> » '; } foreach ($breadcrumb as $key => $val) { $desc = is_array($val) ? $val[1] : h($val); if ($desc != "") { echo "<a href='" . h(ME . "{$key}=") . urlencode(is_array($val) ? $val[0] : $val) . "'>{$desc}</a> » "; } } } echo "{$title}\n"; } } echo "\n\t\t<div class='well well-sm'>\n\t\t\t{$title_all}\n\t\t</div>\n"; echo "<div id='ajaxstatus' class='jsonly hidden'></div>\n"; restart_session(); page_messages($error); $databases =& get_session("dbs"); if (DB != "" && $databases && !in_array(DB, $databases, true)) { $databases = null; } stop_session(); define("PAGE_HEADER", 1); }
/** Print HTML header * @param string used in title, breadcrumb and heading, should be HTML escaped * @param string * @param mixed array("key" => "link", "key2" => array("link", "desc")), null for nothing, false for driver only, true for driver and server * @param string used after colon in title and heading, should be HTML escaped * @return null */ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") { global $LANG, $VERSION, $adminer, $drivers, $jush; page_headers(); $title_all = $title . ($title2 != "" ? ": {$title2}" : ""); $title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name()); ?> <!DOCTYPE html> <html lang="<?php echo $LANG; ?> " dir="<?php echo lang('ltr'); ?> "> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <meta name="robots" content="noindex"> <title><?php echo $title_page; ?> </title> <link rel="stylesheet" type="text/css" href="../adminer/static/default.css"> <script type="text/javascript" src="../adminer/static/functions.js"></script> <script type="text/javascript" src="static/editing.js"></script> <?php if ($adminer->head()) { ?> <link rel="shortcut icon" type="image/x-icon" href="../adminer/static/favicon.ico"> <link rel="apple-touch-icon" href="../adminer/static/favicon.ico"> <?php if (file_exists("adminer.css")) { ?> <link rel="stylesheet" type="text/css" href="adminer.css"> <?php } } ?> <body class="<?php echo lang('ltr'); ?> nojs" onkeydown="bodyKeydown(event);" onclick="bodyClick(event);"> <script type="text/javascript"> document.body.className = document.body.className.replace(/ nojs/, ' js'); </script> <div id="help" class="jush-<?php echo $jush; ?> jsonly hidden" onmouseover="helpOpen = 1;" onmouseout="helpMouseout(this, event);"></div> <div id="content"> <?php if ($breadcrumb !== null) { $link = substr(preg_replace('~\\b(username|db|ns)=[^&]*&~', '', ME), 0, -1); echo '<p id="breadcrumb"><a href="' . h($link ? $link : ".") . '">' . $drivers[DRIVER] . '</a> » '; $link = substr(preg_replace('~\\b(db|ns)=[^&]*&~', '', ME), 0, -1); $server = SERVER != "" ? h(SERVER) : lang('Server'); if ($breadcrumb === false) { echo "{$server}\n"; } else { echo "<a href='" . ($link ? h($link) : ".") . "' accesskey='1' title='Alt+Shift+1'>{$server}</a> » "; if ($_GET["ns"] != "" || DB != "" && is_array($breadcrumb)) { echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> » '; } if (is_array($breadcrumb)) { if ($_GET["ns"] != "") { echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> » '; } foreach ($breadcrumb as $key => $val) { $desc = is_array($val) ? $val[1] : h($val); if ($desc != "") { echo "<a href='" . h(ME . "{$key}=") . urlencode(is_array($val) ? $val[0] : $val) . "'>{$desc}</a> » "; } } } echo "{$title}\n"; } } echo "<h2>{$title_all}</h2>\n"; restart_session(); page_messages($error); $databases =& get_session("dbs"); if (DB != "" && $databases && !in_array(DB, $databases, true)) { $databases = null; } stop_session(); define("PAGE_HEADER", 1); }
/** Print HTML header * @param string used in title, breadcrumb and heading, should be HTML escaped * @param string * @param mixed array("key" => "link=desc", "key2" => array("link", "desc")), null for nothing, false for driver only, true for driver and server * @param string used after colon in title and heading, will be HTML escaped * @return null */ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") { global $LANG, $adminer, $connection, $drivers; header("Content-Type: text/html; charset=utf-8"); if ($adminer->headers()) { header("X-XSS-Protection: 0"); // prevents introducing XSS in IE8 by removing safe parts of the page } $title_all = $title . ($title2 != "" ? ": " . h($title2) : ""); $title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name()); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="<?php echo $LANG; ?> " dir="<?php echo lang('ltr'); ?> "> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <meta name="robots" content="noindex"> <title><?php echo $title_page; ?> </title> <link rel="stylesheet" type="text/css" href="../adminer/static/default.css"> <script type="text/javascript" src="../adminer/static/functions.js"></script> <script type="text/javascript" src="static/editing.js"></script> <?php if ($adminer->head()) { ?> <link rel="shortcut icon" type="image/x-icon" href="../adminer/static/favicon.ico" id="favicon"> <?php if (file_exists("adminer.css")) { ?> <link rel="stylesheet" type="text/css" href="adminer.css"> <?php } } ?> <body class="<?php echo lang('ltr'); ?> nojs" onkeydown="bodyKeydown(event);" onclick="bodyClick(event);" onload="bodyLoad('<?php echo is_object($connection) ? substr($connection->server_info, 0, 3) : ""; ?> ');"> <script type="text/javascript"> document.body.className = document.body.className.replace(/ nojs/, ' js'); </script> <div id="content"> <?php if ($breadcrumb !== null) { $link = substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1); echo '<p id="breadcrumb"><a href="' . h($link ? $link : ".") . '">' . $drivers[DRIVER] . '</a> » '; $link = substr(preg_replace('~(db|ns)=[^&]*&~', '', ME), 0, -1); $server = SERVER != "" ? h(SERVER) : lang('Server'); if ($breadcrumb === false) { echo "{$server}\n"; } else { echo "<a href='" . ($link ? h($link) : ".") . "' accesskey='1' title='Alt+Shift+1'>{$server}</a> » "; if ($_GET["ns"] != "" || DB != "" && is_array($breadcrumb)) { echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> » '; } if (is_array($breadcrumb)) { if ($_GET["ns"] != "") { echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> » '; } foreach ($breadcrumb as $key => $val) { $desc = is_array($val) ? $val[1] : $val; if ($desc != "") { echo '<a href="' . h(ME . "{$key}=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . h($desc) . '</a> » '; } } } echo "{$title}\n"; } } echo "<h2>{$title_all}</h2>\n"; restart_session(); $uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]); $messages = $_SESSION["messages"][$uri]; if ($messages) { echo "<div class='message'>" . implode("</div>\n<div class='message'>", $messages) . "</div>\n"; unset($_SESSION["messages"][$uri]); } $databases =& get_session("dbs"); if (DB != "" && $databases && !in_array(DB, $databases, true)) { $databases = null; } stop_session(); if ($error) { echo "<div class='error'>{$error}</div>\n"; } define("PAGE_HEADER", 1); }
/** Rename database from DB * @param string new name * @param string * @return bool */ function rename_database($name, $collation) { $return = false; if (create_database($name, $collation)) { //! move triggers $rename = array(); foreach (tables_list() as $table => $type) { $rename[] = table($table) . " TO " . idf_escape($name) . "." . table($table); } $return = !$rename || queries("RENAME TABLE " . implode(", ", $rename)); if ($return) { queries("DROP DATABASE " . idf_escape(DB)); } restart_session(); set_session("dbs", null); } return $return; }
/** Query printed after execution in the message * @param string executed query * @return string */ function messageQuery($query) { global $jush; static $count = 0; restart_session(); $id = "sql-" . $count++; $history =& get_session("queries"); if (strlen($query) > 1000000.0) { // not DB - reset in drop database $query = ereg_replace('[\\x80-\\xFF]+$', '', substr($query, 0, 1000000.0)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment } $history[$_GET["db"]][] = $query; // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"] return " <a href='#{$id}' onclick=\"return !toggle('{$id}');\">" . lang('SQL command') . "</a><div id='{$id}' class='hidden'><pre><code class='jush-{$jush}'>" . shorten_utf8($query, 1000) . '</code></pre><p><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>'; }
/** Send Location header and exit * @param string null to only set a message * @param string * @return null */ function redirect($location, $message = null) { if (isset($message)) { restart_session(); $_SESSION["messages"][preg_replace('~^[^?]*~', '', isset($location) ? $location : $_SERVER["REQUEST_URI"])][] = $message; } if (isset($location)) { if ($location == "") { $location = "."; } header((is_adminer_ajax() ? "X-AJAX-Redirect" : "Location") . ": {$location}"); exit; } }