diff --git a/cfg/.htaccess b/cfg/.htaccess new file mode 100644 index 0000000..b584d98 --- /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 0000000..b584d98 --- /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 c2cc4e8..dbf7c66 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 2e389fe..6492ae4 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 8d1e173..39fd27f 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 .