mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 09:41:40 +09:00
Fix #1721 add some safeguards when saving system config file
This commit is contained in:
parent
b01a148675
commit
254634479c
3 changed files with 25 additions and 4 deletions
|
|
@ -135,16 +135,34 @@ class Config
|
|||
self::setAll($config);
|
||||
}
|
||||
|
||||
// Backup the main config file.
|
||||
$config_filename = \RX_BASEDIR . self::$config_filename;
|
||||
$backup_filename = \RX_BASEDIR . self::$config_filename . '.backup.' . time() . '.php';
|
||||
$result = Storage::copy($config_filename, $backup_filename);
|
||||
clearstatcache(true, $backup_filename);
|
||||
if (!$result || filesize($config_filename) !== filesize($backup_filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the main config file.
|
||||
$buff = '<?php' . "\n" . '// Rhymix System Configuration' . "\n" . 'return ' . self::serialize(self::$_config) . ';' . "\n";
|
||||
$result = Storage::write(\RX_BASEDIR . self::$config_filename, $buff) ? true : false;
|
||||
$result = Storage::write($config_filename, $buff) ? true : false;
|
||||
clearstatcache(true, $config_filename);
|
||||
if (!$result || filesize($config_filename) !== strlen($buff))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the backup file.
|
||||
Storage::delete($backup_filename);
|
||||
|
||||
// Save XE-compatible config files.
|
||||
$warning = '// THIS FILE IS NOT USED IN RHYMIX.' . "\n" . '// TO MODIFY SYSTEM CONFIGURATION, EDIT config.php INSTEAD.';
|
||||
$buff = '<?php' . "\n" . $warning . "\n";
|
||||
Storage::write(\RX_BASEDIR . self::$old_db_config_filename, $buff);
|
||||
Storage::write(\RX_BASEDIR . self::$old_ftp_config_filename, $buff);
|
||||
return $result;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ class Storage
|
|||
flock($fp, \LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
if ($result === false)
|
||||
if ($result === false || (is_string($content) && strlen($content) !== $result))
|
||||
{
|
||||
trigger_error('Cannot write file: ' . (isset($original_filename) ? $original_filename : $filename), \E_USER_WARNING);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1257,7 +1257,10 @@ class adminAdminController extends admin
|
|||
Rhymix\Framework\Config::set('url.http_port', $vars->http_port ?: null);
|
||||
Rhymix\Framework\Config::set('url.https_port', $vars->https_port ?: null);
|
||||
Rhymix\Framework\Config::set('url.ssl', $vars->domain_security);
|
||||
Rhymix\Framework\Config::save();
|
||||
if (!Rhymix\Framework\Config::save())
|
||||
{
|
||||
throw new Rhymix\Framework\Exception('msg_failed_to_save_config');
|
||||
}
|
||||
}
|
||||
|
||||
// Commit.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue