diff --git a/.docker/php/entrypoint.sh b/.docker/php/entrypoint.sh
index 05d37fe70bb..631b3b58472 100644
--- a/.docker/php/entrypoint.sh
+++ b/.docker/php/entrypoint.sh
@@ -128,6 +128,18 @@ chown -R www-data:www-data \
"$BOARD_DIR/Settings.php" \
"$BOARD_DIR/Settings_bak.php" 2>/dev/null || true
+# ---------------------------------------------------------------- manifest
+# The installer and upgrader both try to check the manifest in order to
+# verify that all required files are present. However, the manifest is
+# intentionally not included in development versions of SMF. Although the
+# installer and upgrader will silently ignore a missing manifest file in
+# development versions, creating one on the fly harms nothing and allows
+# more complete testing of the install and upgrade processes.
+if [ ! -f "$BOARD_DIR/Sources/Maintenance/manifest.php" ]; then
+ log 'building manifest.php'
+ php -f "$BOARD_DIR/other/update_manifest.php" &>/dev/null || true
+fi
+
log 'ready'
exec "$@"
diff --git a/.gitignore b/.gitignore
index d68f074d24d..283e7e49228 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,9 +29,6 @@ Themes/default/scripts/autolinker.js
custom_avatar/
!custom_avatar/index.php
!custom_avatar/blank.png
-Sources/Unicode/*.php
-!Sources/Unicode/index.php
-!Sources/Unicode/Utf8String.php
logs
# Compiled source #
diff --git a/Languages/en_US/Maintenance.php b/Languages/en_US/Maintenance.php
index a12ad693d89..2ef5b54c2eb 100644
--- a/Languages/en_US/Maintenance.php
+++ b/Languages/en_US/Maintenance.php
@@ -59,6 +59,8 @@
$txt['query_unsuccessful'] = 'Unsuccessful!';
$txt['query_failed'] = 'This query: {QUERY_STRING}
Caused the error: {QUERY_ERROR}';
+$txt['error_missing_files'] = 'Some required files are either missing or have unexpected content.
Please make sure you uploaded all of the files included in the SMF package and then try again.';
+$txt['error_missing_files_debug'] = 'The following files are either missing or have unexpected content: {missing_files}
Please make sure you uploaded all of the files included in the SMF package and then try again.';
// Progress bars and steps.
$txt['maintenance_progress'] = 'Progress';
@@ -126,7 +128,6 @@
$txt['error_db_missing'] = 'The installer was unable to detect any database support in PHP. Please ask your host to ensure that PHP was compiled with the desired database, or that the proper extension is being loaded.';
$txt['error_db_type_unknown'] = '“{db_type}” is not a database type this server supports. Supported types: {supported}.';
$txt['error_session_missing'] = 'The installer was unable to detect sessions support in your server’s installation of PHP. Please ask your host to ensure that PHP was compiled with session support (which in fact is the PHP default, meaning your host currently has explicitly disabled it).';
-$txt['error_missing_files'] = 'Unable to find crucial installation files in the directory of this script!
Please make sure you uploaded the entire installation package, including the sql file, and then try again.';
$txt['error_session_save_path'] = 'Please inform your host that the session.save_path specified in php.ini is not valid! It needs to be changed to a directory that exists and is writable by the user PHP is running under.
';
$txt['error_mod_security'] = 'The installer has detected the mod_security module is installed on your web server. Mod_security will block submitted forms even before SMF gets a say in anything. SMF has a built-in security scanner that will work more effectively than mod_security and that will not block submitted forms.
More information about disabling mod_security';
$txt['error_mod_security_no_write'] = 'The installer has detected the mod_security module is installed on your web server. Mod_security will block submitted forms even before SMF gets a say in anything. SMF has a built-in security scanner that will work more effectively than mod_security and that will not block submitted forms.
More information about disabling mod_security
Alternatively, you may wish to use your ftp client to chmod .htaccess in the forum directory to be writable (777), and then refresh this page.';
@@ -447,7 +448,6 @@
// Upgrade error messages
$txt['upgrade_unsuccessful'] = 'Unsuccessful!';
-$txt['error_upgrade_files_missing'] = 'The upgrader was unable to find some crucial files.
Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.';
$txt['error_upgrade_old_files'] = 'The upgrader found some old or outdated files.
Please make certain you uploaded the new versions of all the files included in the package.';
$txt['error_cache_not_found'] = 'The cache directory could not be found.
Please make sure you have a directory called "cache" in your forum directory before continuing.';
$txt['error_agreement_not_writable'] = 'The upgrader was unable to obtain write access to agreement.txt.
If you are using a linux or unix based server, please ensure that the file is chmod’d to 777, or if it does not exist that the directory this upgrader is in is 777.
If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its directory.';
diff --git a/Sources/Actions/ViewQuery.php b/Sources/Actions/ViewQuery.php
index b3edf092643..6c7dfae85e5 100644
--- a/Sources/Actions/ViewQuery.php
+++ b/Sources/Actions/ViewQuery.php
@@ -205,7 +205,7 @@ public function execute(): void
$result = Db::$db->query('ANALYZE FORMAT=JSON ' . $select);
} elseif ($vendor == 'PostgreSQL') {
$result = Db::$db->query('(ANALYZE, FORMAT JSON) ' . $select);
- } elseif ($vendor == 'MySQL' && version_compare($version, '8.3.0', '>=')) {
+ } elseif ($vendor == 'MySQL' && version_compare(Utils::standardizeVersionString($version), '8.3.0', '>=')) {
Db::$db->query('SET explain_json_format_version=2');
$result = Db::$db->query('EXPLAIN ANALYZE FORMAT=JSON ' . $select);
} else {
diff --git a/Sources/Config.php b/Sources/Config.php
index 0014252111a..b5d1e7e0f53 100644
--- a/Sources/Config.php
+++ b/Sources/Config.php
@@ -1135,8 +1135,8 @@ public static function reloadModSettings(): void
)
&& !empty(self::$modSettings['smfVersion'])
&& version_compare(
- strtolower(strtr(self::$modSettings['smfVersion'], [' ' => '.'])),
- strtolower(strtr(SMF_VERSION, [' ' => '.'])),
+ strtolower(Utils::standardizeVersionString(self::$modSettings['smfVersion'])),
+ strtolower(Utils::standardizeVersionString(SMF_VERSION)),
'!=',
)
) {
diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php
index 698b50836d6..9ff45ed598c 100644
--- a/Sources/Db/APIs/MySQL.php
+++ b/Sources/Db/APIs/MySQL.php
@@ -867,7 +867,7 @@ public function cte_support(): bool
$min_version = str_contains(strtolower($this->version), 'mariadb') ? '10.2.2' : '8.0.1';
- $this->supports_cte = version_compare($this->version, $min_version, '>=');
+ $this->supports_cte = version_compare(Utils::standardizeVersionString($this->version), $min_version, '>=');
return $this->supports_cte;
}
diff --git a/Sources/Db/Schema/Table.php b/Sources/Db/Schema/Table.php
index dfb4278817c..b391c970819 100644
--- a/Sources/Db/Schema/Table.php
+++ b/Sources/Db/Schema/Table.php
@@ -18,6 +18,7 @@
use SMF\Config;
use SMF\Db\DatabaseApi as Db;
use SMF\Lang;
+use SMF\Utils;
/**
* Represents a database table.
@@ -67,7 +68,7 @@ abstract class Table
if (
!isset($this->default_charset)
&& preg_match('/\\\\v(\d+_\d+)\\\\/', $this::class, $matches)
- && version_compare(strtr($matches[1], '_', '.'), '3.0', '>=')
+ && version_compare(Utils::standardizeVersionString($matches[1]), '3.0', '>=')
) {
$this->default_charset = Db::$db->title === MYSQL_TITLE ? 'utf8mb4' : 'utf8';
}
diff --git a/Sources/Db/Schema/v3_0/Initialize/PostgreSQL.php b/Sources/Db/Schema/v3_0/Initialize/PostgreSQL.php
index 5f4b9fd1cc6..61ee45f9904 100644
--- a/Sources/Db/Schema/v3_0/Initialize/PostgreSQL.php
+++ b/Sources/Db/Schema/v3_0/Initialize/PostgreSQL.php
@@ -15,6 +15,8 @@
namespace SMF\Db\Schema\v3_0\Initialize;
+use SMF\Utils;
+
class PostgreSQL extends Base
{
/****************
@@ -33,7 +35,7 @@ public function functions(): array
// PostgreSQL changed how we can do some aggregation functions in 14 and beyond
// Idea for the GROUP_CONCAT from: https://dba.stackexchange.com/questions/24984/is-it-possible-to-wrap-aggregate-functions-in-postgres
- if (version_compare($this->version, '14', '>')) {
+ if (version_compare(Utils::standardizeVersionString($this->version), '14', '>')) {
// This isn't even my final form.
$functions[] = '
CREATE OR REPLACE FUNCTION GROUP_CONCAT_FINAL(anycompatiblearray)
diff --git a/Sources/MailAgent/MailAgent.php b/Sources/MailAgent/MailAgent.php
index 6a4c0c1f9e3..90792dbfe26 100644
--- a/Sources/MailAgent/MailAgent.php
+++ b/Sources/MailAgent/MailAgent.php
@@ -151,7 +151,18 @@ public function agentSettings(array &$config_vars): void {}
*/
public function isCompatible(string $smfVersion): bool
{
- return version_compare($this->min_smf_version, $smfVersion, '<=') && version_compare($smfVersion, $this->version_compatible, '>=');
+ return (
+ version_compare(
+ Utils::standardizeVersionString($this->min_smf_version),
+ Utils::standardizeVersionString($smfVersion),
+ '<=',
+ )
+ && version_compare(
+ Utils::standardizeVersionString($smfVersion),
+ Utils::standardizeVersionString($this->version_compatible),
+ '>=',
+ )
+ );
}
/**
diff --git a/Sources/Maintenance/Maintenance.php b/Sources/Maintenance/Maintenance.php
index ae1ed8a67b9..e1fdc6c199e 100644
--- a/Sources/Maintenance/Maintenance.php
+++ b/Sources/Maintenance/Maintenance.php
@@ -426,6 +426,217 @@ function ($matches) {
return $boarddir ?? \dirname(__DIR__);
}
+ /**
+ * Checks the files listed in manifest.php and returns a list of any that are
+ * missing or have incorrect content.
+ *
+ * @param string $start_version The version of SMF we are starting from.
+ * For upgrades, this should be the version of SMF that was in use before
+ * the upgrade began. For new installs, this should be SMF_VERSION.
+ * @param bool $check_content Whether to validate the content of the files.
+ * @return array A list of missing or corrupt files.
+ */
+ final public static function checkManifest(string $start_version, bool $check_content): array
+ {
+ $boarddir = self::getBaseDir();
+
+ $missing_or_corrupt_files = [];
+
+ // Does the manifest file exist?
+ if (!is_file(__DIR__ . DIRECTORY_SEPARATOR . 'manifest.php')) {
+ // Development versions normally don't include a manifest.
+ // This is by design and receives special handling here.
+ if (str_ends_with(SMF_VERSION, '-dev')) {
+ // Just check the migrations and cleanups and call it done.
+ foreach (Tools\Upgrade::VERSION_MAP as $version => $ns) {
+ if (
+ version_compare(
+ Utils::standardizeVersionString($start_version),
+ $version,
+ '>',
+ )
+ ) {
+ continue;
+ }
+
+ foreach (Tools\Upgrade::MIGRATIONS[$ns] as $class) {
+ if (!class_exists($class)) {
+ $missing_or_corrupt_files[] = preg_replace(
+ ['/^SMF\b/', '/\\\\/', '/$/'],
+ ['Sources', DIRECTORY_SEPARATOR, '.php'],
+ $class,
+ );
+ }
+ }
+
+ foreach (Tools\Upgrade::CLEANUPS[$ns] as $class) {
+ if (!class_exists($class)) {
+ $missing_or_corrupt_files[] = preg_replace(
+ ['/^SMF\b/', '/\\\\/', '/$/'],
+ ['Sources', DIRECTORY_SEPARATOR, '.php'],
+ $class,
+ );
+ }
+ }
+ }
+
+ return $missing_or_corrupt_files;
+ }
+
+ // We can't do anything without the manifest file.
+ $sourcedir = Config::$sourcedir ?? $boarddir . DIRECTORY_SEPARATOR . 'Sources';
+
+ $missing_or_corrupt_files[] = str_replace(
+ Sapi::canonicalPath($sourcedir),
+ basename($sourcedir),
+ __DIR__ . DIRECTORY_SEPARATOR . 'manifest.php',
+ );
+
+ return $missing_or_corrupt_files;
+ }
+
+ // Get the manifest.
+ try {
+ $contents = @file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'manifest.php');
+
+ $valid = (
+ $contents !== false
+ // Must start with an opening PHP tag.
+ && str_starts_with($contents, '<' . '?php')
+ // Must not contain a closing tag.
+ && !str_contains($contents, '?' . '>')
+ // Does it at least appear to have the expected contents?
+ && str_contains($contents, "\nreturn ")
+ );
+
+ unset($contents);
+
+ $manifest = !$valid ? false : include __DIR__ . DIRECTORY_SEPARATOR . 'manifest.php';
+ } catch (\Throwable $e) {
+ $manifest = false;
+ }
+
+ // Manifest must be an array.
+ if (!\is_array($manifest)) {
+ $sourcedir = Config::$sourcedir ?? $boarddir . DIRECTORY_SEPARATOR . 'Sources';
+
+ $missing_or_corrupt_files[] = str_replace(
+ Sapi::canonicalPath($sourcedir),
+ basename($sourcedir),
+ __DIR__ . DIRECTORY_SEPARATOR . 'manifest.php',
+ );
+
+ return $missing_or_corrupt_files;
+ }
+
+ // Which sections of the manifest do we care about?
+ $max = preg_replace('/^(\d)\.(\d).*/', '$1.$2', SMF_VERSION);
+ $min = preg_replace('/^(\d)\.(\d).*/', '$1.$2', $start_version);
+
+ $required_versions = array_filter(
+ array_map(
+ fn($v) => preg_replace('/^(\d)\.(\d).*/', '$1.$2', $v),
+ array_keys(Tools\Upgrade::VERSION_MAP),
+ ),
+ fn($v) => version_compare($v, $min, '>=') && version_compare($v, $max, '<='),
+ );
+
+ // Verify that each section of the manifest is structured correctly.
+ foreach ($required_versions as $version) {
+ if (
+ // $manifest[$version] must exist.
+ !\array_key_exists($version, $manifest)
+ // Keys must be strings.
+ || (
+ array_keys($manifest[$version]) !== array_map(
+ 'strval',
+ array_keys($manifest[$version]),
+ )
+ )
+ // Values must be strings or bools.
+ || (
+ $manifest[$version] !== array_filter(
+ $manifest[$version],
+ fn($v) => \is_bool($v) || \is_string($v),
+ )
+ )
+ ) {
+ $sourcedir = Config::$sourcedir ?? $boarddir . DIRECTORY_SEPARATOR . 'Sources';
+
+ $missing_or_corrupt_files[] = str_replace(
+ Sapi::canonicalPath($sourcedir),
+ basename($sourcedir),
+ __DIR__ . DIRECTORY_SEPARATOR . 'manifest.php',
+ );
+
+ return $missing_or_corrupt_files;
+ }
+ }
+
+ // Do all the files in the manifest exist and have the expected content?
+ foreach ($required_versions as $version) {
+ foreach ($manifest[$version] as $path => $checksum) {
+ $is_valid = false;
+ $possible_paths = [];
+
+ // Check for special directories that could have been moved.
+ switch (strstr($path, '/', true)) {
+ case 'Languages':
+ if (isset(Config::$languagesdir)) {
+ $possible_paths[] = Sapi::canonicalPath(Config::$languagesdir . strstr($path, '/'));
+ }
+ break;
+
+ case 'Packages':
+ if (isset(Config::$packagesdir)) {
+ $possible_paths[] = Sapi::canonicalPath(Config::$packagesdir . strstr($path, '/'));
+ }
+ break;
+
+ case 'Sources':
+ if (isset(Config::$sourcedir)) {
+ $possible_paths[] = Sapi::canonicalPath(Config::$sourcedir . strstr($path, '/'));
+ }
+ break;
+
+ case 'vendor':
+ if (isset(Config::$vendordir)) {
+ $possible_paths[] = Sapi::canonicalPath(Config::$vendordir . strstr($path, '/'));
+ }
+ break;
+ }
+
+ // Standard path.
+ $possible_paths[] = Sapi::canonicalPath($boarddir . '/' . $path);
+
+ // Check each possible path.
+ foreach (array_unique($possible_paths) as $possible_path) {
+ $is_valid = (
+ file_exists($possible_path)
+ && (
+ !$check_content
+ || $checksum === true
+ || (
+ is_file($possible_path)
+ && $checksum === @md5_file($possible_path)
+ )
+ )
+ );
+
+ if ($is_valid) {
+ break;
+ }
+ }
+
+ if (!$is_valid) {
+ $missing_or_corrupt_files[] = $path;
+ }
+ }
+ }
+
+ return $missing_or_corrupt_files;
+ }
+
/**
* Fetch our current step.
*
diff --git a/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php b/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php
index 97c1aea00fd..1d1fbc4f50f 100644
--- a/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php
+++ b/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php
@@ -43,7 +43,7 @@ class BoardDescriptions extends MigrationBase
public function isCandidate(): bool
{
return version_compare(
- str_replace(' ', '.', strtolower(Config::$modSettings['smfVersion'] ?? '0.0.dev.0')),
+ Utils::standardizeVersionString(Config::$modSettings['smfVersion'] ?? '0.0.dev.0'),
'2.1.dev.0',
'<',
);
diff --git a/Sources/Maintenance/Migration/v2_1/UserDrafts.php b/Sources/Maintenance/Migration/v2_1/UserDrafts.php
index dbc8cc516b6..8fd0ba543d5 100644
--- a/Sources/Maintenance/Migration/v2_1/UserDrafts.php
+++ b/Sources/Maintenance/Migration/v2_1/UserDrafts.php
@@ -20,6 +20,7 @@
use SMF\Db\Schema;
use SMF\Maintenance\Maintenance;
use SMF\Maintenance\Migration\MigrationBase;
+use SMF\Utils;
class UserDrafts extends MigrationBase
{
@@ -64,7 +65,7 @@ public function execute(): bool
if (
$start <= 1
&& version_compare(
- str_replace(' ', '.', strtolower(Config::$modSettings['smfVersion'] ?? '0.0.dev.0')),
+ Utils::standardizeVersionString(Config::$modSettings['smfVersion'] ?? '0.0.dev.0'),
'2.1.dev.0',
'<',
)
diff --git a/Sources/Maintenance/Tools/Install.php b/Sources/Maintenance/Tools/Install.php
index 457bc6e9237..4ae4b1e426d 100644
--- a/Sources/Maintenance/Tools/Install.php
+++ b/Sources/Maintenance/Tools/Install.php
@@ -112,6 +112,11 @@ class Install extends ToolsBase implements ToolsInterface
*/
public function __construct()
{
+ // Are we doing debug?
+ if (isset($_GET['debug']) || isset($_POST['debug'])) {
+ $this->debug = true;
+ }
+
Maintenance::$languages = $this->detectLanguages(['General', 'Maintenance']);
if (empty(Maintenance::$languages)) {
@@ -252,6 +257,9 @@ public function welcome(): bool
{
// Done the submission?
if (isset($_POST['contbutt'])) {
+ // Does the admin want debug info?
+ $this->debug = isset($_POST['debug']);
+
return true;
}
@@ -295,13 +303,31 @@ public function welcome(): bool
}
// Make sure they uploaded all the files.
- if (!file_exists(Config::$boarddir . '/index.php')) {
- Maintenance::$errors[] = Lang::getTxt('error_missing_files', file: 'Maintenance');
- $this->logProgress(Lang::getTxt('error_missing_files', file: 'Maintenance'));
+ if (($missing_files = Maintenance::checkManifest(SMF_VERSION, true)) !== []) {
+ $error_message = Lang::getTxt(
+ 'error_missing_files' . ($this->isDebug() ? '_debug' : ''),
+ [
+ 'missing_files' => '