Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .docker/php/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
4 changes: 2 additions & 2 deletions Languages/en_US/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><br>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}<br><br>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';
Expand Down Expand Up @@ -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!<br><br>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 <strong>session.save_path specified in php.ini</strong> is not valid! It needs to be changed to a directory that <strong>exists</strong> and is <strong>writable</strong> by the user PHP is running under.<br>';
$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.<br><br><a href="https://www.simplemachines.org/redirect/mod_security">More information about disabling mod_security</a>';
$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.<br><br><a href="https://www.simplemachines.org/redirect/mod_security">More information about disabling mod_security</a><br><br>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.';
Expand Down Expand Up @@ -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.<br><br>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.<br><br>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.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.';
$txt['error_agreement_not_writable'] = 'The upgrader was unable to obtain write access to agreement.txt.<br><br>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.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its directory.';
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/ViewQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
'!=',
)
) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Db/APIs/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Db/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use SMF\Config;
use SMF\Db\DatabaseApi as Db;
use SMF\Lang;
use SMF\Utils;

/**
* Represents a database table.
Expand Down Expand Up @@ -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';
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Db/Schema/v3_0/Initialize/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace SMF\Db\Schema\v3_0\Initialize;

use SMF\Utils;

class PostgreSQL extends Base
{
/****************
Expand All @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion Sources/MailAgent/MailAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
'>=',
)
);
}

/**
Expand Down
211 changes: 211 additions & 0 deletions Sources/Maintenance/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion Sources/Maintenance/Migration/v2_1/BoardDescriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'<',
);
Expand Down
3 changes: 2 additions & 1 deletion Sources/Maintenance/Migration/v2_1/UserDrafts.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SMF\Db\Schema;
use SMF\Maintenance\Maintenance;
use SMF\Maintenance\Migration\MigrationBase;
use SMF\Utils;

class UserDrafts extends MigrationBase
{
Expand Down Expand Up @@ -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',
'<',
)
Expand Down
Loading