2 /* vim: set expandtab sw=4 ts=4 sts=4: */
7 if (! defined('PHPMYADMIN')) {
12 * returns HTML for error message
14 * @return String HTML code
16 function PMA_getHtmlForErrorMessage()
19 if (isset($_SESSION['replication']['sr_action_status'])
20 && isset($_SESSION['replication']['sr_action_info'])
22 if ($_SESSION['replication']['sr_action_status'] == 'error') {
23 $error_message = $_SESSION['replication']['sr_action_info'];
24 $html .= PMA_Message
::error($error_message)->getDisplay();
25 $_SESSION['replication']['sr_action_status'] = 'unknown';
26 } elseif ($_SESSION['replication']['sr_action_status'] == 'success') {
27 $success_message = $_SESSION['replication']['sr_action_info'];
28 $html .= PMA_Message
::success($success_message)->getDisplay();
29 $_SESSION['replication']['sr_action_status'] = 'unknown';
36 * returns HTML for master replication
38 * @return String HTML code
40 function PMA_getHtmlForMasterReplication()
43 if (! isset($_REQUEST['repl_clear_scr'])) {
44 $html .= '<fieldset>';
45 $html .= '<legend>' . __('Master replication') . '</legend>';
46 $html .= __('This server is configured as master in a replication process.');
48 $html .= ' <li><a href="#" id="master_status_href">';
49 $html .= __('Show master status') . '</a>';
50 $html .= PMA_getHtmlForReplicationStatusTable('master', true, false);
53 $html .= ' <li><a href="#" id="master_slaves_href">';
54 $html .= __('Show connected slaves') . '</a>';
55 $html .= PMA_getHtmlForReplicationSlavesTable(true);
58 $_url_params = $GLOBALS['url_params'];
59 $_url_params['mr_adduser'] = true;
60 $_url_params['repl_clear_scr'] = true;
62 $html .= ' <li><a href="server_replication.php';
63 $html .= PMA_URL_getCommon($_url_params)
64 . '" id="master_addslaveuser_href">';
65 $html .= __('Add slave replication user') . '</a></li>';
68 // Display 'Add replication slave user' form
69 if (isset($_REQUEST['mr_adduser'])) {
70 $html .= PMA_getHtmlForReplicationMasterAddSlaveuser();
71 } elseif (! isset($_REQUEST['repl_clear_scr'])) {
73 $html .= "</fieldset>";
80 * returns HTML for master replication configuration
82 * @return String HTML code
84 function PMA_getHtmlForMasterConfiguration()
87 $html .= '<legend>' . __('Master configuration') . '</legend>';
89 'This server is not configured as master server in a '
90 . 'replication process. You can choose from either replicating '
91 . 'all databases and ignoring certain (useful if you want to replicate '
92 . 'majority of databases) or you can choose to ignore all databases by '
93 . 'default and allow only certain databases to be replicated. '
94 . 'Please select the mode:'
97 $html .= '<select name="db_type" id="db_type">';
98 $html .= '<option value="all">' . __('Replicate all databases; Ignore:');
100 $html .= '<option value="ign">' . __('Ignore all databases; Replicate:');
101 $html .= '</option>';
102 $html .= '</select>';
103 $html .= '<br /><br />';
104 $html .= __('Please select databases:') . '<br />';
105 $html .= PMA_getHtmlForReplicationDbMultibox();
106 $html .= '<br /><br />';
108 'Now, add the following lines at the end of [mysqld] section'
109 . ' in your my.cnf and please restart the MySQL server afterwards.'
111 $html .= '<pre id="rep"></pre>';
113 'Once you restarted MySQL server, please click on Go button. '
114 . 'Afterwards, you should see a message informing you, that this server'
115 . ' <b>is</b> configured as master.'
117 $html .= '</fieldset>';
118 $html .= '<fieldset class="tblFooters">';
119 $html .= ' <form method="post" action="server_replication.php" >';
120 $html .= PMA_URL_getHiddenInputs('', '');
121 $html .= ' <input type="submit" value="' . __('Go') . '" id="goButton" />';
123 $html .= '</fieldset>';
129 * returns HTML for slave replication configuration
131 * @param bool $server_slave_status Whether it is Master or Slave
132 * @param Array $server_slave_replication Slave replication
134 * @return String HTML code
136 function PMA_getHtmlForSlaveConfiguration($server_slave_status, $server_slave_replication)
138 $html = '<fieldset>';
139 $html .= '<legend>' . __('Slave replication') . '</legend>';
140 if ($server_slave_status) {
141 $html .= '<div id="slave_configuration_gui">';
143 $_url_params = $GLOBALS['url_params'];
144 $_url_params['sr_take_action'] = true;
145 $_url_params['sr_slave_server_control'] = true;
147 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
148 $_url_params['sr_slave_action'] = 'start';
150 $_url_params['sr_slave_action'] = 'stop';
153 $_url_params['sr_slave_control_parm'] = 'IO_THREAD';
154 $slave_control_io_link = 'server_replication.php'
155 . PMA_URL_getCommon($_url_params);
157 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
158 $_url_params['sr_slave_action'] = 'start';
160 $_url_params['sr_slave_action'] = 'stop';
163 $_url_params['sr_slave_control_parm'] = 'SQL_THREAD';
164 $slave_control_sql_link = 'server_replication.php'
165 . PMA_URL_getCommon($_url_params);
167 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No'
168 ||
$server_slave_replication[0]['Slave_SQL_Running'] == 'No'
170 $_url_params['sr_slave_action'] = 'start';
172 $_url_params['sr_slave_action'] = 'stop';
175 $_url_params['sr_slave_control_parm'] = null;
176 $slave_control_full_link = 'server_replication.php'
177 . PMA_URL_getCommon($_url_params);
179 $_url_params['sr_slave_action'] = 'reset';
180 $slave_control_reset_link = 'server_replication.php'
181 . PMA_URL_getCommon($_url_params);
183 $_url_params = $GLOBALS['url_params'];
184 $_url_params['sr_slave_skip_error'] = true;
185 $slave_skip_error_link = 'server_replication.php'
186 . PMA_URL_getCommon($_url_params);
188 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
189 $html .= PMA_Message
::error(
190 __('Slave SQL Thread not running!')
193 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
194 $html .= PMA_Message
::error(
195 __('Slave IO Thread not running!')
199 $_url_params = $GLOBALS['url_params'];
200 $_url_params['sl_configure'] = true;
201 $_url_params['repl_clear_scr'] = true;
203 $reconfiguremaster_link = 'server_replication.php'
204 . PMA_URL_getCommon($_url_params);
206 $html .= __('Server is configured as slave in a replication process. Would you like to:');
209 $html .= ' <li><a href="#" id="slave_status_href">';
210 $html .= __('See slave status table') . '</a>';
211 $html .= PMA_getHtmlForReplicationStatusTable('slave', true, false);
214 $html .= ' <li><a href="#" id="slave_control_href">';
215 $html .= __('Control slave:') . '</a>';
216 $html .= ' <div id="slave_control_gui" style="display: none">';
218 $html .= ' <li><a href="'. $slave_control_full_link . '">';
219 $html .= (($server_slave_replication[0]['Slave_IO_Running'] == 'No' ||
220 $server_slave_replication[0]['Slave_SQL_Running'] == 'No')
222 : __('Full stop')) . ' </a></li>';
223 $html .= ' <li><a href="'. $slave_control_reset_link . '">';
224 $html .= __('Reset slave') . '</a></li>';
225 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
226 $html .= ' <li><a href="' . $slave_control_sql_link . '">';
227 $html .= __('Start SQL Thread only') . '</a></li>';
229 $html .= ' <li><a href="' . $slave_control_sql_link . '">';
230 $html .= __('Stop SQL Thread only') . '</a></li>';
232 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
233 $html .= ' <li><a href="' . $slave_control_io_link . '">';
234 $html .= __('Start IO Thread only') . '</a></li>';
236 $html .= ' <li><a href="' . $slave_control_io_link . '">';
237 $html .= __('Stop IO Thread only') . '</a></li>';
243 $html .= PMA_getHtmlForSlaveErrorManagement($slave_skip_error_link);
245 $html .= ' <li><a href="' . $reconfiguremaster_link . '">';
246 $html .= __('Change or reconfigure master server') . '</a></li>';
250 } elseif (! isset($_REQUEST['sl_configure'])) {
251 $_url_params = $GLOBALS['url_params'];
252 $_url_params['sl_configure'] = true;
253 $_url_params['repl_clear_scr'] = true;
257 'This server is not configured as slave in a replication process. '
258 . 'Would you like to <a href="%s">configure</a> it?'
260 'server_replication.php' . PMA_URL_getCommon($_url_params)
263 $html .= '</fieldset>';
269 * returns HTML for Slave Error Management
271 * @param String $slave_skip_error_link error link
273 * @return String HTML code
275 function PMA_getHtmlForSlaveErrorManagement($slave_skip_error_link)
277 $html = '<a href="#" id="slave_errormanagement_href">';
278 $html .= __('Error management:') . '</a>';
279 $html .= ' <div id="slave_errormanagement_gui" style="display: none">';
280 $html .= PMA_Message
::error(
281 __('Skipping errors might lead into unsynchronized master and slave!')
284 $html .= ' <li><a href="' . $slave_skip_error_link . '">';
285 $html .= __('Skip current error') . '</a></li>';
286 $html .= ' <li>' . __('Skip next');
287 $html .= ' <form method="post" action="server_replication.php">';
288 $html .= PMA_URL_getHiddenInputs('', '');
289 $html .= ' <input type="text" name="sr_skip_errors_count" value="1" ';
290 $html .= 'style="width: 30px" />' . __('errors.');
291 $html .= ' <input type="submit" name="sr_slave_skip_error" ';
292 $html .= 'value="' . __('Go') . '" />';
293 $html .= ' <input type="hidden" name="sr_take_action" value="1" />';
294 $html .= ' </form></li>';
301 * returns HTML for not configure for a server replication
303 * @return String HTML code
305 function PMA_getHtmlForNotServerReplication()
307 $_url_params = $GLOBALS['url_params'];
308 $_url_params['mr_configure'] = true;
310 $html = '<fieldset>';
311 $html .= '<legend>' . __('Master replication') . '</legend>';
314 'This server is not configured as master in a replication process. '
315 . 'Would you like to <a href="%s">configure</a> it?'
317 'server_replication.php' . PMA_URL_getCommon($_url_params)
319 $html .= '</fieldset>';
324 * returns HTML code for selecting databases
326 * @return String HTML code
328 function PMA_getHtmlForReplicationDbMultibox()
331 $multi_values .= '<select name="db_select[]" '
332 . 'size="6" multiple="multiple" id="db_select">';
334 foreach ($GLOBALS['pma']->databases
as $current_db) {
335 if ($GLOBALS['dbi']->isSystemSchema($current_db)) {
338 /* TODO: where $selectall should come from? */
339 if (! empty($selectall) ||
(isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
340 $is_selected = ' selected="selected"';
344 $current_db = htmlspecialchars($current_db);
345 $multi_values .= ' <option value="' . $current_db . '" ';
346 $multi_values .= $is_selected . '>';
347 $multi_values .= $current_db . '</option>';
350 $multi_values .= '</select>';
351 $multi_values .= '<br /><a href="#" id="db_reset_href">';
352 $multi_values .= __('Uncheck All') . '</a>';
354 return $multi_values;
358 * returns HTML for changing master
360 * @param String $submitname - submit button name
362 * @return String HTML code
365 function PMA_getHtmlForReplicationChangeMaster($submitname)
368 list($username_length, $hostname_length)
369 = PMA_replicationGetUsernameHostnameLength();
371 $html .= '<form method="post" action="server_replication.php">';
372 $html .= PMA_URL_getHiddenInputs('', '');
373 $html .= ' <fieldset id="fieldset_add_user_login">';
374 $html .= ' <legend>' . __('Slave configuration');
375 $html .= ' - ' . __('Change or reconfigure master server') . '</legend>';
377 'Make sure, you have unique server-id in your configuration file (my.cnf). '
378 . 'If not, please add the following line into [mysqld] section:'
381 $html .= '<pre>server-id=' . time() . '</pre>';
383 $html .= PMA_getHtmlForAddUserInputDiv(
384 array('text'=>__('User name:'), 'for'=>"text_username"),
388 'id'=>'text_username',
389 'maxlength'=>$username_length,
390 'title'=>__('User name'),
391 'required'=>'required'
395 $html .= PMA_getHtmlForAddUserInputDiv(
396 array('text'=>__('Password:'), 'for'=>"text_pma_pw"),
401 'title'=>__('Password'),
402 'required'=>'required'
406 $html .= PMA_getHtmlForAddUserInputDiv(
407 array('text'=>__('Host:'), 'for'=>"text_hostname"),
411 'id'=>'text_hostname',
412 'maxlength'=>$hostname_length,
414 'required'=>'required'
418 $html .= PMA_getHtmlForAddUserInputDiv(
419 array('text'=>__('Port:'), 'for'=>"text_port"),
426 'required'=>'required'
430 $html .= ' </fieldset>';
431 $html .= ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
432 $html .= ' <input type="hidden" name="sr_take_action" value="true" />';
433 $html .= ' <input type="hidden" name="' . $submitname . '" value="1" />';
434 $html .= ' <input type="submit" id="confslave_submit" value="';
435 $html .= __('Go') . '" />';
436 $html .= ' </fieldset>';
443 * returns HTML code for Add user input div
445 * @param Array $label_array label tag elements
446 * @param Array $input_array input tag elements
448 * @return String HTML code
450 function PMA_getHtmlForAddUserInputDiv($label_array, $input_array)
452 $html = ' <div class="item">';
453 $html .= ' <label for="' . $label_array['for'] . '">';
454 $html .= $label_array['text'] . '</label>';
457 foreach ($input_array as $key=>$value) {
458 $html .= ' ' . $key . '="' . $value. '" ';
466 * This function returns html code for table with replication status.
468 * @param string $type either master or slave
469 * @param boolean $hidden if true, then default style is set to hidden, default value false
470 * @param boolen $title if true, then title is displayed, default true
472 * @return String HTML code
474 function PMA_getHtmlForReplicationStatusTable($type, $hidden = false, $title = true)
476 global $
{"{$type}_variables"};
477 global $
{"{$type}_variables_alerts"};
478 global $
{"{$type}_variables_oks"};
479 global $
{"server_{$type}_replication"};
480 global $
{"strReplicationStatus_{$type}"};
484 // TODO check the Masters server id?
485 // seems to default to '1' when queried via SHOW VARIABLES ,
486 // but resulted in error on the master when slave connects
487 // [ERROR] Error reading packet from server: Misconfigured master
488 // - server id was not set ( server_errno=1236)
489 // [ERROR] Got fatal error 1236: 'Misconfigured master
490 // - server id was not set' from master when reading data from binary log
492 //$server_id = $GLOBALS['dbi']->fetchValue("SHOW VARIABLES LIKE 'server_id'", 0, 1);
494 $html .= '<div id="replication_' . $type . '_section" style="';
495 $html .= ($hidden ?
'display: none;' : '') . '"> ';
498 if ($type == 'master') {
499 $html .= '<h4><a name="replication_' . $type . '"></a>';
500 $html .= __('Master status') . '</h4>';
502 $html .= '<h4><a name="replication_' . $type . '"></a>';
503 $html .= __('Slave status') . '</h4>';
509 $html .= ' <table id="server' . $type . 'replicationsummary" class="data"> ';
512 $html .= ' <th>' . __('Variable') . '</th>';
513 $html .= ' <th>' . __('Value') . '</th>';
515 $html .= ' </thead>';
519 foreach ($
{"{$type}_variables"} as $variable) {
520 $html .= ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
521 $html .= ' <td class="name">';
524 $html .= ' <td class="value">';
527 // TODO change to regexp or something, to allow for negative match
528 if (isset($
{"{$type}_variables_alerts"}[$variable])
529 && $
{"{$type}_variables_alerts"}[$variable] == $
{"server_{$type}_replication"}[0][$variable]
531 $html .= '<span class="attention">';
533 } elseif (isset($
{"{$type}_variables_oks"}[$variable])
534 && $
{"{$type}_variables_oks"}[$variable]
535 == $
{"server_{$type}_replication"}[0][$variable]
537 $html .= '<span class="allfine">';
541 // allow wrapping long table lists into multiple lines
542 static $variables_wrap = array(
543 'Replicate_Do_DB', 'Replicate_Ignore_DB',
544 'Replicate_Do_Table', 'Replicate_Ignore_Table',
545 'Replicate_Wild_Do_Table', 'Replicate_Wild_Ignore_Table');
546 if (in_array($variable, $variables_wrap)) {
547 $html .= str_replace(
550 $
{"server_{$type}_replication"}[0][$variable]
553 $html .= $
{"server_{$type}_replication"}[0][$variable];
560 $odd_row = ! $odd_row;
563 $html .= ' </tbody>';
564 $html .= ' </table>';
572 * returns html code for table with slave users connected to this master
574 * @param boolean $hidden - if true, then default style is set to hidden,
575 * - default value false
579 function PMA_getHtmlForReplicationSlavesTable($hidden = false)
583 $data = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null);
586 $html .= ' <div id="replication_slaves_section" style="';
587 $html .= ($hidden ?
'display: none;' : '') . '"> ';
588 $html .= ' <table class="data">';
591 $html .= ' <th>' . __('Server ID') . '</th>';
592 $html .= ' <th>' . __('Host') . '</th>';
594 $html .= ' </thead>';
598 foreach ($data as $slave) {
599 $html .= ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
600 $html .= ' <td class="value">' . $slave['Server_id'] . '</td>';
601 $html .= ' <td class="value">' . $slave['Host'] . '</td>';
604 $odd_row = ! $odd_row;
607 $html .= ' </tbody>';
608 $html .= ' </table>';
610 $html .= PMA_Message
::notice(
612 'Only slaves started with the '
613 . '--report-host=host_name option are visible in this list.'
623 * get the correct username and hostname lengths for this MySQL server
625 * @return array username length, hostname length
628 function PMA_replicationGetUsernameHostnameLength()
630 $fields_info = $GLOBALS['dbi']->getColumns('mysql', 'user');
631 $username_length = 16;
632 $hostname_length = 41;
633 foreach ($fields_info as $val) {
634 if ($val['Field'] == 'User') {
635 strtok($val['Type'], '()');
638 $username_length = $v;
640 } elseif ($val['Field'] == 'Host') {
641 strtok($val['Type'], '()');
644 $hostname_length = $v;
648 return array($username_length, $hostname_length);
652 * returns html code to add a replication slave user to the master
654 * @return String HTML code
656 function PMA_getHtmlForReplicationMasterAddSlaveuser()
659 list($username_length, $hostname_length)
660 = PMA_replicationGetUsernameHostnameLength();
662 if (isset($_REQUEST['username']) && strlen($_REQUEST['username']) === 0) {
663 $GLOBALS['pred_username'] = 'any';
665 $html .= '<div id="master_addslaveuser_gui">';
666 $html .= '<form autocomplete="off" method="post" ';
667 $html .= 'action="server_privileges.php"';
668 $html .= ' onsubmit="return checkAddUser(this);">';
669 $html .= PMA_URL_getHiddenInputs('', '');
670 $html .= '<fieldset id="fieldset_add_user_login">'
671 . '<legend>' . __('Add slave replication user') . '</legend>'
672 . PMA_getHtmlForAddUserLoginForm($username_length)
673 . '<div class="item">'
674 . '<label for="select_pred_hostname">'
677 . '<span class="options">'
678 . ' <select name="pred_hostname" id="select_pred_hostname" title="'
681 $_current_user = $GLOBALS['dbi']->fetchValue('SELECT USER();');
682 if (! empty($_current_user)) {
683 $thishost = str_replace(
686 substr($_current_user, (strrpos($_current_user, '@') +
1))
688 if ($thishost == 'localhost' ||
$thishost == '127.0.0.1') {
692 $html .= ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } '
693 . 'else if (this.value == \'localhost\') '
694 . '{ hostname.value = \'localhost\'; } '
697 : 'else if (this.value == \'thishost\') { hostname.value = \''
698 . addslashes(htmlspecialchars($thishost)) . '\'; } ')
699 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } '
700 . 'else if (this.value == \'userdefined\') '
701 . '{ hostname.focus(); hostname.select(); }">'
703 unset($_current_user);
705 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
706 if (! isset($GLOBALS['pred_hostname']) && isset($_REQUEST['hostname'])) {
707 switch (strtolower($_REQUEST['hostname'])) {
710 $GLOBALS['pred_hostname'] = 'localhost';
713 $GLOBALS['pred_hostname'] = 'any';
716 $GLOBALS['pred_hostname'] = 'userdefined';
720 $html .= ' <option value="any"'
721 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
722 ?
' selected="selected"' : '') . '>' . __('Any host')
724 . ' <option value="localhost"'
725 . ((isset($GLOBALS['pred_hostname'])
726 && $GLOBALS['pred_hostname'] == 'localhost')
727 ?
' selected="selected"' : '') . '>' . __('Local')
730 if (!empty($thishost)) {
731 $html .= ' <option value="thishost"'
732 . ((isset($GLOBALS['pred_hostname'])
733 && $GLOBALS['pred_hostname'] == 'thishost')
734 ?
' selected="selected"' : '') . '>' . __('This Host')
739 $html .= PMA_getHtmlForTableInfoForm($hostname_length);
746 * returns html code to add a replication slave user to the master
748 * @param int $username_length Username length
750 * @return String HTML code
752 function PMA_getHtmlForAddUserLoginForm($username_length)
754 $html = '<input type="hidden" name="grant_count" value="25" />'
755 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
756 . '<input id="checkbox_Repl_slave_priv" type="hidden"'
757 . ' title="Needed for the replication slaves." '
758 . 'value="Y" name="Repl_slave_priv"/>'
759 . '<input id="checkbox_Repl_client_priv" type="hidden" '
760 . 'title="Needed for the replication slaves."'
761 . ' value="Y" name="Repl_client_priv"/> '
762 . '<input type="hidden" name="sr_take_action" value="true" />'
763 . '<div class="item">'
764 . '<label for="select_pred_username">'
765 . ' ' . __('User name:')
767 . '<span class="options">'
768 . ' <select name="pred_username" id="select_pred_username" '
769 . 'title="' . __('User name') . '"'
770 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } '
771 . 'else if (this.value == \'userdefined\') { '
772 . ' username.focus(); username.select(); }">'
773 . ' <option value="any"'
774 . ((isset($GLOBALS['pred_username'])
775 && $GLOBALS['pred_username'] == 'any') ?
' selected="selected"' : '')
776 . '>' . __('Any user') . '</option>'
777 . ' <option value="userdefined"'
778 . ((! isset($GLOBALS['pred_username'])
779 ||
$GLOBALS['pred_username'] == 'userdefined')
780 ?
' selected="selected"' : '')
781 . '>' . __('Use text field:') . '</option>'
784 . '<input type="text" name="username" maxlength="'
785 . $username_length . '" title="' . __('User name') . '"'
786 . (empty($_REQUEST['username']) ?
'' : ' value="'
787 . (isset($GLOBALS['new_username'])
788 ?
$GLOBALS['new_username']
789 : $_REQUEST['username']) . '"')
790 . ' onchange="pred_username.value = \'userdefined\';" />'
797 * returns HTML for TableInfoForm
799 * @param int $hostname_length Selected hostname length
801 * @return String HTML code
803 function PMA_getHtmlForTableInfoForm($hostname_length)
805 $html = ' <option value="hosttable"'
806 . ((isset($GLOBALS['pred_hostname'])
807 && $GLOBALS['pred_hostname'] == 'hosttable')
808 ?
' selected="selected"' : '') . '>' . __('Use Host Table')
810 . ' <option value="userdefined"'
811 . ((isset($GLOBALS['pred_hostname'])
812 && $GLOBALS['pred_hostname'] == 'userdefined')
813 ?
' selected="selected"' : '')
814 . '>' . __('Use text field:') . '</option>'
817 . '<input type="text" name="hostname" maxlength="'
818 . $hostname_length . '" value="'
819 . (isset($_REQUEST['hostname']) ?
$_REQUEST['hostname'] : '')
820 . '" title="' . __('Host')
821 . '" onchange="pred_hostname.value = \'userdefined\';" />'
822 . PMA_Util
::showHint(
824 'When Host table is used, this field is ignored '
825 . 'and values stored in Host table are used instead.'
829 . '<div class="item">'
830 . '<label for="select_pred_password">'
831 . ' ' . __('Password:')
833 . '<span class="options">'
834 . ' <select name="pred_password" id="select_pred_password" title="'
835 . __('Password') . '"'
836 . ' onchange="if (this.value == \'none\') '
837 . '{ pma_pw.value = \'\'; pma_pw2.value = \'\'; } '
838 . 'else if (this.value == \'userdefined\') '
839 . '{ pma_pw.focus(); pma_pw.select(); }">'
840 . ' <option value="none"';
841 if (isset($_REQUEST['username'])) {
842 $html .= ' selected="selected"';
844 $html .= '>' . __('No Password') . '</option>'
845 . ' <option value="userdefined"'
846 . (isset($_REQUEST['username']) ?
'' : ' selected="selected"')
847 . '>' . __('Use text field:') . '</option>'
850 . '<input type="password" id="text_pma_pw" name="pma_pw" title="'
851 . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
853 . '<div class="item">'
854 . '<label for="text_pma_pw2">'
855 . ' ' . __('Re-type:')
857 . '<span class="options"> </span>'
858 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="'
859 . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
861 . '<div class="item">'
862 . '<label for="button_generate_password">'
863 . ' ' . __('Generate Password:')
865 . '<span class="options">'
866 . ' <input type="button" class="button" '
867 . 'id="button_generate_password" value="' . __('Generate')
868 . '" onclick="suggestPassword(this.form)" />'
870 . '<input type="text" name="generated_pw" id="generated_pw" />'
873 $html .= '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
874 . ' <input type="hidden" name="adduser_submit" value="1" />'
875 . ' <input type="submit" id="adduser_submit" value="' . __('Go') . '" />'
881 * handle control requests
885 function PMA_handleControlRequest()
887 if (isset($_REQUEST['sr_take_action'])) {
889 if (isset($_REQUEST['slave_changemaster'])) {
890 PMA_handleRequestForSlaveChangeMaster();
891 } elseif (isset($_REQUEST['sr_slave_server_control'])) {
892 PMA_handleRequestForSlaveServerControl();
894 } elseif (isset($_REQUEST['sr_slave_skip_error'])) {
895 PMA_handleRequestForSlaveSkipError();
900 "Location: server_replication.php"
901 . PMA_URL_getCommon($GLOBALS['url_params'])
908 * handle control requests for Slave Change Master
912 function PMA_handleRequestForSlaveChangeMaster()
914 $_SESSION['replication']['m_username'] = $sr['username']
915 = PMA_Util
::sqlAddSlashes($_REQUEST['username']);
916 $_SESSION['replication']['m_password'] = $sr['pma_pw']
917 = PMA_Util
::sqlAddSlashes($_REQUEST['pma_pw']);
918 $_SESSION['replication']['m_hostname'] = $sr['hostname']
919 = PMA_Util
::sqlAddSlashes($_REQUEST['hostname']);
920 $_SESSION['replication']['m_port'] = $sr['port']
921 = PMA_Util
::sqlAddSlashes($_REQUEST['port']);
922 $_SESSION['replication']['m_correct'] = '';
923 $_SESSION['replication']['sr_action_status'] = 'error';
924 $_SESSION['replication']['sr_action_info'] = __('Unknown error');
926 // Attempt to connect to the new master server
927 $link_to_master = PMA_Replication_connectToMaster(
928 $sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port']
931 if (! $link_to_master) {
932 $_SESSION['replication']['sr_action_status'] = 'error';
933 $_SESSION['replication']['sr_action_info'] = sprintf(
934 __('Unable to connect to master %s.'),
935 htmlspecialchars($sr['hostname'])
938 // Read the current master position
939 $position = PMA_Replication_Slave_binLogMaster($link_to_master);
941 if (empty($position)) {
942 $_SESSION['replication']['sr_action_status'] = 'error';
943 $_SESSION['replication']['sr_action_info']
945 'Unable to read master log position. '
946 . 'Possible privilege problem on master.'
949 $_SESSION['replication']['m_correct'] = true;
951 if (! PMA_Replication_Slave_changeMaster(
961 $_SESSION['replication']['sr_action_status'] = 'error';
962 $_SESSION['replication']['sr_action_info']
963 = __('Unable to change master');
965 $_SESSION['replication']['sr_action_status'] = 'success';
966 $_SESSION['replication']['sr_action_info'] = sprintf(
967 __('Master server changed successfully to %s'),
968 htmlspecialchars($sr['hostname'])
976 * handle control requests for Slave Server Control
980 function PMA_handleRequestForSlaveServerControl()
982 if ($_REQUEST['sr_slave_action'] == 'reset') {
983 PMA_Replication_Slave_control("STOP");
984 $GLOBALS['dbi']->tryQuery("RESET SLAVE;");
985 PMA_Replication_Slave_control("START");
987 PMA_Replication_Slave_control(
988 $_REQUEST['sr_slave_action'],
989 $_REQUEST['sr_slave_control_parm']
995 * handle control requests for Slave Skip Error
999 function PMA_handleRequestForSlaveSkipError()
1002 if (isset($_REQUEST['sr_skip_errors_count'])) {
1003 $count = $_REQUEST['sr_skip_errors_count'] * 1;
1005 PMA_Replication_Slave_control("STOP");
1006 $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";");
1007 PMA_Replication_Slave_control("START");