2 /* vim: set expandtab sw=4 ts=4 sts=4: */
12 require_once './libraries/common.inc.php';
15 * Does the common work
17 $GLOBALS['js_include'][] = 'server_privileges.js';
18 $GLOBALS['js_include'][] = 'functions.js';
19 $GLOBALS['js_include'][] = 'replication.js';
21 require './libraries/server_common.inc.php';
22 require './libraries/replication.inc.php';
23 require './libraries/replication_gui.lib.php';
24 require_once './libraries/server_synchronize.lib.php';
27 * Checks if the user is allowed to do what he tries to...
29 if (! $is_superuser) {
30 require './libraries/server_links.inc.php';
32 . PMA_getIcon('s_replication.png')
33 . $GLOBALS['strReplication'] . "\n"
35 PMA_Message
::error('strNoPrivileges')->display();
36 require_once './libraries/footer.inc.php';
40 * Handling control requests
42 if (isset($GLOBALS['sr_take_action'])) {
44 if (isset($GLOBALS['slave_changemaster'])) {
45 $_SESSION['replication']['m_username'] = $sr['username'] = PMA_sqlAddslashes($GLOBALS['username']);
46 $_SESSION['replication']['m_password'] = $sr['pma_pw'] = PMA_sqlAddslashes($GLOBALS['pma_pw']);
47 $_SESSION['replication']['m_hostname'] = $sr['hostname'] = PMA_sqlAddslashes($GLOBALS['hostname']);
48 $_SESSION['replication']['m_port'] = $sr['port'] = PMA_sqlAddslashes($GLOBALS['port']);
49 $_SESSION['replication']['m_correct'] = '';
50 $_SESSION['replication']['sr_action_status'] = 'error';
51 $_SESSION['replication']['sr_action_info'] = __('Unknown error');
53 // Attempt to connect to the new master server
54 $link_to_master = PMA_replication_connect_to_master($sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port']);
56 if (! $link_to_master) {
57 $_SESSION['replication']['sr_action_status'] = 'error';
58 $_SESSION['replication']['sr_action_info'] = sprintf($GLOBALS['strReplicationErrorMasterConnect'], $sr['hostname']);
60 // Read the current master position
61 $position = PMA_replication_slave_bin_log_master($link_to_master);
63 if (empty($position)) {
64 $_SESSION['replication']['sr_action_status'] = 'error';
65 $_SESSION['replication']['sr_action_info'] = $GLOBALS['strReplicationErrorGetPosition'];
67 $_SESSION['replication']['m_correct'] = true;
69 if (! PMA_replication_slave_change_master($sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port'], $position, true, false)) {
70 $_SESSION['replication']['sr_action_status'] = 'error';
71 $_SESSION['replication']['sr_action_info'] = $GLOBALS['strReplicationUnableToChange'];
73 $_SESSION['replication']['sr_action_status'] = 'success';
74 $_SESSION['replication']['sr_action_info'] = sprintf($GLOBALS['strReplicationChangedSuccesfully'], $sr['hostname']);
78 } elseif (isset($GLOBALS['sr_slave_server_control'])) {
79 if ($GLOBALS['sr_slave_action'] == 'reset') {
80 PMA_replication_slave_control("STOP");
81 PMA_DBI_try_query("RESET SLAVE;");
82 PMA_replication_slave_control("START");
84 PMA_replication_slave_control($GLOBALS['sr_slave_action'], $GLOBALS['sr_slave_control_parm']);
88 } elseif (isset($GLOBALS['sr_slave_skip_error'])) {
90 if (isset($GLOBALS['sr_skip_errors_count'])) {
91 $count = $GLOBALS['sr_skip_errors_count'] * 1;
93 PMA_replication_slave_control("STOP");
94 PMA_DBI_try_query("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";");
95 PMA_replication_slave_control("START");
97 } elseif (isset($GLOBALS['sl_sync'])) {
98 // TODO username, host and port could be read from 'show slave status',
99 // when asked for a password this might work in more situations then just after changing master (where the master password is stored in session)
100 $src_link = PMA_replication_connect_to_master($_SESSION['replication']['m_username'], $_SESSION['replication']['m_password'], $_SESSION['replication']['m_hostname'], $_SESSION['replication']['m_port']);
101 $trg_link = null; // using null to indicate the current PMA server
103 $data = PMA_DBI_fetch_result('SHOW MASTER STATUS', null, null, $src_link); // let's find out, which databases are replicated
106 $ignore_db = array();
109 if (! empty($data[0]['Binlog_Do_DB'])) {
110 $do_db = explode(',', $data[0]['Binlog_Do_DB']);
112 if (! empty($data[0]['Binlog_Ignore_DB'])) {
113 $ignore_db = explode(',', $data[0]['Binlog_Ignore_DB']);
116 $tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $src_link);
117 while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) {
118 if ($tmp_row[0] == 'information_schema') {
121 if (count($do_db) == 0) {
122 if (array_search($tmp_row[0], $ignore_db) !== false) {
125 $dblist[] = $tmp_row[0];
127 PMA_DBI_query('CREATE DATABASE IF NOT EXISTS '.$tmp_row[0], $trg_link);
129 if (array_search($tmp_row[0], $do_db) !== false) {
130 $dblist[] = $tmp_row[0];
131 PMA_DBI_query('CREATE DATABASE IF NOT EXISTS '.$tmp_row[0], $trg_link);
136 unset($do_db, $ignore_db, $data);
138 if (isset($GLOBALS['repl_data'])) {
139 $include_data = true;
141 $include_data = false;
143 foreach ($dblist as $db) {
144 PMA_replication_synchronize_db($db, $src_link, $trg_link, $include_data);
146 // TODO some form of user feedback error/success would be nice
147 // What happens if $dblist is empty?
152 Header("Location: ". PMA_generate_common_url($GLOBALS['url_params']));
159 require './libraries/server_links.inc.php';
161 echo '<div id="replication">';
163 echo ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_replication.png" width="16" height="16" alt="" />';
164 echo $GLOBALS['strReplication'];
167 // Display error messages
168 if (isset($_SESSION['replication']['sr_action_status']) && isset($_SESSION['replication']['sr_action_info'])) {
169 if ($_SESSION['replication']['sr_action_status'] == 'error') {
170 PMA_Message
::error($_SESSION['replication']['sr_action_info'])->display();
171 $_SESSION['replication']['sr_action_status'] = 'unknown';
172 } elseif ($_SESSION['replication']['sr_action_status'] == 'success') {
173 PMA_Message
::success($_SESSION['replication']['sr_action_info'])->display();
174 $_SESSION['replication']['sr_action_status'] = 'unknown';
178 if ($server_master_status) {
179 if (! isset($GLOBALS['repl_clear_scr'])) {
181 echo '<legend>' . $GLOBALS['strReplicationMaster'] . '</legend>';
182 echo $GLOBALS['strReplicationConfiguredMaster'];
184 echo ' <li><a href="#" id="master_status_href">' . $GLOBALS['strReplicationShowMasterStatus'] . '</a></li>';
185 PMA_replication_print_status_table('master', true, false);
187 echo ' <li><a href="#" id="master_slaves_href">' . $GLOBALS['strReplicationShowConnectedSlaves'] . '</a></li>';
188 PMA_replication_print_slaves_table(true);
190 $_url_params = $GLOBALS['url_params'];
191 $_url_params['mr_adduser'] = true;
192 $_url_params['repl_clear_scr'] = true;
194 echo ' <li><a href="' . PMA_generate_common_url($_url_params) . '" id="master_addslaveuser_href">' . $GLOBALS['strReplicationAddSlaveUser'] . '</a></li>';
197 // Display 'Add replication slave user' form
198 if (isset($GLOBALS['mr_adduser'])) {
199 PMA_replication_gui_master_addslaveuser();
200 } elseif (! isset($GLOBALS['repl_clear_scr'])) {
204 } elseif (! isset($GLOBALS['mr_configure']) && ! isset($GLOBALS['repl_clear_scr'])) {
205 $_url_params = $GLOBALS['url_params'];
206 $_url_params['mr_configure'] = true;
209 echo '<legend>' . $GLOBALS['strReplicationMaster'] . '</legend>';
210 echo sprintf($GLOBALS['strReplicationServernConfiguredMaster'], PMA_generate_common_url($_url_params));
214 if (isset($GLOBALS['mr_configure'])) {
215 // Render the 'Master configuration' section
217 echo '<legend>' . $GLOBALS['strReplicationMasterConfiguration'] . '</legend>';
218 echo $GLOBALS['strReplicationMasterChooseMode'] . '<br /><br />';
220 echo '<select name="db_type" id="db_type">';
221 echo '<option value="all">' . $GLOBALS['strReplicationMasterChooseAll'] . '</option>';
222 echo '<option value="ign">' . $GLOBALS['strReplicationMasterChooseIgn'] . '</option>';
225 echo $GLOBALS['strReplicationSelectDatabases'] . '<br />';
226 echo PMA_replication_db_multibox();
228 echo $GLOBALS['strReplicationAddLines'] . '<br />';
229 echo '<pre id="rep"></pre>';
230 echo $GLOBALS['strReplicationRestartServer'];
232 echo '<fieldset class="tblFooters">';
233 echo ' <form method="post" action="server_replication.php" >';
234 echo PMA_generate_common_hidden_inputs('', '');
235 echo ' <input type="submit" value="' . $GLOBALS['strGo'] . '" id="goButton" />';
239 require_once './libraries/footer.inc.php';
245 if (! isset($GLOBALS['repl_clear_scr'])) {
246 // Render the 'Slave configuration' section
248 echo '<legend>' . $GLOBALS['strReplicationSlave'] . '</legend>';
249 if ($server_slave_status) {
250 echo '<div id="slave_configuration_gui">';
252 $_url_params = $GLOBALS['url_params'];
253 $_url_params['sr_take_action'] = true;
254 $_url_params['sr_slave_server_control'] = true;
256 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
257 $_url_params['sr_slave_action'] = 'start';
259 $_url_params['sr_slave_action'] = 'stop';
262 $_url_params['sr_slave_control_parm'] = 'IO_THREAD';
263 $slave_control_io_link = PMA_generate_common_url($_url_params);
265 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
266 $_url_params['sr_slave_action'] = 'start';
268 $_url_params['sr_slave_action'] = 'stop';
271 $_url_params['sr_slave_control_parm'] = 'SQL_THREAD';
272 $slave_control_sql_link = PMA_generate_common_url($_url_params);
274 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No'
275 ||
$server_slave_replication[0]['Slave_SQL_Running'] == 'No'
277 $_url_params['sr_slave_action'] = 'start';
279 $_url_params['sr_slave_action'] = 'stop';
282 $_url_params['sr_slave_control_parm'] = null;
283 $slave_control_full_link = PMA_generate_common_url($_url_params);
285 $_url_params['sr_slave_action'] = 'reset';
286 $slave_control_reset_link = PMA_generate_common_url($_url_params);
288 $_url_params = $GLOBALS['url_params'];
289 $_url_params['sr_slave_skip_error'] = true;
290 $slave_skip_error_link = PMA_generate_common_url($_url_params);
292 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
293 PMA_Message
::warning('strReplicationSlaveSQLThreadNotRunning')->display();
295 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
296 PMA_Message
::warning('strReplicationSlaveIOThreadNotRunning')->display();
299 $_url_params = $GLOBALS['url_params'];
300 $_url_params['sl_configure'] = true;
301 $_url_params['repl_clear_scr'] = true;
303 $reconfiguremaster_link = PMA_generate_common_url($_url_params);
305 echo $GLOBALS['strReplicationSlaveConfigured'];
308 echo ' <li><a href="#" id="slave_status_href">' . $GLOBALS['strReplicationSlaveSeeStatus'] . '</a></li>';
309 echo PMA_replication_print_status_table('slave', true, false);
310 if (isset($_SESSION['replication']['m_correct']) && $_SESSION['replication']['m_correct'] == true) {
311 echo ' <li><a href="#" id="slave_synchronization_href">' . $GLOBALS['strReplicationSynchronize'] . '</a></li>';
312 echo ' <div id="slave_synchronization_gui" style="display: none">';
313 echo ' <form method="post" action="server_replication.php">';
314 echo PMA_generate_common_hidden_inputs('', '');
315 echo ' <input type="checkbox" name="repl_struc" value="1" checked="checked" disabled="disabled" /> ' . $GLOBALS['strStructure'] . '<br />'; // this is just for vizualization, it has no other purpose
316 echo ' <input type="checkbox" name="repl_data" value="1" checked="checked" /> ' . $GLOBALS['strData'] .' <br />';
317 echo ' <input type="hidden" name="sr_take_action" value="1" />';
318 echo ' <input type="submit" name="sl_sync" value="' . $GLOBALS['strGo'] . '" />';
322 echo ' <li><a href="#" id="slave_control_href">' . $GLOBALS['strReplicationControlSlave'] . '</a>';
323 echo ' <div id="slave_control_gui" style="display: none">';
325 echo ' <li><a href="'. $slave_control_full_link . '">' . (($server_slave_replication[0]['Slave_IO_Running'] == 'No' ||
$server_slave_replication[0]['Slave_SQL_Running'] == 'No') ?
$GLOBALS['strFullStart'] : $GLOBALS['strFullStop']) . ' </a></li>';
326 echo ' <li><a href="'. $slave_control_reset_link . '">' . $GLOBALS['strReplicationSlaveReset'] . '</a></li>';
327 echo ' <li><a href="' . $slave_control_sql_link . '">' . sprintf($GLOBALS['strReplicationSlaveSQLThread'], ($server_slave_replication[0]['Slave_SQL_Running'] == 'No' ?
$GLOBALS['strStart'] : $GLOBALS['strStop'])) . '</a></li>';
328 echo ' <li><a href="' . $slave_control_io_link . '">' . sprintf($GLOBALS['strReplicationSlaveIOThread'], ($server_slave_replication[0]['Slave_IO_Running'] == 'No' ?
$GLOBALS['strStart'] : $GLOBALS['strStop'])) . '</a></li>';
332 echo ' <li><a href="#" id="slave_errormanagement_href">' . $GLOBALS['strReplicationSlaveErrorManagement'] . '</a>';
333 echo ' <div id="slave_errormanagement_gui" style="display: none">';
334 PMA_Message
::warning($GLOBALS['strReplicationSkippingErrorWarn'])->display();
336 echo ' <li><a href="' . $slave_skip_error_link . '">' . $GLOBALS['strReplicationSlaveSkipCurrentError'] . '</a></li>';
337 echo ' <li>' . $GLOBALS['strReplicationSlaveSkipNext'];
338 echo ' <form method="post" action="server_replication.php">';
339 echo PMA_generate_common_hidden_inputs('', '');
340 echo ' <input type="text" name="sr_skip_errors_count" value="1" style="width: 30px" />' . $GLOBALS['strReplicationSlaveSkipNextErrors'];
341 echo ' <input type="submit" name="sr_slave_skip_error" value="' . $GLOBALS['strGo'] . '" />';
342 echo ' <input type="hidden" name="sr_take_action" value="1" />';
343 echo ' </form></li>';
347 echo ' <li><a href="' . $reconfiguremaster_link . '">' . $GLOBALS['strReplicationSlaveChangeMaster'] . '</a></li>';
350 } elseif (! isset($GLOBALS['sl_configure'])) {
351 $_url_params = $GLOBALS['url_params'];
352 $_url_params['sl_configure'] = true;
353 $_url_params['repl_clear_scr'] = true;
355 echo sprintf($GLOBALS['strReplicationSlaveNotConfigured'], PMA_generate_common_url($_url_params));
360 if (isset($GLOBALS['sl_configure'])) {
361 PMA_replication_gui_changemaster("slave_changemaster");
363 require_once './libraries/footer.inc.php';