[fix] Add configuration variable for Nginx

This commit is contained in:
magikcypress 2017-04-25 17:17:33 +02:00
parent af595ed96d
commit 02204a26de
3 changed files with 29 additions and 27 deletions

View File

@ -3,9 +3,6 @@
; An explanation of each setting can be find online at https://github.com/PrivateBin/PrivateBin/wiki/Configuration. ; An explanation of each setting can be find online at https://github.com/PrivateBin/PrivateBin/wiki/Configuration.
[main] [main]
; (optional) set a project name to be displayed on the website
; name = "PrivateBin"
; enable or disable the discussion feature, defaults to true ; enable or disable the discussion feature, defaults to true
discussion = true discussion = true
@ -21,10 +18,6 @@ fileupload = false
; preselect the burn-after-reading feature, defaults to false ; preselect the burn-after-reading feature, defaults to false
burnafterreadingselected = false burnafterreadingselected = false
; delete a burn after reading paste immediatly after it is first accessed from
; the server and do not wait for a successful decryption
instantburnafterreading = false
; which display mode to preselect by default, defaults to "plaintext" ; which display mode to preselect by default, defaults to "plaintext"
; make sure the value exists in [formatter_options] ; make sure the value exists in [formatter_options]
defaultformatter = "plaintext" defaultformatter = "plaintext"
@ -32,10 +25,10 @@ defaultformatter = "plaintext"
; (optional) set a syntax highlighting theme, as found in css/prettify/ ; (optional) set a syntax highlighting theme, as found in css/prettify/
; syntaxhighlightingtheme = "sons-of-obsidian" ; syntaxhighlightingtheme = "sons-of-obsidian"
; size limit per paste or comment in bytes, defaults to 2 Mebibytes ; size limit per paste or comment in bytes, defaults to 2 Mibibytes
sizelimit = 2097152 sizelimit = 2097152
; template to include, default is "bootstrap" (tpl/bootstrap.php) ; template to include, default is "bootstrap" (tpl/bootstrap.html)
template = "bootstrap" template = "bootstrap"
; (optional) notice to display ; (optional) notice to display
@ -67,14 +60,17 @@ languageselection = false
; custom scripts from third-party domains to your templates, e.g. tracking ; custom scripts from third-party domains to your templates, e.g. tracking
; scripts or run your site behind certain DDoS-protection services. ; scripts or run your site behind certain DDoS-protection services.
; Check the documentation at https://content-security-policy.com/ ; Check the documentation at https://content-security-policy.com/
; Note: If you use a bootstrap theme, you can remove the allow-popups from the sandbox restrictions. ; cspheader = "default-src 'none'; manifest-src 'self'; connect-src *; script-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' data:; referrer no-referrer;"
; cspheader = "default-src 'none'; manifest-src 'self'; connect-src *; script-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' data:; referrer no-referrer; sandbox allow-same-origin allow-scripts allow-forms allow-popups"
; stay compatible with PrivateBin Alpha 0.19, less secure ; stay compatible with PrivateBin Alpha 0.19, less secure
; if enabled will use base64.js version 1.7 instead of 2.1.9 and sha1 instead of ; if enabled will use base64.js version 1.7 instead of 2.1.9 and sha1 instead of
; sha256 in HMAC for the deletion token ; sha256 in HMAC for the deletion token
zerobincompatibility = false zerobincompatibility = false
; allows you to specify the name of the web server you are using to use ParseBin.
; If you use nginx or other webserver, delete semicolon
; webserver = "nginx"
[expire] [expire]
; expire value that is selected per default ; expire value that is selected per default
; make sure the value exists in [expire_options] ; make sure the value exists in [expire_options]

View File

@ -36,13 +36,11 @@ class Configuration
*/ */
private static $_defaults = array( private static $_defaults = array(
'main' => array( 'main' => array(
'name' => 'PrivateBin',
'discussion' => true, 'discussion' => true,
'opendiscussion' => false, 'opendiscussion' => false,
'password' => true, 'password' => true,
'fileupload' => false, 'fileupload' => false,
'burnafterreadingselected' => false, 'burnafterreadingselected' => false,
'instantburnafterreading' => false,
'defaultformatter' => 'plaintext', 'defaultformatter' => 'plaintext',
'syntaxhighlightingtheme' => null, 'syntaxhighlightingtheme' => null,
'sizelimit' => 2097152, 'sizelimit' => 2097152,
@ -52,8 +50,9 @@ class Configuration
'languagedefault' => '', 'languagedefault' => '',
'urlshortener' => '', 'urlshortener' => '',
'icon' => 'identicon', 'icon' => 'identicon',
'cspheader' => 'default-src \'none\'; manifest-src \'self\'; connect-src *; script-src \'self\'; style-src \'self\'; font-src \'self\'; img-src \'self\' data:; referrer no-referrer; sandbox allow-same-origin allow-scripts allow-forms allow-popups', 'cspheader' => 'default-src \'none\'; manifest-src \'self\'; connect-src *; script-src \'self\'; style-src \'self\'; font-src \'self\'; img-src \'self\' data:; referrer no-referrer;',
'zerobincompatibility' => false, 'zerobincompatibility' => false,
'webserver' => 'apache',
), ),
'expire' => array( 'expire' => array(
'default' => '1week', 'default' => '1week',
@ -241,7 +240,7 @@ class Configuration
public function getSection($section) public function getSection($section)
{ {
if (!array_key_exists($section, $this->_configuration)) { if (!array_key_exists($section, $this->_configuration)) {
throw new Exception(I18n::_('%s requires configuration section [%s] to be present in configuration file.', I18n::_($this->getKey('name')), $section), 3); throw new Exception(I18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 3);
} }
return $this->_configuration[$section]; return $this->_configuration[$section];
} }

View File

@ -36,6 +36,7 @@ abstract class AbstractPersistence
* @access public * @access public
* @static * @static
* @param string $path * @param string $path
* @return void
*/ */
public static function setPath($path) public static function setPath($path)
{ {
@ -79,26 +80,32 @@ abstract class AbstractPersistence
* @access protected * @access protected
* @static * @static
* @throws Exception * @throws Exception
* @return void
*/ */
protected static function _initialize() protected static function _initialize()
{ {
// Create storage directory if it does not exist. // Create storage directory if it does not exist.
if (!is_dir(self::$_path)) { if (!is_dir(self::$_path)) {
if (!@mkdir(self::$_path, 0700)) { if (!@mkdir(self::$_path)) {
throw new Exception('unable to create directory ' . self::$_path, 10); throw new Exception('unable to create directory ' . self::$_path, 10);
} }
} }
$file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess';
if (!is_file($file)) { if (property_exists($data->meta, 'webserver') && $data->meta->webserver && $this->_conf->getKey('webserver') == "Apache") {
$writtenBytes = @file_put_contents( // Create .htaccess file if it does not exist.
$file, $file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess';
'Require all denied' . PHP_EOL, if (!is_file($file)) {
LOCK_EX $writtenBytes = @file_put_contents(
); $file,
if ($writtenBytes === false || $writtenBytes < 19) { 'Allow from none' . PHP_EOL .
throw new Exception('unable to write to file ' . $file, 11); 'Deny from all' . PHP_EOL,
} LOCK_EX
} );
if ($writtenBytes === false || $writtenBytes < 30) {
throw new Exception('unable to write to file ' . $file, 11);
}
}
}
} }
/** /**