diff --git a/libraries/replication_gui.lib.php b/libraries/replication_gui.lib.php index 392e1b8f16..e5d3b67685 100644 --- a/libraries/replication_gui.lib.php +++ b/libraries/replication_gui.lib.php @@ -60,7 +60,8 @@ function PMA_getHtmlForMasterReplication() $_url_params['repl_clear_scr'] = true; $html .= '
  • '; + $html .= PMA_generate_common_url($_url_params) + . '" id="master_addslaveuser_href">'; $html .= __('Add slave replication user') . '
  • '; } @@ -84,11 +85,14 @@ function PMA_getHtmlForMasterConfiguration() { $html = '
    '; $html .= '' . __('Master configuration') . ''; - $html .= __('This server is not configured as master server in a replication process. ' - . 'You can choose from either replicating all databases and ignoring certain ' - . '(useful if you want to replicate majority of databases) or you can choose to ignore ' - . 'all databases by default and allow only certain databases to be replicated. Please select the mode:') - . '

    '; + $html .= __( + 'This server is not configured as master server in a ' + . 'replication process. You can choose from either replicating ' + . 'all databases and ignoring certain (useful if you want to replicate ' + . 'majority of databases) or you can choose to ignore all databases by ' + . 'default and allow only certain databases to be replicated. ' + . 'Please select the mode:' + ) . '

    '; $html .= '' . __('errors.'); - $html .= ' '; + $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; @@ -285,9 +309,13 @@ function PMA_getHtmlForNotServerReplication() $html = '
    '; $html .= '' . __('Master replication') . ''; - $html .= sprintf(__('This server is not configured as master in a replication process. ' - . 'Would you like to configure it?'), 'server_replication.php' - . PMA_generate_common_url($_url_params)); + $html .= sprintf( + __( + 'This server is not configured as master in a replication process. ' + . 'Would you like to configure it?' + ), + 'server_replication.php' . PMA_generate_common_url($_url_params) + ); $html .= '
    '; return $html; } @@ -313,12 +341,14 @@ function PMA_getHtmlForReplicationDbMultibox() $is_selected = ''; } $current_db = htmlspecialchars($current_db); - $multi_values .= ' '; } // end while $multi_values .= ''; - $multi_values .= '
    ' . __('Uncheck All') . ''; + $multi_values .= '
    '; + $multi_values .= __('Uncheck All') . ''; return $multi_values; } @@ -334,57 +364,70 @@ function PMA_getHtmlForReplicationDbMultibox() function PMA_getHtmlForReplicationChangeMaster($submitname) { $html = ''; - list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length(); + list($username_length, $hostname_length) + = PMA_replicationGetUsernameHostnameLength(); $html .= '
    '; $html .= PMA_generate_common_hidden_inputs('', ''); $html .= '
    '; $html .= ' ' . __('Slave configuration'); $html .= ' - ' . __('Change or reconfigure master server') . ''; - $html .= __('Make sure, you have unique server-id in your configuration file (my.cnf). ' - . 'If not, please add the following line into [mysqld] section:') . '
    '; + $html .= __( + 'Make sure, you have unique server-id in your configuration file (my.cnf). ' + . 'If not, please add the following line into [mysqld] section:' + ); + $html .= '
    '; $html .= '
    server-id=' . time() . '
    '; - $html .= PMA_getHtmlForAddUserInputDiv(array('text'=>__('User name:'), 'for'=>"text_username"), - array('type'=>'text', - 'name'=>'username', - 'id'=>'text_username', - 'maxlength'=>$username_length, - 'title'=>__('User name') - ) - ); + $html .= PMA_getHtmlForAddUserInputDiv( + array('text'=>__('User name:'), 'for'=>"text_username"), + array( + 'type'=>'text', + 'name'=>'username', + 'id'=>'text_username', + 'maxlength'=>$username_length, + 'title'=>__('User name') + ) + ); - $html .= PMA_getHtmlForAddUserInputDiv(array('text'=>__('Password:'), 'for'=>"text_pma_pw"), - array('type'=>'password', - 'name'=>'pma_pw', - 'id'=>'text_pma_pw', - 'title'=>__('Password') - ) - ); + $html .= PMA_getHtmlForAddUserInputDiv( + array('text'=>__('Password:'), 'for'=>"text_pma_pw"), + array( + 'type'=>'password', + 'name'=>'pma_pw', + 'id'=>'text_pma_pw', + 'title'=>__('Password') + ) + ); - $html .= PMA_getHtmlForAddUserInputDiv(array('text'=>__('Host:'), 'for'=>"text_hostname"), - array('type'=>'text', - 'name'=>'hostname', - 'id'=>'text_hostname', - 'maxlength'=>$hostname_length, - 'value'=>'' - ) - ); + $html .= PMA_getHtmlForAddUserInputDiv( + array('text'=>__('Host:'), 'for'=>"text_hostname"), + array( + 'type'=>'text', + 'name'=>'hostname', + 'id'=>'text_hostname', + 'maxlength'=>$hostname_length, + 'value'=>'' + ) + ); - $html .= PMA_getHtmlForAddUserInputDiv(array('text'=>__('Port:'), 'for'=>"text_port"), - array('type'=>'text', - 'name'=>'text_port', - 'id'=>'text_port', - 'maxlength'=>6, - 'value'=>'3306' - ) - ); + $html .= PMA_getHtmlForAddUserInputDiv( + array('text'=>__('Port:'), 'for'=>"text_port"), + array( + 'type'=>'text', + 'name'=>'text_port', + 'id'=>'text_port', + 'maxlength'=>6, + 'value'=>'3306' + ) + ); $html .= '
    '; $html .= ' '; $html .= '
    '; @@ -394,8 +437,8 @@ function PMA_getHtmlForReplicationChangeMaster($submitname) /** * returns HTML code for Add user input div * - * @param Array $label_array label tag elements - * @param Array $input_array input tag elements + * @param Array $label_array label tag elements + * @param Array $input_array input tag elements * * @return String HTML code */ @@ -406,8 +449,9 @@ function PMA_getHtmlForAddUserInputDiv($label_array, $input_array) $html .= $label_array['text'] . ''; $html .= ' $value) + foreach ($input_array as $key=>$value) { $html .= ' ' . $key . '="' . $value. '" '; + } $html .= ' />'; $html .= ' '; return $html; @@ -433,9 +477,12 @@ function PMA_getHtmlForReplicationStatusTable($type, $hidden = false, $title = t $html = ''; // TODO check the Masters server id? - // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects - // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236) - // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log + // seems to default to '1' when queried via SHOW VARIABLES , + // but resulted in error on the master when slave connects + // [ERROR] Error reading packet from server: Misconfigured master + // - server id was not set ( server_errno=1236) + // [ERROR] Got fatal error 1236: 'Misconfigured master + // - server id was not set' from master when reading data from binary log // //$server_id = $GLOBALS['dbi']->fetchValue("SHOW VARIABLES LIKE 'server_id'", 0, 1); @@ -479,7 +526,8 @@ function PMA_getHtmlForReplicationStatusTable($type, $hidden = false, $title = t $html .= ''; } elseif (isset(${"{$type}_variables_oks"}[$variable]) - && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable] + && ${"{$type}_variables_oks"}[$variable] + == ${"server_{$type}_replication"}[0][$variable] ) { $html .= ''; } else { @@ -491,7 +539,11 @@ function PMA_getHtmlForReplicationStatusTable($type, $hidden = false, $title = t 'Replicate_Do_Table', 'Replicate_Ignore_Table', 'Replicate_Wild_Do_Table', 'Replicate_Wild_Ignore_Table'); if (in_array($variable, $variables_wrap)) { - $html .= str_replace(',', ', ', ${"server_{$type}_replication"}[0][$variable]); + $html .= str_replace( + ',', + ', ', + ${"server_{$type}_replication"}[0][$variable] + ); } else { $html .= ${"server_{$type}_replication"}[0][$variable]; } @@ -514,7 +566,8 @@ function PMA_getHtmlForReplicationStatusTable($type, $hidden = false, $title = t /** * returns html code for table with slave users connected to this master * - * @param boolean $hidden - if true, then default style is set to hidden, default value false + * @param boolean $hidden - if true, then default style is set to hidden, + * - default value false * * @return void */ @@ -549,8 +602,12 @@ function PMA_getHtmlForReplicationSlavesTable($hidden = false) $html .= ' '; $html .= ' '; $html .= '
    '; - $html .= PMA_Message::notice(__('Only slaves started with the ' - . '--report-host=host_name option are visible in this list.'))->getDisplay(); + $html .= PMA_Message::notice( + __( + 'Only slaves started with the ' + . '--report-host=host_name option are visible in this list.' + ) + )->getDisplay(); $html .= '
    '; $html .= ' '; @@ -563,7 +620,7 @@ function PMA_getHtmlForReplicationSlavesTable($hidden = false) * @return array username length, hostname length */ -function PMA_replication_get_username_hostname_length() +function PMA_replicationGetUsernameHostnameLength() { $fields_info = $GLOBALS['dbi']->getColumns('mysql', 'user'); $username_length = 16; @@ -594,13 +651,15 @@ function PMA_replication_get_username_hostname_length() function PMA_getHtmlForReplicationMasterAddSlaveuser() { $html = ''; - list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length(); + list($username_length, $hostname_length) + = PMA_replicationGetUsernameHostnameLength(); if (isset($_REQUEST['username']) && strlen($_REQUEST['username']) === 0) { $GLOBALS['pred_username'] = 'any'; } $html .= '
    '; - $html .= '
    fetchValue('SELECT USER();'); if (! empty($_current_user)) { - $thishost = str_replace("'", - '', - substr($_current_user, (strrpos($_current_user, '@') + 1)) - ); + $thishost = str_replace( + "'", + '', + substr($_current_user, (strrpos($_current_user, '@') + 1)) + ); if ($thishost == 'localhost' || $thishost == '127.0.0.1') { unset($thishost); } } $html .= ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } ' - . 'else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } ' + . 'else if (this.value == \'localhost\') ' + . '{ hostname.value = \'localhost\'; } ' . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ') . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } ' - . 'else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' + . 'else if (this.value == \'userdefined\') ' + . '{ hostname.focus(); hostname.select(); }">' . "\n"; unset($_current_user); @@ -655,13 +717,15 @@ function PMA_getHtmlForReplicationMasterAddSlaveuser() ? ' selected="selected"' : '') . '>' . __('Any host') . '' . ' '; if (!empty($thishost)) { $html .= ' '; } @@ -685,8 +749,10 @@ function PMA_getHtmlForAddUserLoginForm($username_length) $html = '' . '' . '' - . '' + . ' ' . '' . '
    ' @@ -694,22 +760,28 @@ function PMA_getHtmlForAddUserLoginForm($username_length) . ' ' . __('User name:') . '' . '' - . ' ' . '' . '' . '
    '; @@ -726,11 +798,13 @@ function PMA_getHtmlForAddUserLoginForm($username_length) function PMA_getHtmlForTableInfoForm($hostname_length) { $html = ' ' . ' ' . ' ' @@ -741,7 +815,10 @@ function PMA_getHtmlForTableInfoForm($hostname_length) . '" title="' . __('Host') . '" onchange="pred_hostname.value = \'userdefined\';" />' . PMA_Util::showHint( - __('When Host table is used, this field is ignored and values stored in Host table are used instead.') + __( + 'When Host table is used, this field is ignored ' + . 'and values stored in Host table are used instead.' + ) ) . '
    ' . '
    ' @@ -751,8 +828,10 @@ function PMA_getHtmlForTableInfoForm($hostname_length) . '' . ' ' + . ' ' . '' . '' . '
    ' @@ -792,4 +872,133 @@ function PMA_getHtmlForTableInfoForm($hostname_length) return $html; } +/** + * handle control requests + * + * @return NULL + */ +function PMA_handleControlRequest() +{ + if (isset($_REQUEST['sr_take_action'])) { + $refresh = false; + if (isset($_REQUEST['slave_changemaster'])) { + PMA_handleRequestForSlaveChangeMaster(); + } elseif (isset($_REQUEST['sr_slave_server_control'])) { + PMA_handleRequestForSlaveServerControl(); + } elseif (isset($_REQUEST['sr_slave_skip_error'])) { + PMA_handleRequestForSlaveSkipError(); + } + + if ($refresh) { + Header( + "Location: server_replication.php" + . PMA_generate_common_url($GLOBALS['url_params']) + ); + } + unset($refresh); + } +} +/** + * handle control requests for Slave Change Master + * + * @return NULL + */ +function PMA_handleRequestForSlaveChangeMaster() +{ + $_SESSION['replication']['m_username'] = $sr['username'] + = PMA_Util::sqlAddSlashes($_REQUEST['username']); + $_SESSION['replication']['m_password'] = $sr['pma_pw'] + = PMA_Util::sqlAddSlashes($_REQUEST['pma_pw']); + $_SESSION['replication']['m_hostname'] = $sr['hostname'] + = PMA_Util::sqlAddSlashes($_REQUEST['hostname']); + $_SESSION['replication']['m_port'] = $sr['port'] + = PMA_Util::sqlAddSlashes($_REQUEST['port']); + $_SESSION['replication']['m_correct'] = ''; + $_SESSION['replication']['sr_action_status'] = 'error'; + $_SESSION['replication']['sr_action_info'] = __('Unknown error'); + + // Attempt to connect to the new master server + $link_to_master = PMA_Replication_connectToMaster( + $sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port'] + ); + + if (! $link_to_master) { + $_SESSION['replication']['sr_action_status'] = 'error'; + $_SESSION['replication']['sr_action_info'] = sprintf( + __('Unable to connect to master %s.'), + htmlspecialchars($sr['hostname']) + ); + } else { + // Read the current master position + $position = PMA_Replication_Slave_binLogMaster($link_to_master); + + if (empty($position)) { + $_SESSION['replication']['sr_action_status'] = 'error'; + $_SESSION['replication']['sr_action_info'] + = __( + 'Unable to read master log position. ' + . 'Possible privilege problem on master.' + ); + } else { + $_SESSION['replication']['m_correct'] = true; + + if (! PMA_Replication_Slave_changeMaster( + $sr['username'], + $sr['pma_pw'], + $sr['hostname'], + $sr['port'], + $position, + true, + false + ) + ) { + $_SESSION['replication']['sr_action_status'] = 'error'; + $_SESSION['replication']['sr_action_info'] + = __('Unable to change master'); + } else { + $_SESSION['replication']['sr_action_status'] = 'success'; + $_SESSION['replication']['sr_action_info'] = sprintf( + __('Master server changed successfully to %s'), + htmlspecialchars($sr['hostname']) + ); + } + } + } +} + +/** + * handle control requests for Slave Server Control + * + * @return NULL + */ +function PMA_handleRequestForSlaveServerControl() +{ + if ($_REQUEST['sr_slave_action'] == 'reset') { + PMA_Replication_Slave_control("STOP"); + $GLOBALS['dbi']->tryQuery("RESET SLAVE;"); + PMA_Replication_Slave_control("START"); + } else { + PMA_Replication_Slave_control( + $_REQUEST['sr_slave_action'], + $_REQUEST['sr_slave_control_parm'] + ); + } + $refresh = true; +} + +/** + * handle control requests for Slave Skip Error + * + * @return NULL + */ +function PMA_handleRequestForSlaveSkipError() +{ + $count = 1; + if (isset($_REQUEST['sr_skip_errors_count'])) { + $count = $_REQUEST['sr_skip_errors_count'] * 1; + } + PMA_Replication_Slave_control("STOP"); + $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";"); + PMA_Replication_Slave_control("START"); +} ?> diff --git a/server_replication.php b/server_replication.php index f1e196da03..022e389b8b 100644 --- a/server_replication.php +++ b/server_replication.php @@ -40,87 +40,7 @@ if (isset($_REQUEST['url_params'])) { /** * Handling control requests */ -if (isset($_REQUEST['sr_take_action'])) { - $refresh = false; - if (isset($_REQUEST['slave_changemaster'])) { - $_SESSION['replication']['m_username'] = $sr['username'] = PMA_Util::sqlAddSlashes($_REQUEST['username']); - $_SESSION['replication']['m_password'] = $sr['pma_pw'] = PMA_Util::sqlAddSlashes($_REQUEST['pma_pw']); - $_SESSION['replication']['m_hostname'] = $sr['hostname'] = PMA_Util::sqlAddSlashes($_REQUEST['hostname']); - $_SESSION['replication']['m_port'] = $sr['port'] = PMA_Util::sqlAddSlashes($_REQUEST['port']); - $_SESSION['replication']['m_correct'] = ''; - $_SESSION['replication']['sr_action_status'] = 'error'; - $_SESSION['replication']['sr_action_info'] = __('Unknown error'); - - // Attempt to connect to the new master server - $link_to_master = PMA_Replication_connectToMaster( - $sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port'] - ); - - if (! $link_to_master) { - $_SESSION['replication']['sr_action_status'] = 'error'; - $_SESSION['replication']['sr_action_info'] = sprintf( - __('Unable to connect to master %s.'), - htmlspecialchars($sr['hostname']) - ); - } else { - // Read the current master position - $position = PMA_Replication_Slave_binLogMaster($link_to_master); - - if (empty($position)) { - $_SESSION['replication']['sr_action_status'] = 'error'; - $_SESSION['replication']['sr_action_info'] = - __('Unable to read master log position. Possible privilege problem on master.'); - } else { - $_SESSION['replication']['m_correct'] = true; - - if (! PMA_Replication_Slave_changeMaster( - $sr['username'], - $sr['pma_pw'], - $sr['hostname'], - $sr['port'], - $position, - true, - false)) { - $_SESSION['replication']['sr_action_status'] = 'error'; - $_SESSION['replication']['sr_action_info'] = __('Unable to change master'); - } else { - $_SESSION['replication']['sr_action_status'] = 'success'; - $_SESSION['replication']['sr_action_info'] = sprintf( - __('Master server changed successfully to %s'), - htmlspecialchars($sr['hostname']) - ); - } - } - } - } elseif (isset($_REQUEST['sr_slave_server_control'])) { - if ($_REQUEST['sr_slave_action'] == 'reset') { - PMA_Replication_Slave_control("STOP"); - $GLOBALS['dbi']->tryQuery("RESET SLAVE;"); - PMA_Replication_Slave_control("START"); - } else { - PMA_Replication_Slave_control( - $_REQUEST['sr_slave_action'], - $_REQUEST['sr_slave_control_parm'] - ); - } - $refresh = true; - - } elseif (isset($_REQUEST['sr_slave_skip_error'])) { - $count = 1; - if (isset($_REQUEST['sr_skip_errors_count'])) { - $count = $_REQUEST['sr_skip_errors_count'] * 1; - } - PMA_Replication_Slave_control("STOP"); - $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";"); - PMA_Replication_Slave_control("START"); - - } - - if ($refresh) { - Header("Location: server_replication.php" . PMA_generate_common_url($GLOBALS['url_params'])); - } - unset($refresh); -} +PMA_handleControlRequest(); /** * start output @@ -133,7 +53,8 @@ $response->addHTML(PMA_getHtmlForErrorMessage()); if ($server_master_status) { $response->addHTML(PMA_getHtmlForMasterReplication()); -} elseif (! isset($_REQUEST['mr_configure']) && ! isset($_REQUEST['repl_clear_scr'])) { +} elseif (! isset($_REQUEST['mr_configure']) && + ! isset($_REQUEST['repl_clear_scr'])) { $response->addHTML(PMA_getHtmlForNotServerReplication()); } @@ -147,7 +68,12 @@ $response->addHTML(''); if (! isset($_REQUEST['repl_clear_scr'])) { // Render the 'Slave configuration' section - $response->addHTML(PMA_getHtmlForSlaveConfiguration($server_slave_status, $server_slave_replication)); + $response->addHTML( + PMA_getHtmlForSlaveConfiguration( + $server_slave_status, + $server_slave_replication + ) + ); } if (isset($_REQUEST['sl_configure'])) { $response->addHTML(PMA_getHtmlForReplicationChangeMaster("slave_changemaster"));