diff --git a/install/dist/lib/gentoo.lib.php b/install/dist/lib/gentoo.lib.php index 69691a6afd7c34f1ed1baa89ddd0f867e0653499..eac07e0a8bcf35cddb8f2f6e1f0b92317bd92698 100644 --- a/install/dist/lib/gentoo.lib.php +++ b/install/dist/lib/gentoo.lib.php @@ -754,13 +754,7 @@ class installer extends installer_base } //* load the powerdns databse dump - if($conf['mysql']['admin_password'] == '') { - caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' --force '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", - __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); - } else { - caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' --force '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", - __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); - } + $this->load_sql_via_cli($conf['powerdns']['database'], ISPC_INSTALL_ROOT.'/install/sql/powerdns.sql', __FILE__, __LINE__, 'read in install/sql/powerdns.sql', 'could not read in install/sql/powerdns.sql'); //* Create the powerdns config file $content = $this->get_template_file('pdns.local', true, true); //* get contents & insert db cred diff --git a/install/lib/install.lib.php b/install/lib/install.lib.php index 885432f7efc94429f2e7a685836b32e79b58c3e1..aa470717aa35d56f1cb106b7e1815b24205b83de 100644 --- a/install/lib/install.lib.php +++ b/install/lib/install.lib.php @@ -449,9 +449,11 @@ function caselog($command, $file = '', $line = '', $success = '', $failure = '') if($ret_val != 0){ if($failure == '') $failure = 'could not '.$command; ilog($pre.'WARNING: '.$failure); + return false; } else { if($success == '') $success = $command; ilog($pre.$success); + return true; } } diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 9ae569b6fba0a3bbf28c6b0fd977ad7155a0c784..2edb22055c34bc31092e23616f9dad14973f989d 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -368,13 +368,9 @@ class installer_base extends stdClass { if(count($db_tables) > 0) { $this->error('Stopped: Database already contains some tables.'); } else { - if($conf['mysql']['admin_password'] == '') { - caselog("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -P ".escapeshellarg($conf['mysql']['port'])." ".escapeshellarg($conf['mysql']['database'])." < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", - __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); - } else { - caselog("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." -P ".escapeshellarg($conf['mysql']['port'])." ".escapeshellarg($conf['mysql']['database'])." < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", - __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); - } + + $this->load_sql_via_cli($conf['mysql']['database'], ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql", __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); + $db_tables = $this->db->getTables(); if(count($db_tables) == 0) { $this->error('Unable to load SQL-Dump into database table.'); @@ -387,6 +383,26 @@ class installer_base extends stdClass { } } + public function load_sql_via_cli($database, $filename, $file = '', $line = '', $success = '', $failure = '', $logfile = '/dev/null') { + global $conf; + + $command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset']) + ." --host=".escapeshellarg($conf['mysql']['host']) + ." --user=".escapeshellarg($conf['mysql']['admin_user']); + + // Localhost defaults to use a socket + if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { + $command .= " --port=".escapeshellarg($conf['mysql']['port']); + } + if (!empty($conf['mysql']['admin_password'])) { + $command .= " --password=".escapeshellarg($conf['mysql']['admin_password']); + } + $command .= " --database=".escapeshellarg($database); + + caselog($command . " < '$filename' &>> $logfile", $file, $line, $success, $failure); + } + + //** Create the server record in the database public function add_database_server_record() { @@ -2222,13 +2238,7 @@ class installer_base extends stdClass { } //* load the powerdns databse dump - if($conf['mysql']['admin_password'] == '') { - caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' --force '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", - __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); - } else { - caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' --force '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null", - __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql'); - } + $this->load_sql_via_cli($conf['powerdns']['database'], ISPC_INSTALL_ROOT."/install/sql/powerdns.sql", __FILE__, __LINE__, 'read in powerdns.sql', 'could not read in powerdns.sql'); //* Create the powerdns config file $configfile = 'pdns.local'; diff --git a/install/lib/update.lib.php b/install/lib/update.lib.php index d88d64d6cd414f85387f10882b979bf44fbc7e6e..d82db9a3a7e802e54dc6bda31e6800d55dbc0b13 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -39,15 +39,11 @@ class installer_patch_update { //* DB dump function function prepareDBDump() { - global $conf; + global $inst, $conf; //** load the pre update sql script do perform modifications on the database before the database is dumped if(is_file(ISPC_INSTALL_ROOT."/install/sql/pre_update.sql")) { - if($conf['mysql']['admin_password'] == '') { - caselog("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['mysql']['database'])." < '".ISPC_INSTALL_ROOT."/install/sql/pre_update.sql' &> /dev/null", __FILE__, __LINE__, 'read in pre_update.sql', 'could not read in pre_update.sql'); - } else { - caselog("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['mysql']['database'])." < '".ISPC_INSTALL_ROOT."/install/sql/pre_update.sql' &> /dev/null", __FILE__, __LINE__, 'read in pre_update.sql', 'could not read in pre_update.sql'); - } + $inst->load_sql_via_cli($conf['mysql']['database'], ISPC_INSTALL_ROOT.'/install/sql/pre_update.sql', __FILE__, __LINE__, 'read in pre_update.sql', 'could not read in pre_update.sql'); } //** export the current database data @@ -103,7 +99,22 @@ function checkDbHealth() { $notok = array(); echo "Checking ISPConfig database .. "; - exec("mysqlcheck -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." -P ".escapeshellarg($conf['mysql']['port'])." --auto-repair ".escapeshellarg($conf["mysql"]["database"]), $result); + + $command = "mysqlcheck --auto-repair" + ." --host=".escapeshellarg($conf['mysql']['host']) + ." --user=".escapeshellarg($conf['mysql']['admin_user']); + + // Localhost defaults to use a socket + if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { + $command .= " --port=".escapeshellarg($conf['mysql']['port']); + } + if (!empty($conf['mysql']['admin_password'])) { + $command .= " --password=".escapeshellarg($conf['mysql']['admin_password']); + } + $command .= " ".escapeshellarg($conf["mysql"]["database"]); + + exec($command, $result); + for( $i=0; $ilng('Loading SQL patch file').': '.$sql_patch_filename); + $inst->load_sql_via_cli($conf['mysql']['database'], $sql_patch_filename, __FILE__, __LINE__, "read in $sql_patch_filename", "could not read in $sql_patch_filename", $logfile); //* Exec onAfterSQL function if(isset($php_patch) && is_object($php_patch) && method_exists($php_patch, 'onAfterSQL')) { @@ -266,11 +270,7 @@ function updateDbAndIni() { } //** load old data back into database - if( !empty($conf["mysql"]["admin_password"]) ) { - system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['mysql']['database'])." < existing_db.sql"); - } else { - system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['mysql']['database'])." < existing_db.sql"); - } + $inst->load_sql_via_cli($conf['mysql']['database'], 'existing_db.sql', __FILE__, __LINE__, 'read in existing_db.sql', 'could not read in existing_db.sql'); //** Get the database version number based on the patchfile $found = true; @@ -301,11 +301,7 @@ function updateDbAndIni() { $inst->configure_powerdns(); //** load old data back into the PowerDNS database - if( !empty($conf["mysql"]["admin_password"]) ) { - system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." ".escapeshellarg($conf['powerdns']['database'])." < existing_powerdns_db.sql"); - } else { - system("mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." ".escapeshellarg($conf['powerdns']['database'])." < existing_powerdns_db.sql"); - } + $inst->load_sql_via_cli($conf['powerdns']['database'], 'existing_powerdns_db.sql', __FILE__, __LINE__, 'read in existing_powerdns_db.sql', 'could not read in existing_powerdns_db.sql'); } } diff --git a/install/update.php b/install/update.php index 55b711da739eeb96e9b25641816a79a5f2205848..899b9a5a3cef74c6f4cb46c370fc0e8c6eac3ac7 100644 --- a/install/update.php +++ b/install/update.php @@ -320,15 +320,23 @@ checkDbHealth(); /* * Check command line mysql login */ -if( !empty($conf["mysql"]["admin_password"]) ) { - $cmd = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -p".escapeshellarg($conf['mysql']['admin_password'])." -P ".escapeshellarg($conf['mysql']['port'])." -D ".escapeshellarg($conf['mysql']['database'])." -e ". escapeshellarg('SHOW DATABASES'); -} else { - $cmd = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset'])." --force -h ".escapeshellarg($conf['mysql']['host'])." -u ".escapeshellarg($conf['mysql']['admin_user'])." -P ".escapeshellarg($conf['mysql']['port'])." -D ".escapeshellarg($conf['mysql']['database'])." -e ". escapeshellarg('SHOW DATABASES'); +$command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset']) + ." --host=".escapeshellarg($conf['mysql']['host']) + ." --user=".escapeshellarg($conf['mysql']['admin_user']); + +// Localhost defaults to use a socket +if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { + $command .= " --port=".escapeshellarg($conf['mysql']['port']); +} +if (!empty($conf['mysql']['admin_password'])) { + $command .= " --password=".escapeshellarg($conf['mysql']['admin_password']); } -$retval = 0; -$retout = array(); -exec($cmd, $retout, $retval); -if($retval != 0) { + +$command .= " --database=".escapeshellarg($conf['mysql']['database']); +$command .= " --execute='SHOW DATABASES'"; + +$retval = caselog($command . " &> /dev/null", __FILE__, __LINE__, 'Tested sql cli connection', 'sql cli connection failed'); +if($retval == false) { die("Unable to call mysql command line with credentials from mysql_clientdb.conf\n"); }