diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 3fc2c0a8..7df9d79a 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -38,7 +38,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { ksort($row["fields"]); $orig_field = reset($orig_fields); $after = " FIRST"; - + foreach ($row["fields"] as $key => $field) { $foreign_key = $foreign_keys[$field["type"]]; $type_field = ($foreign_key !== null ? $referencable_primary[$foreign_key] : $field); //! can collide with user defined type @@ -58,7 +58,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { } } if ($foreign_key !== null) { - $foreign[idf_escape($field["field"])] = ($TABLE != "" && $jush != "sqlite" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (ereg("^($on_actions)\$", $field["on_delete"]) ? " ON DELETE $field[on_delete]" : ""); + $foreign[idf_escape($field["field"])] = ($TABLE != "" && $jush != "sqlite" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (preg_match("~^($on_actions)\$~", $field["on_delete"]) ? " ON DELETE $field[on_delete]" : ""); } $after = " AFTER " . idf_escape($field["field"]); } elseif ($field["orig"] != "") { @@ -72,7 +72,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { } } } - + $partitioning = ""; if ($partition_by[$row["partition_by"]]) { $partitions = array(); @@ -86,17 +86,17 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { ? " (" . implode(",", $partitions) . "\n)" : ($row["partitions"] ? " PARTITIONS " . (+$row["partitions"]) : "") ); - } elseif (support("partitioning") && ereg("partitioned", $table_status["Create_options"])) { + } elseif (support("partitioning") && preg_match("~partitioned~", $table_status["Create_options"])) { $partitioning .= "\nREMOVE PARTITIONING"; } - + $message = lang('Table has been altered.'); if ($TABLE == "") { cookie("adminer_engine", $row["Engine"]); $message = lang('Table has been created.'); } $name = trim($row["name"]); - + queries_redirect(ME . (support("table") ? "table=" : "select=") . urlencode($name), $message, alter_table( $TABLE, $name, @@ -119,7 +119,7 @@ if (!$_POST) { "fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))), "partition_names" => array(""), ); - + if ($TABLE != "") { $row = $table_status; $row["name"] = $TABLE; @@ -131,7 +131,7 @@ if (!$_POST) { $field["has_default"] = isset($field["default"]); $row["fields"][] = $field; } - + if (support("partitioning")) { $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($TABLE); $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1"); @@ -161,7 +161,7 @@ foreach ($engines as $engine) { : " autocapitalize="off"> " . optionlist(array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) . "" : ""); ?> - "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?> + "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?> @@ -196,7 +196,7 @@ edit_fields($row["fields"], $collations, "TABLE", $foreign_keys, $comments); >

diff --git a/adminer/database.inc.php b/adminer/database.inc.php index c77a67d0..b0f5db6c 100644 --- a/adminer/database.inc.php +++ b/adminer/database.inc.php @@ -31,7 +31,7 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c if (!$row["collation"]) { redirect(substr(ME, 0, -1)); } - query_redirect("ALTER DATABASE " . idf_escape($name) . (eregi('^[a-z0-9_]+$', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.')); + query_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.')); } } diff --git a/adminer/db.inc.php b/adminer/db.inc.php index c81a8c93..4fae3bad 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -7,7 +7,7 @@ if ($tables_views && !$error && !$_POST["search"]) { if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"] || $_POST["copy"])) { queries("SET foreign_key_checks = 0"); // allows to truncate or drop several tables at once } - + if ($_POST["truncate"]) { if ($_POST["tables"]) { $result = truncate_tables($_POST["tables"]); @@ -40,7 +40,7 @@ if ($tables_views && !$error && !$_POST["search"]) { $message .= "" . h($row["Table"]) . ": " . h($row["Msg_text"]) . "
"; } } - + queries_redirect(substr(ME, 0, -1), $message, $result); } @@ -63,7 +63,7 @@ if ($adminer->homepage()) { } } echo "\n"; - + echo '\n"; - + $tables = 0; foreach ($tables_list as $name => $type) { - $view = ($type !== null && !eregi("table", $type)); + $view = ($type !== null && !preg_match('~table~i', $type)); echo '
'; echo '' . lang('Table'); echo '' . lang('Engine'); @@ -75,10 +75,10 @@ if ($adminer->homepage()) { echo '' . lang('Rows'); echo (support("comment") ? '' . lang('Comment') : ''); echo "
' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');"); echo '' . (support("table") ? '' . h($name) . '' : h($name)); if ($view) { @@ -104,14 +104,14 @@ if ($adminer->homepage()) { } echo (support("comment") ? " " : ""); } - + echo "
 " . lang('%d in total', count($tables_list)); echo "" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : ""); echo "" . nbsp(db_collation(DB, collations())); foreach (array("Data_length", "Index_length", "Data_free") as $key) { echo " "; } - + echo "
\n"; if (!information_schema(DB)) { $vacuum = " "; @@ -141,10 +141,10 @@ if ($adminer->homepage()) { echo "\n"; echo "\n"; } - + echo '

" . lang('Routines') . "

\n"; $routines = routines(); @@ -166,7 +166,7 @@ if ($adminer->homepage()) { . '' . lang('Create function') . "\n" ; } - + if (support("sequence")) { echo "

" . lang('Sequences') . "

\n"; $sequences = get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema()"); @@ -181,7 +181,7 @@ if ($adminer->homepage()) { } echo "

" . lang('User types') . "

\n"; $user_types = types(); @@ -196,7 +196,7 @@ if ($adminer->homepage()) { } echo "

" . lang('Events') . "

\n"; $rows = get_rows("SHOW EVENTS"); @@ -218,7 +218,7 @@ if ($adminer->homepage()) { } echo '

" . lang('You have no privileges to update this table.') . "\n"; } else { echo "\n"; - + foreach ($fields as $name => $field) { echo "
" . $adminer->fieldName($field); $default = $_GET["set"][bracket_escape($name)]; if ($default === null) { $default = $field["default"]; - if ($field["type"] == "bit" && ereg("^b'([01]*)'\$", $default, $regs)) { + if ($field["type"] == "bit" && preg_match("~^b'([01]*)'\$~", $default, $regs)) { $default = $regs[1]; } } $value = ($row !== null - ? ($row[$name] != "" && $jush == "sql" && ereg("enum|set", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name]) + ? ($row[$name] != "" && $jush == "sql" && preg_match("~enum|set~", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name]) : (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $default)) ); if (!$_POST["save"] && is_string($value)) { $value = $adminer->editVal($value, $field); } $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : ($value !== null ? '' : 'NULL')))); - if (ereg("time", $field["type"]) && $value == "CURRENT_TIMESTAMP") { + if (preg_match("~time~", $field["type"]) && $value == "CURRENT_TIMESTAMP") { $value = ""; $function = "now"; } input($field, $value, $function); echo "\n"; } - + if (!support("table")) { echo "
 "; } - + echo "
\n"; } ?> diff --git a/adminer/foreign.inc.php b/adminer/foreign.inc.php index 66cea6c1..307e288e 100644 --- a/adminer/foreign.inc.php +++ b/adminer/foreign.inc.php @@ -13,12 +13,12 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change- foreach ($source as $key => $val) { $target[$key] = $row["target"][$key]; } - + query_redirect("ALTER TABLE " . table($TABLE) . ($name != "" ? "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name) . "," : "") . "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . table($row["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")" //! reuse $name - check in older MySQL versions - . (ereg("^($on_actions)\$", $row["on_delete"]) ? " ON DELETE $row[on_delete]" : "") - . (ereg("^($on_actions)\$", $row["on_update"]) ? " ON UPDATE $row[on_update]" : "") + . (preg_match("~^($on_actions)\$~", $row["on_delete"]) ? " ON DELETE $row[on_delete]" : "") + . (preg_match("~^($on_actions)\$~", $row["on_update"]) ? " ON UPDATE $row[on_update]" : "") , ME . "table=" . urlencode($TABLE), ($name != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.'))); $error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "
$error"; //! no partitioning } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 5b93d9b9..dcb98aa8 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -207,8 +207,8 @@ username.form['auth[driver]'].onchange(); * @return string */ function selectVal($val, $link, $field) { - $return = ($val === null ? "NULL" : (ereg("char|binary", $field["type"]) && !ereg("var", $field["type"]) ? "$val" : $val)); - if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) { + $return = ($val === null ? "NULL" : (preg_match("~char|binary~", $field["type"]) && !preg_match("~var~", $field["type"]) ? "$val" : $val)); + if (preg_match('~blob|bytea|raw|file~', $field["type"]) && !is_utf8($val)) { $return = lang('%d byte(s)', strlen(html_entity_decode($val, ENT_QUOTES))); } return ($link ? "$return" : $return); @@ -401,14 +401,14 @@ username.form['auth[driver]'].onchange(); foreach ((array) $_GET["where"] as $val) { if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) { $cond = " $val[op]"; - if (ereg('IN$', $val["op"])) { + if (preg_match('~IN$~', $val["op"])) { $in = process_length($val["val"]); $cond .= " (" . ($in != "" ? $in : "NULL") . ")"; } elseif ($val["op"] == "SQL") { $cond = " $val[val]"; // SQL injection } elseif ($val["op"] == "LIKE %%") { $cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%"); - } elseif (!ereg('NULL$', $val["op"])) { + } elseif (!preg_match('~NULL$~', $val["op"])) { $cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]); } if ($val["col"] != "") { @@ -417,12 +417,12 @@ username.form['auth[driver]'].onchange(); // find anywhere $cols = array(); foreach ($fields as $name => $field) { - $is_text = ereg('char|text|enum|set', $field["type"]); - if ((is_numeric($val["val"]) || !ereg('(^|[^o])int|float|double|decimal|bit', $field["type"])) - && (!ereg("[\x80-\xFF]", $val["val"]) || $is_text) + $is_text = preg_match('~char|text|enum|set~', $field["type"]); + if ((is_numeric($val["val"]) || !preg_match('~(^|[^o])int|float|double|decimal|bit~', $field["type"])) + && (!preg_match("~[\x80-\xFF]~", $val["val"]) || $is_text) ) { $name = idf_escape($name); - $cols[] = ($jush == "sql" && $is_text && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name); + $cols[] = ($jush == "sql" && $is_text && !preg_match('~^utf8~', $field["collation"]) ? "CONVERT($name USING utf8)" : $name); } } $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0"); @@ -495,7 +495,7 @@ username.form['auth[driver]'].onchange(); $history = &get_session("queries"); $id = "sql-" . count($history[$_GET["db"]]); if (strlen($query) > 1e6) { - $query = ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment + $query = preg_replace('~[\x80-\xFF]+$~', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment } $history[$_GET["db"]][] = array($query, time()); // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"] return " " . @date("H:i:s") . " " . lang('SQL command') . "

'; // @ - time zone may be not set @@ -511,11 +511,11 @@ username.form['auth[driver]'].onchange(); foreach ($edit_functions as $key => $functions) { if (!$key || (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET)))) { // relative functions foreach ($functions as $pattern => $val) { - if (!$pattern || ereg($pattern, $field["type"])) { + if (!$pattern || preg_match("~$pattern~", $field["type"])) { $return .= "/$val"; } } - if ($key && !ereg('set|blob|bytea|raw|file', $field["type"])) { + if ($key && !preg_match('~set|blob|bytea|raw|file~', $field["type"])) { $return .= "/SQL"; } } @@ -552,17 +552,17 @@ username.form['auth[driver]'].onchange(); } $name = $field["field"]; $return = q($value); - if (ereg('^(now|getdate|uuid)$', $function)) { + if (preg_match('~^(now|getdate|uuid)$~', $function)) { $return = "$function()"; - } elseif (ereg('^current_(date|timestamp)$', $function)) { + } elseif (preg_match('~^current_(date|timestamp)$~', $function)) { $return = $function; - } elseif (ereg('^([+-]|\\|\\|)$', $function)) { + } elseif (preg_match('~^([+-]|\\|\\|)$~', $function)) { $return = idf_escape($name) . " $function $return"; - } elseif (ereg('^[+-] interval$', $function)) { + } elseif (preg_match('~^[+-] interval$~', $function)) { $return = idf_escape($name) . " $function " . (preg_match("~^(\\d+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return); - } elseif (ereg('^(addtime|subtime|concat)$', $function)) { + } elseif (preg_match('~^(addtime|subtime|concat)$~', $function)) { $return = "$function(" . idf_escape($name) . ", $return)"; - } elseif (ereg('^(md5|sha1|password|encrypt)$', $function)) { + } elseif (preg_match('~^(md5|sha1|password|encrypt)$~', $function)) { $return = "$function($return)"; } return unconvert_field($field, $return); @@ -674,7 +674,7 @@ username.form['auth[driver]'].onchange(); foreach ($row as $key => $val) { $field = $fields[$key]; $row[$key] = ($val !== null - ? unconvert_field($field, ereg('(^|[^o])int|float|double|decimal', $field["type"]) && $val != '' ? $val : q($val)) + ? unconvert_field($field, preg_match('~(^|[^o])int|float|double|decimal~', $field["type"]) && $val != '' ? $val : q($val)) : "NULL" ); } @@ -713,7 +713,7 @@ username.form['auth[driver]'].onchange(); */ function dumpHeaders($identifier, $multi_table = false) { $output = $_POST["output"]; - $ext = (ereg('sql', $_POST["format"]) ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR + $ext = (preg_match('~sql~', $_POST["format"]) ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR header("Content-Type: " . ($output == "gz" ? "application/x-gzip" : ($ext == "tar" ? "application/x-tar" : diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index 2aad2271..9163d437 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -4,7 +4,7 @@ error_reporting(6135); // errors and warnings include "../adminer/include/coverage.inc.php"; // disable filter.default -$filter = !ereg('^(unsafe_raw)?$', ini_get("filter.default")); +$filter = !preg_match('~^(unsafe_raw)?$~', ini_get("filter.default")); if ($filter || ini_get("filter.default_flags")) { foreach (array('_GET', '_POST', '_COOKIE', '_SERVER') as $val) { $unsafe = filter_input_array(constant("INPUT$val"), FILTER_UNSAFE_RAW); diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 78c0d4d3..efe90c69 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -140,11 +140,11 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) { global $structured_types, $types, $unsigned, $on_actions; ?> -" size="3" onfocus="editingLengthFocus(this);" onchange="editingLengthChange(this);" onkeyup="this.onchange();">