updated doc blocks, comments, fixed indentations, moved some constant strings

This commit is contained in:
El RIDO 2021-06-14 06:44:30 +02:00
parent b72994f2e0
commit 3327645fd4
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
5 changed files with 24 additions and 15 deletions

View File

@ -15,7 +15,7 @@ namespace PrivateBin\Data;
/** /**
* AbstractData * AbstractData
* *
* Abstract model for PrivateBin data access, implemented as a singleton. * Abstract model for data access, implemented as a singleton.
*/ */
abstract class AbstractData abstract class AbstractData
{ {
@ -40,7 +40,7 @@ abstract class AbstractData
/** /**
* Enforce singleton, disable constructor * Enforce singleton, disable constructor
* *
* Instantiate using {@link getInstance()}, privatebin is a singleton object. * Instantiate using {@link getInstance()}, this object implements the singleton pattern.
* *
* @access protected * @access protected
*/ */
@ -51,7 +51,7 @@ abstract class AbstractData
/** /**
* Enforce singleton, disable cloning * Enforce singleton, disable cloning
* *
* Instantiate using {@link getInstance()}, privatebin is a singleton object. * Instantiate using {@link getInstance()}, this object implements the singleton pattern.
* *
* @access private * @access private
*/ */

View File

@ -23,12 +23,19 @@ use PrivateBin\Json;
class Filesystem extends AbstractData class Filesystem extends AbstractData
{ {
/** /**
* first line in file, to protect its contents * first line in paste or comment files, to protect their contents from browsing exposed data directories
* *
* @const string * @const string
*/ */
const PROTECTION_LINE = '<?php http_response_code(403); /*'; const PROTECTION_LINE = '<?php http_response_code(403); /*';
/**
* line in generated .htaccess files, to protect exposed directories from being browsable on apache web servers
*
* @const string
*/
const HTACCESS_LINE = 'Require all denied';
/** /**
* path in which to persist something * path in which to persist something
* *
@ -513,11 +520,15 @@ class Filesystem extends AbstractData
if ($fileCreated = @touch($file)) { if ($fileCreated = @touch($file)) {
$writtenBytes = @file_put_contents( $writtenBytes = @file_put_contents(
$file, $file,
'Require all denied' . PHP_EOL, self::HTACCESS_LINE . PHP_EOL,
LOCK_EX LOCK_EX
); );
} }
if ($fileCreated === false || $writtenBytes === false || $writtenBytes < 19) { if (
$fileCreated === false ||
$writtenBytes === false ||
$writtenBytes < strlen(self::HTACCESS_LINE . PHP_EOL)
) {
return false; return false;
} }
} }
@ -533,7 +544,7 @@ class Filesystem extends AbstractData
if ($fileCreated === false || $writtenBytes === false || $writtenBytes < strlen($data)) { if ($fileCreated === false || $writtenBytes === false || $writtenBytes < strlen($data)) {
return false; return false;
} }
@chmod($filename, 0640); // protect file access @chmod($filename, 0640); // protect file from access by other users on the host
return true; return true;
} }

View File

@ -9,8 +9,6 @@ use PrivateBin\Json;
class GoogleCloudStorage extends AbstractData class GoogleCloudStorage extends AbstractData
{ {
const DATETIME_FORMAT = 'Y-m-d\TH:i:s.u\Z';
/** /**
* returns a Google Cloud Storage data backend. * returns a Google Cloud Storage data backend.
* *

View File

@ -306,7 +306,7 @@ class StorageObjectStub extends StorageObject
$this->_info = $info; $this->_info = $info;
$this->_connection = $connection; $this->_connection = $connection;
$timeCreated = new Datetime(); $timeCreated = new Datetime();
$this->_info['metadata']['timeCreated'] = $timeCreated->format(GoogleCloudStorage::DATETIME_FORMAT); $this->_info['metadata']['timeCreated'] = $timeCreated->format('Y-m-d\TH:i:s.u\Z');
} }
public function acl() public function acl()