From e3fd38fd7ef7e3bb1dbb871fdd6786c7009aa36d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 12 May 2022 11:04:02 +0200 Subject: [PATCH] Remove the WCF_N input in WCFSetup Users should install separate instances into separate databases for security reasons. This also avoids issues with users running a non-standard number and any existing guides / queries not working, because the database tables have a different name. --- extra/examples/wsc-dev-config-55.json | 3 +-- .../files/lib/system/WCFSetup.class.php | 19 +++---------------- .../system/devtools/DevtoolsSetup.class.php | 1 - wcfsetup/setup/lang/setup_de.xml | 4 +--- wcfsetup/setup/lang/setup_en.xml | 4 +--- wcfsetup/setup/template/stepConfigureDB.tpl | 8 -------- 6 files changed, 6 insertions(+), 33 deletions(-) diff --git a/extra/examples/wsc-dev-config-55.json b/extra/examples/wsc-dev-config-55.json index 605aa81ebf..24b5118aa7 100644 --- a/extra/examples/wsc-dev-config-55.json +++ b/extra/examples/wsc-dev-config-55.json @@ -4,8 +4,7 @@ "auto": true, "host": "localhost", "password": "root", - "username": "root", - "dbNumber": "2" + "username": "root" }, "useDefaultInstallPath": true, "forceStaticCookiePrefix": true diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 607e4315cf..792ed2893d 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -651,7 +651,6 @@ class WCFSetup extends WCF $dbUser = $_ENV['WCFSETUP_DBUSER']; $dbPassword = $_ENV['WCFSETUP_DBPASSWORD']; $dbName = $_ENV['WCFSETUP_DBNAME']; - $dbNumber = 1; $attemptConnection = true; } elseif (self::$developerMode && ($config = DevtoolsSetup::getInstance()->getDatabaseConfig()) !== null) { @@ -659,7 +658,6 @@ class WCFSetup extends WCF $dbUser = $config['username']; $dbPassword = $config['password']; $dbName = $config['dbName']; - $dbNumber = $config['dbNumber']; if ($config['auto']) { $attemptConnection = true; @@ -669,7 +667,6 @@ class WCFSetup extends WCF $dbUser = 'root'; $dbPassword = ''; $dbName = 'wcf'; - $dbNumber = 1; } if ($attemptConnection) { @@ -686,11 +683,6 @@ class WCFSetup extends WCF $dbName = $_POST['dbName']; } - // ensure that $dbNumber is zero or a positive integer - if (isset($_POST['dbNumber'])) { - $dbNumber = \max(0, \intval($_POST['dbNumber'])); - } - // get port $dbHostWithoutPort = $dbHost; $dbPort = 0; @@ -790,7 +782,7 @@ class WCFSetup extends WCF */ // check for table conflicts - $conflictedTables = $this->getConflictedTables($db, $dbNumber); + $conflictedTables = $this->getConflictedTables($db); // write config.inc if (empty($conflictedTables)) { @@ -803,7 +795,7 @@ class WCFSetup extends WCF $file->write("\$dbUser = '" . \str_replace("'", "\\'", $dbUser) . "';\n"); $file->write("\$dbPassword = '" . \str_replace("'", "\\'", $dbPassword) . "';\n"); $file->write("\$dbName = '" . \str_replace("'", "\\'", $dbName) . "';\n"); - $file->write("if (!defined('WCF_N')) define('WCF_N', {$dbNumber});\n"); + $file->write("if (!defined('WCF_N')) define('WCF_N', 1);\n"); $file->close(); // go to next step @@ -823,7 +815,6 @@ class WCFSetup extends WCF 'dbUser' => $dbUser, 'dbPassword' => $dbPassword, 'dbName' => $dbName, - 'dbNumber' => $dbNumber, 'nextStep' => 'configureDB', ]); WCF::getTPL()->display('stepConfigureDB'); @@ -834,17 +825,13 @@ class WCFSetup extends WCF * which will be created in the next step. * * @param \wcf\system\database\Database $db - * @param int $dbNumber * @return string[] list of already existing tables */ - protected function getConflictedTables($db, $dbNumber) + protected function getConflictedTables($db) { // get content of the sql structure file $sql = \file_get_contents(TMP_DIR . 'setup/db/install.sql'); - // installation number value 'n' (WCF_N) must be reflected in the executed sql queries - $sql = \str_replace('wcf1_', 'wcf' . $dbNumber . '_', $sql); - // get all tablenames which should be created \preg_match_all("%CREATE\\s+TABLE\\s+(\\w+)%", $sql, $matches); diff --git a/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php b/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php index ba35890fdf..62e44910d6 100644 --- a/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php +++ b/wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php @@ -79,7 +79,6 @@ class DevtoolsSetup extends SingletonFactory 'password' => $dbConfig['password'], 'username' => $dbConfig['username'], 'dbName' => $dbName, - 'dbNumber' => $dbConfig['dbNumber'], ]; } diff --git a/wcfsetup/setup/lang/setup_de.xml b/wcfsetup/setup/lang/setup_de.xml index 8bac0d1ba2..86ea5f2d65 100644 --- a/wcfsetup/setup/lang/setup_de.xml +++ b/wcfsetup/setup/lang/setup_de.xml @@ -61,11 +61,9 @@ - - 1 wählen.]]> {$exception->getMessage()}{if $exception->getPrevious()}
{$exception->getPrevious()->getMessage()}{/if}
]]>
- 1}n{/if} existier{if $conflictedTables|count > 1}en{else}t{/if} schon in der Datenbank „{$dbName}“:
{implode from=$conflictedTables item="table"}{$table}{/implode}.

Um dieses Problem zu beheben, können Sie:
1. diese Tabelle{if $conflictedTables|count > 1}n{/if} manuell löschen und die „Weiter“ Schaltfläche betätigen, oder
2. Sie geben die Daten einer anderen Datenbank ein und betätigen die „Weiter“ Schaltfläche, oder
3. Sie geben eine von „{$dbNumber}“ unterschiedliche Installationsnummer an und betätigen die „Weiter“ Schaltfläche.]]>
+ 1}n{/if} existier{if $conflictedTables|count > 1}en{else}t{/if} schon in der Datenbank „{$dbName}“:
{implode from=$conflictedTables item="table"}{$table}{/implode}.

Um dieses Problem zu beheben, können Sie:
1. diese Tabelle{if $conflictedTables|count > 1}n{/if} manuell löschen und die „Weiter“ Schaltfläche betätigen, oder
2. Sie geben die Daten einer anderen Datenbank ein und betätigen die „Weiter“ Schaltfläche.]]>
diff --git a/wcfsetup/setup/lang/setup_en.xml b/wcfsetup/setup/lang/setup_en.xml index cfa8e785e0..aad35e741a 100644 --- a/wcfsetup/setup/lang/setup_en.xml +++ b/wcfsetup/setup/lang/setup_en.xml @@ -61,11 +61,9 @@ - - 1.]]> {$exception->getMessage()}{if $exception->getPrevious()}
{$exception->getPrevious()->getMessage()}{/if}
]]>
- 1}s{/if} already exist{if $conflictedTables|count == 1}s{/if} within your “{$dbName}” Database:
{implode from=$conflictedTables item="table"}{$table}{/implode}.

To solve this problem, please do one of the following:
1. Remove the table{if $conflictedTables|count > 1}s{/if} manually and continue the installation with the “Next” button or
2. You re-enter the database access information, but to a different database and continue the installation with the “Next” button or
3. Enter a new installation number, not forgetting to continue the installation with the “Next” Button.]]>
+ 1}s{/if} already exist{if $conflictedTables|count == 1}s{/if} within your “{$dbName}” Database:
{implode from=$conflictedTables item="table"}{$table}{/implode}.

To solve this problem, please do one of the following:
1. Remove the table{if $conflictedTables|count > 1}s{/if} manually and continue the installation with the “Next” button or
2. You re-enter the database access information, but to a different database and continue the installation with the “Next” button.]]>
diff --git a/wcfsetup/setup/template/stepConfigureDB.tpl b/wcfsetup/setup/template/stepConfigureDB.tpl index 446f4ef199..0329f8abb4 100644 --- a/wcfsetup/setup/template/stepConfigureDB.tpl +++ b/wcfsetup/setup/template/stepConfigureDB.tpl @@ -37,14 +37,6 @@ {lang}wcf.global.configureDB.database.description{/lang} - -
-
-
- - {lang}wcf.global.configureDB.number.description{/lang} -
-
-- 2.20.1