diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index ba4d3ed76022..453c57fb7914 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -37,6 +37,11 @@ class Privileges */ private $relationCleanup; + /** + * @var DatabaseInterface $dbi + */ + public $dbi; + /** * Privileges constructor. * @@ -45,8 +50,9 @@ class Privileges public function __construct(Template $template) { $this->template = $template; - $relation = new Relation($GLOBALS['dbi']); - $this->relationCleanup = new RelationCleanup($GLOBALS['dbi'], $relation); + $this->dbi = $GLOBALS['dbi']; + $relation = new Relation($this->dbi); + $this->relationCleanup = new RelationCleanup($this->dbi, $relation); } /** @@ -122,9 +128,9 @@ public function rangeOfUsers($initial = '') } $ret = " WHERE `User` LIKE '" - . $GLOBALS['dbi']->escapeString($initial) . "%'" + . $this->dbi->escapeString($initial) . "%'" . " OR `User` LIKE '" - . $GLOBALS['dbi']->escapeString(mb_strtolower($initial)) + . $this->dbi->escapeString(mb_strtolower($initial)) . "%'"; return $ret; } // end function @@ -156,7 +162,7 @@ public function formatPrivilege(array $privilege, $html) */ public function fillInTablePrivileges(array &$row) { - $row1 = $GLOBALS['dbi']->fetchSingleRow( + $row1 = $this->dbi->fetchSingleRow( 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', 'ASSOC' ); @@ -524,21 +530,21 @@ public function getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname { if ($db == '*') { return "SELECT * FROM `mysql`.`user`" - . " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'" - . " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "';"; + . " WHERE `User` = '" . $this->dbi->escapeString($username) . "'" + . " AND `Host` = '" . $this->dbi->escapeString($hostname) . "';"; } elseif ($table == '*') { return "SELECT * FROM `mysql`.`db`" - . " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'" - . " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "'" - . " AND '" . $GLOBALS['dbi']->escapeString(Util::unescapeMysqlWildcards($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` = '" . $GLOBALS['dbi']->escapeString($username) . "'" - . " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "'" - . " AND `Db` = '" . $GLOBALS['dbi']->escapeString(Util::unescapeMysqlWildcards($db)) . "'" - . " AND `Table_name` = '" . $GLOBALS['dbi']->escapeString($table) . "';"; + . " 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) . "';"; } /** @@ -551,7 +557,7 @@ public function getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname */ public function getHtmlToChooseUserGroup($username) { - $relation = new Relation($GLOBALS['dbi']); + $relation = new Relation($this->dbi); $cfgRelation = $relation->getRelationsParam(); $groupTable = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['usergroups']); @@ -561,8 +567,8 @@ public function getHtmlToChooseUserGroup($username) $userGroup = ''; if (isset($GLOBALS['username'])) { $sql_query = "SELECT `usergroup` FROM " . $userTable - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - $userGroup = $GLOBALS['dbi']->fetchValue( + . " WHERE `username` = '" . $this->dbi->escapeString($username) . "'"; + $userGroup = $this->dbi->fetchValue( $sql_query, 0, 0, @@ -574,11 +580,11 @@ public function getHtmlToChooseUserGroup($username) $sql_query = "SELECT DISTINCT `usergroup` FROM " . $groupTable; $result = $relation->queryAsControlUser($sql_query, false); if ($result) { - while ($row = $GLOBALS['dbi']->fetchRow($result)) { + while ($row = $this->dbi->fetchRow($result)) { $allUserGroups[$row[0]] = $row[0]; } } - $GLOBALS['dbi']->freeResult($result); + $this->dbi->freeResult($result); return $this->template->render('server/privileges/choose_user_group', [ 'all_user_groups' => $allUserGroups, @@ -598,7 +604,7 @@ public function getHtmlToChooseUserGroup($username) public function setUserGroup($username, $userGroup) { $userGroup = is_null($userGroup) ? '' : $userGroup; - $relation = new Relation($GLOBALS['dbi']); + $relation = new Relation($this->dbi); $cfgRelation = $relation->getRelationsParam(); if (empty($cfgRelation['db']) || empty($cfgRelation['users']) || empty($cfgRelation['usergroups'])) { return; @@ -608,8 +614,8 @@ public function setUserGroup($username, $userGroup) . "." . Util::backquote($cfgRelation['users']); $sql_query = "SELECT `usergroup` FROM " . $userTable - . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'"; - $oldUserGroup = $GLOBALS['dbi']->fetchValue( + . " WHERE `username` = '" . $this->dbi->escapeString($username) . "'"; + $oldUserGroup = $this->dbi->fetchValue( $sql_query, 0, 0, @@ -618,16 +624,16 @@ public function setUserGroup($username, $userGroup) if ($oldUserGroup === false) { $upd_query = "INSERT INTO " . $userTable . "(`username`, `usergroup`)" - . " VALUES ('" . $GLOBALS['dbi']->escapeString($username) . "', " - . "'" . $GLOBALS['dbi']->escapeString($userGroup) . "')"; + . " VALUES ('" . $this->dbi->escapeString($username) . "', " + . "'" . $this->dbi->escapeString($userGroup) . "')"; } else { if (empty($userGroup)) { $upd_query = "DELETE FROM " . $userTable - . " WHERE `username`='" . $GLOBALS['dbi']->escapeString($username) . "'"; + . " WHERE `username`='" . $this->dbi->escapeString($username) . "'"; } elseif ($oldUserGroup != $userGroup) { $upd_query = "UPDATE " . $userTable - . " SET `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup) . "'" - . " WHERE `username`='" . $GLOBALS['dbi']->escapeString($username) . "'"; + . " SET `usergroup`='" . $this->dbi->escapeString($userGroup) . "'" + . " WHERE `username`='" . $this->dbi->escapeString($username) . "'"; } } if (isset($upd_query)) { @@ -669,18 +675,18 @@ public function getHtmlToDisplayPrivilegesTable( $username, $hostname ); - $row = $GLOBALS['dbi']->fetchSingleRow($sql_query); + $row = $this->dbi->fetchSingleRow($sql_query); } if (empty($row)) { - if ($table == '*' && $GLOBALS['dbi']->isSuperuser()) { + if ($table == '*' && $this->dbi->isSuperuser()) { $row = []; if ($db == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;'; } elseif ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } - $res = $GLOBALS['dbi']->query($sql_query); - while ($row1 = $GLOBALS['dbi']->fetchRow($res)) { + $res = $this->dbi->query($sql_query); + while ($row1 = $this->dbi->fetchRow($res)) { if (mb_substr($row1[0], 0, 4) == 'max_') { $row[$row1[0]] = 0; } elseif (mb_substr($row1[0], 0, 5) == 'x509_' @@ -691,7 +697,7 @@ public function getHtmlToDisplayPrivilegesTable( $row[$row1[0]] = 'N'; } } - $GLOBALS['dbi']->freeResult($res); + $this->dbi->freeResult($res); } elseif ($table == '*') { $row = []; } else { @@ -702,7 +708,7 @@ public function getHtmlToDisplayPrivilegesTable( $this->fillInTablePrivileges($row); // get columns - $res = $GLOBALS['dbi']->tryQuery( + $res = $this->dbi->tryQuery( 'SHOW COLUMNS FROM ' . Util::backquote( Util::unescapeMysqlWildcards($db) @@ -711,7 +717,7 @@ public function getHtmlToDisplayPrivilegesTable( ); $columns = []; if ($res) { - while ($row1 = $GLOBALS['dbi']->fetchRow($res)) { + while ($row1 = $this->dbi->fetchRow($res)) { $columns[$row1[0]] = [ 'Select' => false, 'Insert' => false, @@ -719,7 +725,7 @@ public function getHtmlToDisplayPrivilegesTable( 'References' => false ]; } - $GLOBALS['dbi']->freeResult($res); + $this->dbi->freeResult($res); } unset($res, $row1); } @@ -944,12 +950,12 @@ public function getHtmlForRoutineSpecificPrivileges( $sql = "SELECT `Proc_priv`" . " FROM `mysql`.`procs_priv`" - . " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'" - . " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "'" + . " WHERE `User` = '" . $this->dbi->escapeString($username) . "'" + . " AND `Host` = '" . $this->dbi->escapeString($hostname) . "'" . " AND `Db` = '" - . $GLOBALS['dbi']->escapeString(Util::unescapeMysqlWildcards($db)) . "'" - . " AND `Routine_name` LIKE '" . $GLOBALS['dbi']->escapeString($routine) . "';"; - $res = $GLOBALS['dbi']->fetchValue($sql); + . $this->dbi->escapeString(Util::unescapeMysqlWildcards($db)) . "'" + . " AND `Routine_name` LIKE '" . $this->dbi->escapeString($routine) . "';"; + $res = $this->dbi->fetchValue($sql); $privs = $this->parseProcPriv($res); @@ -1022,28 +1028,28 @@ public function getHtmlForTableSpecificPrivileges( array $columns, array $row ) { - $res = $GLOBALS['dbi']->query( + $res = $this->dbi->query( 'SELECT `Column_name`, `Column_priv`' . ' FROM `mysql`.`columns_priv`' . ' WHERE `User`' - . ' = \'' . $GLOBALS['dbi']->escapeString($username) . "'" + . ' = \'' . $this->dbi->escapeString($username) . "'" . ' AND `Host`' - . ' = \'' . $GLOBALS['dbi']->escapeString($hostname) . "'" + . ' = \'' . $this->dbi->escapeString($hostname) . "'" . ' AND `Db`' - . ' = \'' . $GLOBALS['dbi']->escapeString( + . ' = \'' . $this->dbi->escapeString( Util::unescapeMysqlWildcards($db) ) . "'" . ' AND `Table_name`' - . ' = \'' . $GLOBALS['dbi']->escapeString($table) . '\';' + . ' = \'' . $this->dbi->escapeString($table) . '\';' ); - while ($row1 = $GLOBALS['dbi']->fetchRow($res)) { + while ($row1 = $this->dbi->fetchRow($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { $columns[$row1[0]][$current] = true; } } - $GLOBALS['dbi']->freeResult($res); + $this->dbi->freeResult($res); unset($res, $row1, $current); $html_output = 'query($get_plugins_query); + $resultset = $this->dbi->query($get_plugins_query); $result = []; - while ($row = $GLOBALS['dbi']->fetchAssoc($resultset)) { + while ($row = $this->dbi->fetchAssoc($resultset)) { // if description is known, enable its translation if ('mysql_native_password' == $row['PLUGIN_NAME']) { $row['PLUGIN_DESCRIPTION'] = __('Native MySQL authentication'); @@ -1628,7 +1634,7 @@ public function getHtmlForLoginInformationFields( $html_output .= '' . "\n" . '