2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Functions for the replication GUI
8 if (! defined('PHPMYADMIN')) {
13 * returns HTML for error message
15 * @return String HTML code
17 function PMA_getHtmlForErrorMessage()
20 if (isset($_SESSION['replication']['sr_action_status'])
21 && isset($_SESSION['replication']['sr_action_info'])
23 if ($_SESSION['replication']['sr_action_status'] == 'error') {
24 $error_message = $_SESSION['replication']['sr_action_info'];
25 $html .= PMA_Message
::error($error_message)->getDisplay();
26 $_SESSION['replication']['sr_action_status'] = 'unknown';
27 } elseif ($_SESSION['replication']['sr_action_status'] == 'success') {
28 $success_message = $_SESSION['replication']['sr_action_info'];
29 $html .= PMA_Message
::success($success_message)->getDisplay();
30 $_SESSION['replication']['sr_action_status'] = 'unknown';
37 * returns HTML for master replication
39 * @return String HTML code
41 function PMA_getHtmlForMasterReplication()
44 if (! isset($_REQUEST['repl_clear_scr'])) {
45 $html .= '<fieldset>';
46 $html .= '<legend>' . __('Master replication') . '</legend>';
47 $html .= __('This server is configured as master in a replication process.');
49 $html .= ' <li><a href="#" id="master_status_href">';
50 $html .= __('Show master status') . '</a>';
51 $html .= PMA_getHtmlForReplicationStatusTable('master', true, false);
54 $html .= ' <li><a href="#" id="master_slaves_href">';
55 $html .= __('Show connected slaves') . '</a>';
56 $html .= PMA_getHtmlForReplicationSlavesTable(true);
59 $_url_params = $GLOBALS['url_params'];
60 $_url_params['mr_adduser'] = true;
61 $_url_params['repl_clear_scr'] = true;
63 $html .= ' <li><a href="server_replication.php';
64 $html .= PMA_URL_getCommon($_url_params)
65 . '" id="master_addslaveuser_href">';
66 $html .= __('Add slave replication user') . '</a></li>';
69 // Display 'Add replication slave user' form
70 if (isset($_REQUEST['mr_adduser'])) {
71 $html .= PMA_getHtmlForReplicationMasterAddSlaveuser();
72 } elseif (! isset($_REQUEST['repl_clear_scr'])) {
74 $html .= "</fieldset>";
81 * returns HTML for master replication configuration
83 * @return String HTML code
85 function PMA_getHtmlForMasterConfiguration()
88 $html .= '<legend>' . __('Master configuration') . '</legend>';
90 'This server is not configured as master server in a '
91 . 'replication process. You can choose from either replicating '
92 . 'all databases and ignoring certain (useful if you want to replicate '
93 . 'majority of databases) or you can choose to ignore all databases by '
94 . 'default and allow only certain databases to be replicated. '
95 . 'Please select the mode:'
98 $html .= '<select name="db_type" id="db_type">';
99 $html .= '<option value="all">' . __('Replicate all databases; Ignore:');
100 $html .= '</option>';
101 $html .= '<option value="ign">' . __('Ignore all databases; Replicate:');
102 $html .= '</option>';
103 $html .= '</select>';
104 $html .= '<br /><br />';
105 $html .= __('Please select databases:') . '<br />';
106 $html .= PMA_getHtmlForReplicationDbMultibox();
107 $html .= '<br /><br />';
109 'Now, add the following lines at the end of [mysqld] section'
110 . ' in your my.cnf and please restart the MySQL server afterwards.'
112 $html .= '<pre id="rep"></pre>';
114 'Once you restarted MySQL server, please click on Go button. '
115 . 'Afterwards, you should see a message informing you, that this server'
116 . ' <b>is</b> configured as master.'
118 $html .= '</fieldset>';
119 $html .= '<fieldset class="tblFooters">';
120 $html .= ' <form method="post" action="server_replication.php" >';
121 $html .= PMA_URL_getHiddenInputs('', '');
122 $html .= ' <input type="submit" value="' . __('Go') . '" id="goButton" />';
124 $html .= '</fieldset>';
130 * returns HTML for slave replication configuration
132 * @param bool $server_slave_status Whether it is Master or Slave
133 * @param Array $server_slave_replication Slave replication
135 * @return String HTML code
137 function PMA_getHtmlForSlaveConfiguration(
138 $server_slave_status, $server_slave_replication
140 $html = '<fieldset>';
141 $html .= '<legend>' . __('Slave replication') . '</legend>';
143 * check for multi-master replication functionality
145 $server_slave_multi_replication = $GLOBALS['dbi']->fetchResult(
146 'SHOW ALL SLAVES STATUS'
148 if ($server_slave_multi_replication) {
149 $html .= __('Master connection:');
150 $html .= '<form method="get" action="server_replication.php">';
151 $html .= PMA_URL_getHiddenInputs($GLOBALS['url_params']);
152 $html .= ' <select name="master_connection">';
153 $html .= '<option value="">' . __('Default') . '</option>';
154 foreach ($server_slave_multi_replication as $server) {
155 $html .= '<option' . (isset($_REQUEST['master_connection'])
156 && $_REQUEST['master_connection'] == $server['Connection_name'] ?
157 ' selected="selected"' : '') . '>' . $server['Connection_name']
160 $html .= '</select>';
161 $html .= ' <input type="submit" value="' . __('Go') . '" id="goButton" />';
163 $html .= '<br /><br />';
165 if ($server_slave_status) {
166 $html .= '<div id="slave_configuration_gui">';
168 $_url_params = $GLOBALS['url_params'];
169 $_url_params['sr_take_action'] = true;
170 $_url_params['sr_slave_server_control'] = true;
172 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
173 $_url_params['sr_slave_action'] = 'start';
175 $_url_params['sr_slave_action'] = 'stop';
178 $_url_params['sr_slave_control_parm'] = 'IO_THREAD';
179 $slave_control_io_link = 'server_replication.php'
180 . PMA_URL_getCommon($_url_params);
182 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
183 $_url_params['sr_slave_action'] = 'start';
185 $_url_params['sr_slave_action'] = 'stop';
188 $_url_params['sr_slave_control_parm'] = 'SQL_THREAD';
189 $slave_control_sql_link = 'server_replication.php'
190 . PMA_URL_getCommon($_url_params);
192 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No'
193 ||
$server_slave_replication[0]['Slave_SQL_Running'] == 'No'
195 $_url_params['sr_slave_action'] = 'start';
197 $_url_params['sr_slave_action'] = 'stop';
200 $_url_params['sr_slave_control_parm'] = null;
201 $slave_control_full_link = 'server_replication.php'
202 . PMA_URL_getCommon($_url_params);
204 $_url_params['sr_slave_action'] = 'reset';
205 $slave_control_reset_link = 'server_replication.php'
206 . PMA_URL_getCommon($_url_params);
208 $_url_params = $GLOBALS['url_params'];
209 $_url_params['sr_take_action'] = true;
210 $_url_params['sr_slave_skip_error'] = true;
211 $slave_skip_error_link = 'server_replication.php'
212 . PMA_URL_getCommon($_url_params);
214 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
215 $html .= PMA_Message
::error(
216 __('Slave SQL Thread not running!')
219 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
220 $html .= PMA_Message
::error(
221 __('Slave IO Thread not running!')
225 $_url_params = $GLOBALS['url_params'];
226 $_url_params['sl_configure'] = true;
227 $_url_params['repl_clear_scr'] = true;
229 $reconfiguremaster_link = 'server_replication.php'
230 . PMA_URL_getCommon($_url_params);
233 'Server is configured as slave in a replication process. Would you ' .
238 $html .= ' <li><a href="#" id="slave_status_href">';
239 $html .= __('See slave status table') . '</a>';
240 $html .= PMA_getHtmlForReplicationStatusTable('slave', true, false);
243 $html .= ' <li><a href="#" id="slave_control_href">';
244 $html .= __('Control slave:') . '</a>';
245 $html .= ' <div id="slave_control_gui" style="display: none">';
247 $html .= ' <li><a href="' . $slave_control_full_link . '">';
248 $html .= (($server_slave_replication[0]['Slave_IO_Running'] == 'No' ||
249 $server_slave_replication[0]['Slave_SQL_Running'] == 'No')
251 : __('Full stop')) . ' </a></li>';
252 $html .= ' <li><a href="' . $slave_control_reset_link . '">';
253 $html .= __('Reset slave') . '</a></li>';
254 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
255 $html .= ' <li><a href="' . $slave_control_sql_link . '">';
256 $html .= __('Start SQL Thread only') . '</a></li>';
258 $html .= ' <li><a href="' . $slave_control_sql_link . '">';
259 $html .= __('Stop SQL Thread only') . '</a></li>';
261 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
262 $html .= ' <li><a href="' . $slave_control_io_link . '">';
263 $html .= __('Start IO Thread only') . '</a></li>';
265 $html .= ' <li><a href="' . $slave_control_io_link . '">';
266 $html .= __('Stop IO Thread only') . '</a></li>';
272 $html .= PMA_getHtmlForSlaveErrorManagement($slave_skip_error_link);
274 $html .= ' <li><a href="' . $reconfiguremaster_link . '">';
275 $html .= __('Change or reconfigure master server') . '</a></li>';
279 } elseif (! isset($_REQUEST['sl_configure'])) {
280 $_url_params = $GLOBALS['url_params'];
281 $_url_params['sl_configure'] = true;
282 $_url_params['repl_clear_scr'] = true;
286 'This server is not configured as slave in a replication process. '
287 . 'Would you like to <a href="%s">configure</a> it?'
289 'server_replication.php' . PMA_URL_getCommon($_url_params)
292 $html .= '</fieldset>';
298 * returns HTML for Slave Error Management
300 * @param String $slave_skip_error_link error link
302 * @return String HTML code
304 function PMA_getHtmlForSlaveErrorManagement($slave_skip_error_link)
306 $html = '<a href="#" id="slave_errormanagement_href">';
307 $html .= __('Error management:') . '</a>';
308 $html .= ' <div id="slave_errormanagement_gui" style="display: none">';
309 $html .= PMA_Message
::error(
310 __('Skipping errors might lead into unsynchronized master and slave!')
313 $html .= ' <li><a href="' . $slave_skip_error_link . '">';
314 $html .= __('Skip current error') . '</a></li>';
316 $html .= ' <form method="post" action="server_replication.php">';
317 $html .= PMA_URL_getHiddenInputs('', '');
319 __('Skip next %s errors.'),
320 '<input type="text" name="sr_skip_errors_count" value="1" '
321 . 'style="width: 30px" />'
323 $html .= ' <input type="submit" name="sr_slave_skip_error" ';
324 $html .= 'value="' . __('Go') . '" />';
325 $html .= ' <input type="hidden" name="sr_take_action" value="1" />';
326 $html .= ' </form></li>';
333 * returns HTML for not configure for a server replication
335 * @return String HTML code
337 function PMA_getHtmlForNotServerReplication()
339 $_url_params = $GLOBALS['url_params'];
340 $_url_params['mr_configure'] = true;
342 $html = '<fieldset>';
343 $html .= '<legend>' . __('Master replication') . '</legend>';
346 'This server is not configured as master in a replication process. '
347 . 'Would you like to <a href="%s">configure</a> it?'
349 'server_replication.php' . PMA_URL_getCommon($_url_params)
351 $html .= '</fieldset>';
356 * returns HTML code for selecting databases
358 * @return String HTML code
360 function PMA_getHtmlForReplicationDbMultibox()
363 $multi_values .= '<select name="db_select[]" '
364 . 'size="6" multiple="multiple" id="db_select">';
366 foreach ($GLOBALS['pma']->databases
as $current_db) {
367 if ($GLOBALS['dbi']->isSystemSchema($current_db)) {
370 $current_db = htmlspecialchars($current_db);
371 $multi_values .= ' <option value="' . $current_db . '" ';
372 $multi_values .= '>';
373 $multi_values .= $current_db . '</option>';
376 $multi_values .= '</select><br />';
377 $multi_values .= '<a href="#" id="db_select_href">' . __('Select All') . '</a>';
378 $multi_values .= ' / ';
379 $multi_values .= '<a href="#" id="db_reset_href">' . __('Unselect All') . '</a>';
381 return $multi_values;
385 * returns HTML for changing master
387 * @param String $submitname - submit button name
389 * @return String HTML code
391 function PMA_getHtmlForReplicationChangeMaster($submitname)
394 list($username_length, $hostname_length)
395 = PMA_replicationGetUsernameHostnameLength();
397 $html .= '<form method="post" action="server_replication.php">';
398 $html .= PMA_URL_getHiddenInputs('', '');
399 $html .= ' <fieldset id="fieldset_add_user_login">';
400 $html .= ' <legend>' . __('Slave configuration');
401 $html .= ' - ' . __('Change or reconfigure master server') . '</legend>';
403 'Make sure, you have unique server-id in your configuration file (my.cnf). '
404 . 'If not, please add the following line into [mysqld] section:'
407 $html .= '<pre>server-id=' . time() . '</pre>';
409 $html .= PMA_getHtmlForAddUserInputDiv(
410 array('text'=>__('User name:'), 'for'=>"text_username"),
414 'id'=>'text_username',
415 'maxlength'=>$username_length,
416 'title'=>__('User name'),
417 'required'=>'required'
421 $html .= PMA_getHtmlForAddUserInputDiv(
422 array('text'=>__('Password:'), 'for'=>"text_pma_pw"),
427 'title'=>__('Password'),
428 'required'=>'required'
432 $html .= PMA_getHtmlForAddUserInputDiv(
433 array('text'=>__('Host:'), 'for'=>"text_hostname"),
437 'id'=>'text_hostname',
438 'maxlength'=>$hostname_length,
440 'required'=>'required'
444 $html .= PMA_getHtmlForAddUserInputDiv(
445 array('text'=>__('Port:'), 'for'=>"text_port"),
452 'required'=>'required'
456 $html .= ' </fieldset>';
457 $html .= ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
458 $html .= ' <input type="hidden" name="sr_take_action" value="true" />';
459 $html .= ' <input type="hidden" name="' . $submitname . '" value="1" />';
460 $html .= ' <input type="submit" id="confslave_submit" value="';
461 $html .= __('Go') . '" />';
462 $html .= ' </fieldset>';
469 * returns HTML code for Add user input div
471 * @param Array $label_array label tag elements
472 * @param Array $input_array input tag elements
474 * @return String HTML code
476 function PMA_getHtmlForAddUserInputDiv($label_array, $input_array)
478 $html = ' <div class="item">';
479 $html .= ' <label for="' . $label_array['for'] . '">';
480 $html .= $label_array['text'] . '</label>';
483 foreach ($input_array as $key=>$value) {
484 $html .= ' ' . $key . '="' . $value . '" ';
492 * This function returns html code for table with replication status.
494 * @param string $type either master or slave
495 * @param boolean $hidden if true, then default style is set to hidden,
496 * default value false
497 * @param boolean $title if true, then title is displayed, default true
499 * @return String HTML code
501 function PMA_getHtmlForReplicationStatusTable($type, $hidden = false, $title = true)
503 global $
{"{$type}_variables"};
504 global $
{"{$type}_variables_alerts"};
505 global $
{"{$type}_variables_oks"};
506 global $
{"server_{$type}_replication"};
507 global $
{"strReplicationStatus_{$type}"};
511 // TODO check the Masters server id?
512 // seems to default to '1' when queried via SHOW VARIABLES ,
513 // but resulted in error on the master when slave connects
514 // [ERROR] Error reading packet from server: Misconfigured master
515 // - server id was not set ( server_errno=1236)
516 // [ERROR] Got fatal error 1236: 'Misconfigured master
517 // - server id was not set' from master when reading data from binary log
519 //$server_id = $GLOBALS['dbi']->fetchValue(
520 // "SHOW VARIABLES LIKE 'server_id'", 0, 1
523 $html .= '<div id="replication_' . $type . '_section" style="';
524 $html .= ($hidden ?
'display: none;' : '') . '"> ';
527 if ($type == 'master') {
528 $html .= '<h4><a name="replication_' . $type . '"></a>';
529 $html .= __('Master status') . '</h4>';
531 $html .= '<h4><a name="replication_' . $type . '"></a>';
532 $html .= __('Slave status') . '</h4>';
538 $html .= ' <table id="server' . $type . 'replicationsummary" class="data"> ';
541 $html .= ' <th>' . __('Variable') . '</th>';
542 $html .= ' <th>' . __('Value') . '</th>';
544 $html .= ' </thead>';
548 foreach ($
{"{$type}_variables"} as $variable) {
549 $html .= ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
550 $html .= ' <td class="name">';
553 $html .= ' <td class="value">';
555 // TODO change to regexp or something, to allow for negative match
556 if (isset($
{"{$type}_variables_alerts"}[$variable])
557 && $
{"{$type}_variables_alerts"}[$variable] == $
{"server_{$type}_replication"}[0][$variable]
559 $html .= '<span class="attention">';
561 } elseif (isset($
{"{$type}_variables_oks"}[$variable])
562 && $
{"{$type}_variables_oks"}[$variable] == $
{"server_{$type}_replication"}[0][$variable]
564 $html .= '<span class="allfine">';
568 // allow wrapping long table lists into multiple lines
569 static $variables_wrap = array(
570 'Replicate_Do_DB', 'Replicate_Ignore_DB',
571 'Replicate_Do_Table', 'Replicate_Ignore_Table',
572 'Replicate_Wild_Do_Table', 'Replicate_Wild_Ignore_Table');
573 if (in_array($variable, $variables_wrap)) {
574 $html .= str_replace(
577 $
{"server_{$type}_replication"}[0][$variable]
580 $html .= $
{"server_{$type}_replication"}[0][$variable];
587 $odd_row = ! $odd_row;
590 $html .= ' </tbody>';
591 $html .= ' </table>';
599 * returns html code for table with slave users connected to this master
601 * @param boolean $hidden - if true, then default style is set to hidden,
602 * - default value false
606 function PMA_getHtmlForReplicationSlavesTable($hidden = false)
610 $data = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null);
613 $html .= ' <div id="replication_slaves_section" style="';
614 $html .= ($hidden ?
'display: none;' : '') . '"> ';
615 $html .= ' <table class="data">';
618 $html .= ' <th>' . __('Server ID') . '</th>';
619 $html .= ' <th>' . __('Host') . '</th>';
621 $html .= ' </thead>';
625 foreach ($data as $slave) {
626 $html .= ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
627 $html .= ' <td class="value">' . $slave['Server_id'] . '</td>';
628 $html .= ' <td class="value">' . $slave['Host'] . '</td>';
631 $odd_row = ! $odd_row;
634 $html .= ' </tbody>';
635 $html .= ' </table>';
637 $html .= PMA_Message
::notice(
639 'Only slaves started with the '
640 . '--report-host=host_name option are visible in this list.'
650 * get the correct username and hostname lengths for this MySQL server
652 * @return array username length, hostname length
654 function PMA_replicationGetUsernameHostnameLength()
656 $fields_info = $GLOBALS['dbi']->getColumns('mysql', 'user');
657 $username_length = 16;
658 $hostname_length = 41;
659 foreach ($fields_info as $val) {
660 if ($val['Field'] == 'User') {
661 strtok($val['Type'], '()');
664 $username_length = $v;
666 } elseif ($val['Field'] == 'Host') {
667 strtok($val['Type'], '()');
670 $hostname_length = $v;
674 return array($username_length, $hostname_length);
678 * returns html code to add a replication slave user to the master
680 * @return String HTML code
682 function PMA_getHtmlForReplicationMasterAddSlaveuser()
685 list($username_length, $hostname_length)
686 = PMA_replicationGetUsernameHostnameLength();
688 if (isset($_REQUEST['username'])
689 && /*overload*/mb_strlen($_REQUEST['username']) === 0
691 $GLOBALS['pred_username'] = 'any';
693 $html .= '<div id="master_addslaveuser_gui">';
694 $html .= '<form autocomplete="off" method="post" ';
695 $html .= 'action="server_privileges.php"';
696 $html .= ' onsubmit="return checkAddUser(this);">';
697 $html .= PMA_URL_getHiddenInputs('', '');
698 $html .= '<fieldset id="fieldset_add_user_login">'
699 . '<legend>' . __('Add slave replication user') . '</legend>'
700 . PMA_getHtmlForAddUserLoginForm($username_length)
701 . '<div class="item">'
702 . '<label for="select_pred_hostname">'
705 . '<span class="options">'
706 . ' <select name="pred_hostname" id="select_pred_hostname" title="'
709 $_current_user = $GLOBALS['dbi']->fetchValue('SELECT USER();');
710 if (! empty($_current_user)) {
711 $thishost = str_replace(
714 /*overload*/mb_substr(
716 (/*overload*/mb_strrpos($_current_user, '@') +
1)
719 if ($thishost == 'localhost' ||
$thishost == '127.0.0.1') {
723 $html .= ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } '
724 . 'else if (this.value == \'localhost\') '
725 . '{ hostname.value = \'localhost\'; } '
728 : 'else if (this.value == \'thishost\') { hostname.value = \''
729 . addslashes(htmlspecialchars($thishost)) . '\'; } ')
730 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } '
731 . 'else if (this.value == \'userdefined\') '
732 . '{ hostname.focus(); hostname.select(); }">'
734 unset($_current_user);
736 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
737 if (! isset($GLOBALS['pred_hostname']) && isset($_REQUEST['hostname'])) {
738 switch (/*overload*/mb_strtolower($_REQUEST['hostname'])) {
741 $GLOBALS['pred_hostname'] = 'localhost';
744 $GLOBALS['pred_hostname'] = 'any';
747 $GLOBALS['pred_hostname'] = 'userdefined';
751 $html .= ' <option value="any"'
752 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
753 ?
' selected="selected"' : '') . '>' . __('Any host')
755 . ' <option value="localhost"'
756 . ((isset($GLOBALS['pred_hostname'])
757 && $GLOBALS['pred_hostname'] == 'localhost')
758 ?
' selected="selected"' : '') . '>' . __('Local')
761 if (!empty($thishost)) {
762 $html .= ' <option value="thishost"'
763 . ((isset($GLOBALS['pred_hostname'])
764 && $GLOBALS['pred_hostname'] == 'thishost')
765 ?
' selected="selected"' : '') . '>' . __('This Host')
770 $html .= PMA_getHtmlForTableInfoForm($hostname_length);
777 * returns html code to add a replication slave user to the master
779 * @param int $username_length Username length
781 * @return String HTML code
783 function PMA_getHtmlForAddUserLoginForm($username_length)
785 $html = '<input type="hidden" name="grant_count" value="25" />'
786 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
787 . '<input id="checkbox_Repl_slave_priv" type="hidden"'
788 . ' title="Needed for the replication slaves." '
789 . 'value="Y" name="Repl_slave_priv"/>'
790 . '<input id="checkbox_Repl_client_priv" type="hidden" '
791 . 'title="Needed for the replication slaves."'
792 . ' value="Y" name="Repl_client_priv"/> '
793 . '<input type="hidden" name="sr_take_action" value="true" />'
794 . '<div class="item">'
795 . '<label for="select_pred_username">'
796 . ' ' . __('User name:')
798 . '<span class="options">'
799 . ' <select name="pred_username" id="select_pred_username" '
800 . 'title="' . __('User name') . '"'
801 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } '
802 . 'else if (this.value == \'userdefined\') { '
803 . ' username.focus(); username.select(); }">'
804 . ' <option value="any"'
805 . ((isset($GLOBALS['pred_username'])
806 && $GLOBALS['pred_username'] == 'any') ?
' selected="selected"' : '')
807 . '>' . __('Any user') . '</option>'
808 . ' <option value="userdefined"'
809 . ((! isset($GLOBALS['pred_username'])
810 ||
$GLOBALS['pred_username'] == 'userdefined')
811 ?
' selected="selected"' : '')
812 . '>' . __('Use text field:') . '</option>'
815 . '<input type="text" name="username" maxlength="'
816 . $username_length . '" title="' . __('User name') . '"'
817 . (empty($_REQUEST['username']) ?
'' : ' value="'
818 . (isset($GLOBALS['new_username'])
819 ?
$GLOBALS['new_username']
820 : $_REQUEST['username']) . '"')
821 . ' onchange="pred_username.value = \'userdefined\';" />'
828 * returns HTML for TableInfoForm
830 * @param int $hostname_length Selected hostname length
832 * @return String HTML code
834 function PMA_getHtmlForTableInfoForm($hostname_length)
836 $html = ' <option value="hosttable"'
837 . ((isset($GLOBALS['pred_hostname'])
838 && $GLOBALS['pred_hostname'] == 'hosttable')
839 ?
' selected="selected"' : '') . '>' . __('Use Host Table')
841 . ' <option value="userdefined"'
842 . ((isset($GLOBALS['pred_hostname'])
843 && $GLOBALS['pred_hostname'] == 'userdefined')
844 ?
' selected="selected"' : '')
845 . '>' . __('Use text field:') . '</option>'
848 . '<input type="text" name="hostname" maxlength="'
849 . $hostname_length . '" value="'
850 . (isset($_REQUEST['hostname']) ?
$_REQUEST['hostname'] : '')
851 . '" title="' . __('Host')
852 . '" onchange="pred_hostname.value = \'userdefined\';" />'
853 . PMA_Util
::showHint(
855 'When Host table is used, this field is ignored '
856 . 'and values stored in Host table are used instead.'
860 . '<div class="item">'
861 . '<label for="select_pred_password">'
862 . ' ' . __('Password:')
864 . '<span class="options">'
865 . ' <select name="pred_password" id="select_pred_password" title="'
866 . __('Password') . '"'
867 . ' onchange="if (this.value == \'none\') '
868 . '{ pma_pw.value = \'\'; pma_pw2.value = \'\'; } '
869 . 'else if (this.value == \'userdefined\') '
870 . '{ pma_pw.focus(); pma_pw.select(); }">'
871 . ' <option value="none"';
872 if (isset($_REQUEST['username'])) {
873 $html .= ' selected="selected"';
875 $html .= '>' . __('No Password') . '</option>'
876 . ' <option value="userdefined"'
877 . (isset($_REQUEST['username']) ?
'' : ' selected="selected"')
878 . '>' . __('Use text field:') . '</option>'
881 . '<input type="password" id="text_pma_pw" name="pma_pw" title="'
882 . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
884 . '<div class="item">'
885 . '<label for="text_pma_pw2">'
886 . ' ' . __('Re-type:')
888 . '<span class="options"> </span>'
889 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="'
890 . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
892 . '<div class="item">'
893 . '<label for="button_generate_password">'
894 . ' ' . __('Generate Password:')
896 . '<span class="options">'
897 . ' <input type="button" class="button" '
898 . 'id="button_generate_password" value="' . __('Generate')
899 . '" onclick="suggestPassword(this.form)" />'
901 . '<input type="text" name="generated_pw" id="generated_pw" />'
904 $html .= '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
905 . ' <input type="hidden" name="adduser_submit" value="1" />'
906 . ' <input type="submit" id="adduser_submit" value="' . __('Go') . '" />'
912 * handle control requests
916 function PMA_handleControlRequest()
918 if (isset($_REQUEST['sr_take_action'])) {
921 $messageSuccess = null;
922 $messageError = null;
924 if (isset($_REQUEST['slave_changemaster'])) {
925 $result = PMA_handleRequestForSlaveChangeMaster();
926 } elseif (isset($_REQUEST['sr_slave_server_control'])) {
927 $result = PMA_handleRequestForSlaveServerControl();
930 switch ($_REQUEST['sr_slave_action']) {
932 $messageSuccess = __('Replication started successfully.');
933 $messageError = __('Error starting replication.');
936 $messageSuccess = __('Replication stopped successfully.');
937 $messageError = __('Error stopping replication.');
940 $messageSuccess = __('Replication resetting successfully.');
941 $messageError = __('Error resetting replication.');
944 $messageSuccess = __('Success.');
945 $messageError = __('Error.');
948 } elseif (isset($_REQUEST['sr_slave_skip_error'])) {
949 $result = PMA_handleRequestForSlaveSkipError();
953 $response = PMA_Response
::getInstance();
954 if ($response->isAjax()) {
955 $response->isSuccess($result);
959 ? PMA_Message
::success($messageSuccess)
960 : PMA_Message
::error($messageError)
963 PMA_sendHeaderLocation(
964 $GLOBALS['cfg']['PmaAbsoluteUri'] . 'server_replication.php'
965 . PMA_URL_getCommon($GLOBALS['url_params'], 'text')
973 * handle control requests for Slave Change Master
977 function PMA_handleRequestForSlaveChangeMaster()
980 $_SESSION['replication']['m_username'] = $sr['username']
981 = PMA_Util
::sqlAddSlashes($_REQUEST['username']);
982 $_SESSION['replication']['m_password'] = $sr['pma_pw']
983 = PMA_Util
::sqlAddSlashes($_REQUEST['pma_pw']);
984 $_SESSION['replication']['m_hostname'] = $sr['hostname']
985 = PMA_Util
::sqlAddSlashes($_REQUEST['hostname']);
986 $_SESSION['replication']['m_port'] = $sr['port']
987 = PMA_Util
::sqlAddSlashes($_REQUEST['text_port']);
988 $_SESSION['replication']['m_correct'] = '';
989 $_SESSION['replication']['sr_action_status'] = 'error';
990 $_SESSION['replication']['sr_action_info'] = __('Unknown error');
992 // Attempt to connect to the new master server
993 $link_to_master = PMA_Replication_connectToMaster(
994 $sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port']
997 if (! $link_to_master) {
998 $_SESSION['replication']['sr_action_status'] = 'error';
999 $_SESSION['replication']['sr_action_info'] = sprintf(
1000 __('Unable to connect to master %s.'),
1001 htmlspecialchars($sr['hostname'])
1004 // Read the current master position
1005 $position = PMA_Replication_Slave_binLogMaster($link_to_master);
1007 if (empty($position)) {
1008 $_SESSION['replication']['sr_action_status'] = 'error';
1009 $_SESSION['replication']['sr_action_info']
1011 'Unable to read master log position. '
1012 . 'Possible privilege problem on master.'
1015 $_SESSION['replication']['m_correct'] = true;
1017 if (! PMA_Replication_Slave_changeMaster(
1027 $_SESSION['replication']['sr_action_status'] = 'error';
1028 $_SESSION['replication']['sr_action_info']
1029 = __('Unable to change master!');
1031 $_SESSION['replication']['sr_action_status'] = 'success';
1032 $_SESSION['replication']['sr_action_info'] = sprintf(
1033 __('Master server changed successfully to %s.'),
1034 htmlspecialchars($sr['hostname'])
1040 return $_SESSION['replication']['sr_action_status'] === 'success';
1044 * handle control requests for Slave Server Control
1048 function PMA_handleRequestForSlaveServerControl()
1050 if (empty($_REQUEST['sr_slave_control_parm'])) {
1051 $_REQUEST['sr_slave_control_parm'] = null;
1053 if ($_REQUEST['sr_slave_action'] == 'reset') {
1054 $qStop = PMA_Replication_Slave_control("STOP");
1055 $qReset = $GLOBALS['dbi']->tryQuery("RESET SLAVE;");
1056 $qStart = PMA_Replication_Slave_control("START");
1058 $result = ($qStop !== false && $qStop !== -1 &&
1059 $qReset !== false && $qReset !== -1 &&
1060 $qStart !== false && $qStart !== -1);
1062 $qControl = PMA_Replication_Slave_control(
1063 $_REQUEST['sr_slave_action'],
1064 $_REQUEST['sr_slave_control_parm']
1067 $result = ($qControl !== false && $qControl !== -1);
1074 * handle control requests for Slave Skip Error
1078 function PMA_handleRequestForSlaveSkipError()
1081 if (isset($_REQUEST['sr_skip_errors_count'])) {
1082 $count = $_REQUEST['sr_skip_errors_count'] * 1;
1085 $qStop = PMA_Replication_Slave_control("STOP");
1086 $qSkip = $GLOBALS['dbi']->tryQuery(
1087 "SET GLOBAL SQL_SLAVE_SKIP_COUNTER = " . $count . ";"
1089 $qStart = PMA_Replication_Slave_control("START");
1091 $result = ($qStop !== false && $qStop !== -1 &&
1092 $qSkip !== false && $qSkip !== -1 &&
1093 $qStart !== false && $qStart !== -1);