2 /* vim: set expandtab sw=4 ts=4 sts=4: */
7 if (! defined('PHPMYADMIN')) {
12 * returns code for selecting databases
14 * @return String HTML code
16 function PMA_replication_db_multibox()
19 $multi_values .= '<select name="db_select[]" size="6" multiple="multiple" id="db_select">';
21 foreach ($GLOBALS['pma']->databases
as $current_db) {
22 if (PMA_is_system_schema($current_db)) {
25 if (! empty($selectall) ||
(isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
26 $is_selected = ' selected="selected"';
30 $current_db = htmlspecialchars($current_db);
31 $multi_values .= ' <option value="' . $current_db . '" ' . $is_selected . '>' . $current_db . '</option>';
34 $multi_values .= '</select>';
35 $multi_values .= '<br /><a href="#" id="db_reset_href">' . __('Uncheck All') . '</a>';
41 * prints out code for changing master
43 * @param String $submitname - submit button name
48 function PMA_replication_gui_changemaster($submitname)
51 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
53 echo '<form method="post" action="server_replication.php">';
54 echo PMA_generate_common_hidden_inputs('', '');
55 echo ' <fieldset id="fieldset_add_user_login">';
56 echo ' <legend>' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . '</legend>';
57 echo __('Make sure, you have unique server-id in your configuration file (my.cnf). If not, please add the following line into [mysqld] section:') . '<br />';
58 echo '<pre>server-id=' . time() . '</pre>';
59 echo ' <div class="item">';
60 echo ' <label for="text_username">' . __('User name') . ':</label>';
61 echo ' <input type="text" name="username" id="text_username" maxlength="'. $username_length . '" title="' . __('User name') . '" />';
63 echo ' <div class="item">';
64 echo ' <label for="text_pma_pw">' . __('Password') .' :</label>';
65 echo ' <input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" />';
67 echo ' <div class="item">';
68 echo ' <label for="text_hostname">' . __('Host') . ' :</label>';
69 echo ' <input type="text" id="text_hostname" name="hostname" maxlength="' . $hostname_length . '" value="" />';
71 echo ' <div class="item">';
72 echo ' <label for="text_port">' . __('Port') . ':</label>';
73 echo ' <input type="text" id="text_port" name="port" maxlength="6" value="3306" />';
76 echo ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
77 echo ' <input type="hidden" name="sr_take_action" value="true" />';
78 echo ' <input type="hidden" name="' . $submitname . '" value="1" />';
79 echo ' <input type="submit" id="confslave_submit" value="' . __('Go') . '" />';
85 * This function prints out table with replication status.
87 * @param string $type either master or slave
88 * @param boolean $hidden if true, then default style is set to hidden, default value false
89 * @param boolen $title if true, then title is displayed, default true
93 function PMA_replication_print_status_table($type, $hidden = false, $title = true)
95 global $
{"{$type}_variables"};
96 global $
{"{$type}_variables_alerts"};
97 global $
{"{$type}_variables_oks"};
98 global $
{"server_{$type}_replication"};
99 global $
{"strReplicationStatus_{$type}"};
101 // TODO check the Masters server id?
102 // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects
103 // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236)
104 // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log
106 //$server_id = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'server_id'", 0, 1);
108 echo '<div id="replication_' . $type . '_section" style="' . ($hidden ?
'display: none;' : '') . '"> ';
111 if ($type == 'master') {
112 echo '<h4><a name="replication_' . $type . '"></a>' . __('Master status') . '</h4>';
114 echo '<h4><a name="replication_' . $type . '"></a>' . __('Slave status') . '</h4>';
120 echo ' <table id="server' . $type . 'replicationsummary" class="data"> ';
123 echo ' <th>' . __('Variable') . '</th>';
124 echo ' <th>' . __('Value') . '</th>';
130 foreach ($
{"{$type}_variables"} as $variable) {
131 echo ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
132 echo ' <td class="name">';
135 echo ' <td class="value">';
138 // TODO change to regexp or something, to allow for negative match
139 if (isset($
{"{$type}_variables_alerts"}[$variable])
140 && $
{"{$type}_variables_alerts"}[$variable] == $
{"server_{$type}_replication"}[0][$variable]
142 echo '<span class="attention">';
144 } elseif (isset($
{"{$type}_variables_oks"}[$variable])
145 && $
{"{$type}_variables_oks"}[$variable] == $
{"server_{$type}_replication"}[0][$variable]
147 echo '<span class="allfine">';
151 // allow wrapping long table lists into multiple lines
152 static $variables_wrap = array(
153 'Replicate_Do_DB', 'Replicate_Ignore_DB',
154 'Replicate_Do_Table', 'Replicate_Ignore_Table',
155 'Replicate_Wild_Do_Table', 'Replicate_Wild_Ignore_Table');
156 if (in_array($variable, $variables_wrap)) {
157 echo str_replace(',', ', ', $
{"server_{$type}_replication"}[0][$variable]);
159 echo $
{"server_{$type}_replication"}[0][$variable];
166 $odd_row = ! $odd_row;
177 * Prints table with slave users connected to this master
179 * @param boolean $hidden - if true, then default style is set to hidden, default value false
183 function PMA_replication_print_slaves_table($hidden = false)
187 $data = PMA_DBI_fetch_result('SHOW SLAVE HOSTS', null, null);
190 echo ' <div id="replication_slaves_section" style="' . ($hidden ?
'display: none;' : '') . '"> ';
191 echo ' <table class="data">';
194 echo ' <th>' . __('Server ID') . '</th>';
195 echo ' <th>' . __('Host') . '</th>';
201 foreach ($data as $slave) {
202 echo ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
203 echo ' <td class="value">' . $slave['Server_id'] . '</td>';
204 echo ' <td class="value">' . $slave['Host'] . '</td>';
207 $odd_row = ! $odd_row;
213 PMA_Message
::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display();
219 * get the correct username and hostname lengths for this MySQL server
221 * @return array username length, hostname length
224 function PMA_replication_get_username_hostname_length()
226 $fields_info = PMA_DBI_get_columns('mysql', 'user');
227 $username_length = 16;
228 $hostname_length = 41;
229 foreach ($fields_info as $val) {
230 if ($val['Field'] == 'User') {
231 strtok($val['Type'], '()');
234 $username_length = $v;
236 } elseif ($val['Field'] == 'Host') {
237 strtok($val['Type'], '()');
240 $hostname_length = $v;
244 return array($username_length, $hostname_length);
248 * Print code to add a replication slave user to the master
252 function PMA_replication_gui_master_addslaveuser()
255 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
257 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
258 $GLOBALS['pred_username'] = 'any';
260 echo '<div id="master_addslaveuser_gui">';
261 echo '<form autocomplete="off" method="post" action="server_privileges.php" onsubmit="return checkAddUser(this);">';
262 echo PMA_generate_common_hidden_inputs('', '');
263 echo '<fieldset id="fieldset_add_user_login">'
264 . '<legend>'.__('Add slave replication user').'</legend>'
265 . '<input type="hidden" name="grant_count" value="25" />'
266 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
267 . '<input id="checkbox_Repl_slave_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_slave_priv"/>'
268 . '<input id="checkbox_Repl_client_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_client_priv"/>'
270 . '<input type="hidden" name="sr_take_action" value="true" />'
271 . '<div class="item">'
272 . '<label for="select_pred_username">'
273 . ' ' . __('User name') . ':'
275 . '<span class="options">'
276 . ' <select name="pred_username" id="select_pred_username" title="' . __('User name') . '"'
277 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">'
278 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ?
' selected="selected"' : '') . '>' . __('Any user') . '</option>'
279 . ' <option value="userdefined"' . ((! isset($GLOBALS['pred_username']) ||
$GLOBALS['pred_username'] == 'userdefined') ?
' selected="selected"' : '') . '>' . __('Use text field') . ':</option>'
282 . '<input type="text" name="username" maxlength="'
283 . $username_length . '" title="' . __('User name') . '"'
284 . (empty($GLOBALS['username'])
286 : ' value="' . (isset($GLOBALS['new_username'])
287 ?
$GLOBALS['new_username']
288 : $GLOBALS['username']) . '"')
289 . ' onchange="pred_username.value = \'userdefined\';" />'
291 . '<div class="item">'
292 . '<label for="select_pred_hostname">'
293 . ' ' . __('Host') . ':'
295 . '<span class="options">'
296 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"';
297 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
298 if (! empty($_current_user)) {
299 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') +
1)));
300 if ($thishost == 'localhost' ||
$thishost == '127.0.0.1') {
304 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
305 . (empty($thishost) ?
'' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
306 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
307 unset($_current_user);
309 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
310 if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
311 switch (strtolower($GLOBALS['hostname'])) {
314 $GLOBALS['pred_hostname'] = 'localhost';
317 $GLOBALS['pred_hostname'] = 'any';
320 $GLOBALS['pred_hostname'] = 'userdefined';
324 echo ' <option value="any"'
325 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
326 ?
' selected="selected"' : '') . '>' . __('Any host')
328 . ' <option value="localhost"'
329 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
330 ?
' selected="selected"' : '') . '>' . __('Local')
333 if (!empty($thishost)) {
334 echo ' <option value="thishost"'
335 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
336 ?
' selected="selected"' : '') . '>' . __('This Host')
340 echo ' <option value="hosttable"'
341 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
342 ?
' selected="selected"' : '') . '>' . __('Use Host Table')
344 . ' <option value="userdefined"'
345 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
346 ?
' selected="selected"' : '')
347 . '>' . __('Use text field') . ':</option>'
350 . '<input type="text" name="hostname" maxlength="'
351 . $hostname_length . '" value="'
352 . (isset($GLOBALS['hostname']) ?
$GLOBALS['hostname'] : '')
353 . '" title="' . __('Host')
354 . '" onchange="pred_hostname.value = \'userdefined\';" />'
355 . PMA_Util
::showHint(
356 __('When Host table is used, this field is ignored and values stored in Host table are used instead.')
359 . '<div class="item">'
360 . '<label for="select_pred_password">'
361 . ' ' . __('Password') . ':'
363 . '<span class="options">'
364 . ' <select name="pred_password" id="select_pred_password" title="'
365 . __('Password') . '"'
366 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">'
367 . ' <option value="none"';
368 if (isset($GLOBALS['username'])) {
369 echo ' selected="selected"';
371 echo '>' . __('No Password') . '</option>'
372 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ?
'' : ' selected="selected"') . '>' . __('Use text field') . ':</option>'
375 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
377 . '<div class="item">'
378 . '<label for="text_pma_pw2">'
379 . ' ' . __('Re-type') . ':'
381 . '<span class="options"> </span>'
382 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
384 . '<div class="item">'
385 . '<label for="button_generate_password">'
386 . ' ' . __('Generate Password') . ':'
388 . '<span class="options">'
389 . ' <input type="button" class="button" id="button_generate_password" value="' . __('Generate') . '" onclick="suggestPassword(this.form)" />'
391 . '<input type="text" name="generated_pw" id="generated_pw" />'
394 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
395 . ' <input type="hidden" name="adduser_submit" value="1" />'
396 . ' <input type="submit" id="adduser_submit" value="' . __('Go') . '" />'