class Privileges (View source)

Privileges class

Methods

__construct(Template $template, DatabaseInterface $dbi, Relation $relation, RelationCleanup $relationCleanup, Plugins $plugins)

No description

string
wildcardEscapeForGrant(string $dbname, string $tablename)

Escapes wildcard in a database+table specification before using it in a GRANT statement.

string
escapeGrantWildcards(string $name)

Add slashes before "_" and "%" characters for using them in MySQL database, table and field names.

string
unescapeGrantWildcards(string $name)

removes slashes before "_" and "%" characters Note: This function does not unescape backslashes!

string
rangeOfUsers(string|null $initial = null)

Generates a condition on the user name

void
fillInTablePrivileges(array $row)

Parses privileges into an array, it modifies the array

array
extractPrivInfo(array|null $row = null, bool $enableHTML = false, bool $tablePrivs = false)

Extracts the privilege information of a priv table row

array
getTableGrantsArray()

Returns an array of table grants and their descriptions

array
getGrantsArray()

Get the grants array which contains all the privilege types and relevant grant messages

string
getSqlQueryForDisplayPrivTable(string $db, string $table, string $username, string $hostname)

Get sql query for display privileges table

void
setUserGroup(string $username, string $userGroup)

Sets the user group from request values

string
getHtmlToDisplayPrivilegesTable(string $db = '*', string $table = '*', bool $submit = true)

Displays the privileges form table

string
getHtmlForRoutineSpecificPrivileges(string $username, string $hostname, string $db, string $routine, string $urlDbname)

Get the HTML snippet for routine specific privileges

string
getHtmlForLoginInformationFields(string|null $user = null, string|null $host = null)

Displays the fields used by the "new user" form as well as the "change login information / copy user" form.

array
getUsernameAndHostnameLength()

Get username and hostname length

string
getCurrentAuthenticationPlugin(string $username, string $hostname)

Get current authentication plugin in use for a user

string|null
getDefaultAuthenticationPlugin()

Get the default authentication plugin

string
getGrants(string $user, string $host)

Returns all the grants for a certain user on a certain host Used in the export privileges for all users section

updatePassword(string $errorUrl, string $username, string $hostname)

Update password and get message for password updating

array
getMessageAndSqlQueryForPrivilegesRevoke(string $dbname, string $tablename, string $username, string $hostname, string $itemType)

Revokes privileges and get message and SQL query for privileges revokes

string
getRequireClause()

Get REQUIRE clause

string
getWithClauseForAddUserAndUpdatePrivs()

Get a WITH clause for 'update privileges' and 'add user'

string
getHtmlForAddUser(string $dbname)

Get HTML for addUsersForm, This function call if isset($_GET['adduser'])

array
getAllPrivileges(DatabaseName $db, TableName|null $table = null)

No description

string
getUserLink(string $linktype, string $username, string $hostname, string $dbname = '', string $tablename = '', string $routinename = '', string $initial = '')

Returns edit, revoke or export link for a user.

int
getUserGroupCount(ConfigurableMenusFeature $configurableMenusFeature)

Returns number of defined user groups

string|null
getUserGroupForUser(string $username)

Returns name of user group that user is part of

array
getExtraDataForAjaxBehavior(string $password, string $sqlQuery, string $hostname, string $username)

This function return the extra data array for the ajax behavior

array
getUserSpecificRights(string $username, string $hostname, string $type, string $dbname = '')

no db name given, so we want all privs for the given user db name was given, so we want all user specific rights for this db So this function returns user rights as an array

array
parseProcPriv(string $privs)

Parses Proc_priv data

string
getHtmlForAllTableSpecificRights(string $username, string $hostname, string $type, string $dbname = '')

Get a HTML table for display user's table specific or database specific rights

string
getUsersOverview(ResultInterface $result, array $dbRights, string $textDir)

Get HTML for display the users overview (if less than 50 users, display them immediately)

string
getHtmlForInitials()

Displays the initials if there are many privileges

array
getDbRightsForUserOverview(string|null $initial)

Get the database rights array for Display user overview

array
deleteUser(array $queries)

Delete user and get message and sql query for delete user in privileges

array
updatePrivileges(string $username, string $hostname, string $tablename, string $dbname, string $itemType)

Update the privileges and return the success or error message

string|null
getDataForChangeOrCopyUser(string $oldUsername, string $oldHostname)

Get List of information: Changes / copies a user

array
getDataForDeleteUsers(array $queries)

Update Data for information: Deletes users

Message|null
updateMessageForReload()

update Message For Reload

array
getDataForQueries(array $queries, array|null $queriesForDisplay)

update Data For Queries from queries_for_display

array
addUser(string|array|null $dbname, string $username, string $hostname, string|null $password, bool $isMenuwork)

update Data for information: Adds a user

void
setProperPasswordHashing(string $authPlugin)

Sets proper value of old_passwords according to the authentication plugin selected

array
getDataForDBInfo()

Update DB information: DB, Table, isWildcard

string
getExportUserDefinitionTextarea(string $username, string $hostname, array|null $selectedUsers)

Get title and textarea for export user definition in Privileges

string
getHtmlForUserOverview(UserPrivileges $userPrivileges, string $textDir, string|null $initial)

Get HTML snippet for display user overview page

string
getHtmlForUserProperties(bool $dbnameIsWildcard, string $urlDbname, string $username, string $hostname, string|array $dbname, string $tablename, string $route)

Get HTML snippet for display user properties

array
getTablePrivsQueriesForChangeOrCopyUser(string $userHostCondition, array $queries, string $username, string $hostname)

Get queries for Table privileges to change or copy user

array
getDbSpecificPrivsQueriesForChangeOrCopyUser(array $queries, string $username, string $hostname, string $oldUsername, string $oldHostname)

Get queries for database specific privileges for change or copy user

array
addUserAndCreateDatabase(bool $error, string $realSqlQuery, string $sqlQuery, string $username, string $hostname, string $dbname, string $alterRealSqlQuery, string $alterSqlQuery, bool $createDb1, bool $createDb2, bool $createDb3)

Prepares queries for adding users and also create database and return query and message

string
getHashedPassword(string $password)

Get the hashed string for password

array
getSqlQueriesForDisplayAndAddUser(string $username, string $hostname, string $password)

Get SQL queries for Display and Add user

string
getRoutineType(string $dbname, string $routineName)

Returns the type ('PROCEDURE' or 'FUNCTION') of the routine

string
getFormForChangePassword(string $username, string $hostname, bool $editOthers, string $route)

No description

Details

__construct(Template $template, DatabaseInterface $dbi, Relation $relation, RelationCleanup $relationCleanup, Plugins $plugins)

No description

Parameters

Template $template
DatabaseInterface $dbi
Relation $relation
RelationCleanup $relationCleanup
Plugins $plugins

string wildcardEscapeForGrant(string $dbname, string $tablename)

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.

Parameters

string $dbname

Database name

string $tablename

Table name

Return Value

string

the escaped (if necessary) database.table

string escapeGrantWildcards(string $name)

Add slashes before "_" and "%" characters for using them in MySQL database, table and field names.

Note: This function does not escape backslashes!

Parameters

string $name

the string to escape

Return Value

string

the escaped string

string unescapeGrantWildcards(string $name)

removes slashes before "_" and "%" characters Note: This function does not unescape backslashes!

Parameters

string $name

the string to escape

Return Value

string

the escaped string

string rangeOfUsers(string|null $initial = null)

Generates a condition on the user name

Parameters

string|null $initial

the user's initial

Return Value

string

the generated condition

void fillInTablePrivileges(array $row)

Parses privileges into an array, it modifies the array

Parameters

array $row

Results row from

Return Value

void

array extractPrivInfo(array|null $row = null, bool $enableHTML = false, bool $tablePrivs = false)

Extracts the privilege information of a priv table row

Parameters

array|null $row

the row

bool $enableHTML

add tag with tooltips

bool $tablePrivs

whether row contains table privileges

Return Value

array

array getTableGrantsArray()

Returns an array of table grants and their descriptions

Return Value

array

array of table grants

array getGrantsArray()

Get the grants array which contains all the privilege types and relevant grant messages

Return Value

array

string getSqlQueryForDisplayPrivTable(string $db, string $table, string $username, string $hostname)

Get sql query for display privileges table

Parameters

string $db

the database

string $table

the table

string $username

username for database connection

string $hostname

hostname for database connection

Return Value

string

sql query

void setUserGroup(string $username, string $userGroup)

Sets the user group from request values

Parameters

string $username username
string $userGroup

user group to set

Return Value

void

string getHtmlToDisplayPrivilegesTable(string $db = '*', string $table = '*', bool $submit = true)

Displays the privileges form table

Parameters

string $db

the database

string $table

the table

bool $submit

whether to display the submit button or not

Return Value

string

html snippet

string getHtmlForRoutineSpecificPrivileges(string $username, string $hostname, string $db, string $routine, string $urlDbname)

Get the HTML snippet for routine specific privileges

Parameters

string $username

username for database connection

string $hostname

hostname for database connection

string $db

the database

string $routine

the routine

string $urlDbname

url encoded db name

Return Value

string

string getHtmlForLoginInformationFields(string|null $user = null, string|null $host = null)

Displays the fields used by the "new user" form as well as the "change login information / copy user" form.

Parameters

string|null $user

User name

string|null $host

Host name

Return Value

string

a HTML snippet

array getUsernameAndHostnameLength()

Get username and hostname length

Return Value

array

username length and hostname length

string getCurrentAuthenticationPlugin(string $username, string $hostname)

Get current authentication plugin in use for a user

Parameters

string $username

User name

string $hostname

Host name

Return Value

string

authentication plugin in use

string|null getDefaultAuthenticationPlugin()

Get the default authentication plugin

Return Value

string|null

authentication plugin

string getGrants(string $user, string $host)

Returns all the grants for a certain user on a certain host Used in the export privileges for all users section

Parameters

string $user

User name

string $host

Host name

Return Value

string

containing all the grants text

Message updatePassword(string $errorUrl, string $username, string $hostname)

Update password and get message for password updating

Parameters

string $errorUrl

error url

string $username username
string $hostname hostname

Return Value

Message

success or error message after updating password

array getMessageAndSqlQueryForPrivilegesRevoke(string $dbname, string $tablename, string $username, string $hostname, string $itemType)

Revokes privileges and get message and SQL query for privileges revokes

Parameters

string $dbname

database name

string $tablename

table name

string $username username
string $hostname

host name

string $itemType

item type

Return Value

array

string getRequireClause()

Get REQUIRE clause

Return Value

string

REQUIRE clause

string getWithClauseForAddUserAndUpdatePrivs()

Get a WITH clause for 'update privileges' and 'add user'

Return Value

string

string getHtmlForAddUser(string $dbname)

Get HTML for addUsersForm, This function call if isset($_GET['adduser'])

Parameters

string $dbname

database name

Return Value

string

HTML for addUserForm

array getAllPrivileges(DatabaseName $db, TableName|null $table = null)

No description

Parameters

DatabaseName $db
TableName|null $table

Return Value

array

Returns edit, revoke or export link for a user.

Parameters

string $linktype

The link type (edit | revoke | export)

string $username

User name

string $hostname

Host name

string $dbname

Database name

string $tablename

Table name

string $routinename

Routine name

string $initial

Initial value

Return Value

string

HTML code with link

int getUserGroupCount(ConfigurableMenusFeature $configurableMenusFeature)

Returns number of defined user groups

Parameters

ConfigurableMenusFeature $configurableMenusFeature

Return Value

int

string|null getUserGroupForUser(string $username)

Returns name of user group that user is part of

Parameters

string $username

User name

Return Value

string|null

usergroup if found or null if not found

array getExtraDataForAjaxBehavior(string $password, string $sqlQuery, string $hostname, string $username)

This function return the extra data array for the ajax behavior

Parameters

string $password password
string $sqlQuery

sql query

string $hostname hostname
string $username username

Return Value

array

array getUserSpecificRights(string $username, string $hostname, string $type, string $dbname = '')

no db name given, so we want all privs for the given user db name was given, so we want all user specific rights for this db So this function returns user rights as an array

Parameters

string $username username
string $hostname

host name

string $type

database or table

string $dbname

database name

Return Value

array

database rights

array parseProcPriv(string $privs)

Parses Proc_priv data

Parameters

string $privs Proc_priv

Return Value

array

string getHtmlForAllTableSpecificRights(string $username, string $hostname, string $type, string $dbname = '')

Get a HTML table for display user's table specific or database specific rights

Parameters

string $username username
string $hostname

host name

string $type

database, table or routine

string $dbname

database name

Return Value

string

string getUsersOverview(ResultInterface $result, array $dbRights, string $textDir)

Get HTML for display the users overview (if less than 50 users, display them immediately)

Parameters

ResultInterface $result

ran sql query

array $dbRights

user's database rights array

string $textDir

text directory

Return Value

string

HTML snippet

string getHtmlForInitials()

Displays the initials if there are many privileges

Return Value

string

array getDbRightsForUserOverview(string|null $initial)

Get the database rights array for Display user overview

Parameters

string|null $initial

Return Value

array

database rights array

array deleteUser(array $queries)

Delete user and get message and sql query for delete user in privileges

Parameters

array $queries queries

Return Value

array

array updatePrivileges(string $username, string $hostname, string $tablename, string $dbname, string $itemType)

Update the privileges and return the success or error message

Parameters

string $username
string $hostname
string $tablename
string $dbname
string $itemType

Return Value

array

string|null getDataForChangeOrCopyUser(string $oldUsername, string $oldHostname)

Get List of information: Changes / copies a user

Parameters

string $oldUsername
string $oldHostname

Return Value

string|null

array getDataForDeleteUsers(array $queries)

Update Data for information: Deletes users

Parameters

array $queries

queries array

Return Value

array

Message|null updateMessageForReload()

update Message For Reload

Return Value

Message|null

array getDataForQueries(array $queries, array|null $queriesForDisplay)

update Data For Queries from queries_for_display

Parameters

array $queries

queries array

array|null $queriesForDisplay

queries array for display

Return Value

array

array addUser(string|array|null $dbname, string $username, string $hostname, string|null $password, bool $isMenuwork)

update Data for information: Adds a user

Parameters

string|array|null $dbname

db name

string $username

user name

string $hostname

host name

string|null $password password
bool $isMenuwork

is_menuwork set?

Return Value

array

void setProperPasswordHashing(string $authPlugin)

Sets proper value of old_passwords according to the authentication plugin selected

Parameters

string $authPlugin

authentication plugin selected

Return Value

void

array getDataForDBInfo()

Update DB information: DB, Table, isWildcard

Return Value

array

string getExportUserDefinitionTextarea(string $username, string $hostname, array|null $selectedUsers)

Get title and textarea for export user definition in Privileges

Parameters

string $username username
string $hostname

host name

array|null $selectedUsers

Return Value

string

string getHtmlForUserOverview(UserPrivileges $userPrivileges, string $textDir, string|null $initial)

Get HTML snippet for display user overview page

Parameters

UserPrivileges $userPrivileges
string $textDir

text directory

string|null $initial

Return Value

string

string getHtmlForUserProperties(bool $dbnameIsWildcard, string $urlDbname, string $username, string $hostname, string|array $dbname, string $tablename, string $route)

Get HTML snippet for display user properties

Parameters

bool $dbnameIsWildcard

whether database name is wildcard or not

string $urlDbname

url database name that urlencode() string

string $username username
string $hostname

host name

string|array $dbname

database name

string $tablename

table name

string $route

Return Value

string

array getTablePrivsQueriesForChangeOrCopyUser(string $userHostCondition, array $queries, string $username, string $hostname)

Get queries for Table privileges to change or copy user

Parameters

string $userHostCondition

user host condition to select relevant table privileges

array $queries

queries array

string $username username
string $hostname

host name

Return Value

array

array getDbSpecificPrivsQueriesForChangeOrCopyUser(array $queries, string $username, string $hostname, string $oldUsername, string $oldHostname)

Get queries for database specific privileges for change or copy user

Parameters

array $queries

queries array with string

string $username username
string $hostname

host name

string $oldUsername
string $oldHostname

Return Value

array

array addUserAndCreateDatabase(bool $error, string $realSqlQuery, string $sqlQuery, string $username, string $hostname, string $dbname, string $alterRealSqlQuery, string $alterSqlQuery, bool $createDb1, bool $createDb2, bool $createDb3)

Prepares queries for adding users and also create database and return query and message

Parameters

bool $error

whether user create or not

string $realSqlQuery

SQL query for add a user

string $sqlQuery

SQL query to be displayed

string $username username
string $hostname

host name

string $dbname

database name

string $alterRealSqlQuery

SQL query for ALTER USER

string $alterSqlQuery

SQL query for ALTER USER to be displayed

bool $createDb1
bool $createDb2
bool $createDb3

Return Value

array

string getHashedPassword(string $password)

Get the hashed string for password

Parameters

string $password password

Return Value

string

array getSqlQueriesForDisplayAndAddUser(string $username, string $hostname, string $password)

Get SQL queries for Display and Add user

Parameters

string $username username
string $hostname

host name

string $password password

Return Value

array

string getRoutineType(string $dbname, string $routineName)

Returns the type ('PROCEDURE' or 'FUNCTION') of the routine

Parameters

string $dbname database
string $routineName routine

Return Value

string type

string getFormForChangePassword(string $username, string $hostname, bool $editOthers, string $route)

No description

Parameters

string $username
string $hostname
bool $editOthers
string $route

Return Value

string