2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 if (! defined('PHPMYADMIN')) {
13 * returns code for selecting databases
15 * @return String HTML code
17 function PMA_replication_db_multibox()
20 $multi_values .= '<select name="db_select[]" size="6" multiple="multiple" id="db_select">';
22 foreach ($GLOBALS['pma']->databases
as $current_db) {
23 if (! empty($selectall) ||
(isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
24 $is_selected = ' selected="selected"';
28 $current_db = htmlspecialchars($current_db);
29 $multi_values .= ' <option value="' . $current_db . '" ' . $is_selected . '>' . $current_db . '</option>';
32 $multi_values .= '</select>';
33 $multi_values .= '<br /><a href="#" id="db_reset_href">' . __('Uncheck All') . '</a>';
39 * prints out code for changing master
41 * @param String $submitname - submit button name
44 function PMA_replication_gui_changemaster($submitname) {
46 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
48 echo '<form method="post" action="server_replication.php">';
49 echo PMA_generate_common_hidden_inputs('', '');
50 echo ' <fieldset id="fieldset_add_user_login">';
51 echo ' <legend>' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . '</legend>';
52 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 />';
53 echo '<pre>server-id=' . time() . '</pre>';
54 echo ' <div class="item">';
55 echo ' <label for="text_username">' . __('User name') . ':</label>';
56 echo ' <input type="text" name="username" id="text_username" maxlength="'. $username_length . '" title="' . __('User name') . '" />';
58 echo ' <div class="item">';
59 echo ' <label for="text_pma_pw">' . __('Password') .' :</label>';
60 echo ' <input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" />';
62 echo ' <div class="item">';
63 echo ' <label for="text_hostname">' . __('Host') . ' :</label>';
64 echo ' <input type="text" id="text_hostname" name="hostname" maxlength="' . $hostname_length . '" value="" />';
66 echo ' <div class="item">';
67 echo ' <label for="text_port">' . __('Port') . ':</label>';
68 echo ' <input type="text" id="text_port" name="port" maxlength="6" value="3306" />';
71 echo ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
72 echo ' <input type="hidden" name="sr_take_action" value="true" />';
73 echo ' <input type="submit" name="' . $submitname . '" id="confslave_submit" value="' . __('Go') . '" />';
79 * This function prints out table with replication status.
81 * @param String type - either master or slave
82 * @param boolean $hidden - if true, then default style is set to hidden, default value false
83 * @param boolen $title - if true, then title is displayed, default true
85 function PMA_replication_print_status_table($type, $hidden = false, $title = true) {
86 global $
{"{$type}_variables"};
87 global $
{"{$type}_variables_alerts"};
88 global $
{"{$type}_variables_oks"};
89 global $
{"server_{$type}_replication"};
90 global $
{"strReplicationStatus_{$type}"};
92 // TODO check the Masters server id?
93 // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects
94 // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236)
95 // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log
97 //$server_id = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'server_id'", 0, 1);
99 echo '<div id="replication_' . $type . '_section" style="' . ($hidden ?
'display: none;' : '') . '"> ';
102 echo '<h4><a name="replication_' . $type . '"></a>' . $
{"strReplicationStatus_{$type}"} . '</h4>';
107 echo ' <table id="server' . $type . 'replicationsummary" class="data"> ';
110 echo ' <th>' . __('Variable') . '</th>';
111 echo ' <th>' . __('Value') . '</th>';
117 foreach ($
{"{$type}_variables"} as $variable) {
118 echo ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
119 echo ' <td class="name">';
122 echo ' <td class="value">';
125 // TODO change to regexp or something, to allow for negative match
126 if (isset($
{"{$type}_variables_alerts"}[$variable])
127 && $
{"{$type}_variables_alerts"}[$variable] == $
{"server_{$type}_replication"}[0][$variable]
129 echo '<span class="attention">';
131 } elseif (isset($
{"{$type}_variables_oks"}[$variable])
132 && $
{"{$type}_variables_oks"}[$variable] == $
{"server_{$type}_replication"}[0][$variable]
134 echo '<span class="allfine">';
138 echo $
{"server_{$type}_replication"}[0][$variable];
144 $odd_row = ! $odd_row;
155 * Prints table with slave users connected to this master
157 * @param boolean $hidden - if true, then default style is set to hidden, default value false
159 function PMA_replication_print_slaves_table($hidden = false) {
162 $data = PMA_DBI_fetch_result('SHOW SLAVE HOSTS', null, null);
165 echo ' <div id="replication_slaves_section" style="' . ($hidden ?
'display: none;' : '') . '"> ';
166 echo ' <table class="data">';
169 echo ' <th>' . __('Server ID') . '</th>';
170 echo ' <th>' . __('Host') . '</th>';
176 foreach ($data as $slave) {
177 echo ' <tr class="' . ($odd_row ?
'odd' : 'even') . '">';
178 echo ' <td class="value">' . $slave['Server_id'] . '</td>';
179 echo ' <td class="value">' . $slave['Host'] . '</td>';
182 $odd_row = ! $odd_row;
188 PMA_Message
::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display();
194 * get the correct username and hostname lengths for this MySQL server
197 * @return array username length, hostname length
200 function PMA_replication_get_username_hostname_length() {
201 $fields_info = PMA_DBI_get_fields('mysql', 'user');
202 $username_length = 16;
203 $hostname_length = 41;
204 foreach ($fields_info as $key => $val) {
205 if ($val['Field'] == 'User') {
206 strtok($val['Type'], '()');
209 $username_length = $v;
211 } elseif ($val['Field'] == 'Host') {
212 strtok($val['Type'], '()');
215 $hostname_length = $v;
219 return array($username_length, $hostname_length);
223 * Print code to add a replication slave user to the master
225 function PMA_replication_gui_master_addslaveuser() {
227 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
229 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
230 $GLOBALS['pred_username'] = 'any';
232 echo '<div id="master_addslaveuser_gui">';
233 echo '<form autocomplete="off" method="post" action="server_privileges.php" onsubmit="return checkAddUser(this);">';
234 echo PMA_generate_common_hidden_inputs('', '');
235 echo '<fieldset id="fieldset_add_user_login">'
236 . '<legend>'.__('Add slave replication user').'</legend>'
237 . '<input type="hidden" name="grant_count" value="25" />'
238 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
239 . '<input id="checkbox_Repl_slave_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_slave_priv"/>'
240 . '<input id="checkbox_Repl_client_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_client_priv"/>'
242 . '<input type="hidden" name="sr_take_action" value="true" />'
243 . '<div class="item">'
244 . '<label for="select_pred_username">'
245 . ' ' . __('User name') . ':'
247 . '<span class="options">'
248 . ' <select name="pred_username" id="select_pred_username" title="' . __('User name') . '"'
249 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">'
250 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ?
' selected="selected"' : '') . '>' . __('Any user') . '</option>'
251 . ' <option value="userdefined"' . ((! isset($GLOBALS['pred_username']) ||
$GLOBALS['pred_username'] == 'userdefined') ?
' selected="selected"' : '') . '>' . __('Use text field') . ':</option>'
254 . '<input type="text" name="username" maxlength="'
255 . $username_length . '" title="' . __('User name') . '"'
256 . (empty($GLOBALS['username'])
258 : ' value="' . (isset($GLOBALS['new_username'])
259 ?
$GLOBALS['new_username']
260 : $GLOBALS['username']) . '"')
261 . ' onchange="pred_username.value = \'userdefined\';" />'
263 . '<div class="item">'
264 . '<label for="select_pred_hostname">'
265 . ' ' . __('Host') . ':'
267 . '<span class="options">'
268 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"';
269 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
270 if (! empty($_current_user)) {
271 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') +
1)));
272 if ($thishost == 'localhost' ||
$thishost == '127.0.0.1') {
276 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
277 . (empty($thishost) ?
'' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
278 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
279 unset($_current_user);
281 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
282 if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
283 switch (strtolower($GLOBALS['hostname'])) {
286 $GLOBALS['pred_hostname'] = 'localhost';
289 $GLOBALS['pred_hostname'] = 'any';
292 $GLOBALS['pred_hostname'] = 'userdefined';
296 echo ' <option value="any"'
297 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
298 ?
' selected="selected"' : '') . '>' . __('Any host')
300 . ' <option value="localhost"'
301 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
302 ?
' selected="selected"' : '') . '>' . __('Local')
305 if (!empty($thishost)) {
306 echo ' <option value="thishost"'
307 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
308 ?
' selected="selected"' : '') . '>' . __('This Host')
312 echo ' <option value="hosttable"'
313 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
314 ?
' selected="selected"' : '') . '>' . __('Use Host Table')
316 . ' <option value="userdefined"'
317 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
318 ?
' selected="selected"' : '')
319 . '>' . __('Use text field') . ':</option>'
322 . '<input type="text" name="hostname" maxlength="'
323 . $hostname_length . '" value="'
324 . (isset($GLOBALS['hostname']) ?
$GLOBALS['hostname'] : '')
325 . '" title="' . __('Host')
326 . '" onchange="pred_hostname.value = \'userdefined\';" />'
327 . PMA_showHint(__('When Host table is used, this field is ignored and values stored in Host table are used instead.'))
329 . '<div class="item">'
330 . '<label for="select_pred_password">'
331 . ' ' . __('Password') . ':'
333 . '<span class="options">'
334 . ' <select name="pred_password" id="select_pred_password" title="'
335 . __('Password') . '"'
336 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">'
337 . ' <option value="none"';
338 if (isset($GLOBALS['username']) && $mode != 'change') {
339 echo ' selected="selected"';
341 echo '>' . __('No Password') . '</option>'
342 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ?
'' : ' selected="selected"') . '>' . __('Use text field') . ':</option>'
345 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
347 . '<div class="item">'
348 . '<label for="text_pma_pw2">'
349 . ' ' . __('Re-type') . ':'
351 . '<span class="options"> </span>'
352 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
354 . '<div class="item">'
355 . '<label for="button_generate_password">'
356 . ' ' . __('Generate Password') . ':'
358 . '<span class="options">'
359 . ' <input type="button" id="button_generate_password" value="' . __('Generate') . '" onclick="suggestPassword(this.form)" />'
361 . '<input type="text" name="generated_pw" id="generated_pw" />'
364 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
365 . ' <input type="submit" name="adduser_submit" id="adduser_submit" value="' . __('Go') . '" />'