" . lang('Editor') . ""; } //! driver, ns function credentials() { return array(SERVER, $_GET["username"], get_password()); } function connectSsl() { } function permanentLogin($create = false) { return password_file($create); } function bruteForceKey() { return $_SERVER["REMOTE_ADDR"]; } function serverName($server) { } function database() { if (connection()) { $databases = adminer()->databases(false); return (!$databases ? get_val("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1)") // username without the database list : $databases[(information_schema($databases[0]) ? 1 : 0)] // first available database ); } } function operators() { return array("<=", ">="); } function schemas() { return schemas(); } function databases($flush = true) { return get_databases($flush); } function pluginsLinks(): void { } function queryTimeout() { return 5; } function afterConnect() { } function headers() { } function csp($csp) { return $csp; } function head($dark = null) { return true; } function bodyClass(): void { echo " editor"; } function css() { $return = array(); foreach (array("", "-dark") as $mode) { $filename = "adminer$mode.css"; if (file_exists($filename)) { $file = file_get_contents($filename); $return["$filename?v=" . crc32($file)] = ($mode ? "dark" : (preg_match('~prefers-color-scheme:\s*dark~', $file) ? '' : 'light') ); } } return $return; } function loginForm() { echo "\n"; echo adminer()->loginFormField('username', '
' . lang('Username') . '', input_hidden("auth[driver]", "server") . ''); echo adminer()->loginFormField('password', '
' . lang('Password') . '', ''); echo "
\n"; echo "

\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; } function loginFormField($name, $heading, $value) { return $heading . $value . "\n"; } function login($login, $password) { return true; } function tableName($tableStatus) { return h(isset($tableStatus["Engine"]) ? ($tableStatus["Comment"] != "" ? $tableStatus["Comment"] : $tableStatus["Name"]) : "" // ignore views ); } function fieldName($field, $order = 0) { return h(preg_replace('~\s+\[.*\]$~', '', ($field["comment"] != "" ? $field["comment"] : $field["field"]))); } function selectLinks($tableStatus, $set = "") { $TABLE = $tableStatus["Name"]; if ($set !== null) { echo '

' . lang('New item') . "\n"; } } function foreignKeys($table) { return foreign_keys($table); } function backwardKeys($table, $tableName) { $return = array(); foreach ( get_rows("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = " . q(adminer()->database()) . " AND REFERENCED_TABLE_SCHEMA = " . q(adminer()->database()) . " AND REFERENCED_TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION", null, "") as $row ) { $return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"]; } foreach ($return as $key => $val) { $name = adminer()->tableName(table_status1($key, true)); if ($name != "") { $search = preg_quote($tableName); $separator = "(:|\\s*-)?\\s+"; $return[$key]["name"] = (preg_match("(^$search$separator(.+)|^(.+?)$separator$search\$)iu", $name, $match) ? $match[2] . $match[3] : $name); } else { unset($return[$key]); } } return $return; } function backwardKeysPrint($backwardKeys, $row) { foreach ($backwardKeys as $table => $backwardKey) { foreach ($backwardKey["keys"] as $cols) { $link = ME . 'select=' . urlencode($table); $i = 0; foreach ($cols as $column => $val) { $link .= where_link($i++, $column, $row[$val]); } echo "" . h($backwardKey["name"]) . ""; $link = ME . 'edit=' . urlencode($table); foreach ($cols as $column => $val) { $link .= "&set" . urlencode("[" . bracket_escape($column) . "]") . "=" . urlencode($row[$val]); } echo "+ "; } } } function selectQuery($query, $start, $failed = false) { return "\n"; } function rowDescription($table) { // first varchar column foreach (fields($table) as $field) { if (preg_match("~varchar|character varying~", $field["type"])) { return idf_escape($field["field"]); } } return ""; } function rowDescriptions($rows, $foreignKeys) { $return = $rows; foreach ($rows[0] as $key => $val) { if (list($table, $id, $name) = $this->_foreignColumn($foreignKeys, $key)) { // find all used ids $ids = array(); foreach ($rows as $row) { $ids[$row[$key]] = q($row[$key]); } // uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow $descriptions = $this->values[$table]; if (!$descriptions) { $descriptions = get_key_vals("SELECT $id, $name FROM " . table($table) . " WHERE $id IN (" . implode(", ", $ids) . ")"); } // use the descriptions foreach ($rows as $n => $row) { if (isset($row[$key])) { $return[$n][$key] = (string) $descriptions[$row[$key]]; } } } } return $return; } function selectLink($val, $field) { } function selectVal($val, $link, $field, $original) { $return = $val; $link = h($link); if (preg_match('~blob|bytea~', $field["type"]) && !is_utf8($val)) { $return = lang('%d byte(s)', strlen($original)); if (preg_match("~^(GIF|\xFF\xD8\xFF|\x89PNG\x0D\x0A\x1A\x0A)~", $original)) { // GIF|JPG|PNG, getimagetype() works with filename $return = "$return"; } } if (like_bool($field) && $return != "") { // bool $return = (preg_match('~^(1|t|true|y|yes|on)$~i', $val) ? lang('yes') : lang('no')); } if ($link) { $return = "$return"; } // Firefox doesn't support if (preg_match('~date~', $field["type"])) { $return = "

$return
"; } return $return; } function editVal($val, $field) { if (preg_match('~date|timestamp~', $field["type"]) && $val !== null) { return preg_replace('~^(\d{2}(\d+))-(0?(\d+))-(0?(\d+))~', lang('$1-$3-$5'), $val); } return $val; } function config() { return array(); } function selectColumnsPrint($select, $columns) { // can allow grouping functions by indexes } function selectSearchPrint($where, $columns, $indexes) { $where = (array) $_GET["where"]; echo '\n"; } function selectOrderPrint($order, $columns, $indexes) { //! desc $orders = array(); foreach ($indexes as $key => $index) { $order = array(); foreach ($index["columns"] as $val) { $order[] = $columns[$val]; } if (count(array_filter($order, 'strlen')) > 1 && $key != "PRIMARY") { $orders[$key] = implode(", ", $order); } } if ($orders) { echo '
' . lang('Sort') . "
"; echo ""; echo "
\n"; } if ($_GET["order"]) { echo "
" . hidden_fields(array( "order" => array(1 => reset($_GET["order"])), "desc" => ($_GET["desc"] ? array(1 => 1) : array()), )) . "
\n"; } } function selectLimitPrint($limit) { echo "
" . lang('Limit') . "
"; //
for easy styling echo html_select("limit", array("", 50, 100), $limit); echo "
\n"; } function selectLengthPrint($text_length) { } function selectActionPrint($indexes) { echo "
" . lang('Action') . "
"; echo ""; echo "
\n"; } function selectCommandPrint() { return true; } function selectImportPrint() { return true; } function selectEmailPrint($emailFields, $columns) { } function selectColumnsProcess($columns, $indexes) { return array(array(), array()); } function selectSearchProcess($fields, $indexes) { $return = array(); foreach ((array) $_GET["where"] as $key => $where) { $col = $where["col"]; $op = $where["op"]; $val = $where["val"]; if (($key >= 0 && $col != "") || $val != "") { $conds = array(); foreach (($col != "" ? array($col => $fields[$col]) : $fields) as $name => $field) { if ($col != "" || is_numeric($val) || !preg_match(number_type(), $field["type"])) { $name = idf_escape($name); if ($col != "" && $field["type"] == "enum") { $conds[] = (in_array(0, $val) ? "$name IS NULL OR " : "") . "$name IN (" . implode(", ", array_map('Adminer\q', $val)) . ")"; } else { $text_type = preg_match('~char|text|enum|set~', $field["type"]); $value = adminer()->processInput($field, (!$op && $text_type && preg_match('~^[^%]+$~', $val) ? "%$val%" : $val)); $conds[] = driver()->convertSearch($name, $where, $field) . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value" : (in_array($op, adminer()->operators()) || $op == "=" ? " $op $value" : ($text_type ? " LIKE $value" : " IN (" . ($value[0] == "'" ? str_replace(",", "', '", $value) : $value) . ")" ))); if ($key < 0 && $val == "0") { $conds[] = "$name IS NULL"; } } } } $return[] = ($conds ? "(" . implode(" OR ", $conds) . ")" : "1 = 0"); } } return $return; } function selectOrderProcess($fields, $indexes) { $index_order = $_GET["index_order"]; if ($index_order != "") { unset($_GET["order"][1]); } if ($_GET["order"]) { return array(idf_escape(reset($_GET["order"])) . ($_GET["desc"] ? " DESC" : "")); } foreach (($index_order != "" ? array($indexes[$index_order]) : $indexes) as $index) { if ($index_order != "" || $index["type"] == "INDEX") { $has_desc = array_filter($index["descs"]); $desc = false; foreach ($index["columns"] as $val) { if (preg_match('~date|timestamp~', $fields[$val]["type"])) { $desc = true; break; } } $return = array(); foreach ($index["columns"] as $key => $val) { $return[] = idf_escape($val) . (($has_desc ? $index["descs"][$key] : $desc) ? " DESC" : ""); } return $return; } } return array(); } function selectLimitProcess() { return (isset($_GET["limit"]) ? intval($_GET["limit"]) : 50); } function selectLengthProcess() { return "100"; } function selectEmailProcess($where, $foreignKeys) { return false; } function selectQueryBuild($select, $where, $group, $order, $limit, $page) { return ""; } function messageQuery($query, $time, $failed = false) { return " " . @date("H:i:s") . ""; } function editRowPrint($table, $fields, $row, $update) { } function editFunctions($field) { $return = array(); if ($field["null"] && preg_match('~blob~', $field["type"])) { $return["NULL"] = lang('empty'); } $return[""] = ($field["null"] || $field["auto_increment"] || like_bool($field) ? "" : "*"); //! respect driver if (preg_match('~date|time~', $field["type"])) { $return["now"] = lang('now'); } if (preg_match('~_(md5|sha1)$~i', $field["field"], $match)) { $return[] = strtolower($match[1]); } return $return; } function editInput($table, $field, $attrs, $value) { if ($field["type"] == "enum") { return (isset($_GET["select"]) ? " " : "") . enum_input("radio", $attrs, $field, ($value || isset($_GET["select"]) ? $value : ""), ($field["null"] ? "" : null)) ; } $options = $this->foreignKeyOptions($table, $field["field"], $value); if ($options !== null) { return (is_array($options) ? "" . optionlist($options, $value, true) . "" : "" . "" . "
" . script("qsl('input').oninput = partial(whisper, '" . ME . "script=complete&source=" . urlencode($table) . "&field=" . urlencode($field["field"]) . "&value='); qsl('div').onclick = whisperClick;", "") ); } if (like_bool($field)) { return '"; } $hint = ""; if (preg_match('~time~', $field["type"])) { $hint = lang('HH:MM:SS'); } if (preg_match('~date|timestamp~', $field["type"])) { $hint = lang('[yyyy]-mm-dd') . ($hint ? " [$hint]" : ""); } if ($hint) { return " ($hint)"; //! maxlength } if (preg_match('~_(md5|sha1)$~i', $field["field"])) { return ""; } return ''; } function editHint($table, $field, $value) { return (preg_match('~\s+(\[.*\])$~', ($field["comment"] != "" ? $field["comment"] : $field["field"]), $match) ? h(" $match[1]") : ''); } function processInput($field, $value, $function = "") { if ($function == "now") { return "$function()"; } $return = $value; if (preg_match('~date|timestamp~', $field["type"]) && preg_match('(^' . str_replace('\$1', '(?P\d*)', preg_replace('~(\\\\\\$([2-6]))~', '(?P\d{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) { $return = ($match["p1"] != "" ? $match["p1"] : ($match["p2"] != "" ? ($match["p2"] < 70 ? 20 : 19) . $match["p2"] : gmdate("Y"))) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match); } $return = q($return); if ($value == "" && like_bool($field)) { $return = "'0'"; } elseif ($value == "" && ($field["null"] || !preg_match('~char|text~', $field["type"]))) { $return = "NULL"; } elseif (preg_match('~^(md5|sha1)$~', $function)) { $return = "$function($return)"; } return unconvert_field($field, $return); } function dumpOutput() { return array(); } function dumpFormat() { return array('csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV'); } function dumpDatabase($db) { } function dumpTable($table, $style, $is_view = 0) { echo "\xef\xbb\xbf"; // UTF-8 byte order mark } function dumpData($table, $style, $query) { $result = connection()->query($query, 1); // 1 - MYSQLI_USE_RESULT if ($result) { while ($row = $result->fetch_assoc()) { if ($style == "table") { dump_csv(array_keys($row)); $style = "INSERT"; } dump_csv($row); } } } function dumpFilename($identifier) { return friendly_url($identifier); } function dumpHeaders($identifier, $multi_table = false) { $ext = "csv"; header("Content-Type: text/csv; charset=utf-8"); return $ext; } function dumpFooter() { } function importServerPath() { } function homepage() { return true; } function navigation($missing) { echo "

" . adminer()->name() . " " . VERSION; $new_version = $_COOKIE["adminer_version"]; echo " " . (version_compare(VERSION, $new_version) < 0 ? h($new_version) : "") . ""; echo "

\n"; switch_lang(); if ($missing == "auth") { $first = true; foreach ((array) $_SESSION["pwds"] as $vendor => $servers) { foreach ($servers[""] as $username => $password) { if ($password !== null) { if ($first) { echo "
    "; echo script("mixin(qs('#logins'), {onmouseover: menuOver, onmouseout: menuOut});"); $first = false; } echo "
  • " . ($username != "" ? h($username) : "" . lang('empty') . "") . "\n"; } } } } else { adminer()->databasesPrint($missing); if ($missing != "db" && $missing != "ns") { $table_status = table_status('', true); if (!$table_status) { echo "

    " . lang('No tables.') . "\n"; } else { adminer()->tablesPrint($table_status); } } } } function syntaxHighlighting($tables) { } function databasesPrint($missing) { } function tablesPrint($tables) { echo "

      "; echo script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});"); foreach ($tables as $row) { echo '
    • '; $name = adminer()->tableName($row); if ($name != "") { // ignore tables without name echo "$name\n" ; } } echo "
    \n"; } function _foreignColumn($foreignKeys, $column) { foreach ((array) $foreignKeys[$column] as $foreignKey) { if (count($foreignKey["source"]) == 1) { $name = adminer()->rowDescription($foreignKey["table"]); if ($name != "") { $id = idf_escape($foreignKey["target"][0]); return array($foreignKey["table"], $id, $name); } } } } private function foreignKeyOptions($table, $column, $value = null) { if (list($target, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) { $return = &$this->values[$target]; if ($return === null) { $table_status = table_status1($target); $return = ($table_status["Rows"] > 1000 ? "" : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($target) . " ORDER BY 2")); } if (!$return && $value !== null) { return get_val("SELECT $name FROM " . table($target) . " WHERE $id = " . q($value)); } return $return; } } }