diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 3ef12987bb..52a60bb5e7 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -1735,10 +1735,16 @@ function PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename) * * @return array $db_rights database rights */ -function PMA_getUserSpecificRights($dbname, $tables, $user_host_condition) +function PMA_getUserSpecificRights($tables, $user_host_condition) { $common_functions = PMA_CommonFunctions::getInstance(); + if (PMA_isValid($_REQUEST['pred_dbname'])) { + $dbname = $_REQUEST['pred_dbname']; + unset($pred_dbname); + } elseif (PMA_isValid($_REQUEST['dbname'])) { + $dbname = $_REQUEST['dbname']; + } if (! isset($dbname)) { $tables_to_search_for_users = array( 'tables_priv', 'columns_priv', @@ -1917,9 +1923,14 @@ function PMA_getHtmlForDisplayUserRightsInRows($db_rights, $link_edit, * * @return array $html_output, $found_rows */ -function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname, - $dbname, $link_edit, $link_revoke +function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname + , $link_edit, $link_revoke ) { + if (PMA_isValid($_REQUEST['pred_dbname'])) { + $dbname = $_REQUEST['pred_dbname']; + } elseif (PMA_isValid($_REQUEST['dbname'])) { + $dbname = $_REQUEST['dbname']; + } // table header $html_output = PMA_generate_common_hidden_inputs('', '') . '' . "\n" @@ -1955,7 +1966,7 @@ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname, * 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 */ - $db_rights = PMA_getUserSpecificRights($dbname, $tables, $user_host_condition); + $db_rights = PMA_getUserSpecificRights($tables, $user_host_condition); ksort($db_rights); @@ -2524,4 +2535,243 @@ function PMA_getHtmlForExportUserDefinition($username, $hostname) return array($title, $export); } +function PMA_getAddUserHtmlFieldset($conditional_class) +{ + return '
' . "\n" + . '' . "\n" + . PMA_CommonFunctions::getInstance()->getIcon('b_usradd.png') + . ' ' . __('Add user') . '' . "\n" + . '
' . "\n"; +} + +function PMA_getHtmlHeaderForDisplayUserProperties($dbname_is_wildcard) +{ + $html_output = '

' . "\n" + . PMA_CommonFunctions::getInstance()->getIcon('b_usredit.png') + . __('Edit Privileges') . ': ' + . __('User'); + + if (isset($_REQUEST['dbname'])) { + $html_output .= ' \'' . htmlspecialchars($_REQUEST['username']) + . '\'@\'' . htmlspecialchars($_REQUEST['hostname']) + . '\'' . "\n"; + + $url_dbname = urlencode( + str_replace( + array('\_', '\%'), + array('_', '%'), $_REQUEST['dbname'] + ) + ); + + $html_output .= ' - ' . ($dbname_is_wildcard ? __('Databases') : __('Database') ); + if (isset($_REQUEST['tablename'])) { + $html_output .= ' ' . htmlspecialchars($_REQUEST['dbname']) + . ''; + + $html_output .= ' - ' . __('Table') + . ' ' . htmlspecialchars($_REQUEST['tablename']) . ''; + } else { + $html_output .= ' ' . htmlspecialchars($_REQUEST['dbname']) . ''; + } + + } else { + $html_output .= ' \'' . htmlspecialchars($_REQUEST['username']) + . '\'@\'' . htmlspecialchars($_REQUEST['hostname']) + . '\'' . "\n"; + + } + $html_output .= '

' . "\n"; + + return $html_output; +} + +function PMA_getHtmlForDiplayUserOverviewPage($link_edit, $pmaThemeImage, + $text_dir, $conditional_class, $link_export, $link_export_all +) { + $html_output = '

' . "\n" + . PMA_CommonFunctions::getInstance()->getIcon('b_usrlist.png') + . __('Users overview') . "\n" + . '

' . "\n"; + + $sql_query = 'SELECT *,' . + " IF(`Password` = _latin1 '', 'N', 'Y') AS 'Password'" . + ' FROM `mysql`.`user`'; + + $sql_query .= (isset($_REQUEST['initial']) ? PMA_rangeOfUsers($_REQUEST['initial']) : ''); + + $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; + $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); + + if (! $res) { + // the query failed! This may have two reasons: + // - the user does not have enough privileges + // - the privilege tables use a structure of an earlier version. + // so let's try a more simple query + + $sql_query = 'SELECT * FROM `mysql`.`user`'; + $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); + + if (! $res) { + $html_output .= PMA_Message::error(__('No Privileges'))->getDisplay(); + PMA_DBI_free_result($res); + unset($res); + } else { + // This message is hardcoded because I will replace it by + // a automatic repair feature soon. + $raw = 'Your privilege table structure seems to be older than' + . ' this MySQL version!
' + . 'Please run the mysql_upgrade command' + . '(mysql_fix_privilege_tables on older systems)' + . ' that should be included in your MySQL server distribution' + . ' to solve this problem!'; + $html_output .= PMA_Message::rawError($raw)->getDisplay(); + } + } else { + $db_rights = PMA_getDbRightsForUserOverview(); + // for all initials, even non A-Z + $array_initials = array(); + + /** + * Displays the initials + * In an Ajax request, we don't need to show this. + * Also not necassary if there is less than 20 privileges + */ + if ($GLOBALS['is_ajax_request'] != true && PMA_DBI_num_rows($res) > 20 ) { + $html_output .= PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class); + } + + /** + * Display the user overview + * (if less than 50 users, display them immediately) + */ + if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) || PMA_DBI_num_rows($res) < 50) { + $html_output .= PMA_displayUserOverview($res, $db_rights, $link_edit,$pmaThemeImage, + $text_dir, $conditional_class, $link_export, $link_export_all + ); + } else { + $html_output .= PMA_getAddUserHtmlFieldset($conditional_class); + } // end if (display overview) + + if ($GLOBALS['is_ajax_request']) { + exit; + } + + $flushnote = new PMA_Message( + __('Note: phpMyAdmin gets the users\' privileges directly from MySQL\'s privilege tables. The content of these tables may differ from the privileges the server uses, if they have been changed manually. In this case, you should %sreload the privileges%s before you continue.') + , PMA_Message::NOTICE + ); + $flushnote->addParam( + '', + false); + $flushnote->addParam('', false); + $html_output .= $flushnote->getDisplay(); + + return $html_output; + } +} + +function PMA_getHtmlForDisplayUserPropeties($dbname_is_wildcard,$url_dbname, + $random_n, $username, $hostname, $link_edit, $link_revoke +) { + if (PMA_isValid($_REQUEST['pred_dbname'])) { + $dbname = $_REQUEST['pred_dbname']; + } elseif (PMA_isValid($_REQUEST['dbname'])) { + $dbname = $_REQUEST['dbname']; + } + if (PMA_isValid($_REQUEST['pred_tablename'])) { + $tablename = $_REQUEST['pred_tablename']; + } elseif (PMA_isValid($_REQUEST['tablename'])) { + $tablename = $_REQUEST['tablename']; + } + $html_output = PMA_getHtmlHeaderForDisplayUserProperties($dbname_is_wildcard); + + $sql = "SELECT '1' FROM `mysql`.`user`" + . " WHERE `User` = '" . PMA_CommonFunctions::getInstance()->sqlAddSlashes($username) . "'" + . " AND `Host` = '" . PMA_CommonFunctions::getInstance()->sqlAddSlashes($hostname) . "';"; + + $user_does_not_exists = (bool) ! PMA_DBI_fetch_value($sql); + + if ($user_does_not_exists) { + $html_output .= PMA_Message::error( + __('The selected user was not found in the privilege table.') + )->getDisplay(); + $html_output .= PMA_getHtmlForDisplayLoginInformationFields(); + //exit; + } + + $html_output .= '
' . "\n"; + + $_params = array( + 'username' => $username, + 'hostname' => $hostname, + ); + if (isset($dbname)) { + $_params['dbname'] = $dbname; + if (isset($tablename)) { + $_params['tablename'] = $tablename; + } + } + $html_output .= PMA_generate_common_hidden_inputs($_params); + + $html_output .= PMA_getHtmlToDisplayPrivilegesTable( + $random_n, + PMA_ifSetOr($dbname, '*', 'length'), + PMA_ifSetOr($tablename, '*', 'length') + ); + + $html_output .= '
' . "\n"; + + if (! isset($tablename) && empty($dbname_is_wildcard)) { + + // no table name was given, display all table specific rights + // but only if $dbname contains no wildcards + + $html_output .= '
' . "\n"; + + list($html_rightsTable, $found_rows) = PMA_getTableForDisplayAllTableSpecificRights( + $username, $hostname, $dbname, $link_edit, $link_revoke + ); + $html_output .= $html_rightsTable; + + if (! isset($dbname)) { + // no database name was given, display select db + $html_output .= PMA_getHTmlForDisplaySelectDbInEditPrivs($found_rows); + + } else { + $html_output .= PMA_displayTablesInEditPrivs($dbname, $found_rows); + } + $html_output .= '' . "\n"; + + $html_output .= '
' . "\n" + . ' ' + . '
' . "\n" + . '
' . "\n"; + } + + // Provide a line with links to the relevant database and table + if (isset($dbname) && empty($dbname_is_wildcard)) { + $html_output .= PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename); + + } + + if (! isset($dbname) && ! $user_does_not_exists) { + //change login information + include_once 'libraries/display_change_password.lib.php'; + $html_output .= PMA_getChangeLoginInformationHtmlForm($username, $hostname); + } + + return $html_output; +} ?> diff --git a/server_privileges.php b/server_privileges.php index 845570db21..3c2e765df0 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -621,203 +621,23 @@ if (isset($_REQUEST['export']) if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs))) { if (! isset($username)) { // No username is given --> display the overview - echo '

' . "\n" - . $common_functions->getIcon('b_usrlist.png') - . __('Users overview') . "\n" - . '

' . "\n"; - - $sql_query = 'SELECT *,' . - " IF(`Password` = _latin1 '', 'N', 'Y') AS 'Password'" . - ' FROM `mysql`.`user`'; - - $sql_query .= (isset($initial) ? PMA_rangeOfUsers($initial) : ''); - - $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; - $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); - - if (! $res) { - // the query failed! This may have two reasons: - // - the user does not have enough privileges - // - the privilege tables use a structure of an earlier version. - // so let's try a more simple query - - $sql_query = 'SELECT * FROM `mysql`.`user`'; - $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); - - if (! $res) { - PMA_Message::error(__('No Privileges'))->display(); - PMA_DBI_free_result($res); - unset($res); - } else { - // This message is hardcoded because I will replace it by - // a automatic repair feature soon. - $raw = 'Your privilege table structure seems to be older than' - . ' this MySQL version!
' - . 'Please run the mysql_upgrade command' - . '(mysql_fix_privilege_tables on older systems)' - . ' that should be included in your MySQL server distribution' - . ' to solve this problem!'; - PMA_Message::rawError($raw)->display(); - } - } else { - $db_rights = PMA_getDbRightsForUserOverview(); - // for all initials, even non A-Z - $array_initials = array(); - - /** - * Displays the initials - * In an Ajax request, we don't need to show this. - * Also not necassary if there is less than 20 privileges - */ - if ($GLOBALS['is_ajax_request'] != true && PMA_DBI_num_rows($res) > 20 ) { - echo PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class); - } - - /** - * Display the user overview - * (if less than 50 users, display them immediately) - */ - if (isset($initial) || isset($showall) || PMA_DBI_num_rows($res) < 50) { - - echo PMA_displayUserOverview($res, $db_rights, $link_edit, - $pmaThemeImage, $text_dir, $conditional_class, $link_export, $link_export_all - ); - } else { - - unset ($row); - echo '
' . "\n" - . ' ' . "\n" - . $common_functions->getIcon('b_usradd.png') - . ' ' . __('Add user') . '' . "\n" - . '
' . "\n"; - } // end if (display overview) - - if ($GLOBALS['is_ajax_request']) { - exit; - } - - $flushnote = new PMA_Message( - __('Note: phpMyAdmin gets the users\' privileges directly from MySQL\'s privilege tables. The content of these tables may differ from the privileges the server uses, if they have been changed manually. In this case, you should %sreload the privileges%s before you continue.') - , PMA_Message::NOTICE - ); - $flushnote->addParam( - '', - false); - $flushnote->addParam('', false); - $flushnote->display(); - } - - + $response->addHTML( + PMA_getHtmlForDiplayUserOverviewPage($link_edit, $pmaThemeImage, + $text_dir, $conditional_class, $link_export, $link_export_all + ) + ); } else { - // A user was selected -> display the user's properties // In an Ajax request, prevent cached values from showing if ($GLOBALS['is_ajax_request'] == true) { header('Cache-Control: no-cache'); } - - echo '

' . "\n" - . $common_functions->getIcon('b_usredit.png') - . __('Edit Privileges') . ': ' - . __('User'); - - if (isset($dbname)) { - echo ' \'' - . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) - . '\'' . "\n"; - $url_dbname = urlencode(str_replace(array('\_', '\%'), array('_', '%'), $dbname)); - - echo ' - ' . ($dbname_is_wildcard ? __('Databases') : __('Database') ); - if (isset($tablename)) { - echo ' ' . htmlspecialchars($dbname) . ''; - echo ' - ' . __('Table') . ' ' . htmlspecialchars($tablename) . ''; - } else { - echo ' ' . htmlspecialchars($dbname) . ''; - } - - } else { - echo ' \'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) - . '\'' . "\n"; - - } - echo '

' . "\n"; - - $sql = "SELECT '1' FROM `mysql`.`user`" - . " WHERE `User` = '" . $common_functions->sqlAddSlashes($username) . "'" - . " AND `Host` = '" . $common_functions->sqlAddSlashes($hostname) . "';"; - $user_does_not_exists = (bool) ! PMA_DBI_fetch_value($sql); - unset($sql); - if ($user_does_not_exists) { - PMA_Message::error(__('The selected user was not found in the privilege table.'))->display(); - echo PMA_getHtmlForDisplayLoginInformationFields(); - //exit; - } - - echo '
' . "\n"; - $_params = array( - 'username' => $username, - 'hostname' => $hostname, + $response->addHTML( + PMA_getHtmlForDisplayUserPropeties($dbname_is_wildcard,$url_dbname, + $random_n, $username, $hostname, $link_edit, $link_revoke + ) ); - if (isset($dbname)) { - $_params['dbname'] = $dbname; - if (isset($tablename)) { - $_params['tablename'] = $tablename; - } - } - echo PMA_generate_common_hidden_inputs($_params); - - echo PMA_getHtmlToDisplayPrivilegesTable( - $random_n, - PMA_ifSetOr($dbname, '*', 'length'), - PMA_ifSetOr($tablename, '*', 'length') - ); - - echo '
' . "\n"; - - if (! isset($tablename) && empty($dbname_is_wildcard)) { - - // no table name was given, display all table specific rights - // but only if $dbname contains no wildcards - - echo '
' . "\n"; - - list($html_output, $found_rows) = PMA_getTableForDisplayAllTableSpecificRights( - $username, $hostname, $dbname, $link_edit, $link_revoke - ); - echo $html_output; - - if (! isset($dbname)) { - // no database name was given, display select db - echo PMA_getHTmlForDisplaySelectDbInEditPrivs($found_rows); - - } else { - echo PMA_displayTablesInEditPrivs($dbname, $found_rows); - } - echo '' . "\n"; - echo '
' . "\n" - . ' ' - . '
' . "\n" - . '
' . "\n"; - } - - // Provide a line with links to the relevant database and table - if (isset($dbname) && empty($dbname_is_wildcard)) { - echo PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename); - - } - - if (! isset($dbname) && ! $user_does_not_exists) { - //change login information - include_once 'libraries/display_change_password.lib.php'; - echo PMA_getChangeLoginInformationHtmlForm($username, $hostname); - } } } elseif (isset($_REQUEST['adduser'])) { // Add user