Просмотр исходного кода

Fixed bug with missing directory separator and added .htaccess files to lib & cfg directories. If those are not present, the application will create them for you.

Simon Rupf 14 лет назад
Родитель
Сommit
23487ce779
5 измененных файлов с 32 добавлено и 9 удалено
  1. 2 0
      cfg/.htaccess
  2. 2 0
      lib/.htaccess
  3. 11 1
      lib/traffic_limiter.php
  4. 9 0
      lib/zerobin.php
  5. 8 8
      lib/zerobin_data.php

+ 2 - 0
cfg/.htaccess

@@ -0,0 +1,2 @@
+Allow from none
+Deny from all

+ 2 - 0
lib/.htaccess

@@ -0,0 +1,2 @@
+Allow from none
+Deny from all

+ 11 - 1
lib/traffic_limiter.php

@@ -69,7 +69,17 @@ class traffic_limiter
      */
     public static function canPass($ip)
     {
-        if (!is_dir(self::$_path)) mkdir(self::$_path, 0705, true);
+        // Create storage directory if it does not exist.
+        if (!is_dir(self::$_path)) mkdir(self::$_path, 0705);
+        // Create .htaccess file if it does not exist.
+        if (!is_file(self::$_path . '/.htaccess'))
+        {
+            file_put_contents(
+                self::$_path . '/.htaccess',
+                'Allow from none' . PHP_EOL .
+                'Deny from all'. PHP_EOL
+            );
+        }
         $file = self::$_path . '/traffic_limiter.php';
         if (!is_file($file))
         {

+ 9 - 0
lib/zerobin.php

@@ -95,6 +95,15 @@ class zerobin
      */
     private function _init()
     {
+        foreach (array('cfg', 'lib') as $dir)
+        {
+            if (!is_file(PATH . $dir . '/.htaccess')) file_put_contents(
+                PATH . $dir . '/.htaccess',
+                'Allow from none' . PHP_EOL .
+                'Deny from all'. PHP_EOL
+            );
+        }
+
         $this->_conf = parse_ini_file(PATH . 'cfg/conf.ini');
         $this->_model = $this->_conf['model'];
     }

+ 8 - 8
lib/zerobin_data.php

@@ -60,15 +60,16 @@ class zerobin_data
      */
     public static function getInstance($options)
     {
+        // if given update the data directory
+        if (
+        	is_array($options) &&
+        	array_key_exists('dir', $options)
+        ) self::$_dir = $options['dir'] . '/';
         // if needed initialize the singleton
         if(null === self::$_instance) {
             self::$_instance = new self;
             self::_init();
         }
-        if (
-        	is_array($options) && 
-        	array_key_exists('dir', $options)
-        ) self::$_dir = $options['dir'];
         return self::$_instance;
     }
 
@@ -232,12 +233,11 @@ class zerobin_data
      */
     private static function _init()
     {
-        if (defined('PATH')) self::$_dir = PATH . self::$_dir;
-
         // Create storage directory if it does not exist.
-        if (!is_dir(self::$_dir))
+        if (!is_dir(self::$_dir)) mkdir(self::$_dir, 0705);
+        // Create .htaccess file if it does not exist.
+        if (!is_file(self::$_dir . '.htaccess'))
         {
-            mkdir(self::$_dir, 0705);
             file_put_contents(
                 self::$_dir . '.htaccess',
                 'Allow from none' . PHP_EOL .