From fabbd13c469849214d7ba47b7d60a0c37154956f Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 30 Jan 2003 10:33:04 +0000 Subject: [PATCH] Removed the old user management --- ChangeLog | 6 +- libraries/user_details.js | 219 ------ main.php3 | 7 - user_details.php3 | 1509 ------------------------------------- 4 files changed, 5 insertions(+), 1736 deletions(-) delete mode 100644 libraries/user_details.js delete mode 100644 user_details.php3 diff --git a/ChangeLog b/ChangeLog index 6b92abab3..d6e945dbf 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-01-30 Alexander M. Turek + * main.php3, user_details.php3, libraries/user_details.js: Removed the old + user management. + 2003-01-29 Marc Delisle * tbl_select.php3: drop-down for enums, thanks to Joerg Klein (j0erch) @@ -27,7 +31,7 @@ $Source$ * lang/italian*: Updates, thanks to Pietro Danesi (danone) * lang/english*: Resorted and Resynced. * lang/farsi*: Added ready for Farsi translation - * lang/sync_lang.sh, libraries/select_lang.lib.php3: + * lang/sync_lang.sh, libraries/select_lang.lib.php3: - Updates ready for Farsi translation * lang/polish*: Updates, thanks to Jakub Wilk (ubanus) * fulltext.png, partialtext.png, pma_logo.png: diff --git a/libraries/user_details.js b/libraries/user_details.js deleted file mode 100644 index d9be65c86..000000000 --- a/libraries/user_details.js +++ /dev/null @@ -1,219 +0,0 @@ -/* $Id$ */ - - -/** - * Validates the password field in a form - * - * @param object the form - * - * @return boolean whether the field value is valid or not - */ -function checkPassword(the_form) -{ - // Gets the elements pointers - if (the_form.name == 'addUserForm' || the_form.name == 'chgPassword') { - var pswd_index = 1; - var pswd1_name = 'pma_pw'; - var pswd2_name = 'pma_pw2'; - } else { - pswd_index = 2; - pswd1_name = 'new_pw'; - pswd2_name = 'new_pw2'; - } - - // Validates - if (the_form.elements['nopass'][pswd_index].checked) { - if (the_form.elements[pswd1_name].value == '') { - alert(jsPasswordEmpty); - the_form.elements[pswd2_name].value = ''; - the_form.elements[pswd1_name].focus(); - return false; - } else if (the_form.elements[pswd1_name].value != the_form.elements[pswd2_name].value) { - alert(jsPasswordNotSame); - the_form.elements[pswd1_name].value = ''; - the_form.elements[pswd2_name].value = ''; - the_form.elements[pswd1_name].focus(); - return false; - } // end if...else if - } // end if - - return true; -} // end of the 'checkPassword()' function - - -/** - * Validates the "add an user" form - * - * @return boolean whether the form is validated or not - */ -function checkAddUser() -{ - var the_form = document.forms['addUserForm']; - - if (the_form.elements['anyhost'][1].checked && the_form.elements['host'].value == '') { - alert(jsHostEmpty); - the_form.elements['host'].focus(); - return false; - } - - if (the_form.elements['anyuser'][1].checked && the_form.elements['pma_user'].value == '') { - alert(jsUserEmpty); - the_form.elements['pma_user'].focus(); - return false; - } - - return checkPassword(the_form); -} // end of the 'checkAddUser()' function - - -/** - * Validates the "update a profile" form - * - * @return boolean whether the form is validated or not - */ -function checkUpdProfile() -{ - var the_form = document.forms['updUserForm']; - - if (the_form.elements['anyhost'][1].checked && the_form.elements['new_server'].value == '') { - alert(jsHostEmpty); - the_form.elements['new_server'].focus(); - return false; - } - - if (the_form.elements['anyuser'][1].checked && the_form.elements['new_user'].value == '') { - alert(jsUserEmpty); - the_form.elements['new_user'].focus(); - return false; - } - - return checkPassword(the_form); -} // end of the 'checkUpdProfile()' function - - -/** - * Gets the list of selected options in combo - * - * @param object the form to check - * - * @return string the list of selected options - */ -function getSelected(the_field) { - var the_list = ''; - var opts = the_field.options; - var opts_cnt = opts.length; - - for (var i = 0; i < opts_cnt; i++) { - if (opts[i].selected) { - the_list += opts[i].text + ', '; - } - } // end for - - return the_list.substring(0, the_list.length - 2); -} // end of the 'getSelected()' function - - -/** - * Reloads the page to get tables names in a database or fields names in a - * table - * - * @param object the input text box to build the query from - */ -function change(the_field) { - var l = location.href; - var lpos = l.indexOf('?lang'); - var box_name = the_field.name; - var the_form = the_field.form.elements; - var sel_idx = null; - - if (box_name == 'newdb') { - the_form['anydb'][0].checked = true; - the_form['anytable'][0].checked = true; - the_form['anycolumn'][0].checked = true; - if (typeof(the_form['dbgrant']) != 'undefined') { - the_form['dbgrant'].selectedIndex = -1; - } - if (typeof(the_form['tablegrant']) != 'undefined') { - the_form['tablegrant'].selectedIndex = -1; - } - if (typeof(the_form['colgrant']) != 'undefined') { - the_form['colgrant'].selectedIndex = -1; - } - } - else { - if (lpos <= 0) { - l += '?lang=' + the_form['lang'].value - + '&convcharset=' . the_form['convcharset'].value - + '&server=' + the_form['server'].value - + '&grants=1' - + '&host=' + escape(the_form['host'].value) - + '&pma_user=' + escape(the_form['pma_user'].value); - sel_idx = the_form['dbgrant'].selectedIndex; - if (sel_idx > 0) { - l += '&dbgrant=' + escape(the_form['dbgrant'].options[sel_idx].text); - } - sel_idx = the_form['tablegrant'].selectedIndex; - if (sel_idx > 0) { - l += '&tablegrant=' + escape(the_form['tablegrant'].options[sel_idx].text); - } - } - - var lpos = l.indexOf('&' + box_name); - if (lpos > 0) { - l = l.substring(0, lpos); - } // end if - - location.href = l + '&' + box_name + '=' + escape(getSelected(the_field)); - } - -} // end of the 'change()' function - - -/** - * Checks/unchecks all privileges - * - * @param string the form name - * @param boolean whether to check or to uncheck the element - * - * @return boolean always true - */ -function checkForm(the_form, do_check) { - var elts = document.forms[the_form].elements; - var elts_cnt = elts.length; - - for (var i = 0; i < elts_cnt; i++) { - var whichElt = elts[i].name; - if (whichElt.indexOf('_priv') >= 0) { - document.forms[the_form].elements[whichElt].checked = do_check; - } // end if - } // end for - - return true; -} // end of the 'checkForm()' function - - -/** - * Checks/unchecks all tables - * - * @param string the form name - * @param boolean whether to check or to uncheck the element - * - * @return boolean always true - */ -function setCheckboxes(the_form, do_check) -{ - var elts = document.forms[the_form].elements['selected_usr[]']; - var elts_cnt = (typeof(elts.length) != 'undefined') - ? elts.length - : 0; - - if (elts_cnt) { - for (var i = 0; i < elts_cnt; i++) { - elts[i].checked = do_check; - } // end for - } else { - elts.checked = do_check; - } // end if... else - - return true; -} // end of the 'setCheckboxes()' function diff --git a/main.php3 b/main.php3 index 6924e5e51..b2c9f14c5 100755 --- a/main.php3 +++ b/main.php3 @@ -389,13 +389,6 @@ if ($server > 0) { if ($is_superuser) { echo "\n"; ?> - - item - - -  ()  - - item diff --git a/user_details.php3 b/user_details.php3 deleted file mode 100644 index 2e0b6f3c3..000000000 --- a/user_details.php3 +++ /dev/null @@ -1,1509 +0,0 @@ - - - - - - ' . $GLOBALS['strAction'] . '' . "\n"; - echo ' ' . "\n"; - echo ' '; - } else { - echo "\n"; - echo ' '; - } - echo "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - if (!$dbcheck) { - echo ' ' . "\n"; - } - ?> - - ' . $row['User'] . '@' . $row['Host'] . '') . '
' . $GLOBALS['strRememberReload']) - . '&goto=user_details.php3'; - if ($grantopt) { - $revoke_grant_url = 'sql.php3' - . '?' . $url_query - . '&sql_query=' . urlencode('REVOKE GRANT OPTION ON ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' FROM \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'') - . '&zero_rows=' . urlencode(sprintf($GLOBALS['strRevokeGrantMessage'], ' ' . $row['User'] . '@' . $row['Host'] . '') . '
' . $GLOBALS['strRememberReload']) - . '&goto=user_details.php3'; - } - ?> - - - bgcolor=""> - - - - - bgcolor=""> - - - - - - - - - - - - - - - - - - - - 0 - // $host_db_result is an array containing related to only one user - // -> exit the loop - if (is_array($host_db_result)) { - break; - } - } // end while $row - ?> -
' . $GLOBALS['strHost'] . '' . $GLOBALS['strUser'] . '' . $GLOBALS['strAction'] . '' . $GLOBALS['strDatabase'] . '' . UCFirst($GLOBALS['strTable']) . '' . $GLOBALS['strPrivileges'] . '' . $GLOBALS['strGrantOption'] . '
- - -  ' . $GLOBALS['strAny'] . ''; ?>' . $GLOBALS['strAll'] . '' : $db; ?>' . $GLOBALS['strAll'] . '' : $table; ?>' . $GLOBALS['strNoPrivileges'] . ''; ?>
-
- - - - - ' . "\n"; - } else { - echo ' ' . "\n"; - } - echo ' ' . "\n"; - echo ' ' . "\n"; - if ($item % 2 == 0) { - echo ' ' . "\n"; - } - } // end while - if ($item % 2 == 1) { - echo ' ' . "\n"; - } // end if - ?> -
 ' . "\n"; - echo ' ' . "\n"; - echo '
 ' . "\n"; - echo '
- - - - - - -
- - -   - - -
- - -
    - -
  • -
    - -   - -
    -
  • - -
  • -
    - - - - - -
    -  :  - - - - -
    -
    -
  • - -
  • -
    - - - - - - - - - - - - - - - - - - - - - - - -
    - - -   - -  :  - - ="this.form.anyhost[1].checked = true" /> -
    - - -   - -  :  - - ="this.form.anyuser[1].checked = true" /> -
    - - -   - -  :  - - ="nopass[1].checked = true" /> -    -  :  - ="nopass[1].checked = true" /> -
    -
    -  : -
    -
    - - - -
    -
  • - -
- - -
    - -
  • -
    - - -
    -
  • - -
  • -
    - - - " /> - " /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - /> - -     - /> - (*) :  - - - -   - -
    - /> - -     - /> -  :  - - - -   - -
    - - -     - -  :  - - ' . "\n"; - echo ' ' . '' . "\n"; - echo ' ' . '' . "\n"; - } - else { - $result = PMA_mysql_query('SHOW COLUMNS FROM ' . PMA_backquote($tablegrant) . ' FROM ' . PMA_backquote($dbgrant)); - if ($result && @mysql_num_rows($result)) { - echo ' ' - . '' . "\n"; - echo ' ' . '' . "\n"; - } // end if... else... - echo ' ' - . '' . "\n"; - } // end if... else - ?> -
    - -
    -   - ="change(this)" /> -
    - - - - - -
    -
    -  :  -
    -
    - - -
    -
  • - -
- - -
    - -
  • -
    - - -
    -
  • - -
  • -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - /> - -   - /> -  :  - - " class="textfield" ="this.form.anyhost[1].checked = true" /> -
    - /> - -   - /> -  :  - - " class="textfield" ="this.form.anyuser[1].checked = true" /> -
    - - -  
          
    - - -   - -  :  - - ="nopass[2].checked = true" /> -    -  :  - ="nopass[2].checked = true" /> -
    - - " /> - " /> - -
    -
  • - -
  • -
    - - - - " /> - " /> - -
    -
  • - -
- ' . $GLOBALS['strEnglishPrivileges'] . '
' . "\n"; - echo '' . "\n"; - echo '' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo ' ' . "\n"; - echo '' . "\n"; - - $i = 0; - while ($row = PMA_mysql_fetch_array($result)) { - - $bgcolor = ($i % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; - - $strPriv = ''; - if ($row['Select_priv'] == 'Y') { - $strPriv .= 'Select '; - } - if ($row['Insert_priv'] == 'Y') { - $strPriv .= 'Insert '; - } - if ($row['Update_priv'] == 'Y') { - $strPriv .= 'Update '; - } - if ($row['Delete_priv'] == 'Y') { - $strPriv .= 'Delete '; - } - if ($row['Create_priv'] == 'Y') { - $strPriv .= 'Create '; - } - if ($row['Drop_priv'] == 'Y') { - $strPriv .= 'Drop '; - } - if ($row['Reload_priv'] == 'Y') { - $strPriv .= 'Reload '; - } - if ($row['Shutdown_priv'] == 'Y') { - $strPriv .= 'Shutdown '; - } - if ($row['Process_priv'] == 'Y') { - $strPriv .= 'Process '; - } - if ($row['File_priv'] == 'Y') { - $strPriv .= 'File '; - } - if ($row['Grant_priv'] == 'Y') { - $strPriv .= 'Grant '; - } - if ($row['References_priv'] == 'Y') { - $strPriv .= 'References '; - } - if ($row['Index_priv'] == 'Y') { - $strPriv .= 'Index '; - } - if ($row['Alter_priv'] == 'Y') { - $strPriv .= 'Alter '; - } - if ($strPriv == '') { - $strPriv = '' . $GLOBALS['strNoPrivileges'] . ''; - } - - $query = PMA_generate_common_url('mysql', 'user'); - if (!$user) { - $edit_url = 'user_details.php3?' - . PMA_generate_common_url() - . '&edit=1&host=' . urlencode($row['Host']) . '&pma_user=' . urlencode($row['User']); - } - $delete_url = 'user_details.php3?' - . $query - . '&delete=1&confirm=1&delete_host=' . urlencode($row['Host']) . '&delete_user=' . urlencode($row['User']); - $check_url = 'user_details.php3?' - . PMA_generate_common_url() - . '&grants=1&host=' . urlencode($row['Host']) . '&pma_user=' . urlencode($row['User']); - ?> - - - - - - - - - - - - - - -
' . $GLOBALS['strAction'] . '' . $GLOBALS['strHost'] . '' . $GLOBALS['strUser'] . '' . $GLOBALS['strPassword'] . '' . $GLOBALS['strPrivileges'] . '
- - - - - - - - - - - - ' . $row['User'] . '' : '' . $GLOBALS['strAny'] . '') . "\n"; ?> - - ' . $GLOBALS['strNo'] . '') . "\n"; ?> - - -
-
- ' . "\n"; - echo 'DELETE FROM mysql.user WHERE Host = \'' . $the_host . '\' AND User = \'' . $the_user . '\'' . '
' . "\n"; - ?> -
- - - " /> - " /> - - -
- ' . $strError . '

' . "\n"; - echo '

    ' . $strNoRights . '

' . "\n"; - include('./footer.inc.php3'); - exit(); -} -// The previous logic did not work if the password field is named "password": -//$result = @PMA_mysql_query('SELECT COUNT(Password) FROM mysql.user'); -//$password_field = (($result && PMA_mysql_result($result, 0)) ? 'Password' : 'password'); - -// using a syntax that works with older and recent MySQL, -// and assumes that the field name ends with "assword": -$result = @PMA_mysql_query('SHOW FIELDS FROM user FROM mysql LIKE \'%assword\''); -if ($result) { - $password_field = PMA_mysql_result($result, 0); -} - -/** - * Autocomplete feature of IE kills the "onchange" event handler and it must be - * replaced by the "onpropertychange" one in this case - */ -$chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5) - ? 'onpropertychange' - : 'onchange'; - - -/** - * Displays headers - */ -if (isset($db)) { - $db_bkp = (get_magic_quotes_gpc() ? stripslashes($db) : $db); - unset($db); -} -if (isset($table)) { - $table_bkp = (get_magic_quotes_gpc() ? stripslashes($table) : $table); - unset($table); -} -if (get_magic_quotes_gpc()) { - if (!empty($host)) { - $host = stripslashes($host); - } - if (!empty($pma_user)) { - $pma_user = stripslashes($pma_user); - } -} - -if (!isset($message)) { - $js_to_run = 'user_details.js'; - include('./header.inc.php3'); -} -if (!isset($submit_updProfile)) { - echo '

' . "\n"; - echo ' ' . ((!isset($host) || $host == '') ? $strAnyHost : $strHost . ' ' . $host) . ' - ' . ((!isset($pma_user) || $pma_user == '') ? $strAnyUser : $strUser . ' ' . $pma_user) . "\n"; - echo '

'; -} -if (isset($message)) { - $show_query = '1'; - PMA_showMessage($message); -} - -if (isset($db_bkp)) { - $db = $db_bkp; - unset($db_bkp); -} -if (isset($table_bkp)) { - $table = $table_bkp; - unset($table_bkp); -} - - -/** - * Some actions has been submitted - */ -// Confirms an action -if (isset($confirm) && $confirm) { - PMA_confirm($delete_host, $delete_user); - exit(); -} - -// Reloads mysql -else if (($server > 0) && isset($mode) && ($mode == 'reload')) { - $result = PMA_mysql_query('FLUSH PRIVILEGES'); - if ($result != 0) { - echo '

' . $strMySQLReloaded . '

' . "\n"; - } else { - echo '

' . $strReloadFailed . '

' . "\n"; - } -} - -// Deletes an user -else if (isset($delete) && $delete - && isset($btnConfirm) && $btnConfirm == $strYes) { - if (get_magic_quotes_gpc()) { - $delete_host = stripslashes($delete_host); - $delete_user = stripslashes($delete_user); - } - $common_where = ' WHERE Host = \'' . PMA_sqlAddslashes($delete_host) . '\' AND User = \'' . PMA_sqlAddslashes($delete_user) . '\''; - - // Delete Grants First! - $sql_query = 'DELETE FROM mysql.db' . $common_where; - $sql_query_cpy = $sql_query; - PMA_mysql_query($sql_query); - $sql_query = 'DELETE FROM mysql.tables_priv' . $common_where; - $sql_query_cpy .= ";\n" . $sql_query; - PMA_mysql_query($sql_query); - $sql_query = 'DELETE FROM mysql.columns_priv' . $common_where; - $sql_query_cpy .= ";\n" . $sql_query; - PMA_mysql_query($sql_query); - - $sql_query = 'DELETE FROM mysql.user' . $common_where; - $sql_query_cpy .= ";\n" . $sql_query; - $result = PMA_mysql_query($sql_query); - - $sql_query = $sql_query_cpy; - unset($sql_query_cpy); - if ($result) { - PMA_showMessage(sprintf($strDeleteUserMessage, '' . $delete_user . '@' . $delete_host . '') . '
' . $strRememberReload); - } else { - PMA_showMessage($strDeleteFailed); - } -} - -// Adds an user -else if (isset($submit_addUser)) { - $show_query = '1'; - if (!isset($host) || $host == '') { - $host = '%'; - } - //if (!isset($pma_user) || $pma_user == '') { - // $pma_user = '%'; - //} - if (isset($anyuser) && $anyuser=="1") { - $pma_user = ''; - - // this is for the case where js is disabled, so they did not get - // the error before submitting - } else if (isset($pma_user) && empty($pma_user)) { - echo '

' . $strError . ' : ' . $strUserEmpty . '

' . "\n"; - unset($host); - unset($pma_user); - $forgot_checkbox_any_user = TRUE; - } - - // Password is not confirmed - if ((!isset($nopass) || !$nopass) && $pma_pw == '') { - echo '

' . $strError . ' : ' . $strPasswordEmpty . '

' . "\n"; - unset($host); - unset($pma_user); - } - else if ($pma_pw != '' - && (!isset($pma_pw2) || $pma_pw != $pma_pw2)) { - echo '

' . $strError . ' : ' . $strPasswordNotSame . '

' . "\n"; - unset($host); - unset($pma_user); - } - - // Password confirmed - else if (!isset($forgot_checkbox_any_user)) { - $sql_query = ''; - $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload', - 'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter'); - for ($i = 0; $i < 14; $i++) { - $priv_name = $list_priv[$i] . '_priv'; - if (isset($$priv_name)) { - $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'Y\''; - } else { - $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'N\''; - } - } // end for - unset($list_priv); - - if (get_magic_quotes_gpc() && $pma_pw != '') { - $pma_pw = stripslashes($pma_pw); - } - - $local_query = 'INSERT INTO mysql.user ' - . 'SET Host = \'' . PMA_sqlAddslashes($host) . '\', User = \'' . PMA_sqlAddslashes($pma_user) . '\', ' . $password_field . ' = ' . (($pma_pw == '') ? '\'\'' : 'PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')') - . ', ' . $sql_query; - $sql_query = 'INSERT INTO mysql.user ' - . 'SET Host = \'' . PMA_sqlAddslashes($host) . '\', User = \'' . PMA_sqlAddslashes($pma_user) . '\', ' . $password_field . ' = ' . (($pma_pw == '') ? '\'\'' : 'PASSWORD(\'' . ereg_replace('.', '*', $pma_pw) . '\')') - . ', ' . $sql_query; - $result = @PMA_mysql_query($local_query) or PMA_mysqlDie('', '', FALSE, $err_url); - unset($host); - unset($pma_user); - PMA_showMessage($strAddUserMessage . '
' . $strRememberReload); - } // end else -} - -// Updates the profile of an user -else if (isset($submit_updProfile)) { - $show_query = '1'; - $edit = TRUE; - if (!isset($host) || $host == '') { - $host = '%'; - } - //if (!isset($pma_user) || $pma_user == '') { - // $pma_user = '%'; - //} - if (!isset($pma_user)) { - $pma_user = ''; - } - - // Builds the sql query - $common_upd = ''; - - if (isset($anyhost) && $anyhost) { - $new_server = '%'; - } else if ($new_server != '' && get_magic_quotes_gpc()) { - $new_server = stripslashes($new_server); - } - if ($new_server != '' && $new_server != $host) { - $common_upd .= 'Host = \'' . PMA_sqlAddslashes($new_server) . '\''; - } else if (isset($new_server)) { - unset($new_server); - } - if (isset($anyuser) && $anyuser=="1") { - //$new_user = '%'; - // anonymous user must be empty, not % - $new_user = ''; - } else if ($new_user != '' && get_magic_quotes_gpc()) { - $new_user = stripslashes($new_user); - } - //if ($new_user != '' && $new_user != $pma_user) { - if ($new_user != $pma_user) { - $common_upd .= (empty($common_upd) ? '' : ', ') - . 'User = \'' . PMA_sqlAddslashes($new_user) . '\''; - } else if (isset($new_user)) { - unset($new_user); - } - - if (isset($nopass) && $nopass == -1) { - $sql_query = $common_upd; - $local_query = $common_upd; - } - else if ((!isset($nopass) || $nopass == 0) && $new_pw == '') { - echo '

' . "\n"; - echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ? $pma_user : $strAny) . "\n"; - echo '

' . "\n"; - echo '

' . $strError . ' : ' . $strPasswordEmpty . '

' . "\n"; - } - else if ($new_pw != '' - && (!isset($new_pw2) || $new_pw != $new_pw2)) { - echo '

' . "\n"; - echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ? $pma_user : $strAny) . "\n"; - echo '

' . "\n"; - echo '

' . $strError . ' : ' . $strPasswordNotSame . '

' . "\n"; - } - else { - $sql_query = (empty($common_upd) ? '' : $common_upd . ', ') - . $password_field . ' = ' . (($new_pw == '') ? '\'\'' : 'PASSWORD(\'' . ereg_replace('.', '*', $new_pw) . '\')'); - $local_query = (empty($common_upd) ? '' : $common_upd . ', ') - . $password_field . ' = ' . (($new_pw == '') ? '\'\'' : 'PASSWORD(\'' . PMA_sqlAddslashes($new_pw) . '\')'); - } - - if (!empty($sql_query)) { - $common_where = ' WHERE Host = \'' . PMA_sqlAddslashes($host) . '\' AND User = \'' . PMA_sqlAddslashes($pma_user) . '\''; - // Updates profile - $local_query = 'UPDATE user SET ' . $local_query . $common_where; - $sql_query_cpy = 'UPDATE user SET ' . $sql_query . $common_where; - $result = @PMA_mysql_query($local_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&edit=1'); - - // Updates grants - if (isset($new_server) || isset($new_user)) { - $sql_query = 'UPDATE mysql.db SET ' . $common_upd . $common_where; - $sql_query_cpy .= ";\n" . $sql_query; - PMA_mysql_query($sql_query); - $sql_query = 'UPDATE mysql.tables_priv SET ' . $common_upd . $common_where; - $sql_query_cpy .= ";\n" . $sql_query; - PMA_mysql_query($sql_query); - $sql_query = 'UPDATE mysql.columns_priv SET ' . $common_upd . $common_where; - $sql_query_cpy .= ";\n" . $sql_query; - PMA_mysql_query($sql_query); - unset($common_upd); - } - - $sql_query = $sql_query_cpy; - unset($sql_query_cpy); - if (isset($new_server)) { - $host = $new_server; - } - if (isset($new_user)) { - $pma_user = $new_user; - } - echo '

' . "\n"; - echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ? $pma_user : $strAny) . "\n"; - echo '

' . "\n"; - PMA_showMessage($strUpdateProfileMessage . '
' . $strRememberReload); - } else { - echo '

' . "\n"; - echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ? $pma_user : $strAny) . "\n"; - echo '

' . "\n"; - PMA_showMessage($strNoModification); - } -} - -// Changes the privileges of an user -else if (isset($submit_chgPriv)) { - $show_query = '1'; - $edit = TRUE; - if (!isset($host) || $host == '') { - $host = '%'; - } - if (!isset($pma_user) || $pma_user == '') { - $pma_user = '%'; - } - - $sql_query = ''; - $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload', - 'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter'); - for ($i = 0; $i < 14; $i++) { - $priv_name = $list_priv[$i] . '_priv'; - if (isset($$priv_name)) { - $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'Y\''; - } else { - $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'N\''; - } - } // end for - unset($list_priv); - - $sql_query = 'UPDATE user SET ' - . $sql_query - . ' WHERE Host = \'' . PMA_sqlAddslashes($host) . '\' AND User = \'' . PMA_sqlAddslashes($pma_user) . '\''; - $result = @PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&edit=1'); - PMA_showMessage(sprintf($strUpdatePrivMessage, '' . $pma_user . '@' . $host . '') . '
' . $strRememberReload); -} - -// Revoke/Grant privileges -else if (isset($grants) && $grants) { - $show_query = '1'; - if (!isset($host) || $host == '') { - $host = '%'; - } - if (!isset($pma_user) || $pma_user == '') { - $pma_user = '%'; - } - - if (isset($upd_grants)) { - $sql_query = ''; - $col_list = ''; - - if (isset($colgrant) && !$anycolumn && !$newdb) { - $colgrant_cnt = count($colgrant); - for ($i = 0; $i < $colgrant_cnt; $i++) { - if (get_magic_quotes_gpc()) { - $colgrant[$i] = stripslashes($colgrant[$i]); - } - $col_list .= (empty($col_list) ? PMA_backquote($colgrant[$i]) : ', ' . PMA_backquote($colgrant[$i])); - } // end for - unset($colgrant); - $col_list = ' (' . $col_list . ')'; - } // end if - - $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload', - 'Shutdown', 'Process', 'File', 'References', 'Index', 'Alter'); - for ($i = 0; $i < 13; $i++) { - $priv_name = $list_priv[$i] . '_priv'; - if (isset($$priv_name)) { - $sql_query .= (empty($sql_query) ? $list_priv[$i] : ', ' . $list_priv[$i]) . $col_list; - } - } // end for - unset($list_priv); - if (empty($sql_query)) { - $sql_query = 'USAGE' . $col_list; - } - $priv_grant = 'Grant_priv'; - $priv_grant = (isset($$priv_grant) ? ' WITH GRANT OPTION' : ''); - - if (get_magic_quotes_gpc()) { - if ($newdb) { - $newdb = stripslashes($newdb); - } else { - if (isset($dbgrant) && !$anydb && !$newdb) { - $dbgrant = stripslashes($dbgrant); - } - if (isset($tablegrant) && !$anytable && !$newdb) { - $tablegrant = stripslashes($tablegrant); - } - } - } // end if - - // Escape wilcard characters if required - if (isset($dbgrant) && !$anydb && !$newdb) { - $re = '(^|(\\\\\\\\)+|[^\])(_|%)'; // non-escaped wildcards - $dbgrant = ereg_replace($re, '\\1\\\\3', $dbgrant); - } - - if (!$newdb) { - $sql_query .= ' ON ' - . (($anydb || $dbgrant == '') ? '*' : PMA_backquote($dbgrant)) - . '.' - . (($anytable || $tablegrant == '') ? '*' : PMA_backquote($tablegrant)); - } else { - $sql_query .= ' ON ' . PMA_backquote($newdb) . '.*'; - } - - $sql_query .= ' TO ' . '\'' . PMA_sqlAddslashes($pma_user) . '\'' . '@' . '\'' . PMA_sqlAddslashes($host) . '\''; - - $sql_query = 'GRANT ' . $sql_query . $priv_grant; - $result = @PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&grants=1'); - PMA_showMessage($strAddPrivMessage . '.
' . $strRememberReload); - } // end if -} - - - -/** - * Displays the page - */ -// Edit an user properies -if (isset($edit) && $edit) { - PMA_tableUsers($host, $pma_user); - PMA_editOperations($host, $pma_user); -} - -// Revoke/Grant privileges for an user -else if (isset($grants) && $grants) { - // Displays the full list of privileges for this host & user - $infos['Host'] = $host; - $infos['User'] = $pma_user; - PMA_tableGrants($infos); - - // Displays the list of privileges for user on the selected db/table/column - $user_priv = array(); - $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload', - 'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', - 'Alter'); - $list_priv_new = array(); - - // Gets globals privileges - $result = PMA_mysql_query('SELECT * FROM mysql.user WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\')'); - $row = ($result) ? @PMA_mysql_fetch_array($result) : FALSE; - if ($row) { - while (list(,$priv) = each($list_priv)) { - $priv_priv = $priv . '_priv'; - if ($row[$priv_priv] == 'Y') { - $user_priv[$priv_priv] = 'Y'; - } else { - $user_priv[$priv_priv] = 'N'; - $list_priv_new[] = $priv; - } - } // end while - mysql_free_result($result); - $list_priv = $list_priv_new; - unset($list_priv_new); - $list_priv_new = array(); - } // end if $row - - // If a target database is set, gets privileges for this database - if (count($list_priv) && isset($dbgrant)) { - if (get_magic_quotes_gpc()) { - $dbgrant = stripslashes($dbgrant); - } - $result = PMA_mysql_query('SELECT * FROM mysql.db WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\') AND Db = \'' . PMA_sqlAddslashes($dbgrant) . '\''); - $row = ($result) ? @PMA_mysql_fetch_array($result) : FALSE; - if ($row) { - while (list(,$priv) = each($list_priv)) { - $priv_priv = $priv . '_priv'; - if (isset($row[$priv_priv]) && $row[$priv_priv] == 'Y') { - $user_priv[$priv_priv] = 'Y'; - } else { - $list_priv_new[] = $priv; - } - } // end while - mysql_free_result($result); - $list_priv = $list_priv_new; - unset($list_priv_new); - $list_priv_new = array(); - } // end if $row - } // end if - - // If a target table is set, gets privileges for this table - if (count($list_priv) && isset($tablegrant)) { - if (get_magic_quotes_gpc()) { - $tablegrant = stripslashes($tablegrant); - } - $result = PMA_mysql_query('SELECT * FROM mysql.tables_priv WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\') AND Db = \'' . PMA_sqlAddslashes($dbgrant) . '\' AND Table_name = \'' . PMA_sqlAddslashes($tablegrant) . '\''); - $row = ($result) ? @PMA_mysql_fetch_array($result) : FALSE; - if ($row && $row['Table_priv']) { - while (list(,$priv) = each($list_priv)) { - $priv_priv = $priv . '_priv'; - if (eregi('(^|,)' . $priv . '(,|$)', $row['Table_priv'])) { - $user_priv[$priv_priv] = 'Y'; - } else { - $list_priv_new[] = $priv; - } - } // end while - mysql_free_result($result); - $list_priv = $list_priv_new; - unset($list_priv_new); - $list_priv_new = array(); - } // end if $row - } // end if - - // TODO: column privileges - - PMA_grantOperations($user_priv); -} - -// Check database privileges -else if (isset($check) && $check) { - PMA_checkDb($db); - ?> - -