diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 7071eb9d..8198d7f2 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -83,8 +83,7 @@ if (!defined('Adminer\DRIVER')) { return (bool) $this->link; } - /** Set the client character set - */ + /** Set the client character set */ function set_charset(string $charset): bool { if (function_exists('mysql_set_charset')) { if (mysql_set_charset($charset, $this->link)) { @@ -126,8 +125,6 @@ if (!defined('Adminer\DRIVER')) { /** @var resource */ private $result; /** @var int */ private $offset = 0; - /** Constructor - */ function __construct(resource $result) { $this->result = $result; $this->num_rows = mysql_num_rows($result); @@ -157,8 +154,7 @@ if (!defined('Adminer\DRIVER')) { return $return; } - /** Free result set - */ + /** Free result set */ function __destruct() { mysql_free_result($this->result); } @@ -355,14 +351,12 @@ if (!defined('Adminer\DRIVER')) { - /** Escape database identifier - */ + /** Escape database identifier */ function idf_escape(string $idf): string { return "`" . str_replace("`", "``", $idf) . "`"; } - /** Get escaped table name - */ + /** Get escaped table name */ function table(string $idf): string { return idf_escape($idf); } @@ -434,8 +428,7 @@ if (!defined('Adminer\DRIVER')) { return $return; } - /** Get logged user - */ + /** Get logged user */ function logged_user(): string { return get_val("SELECT USER()"); } @@ -628,15 +621,13 @@ if (!defined('Adminer\DRIVER')) { return $return; } - /** Find out if database is information_schema - */ + /** Find out if database is information_schema */ function information_schema(string $db): bool { return ($db == "information_schema") || (min_version(5.5) && $db == "performance_schema"); } - /** Get escaped error message - */ + /** Get escaped error message */ function error(): string { global $connection; return h(preg_replace('~^You have an error.*syntax to use~U', "Syntax error", $connection->error)); @@ -680,8 +671,7 @@ if (!defined('Adminer\DRIVER')) { return $return; } - /** Generate modifier for auto increment column - */ + /** Generate modifier for auto increment column */ function auto_increment(): string { $auto_increment_index = " PRIMARY KEY"; // don't overwrite primary key by auto_increment @@ -959,8 +949,7 @@ if (!defined('Adminer\DRIVER')) { return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]); } - /** Get SQL command to create table - */ + /** Get SQL command to create table */ function create_sql(string $table, bool $auto_increment, string $style): string { $return = get_val("SHOW CREATE TABLE " . table($table), 1); if (!$auto_increment) { @@ -969,20 +958,17 @@ if (!defined('Adminer\DRIVER')) { return $return; } - /** Get SQL command to truncate table - */ + /** Get SQL command to truncate table */ function truncate_sql(string $table): string { return "TRUNCATE " . table($table); } - /** Get SQL command to change database - */ + /** Get SQL command to change database */ function use_sql(string $database): string { return "USE " . idf_escape($database); } - /** Get SQL commands to create triggers - */ + /** Get SQL commands to create triggers */ function trigger_sql(string $table): string { $return = ""; foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_\\")), null, "-- ") as $row) { @@ -1061,8 +1047,7 @@ if (!defined('Adminer\DRIVER')) { return queries("KILL " . number($val)); } - /** Return query to get connection ID - */ + /** Return query to get connection ID */ function connection_id(): string { return "SELECT CONNECTION_ID()"; } @@ -1083,8 +1068,7 @@ if (!defined('Adminer\DRIVER')) { return array(); } - /** Get values of user defined type - */ + /** Get values of user defined type */ function type_values(int $id): string { return ""; } @@ -1096,14 +1080,12 @@ if (!defined('Adminer\DRIVER')) { return array(); } - /** Get current schema - */ + /** Get current schema */ function get_schema(): string { return ""; } - /** Set current schema - */ + /** Set current schema */ function set_schema(string $schema, Db $connection2 = null): bool { return true; } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 046103ac..8d9b6a42 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -34,8 +34,7 @@ class Adminer { return password_file($create); } - /** Return key used to group brute force attacks; behind a reverse proxy, you want to return the last part of X-Forwarded-For - */ + /** Return key used to group brute force attacks; behind a reverse proxy, you want to return the last part of X-Forwarded-For */ function bruteForceKey(): string { return $_SERVER["REMOTE_ADDR"]; } @@ -47,8 +46,7 @@ class Adminer { return h($server); } - /** Identifier of selected database - */ + /** Identifier of selected database */ function database(): string { // should be used everywhere instead of DB return DB; @@ -75,8 +73,7 @@ class Adminer { return 2; } - /** Headers to send before HTML output - */ + /** Headers to send before HTML output */ function headers(): void { } @@ -112,8 +109,7 @@ class Adminer { return $return; } - /** Print login form - */ + /** Print login form */ function loginForm(): void { global $drivers; echo "\n"; @@ -245,8 +241,7 @@ class Adminer { return shorten_utf8(trim($query), 1000); } - /** Print HTML code just before the Execute button in SQL command - */ + /** Print HTML code just before the Execute button in SQL command */ function sqlPrintAfter(): void { } @@ -1029,8 +1024,7 @@ class Adminer { ); } - /** Print databases list in menu - */ + /** Print databases list in menu */ function databasesPrint(string $missing): void { global $adminer, $connection; $databases = $this->databases(); diff --git a/adminer/include/db.inc.php b/adminer/include/db.inc.php index be588c2b..656cc69c 100644 --- a/adminer/include/db.inc.php +++ b/adminer/include/db.inc.php @@ -13,8 +13,7 @@ abstract class SqlDb { /** @var string */ public $error; // last error message /** @var Result|bool */ protected $multi; // used for multiquery - /** Connect to server - */ + /** Connect to server */ abstract function connect(string $server, string $username, string $password): bool; /** Quote string to use in SQL @@ -22,8 +21,7 @@ abstract class SqlDb { */ abstract function quote(string $string): string; - /** Select database - */ + /** Select database */ abstract function select_db(string $database): bool; /** Send query @@ -45,8 +43,7 @@ abstract class SqlDb { return $this->multi; } - /** Fetch next resultset - */ + /** Fetch next resultset */ function next_result(): bool { return false; } diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index d5ce1174..9fada1bf 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -125,8 +125,7 @@ const thousandsSeparator = '" . js_escape(lang(',')) . "';") define('Adminer\PAGE_HEADER', 1); } -/** Send HTTP headers -*/ +/** Send HTTP headers */ function page_headers(): void { global $adminer; header("Content-Type: text/html; charset=utf-8"); @@ -172,8 +171,7 @@ function get_nonce(): string { return $nonce; } -/** Print flash and error messages -*/ +/** Print flash and error messages */ function page_messages(string $error): void { global $adminer; $uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]); diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index 0a04d937..392c501a 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -3,15 +3,13 @@ namespace Adminer; $drivers = array(); -/** Add a driver -*/ +/** Add a driver */ function add_driver(string $id, string $name): void { global $drivers; $drivers[$id] = $name; } -/** Get driver name -*/ +/** Get driver name */ function get_driver(string $id): string { global $drivers; return $drivers[$id]; @@ -33,8 +31,7 @@ abstract class SqlDriver { /** @var string */ public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; // regular expression for parsing enum lengths /** @var list */ public $generated = array(); // allowed types of generated columns - /** Create object for performing database operations - */ + /** Create object for performing database operations */ function __construct(Db $connection) { $this->conn = $connection; } @@ -134,8 +131,7 @@ abstract class SqlDriver { ) . $this->insertReturning($table)); } - /** Get RETURNING clause for INSERT queries (PostgreSQL specific) - */ + /** Get RETURNING clause for INSERT queries (PostgreSQL specific) */ function insertReturning(string $table): string { return ""; } @@ -186,8 +182,7 @@ abstract class SqlDriver { return $idf; } - /** Convert operator so it can be used in search - */ + /** Convert operator so it can be used in search */ function convertOperator(string $operator): string { return $operator; } @@ -202,8 +197,7 @@ abstract class SqlDriver { ); } - /** Quote binary string - */ + /** Quote binary string */ function quoteBinary(string $s): string { return q($s); } @@ -220,8 +214,7 @@ abstract class SqlDriver { function tableHelp(string $name, bool $is_view = false) { } - /** Check if C-style escapes are supported - */ + /** Check if C-style escapes are supported */ function hasCStyleEscapes(): bool { return false; } diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index d58afaf1..f30b1f3c 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -217,8 +217,7 @@ function get_partitions_info(string $table): array { return $return; } -/** Filter length value including enums -*/ +/** Filter length value including enums */ function process_length(string $length): string { global $driver; $enum_length = $driver->enumLength; @@ -491,8 +490,7 @@ function create_routine($routine, array $row): string { ; } -/** Remove current user definer from SQL command -*/ +/** Remove current user definer from SQL command */ function remove_definer(string $query): string { return preg_replace('~^([A-Z =]+) DEFINER=`' . preg_replace('~@(.*)~', '`@`(%|\1)', logged_user()) . '`~', '\1', $query); //! proper escaping of user } @@ -531,8 +529,7 @@ function tar_file(string $filename, $tmp_file): void { echo str_repeat("\0", 511 - ($tmp_file->size + 511) % 512); } -/** Get INI bytes value -*/ +/** Get INI bytes value */ function ini_bytes(string $ini): int { $val = ini_get($ini); switch (strtolower(substr($val, -1))) { @@ -584,8 +581,7 @@ function db_size(string $db): string { return format_number($return); } -/** Print SET NAMES if utf8mb4 might be needed -*/ +/** Print SET NAMES if utf8mb4 might be needed */ function set_utf8mb4(string $create): void { global $connection; static $set = false; diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 55ed3ae2..f2504ee0 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -3,8 +3,7 @@ namespace Adminer; // This file is used both in Adminer and Adminer Editor. -/** Get database connection -*/ +/** Get database connection */ function connection(): Db { // can be used in customization, $connection is minified global $connection; @@ -27,8 +26,7 @@ function driver() { return $driver; } -/** Get Adminer version -*/ +/** Get Adminer version */ function version(): string { global $VERSION; return $VERSION; @@ -45,15 +43,13 @@ function idf_unescape(string $idf): string { return str_replace($last . $last, $last, substr($idf, 1, -1)); } -/** Shortcut for $connection->quote($string) -*/ +/** Shortcut for $connection->quote($string) */ function q(string $string): string { global $connection; return $connection->quote($string); } -/** Escape string to use inside '' -*/ +/** Escape string to use inside '' */ function escape_string(string $val): string { return substr(q($val), 1, -1); } @@ -69,14 +65,12 @@ function idx(?array $array, $key, $default = null) { return ($array && array_key_exists($key, $array) ? $array[$key] : $default); } -/** Remove non-digits from a string -*/ +/** Remove non-digits from a string */ function number(string $val): string { return preg_replace('~[^0-9]+~', '', $val); } -/** Get regular expression to match numeric types -*/ +/** Get regular expression to match numeric types */ function number_type(): string { return '((? ':1', ']' => ':2', '[' => ':3', '"' => ':4'); @@ -128,21 +121,18 @@ function min_version($version, $maria_db = "", Db $connection2 = null): bool { return $version && version_compare($server_info, $version) >= 0; } -/** Get connection charset -*/ +/** Get connection charset */ function charset(Db $connection): string { return (min_version("5.5.3", 0, $connection) ? "utf8mb4" : "utf8"); // SHOW CHARSET would require an extra query } -/** Get INI boolean value -*/ +/** Get INI boolean value */ function ini_bool(string $ini): bool { $val = ini_get($ini); return (preg_match('~^(on|true|yes)$~i', $val) || (int) $val); // boolean values set by php_value are strings } -/** Check if SID is necessary -*/ +/** Check if SID is necessary */ function sid(): bool { static $return; if ($return === null) { // restart_session() defines SID @@ -151,8 +141,7 @@ function sid(): bool { return $return; } -/** Set password to session -*/ +/** Set password to session */ function set_password(string $vendor, string $server, string $username, ?string $password): void { $_SESSION["pwds"][$vendor][$server][$username] = ($_COOKIE["adminer_key"] && is_string($password) ? array(encrypt_string($password, $_COOKIE["adminer_key"])) @@ -258,8 +247,7 @@ function unique_array(array $row, array $indexes) { } } -/** Escape column key used in where() -*/ +/** Escape column key used in where() */ function escape_key(string $key): string { if (preg_match('(^([\w(]+)(' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . ')([ \w)]+)$)', $key, $match)) { //! columns looking like functions return $match[1] . idf_escape(idf_unescape($match[2])) . $match[3]; //! SQL injection @@ -369,16 +357,14 @@ function save_settings(array $settings, string $cookie = "adminer_settings"): vo cookie($cookie, http_build_query($settings + get_settings($cookie))); } -/** Restart stopped session -*/ +/** Restart stopped session */ function restart_session(): void { if (!ini_bool("session.use_cookies") && (!function_exists('session_status') || session_status() == 1)) { // 1 - PHP_SESSION_NONE, session_status() available since PHP 5.4 session_start(); } } -/** Stop session if possible -*/ +/** Stop session if possible */ function stop_session(bool $force = false): void { $use_cookies = ini_bool("session.use_cookies"); if (!$use_cookies || $force) { @@ -404,8 +390,7 @@ function set_session(string $key, $val) { $_SESSION[$key][DRIVER][SERVER][$_GET["username"]] = $val; // used also in auth.inc.php } -/** Get authenticated URL -*/ +/** Get authenticated URL */ function auth_url(string $vendor, string $server, string $username, string $db = null): string { global $drivers; $uri = remove_from_uri(implode("|", array_keys($drivers)) @@ -425,8 +410,7 @@ function auth_url(string $vendor, string $server, string $username, string $db = ; } -/** Find whether it is an AJAX request -*/ +/** Find whether it is an AJAX request */ function is_ajax(): bool { return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"); } @@ -448,8 +432,7 @@ function redirect(string $location, string $message = null): void { } } -/** Execute query and redirect if successful -*/ +/** Execute query and redirect if successful */ function query_redirect(string $query, string $location, string $message, bool $redirect = true, bool $execute = true, bool $failed = false, string $time = ""): bool { global $connection, $error, $adminer; if ($execute) { @@ -502,8 +485,7 @@ function apply_queries(string $query, array $tables, callable $escape = 'Adminer return true; } -/** Redirect by remembered queries -*/ +/** Redirect by remembered queries */ function queries_redirect(string $location, string $message, bool $redirect): bool { $queries = implode("\n", Queries::$queries); $time = format_time(Queries::$start); @@ -518,14 +500,12 @@ function format_time(float $start): string { return lang('%.3f s', max(0, microtime(true) - $start)); } -/** Get relative REQUEST_URI -*/ +/** Get relative REQUEST_URI */ function relative_uri(): string { return str_replace(":", "%3a", preg_replace('~^[^?]*/([^?]*)~', '\1', $_SERVER["REQUEST_URI"])); } -/** Remove parameter from query string -*/ +/** Remove parameter from query string */ function remove_from_uri(string $param = ""): string { return substr(preg_replace("~(?<=[?&])($param" . (SID ? "" : "|" . session_name()) . ")=[^&]*&~", '', relative_uri() . "&"), 0, -1); } @@ -569,22 +549,19 @@ function get_file(string $key, bool $decompress = false, string $delimiter = "") return $return; } -/** Determine upload error -*/ +/** Determine upload error */ function upload_error(int $error): string { $max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : 0); // post_max_size is checked in index.php return ($error ? lang('Unable to upload a file.') . ($max_size ? " " . lang('Maximum allowed file size is %sB.', $max_size) : "") : lang('File does not exist.')); } -/** Create repeat pattern for preg -*/ +/** Create repeat pattern for preg */ function repeat_pattern(string $pattern, int $length): string { // fix for Compilation failed: number too big in {} quantifier return str_repeat("$pattern{0,65535}", $length / 65535) . "$pattern{0," . ($length % 65535) . "}"; // can create {0,0} which is OK } -/** Check whether the string is in UTF-8 -*/ +/** Check whether the string is in UTF-8 */ function is_utf8(string $val): bool { // don't print control chars except \t\r\n return (preg_match('~~u', $val) && !preg_match('~[\0-\x8\xB\xC\xE-\x1F]~', $val)); @@ -607,8 +584,7 @@ function format_number($val): string { return strtr(number_format($val, 0, ".", lang(',')), preg_split('~~u', lang('0123456789'), -1, PREG_SPLIT_NO_EMPTY)); } -/** Generate friendly URL -*/ +/** Generate friendly URL */ function friendly_url(string $val): string { // used for blobs and export return preg_replace('~\W~i', '-', $val); @@ -699,8 +675,7 @@ function apply_sql_function(string $function, string $column): string { return ($function ? ($function == "unixepoch" ? "DATETIME($column, '$function')" : ($function == "count distinct" ? "COUNT(DISTINCT " : strtoupper("$function(")) . "$column)") : $column); } -/** Get path of the temporary directory -*/ +/** Get path of the temporary directory */ function get_temp_dir(): string { $return = ini_get("upload_tmp_dir"); // session_save_path() may contain other storage path if (!$return) { @@ -737,8 +712,7 @@ function file_open_lock(string $filename) { return $fp; } -/** Write and unlock a file -*/ +/** Write and unlock a file */ function file_write_unlock(resource $fp, string $data): void { rewind($fp); fwrite($fp, $data); @@ -746,8 +720,7 @@ function file_write_unlock(resource $fp, string $data): void { file_unlock($fp); } -/** Unlock and close a file -*/ +/** Unlock and close a file */ function file_unlock(resource $fp): void { flock($fp, LOCK_UN); fclose($fp); @@ -832,8 +805,7 @@ function select_value($val, string $link, array $field, int $text_length): strin return $adminer->selectVal($return, $link, $field, $val); } -/** Check whether the string is e-mail address -*/ +/** Check whether the string is e-mail address */ function is_mail(?string $email): bool { $atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name $domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component @@ -841,8 +813,7 @@ function is_mail(?string $email): bool { return is_string($email) && preg_match("(^$pattern(,\\s*$pattern)*\$)i", $email); } -/** Check whether the string is URL address -*/ +/** Check whether the string is URL address */ function is_url(string $string): bool { $domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component //! IDN return preg_match("~^(https?)://($domain?\\.)+$domain(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i", $string); //! restrict path, query and fragment characters @@ -894,23 +865,19 @@ function slow_query(string $query): array { return $return; } -/** Generate BREACH resistant CSRF token -*/ +/** Generate BREACH resistant CSRF token */ function get_token(): string { $rand = rand(1, 1e6); return ($rand ^ $_SESSION["token"]) . ":$rand"; } -/** Verify if supplied CSRF token is valid -*/ +/** Verify if supplied CSRF token is valid */ function verify_token(): bool { list($token, $rand) = explode(":", $_POST["token"]); return ($rand ^ $_SESSION["token"]) == $token; } // used in compiled version -/** -*/ function lzw_decompress(string $binary): string { // convert binary string to codes $dictionary_count = 256; diff --git a/adminer/include/html.inc.php b/adminer/include/html.inc.php index 9b7cb642..54225a03 100644 --- a/adminer/include/html.inc.php +++ b/adminer/include/html.inc.php @@ -1,20 +1,17 @@ element -*/ +/** Return $trailing"; } -/** Return \n"; } -/** Get a nonce="" attribute with CSP nonce -*/ +/** Get a nonce="" attribute with CSP nonce */ function nonce(): string { return ' nonce="' . get_nonce() . '"'; } @@ -36,20 +33,17 @@ function input_token(string $special = ""): string { return input_hidden("token", ($special ?: $token)); } -/** Get a target="_blank" attribute -*/ +/** Get a target="_blank" attribute */ function target_blank(): string { return ' target="_blank" rel="noreferrer noopener"'; } -/** Escape for HTML -*/ +/** Escape for HTML */ function h(string $string): string { return str_replace("\0", "�", htmlspecialchars($string, ENT_QUOTES, 'utf-8')); } -/** Convert \n to
-*/ +/** Convert \n to
*/ function nl_br(string $string): string { return str_replace("\n", "
", $string); // nl2br() uses XHTML before PHP 5.3 } @@ -116,14 +110,12 @@ function html_radios(string $name, array $options, string $value = ""): string { return $return; } -/** Get onclick confirmation -*/ +/** Get onclick confirmation */ function confirm(string $message = "", string $selector = "qsl('input')"): string { return script("$selector.onclick = () => confirm('" . ($message ? js_escape($message) : lang('Are you sure?')) . "');", ""); } -/** Print header for hidden fieldset (close by ) -*/ +/** Print header for hidden fieldset (close by ) */ function print_fieldset(string $id, string $legend, bool $visible = false): void { echo "
"; echo "$legend"; @@ -132,20 +124,17 @@ function print_fieldset(string $id, string $legend, bool $visible = false): void echo "