diff --git a/js/functions.js b/js/functions.js index 52547421d..a0345b77a 100644 --- a/js/functions.js +++ b/js/functions.js @@ -568,18 +568,42 @@ function ApplySelectedChanges(token) */ function validateConnection(form_name, form_obj) { + var check = true; + var src_hostfilled = true; + var trg_hostfilled = true; + for (var i=1; i diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index cd3b0bf04..9e582e826 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -21,18 +21,18 @@ if (! defined('PMA_MYSQL_CLIENT_API')) { unset($client_api); } -function PMA_DBI_real_connect($server, $user, $password, $client_flags) +function PMA_DBI_real_connect($server, $user, $password, $client_flags, $persistant=false) { global $cfg; if (empty($client_flags)) { - if ($cfg['PersistentConnections']) { + if ($cfg['PersistentConnections'] || $persistant) { $link = @mysql_pconnect($server, $user, $password); } else { $link = @mysql_connect($server, $user, $password); } } else { - if ($cfg['PersistentConnections']) { + if ($cfg['PersistentConnections'] || $persistant) { $link = @mysql_pconnect($server, $user, $password, $client_flags); } else { $link = @mysql_connect($server, $user, $password, false, $client_flags); @@ -41,23 +41,40 @@ function PMA_DBI_real_connect($server, $user, $password, $client_flags) return $link; } - -function PMA_DBI_connect($user, $password, $is_controluser = false) +/** + * @param string $user mysql user name + * @param string $password mysql user password + * @param boolean $is_controluser + * @param array $server host/port/socket/persistant + * @return mixed false on error or a mysqli object on success + */ +function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null) { global $cfg, $php_errormsg; - - $server_port = (empty($cfg['Server']['port'])) + + if ($server) { + $server_port = (empty($server['port'])) ? '' - : ':' . $cfg['Server']['port']; + : ':' . (int)$server['port']; + $server_socket = (empty($server['socket'])) + ? '' + : ':' . $server['socket']; + $server_persistant = (empty($server['persistant'])) + ? false + : true; + } else { + $server_port = (empty($cfg['Server']['port'])) + ? '' + : ':' . (int)$cfg['Server']['port']; + $server_socket = (empty($cfg['Server']['socket'])) + ? '' + : ':' . $cfg['Server']['socket']; + } if (strtolower($cfg['Server']['connect_type']) == 'tcp') { $cfg['Server']['socket'] = ''; } - $server_socket = (empty($cfg['Server']['socket'])) - ? '' - : ':' . $cfg['Server']['socket']; - $client_flags = 0; // always use CLIENT_LOCAL_FILES as defined in mysql_com.h @@ -74,14 +91,20 @@ function PMA_DBI_connect($user, $password, $is_controluser = false) if (defined('MYSQL_CLIENT_SSL') && $cfg['Server']['ssl']) { $client_flags |= MYSQL_CLIENT_SSL; } + + if (!$server) { + $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); - $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); - - // Retry with empty password if we're allowed to - if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { - $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); + // Retry with empty password if we're allowed to + if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { + $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); + } + } else { + if (!isset($server['host'])) + $link = PMA_DBI_real_connect($server_socket, $user, $password, NULL, $server_persistant); + else + $link = PMA_DBI_real_connect($server['host'] . $server_port . $server_socket, $user, $password, NULL, $server_persistant); } - if (empty($link)) { if ($is_controluser) { trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); @@ -90,8 +113,8 @@ function PMA_DBI_connect($user, $password, $is_controluser = false) PMA_log_user($user, 'mysql-denied'); PMA_auth_fails(); } // end if - - PMA_DBI_postConnect($link, $is_controluser); + if (!$server) + PMA_DBI_postConnect($link, $is_controluser); return $link; } @@ -173,7 +196,6 @@ function PMA_DBI_try_query($query, $link = null, $options = 0) } $_SESSION['debug']['queries'][$hash]['trace'][] = $trace; } - if($r != FALSE and PMA_Tracker::isActive() == TRUE ) PMA_Tracker::handleQuery($query); diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 660b944a7..15801c23d 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -54,22 +54,37 @@ if (! defined('MYSQLI_TYPE_BIT')) { * @param string $user mysql user name * @param string $password mysql user password * @param boolean $is_controluser + * @param array $server host/port/socket * @return mixed false on error or a mysqli object on success */ -function PMA_DBI_connect($user, $password, $is_controluser = false) +function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null) { - $server_port = (empty($GLOBALS['cfg']['Server']['port'])) - ? false - : (int) $GLOBALS['cfg']['Server']['port']; + if ($server) { + $server_port = (empty($server['port'])) + ? '' + : (int)$server['port']; + $server_socket = (empty($server['socket'])) + ? '' + : $server['socket']; + $server['host'] = (empty($server['host'])) + ? 'localhost' + : $server['host']; + } else { + $server_port = (empty($GLOBALS['cfg']['Server']['port'])) + ? false + : (int) $GLOBALS['cfg']['Server']['port']; + $server_socket = (empty($GLOBALS['cfg']['Server']['socket'])) + ? null + : $GLOBALS['cfg']['Server']['socket']; + } + if (strtolower($GLOBALS['cfg']['Server']['connect_type']) == 'tcp') { $GLOBALS['cfg']['Server']['socket'] = ''; } // NULL enables connection to the default socket - $server_socket = (empty($GLOBALS['cfg']['Server']['socket'])) - ? null - : $GLOBALS['cfg']['Server']['socket']; + $link = mysqli_init(); @@ -86,21 +101,25 @@ function PMA_DBI_connect($user, $password, $is_controluser = false) if ($GLOBALS['cfg']['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) { $client_flags |= MYSQLI_CLIENT_SSL; } + + if (!$server) { + $return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags); - $return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags); - - // Retry with empty password if we're allowed to - if ($return_value == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) { - $return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags); + // Retry with empty password if we're allowed to + if ($return_value == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) { + $return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags); + } + } else { + $return_value = @mysqli_real_connect($link, $server['host'], $user, $password, false, $server_port, $server_socket); } if ($return_value == false) { - if ($is_controluser) { - trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); - return false; - } - PMA_log_user($user, 'mysql-denied'); - PMA_auth_fails(); + if ($is_controluser) { + trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); + return false; + } + PMA_log_user($user, 'mysql-denied'); + PMA_auth_fails(); } // end if PMA_DBI_postConnect($link, $is_controluser); diff --git a/server_synchronize.php b/server_synchronize.php index 92098b5ee..6582cbee9 100644 --- a/server_synchronize.php +++ b/server_synchronize.php @@ -47,31 +47,44 @@ if (isset($_REQUEST['token'])) { */ if ((isset($_REQUEST['submit_connect']))) { - $src_host = $_REQUEST['src_host']; - $src_username = $_REQUEST['src_username']; - $src_password = $_REQUEST['src_pass']; - $src_port = $_REQUEST['src_port']; - $src_db = $_REQUEST['src_db']; - $src_connection = @mysql_connect($src_host, $src_username, $src_password); - - $trg_host = $_REQUEST['trg_host']; - $trg_username = $_REQUEST['trg_username']; - $trg_password = $_REQUEST['trg_pass']; - $trg_port = $_REQUEST['trg_port']; - $trg_db = $_REQUEST['trg_db']; - $trg_connection = @mysql_connect($trg_host, $trg_username, $trg_password); + $cons = array ("src", "trg"); + foreach ($cons as $con) { + ${"{$con}_host"} = $_REQUEST[$con.'_host']; + ${"{$con}_username"} = $_REQUEST[$con.'_username']; + ${"{$con}_password"} = $_REQUEST[$con.'_pass']; + ${"{$con}_port"} = $_REQUEST[$con.'_port']; + ${"{$con}_socket"} = $_REQUEST[$con.'_socket']; + ${"{$con}_db"} = $_REQUEST[$con.'_db']; + ${"{$con}_url"} = ''; + + if (isset(${"{$con}_socket"}) && !empty(${"{$con}_socket"})) { + ${"{$con}_url"} = ':'.${"{$con}_socket"}; + ${"{$con}_server"}['socket'] = ${"{$con}_socket"}; + } else { + ${"{$con}_url"} = ${"{$con}_host"}; + ${"{$con}_server"}['host'] = ${"{$con}_host"}; + if (isset(${"{$con}_port"}) && !empty(${"{$con}_port"}) && ((int)${"{$con}_port"}*1)>0) { + ${"{$con}_url"} .= ':' . ${"{$con}_port"}; + ${"{$con}_server"}['port'] = ${"{$con}_port"}; + } + } + + ${"{$con}_connection"} = @mysql_connect(${"{$con}_url"}, ${"{$con}_username"}, ${"{$con}_password"}); + } + unset ($con, $cons); if (!($src_connection) || !($trg_connection)) { /** * Displays the connection error string if * connections are not established */ + echo '
' . "\n" ; if(!$src_connection) { - echo "Could not connect to the source
"; + echo $GLOBALS['strCouldNotConnectSource'].'
'; } if(!$trg_connection){ - echo "Could not connect to the target"; + echo $GLOBALS['strCouldNotConnectTarget']; } echo '
'; unset($_REQUEST['submit_connect']); @@ -81,22 +94,22 @@ if ((isset($_REQUEST['submit_connect']))) { * Creating the link object for both source and target databases and * selecting the source and target databases using these links */ - $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false); - $src_db_selected = PMA_DBI_select_db($src_db, $src_link); - - $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false); - $trg_db_selected = PMA_DBI_select_db($trg_db, $trg_link); + $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $src_server); + $src_connection = PMA_DBI_select_db($src_db, $src_link); + + $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $trg_server); + $trg_connection = PMA_DBI_select_db($trg_db, $trg_link); if (($src_db_selected != 1) || ($trg_db_selected != 1)) { /** * Displays error string if the database(s) did not exist */ - echo '
' . "\n" ; + echo '
' . "\n" ; if ($src_db_selected != 1) { - echo "'".$src_db."' database does not exists
"; + echo sprintf($GLOBALS['strDatabaseNotExisting'], $src_db); } if ($trg_db_selected != 1) { - echo "'".$trg_db."' database does not exists
"; + echo sprintf($GLOBALS['strDatabaseNotExisting'], $trg_db); } echo '
'; unset($_REQUEST['submit_connect']); @@ -203,6 +216,8 @@ if ((isset($_REQUEST['submit_connect']))) { $_SESSION['src_password'] = $src_password; $_SESSION['trg_password'] = $trg_password; $_SESSION['trg_password'] = $trg_password; + $_SESSION['src_server'] = $src_server; + $_SESSION['trg_server'] = $trg_server; $_SESSION['matching_tables_keys'] = $matching_tables_keys; $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields; $_SESSION['uncommon_tables_row_count'] = $row_count; @@ -493,6 +508,8 @@ if (isset($_REQUEST['Table_ids'])) { $trg_username = $_SESSION['trg_username']; $src_password = $_SESSION['src_password']; $trg_password = $_SESSION['trg_password']; + $src_server = $_SESSION['src_server']; + $trg_server = $_SESSION['trg_server']; $uncommon_tables = $_SESSION['uncommon_tables']; $matching_tables = $_SESSION['matching_tables']; $matching_tables_keys = $_SESSION['matching_tables_keys']; @@ -520,8 +537,8 @@ if (isset($_REQUEST['Table_ids'])) { /** * Creating link object for source and target databases */ - $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false); - $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false); + $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $src_server); + $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $trg_server); /** * Initializing arrays to save the table ids whose data and structure difference is to be applied @@ -1177,8 +1194,10 @@ if (isset($_REQUEST['synchronize_db'])) { echo '
' + >' // TODO: add check if all var. are filled in . PMA_generate_common_hidden_inputs('', ''); + echo '
'."\n"; + echo 'Synchronization'."\n"; /** * Displays the form for source server */ @@ -1187,56 +1206,64 @@ if (isset($_REQUEST['synchronize_db'])) { Source Database - Host: - + '. $GLOBALS['strHost']. ' + - Username: - + '. $GLOBALS['strPort']. ' + - Password: - + '. $GLOBALS['strSocket']. ' + - Port: - + '. $GLOBALS['strUserName']. ' + - Database: - + '. $GLOBALS['strPassword']. ' + + + + '. $GLOBALS['strDatabase']. ' + '; /** * Displays the form for target server */ - echo ' + echo '
- - + + - - + + - - + + - - + + - - + + + + + +
Target Database
Host: '. $GLOBALS['strHost']. '
Username: '. $GLOBALS['strPort']. '
Password: '. $GLOBALS['strSocket']. '
Port: '. $GLOBALS['strUserName']. '
Database: '. $GLOBALS['strPassword']. '
'. $GLOBALS['strDatabase']. '
- +
diff --git a/themes/original/img/s_sync.png b/themes/original/img/s_sync.png index 61e6b838e..49618bed2 100644 Binary files a/themes/original/img/s_sync.png and b/themes/original/img/s_sync.png differ