getDisplay(); $_SESSION['replication']['sr_action_status'] = 'unknown'; } elseif ($_SESSION['replication']['sr_action_status'] == 'success') { $success_message = $_SESSION['replication']['sr_action_info']; $html .= PMA_Message::success($success_message)->getDisplay(); $_SESSION['replication']['sr_action_status'] = 'unknown'; } } return $html; } /** * returns HTML for master replication * * @return String HTML code */ function PMA_getHtmlForMasterReplication() { $html = ''; if (! isset($_REQUEST['repl_clear_scr'])) { $html .= '
'; $html .= '' . __('Master replication') . ''; $html .= __('This server is configured as master in a replication process.'); $html .= '"; $html .= "
"; } return $html; } /** * returns HTML for master replication configuration * * @return String HTML code */ 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 .= ''; $html .= '

'; $html .= __('Please select databases:') . '
'; $html .= PMA_getHtmlForReplicationDbMultibox(); $html .= '

'; $html .= __( 'Now, add the following lines at the end of [mysqld] section' . ' in your my.cnf and please restart the MySQL server afterwards.' ). '
'; $html .= '
';
    $html .= __(
        'Once you restarted MySQL server, please click on Go button. '
        . 'Afterwards, you should see a message informing you, that this server'
        . ' is configured as master.'
    );
    $html .= '
'; $html .= '
'; $html .= '
'; $html .= PMA_URL_getHiddenInputs('', ''); $html .= ' '; $html .= '
'; $html .= '
'; return $html; } /** * returns HTML for slave replication configuration * * @param bool $server_slave_status Whether it is Master or Slave * @param Array $server_slave_replication Slave replication * * @return String HTML code */ function PMA_getHtmlForSlaveConfiguration( $server_slave_status, $server_slave_replication ) { $html = '
'; $html .= '' . __('Slave replication') . ''; if ($server_slave_status) { $html .= '
'; $_url_params = $GLOBALS['url_params']; $_url_params['sr_take_action'] = true; $_url_params['sr_slave_server_control'] = true; if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') { $_url_params['sr_slave_action'] = 'start'; } else { $_url_params['sr_slave_action'] = 'stop'; } $_url_params['sr_slave_control_parm'] = 'IO_THREAD'; $slave_control_io_link = 'server_replication.php' . PMA_URL_getCommon($_url_params); if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') { $_url_params['sr_slave_action'] = 'start'; } else { $_url_params['sr_slave_action'] = 'stop'; } $_url_params['sr_slave_control_parm'] = 'SQL_THREAD'; $slave_control_sql_link = 'server_replication.php' . PMA_URL_getCommon($_url_params); if ($server_slave_replication[0]['Slave_IO_Running'] == 'No' || $server_slave_replication[0]['Slave_SQL_Running'] == 'No' ) { $_url_params['sr_slave_action'] = 'start'; } else { $_url_params['sr_slave_action'] = 'stop'; } $_url_params['sr_slave_control_parm'] = null; $slave_control_full_link = 'server_replication.php' . PMA_URL_getCommon($_url_params); $_url_params['sr_slave_action'] = 'reset'; $slave_control_reset_link = 'server_replication.php' . PMA_URL_getCommon($_url_params); $_url_params = $GLOBALS['url_params']; $_url_params['sr_slave_skip_error'] = true; $slave_skip_error_link = 'server_replication.php' . PMA_URL_getCommon($_url_params); if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') { $html .= PMA_Message::error( __('Slave SQL Thread not running!') )->getDisplay(); } if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') { $html .= PMA_Message::error( __('Slave IO Thread not running!') )->getDisplay(); } $_url_params = $GLOBALS['url_params']; $_url_params['sl_configure'] = true; $_url_params['repl_clear_scr'] = true; $reconfiguremaster_link = 'server_replication.php' . PMA_URL_getCommon($_url_params); $html .= __('Server is configured as slave in a replication process. Would you like to:'); $html .= '
'; $html .= ''; $html .= '
'; } elseif (! isset($_REQUEST['sl_configure'])) { $_url_params = $GLOBALS['url_params']; $_url_params['sl_configure'] = true; $_url_params['repl_clear_scr'] = true; $html .= sprintf( __( 'This server is not configured as slave in a replication process. ' . 'Would you like to configure it?' ), 'server_replication.php' . PMA_URL_getCommon($_url_params) ); } $html .= '
'; return $html; } /** * returns HTML for Slave Error Management * * @param String $slave_skip_error_link error link * * @return String HTML code */ function PMA_getHtmlForSlaveErrorManagement($slave_skip_error_link) { $html = ''; $html .= __('Error management:') . ''; $html .= ' '; return $html; } /** * returns HTML for not configure for a server replication * * @return String HTML code */ function PMA_getHtmlForNotServerReplication() { $_url_params = $GLOBALS['url_params']; $_url_params['mr_configure'] = true; $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_URL_getCommon($_url_params) ); $html .= '
'; return $html; } /** * returns HTML code for selecting databases * * @return String HTML code */ function PMA_getHtmlForReplicationDbMultibox() { $multi_values = ''; $multi_values .= ''; $multi_values .= '
'; $multi_values .= __('Uncheck All') . ''; return $multi_values; } /** * returns HTML for changing master * * @param String $submitname - submit button name * * @return String HTML code */ function PMA_getHtmlForReplicationChangeMaster($submitname) { $html = ''; list($username_length, $hostname_length) = PMA_replicationGetUsernameHostnameLength(); $html .= '
'; $html .= PMA_URL_getHiddenInputs('', ''); $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 .= '
'; $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'), 'required'=>'required' ) ); $html .= PMA_getHtmlForAddUserInputDiv( array('text'=>__('Password:'), 'for'=>"text_pma_pw"), array( 'type'=>'password', 'name'=>'pma_pw', 'id'=>'text_pma_pw', 'title'=>__('Password'), 'required'=>'required' ) ); $html .= PMA_getHtmlForAddUserInputDiv( array('text'=>__('Host:'), 'for'=>"text_hostname"), array( 'type'=>'text', 'name'=>'hostname', 'id'=>'text_hostname', 'maxlength'=>$hostname_length, 'value'=>'', 'required'=>'required' ) ); $html .= PMA_getHtmlForAddUserInputDiv( array('text'=>__('Port:'), 'for'=>"text_port"), array( 'type'=>'number', 'name'=>'text_port', 'id'=>'text_port', 'maxlength'=>6, 'value'=>'3306', 'required'=>'required' ) ); $html .= '
'; $html .= ' '; $html .= '
'; return $html; } /** * returns HTML code for Add user input div * * @param Array $label_array label tag elements * @param Array $input_array input tag elements * * @return String HTML code */ function PMA_getHtmlForAddUserInputDiv($label_array, $input_array) { $html = '
'; $html .= ' '; $html .= ' $value) { $html .= ' ' . $key . '="' . $value. '" '; } $html .= ' />'; $html .= '
'; return $html; } /** * This function returns html code for table with replication status. * * @param string $type either master or slave * @param boolean $hidden if true, then default style is set to hidden, * default value false * @param boolean $title if true, then title is displayed, default true * * @return String HTML code */ function PMA_getHtmlForReplicationStatusTable($type, $hidden = false, $title = true) { global ${"{$type}_variables"}; global ${"{$type}_variables_alerts"}; global ${"{$type}_variables_oks"}; global ${"server_{$type}_replication"}; global ${"strReplicationStatus_{$type}"}; $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 // //$server_id = $GLOBALS['dbi']->fetchValue( // "SHOW VARIABLES LIKE 'server_id'", 0, 1 //); $html .= '
'; if ($title) { if ($type == 'master') { $html .= '

'; $html .= __('Master status') . '

'; } else { $html .= '

'; $html .= __('Slave status') . '

'; } } else { $html .= '
'; } $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $odd_row = true; foreach (${"{$type}_variables"} as $variable) { $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $odd_row = ! $odd_row; } $html .= ' '; $html .= '
' . __('Variable') . '' . __('Value') . '
'; $html .= $variable; $html .= ' '; // TODO change to regexp or something, to allow for negative match if (isset(${"{$type}_variables_alerts"}[$variable]) && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable] ) { $html .= ''; } elseif (isset(${"{$type}_variables_oks"}[$variable]) && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable] ) { $html .= ''; } else { $html .= ''; } // allow wrapping long table lists into multiple lines static $variables_wrap = array( 'Replicate_Do_DB', 'Replicate_Ignore_DB', '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] ); } else { $html .= ${"server_{$type}_replication"}[0][$variable]; } $html .= ''; $html .= '
'; $html .= '
'; $html .= '
'; return $html; } /** * 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 * * @return string */ function PMA_getHtmlForReplicationSlavesTable($hidden = false) { $html = ''; // Fetch data $data = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null); $html .= '
'; $html .= '
'; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $odd_row = true; foreach ($data as $slave) { $html .= ' '; $html .= ' '; $html .= ' '; $html .= ' '; $odd_row = ! $odd_row; } $html .= ' '; $html .= '
' . __('Server ID') . '' . __('Host') . '
' . $slave['Server_id'] . '' . $slave['Host'] . '
'; $html .= '
'; $html .= PMA_Message::notice( __( 'Only slaves started with the ' . '--report-host=host_name option are visible in this list.' ) )->getDisplay(); $html .= '
'; $html .= '
'; return $html; } /** * get the correct username and hostname lengths for this MySQL server * * @return array username length, hostname length */ function PMA_replicationGetUsernameHostnameLength() { $fields_info = $GLOBALS['dbi']->getColumns('mysql', 'user'); $username_length = 16; $hostname_length = 41; foreach ($fields_info as $val) { if ($val['Field'] == 'User') { strtok($val['Type'], '()'); $v = strtok('()'); if (is_int($v)) { $username_length = $v; } } elseif ($val['Field'] == 'Host') { strtok($val['Type'], '()'); $v = strtok('()'); if (is_int($v)) { $hostname_length = $v; } } } return array($username_length, $hostname_length); } /** * returns html code to add a replication slave user to the master * * @return String HTML code */ function PMA_getHtmlForReplicationMasterAddSlaveuser() { $html = ''; list($username_length, $hostname_length) = PMA_replicationGetUsernameHostnameLength(); if (isset($_REQUEST['username']) && strlen($_REQUEST['username']) === 0) { $GLOBALS['pred_username'] = 'any'; } $html .= '
'; $html .= '
' . __('Add slave replication user') . '' . PMA_getHtmlForAddUserLoginForm($username_length) . '
' . '' . '' . ' ' . '' . '' . ' ' . '' . '
' . '' . '' . ' ' . '' . '' . '
'; return $html; } /** * returns HTML for TableInfoForm * * @param int $hostname_length Selected hostname length * * @return String HTML code */ function PMA_getHtmlForTableInfoForm($hostname_length) { $html = ' ' . ' ' . ' ' . '
' . '' . PMA_Util::showHint( __( 'When Host table is used, this field is ignored ' . 'and values stored in Host table are used instead.' ) ) . '
' . '
' . '' . '' . ' ' . '' . '' . '
' . '
' . '' . ' ' . '' . '
' . '
' . '' . '' . ' ' . '' . '' . '
' . ''; $html .= ''; return $html; } /** * handle control requests * * @return NULL */ function PMA_handleControlRequest() { if (isset($_REQUEST['sr_take_action'])) { $refresh = false; $result = null; $messageSuccess = null; $messageError = null; if (isset($_REQUEST['slave_changemaster'])) { $result = PMA_handleRequestForSlaveChangeMaster(); } elseif (isset($_REQUEST['sr_slave_server_control'])) { $result = PMA_handleRequestForSlaveServerControl(); $refresh = true; switch ($_REQUEST['sr_slave_action']) { case 'start': $messageSuccess = __('Replication started successfully.'); $messageError = __('Error starting replication.'); break; case 'stop': $messageSuccess = __('Replication stopped successfully.'); $messageError = __('Error stopping replication.'); break; case 'reset': $messageSuccess = __('Replication resetting successfully.'); $messageError = __('Error resetting replication.'); break; default: $messageSuccess = __('Success.'); $messageError = __('Error.'); break; } } elseif (isset($_REQUEST['sr_slave_skip_error'])) { $result = PMA_handleRequestForSlaveSkipError(); } if ($refresh) { $response = PMA_Response::getInstance(); if ($response->isAjax()) { $response->isSuccess($result); $response->addJSON( 'message', $result ? PMA_Message::success($messageSuccess) : PMA_Message::error($messageError) ); } else { PMA_sendHeaderLocation( $GLOBALS['cfg']['PmaAbsoluteUri'] . 'server_replication.php' . PMA_URL_getCommon($GLOBALS['url_params'], '&') ); } } unset($refresh); } } /** * handle control requests for Slave Change Master * * @return boolean */ 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']) ); } } } return $_SESSION['replication']['sr_action_status'] === 'success'; } /** * handle control requests for Slave Server Control * * @return boolean */ function PMA_handleRequestForSlaveServerControl() { if (empty($_REQUEST['sr_slave_control_parm'])) { $_REQUEST['sr_slave_control_parm'] = null; } if ($_REQUEST['sr_slave_action'] == 'reset') { $qStop = PMA_Replication_Slave_control("STOP"); $qReset = $GLOBALS['dbi']->tryQuery("RESET SLAVE;"); $qStart = PMA_Replication_Slave_control("START"); $result = ($qStop !== false && $qStop !== -1 && $qReset !== false && $qReset !== -1 && $qStart !== false && $qStart !== -1); } else { $qControl = PMA_Replication_Slave_control( $_REQUEST['sr_slave_action'], $_REQUEST['sr_slave_control_parm'] ); $result = ($qControl !== false && $qControl !== -1); } return $result; } /** * handle control requests for Slave Skip Error * * @return boolean */ function PMA_handleRequestForSlaveSkipError() { $count = 1; if (isset($_REQUEST['sr_skip_errors_count'])) { $count = $_REQUEST['sr_skip_errors_count'] * 1; } $qStop = PMA_Replication_Slave_control("STOP"); $qSkip = $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";"); $qStart = PMA_Replication_Slave_control("START"); $result = ($qStop !== false && $qStop !== -1 && $qSkip !== false && $qSkip !== -1 && $qStart !== false && $qStart !== -1); return $result; } ?>