From 6e8eafe12938b3733a753dc59dd2f31c5501ac4d Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 4 Oct 2017 21:55:03 +0200 Subject: [PATCH] implemented INI cenversion functionality --- lib/Configuration.php | 28 ++++++++++++++++++++++++++++ lib/Data/Database.php | 5 ++--- tst/ConfigurationTest.php | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/lib/Configuration.php b/lib/Configuration.php index a9c8a75..4b7d35c 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -101,6 +101,33 @@ class Configuration { $config = array(); $configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.php'; + $configIni = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'; + + // rename INI files to avoid configuration leakage + if (is_readable($configIni)) { + // don't overwrite already converted file + if (!is_file($configFile)) { + $iniUpgradeError = false; + $context = stream_context_create(); + $iniHandle = fopen($configIni, 'r', 1, $context); + $written = file_put_contents($configFile, '; $values) { // fill missing sections with default values diff --git a/lib/Data/Database.php b/lib/Data/Database.php index 2c844ef..9685edd 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -693,9 +693,8 @@ class Database extends AbstractData 'CREATE INDEX IF NOT EXISTS comment_parent ON ' . self::_sanitizeIdentifier('comment') . '(pasteid);' ); - // no break, continue with updates for 0.22 - case '0.22': - case '1.0': + // no break, continue with updates for 0.22 and later + default: self::_exec( 'UPDATE ' . self::_sanitizeIdentifier('config') . ' SET value = ? WHERE id = ?', diff --git a/tst/ConfigurationTest.php b/tst/ConfigurationTest.php index b98425e..55d8288 100644 --- a/tst/ConfigurationTest.php +++ b/tst/ConfigurationTest.php @@ -157,4 +157,20 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase 'configuration values get converted' ); } + + public function testRenameIniSample() + { + $iniSample = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample'; + $phpSample = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.sample.php'; + + Helper::createIniFile(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', $this->_options); + if (is_file(CONF)) { + chmod(CONF, 0600); + unlink(CONF); + } + rename($phpSample, $iniSample); + new Configuration; + $this->assertFileNotExists($iniSample, 'old sample file gets removed'); + $this->assertFileExists($phpSample, 'new sample file gets created'); + } }