Translated using Weblate (Estonian)
[phpmyadmin.git] / libraries / replication_gui.lib.php
blob70f1618811e81e4722036c4fdba2b827ac671282
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
12 * returns HTML for error message
14 * @return String HTML code
16 function PMA_getHtmlForErrorMessage()
18 $html = '';
19 if (isset($_SESSION['replication']['sr_action_status'])
20 && isset($_SESSION['replication']['sr_action_info'])
21 ) {
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';
32 return $html;
35 /**
36 * returns HTML for master replication
38 * @return String HTML code
40 function PMA_getHtmlForMasterReplication()
42 $html = '';
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.');
47 $html .= '<ul>';
48 $html .= ' <li><a href="#" id="master_status_href">';
49 $html .= __('Show master status') . '</a>';
50 $html .= PMA_getHtmlForReplicationStatusTable('master', true, false);
51 $html .= ' </li>';
53 $html .= ' <li><a href="#" id="master_slaves_href">';
54 $html .= __('Show connected slaves') . '</a>';
55 $html .= PMA_getHtmlForReplicationSlavesTable(true);
56 $html .= ' </li>';
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'])) {
72 $html .= "</ul>";
73 $html .= "</fieldset>";
76 return $html;
79 /**
80 * returns HTML for master replication configuration
82 * @return String HTML code
84 function PMA_getHtmlForMasterConfiguration()
86 $html = '<fieldset>';
87 $html .= '<legend>' . __('Master configuration') . '</legend>';
88 $html .= __(
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:'
95 ) . '<br /><br />';
97 $html .= '<select name="db_type" id="db_type">';
98 $html .= '<option value="all">' . __('Replicate all databases; Ignore:');
99 $html .= '</option>';
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 />';
107 $html .= __(
108 'Now, add the following lines at the end of [mysqld] section'
109 . ' in your my.cnf and please restart the MySQL server afterwards.'
110 ). '<br />';
111 $html .= '<pre id="rep"></pre>';
112 $html .= __(
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" />';
122 $html .= ' </form>';
123 $html .= '</fieldset>';
125 return $html;
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';
149 } else {
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';
159 } else {
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';
171 } else {
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!')
191 )->getDisplay();
193 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
194 $html .= PMA_Message::error(
195 __('Slave IO Thread not running!')
196 )->getDisplay();
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:');
207 $html .= '<br />';
208 $html .= '<ul>';
209 $html .= ' <li><a href="#" id="slave_status_href">';
210 $html .= __('See slave status table') . '</a>';
211 $html .= PMA_getHtmlForReplicationStatusTable('slave', true, false);
212 $html .= ' </li>';
214 $html .= ' <li><a href="#" id="slave_control_href">';
215 $html .= __('Control slave:') . '</a>';
216 $html .= ' <div id="slave_control_gui" style="display: none">';
217 $html .= ' <ul>';
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')
221 ? __('Full start')
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>';
228 } else {
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>';
235 } else {
236 $html .= ' <li><a href="' . $slave_control_io_link . '">';
237 $html .= __('Stop IO Thread only') . '</a></li>';
239 $html .= ' </ul>';
240 $html .= ' </div>';
241 $html .= ' </li>';
242 $html .= ' <li>';
243 $html .= PMA_getHtmlForSlaveErrorManagement($slave_skip_error_link);
244 $html .= ' </li>';
245 $html .= ' <li><a href="' . $reconfiguremaster_link . '">';
246 $html .= __('Change or reconfigure master server') . '</a></li>';
247 $html .= '</ul>';
248 $html .= '</div>';
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;
255 $html .= sprintf(
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>';
265 return $html;
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!')
282 )->getDisplay();
283 $html .= ' <ul>';
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>';
295 $html .= ' </ul>';
296 $html .= ' </div>';
297 return $html;
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>';
312 $html .= sprintf(
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>';
320 return $html;
324 * returns HTML code for selecting databases
326 * @return String HTML code
328 function PMA_getHtmlForReplicationDbMultibox()
330 $multi_values = '';
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)) {
336 continue;
338 /* TODO: where $selectall should come from? */
339 if (! empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
340 $is_selected = ' selected="selected"';
341 } else {
342 $is_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>';
348 } // end while
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)
367 $html = '';
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>';
376 $html .= __(
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:'
380 $html .= '<br />';
381 $html .= '<pre>server-id=' . time() . '</pre>';
383 $html .= PMA_getHtmlForAddUserInputDiv(
384 array('text'=>__('User name:'), 'for'=>"text_username"),
385 array(
386 'type'=>'text',
387 'name'=>'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"),
397 array(
398 'type'=>'password',
399 'name'=>'pma_pw',
400 'id'=>'text_pma_pw',
401 'title'=>__('Password'),
402 'required'=>'required'
406 $html .= PMA_getHtmlForAddUserInputDiv(
407 array('text'=>__('Host:'), 'for'=>"text_hostname"),
408 array(
409 'type'=>'text',
410 'name'=>'hostname',
411 'id'=>'text_hostname',
412 'maxlength'=>$hostname_length,
413 'value'=>'',
414 'required'=>'required'
418 $html .= PMA_getHtmlForAddUserInputDiv(
419 array('text'=>__('Port:'), 'for'=>"text_port"),
420 array(
421 'type'=>'number',
422 'name'=>'text_port',
423 'id'=>'text_port',
424 'maxlength'=>6,
425 'value'=>'3306',
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>';
437 $html .= '</form>';
439 return $html;
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>';
456 $html .= ' <input ';
457 foreach ($input_array as $key=>$value) {
458 $html .= ' ' . $key . '="' . $value. '" ';
460 $html .= ' />';
461 $html .= ' </div>';
462 return $html;
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}"};
482 $html = '';
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;' : '') . '"> ';
497 if ($title) {
498 if ($type == 'master') {
499 $html .= '<h4><a name="replication_' . $type . '"></a>';
500 $html .= __('Master status') . '</h4>';
501 } else {
502 $html .= '<h4><a name="replication_' . $type . '"></a>';
503 $html .= __('Slave status') . '</h4>';
505 } else {
506 $html .= '<br />';
509 $html .= ' <table id="server' . $type . 'replicationsummary" class="data"> ';
510 $html .= ' <thead>';
511 $html .= ' <tr>';
512 $html .= ' <th>' . __('Variable') . '</th>';
513 $html .= ' <th>' . __('Value') . '</th>';
514 $html .= ' </tr>';
515 $html .= ' </thead>';
516 $html .= ' <tbody>';
518 $odd_row = true;
519 foreach (${"{$type}_variables"} as $variable) {
520 $html .= ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
521 $html .= ' <td class="name">';
522 $html .= $variable;
523 $html .= ' </td>';
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">';
538 } else {
539 $html .= '<span>';
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(
548 ',',
549 ', ',
550 ${"server_{$type}_replication"}[0][$variable]
552 } else {
553 $html .= ${"server_{$type}_replication"}[0][$variable];
555 $html .= '</span>';
557 $html .= ' </td>';
558 $html .= ' </tr>';
560 $odd_row = ! $odd_row;
563 $html .= ' </tbody>';
564 $html .= ' </table>';
565 $html .= ' <br />';
566 $html .= '</div>';
568 return $html;
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
577 * @return void
579 function PMA_getHtmlForReplicationSlavesTable($hidden = false)
581 $html = '';
582 // Fetch data
583 $data = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null);
585 $html .= ' <br />';
586 $html .= ' <div id="replication_slaves_section" style="';
587 $html .= ($hidden ? 'display: none;' : '') . '"> ';
588 $html .= ' <table class="data">';
589 $html .= ' <thead>';
590 $html .= ' <tr>';
591 $html .= ' <th>' . __('Server ID') . '</th>';
592 $html .= ' <th>' . __('Host') . '</th>';
593 $html .= ' </tr>';
594 $html .= ' </thead>';
595 $html .= ' <tbody>';
597 $odd_row = true;
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>';
602 $html .= ' </tr>';
604 $odd_row = ! $odd_row;
607 $html .= ' </tbody>';
608 $html .= ' </table>';
609 $html .= ' <br />';
610 $html .= PMA_Message::notice(
612 'Only slaves started with the '
613 . '--report-host=host_name option are visible in this list.'
615 )->getDisplay();
616 $html .= ' <br />';
617 $html .= ' </div>';
619 return $html;
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'], '()');
636 $v = strtok('()');
637 if (is_int($v)) {
638 $username_length = $v;
640 } elseif ($val['Field'] == 'Host') {
641 strtok($val['Type'], '()');
642 $v = strtok('()');
643 if (is_int($v)) {
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()
658 $html = '';
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">'
675 . ' ' . __('Host:')
676 . '</label>'
677 . '<span class="options">'
678 . ' <select name="pred_hostname" id="select_pred_hostname" title="'
679 . __('Host') . '"';
681 $_current_user = $GLOBALS['dbi']->fetchValue('SELECT USER();');
682 if (! empty($_current_user)) {
683 $thishost = str_replace(
684 "'",
686 substr($_current_user, (strrpos($_current_user, '@') + 1))
688 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
689 unset($thishost);
692 $html .= ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } '
693 . 'else if (this.value == \'localhost\') '
694 . '{ hostname.value = \'localhost\'; } '
695 . (empty($thishost)
696 ? ''
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(); }">'
702 . "\n";
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'])) {
708 case 'localhost':
709 case '127.0.0.1':
710 $GLOBALS['pred_hostname'] = 'localhost';
711 break;
712 case '%':
713 $GLOBALS['pred_hostname'] = 'any';
714 break;
715 default:
716 $GLOBALS['pred_hostname'] = 'userdefined';
717 break;
720 $html .= ' <option value="any"'
721 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
722 ? ' selected="selected"' : '') . '>' . __('Any host')
723 . '</option>'
724 . ' <option value="localhost"'
725 . ((isset($GLOBALS['pred_hostname'])
726 && $GLOBALS['pred_hostname'] == 'localhost')
727 ? ' selected="selected"' : '') . '>' . __('Local')
728 . '</option>';
730 if (!empty($thishost)) {
731 $html .= ' <option value="thishost"'
732 . ((isset($GLOBALS['pred_hostname'])
733 && $GLOBALS['pred_hostname'] == 'thishost')
734 ? ' selected="selected"' : '') . '>' . __('This Host')
735 . '</option>';
737 unset($thishost);
739 $html .= PMA_getHtmlForTableInfoForm($hostname_length);
740 $html .= '</form>';
741 $html .= '</div>';
743 return $html;
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:')
766 . '</label>'
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>'
782 . ' </select>'
783 . '</span>'
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\';" />'
791 . '</div>';
793 return $html;
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')
809 . '</option>'
810 . ' <option value="userdefined"'
811 . ((isset($GLOBALS['pred_hostname'])
812 && $GLOBALS['pred_hostname'] == 'userdefined')
813 ? ' selected="selected"' : '')
814 . '>' . __('Use text field:') . '</option>'
815 . ' </select>'
816 . '</span>'
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.'
828 . '</div>'
829 . '<div class="item">'
830 . '<label for="select_pred_password">'
831 . ' ' . __('Password:')
832 . '</label>'
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>'
848 . ' </select>'
849 . '</span>'
850 . '<input type="password" id="text_pma_pw" name="pma_pw" title="'
851 . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
852 . '</div>'
853 . '<div class="item">'
854 . '<label for="text_pma_pw2">'
855 . ' ' . __('Re-type:')
856 . '</label>'
857 . '<span class="options">&nbsp;</span>'
858 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="'
859 . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
860 . '</div>'
861 . '<div class="item">'
862 . '<label for="button_generate_password">'
863 . ' ' . __('Generate Password:')
864 . '</label>'
865 . '<span class="options">'
866 . ' <input type="button" class="button" '
867 . 'id="button_generate_password" value="' . __('Generate')
868 . '" onclick="suggestPassword(this.form)" />'
869 . '</span>'
870 . '<input type="text" name="generated_pw" id="generated_pw" />'
871 . '</div>'
872 . '</fieldset>';
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') . '" />'
876 . '</fieldset>';
877 return $html;
881 * handle control requests
883 * @return NULL
885 function PMA_handleControlRequest()
887 if (isset($_REQUEST['sr_take_action'])) {
888 $refresh = false;
889 if (isset($_REQUEST['slave_changemaster'])) {
890 PMA_handleRequestForSlaveChangeMaster();
891 } elseif (isset($_REQUEST['sr_slave_server_control'])) {
892 PMA_handleRequestForSlaveServerControl();
893 $refresh = true;
894 } elseif (isset($_REQUEST['sr_slave_skip_error'])) {
895 PMA_handleRequestForSlaveSkipError();
898 if ($refresh) {
899 Header(
900 "Location: server_replication.php"
901 . PMA_URL_getCommon($GLOBALS['url_params'])
904 unset($refresh);
908 * handle control requests for Slave Change Master
910 * @return NULL
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'])
937 } else {
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']
944 = __(
945 'Unable to read master log position. '
946 . 'Possible privilege problem on master.'
948 } else {
949 $_SESSION['replication']['m_correct'] = true;
951 if (! PMA_Replication_Slave_changeMaster(
952 $sr['username'],
953 $sr['pma_pw'],
954 $sr['hostname'],
955 $sr['port'],
956 $position,
957 true,
958 false
961 $_SESSION['replication']['sr_action_status'] = 'error';
962 $_SESSION['replication']['sr_action_info']
963 = __('Unable to change master');
964 } else {
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
978 * @return NULL
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");
986 } else {
987 PMA_Replication_Slave_control(
988 $_REQUEST['sr_slave_action'],
989 $_REQUEST['sr_slave_control_parm']
995 * handle control requests for Slave Skip Error
997 * @return NULL
999 function PMA_handleRequestForSlaveSkipError()
1001 $count = 1;
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");