瀏覽代碼

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

El RIDO 5 年之前
父節點
當前提交
3327645fd4
共有 5 個文件被更改,包括 24 次插入15 次删除
  1. 3 3
      lib/Data/AbstractData.php
  2. 1 1
      lib/Data/Database.php
  3. 19 8
      lib/Data/Filesystem.php
  4. 0 2
      lib/Data/GoogleCloudStorage.php
  5. 1 1
      tst/Bootstrap.php

+ 3 - 3
lib/Data/AbstractData.php

@@ -15,7 +15,7 @@ namespace PrivateBin\Data;
 /**
  * AbstractData
  *
- * Abstract model for PrivateBin data access, implemented as a singleton.
+ * Abstract model for data access, implemented as a singleton.
  */
 abstract class AbstractData
 {
@@ -40,7 +40,7 @@ abstract class AbstractData
     /**
      * 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
      */
@@ -51,7 +51,7 @@ abstract class AbstractData
     /**
      * 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
      */

+ 1 - 1
lib/Data/Database.php

@@ -234,7 +234,7 @@ class Database extends AbstractData
 
         self::$_cache[$pasteid] = false;
         try {
-            $paste                  = self::_select(
+            $paste = self::_select(
                 'SELECT * FROM ' . self::_sanitizeIdentifier('paste') .
                 ' WHERE dataid = ?', array($pasteid), true
             );

+ 19 - 8
lib/Data/Filesystem.php

@@ -23,12 +23,19 @@ use PrivateBin\Json;
 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 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
      *
@@ -327,8 +334,8 @@ class Filesystem extends AbstractData
             substr(
                 file_get_contents($filename),
                 strlen(self::PROTECTION_LINE . PHP_EOL)
-                )
-            );
+            )
+        );
     }
 
     /**
@@ -453,7 +460,7 @@ class Filesystem extends AbstractData
     private static function _isFirstLevelDir($element)
     {
         return self::_isSecondLevelDir($element) &&
-        is_dir(self::$_path . DIRECTORY_SEPARATOR . $element);
+            is_dir(self::$_path . DIRECTORY_SEPARATOR . $element);
     }
 
     /**
@@ -513,11 +520,15 @@ class Filesystem extends AbstractData
             if ($fileCreated = @touch($file)) {
                 $writtenBytes = @file_put_contents(
                     $file,
-                    'Require all denied' . PHP_EOL,
+                    self::HTACCESS_LINE . PHP_EOL,
                     LOCK_EX
-                    );
+                );
             }
-            if ($fileCreated === false || $writtenBytes === false || $writtenBytes < 19) {
+            if (
+                $fileCreated === false ||
+                $writtenBytes === false ||
+                $writtenBytes < strlen(self::HTACCESS_LINE . PHP_EOL)
+            ) {
                 return false;
             }
         }
@@ -533,7 +544,7 @@ class Filesystem extends AbstractData
         if ($fileCreated === false || $writtenBytes === false || $writtenBytes < strlen($data)) {
             return false;
         }
-        @chmod($filename, 0640); // protect file access
+        @chmod($filename, 0640); // protect file from access by other users on the host
         return true;
     }
 

+ 0 - 2
lib/Data/GoogleCloudStorage.php

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

+ 1 - 1
tst/Bootstrap.php

@@ -306,7 +306,7 @@ class StorageObjectStub extends StorageObject
         $this->_info                            = $info;
         $this->_connection                      = $connection;
         $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()