Merge branch 'm1cr0man-master'

This commit is contained in:
El RIDO 2019-12-25 08:16:33 +01:00
commit ddaee6486d
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
5 changed files with 86 additions and 9 deletions

View File

@ -3,6 +3,7 @@
* **1.4 (not yet released)** * **1.4 (not yet released)**
* ADDED: Translation for Ukrainian (#533) * ADDED: Translation for Ukrainian (#533)
* ADDED: Option to send a mail with the link, when creating a paste (#398) * ADDED: Option to send a mail with the link, when creating a paste (#398)
* ADDED: Add support for CONFIG_PATH environment variable (#552)
* FIXED: Password disabling option (#527) * FIXED: Password disabling option (#527)
* **1.3.1 (2019-09-22)** * **1.3.1 (2019-09-22)**
* ADDED: Translation for Bulgarian (#455) * ADDED: Translation for Bulgarian (#455)

View File

@ -26,6 +26,7 @@ Sébastien Sauvage - original idea and main developer
* thororm - Display of video, audio & PDF, drag & drop, preview of attachments * thororm - Display of video, audio & PDF, drag & drop, preview of attachments
* Harald Leithner - base58 encoding of key * Harald Leithner - base58 encoding of key
* Haocen - lots of bugfixes and UI improvements * Haocen - lots of bugfixes and UI improvements
* Lucas Savva - configurable config file location, NixOS packaging
## Translations ## Translations
* Hexalyse - French * Hexalyse - French

View File

@ -50,6 +50,27 @@ process (see also
> PrivateBin will look for your includes / data here: > PrivateBin will look for your includes / data here:
> /home/example.com/secret/privatebin > /home/example.com/secret/privatebin
### Changing the config path only
In situations where you want to keep the PrivateBin static files separate from the
rest of your data, or you want to reuse the installation files on multiple vhosts,
you may only want to change the `conf.php`. In this instance, you can set the
`CONFIG_PATH` environment variable to the absolute path to the `conf.php` file.
This can be done in your web server's virtual host config, the PHP config, or in
the index.php if you choose to customize it.
Note that your PHP process will need read access to the config wherever it may be.
> #### CONFIG_PATH example
> Setting the value in an Apache Vhost:
> SetEnv CONFIG_PATH /var/lib/privatebin/conf.php
>
> In a php-fpm pool config:
> env[CONFIG_PATH] = /var/lib/privatebin/conf.php
>
> In the index.php, near the top:
> putenv('CONFIG_PATH=/var/lib/privatebin/conf.php');
### Transport security ### Transport security
When setting up PrivateBin, also set up HTTPS, if you haven't already. Without HTTPS When setting up PrivateBin, also set up HTTPS, if you haven't already. Without HTTPS
@ -66,8 +87,9 @@ See [this FAQ item](https://github.com/PrivateBin/PrivateBin/wiki/FAQ#what-are-t
In the file `cfg/conf.php` you can configure PrivateBin. A `cfg/conf.sample.php` In the file `cfg/conf.php` you can configure PrivateBin. A `cfg/conf.sample.php`
is provided containing all options and default values. You can copy it to is provided containing all options and default values. You can copy it to
`cfg/conf.php` and adapt it as needed. The config file is divided into multiple `cfg/conf.php` and adapt it as needed. Alternatively you can copy it anywhere and
sections, which are enclosed in square brackets. set the `CONFIG_PATH` environment variable (see above notes). The config file is
divided into multiple sections, which are enclosed in square brackets.
In the `[main]` section you can enable or disable the discussion feature, set In the `[main]` section you can enable or disable the discussion feature, set
the limit of stored pastes and comments in bytes. The `[traffic]` section lets the limit of stored pastes and comments in bytes. The `[traffic]` section lets

View File

@ -102,8 +102,9 @@ class Configuration
public function __construct() public function __construct()
{ {
$config = array(); $config = array();
$configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.php'; $basePath = (getenv('CONFIG_PATH') !== false ? getenv('CONFIG_PATH') : PATH . 'cfg') . DIRECTORY_SEPARATOR;
$configIni = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'; $configIni = $basePath . 'conf.ini';
$configFile = $basePath . 'conf.php';
// rename INI files to avoid configuration leakage // rename INI files to avoid configuration leakage
if (is_readable($configIni)) { if (is_readable($configIni)) {
@ -112,7 +113,7 @@ class Configuration
// cleanup sample, too // cleanup sample, too
$configIniSample = $configIni . '.sample'; $configIniSample = $configIni . '.sample';
if (is_readable($configIniSample)) { if (is_readable($configIniSample)) {
DataStore::prependRename($configIniSample, PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.sample.php', ';'); DataStore::prependRename($configIniSample, $basePath . 'conf.sample.php', ';');
} }
} }

View File

@ -4,24 +4,31 @@ use PrivateBin\Configuration;
class ConfigurationTest extends PHPUnit_Framework_TestCase class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
private $_minimalConfig;
private $_options; private $_options;
private $_minimalConfig; private $_path;
public function setUp() public function setUp()
{ {
/* Setup Routine */ /* Setup Routine */
Helper::confBackup(); Helper::confBackup();
$this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]';
$this->_options = Configuration::getDefaults(); $this->_options = Configuration::getDefaults();
$this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir']; $this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir'];
$this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir']; $this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir'];
$this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir']; $this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir'];
$this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]'; $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_cfg';
if (!is_dir($this->_path)) {
mkdir($this->_path);
}
} }
public function tearDown() public function tearDown()
{ {
/* Tear Down Routine */ /* Tear Down Routine */
Helper::rmDir($this->_path);
if (is_file(CONF)) { if (is_file(CONF)) {
unlink(CONF); unlink(CONF);
} }
@ -177,4 +184,49 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$this->assertFileExists(CONF, 'old configuration file gets converted'); $this->assertFileExists(CONF, 'old configuration file gets converted');
$this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed'); $this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed');
} }
public function testConfigPath()
{
// setup
$configFile = $this->_path . DIRECTORY_SEPARATOR . 'conf.php';
$options = $this->_options;
$options['main']['name'] = 'OtherBin';
Helper::createIniFile($configFile, $options);
// test
putenv('CONFIG_PATH=' . $this->_path);
$conf = new Configuration;
$this->assertEquals('OtherBin', $conf->getKey('name'), 'changing config path is supported');
// cleanup environment
if (is_file($configFile)) {
unlink($configFile);
}
putenv('CONFIG_PATH');
}
public function testConfigPathIni()
{
// setup
$configFile = $this->_path . DIRECTORY_SEPARATOR . 'conf.ini';
$configMigrated = $this->_path . DIRECTORY_SEPARATOR . 'conf.php';
$options = $this->_options;
$options['main']['name'] = 'OtherBin';
Helper::createIniFile($configFile, $options);
$this->assertFileNotExists(CONF, 'configuration in the default location is non existing');
// test
putenv('CONFIG_PATH=' . $this->_path);
$conf = new Configuration;
$this->assertEquals('OtherBin', $conf->getKey('name'), 'changing config path is supported for ini files as well');
$this->assertFileExists($configMigrated, 'old configuration file gets converted');
$this->assertFileNotExists($configFile, 'old configuration file gets removed');
$this->assertFileNotExists(CONF, 'configuration is not created in the default location');
// cleanup environment
if (is_file($configFile)) {
unlink($configFile);
}
putenv('CONFIG_PATH');
}
} }