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'][] = 'mootools.js';
20 $GLOBALS['js_include'][] = 'mootools_common.js';
22 require './libraries/server_common.inc.php';
23 require './libraries/replication.inc.php';
24 require './libraries/replication_gui.lib.php';
25 require_once './libraries/server_synchronize.lib.php';
28 * Checks if the user is allowed to do what he tries to...
30 if (! $is_superuser) {
31 require './libraries/server_links.inc.php';
33 . PMA_getIcon('s_replication.png')
34 . $GLOBALS['strReplication'] . "\n"
36 PMA_Message
::error('strNoPrivileges')->display();
37 require_once './libraries/footer.inc.php';
41 * Handling control requests
44 if (isset($GLOBALS['sr_take_action'])) {
46 if (isset($GLOBALS['slave_changemaster'])) {
47 $_SESSION['replication']['m_username'] = $sr['username'] = PMA_sqlAddslashes($GLOBALS['username']);
48 $_SESSION['replication']['m_password'] = $sr['pma_pw'] = PMA_sqlAddslashes($GLOBALS['pma_pw']);
49 $_SESSION['replication']['m_hostname'] = $sr['hostname'] = PMA_sqlAddslashes($GLOBALS['hostname']);
50 $_SESSION['replication']['m_port'] = $sr['port'] = PMA_sqlAddslashes($GLOBALS['port']);
51 $_SESSION['replication']['m_correct'] = '';
52 $_SESSION['replication']['sr_action_status'] = 'error';
53 $_SESSION['replication']['sr_action_info'] = $strReplicationUnknownError;
54 // Attempt to connect to the new master server
55 $link_to_master = PMA_replication_connect_to_master($sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port']);
57 if (! $link_to_master) {
58 $_SESSION['replication']['sr_action_status'] = 'error';
59 $_SESSION['replication']['sr_action_info'] = sprintf($GLOBALS['strReplicationErrorMasterConnect'], $sr['hostname']);
61 // Read the current master position
62 $position = PMA_replication_slave_bin_log_master($link_to_master);
64 if (empty($position)) {
65 $_SESSION['replication']['sr_action_status'] = 'error';
66 $_SESSION['replication']['sr_action_info'] = $GLOBALS['strReplicationErrorGetPosition'];
68 $_SESSION['replication']['m_correct'] = true;
70 if (! PMA_replication_slave_change_master($sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port'], $position, true, false)) {
71 $_SESSION['replication']['sr_action_status'] = 'error';
72 $_SESSION['replication']['sr_action_info'] = $GLOBALS['strReplicationUnableToChange'];
74 $_SESSION['replication']['sr_action_status'] = 'success';
75 $_SESSION['replication']['sr_action_info'] = sprintf($GLOBALS['strReplicationChangedSuccesfully'], $sr['hostname']);
79 } elseif (isset($GLOBALS['sr_slave_server_control'])) {
80 if ($GLOBALS['sr_slave_action'] == 'reset') {
81 PMA_replication_slave_control("STOP");
82 PMA_DBI_try_query("RESET SLAVE;");
83 PMA_replication_slave_control("START");
85 PMA_replication_slave_control($GLOBALS['sr_slave_action'], $GLOBALS['sr_slave_control_parm']);
89 } elseif (isset($GLOBALS['sr_slave_skip_error'])) {
91 if (isset($GLOBALS['sr_skip_errors_count'])) {
92 $count = $GLOBALS['sr_skip_errors_count'] * 1;
94 PMA_replication_slave_control("STOP");
95 PMA_DBI_try_query("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";");
96 PMA_replication_slave_control("START");
98 } elseif (isset($GLOBALS['sl_sync'])) {
99 // TODO username, host and port could be read from 'show slave status',
100 // when asked for a password this might work in more situations the just after changing master (where the master password is stored in session)
101 $src_link = PMA_replication_connect_to_master($_SESSION['replication']['m_username'], $_SESSION['replication']['m_password'], $_SESSION['replication']['m_hostname'], $_SESSION['replication']['m_port']);
102 $trg_link = null; // using null to indicate the current PMA server
104 $data = PMA_DBI_fetch_result('SHOW MASTER STATUS', null, null, $src_link); // let's find out, which databases are replicated
107 $ignore_db = array();
110 if (! empty($data[0]['Binlog_Do_DB'])) {
111 $do_db = explode(',', $data[0]['Binlog_Do_DB']);
113 if (! empty($data[0]['Binlog_Ignore_DB'])) {
114 $ignore_db = explode(',', $data[0]['Binlog_Ignore_DB']);
117 $tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $src_link);
118 while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) {
119 if ($tmp_row[0] == 'information_schema') {
122 if (count($do_db) == 0) {
123 if (array_search($tmp_row[0], $ignore_db) !== false) {
126 $dblist[] = $tmp_row[0];
128 PMA_DBI_query('CREATE DATABASE IF NOT EXISTS '.$tmp_row[0], $trg_link);
130 if (array_search($tmp_row[0], $do_db) !== false) {
131 $dblist[] = $tmp_row[0];
132 PMA_DBI_query('CREATE DATABASE IF NOT EXISTS '.$tmp_row[0], $trg_link);
137 unset($do_db, $ignore_db, $data);
139 if (isset($GLOBALS['repl_data'])) {
140 $include_data = true;
142 $include_data = false;
144 foreach ($dblist as $db) {
145 PMA_replication_synchronize_db($db, $src_link, $trg_link, $include_data);
147 // TODO some form of user feedback error/success would be nice
148 // What happens if $dblist is empty?
153 Header("Location: ". PMA_generate_common_url($GLOBALS['url_params']));
160 require './libraries/server_links.inc.php';
162 echo '<div id="replication">';
164 echo ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_replication.png" width="16" height="16" alt="" />';
165 echo $GLOBALS['strReplication'];
168 // Display error messages
169 if (isset($_SESSION['replication']['sr_action_status']) && isset($_SESSION['replication']['sr_action_info'])) {
170 if ($_SESSION['replication']['sr_action_status'] == 'error') {
171 PMA_Message
::error($_SESSION['replication']['sr_action_info'])->display();
172 $_SESSION['replication']['sr_action_status'] = 'unknown';
173 } elseif ($_SESSION['replication']['sr_action_status'] == 'success') {
174 PMA_Message
::success($_SESSION['replication']['sr_action_info'])->display();
175 $_SESSION['replication']['sr_action_status'] = 'unknown';
179 if ($server_master_status) {
180 if (! isset($GLOBALS['repl_clear_scr'])) {
181 echo PMA_js_mootools_domready($jscode['master_replication']);
183 echo '<legend>' . $GLOBALS['strReplicationMaster'] . '</legend>';
184 echo $GLOBALS['strReplicationConfiguredMaster'];
186 echo ' <li><a href="#" id="master_status_href">' . $GLOBALS['strReplicationShowMasterStatus'] . '</a></li>';
187 PMA_replication_print_status_table('master', true, false);
189 echo ' <li><a href="#" id="master_slaves_href">' . $GLOBALS['strReplicationShowConnectedSlaves'] . '</a></li>';
190 PMA_replication_print_slaves_table(true);
192 $_url_params = $GLOBALS['url_params'];
193 $_url_params['mr_adduser'] = true;
194 $_url_params['repl_clear_scr'] = true;
196 echo ' <li><a href="' . PMA_generate_common_url($_url_params) . '" id="master_addslaveuser_href">' . $GLOBALS['strReplicationAddSlaveUser'] . '</a></li>';
199 // Display 'Add replication slave user' form
200 if (isset($GLOBALS['mr_adduser'])) {
201 PMA_replication_gui_master_addslaveuser();
202 } elseif (! isset($GLOBALS['repl_clear_scr'])) {
206 } elseif (! isset($GLOBALS['mr_configure']) && ! isset($GLOBALS['repl_clear_scr'])) {
207 $_url_params = $GLOBALS['url_params'];
208 $_url_params['mr_configure'] = true;
211 echo '<legend>' . $GLOBALS['strReplicationMaster'] . '</legend>';
212 echo sprintf($GLOBALS['strReplicationServernConfiguredMaster'], PMA_generate_common_url($_url_params));
216 if (isset($GLOBALS['mr_configure'])) {
217 // Render the 'Master configuration' section
218 echo PMA_js_mootools_domready($jscode['configure_master']);
220 echo '<legend>' . $GLOBALS['strReplicationMasterConfiguration'] . '</legend>';
221 echo $GLOBALS['strReplicationMasterChooseMode'] . '<br /><br />';
223 echo '<select name="db_type" id="db_type">';
224 echo '<option value="all">' . $GLOBALS['strReplicationMasterChooseAll'] . '</option>';
225 echo '<option value="ign">' . $GLOBALS['strReplicationMasterChooseIgn'] . '</option>';
228 echo $GLOBALS['strReplicationSelectDatabases'] . '<br />';
229 echo PMA_replication_db_multibox();
231 echo $GLOBALS['strReplicationAddLines'] . '<br />';
232 echo '<pre id="rep">server-id='. $serverid . '<br />log-bin=mysql-bin<br />log-error=mysql-bin.err<br /></pre>';
233 echo $GLOBALS['strReplicationRestartServer'];
235 echo '<fieldset class="tblFooters">';
236 echo ' <form method="post" action="server_replication.php" >';
237 echo PMA_generate_common_hidden_inputs('', '');
238 echo ' <input type="submit" value="' . $GLOBALS['strGo'] . '" id="goButton" />';
242 require_once './libraries/footer.inc.php';
248 if (! isset($GLOBALS['repl_clear_scr'])) {
249 // Render the 'Slave configuration' section
251 echo '<legend>' . $GLOBALS['strReplicationSlave'] . '</legend>';
252 if ($server_slave_status) {
253 echo PMA_js_mootools_domready($jscode['slave_control']);
254 echo '<div id="slave_configuration_gui">';
256 $_url_params = $GLOBALS['url_params'];
257 $_url_params['sr_take_action'] = true;
258 $_url_params['sr_slave_server_control'] = true;
260 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
261 $_url_params['sr_slave_action'] = 'start';
263 $_url_params['sr_slave_action'] = 'stop';
266 $_url_params['sr_slave_control_parm'] = 'IO_THREAD';
267 $slave_control_io_link = PMA_generate_common_url($_url_params);
269 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
270 $_url_params['sr_slave_action'] = 'start';
272 $_url_params['sr_slave_action'] = 'stop';
275 $_url_params['sr_slave_control_parm'] = 'SQL_THREAD';
276 $slave_control_sql_link = PMA_generate_common_url($_url_params);
278 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No'
279 ||
$server_slave_replication[0]['Slave_SQL_Running'] == 'No'
281 $_url_params['sr_slave_action'] = 'start';
283 $_url_params['sr_slave_action'] = 'stop';
286 $_url_params['sr_slave_control_parm'] = null;
287 $slave_control_full_link = PMA_generate_common_url($_url_params);
289 $_url_params['sr_slave_action'] = 'reset';
290 $slave_control_reset_link = PMA_generate_common_url($_url_params);
292 $_url_params = $GLOBALS['url_params'];
293 $_url_params['sr_slave_skip_error'] = true;
294 $slave_skip_error_link = PMA_generate_common_url($_url_params);
296 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No')
297 PMA_Message
::warning('Slave SQL Thread not running!')->display();
298 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No')
299 PMA_Message
::warning('Slave IO Thread not running!')->display();
301 $_url_params = $GLOBALS['url_params'];
302 $_url_params['sl_configure'] = true;
303 $_url_params['repl_clear_scr'] = true;
305 $reconfiguremaster_link = PMA_generate_common_url($_url_params);
307 echo $GLOBALS['strReplicationSlaveConfigured'];
310 echo ' <li><a href="#" id="slave_status_href">' . $GLOBALS['strReplicationSlaveSeeStatus'] . '</a></li>';
311 echo PMA_replication_print_status_table('slave', true, false);
312 if (isset($_SESSION['replication']['m_correct']) && $_SESSION['replication']['m_correct'] == true) {
313 echo PMA_js_mootools_domready($jscode['slave_control_sync']);
314 echo ' <li><a href="#" id="slave_synchronization_href">' . $GLOBALS['strReplicationSynchronize'] . '</a></li>';
315 echo ' <div id="slave_synchronization_gui" style="display: none">';
316 echo ' <form method="post" action="server_replication.php">';
317 echo PMA_generate_common_hidden_inputs('', '');
318 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
319 echo ' <input type="checkbox" name="repl_data" value="1" checked="checked" /> ' . $GLOBALS['strData'] .' <br />';
320 echo ' <input type="hidden" name="sr_take_action" value="1" />';
321 echo ' <input type="submit" name="sl_sync" value="' . $GLOBALS['strGo'] . '" />';
325 echo ' <li><a href="#" id="slave_control_href">' . $GLOBALS['strReplicationControlSlave'] . '</a>';
326 echo ' <div id="slave_control_gui" style="display: none">';
328 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>';
329 echo ' <li><a href="'. $slave_control_reset_link . '">' . $GLOBALS['strReplicationSlaveReset'] . '</a></li>';
330 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>';
331 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>';
335 echo ' <li><a href="#" id="slave_errormanagement_href">' . $GLOBALS['strReplicationSlaveErrorManagement'] . '</a>';
336 echo ' <div id="slave_errormanagement_gui" style="display: none">';
337 PMA_Message
::warning($GLOBALS['strReplicationSkippingErrorWarn'])->display();
339 echo ' <li><a href="' . $slave_skip_error_link . '">' . $GLOBALS['strReplicationSlaveSkipCurrentError'] . '</a></li>';
340 echo ' <li>' . $GLOBALS['strReplicationSlaveSkipNext'];
341 echo ' <form method="post" action="server_replication.php">';
342 echo PMA_generate_common_hidden_inputs('', '');
343 echo ' <input type="text" name="sr_skip_errors_count" value="1" style="width: 30px" />' . $GLOBALS['strReplicationSlaveSkipNextErrors'];
344 echo ' <input type="submit" name="sr_slave_skip_error" value="' . $GLOBALS['strGo'] . '" />';
345 echo ' <input type="hidden" name="sr_take_action" value="1" />';
346 echo ' </form></li>';
350 echo ' <li><a href="' . $reconfiguremaster_link . '">' . $GLOBALS['strReplicationSlaveChangeMaster'] . '</a></li>';
353 } elseif (! isset($GLOBALS['sl_configure'])) {
354 $_url_params = $GLOBALS['url_params'];
355 $_url_params['sl_configure'] = true;
356 $_url_params['repl_clear_scr'] = true;
358 echo sprintf($GLOBALS['strReplicationSlaveNotConfigured'], PMA_generate_common_url($_url_params));
363 if (isset($GLOBALS['sl_configure'])) {
364 PMA_replication_gui_changemaster("slave_changemaster");
366 require_once './libraries/footer.inc.php';