Skip to content

Commit

Permalink
Retrieve parameters from $_POST in server replication
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed Nov 10, 2018
1 parent a98207c commit eb13c69
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 72 deletions.
110 changes: 53 additions & 57 deletions libraries/classes/ReplicationGui.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function getHtmlForErrorMessage()
public static function getHtmlForMasterReplication()
{
$html = '';
if (! isset($_REQUEST['repl_clear_scr'])) {
if (! isset($_POST['repl_clear_scr'])) {
$html .= '<fieldset>';
$html .= '<legend>' . __('Master replication') . '</legend>';
$html .= __('This server is configured as master in a replication process.');
Expand All @@ -72,16 +72,16 @@ public static function getHtmlForMasterReplication()
$_url_params['mr_adduser'] = true;
$_url_params['repl_clear_scr'] = true;

$html .= ' <li><a href="server_replication.php';
$html .= Url::getCommon($_url_params)
$html .= ' <li><a href="server_replication.php" data-post="';
$html .= Url::getCommon($_url_params, '')
. '" id="master_addslaveuser_href">';
$html .= __('Add slave replication user') . '</a></li>';
}

// Display 'Add replication slave user' form
if (isset($_REQUEST['mr_adduser'])) {
if (isset($_POST['mr_adduser'])) {
$html .= self::getHtmlForReplicationMasterAddSlaveUser();
} elseif (! isset($_REQUEST['repl_clear_scr'])) {
} elseif (! isset($_POST['repl_clear_scr'])) {
$html .= "</ul>";
$html .= "</fieldset>";
}
Expand Down Expand Up @@ -164,8 +164,8 @@ public static function getHtmlForSlaveConfiguration(
$html .= ' <select name="master_connection">';
$html .= '<option value="">' . __('Default') . '</option>';
foreach ($server_slave_multi_replication as $server) {
$html .= '<option' . (isset($_REQUEST['master_connection'])
&& $_REQUEST['master_connection'] == $server['Connection_name'] ?
$html .= '<option' . (isset($_POST['master_connection'])
&& $_POST['master_connection'] == $server['Connection_name'] ?
' selected="selected"' : '') . '>' . $server['Connection_name']
. '</option>';
}
Expand All @@ -188,8 +188,7 @@ public static function getHtmlForSlaveConfiguration(
}

$_url_params['sr_slave_control_parm'] = 'IO_THREAD';
$slave_control_io_link = 'server_replication.php'
. Url::getCommon($_url_params);
$slave_control_io_link = Url::getCommon($_url_params, '');

if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
$_url_params['sr_slave_action'] = 'start';
Expand All @@ -198,8 +197,7 @@ public static function getHtmlForSlaveConfiguration(
}

$_url_params['sr_slave_control_parm'] = 'SQL_THREAD';
$slave_control_sql_link = 'server_replication.php'
. Url::getCommon($_url_params);
$slave_control_sql_link = Url::getCommon($_url_params, '');

if ($server_slave_replication[0]['Slave_IO_Running'] == 'No'
|| $server_slave_replication[0]['Slave_SQL_Running'] == 'No'
Expand All @@ -210,18 +208,15 @@ public static function getHtmlForSlaveConfiguration(
}

$_url_params['sr_slave_control_parm'] = null;
$slave_control_full_link = 'server_replication.php'
. Url::getCommon($_url_params);
$slave_control_full_link = Url::getCommon($_url_params, '');

$_url_params['sr_slave_action'] = 'reset';
$slave_control_reset_link = 'server_replication.php'
. Url::getCommon($_url_params);
$slave_control_reset_link = Url::getCommon($_url_params, '');

$_url_params = $GLOBALS['url_params'];
$_url_params['sr_take_action'] = true;
$_url_params['sr_slave_skip_error'] = true;
$slave_skip_error_link = 'server_replication.php'
. Url::getCommon($_url_params);
$slave_skip_error_link = Url::getCommon($_url_params, '');

if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
$html .= Message::error(
Expand All @@ -238,8 +233,7 @@ public static function getHtmlForSlaveConfiguration(
$_url_params['sl_configure'] = true;
$_url_params['repl_clear_scr'] = true;

$reconfiguremaster_link = 'server_replication.php'
. Url::getCommon($_url_params);
$reconfiguremaster_link = Url::getCommon($_url_params, '');

$html .= __(
'Server is configured as slave in a replication process. Would you ' .
Expand All @@ -256,26 +250,26 @@ public static function getHtmlForSlaveConfiguration(
$html .= __('Control slave:') . '</a>';
$html .= ' <div id="slave_control_gui" class="hide">';
$html .= ' <ul>';
$html .= ' <li><a href="' . $slave_control_full_link . '">';
$html .= ' <li><a href="server_replication.php" data-post="' . $slave_control_full_link . '">';
$html .= (($server_slave_replication[0]['Slave_IO_Running'] == 'No' ||
$server_slave_replication[0]['Slave_SQL_Running'] == 'No')
? __('Full start')
: __('Full stop')) . ' </a></li>';
$html .= ' <li><a class="ajax" id="reset_slave"'
. ' href="' . $slave_control_reset_link . '">';
. ' href="server_replication.php" data-post="' . $slave_control_reset_link . '">';
$html .= __('Reset slave') . '</a></li>';
if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
$html .= ' <li><a href="' . $slave_control_sql_link . '">';
$html .= ' <li><a href="server_replication.php" data-post="' . $slave_control_sql_link . '">';
$html .= __('Start SQL Thread only') . '</a></li>';
} else {
$html .= ' <li><a href="' . $slave_control_sql_link . '">';
$html .= ' <li><a href="server_replication.php" data-post="' . $slave_control_sql_link . '">';
$html .= __('Stop SQL Thread only') . '</a></li>';
}
if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
$html .= ' <li><a href="' . $slave_control_io_link . '">';
$html .= ' <li><a href="server_replication.php" data-post="' . $slave_control_io_link . '">';
$html .= __('Start IO Thread only') . '</a></li>';
} else {
$html .= ' <li><a href="' . $slave_control_io_link . '">';
$html .= ' <li><a href="server_replication.php" data-post="' . $slave_control_io_link . '">';
$html .= __('Stop IO Thread only') . '</a></li>';
}
$html .= ' </ul>';
Expand All @@ -284,22 +278,23 @@ public static function getHtmlForSlaveConfiguration(
$html .= ' <li>';
$html .= self::getHtmlForSlaveErrorManagement($slave_skip_error_link);
$html .= ' </li>';
$html .= ' <li><a href="' . $reconfiguremaster_link . '">';
$html .= ' <li><a href="server_replication.php" data-post="' . $reconfiguremaster_link . '">';
$html .= __('Change or reconfigure master server') . '</a></li>';
$html .= '</ul>';
$html .= '</div>';

} elseif (! isset($_REQUEST['sl_configure'])) {
} elseif (! isset($_POST['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 <a href="%s">configure</a> it?'
. 'Would you like to %sconfigure%s it?'
),
'server_replication.php' . Url::getCommon($_url_params)
'<a href="server_replication.php" data-post="' . Url::getCommon($_url_params, '') . '">',
'</a>'
);
}
$html .= '</fieldset>';
Expand All @@ -324,7 +319,7 @@ public static function getHtmlForSlaveErrorManagement($slave_skip_error_link)
__('Skipping errors might lead into unsynchronized master and slave!')
)->getDisplay();
$html .= ' <ul>';
$html .= ' <li><a href="' . $slave_skip_error_link . '">';
$html .= ' <li><a href="server_replication.php" data-post="' . $slave_skip_error_link . '">';
$html .= __('Skip current error') . '</a></li>';
$html .= ' <li>';
$html .= ' <form method="post" action="server_replication.php">';
Expand Down Expand Up @@ -358,9 +353,10 @@ public static function getHtmlForNotServerReplication()
$html .= sprintf(
__(
'This server is not configured as master in a replication process. '
. 'Would you like to <a href="%s">configure</a> it?'
. 'Would you like to %sconfigure%s it?'
),
'server_replication.php' . Url::getCommon($_url_params)
'<a href="server_replication.php" data-post="' . Url::getCommon($_url_params, '') . '">',
'</a>'
);
$html .= '</fieldset>';
return $html;
Expand Down Expand Up @@ -693,7 +689,7 @@ public static function getHtmlForReplicationMasterAddSlaveUser()
list($username_length, $hostname_length)
= self::getUsernameHostnameLength();

if (isset($_REQUEST['username']) && strlen($_REQUEST['username']) === 0) {
if (isset($_POST['username']) && strlen($_POST['username']) === 0) {
$GLOBALS['pred_username'] = 'any';
}
$html .= '<div id="master_addslaveuser_gui">';
Expand Down Expand Up @@ -732,8 +728,8 @@ public static function getHtmlForReplicationMasterAddSlaveUser()
unset($_current_user);

// when we start editing a user, $GLOBALS['pred_hostname'] is not defined
if (! isset($GLOBALS['pred_hostname']) && isset($_REQUEST['hostname'])) {
switch (mb_strtolower($_REQUEST['hostname'])) {
if (! isset($GLOBALS['pred_hostname']) && isset($_POST['hostname'])) {
switch (mb_strtolower($_POST['hostname'])) {
case 'localhost':
case '127.0.0.1':
$GLOBALS['pred_hostname'] = 'localhost';
Expand Down Expand Up @@ -810,10 +806,10 @@ public static function getHtmlForAddUserLoginForm($username_length)
. '</span>'
. '<input type="text" name="username" id="pma_username" maxlength="'
. $username_length . '" title="' . __('User name') . '"'
. (empty($_REQUEST['username']) ? '' : ' value="'
. (empty($_POST['username']) ? '' : ' value="'
. (isset($GLOBALS['new_username'])
? $GLOBALS['new_username']
: htmlspecialchars($_REQUEST['username'])) . '"')
: htmlspecialchars($_POST['username'])) . '"')
. ' />'
. '</div>';

Expand Down Expand Up @@ -843,7 +839,7 @@ public static function getHtmlForTableInfoForm($hostname_length)
. '</span>'
. '<input type="text" name="hostname" id="pma_hostname" maxlength="'
. $hostname_length . '" value="'
. (isset($_REQUEST['hostname']) ? htmlspecialchars($_REQUEST['hostname']) : '')
. (isset($_POST['hostname']) ? htmlspecialchars($_POST['hostname']) : '')
. '" title="' . __('Host')
. '" />'
. Util::showHint(
Expand All @@ -861,12 +857,12 @@ public static function getHtmlForTableInfoForm($hostname_length)
. ' <select name="pred_password" id="select_pred_password" title="'
. __('Password') . '">'
. ' <option value="none"';
if (isset($_REQUEST['username'])) {
if (isset($_POST['username'])) {
$html .= ' selected="selected"';
}
$html .= '>' . __('No Password') . '</option>'
. ' <option value="userdefined"'
. (isset($_REQUEST['username']) ? '' : ' selected="selected"')
. (isset($_POST['username']) ? '' : ' selected="selected"')
. '>' . __('Use text field:') . '</option>'
. ' </select>'
. '</span>'
Expand Down Expand Up @@ -907,22 +903,22 @@ public static function getHtmlForTableInfoForm($hostname_length)
*/
public static function handleControlRequest()
{
if (isset($_REQUEST['sr_take_action'])) {
if (isset($_POST['sr_take_action'])) {
$refresh = false;
$result = false;
$messageSuccess = null;
$messageError = null;

if (isset($_REQUEST['slave_changemaster']) && ! $GLOBALS['cfg']['AllowArbitraryServer']) {
if (isset($_POST['slave_changemaster']) && ! $GLOBALS['cfg']['AllowArbitraryServer']) {
$_SESSION['replication']['sr_action_status'] = 'error';
$_SESSION['replication']['sr_action_info'] = __('Connection to server is disabled, please enable $cfg[\'AllowArbitraryServer\'] in phpMyAdmin configuration.');
} elseif (isset($_REQUEST['slave_changemaster'])) {
} elseif (isset($_POST['slave_changemaster'])) {
$result = self::handleRequestForSlaveChangeMaster();
} elseif (isset($_REQUEST['sr_slave_server_control'])) {
} elseif (isset($_POST['sr_slave_server_control'])) {
$result = self::handleRequestForSlaveServerControl();
$refresh = true;

switch ($_REQUEST['sr_slave_action']) {
switch ($_POST['sr_slave_action']) {
case 'start':
$messageSuccess = __('Replication started successfully.');
$messageError = __('Error starting replication.');
Expand All @@ -940,7 +936,7 @@ public static function handleControlRequest()
$messageError = __('Error.');
break;
}
} elseif (isset($_REQUEST['sr_slave_skip_error'])) {
} elseif (isset($_POST['sr_slave_skip_error'])) {
$result = self::handleRequestForSlaveSkipError();
}

Expand Down Expand Up @@ -974,13 +970,13 @@ public static function handleRequestForSlaveChangeMaster()
{
$sr = array();
$_SESSION['replication']['m_username'] = $sr['username']
= $GLOBALS['dbi']->escapeString($_REQUEST['username']);
= $GLOBALS['dbi']->escapeString($_POST['username']);
$_SESSION['replication']['m_password'] = $sr['pma_pw']
= $GLOBALS['dbi']->escapeString($_REQUEST['pma_pw']);
= $GLOBALS['dbi']->escapeString($_POST['pma_pw']);
$_SESSION['replication']['m_hostname'] = $sr['hostname']
= $GLOBALS['dbi']->escapeString($_REQUEST['hostname']);
= $GLOBALS['dbi']->escapeString($_POST['hostname']);
$_SESSION['replication']['m_port'] = $sr['port']
= $GLOBALS['dbi']->escapeString($_REQUEST['text_port']);
= $GLOBALS['dbi']->escapeString($_POST['text_port']);
$_SESSION['replication']['m_correct'] = '';
$_SESSION['replication']['sr_action_status'] = 'error';
$_SESSION['replication']['sr_action_info'] = __('Unknown error');
Expand Down Expand Up @@ -1043,10 +1039,10 @@ public static function handleRequestForSlaveChangeMaster()
*/
public static function handleRequestForSlaveServerControl()
{
if (empty($_REQUEST['sr_slave_control_parm'])) {
$_REQUEST['sr_slave_control_parm'] = null;
if (empty($_POST['sr_slave_control_parm'])) {
$_POST['sr_slave_control_parm'] = null;
}
if ($_REQUEST['sr_slave_action'] == 'reset') {
if ($_POST['sr_slave_action'] == 'reset') {
$qStop = Replication::slaveControl("STOP");
$qReset = $GLOBALS['dbi']->tryQuery("RESET SLAVE;");
$qStart = Replication::slaveControl("START");
Expand All @@ -1056,8 +1052,8 @@ public static function handleRequestForSlaveServerControl()
$qStart !== false && $qStart !== -1);
} else {
$qControl = Replication::slaveControl(
$_REQUEST['sr_slave_action'],
$_REQUEST['sr_slave_control_parm']
$_POST['sr_slave_action'],
$_POST['sr_slave_control_parm']
);

$result = ($qControl !== false && $qControl !== -1);
Expand All @@ -1074,8 +1070,8 @@ public static function handleRequestForSlaveServerControl()
public static function handleRequestForSlaveSkipError()
{
$count = 1;
if (isset($_REQUEST['sr_skip_errors_count'])) {
$count = $_REQUEST['sr_skip_errors_count'] * 1;
if (isset($_POST['sr_skip_errors_count'])) {
$count = $_POST['sr_skip_errors_count'] * 1;
}

$qStop = Replication::slaveControl("STOP");
Expand Down
6 changes: 3 additions & 3 deletions libraries/replication.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* set selected master server
*/
if (! empty($_REQUEST['master_connection'])) {
if (! empty($_POST['master_connection'])) {
/**
* check for multi-master replication functionality
*/
Expand All @@ -30,10 +30,10 @@
$GLOBALS['dbi']->query(
"SET @@default_master_connection = '"
. $GLOBALS['dbi']->escapeString(
$_REQUEST['master_connection']
$_POST['master_connection']
) . "'"
);
$GLOBALS['url_params']['master_connection'] = $_REQUEST['master_connection'];
$GLOBALS['url_params']['master_connection'] = $_POST['master_connection'];
}
}

Expand Down
16 changes: 8 additions & 8 deletions server_replication.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
exit;
}

// change $GLOBALS['url_params'] with $_REQUEST['url_params']
// change $GLOBALS['url_params'] with $_POST['url_params']
// only if it is an array
if (isset($_REQUEST['url_params']) && is_array($_REQUEST['url_params'])) {
$GLOBALS['url_params'] = $_REQUEST['url_params'];
if (isset($_POST['url_params']) && is_array($_POST['url_params'])) {
$GLOBALS['url_params'] = $_POST['url_params'];
}

/**
Expand All @@ -64,21 +64,21 @@

if ($GLOBALS['replication_info']['master']['status']) {
$response->addHTML(ReplicationGui::getHtmlForMasterReplication());
} elseif (! isset($_REQUEST['mr_configure'])
&& ! isset($_REQUEST['repl_clear_scr'])
} elseif (! isset($_POST['mr_configure'])
&& ! isset($_POST['repl_clear_scr'])
) {
$response->addHTML(ReplicationGui::getHtmlForNotServerReplication());
}

if (isset($_REQUEST['mr_configure'])) {
if (isset($_POST['mr_configure'])) {
// Render the 'Master configuration' section
$response->addHTML(ReplicationGui::getHtmlForMasterConfiguration());
exit;
}

$response->addHTML('</div>');

if (! isset($_REQUEST['repl_clear_scr'])) {
if (! isset($_POST['repl_clear_scr'])) {
// Render the 'Slave configuration' section
$response->addHTML(
ReplicationGui::getHtmlForSlaveConfiguration(
Expand All @@ -87,6 +87,6 @@
)
);
}
if (isset($_REQUEST['sl_configure'])) {
if (isset($_POST['sl_configure'])) {
$response->addHTML(ReplicationGui::getHtmlForReplicationChangeMaster("slave_changemaster"));
}
Loading

0 comments on commit eb13c69

Please sign in to comment.