From 23487ce7794ee1bdab726f01c28c9b9704af6684 Mon Sep 17 00:00:00 2001 From: Simon Rupf Date: Mon, 30 Apr 2012 13:58:29 +0200 Subject: [PATCH] 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. --- cfg/.htaccess | 2 ++ lib/.htaccess | 2 ++ lib/traffic_limiter.php | 12 +++++++++++- lib/zerobin.php | 9 +++++++++ lib/zerobin_data.php | 16 ++++++++-------- 5 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 cfg/.htaccess create mode 100644 lib/.htaccess diff --git a/cfg/.htaccess b/cfg/.htaccess new file mode 100644 index 00000000..b584d98c --- /dev/null +++ b/cfg/.htaccess @@ -0,0 +1,2 @@ +Allow from none +Deny from all diff --git a/lib/.htaccess b/lib/.htaccess new file mode 100644 index 00000000..b584d98c --- /dev/null +++ b/lib/.htaccess @@ -0,0 +1,2 @@ +Allow from none +Deny from all diff --git a/lib/traffic_limiter.php b/lib/traffic_limiter.php index c2cc4e8a..dbf7c663 100644 --- a/lib/traffic_limiter.php +++ b/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)) { diff --git a/lib/zerobin.php b/lib/zerobin.php index 2e389fe1..6492ae44 100644 --- a/lib/zerobin.php +++ b/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']; } diff --git a/lib/zerobin_data.php b/lib/zerobin_data.php index 8d1e1732..39fd27f5 100644 --- a/lib/zerobin_data.php +++ b/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 .