aboutsummaryrefslogtreecommitdiff
path: root/srcs/phpmyadmin/libraries/classes/Server
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-09 10:55:03 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-09 13:09:38 +0100
commit04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa (patch)
tree5c691241355c943a3c68ddb06b8cf8c60aa11319 /srcs/phpmyadmin/libraries/classes/Server
parent7e0d85db834d6351ed85d01e5126ac31dc510b86 (diff)
downloadft_server-04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa.tar.gz
ft_server-04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa.tar.bz2
ft_server-04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa.zip
phpmyadmin working
Diffstat (limited to 'srcs/phpmyadmin/libraries/classes/Server')
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/Plugin.php274
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/Plugins.php74
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/Privileges.php5649
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/Select.php128
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/Status/Data.php430
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/Status/Monitor.php546
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/UserGroups.php390
-rw-r--r--srcs/phpmyadmin/libraries/classes/Server/Users.php64
8 files changed, 7555 insertions, 0 deletions
diff --git a/srcs/phpmyadmin/libraries/classes/Server/Plugin.php b/srcs/phpmyadmin/libraries/classes/Server/Plugin.php
new file mode 100644
index 0000000..9b45297
--- /dev/null
+++ b/srcs/phpmyadmin/libraries/classes/Server/Plugin.php
@@ -0,0 +1,274 @@
+<?php
+/**
+ * Server Plugin value object
+ * @package PhpMyAdmin\Server
+ */
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Server;
+
+/**
+ * Server Plugin value object
+ * @package PhpMyAdmin\Server
+ */
+final class Plugin
+{
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @var string|null
+ */
+ private $version;
+
+ /**
+ * @var string
+ */
+ private $status;
+
+ /**
+ * @var string
+ */
+ private $type;
+
+ /**
+ * @var string|null
+ */
+ private $typeVersion;
+
+ /**
+ * @var string|null
+ */
+ private $library;
+
+ /**
+ * @var string|null
+ */
+ private $libraryVersion;
+
+ /**
+ * @var string|null
+ */
+ private $author;
+
+ /**
+ * @var string|null
+ */
+ private $description;
+
+ /**
+ * @var string
+ */
+ private $license;
+
+ /**
+ * @var string|null
+ */
+ private $loadOption;
+
+ /**
+ * @var string|null
+ */
+ private $maturity;
+
+ /**
+ * @var string|null
+ */
+ private $authVersion;
+
+ /**
+ * @param string $name Name of the plugin
+ * @param string|null $version Version from the plugin's general type descriptor
+ * @param string $status Plugin status
+ * @param string $type Type of plugin
+ * @param string|null $typeVersion Version from the plugin's type-specific descriptor
+ * @param string|null $library Plugin's shared object file name
+ * @param string|null $libraryVersion Version from the plugin's API interface
+ * @param string|null $author Author of the plugin
+ * @param string|null $description Description
+ * @param string $license Plugin's licence
+ * @param string|null $loadOption How the plugin was loaded
+ * @param string|null $maturity Plugin's maturity level
+ * @param string|null $authVersion Plugin's version as determined by the plugin author
+ */
+ private function __construct(
+ string $name,
+ ?string $version,
+ string $status,
+ string $type,
+ ?string $typeVersion,
+ ?string $library,
+ ?string $libraryVersion,
+ ?string $author,
+ ?string $description,
+ string $license,
+ ?string $loadOption,
+ ?string $maturity,
+ ?string $authVersion
+ ) {
+ $this->name = $name;
+ $this->version = $version;
+ $this->status = $status;
+ $this->type = $type;
+ $this->typeVersion = $typeVersion;
+ $this->library = $library;
+ $this->libraryVersion = $libraryVersion;
+ $this->author = $author;
+ $this->description = $description;
+ $this->license = $license;
+ $this->loadOption = $loadOption;
+ $this->maturity = $maturity;
+ $this->authVersion = $authVersion;
+ }
+
+ /**
+ * @param array $state array with the properties
+ * @return self
+ */
+ public static function fromState(array $state): self
+ {
+ return new self(
+ $state['name'] ?? '',
+ $state['version'] ?? null,
+ $state['status'] ?? '',
+ $state['type'] ?? '',
+ $state['typeVersion'] ?? null,
+ $state['library'] ?? null,
+ $state['libraryVersion'] ?? null,
+ $state['author'] ?? null,
+ $state['description'] ?? null,
+ $state['license'] ?? '',
+ $state['loadOption'] ?? null,
+ $state['maturity'] ?? null,
+ $state['authVersion'] ?? null
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function toArray(): array
+ {
+ return [
+ 'name' => $this->getName(),
+ 'version' => $this->getVersion(),
+ 'status' => $this->getStatus(),
+ 'type' => $this->getType(),
+ 'type_version' => $this->getTypeVersion(),
+ 'library' => $this->getLibrary(),
+ 'library_version' => $this->getLibraryVersion(),
+ 'author' => $this->getAuthor(),
+ 'description' => $this->getDescription(),
+ 'license' => $this->getLicense(),
+ 'load_option' => $this->getLoadOption(),
+ 'maturity' => $this->getMaturity(),
+ 'auth_version' => $this->getAuthVersion(),
+ ];
+ }
+
+ /**
+ * @return string
+ */
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getVersion(): ?string
+ {
+ return $this->version;
+ }
+
+ /**
+ * @return string
+ */
+ public function getStatus(): string
+ {
+ return $this->status;
+ }
+
+ /**
+ * @return string
+ */
+ public function getType(): string
+ {
+ return $this->type;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getTypeVersion(): ?string
+ {
+ return $this->typeVersion;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getLibrary(): ?string
+ {
+ return $this->library;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getLibraryVersion(): ?string
+ {
+ return $this->libraryVersion;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getAuthor(): ?string
+ {
+ return $this->author;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getDescription(): ?string
+ {
+ return $this->description;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLicense(): string
+ {
+ return $this->license;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getLoadOption(): ?string
+ {
+ return $this->loadOption;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getMaturity(): ?string
+ {
+ return $this->maturity;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getAuthVersion(): ?string
+ {
+ return $this->authVersion;
+ }
+}
diff --git a/srcs/phpmyadmin/libraries/classes/Server/Plugins.php b/srcs/phpmyadmin/libraries/classes/Server/Plugins.php
new file mode 100644
index 0000000..eb8e85a
--- /dev/null
+++ b/srcs/phpmyadmin/libraries/classes/Server/Plugins.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Class Plugins
+ * @package PhpMyAdmin\Server
+ */
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Server;
+
+use PhpMyAdmin\DatabaseInterface;
+
+/**
+ * Class Plugins
+ * @package PhpMyAdmin\Server
+ */
+class Plugins
+{
+ /**
+ * @var DatabaseInterface
+ */
+ private $dbi;
+
+ /**
+ * @param DatabaseInterface $dbi DatabaseInterface instance
+ */
+ public function __construct(DatabaseInterface $dbi)
+ {
+ $this->dbi = $dbi;
+ }
+
+ /**
+ * @return Plugin[]
+ */
+ public function getAll(): array
+ {
+ global $cfg;
+
+ $sql = 'SHOW PLUGINS';
+ if (! $cfg['Server']['DisableIS']) {
+ $sql = 'SELECT * FROM information_schema.PLUGINS ORDER BY PLUGIN_TYPE, PLUGIN_NAME';
+ }
+ $result = $this->dbi->query($sql);
+ $plugins = [];
+ while ($row = $this->dbi->fetchAssoc($result)) {
+ $plugins[] = $this->mapRowToPlugin($row);
+ }
+ $this->dbi->freeResult($result);
+
+ return $plugins;
+ }
+
+ /**
+ * @param array $row Row fetched from database
+ * @return Plugin
+ */
+ private function mapRowToPlugin(array $row): Plugin
+ {
+ return Plugin::fromState([
+ 'name' => $row['PLUGIN_NAME'] ?? $row['Name'],
+ 'version' => $row['PLUGIN_VERSION'] ?? null,
+ 'status' => $row['PLUGIN_STATUS'] ?? $row['Status'],
+ 'type' => $row['PLUGIN_TYPE'] ?? $row['Type'],
+ 'typeVersion' => $row['PLUGIN_TYPE_VERSION'] ?? null,
+ 'library' => $row['PLUGIN_LIBRARY'] ?? $row['Library'] ?? null,
+ 'libraryVersion' => $row['PLUGIN_LIBRARY_VERSION'] ?? null,
+ 'author' => $row['PLUGIN_AUTHOR'] ?? null,
+ 'description' => $row['PLUGIN_DESCRIPTION'] ?? null,
+ 'license' => $row['PLUGIN_LICENSE'] ?? $row['License'],
+ 'loadOption' => $row['LOAD_OPTION'] ?? null,
+ 'maturity' => $row['PLUGIN_MATURITY'] ?? null,
+ 'authVersion' => $row['PLUGIN_AUTH_VERSION'] ?? null,
+ ]);
+ }
+}
diff --git a/srcs/phpmyadmin/libraries/classes/Server/Privileges.php b/srcs/phpmyadmin/libraries/classes/Server/Privileges.php
new file mode 100644
index 0000000..1e50fbb
--- /dev/null
+++ b/srcs/phpmyadmin/libraries/classes/Server/Privileges.php
@@ -0,0 +1,5649 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * set of functions with the Privileges section in pma
+ *
+ * @package PhpMyAdmin
+ */
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Server;
+
+use PhpMyAdmin\Core;
+use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Display\ChangePassword;
+use PhpMyAdmin\Message;
+use PhpMyAdmin\Relation;
+use PhpMyAdmin\RelationCleanup;
+use PhpMyAdmin\Response;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Url;
+use PhpMyAdmin\Util;
+
+/**
+ * Privileges class
+ *
+ * @package PhpMyAdmin
+ */
+class Privileges
+{
+ /**
+ * @var Template
+ */
+ public $template;
+
+ /**
+ * @var RelationCleanup
+ */
+ private $relationCleanup;
+
+ /**
+ * @var DatabaseInterface
+ */
+ public $dbi;
+
+ /**
+ * @var Relation
+ */
+ public $relation;
+
+ /**
+ * Privileges constructor.
+ *
+ * @param Template $template Template object
+ * @param DatabaseInterface $dbi DatabaseInterface object
+ * @param Relation $relation Relation object
+ * @param RelationCleanup $relationCleanup RelationCleanup object
+ */
+ public function __construct(
+ Template $template,
+ $dbi,
+ Relation $relation,
+ RelationCleanup $relationCleanup
+ ) {
+ $this->template = $template;
+ $this->dbi = $dbi;
+ $this->relation = $relation;
+ $this->relationCleanup = $relationCleanup;
+ }
+
+ /**
+ * Get Html for User Group Dialog
+ *
+ * @param string $username username
+ * @param bool $is_menuswork Is menuswork set in configuration
+ *
+ * @return string html
+ */
+ public function getHtmlForUserGroupDialog($username, $is_menuswork)
+ {
+ $html = '';
+ if (! empty($_GET['edit_user_group_dialog']) && $is_menuswork) {
+ $dialog = $this->getHtmlToChooseUserGroup($username);
+ $response = Response::getInstance();
+ if ($response->isAjax()) {
+ $response->addJSON('message', $dialog);
+ exit;
+ } else {
+ $html .= $dialog;
+ }
+ }
+
+ return $html;
+ }
+
+ /**
+ * Escapes wildcard in a database+table specification
+ * before using it in a GRANT statement.
+ *
+ * Escaping a wildcard character in a GRANT is only accepted at the global
+ * or database level, not at table level; this is why I remove
+ * the escaping character. Internally, in mysql.tables_priv.Db there are
+ * no escaping (for example test_db) but in mysql.db you'll see test\_db
+ * for a db-specific privilege.
+ *
+ * @param string $dbname Database name
+ * @param string $tablename Table name
+ *
+ * @return string the escaped (if necessary) database.table
+ */
+ public function wildcardEscapeForGrant($dbname, $tablename)
+ {
+ if (strlen($dbname) === 0) {
+ $db_and_table = '*.*';
+ } else {
+ if (strlen($tablename) > 0) {
+ $db_and_table = Util::backquote(
+ Util::unescapeMysqlWildcards($dbname)
+ )
+ . '.' . Util::backquote($tablename);
+ } else {
+ $db_and_table = Util::backquote($dbname) . '.*';
+ }
+ }
+ return $db_and_table;
+ }
+
+ /**
+ * Generates a condition on the user name
+ *
+ * @param string $initial the user's initial
+ *
+ * @return string the generated condition
+ */
+ public function rangeOfUsers($initial = '')
+ {
+ // strtolower() is used because the User field
+ // might be BINARY, so LIKE would be case sensitive
+ if ($initial === null || $initial === '') {
+ return '';
+ }
+
+ $ret = " WHERE `User` LIKE '"
+ . $this->dbi->escapeString($initial) . "%'"
+ . " OR `User` LIKE '"
+ . $this->dbi->escapeString(mb_strtolower($initial))
+ . "%'";
+ return $ret;
+ } // end function
+
+ /**
+ * Formats privilege name for a display
+ *
+ * @param array $privilege Privilege information
+ * @param boolean $html Whether to use HTML
+ *
+ * @return string
+ */
+ public function formatPrivilege(array $privilege, $html)
+ {
+ if ($html) {
+ return '<dfn title="' . $privilege[2] . '">'
+ . $privilege[1] . '</dfn>';
+ }
+
+ return $privilege[1];
+ }
+
+ /**
+ * Parses privileges into an array, it modifies the array
+ *
+ * @param array $row Results row from
+ *
+ * @return void
+ */
+ public function fillInTablePrivileges(array &$row)
+ {
+ $row1 = $this->dbi->fetchSingleRow(
+ 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
+ 'ASSOC'
+ );
+ // note: in MySQL 5.0.3 we get "Create View', 'Show view';
+ // the View for Create is spelled with uppercase V
+ // the view for Show is spelled with lowercase v
+ // and there is a space between the words
+
+ $av_grants = explode(
+ '\',\'',
+ mb_substr(
+ $row1['Type'],
+ mb_strpos($row1['Type'], '(') + 2,
+ mb_strpos($row1['Type'], ')')
+ - mb_strpos($row1['Type'], '(') - 3
+ )
+ );
+
+ $users_grants = explode(',', $row['Table_priv']);
+
+ foreach ($av_grants as $current_grant) {
+ $row[$current_grant . '_priv']
+ = in_array($current_grant, $users_grants) ? 'Y' : 'N';
+ }
+ unset($row['Table_priv']);
+ }
+
+
+ /**
+ * Extracts the privilege information of a priv table row
+ *
+ * @param array|null $row the row
+ * @param boolean $enableHTML add <dfn> tag with tooltips
+ * @param boolean $tablePrivs whether row contains table privileges
+ *
+ * @global resource $user_link the database connection
+ *
+ * @return array
+ */
+ public function extractPrivInfo($row = null, $enableHTML = false, $tablePrivs = false)
+ {
+ if ($tablePrivs) {
+ $grants = $this->getTableGrantsArray();
+ } else {
+ $grants = $this->getGrantsArray();
+ }
+
+ if ($row !== null && isset($row['Table_priv'])) {
+ $this->fillInTablePrivileges($row);
+ }
+
+ $privs = [];
+ $allPrivileges = true;
+ foreach ($grants as $current_grant) {
+ if (($row !== null && isset($row[$current_grant[0]]))
+ || ($row === null && isset($GLOBALS[$current_grant[0]]))
+ ) {
+ if (($row !== null && $row[$current_grant[0]] == 'Y')
+ || ($row === null
+ && ($GLOBALS[$current_grant[0]] == 'Y'
+ || (is_array($GLOBALS[$current_grant[0]])
+ && count($GLOBALS[$current_grant[0]]) == $_REQUEST['column_count']
+ && empty($GLOBALS[$current_grant[0] . '_none']))))
+ ) {
+ $privs[] = $this->formatPrivilege($current_grant, $enableHTML);
+ } elseif (! empty($GLOBALS[$current_grant[0]])
+ && is_array($GLOBALS[$current_grant[0]])
+ && empty($GLOBALS[$current_grant[0] . '_none'])
+ ) {
+ // Required for proper escaping of ` (backtick) in a column name
+ $grant_cols = array_map(
+ function ($val) {
+ return Util::backquote($val);
+ },
+ $GLOBALS[$current_grant[0]]
+ );
+
+ $privs[] = $this->formatPrivilege($current_grant, $enableHTML)
+ . ' (' . implode(', ', $grant_cols) . ')';
+ } else {
+ $allPrivileges = false;
+ }
+ }
+ }
+ if (empty($privs)) {
+ if ($enableHTML) {
+ $privs[] = '<dfn title="' . __('No privileges.') . '">USAGE</dfn>';
+ } else {
+ $privs[] = 'USAGE';
+ }
+ } elseif ($allPrivileges
+ && (! isset($_POST['grant_count']) || count($privs) == $_POST['grant_count'])
+ ) {
+ if ($enableHTML) {
+ $privs = ['<dfn title="'
+ . __('Includes all privileges except GRANT.')
+ . '">ALL PRIVILEGES</dfn>',
+ ];
+ } else {
+ $privs = ['ALL PRIVILEGES'];
+ }
+ }
+ return $privs;
+ }
+
+ /**
+ * Returns an array of table grants and their descriptions
+ *
+ * @return array array of table grants
+ */
+ public function getTableGrantsArray()
+ {
+ return [
+ [
+ 'Delete',
+ 'DELETE',
+ $GLOBALS['strPrivDescDelete'],
+ ],
+ [
+ 'Create',
+ 'CREATE',
+ $GLOBALS['strPrivDescCreateTbl'],
+ ],
+ [
+ 'Drop',
+ 'DROP',
+ $GLOBALS['strPrivDescDropTbl'],
+ ],
+ [
+ 'Index',
+ 'INDEX',
+ $GLOBALS['strPrivDescIndex'],
+ ],
+ [
+ 'Alter',
+ 'ALTER',
+ $GLOBALS['strPrivDescAlter'],
+ ],
+ [
+ 'Create View',
+ 'CREATE_VIEW',
+ $GLOBALS['strPrivDescCreateView'],
+ ],
+ [
+ 'Show view',
+ 'SHOW_VIEW',
+ $GLOBALS['strPrivDescShowView'],
+ ],
+ [
+ 'Trigger',
+ 'TRIGGER',
+ $GLOBALS['strPrivDescTrigger'],
+ ],
+ ];
+ }
+
+ /**
+ * Get the grants array which contains all the privilege types
+ * and relevant grant messages
+ *
+ * @return array
+ */
+ public function getGrantsArray()
+ {
+ return [
+ [
+ 'Select_priv',
+ 'SELECT',
+ __('Allows reading data.'),
+ ],
+ [
+ 'Insert_priv',
+ 'INSERT',
+ __('Allows inserting and replacing data.'),
+ ],
+ [
+ 'Update_priv',
+ 'UPDATE',
+ __('Allows changing data.'),
+ ],
+ [
+ 'Delete_priv',
+ 'DELETE',
+ __('Allows deleting data.'),
+ ],
+ [
+ 'Create_priv',
+ 'CREATE',
+ __('Allows creating new databases and tables.'),
+ ],
+ [
+ 'Drop_priv',
+ 'DROP',
+ __('Allows dropping databases and tables.'),
+ ],
+ [
+ 'Reload_priv',
+ 'RELOAD',
+ __('Allows reloading server settings and flushing the server\'s caches.'),
+ ],
+ [
+ 'Shutdown_priv',
+ 'SHUTDOWN',
+ __('Allows shutting down the server.'),
+ ],
+ [
+ 'Process_priv',
+ 'PROCESS',
+ __('Allows viewing processes of all users.'),
+ ],
+ [
+ 'File_priv',
+ 'FILE',
+ __('Allows importing data from and exporting data into files.'),
+ ],
+ [
+ 'References_priv',
+ 'REFERENCES',
+ __('Has no effect in this MySQL version.'),
+ ],
+ [
+ 'Index_priv',
+ 'INDEX',
+ __('Allows creating and dropping indexes.'),
+ ],
+ [
+ 'Alter_priv',
+ 'ALTER',
+ __('Allows altering the structure of existing tables.'),
+ ],
+ [
+ 'Show_db_priv',
+ 'SHOW DATABASES',
+ __('Gives access to the complete list of databases.'),
+ ],
+ [
+ 'Super_priv',
+ 'SUPER',
+ __(
+ 'Allows connecting, even if maximum number of connections '
+ . 'is reached; required for most administrative operations '
+ . 'like setting global variables or killing threads of other users.'
+ ),
+ ],
+ [
+ 'Create_tmp_table_priv',
+ 'CREATE TEMPORARY TABLES',
+ __('Allows creating temporary tables.'),
+ ],
+ [
+ 'Lock_tables_priv',
+ 'LOCK TABLES',
+ __('Allows locking tables for the current thread.'),
+ ],
+ [
+ 'Repl_slave_priv',
+ 'REPLICATION SLAVE',
+ __('Needed for the replication slaves.'),
+ ],
+ [
+ 'Repl_client_priv',
+ 'REPLICATION CLIENT',
+ __('Allows the user to ask where the slaves / masters are.'),
+ ],
+ [
+ 'Create_view_priv',
+ 'CREATE VIEW',
+ __('Allows creating new views.'),
+ ],
+ [
+ 'Event_priv',
+ 'EVENT',
+ __('Allows to set up events for the event scheduler.'),
+ ],
+ [
+ 'Trigger_priv',
+ 'TRIGGER',
+ __('Allows creating and dropping triggers.'),
+ ],
+ // for table privs:
+ [
+ 'Create View_priv',
+ 'CREATE VIEW',
+ __('Allows creating new views.'),
+ ],
+ [
+ 'Show_view_priv',
+ 'SHOW VIEW',
+ __('Allows performing SHOW CREATE VIEW queries.'),
+ ],
+ // for table privs:
+ [
+ 'Show view_priv',
+ 'SHOW VIEW',
+ __('Allows performing SHOW CREATE VIEW queries.'),
+ ],
+ [
+ 'Delete_history_priv',
+ 'DELETE HISTORY',
+ $GLOBALS['strPrivDescDeleteHistoricalRows'],
+ ],
+ [
+ 'Delete versioning rows_priv',
+ 'DELETE HISTORY',
+ $GLOBALS['strPrivDescDeleteHistoricalRows'],
+ ],
+ [
+ 'Create_routine_priv',
+ 'CREATE ROUTINE',
+ __('Allows creating stored routines.'),
+ ],
+ [
+ 'Alter_routine_priv',
+ 'ALTER ROUTINE',
+ __('Allows altering and dropping stored routines.'),
+ ],
+ [
+ 'Create_user_priv',
+ 'CREATE USER',
+ __('Allows creating, dropping and renaming user accounts.'),
+ ],
+ [
+ 'Execute_priv',
+ 'EXECUTE',
+ __('Allows executing stored routines.'),
+ ],
+ ];
+ }
+
+ /**
+ * Displays on which column(s) a table-specific privilege is granted
+ *
+ * @param array $columns columns array
+ * @param array $row first row from result or boolean false
+ * @param string $name_for_select privilege types - Select_priv, Insert_priv
+ * Update_priv, References_priv
+ * @param string $priv_for_header privilege for header
+ * @param string $name privilege name: insert, select, update, references
+ * @param string $name_for_dfn name for dfn
+ * @param string $name_for_current name for current
+ *
+ * @return string html snippet
+ */
+ public function getHtmlForColumnPrivileges(
+ array $columns,
+ array $row,
+ $name_for_select,
+ $priv_for_header,
+ $name,
+ $name_for_dfn,
+ $name_for_current
+ ) {
+ return $this->template->render('server/privileges/column_privileges', [
+ 'columns' => $columns,
+ 'row' => $row,
+ 'name_for_select' => $name_for_select,
+ 'priv_for_header' => $priv_for_header,
+ 'name' => $name,
+ 'name_for_dfn' => $name_for_dfn,
+ 'name_for_current' => $name_for_current,
+ ]);
+ }
+
+ /**
+ * Get sql query for display privileges table
+ *
+ * @param string $db the database
+ * @param string $table the table
+ * @param string $username username for database connection
+ * @param string $hostname hostname for database connection
+ *
+ * @return string sql query
+ */
+ public function getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname)
+ {
+ if ($db == '*') {
+ return "SELECT * FROM `mysql`.`user`"
+ . " WHERE `User` = '" . $this->dbi->escapeString($username) . "'"
+ . " AND `Host` = '" . $this->dbi->escapeString($hostname) . "';";
+ } elseif ($table == '*') {
+ return "SELECT * FROM `mysql`.`db`"
+ . " WHERE `User` = '" . $this->dbi->escapeString($username) . "'"
+ . " AND `Host` = '" . $this->dbi->escapeString($hostname) . "'"
+ . " AND '" . $this->dbi->escapeString(Util::unescapeMysqlWildcards($db)) . "'"
+ . " LIKE `Db`;";
+ }
+ return "SELECT `Table_priv`"
+ . " FROM `mysql`.`tables_priv`"
+ . " WHERE `User` = '" . $this->dbi->escapeString($username) . "'"
+ . " AND `Host` = '" . $this->dbi->escapeString($hostname) . "'"
+ . " AND `Db` = '" . $this->dbi->escapeString(Util::unescapeMysqlWildcards($db)) . "'"
+ . " AND `Table_name` = '" . $this->dbi->escapeString($table) . "';";
+ }
+
+ /**
+ * Displays a dropdown to select the user group
+ * with menu items configured to each of them.
+ *
+ * @param string $username username
+ *
+ * @return string html to select the user group
+ */
+ public function getHtmlToChooseUserGroup($username)
+ {
+ $cfgRelation = $this->relation->getRelationsParam();
+ $groupTable = Util::backquote($cfgRelation['db'])
+ . "." . Util::backquote($cfgRelation['usergroups']);
+ $userTable = Util::backquote($cfgRelation['db'])
+ . "." . Util::backquote($cfgRelation['users']);
+
+ $userGroup = '';
+ if (isset($GLOBALS['username'])) {
+ $sql_query = "SELECT `usergroup` FROM " . $userTable
+ . " WHERE `username` = '" . $this->dbi->escapeString($username) . "'";
+ $userGroup = $this->dbi->fetchValue(
+ $sql_query,
+ 0,
+ 0,
+ DatabaseInterface::CONNECT_CONTROL
+ );
+ }
+
+ $allUserGroups = ['' => ''];
+ $sql_query = "SELECT DISTINCT `usergroup` FROM " . $groupTable;
+ $result = $this->relation->queryAsControlUser($sql_query, false);
+ if ($result) {
+ while ($row = $this->dbi->fetchRow($result)) {
+ $allUserGroups[$row[0]] = $row[0];
+ }
+ }
+ $this->dbi->freeResult($result);
+
+ return $this->template->render('server/privileges/choose_user_group', [
+ 'all_user_groups' => $allUserGroups,
+ 'user_group' => $userGroup,
+ 'params' => ['username' => $username],
+ ]);
+ }
+
+ /**
+ * Sets the user group from request values
+ *
+ * @param string $username username
+ * @param string $userGroup user group to set
+ *
+ * @return void
+ */
+ public function setUserGroup($username, $userGroup)
+ {
+ $userGroup = $userGroup === null ? '' : $userGroup;
+ $cfgRelation = $this->relation->getRelationsParam();
+ if (empty($cfgRelation['db']) || empty($cfgRelation['users']) || empty($cfgRelation['usergroups'])) {
+ return;
+ }
+
+ $userTable = Util::backquote($cfgRelation['db'])
+ . "." . Util::backquote($cfgRelation['users']);
+
+ $sql_query = "SELECT `usergroup` FROM " . $userTable
+ . " WHERE `username` = '" . $this->dbi->escapeString($username) . "'";
+ $oldUserGroup = $this->dbi->fetchValue(
+ $sql_query,
+ 0,
+ 0,
+ DatabaseInterface::CONNECT_CONTROL
+ );
+
+ if ($oldUserGroup === false) {
+ $upd_query = "INSERT INTO " . $userTable . "(`username`, `usergroup`)"
+ . " VALUES ('" . $this->dbi->escapeString($username) . "', "
+ . "'" . $this->dbi->escapeString($userGroup) . "')";
+ } else {
+ if (empty($userGroup)) {
+ $upd_query = "DELETE FROM " . $userTable
+ . " WHERE `username`='" . $this->dbi->escapeString($username) . "'";
+ } elseif ($oldUserGroup != $userGroup) {
+ $upd_query = "UPDATE " . $userTable
+ . " SET `usergroup`='" . $this->dbi->escapeString($userGroup) . "'"
+ . " WHERE `username`='" . $this->dbi->escapeString($username) . "'";
+ }
+ }
+ if (isset($upd_query)) {
+ $this->relation->queryAsControlUser($upd_query);
+ }
+ }
+
+ /**
+ * Displays the privileges form table
+ *