From 309dc3273532077874d83d7474cdcfdc9351f2ab Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Thu, 11 Apr 2024 22:34:26 +0200 Subject: [PATCH 01/15] Refactor mysql cli code to use a passwordless socket connection by skipping the port number --- install/lib/installer_base.lib.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 9ae569b6fb..1b5495fee1 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -368,13 +368,21 @@ 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'); + $command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset']) + ." -h ".escapeshellarg($conf['mysql']['host']) + ." -u ".escapeshellarg($conf['mysql']['admin_user']); + + if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { + $command .= " -P ".escapeshellarg($conf['mysql']['port']); + } + if ($conf['mysql']['admin_password'] == '') { + $command .= " -p".escapeshellarg($conf['mysql']['admin_password']); } + $command .= " ".escapeshellarg($conf['mysql']['database']); + caselog($command . " < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", + __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.'); -- GitLab From aeabd72dee93e29bd0a0c9c79a901d5f71278eab Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Thu, 11 Apr 2024 22:43:00 +0200 Subject: [PATCH 02/15] Move to separate function load_sql_via_cli --- install/lib/installer_base.lib.php | 34 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 1b5495fee1..34e33bd50b 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -368,20 +368,8 @@ class installer_base extends stdClass { if(count($db_tables) > 0) { $this->error('Stopped: Database already contains some tables.'); } else { - $command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset']) - ." -h ".escapeshellarg($conf['mysql']['host']) - ." -u ".escapeshellarg($conf['mysql']['admin_user']); - - if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { - $command .= " -P ".escapeshellarg($conf['mysql']['port']); - } - if ($conf['mysql']['admin_password'] == '') { - $command .= " -p".escapeshellarg($conf['mysql']['admin_password']); - } - $command .= " ".escapeshellarg($conf['mysql']['database']); - caselog($command . " < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", - __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); + load_sql_via_cli(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) { @@ -395,6 +383,26 @@ class installer_base extends stdClass { } } + public function load_sql_via_cli($filename, $file = '', $line = '', $success = '', $failure = '') { + global $conf; + + $command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset']) + ." -h ".escapeshellarg($conf['mysql']['host']) + ." -u ".escapeshellarg($conf['mysql']['admin_user']); + + // Localhost defaults to use a socket + if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { + $command .= " -P ".escapeshellarg($conf['mysql']['port']); + } + if (!empty($conf['mysql']['admin_password']) { + $command .= " -p".escapeshellarg($conf['mysql']['admin_password']); + } + $command .= " ".escapeshellarg($conf['mysql']['database']); + + caselog($command . " < '$filename' &> /dev/null", $file, $line, $success, $failure); + } + + //** Create the server record in the database public function add_database_server_record() { -- GitLab From 51bd514bfd2a674c34972ac16a103f20f2f85022 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Thu, 11 Apr 2024 22:47:33 +0200 Subject: [PATCH 03/15] Support alternate database --- install/lib/installer_base.lib.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 34e33bd50b..5f19c12e7c 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -369,7 +369,7 @@ class installer_base extends stdClass { $this->error('Stopped: Database already contains some tables.'); } else { - load_sql_via_cli(ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql", __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) { @@ -383,7 +383,7 @@ class installer_base extends stdClass { } } - public function load_sql_via_cli($filename, $file = '', $line = '', $success = '', $failure = '') { + public function load_sql_via_cli($database, $filename, $file = '', $line = '', $success = '', $failure = '') { global $conf; $command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset']) @@ -397,7 +397,7 @@ class installer_base extends stdClass { if (!empty($conf['mysql']['admin_password']) { $command .= " -p".escapeshellarg($conf['mysql']['admin_password']); } - $command .= " ".escapeshellarg($conf['mysql']['database']); + $command .= " ".escapeshellarg($database); caselog($command . " < '$filename' &> /dev/null", $file, $line, $success, $failure); } @@ -2238,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'; -- GitLab From 3240864f7fd5c9e700f6e6a01dff848db31dedcb Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Fri, 12 Apr 2024 23:18:28 +0200 Subject: [PATCH 04/15] DRAFT --- install/lib/update.lib.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/install/lib/update.lib.php b/install/lib/update.lib.php index d88d64d6cd..72e37161d3 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -43,11 +43,7 @@ function prepareDBDump() { //** 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'); - } + $this->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 @@ -209,6 +205,8 @@ function updateDbAndIni() { } //* Load patch file into database + $this->load_sql_via_cli($conf['mysql']['database'], $sql_patch_filename, __FILE__, __LINE__, 'read in pre_update.sql', 'could not read in pre_update.sql'); + 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'])." ".escapeshellarg($conf['mysql']['database'])." < ".$sql_patch_filename; } else { -- GitLab From 259fec1b560222b1271a379ab12e8687485df246 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 20 Apr 2024 15:09:33 +0200 Subject: [PATCH 05/15] Add optional logfile --- install/lib/installer_base.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 5f19c12e7c..1a5d40c4fd 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -383,7 +383,7 @@ class installer_base extends stdClass { } } - public function load_sql_via_cli($database, $filename, $file = '', $line = '', $success = '', $failure = '') { + 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']) @@ -399,7 +399,7 @@ class installer_base extends stdClass { } $command .= " ".escapeshellarg($database); - caselog($command . " < '$filename' &> /dev/null", $file, $line, $success, $failure); + caselog($command . " < '$filename' &> $logfile", $file, $line, $success, $failure); } -- GitLab From 2c55ecd7042497fca1b45435f8c1bdeb64c8a761 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 20 Apr 2024 15:10:00 +0200 Subject: [PATCH 06/15] Prefer long-options, more self documenting --- install/lib/installer_base.lib.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 1a5d40c4fd..7b40ef2c9c 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -387,17 +387,17 @@ class installer_base extends stdClass { global $conf; $command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['charset']) - ." -h ".escapeshellarg($conf['mysql']['host']) - ." -u ".escapeshellarg($conf['mysql']['admin_user']); + ." --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 .= " -P ".escapeshellarg($conf['mysql']['port']); + $command .= " --port=".escapeshellarg($conf['mysql']['port']); } if (!empty($conf['mysql']['admin_password']) { - $command .= " -p".escapeshellarg($conf['mysql']['admin_password']); + $command .= " --password=".escapeshellarg($conf['mysql']['admin_password']); } - $command .= " ".escapeshellarg($database); + $command .= " --database=".escapeshellarg($database); caselog($command . " < '$filename' &> $logfile", $file, $line, $success, $failure); } -- GitLab From a9b93d4c9a0cf24d14f5943d48fa14ecc6c5eab5 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 20 Apr 2024 15:10:46 +0200 Subject: [PATCH 07/15] Cleanup connection test, allow passwordless socket use. --- install/lib/install.lib.php | 2 ++ install/update.php | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/install/lib/install.lib.php b/install/lib/install.lib.php index 885432f7ef..aa470717aa 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/update.php b/install/update.php index 55b711da73..58149492c6 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($database); +$command .= " --execute='SHOW DATABASES'"); + +$retval = caselog($command . " &> /dev/null", $file, $line, $success, $failure); +if($retval == false) { die("Unable to call mysql command line with credentials from mysql_clientdb.conf\n"); } -- GitLab From 0b01a2e363fddb16c35785e67ccbf9a2d1249cb0 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 20 Apr 2024 15:14:28 +0200 Subject: [PATCH 08/15] More load_sql_via_cli() use --- install/dist/lib/gentoo.lib.php | 8 +------- install/lib/update.lib.php | 32 +++++--------------------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/install/dist/lib/gentoo.lib.php b/install/dist/lib/gentoo.lib.php index 69691a6afd..eac07e0a8b 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/update.lib.php b/install/lib/update.lib.php index 72e37161d3..84f78b42f5 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -39,11 +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")) { - $this->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'); + $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 @@ -205,21 +205,7 @@ function updateDbAndIni() { } //* Load patch file into database - $this->load_sql_via_cli($conf['mysql']['database'], $sql_patch_filename, __FILE__, __LINE__, 'read in pre_update.sql', 'could not read in pre_update.sql'); - - 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'])." ".escapeshellarg($conf['mysql']['database'])." < ".$sql_patch_filename; - } 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'])." ".escapeshellarg($conf['mysql']['database'])." < ".$sql_patch_filename; - } - - if(in_array($next_db_version,explode(',',$silent_update_versions))) { - $cmd .= ' > /dev/null 2> /dev/null'; - } else { - $cmd .= ' >> /var/log/ispconfig_install.log 2>> /var/log/ispconfig_install.log'; - } - system($cmd); - + $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", '/var/log/ispconfig_install.log'); swriteln($inst->lng('Loading SQL patch file').': '.$sql_patch_filename); //* Exec onAfterSQL function @@ -264,11 +250,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; @@ -299,11 +281,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'); } } -- GitLab From 84d10d1a7b0f284026b4a17e02e2c1080c10a895 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 20 Apr 2024 16:54:35 +0200 Subject: [PATCH 09/15] syntax --- install/lib/installer_base.lib.php | 2 +- install/update.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 7b40ef2c9c..ff94c1c0fa 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -394,7 +394,7 @@ class installer_base extends stdClass { if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { $command .= " --port=".escapeshellarg($conf['mysql']['port']); } - if (!empty($conf['mysql']['admin_password']) { + if (!empty($conf['mysql']['admin_password'])) { $command .= " --password=".escapeshellarg($conf['mysql']['admin_password']); } $command .= " --database=".escapeshellarg($database); diff --git a/install/update.php b/install/update.php index 58149492c6..98a4c6f15d 100644 --- a/install/update.php +++ b/install/update.php @@ -328,12 +328,12 @@ $command = "mysql --default-character-set=".escapeshellarg($conf['mysql']['chars if ($conf['mysql']['host'] != 'localhost' || $conf['mysql']['port'] != '3306') { $command .= " --port=".escapeshellarg($conf['mysql']['port']); } -if (!empty($conf['mysql']['admin_password']) { +if (!empty($conf['mysql']['admin_password'])) { $command .= " --password=".escapeshellarg($conf['mysql']['admin_password']); } $command .= " --database=".escapeshellarg($database); -$command .= " --execute='SHOW DATABASES'"); +$command .= " --execute='SHOW DATABASES'"; $retval = caselog($command . " &> /dev/null", $file, $line, $success, $failure); if($retval == false) { -- GitLab From 78f3245942a969bbfe9d0c0e3f0e9503f8890bad Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 20 Apr 2024 16:54:46 +0200 Subject: [PATCH 10/15] Add correct var values --- install/update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/update.php b/install/update.php index 98a4c6f15d..30e0480dae 100644 --- a/install/update.php +++ b/install/update.php @@ -335,7 +335,7 @@ if (!empty($conf['mysql']['admin_password'])) { $command .= " --database=".escapeshellarg($database); $command .= " --execute='SHOW DATABASES'"; -$retval = caselog($command . " &> /dev/null", $file, $line, $success, $failure); +$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"); } -- GitLab From f875de20170471602d63d9789aa81f104ca46eb7 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 20 Apr 2024 17:04:50 +0200 Subject: [PATCH 11/15] Append --- install/lib/installer_base.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index ff94c1c0fa..2edb22055c 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -399,7 +399,7 @@ class installer_base extends stdClass { } $command .= " --database=".escapeshellarg($database); - caselog($command . " < '$filename' &> $logfile", $file, $line, $success, $failure); + caselog($command . " < '$filename' &>> $logfile", $file, $line, $success, $failure); } -- GitLab From 47af43a710ad04513ed0886ec347e90521c53d0d Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 27 Apr 2024 23:14:05 +0200 Subject: [PATCH 12/15] Replicate conditional command buildup for mysqlcheck --- install/lib/update.lib.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/install/lib/update.lib.php b/install/lib/update.lib.php index 84f78b42f5..25d02ea745 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -99,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; $i Date: Sat, 27 Apr 2024 23:21:53 +0200 Subject: [PATCH 13/15] Fix variable source --- install/update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/update.php b/install/update.php index 30e0480dae..899b9a5a3c 100644 --- a/install/update.php +++ b/install/update.php @@ -332,7 +332,7 @@ if (!empty($conf['mysql']['admin_password'])) { $command .= " --password=".escapeshellarg($conf['mysql']['admin_password']); } -$command .= " --database=".escapeshellarg($database); +$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'); -- GitLab From 29b8aed64bf147b4d45f3808605a2dc6e95b180a Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 28 Apr 2024 09:17:53 +0200 Subject: [PATCH 14/15] Re-add the silent_update_versions feature --- install/lib/update.lib.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/install/lib/update.lib.php b/install/lib/update.lib.php index 25d02ea745..a428151208 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -220,7 +220,12 @@ function updateDbAndIni() { } //* Load patch file into database - $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", '/var/log/ispconfig_install.log'); + if(in_array($next_db_version,explode(',',$silent_update_versions))) { + $logfile = '/dev/null'; + } else { + $logfile = '/var/log/ispconfig_install.log'; + } + $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); swriteln($inst->lng('Loading SQL patch file').': '.$sql_patch_filename); //* Exec onAfterSQL function -- GitLab From 32870480ac230f4f35a012b4eaed10c765ebe3a0 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Fri, 17 May 2024 22:01:49 +0200 Subject: [PATCH 15/15] Loading is not the past-tense, so we should print this before the file is loaded --- install/lib/update.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/lib/update.lib.php b/install/lib/update.lib.php index a428151208..d82db9a3a7 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -225,8 +225,8 @@ function updateDbAndIni() { } else { $logfile = '/var/log/ispconfig_install.log'; } - $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); swriteln($inst->lng('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')) { -- GitLab