Refresh .po files
[phpmyadmin/madhuracj.git] / libraries / replication_gui.lib.php
blobac804674b2657f4db6e3010326ef32e31ca13939
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 code for selecting databases
14 * @return String HTML code
16 function PMA_replication_db_multibox()
18 $multi_values = '';
19 $multi_values .= '<select name="db_select[]" size="6" multiple="multiple" id="db_select">';
21 foreach ($GLOBALS['pma']->databases as $current_db) {
22 if ('information_schema' == $current_db) {
23 continue;
25 if (! empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
26 $is_selected = ' selected="selected"';
27 } else {
28 $is_selected = '';
30 $current_db = htmlspecialchars($current_db);
31 $multi_values .= ' <option value="' . $current_db . '" ' . $is_selected . '>' . $current_db . '</option>';
32 } // end while
34 $multi_values .= '</select>';
35 $multi_values .= '<br /><a href="#" id="db_reset_href">' . __('Uncheck All') . '</a>';
37 return $multi_values;
40 /**
41 * prints out code for changing master
43 * @param String $submitname - submit button name
46 function PMA_replication_gui_changemaster($submitname) {
48 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
50 echo '<form method="post" action="server_replication.php">';
51 echo PMA_generate_common_hidden_inputs('', '');
52 echo ' <fieldset id="fieldset_add_user_login">';
53 echo ' <legend>' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . '</legend>';
54 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 />';
55 echo '<pre>server-id=' . time() . '</pre>';
56 echo ' <div class="item">';
57 echo ' <label for="text_username">' . __('User name') . ':</label>';
58 echo ' <input type="text" name="username" id="text_username" maxlength="'. $username_length . '" title="' . __('User name') . '" />';
59 echo ' </div>';
60 echo ' <div class="item">';
61 echo ' <label for="text_pma_pw">' . __('Password') .' :</label>';
62 echo ' <input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" />';
63 echo ' </div>';
64 echo ' <div class="item">';
65 echo ' <label for="text_hostname">' . __('Host') . ' :</label>';
66 echo ' <input type="text" id="text_hostname" name="hostname" maxlength="' . $hostname_length . '" value="" />';
67 echo ' </div>';
68 echo ' <div class="item">';
69 echo ' <label for="text_port">' . __('Port') . ':</label>';
70 echo ' <input type="text" id="text_port" name="port" maxlength="6" value="3306" />';
71 echo ' </div>';
72 echo ' </fieldset>';
73 echo ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
74 echo ' <input type="hidden" name="sr_take_action" value="true" />';
75 echo ' <input type="submit" name="' . $submitname . '" id="confslave_submit" value="' . __('Go') . '" />';
76 echo ' </fieldset>';
77 echo '</form>';
80 /**
81 * This function prints out table with replication status.
83 * @param String type - either master or slave
84 * @param boolean $hidden - if true, then default style is set to hidden, default value false
85 * @param boolen $title - if true, then title is displayed, default true
87 function PMA_replication_print_status_table($type, $hidden = false, $title = true) {
88 global ${"{$type}_variables"};
89 global ${"{$type}_variables_alerts"};
90 global ${"{$type}_variables_oks"};
91 global ${"server_{$type}_replication"};
92 global ${"strReplicationStatus_{$type}"};
94 // TODO check the Masters server id?
95 // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects
96 // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236)
97 // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log
99 //$server_id = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'server_id'", 0, 1);
101 echo '<div id="replication_' . $type . '_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
103 if ($title) {
104 if ($type == 'master') {
105 echo '<h4><a name="replication_' . $type . '"></a>' . __('Master status') . '</h4>';
106 } else {
107 echo '<h4><a name="replication_' . $type . '"></a>' . __('Slave status') . '</h4>';
109 } else {
110 echo '<br />';
113 echo ' <table id="server' . $type . 'replicationsummary" class="data"> ';
114 echo ' <thead>';
115 echo ' <tr>';
116 echo ' <th>' . __('Variable') . '</th>';
117 echo ' <th>' . __('Value') . '</th>';
118 echo ' </tr>';
119 echo ' </thead>';
120 echo ' <tbody>';
122 $odd_row = true;
123 foreach (${"{$type}_variables"} as $variable) {
124 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
125 echo ' <td class="name">';
126 echo $variable;
127 echo ' </td>';
128 echo ' <td class="value">';
131 // TODO change to regexp or something, to allow for negative match
132 if (isset(${"{$type}_variables_alerts"}[$variable])
133 && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
135 echo '<span class="attention">';
137 } elseif (isset(${"{$type}_variables_oks"}[$variable])
138 && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
140 echo '<span class="allfine">';
141 } else {
142 echo '<span>';
144 echo ${"server_{$type}_replication"}[0][$variable];
145 echo '</span>';
147 echo ' </td>';
148 echo ' </tr>';
150 $odd_row = ! $odd_row;
153 echo ' </tbody>';
154 echo ' </table>';
155 echo ' <br />';
156 echo '</div>';
161 * Prints table with slave users connected to this master
163 * @param boolean $hidden - if true, then default style is set to hidden, default value false
165 function PMA_replication_print_slaves_table($hidden = false) {
167 // Fetch data
168 $data = PMA_DBI_fetch_result('SHOW SLAVE HOSTS', null, null);
170 echo ' <br />';
171 echo ' <div id="replication_slaves_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
172 echo ' <table class="data">';
173 echo ' <thead>';
174 echo ' <tr>';
175 echo ' <th>' . __('Server ID') . '</th>';
176 echo ' <th>' . __('Host') . '</th>';
177 echo ' </tr>';
178 echo ' </thead>';
179 echo ' <tbody>';
181 $odd_row = true;
182 foreach ($data as $slave) {
183 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
184 echo ' <td class="value">' . $slave['Server_id'] . '</td>';
185 echo ' <td class="value">' . $slave['Host'] . '</td>';
186 echo ' </tr>';
188 $odd_row = ! $odd_row;
191 echo ' </tbody>';
192 echo ' </table>';
193 echo ' <br />';
194 PMA_Message::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display();
195 echo ' <br />';
196 echo ' </div>';
200 * get the correct username and hostname lengths for this MySQL server
202 * @return array username length, hostname length
205 function PMA_replication_get_username_hostname_length() {
206 $fields_info = PMA_DBI_get_columns('mysql', 'user');
207 $username_length = 16;
208 $hostname_length = 41;
209 foreach ($fields_info as $val) {
210 if ($val['Field'] == 'User') {
211 strtok($val['Type'], '()');
212 $v = strtok('()');
213 if (is_int($v)) {
214 $username_length = $v;
216 } elseif ($val['Field'] == 'Host') {
217 strtok($val['Type'], '()');
218 $v = strtok('()');
219 if (is_int($v)) {
220 $hostname_length = $v;
224 return array($username_length, $hostname_length);
228 * Print code to add a replication slave user to the master
230 function PMA_replication_gui_master_addslaveuser() {
232 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
234 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
235 $GLOBALS['pred_username'] = 'any';
237 echo '<div id="master_addslaveuser_gui">';
238 echo '<form autocomplete="off" method="post" action="server_privileges.php" onsubmit="return checkAddUser(this);">';
239 echo PMA_generate_common_hidden_inputs('', '');
240 echo '<fieldset id="fieldset_add_user_login">'
241 . '<legend>'.__('Add slave replication user').'</legend>'
242 . '<input type="hidden" name="grant_count" value="25" />'
243 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
244 . '<input id="checkbox_Repl_slave_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_slave_priv"/>'
245 . '<input id="checkbox_Repl_client_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_client_priv"/>'
246 . ''
247 . '<input type="hidden" name="sr_take_action" value="true" />'
248 . '<div class="item">'
249 . '<label for="select_pred_username">'
250 . ' ' . __('User name') . ':'
251 . '</label>'
252 . '<span class="options">'
253 . ' <select name="pred_username" id="select_pred_username" title="' . __('User name') . '"'
254 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">'
255 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . __('Any user') . '</option>'
256 . ' <option value="userdefined"' . ((! isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . __('Use text field') . ':</option>'
257 . ' </select>'
258 . '</span>'
259 . '<input type="text" name="username" maxlength="'
260 . $username_length . '" title="' . __('User name') . '"'
261 . (empty($GLOBALS['username'])
262 ? ''
263 : ' value="' . (isset($GLOBALS['new_username'])
264 ? $GLOBALS['new_username']
265 : $GLOBALS['username']) . '"')
266 . ' onchange="pred_username.value = \'userdefined\';" />'
267 . '</div>'
268 . '<div class="item">'
269 . '<label for="select_pred_hostname">'
270 . ' ' . __('Host') . ':'
271 . '</label>'
272 . '<span class="options">'
273 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"';
274 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
275 if (! empty($_current_user)) {
276 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
277 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
278 unset($thishost);
281 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
282 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
283 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
284 unset($_current_user);
286 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
287 if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
288 switch (strtolower($GLOBALS['hostname'])) {
289 case 'localhost':
290 case '127.0.0.1':
291 $GLOBALS['pred_hostname'] = 'localhost';
292 break;
293 case '%':
294 $GLOBALS['pred_hostname'] = 'any';
295 break;
296 default:
297 $GLOBALS['pred_hostname'] = 'userdefined';
298 break;
301 echo ' <option value="any"'
302 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
303 ? ' selected="selected"' : '') . '>' . __('Any host')
304 . '</option>'
305 . ' <option value="localhost"'
306 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
307 ? ' selected="selected"' : '') . '>' . __('Local')
308 . '</option>';
310 if (!empty($thishost)) {
311 echo ' <option value="thishost"'
312 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
313 ? ' selected="selected"' : '') . '>' . __('This Host')
314 . '</option>';
316 unset($thishost);
317 echo ' <option value="hosttable"'
318 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
319 ? ' selected="selected"' : '') . '>' . __('Use Host Table')
320 . '</option>'
321 . ' <option value="userdefined"'
322 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
323 ? ' selected="selected"' : '')
324 . '>' . __('Use text field') . ':</option>'
325 . ' </select>'
326 . '</span>'
327 . '<input type="text" name="hostname" maxlength="'
328 . $hostname_length . '" value="'
329 . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
330 . '" title="' . __('Host')
331 . '" onchange="pred_hostname.value = \'userdefined\';" />'
332 . PMA_showHint(__('When Host table is used, this field is ignored and values stored in Host table are used instead.'))
333 . '</div>'
334 . '<div class="item">'
335 . '<label for="select_pred_password">'
336 . ' ' . __('Password') . ':'
337 . '</label>'
338 . '<span class="options">'
339 . ' <select name="pred_password" id="select_pred_password" title="'
340 . __('Password') . '"'
341 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">'
342 . ' <option value="none"';
343 if (isset($GLOBALS['username']) && $mode != 'change') {
344 echo ' selected="selected"';
346 echo '>' . __('No Password') . '</option>'
347 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . __('Use text field') . ':</option>'
348 . ' </select>'
349 . '</span>'
350 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
351 . '</div>'
352 . '<div class="item">'
353 . '<label for="text_pma_pw2">'
354 . ' ' . __('Re-type') . ':'
355 . '</label>'
356 . '<span class="options">&nbsp;</span>'
357 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
358 . '</div>'
359 . '<div class="item">'
360 . '<label for="button_generate_password">'
361 . ' ' . __('Generate Password') . ':'
362 . '</label>'
363 . '<span class="options">'
364 . ' <input type="button" id="button_generate_password" value="' . __('Generate') . '" onclick="suggestPassword(this.form)" />'
365 . '</span>'
366 . '<input type="text" name="generated_pw" id="generated_pw" />'
367 . '</div>'
368 . '</fieldset>';
369 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
370 . ' <input type="submit" name="adduser_submit" id="adduser_submit" value="' . __('Go') . '" />'
371 . '</fieldset>';
372 echo '</form>';
373 echo '</div>';