diff options
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/attachment/upload.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/cache/driver/file.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/composer/installer.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/db/extractor/base_extractor.php | 11 | ||||
-rw-r--r-- | phpBB/phpbb/files/types/remote.php | 19 | ||||
-rw-r--r-- | phpBB/phpbb/files/types/remote_storage.php | 19 | ||||
-rw-r--r-- | phpBB/phpbb/filesystem/filesystem.php | 42 | ||||
-rw-r--r-- | phpBB/phpbb/filesystem/temp.php | 54 |
8 files changed, 85 insertions, 74 deletions
diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index 82a7578380..b3cd4972a1 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -21,6 +21,7 @@ use \phpbb\language\language; use \phpbb\mimetype\guesser; use \phpbb\plupload\plupload; use \phpbb\storage\storage; +use \phpbb\filesystem\temp; use \phpbb\user; /** @@ -55,6 +56,9 @@ class upload /** @var storage */ protected $storage; + /** @var temp */ + protected $temp; + /** @var user */ protected $user; @@ -80,9 +84,10 @@ class upload * @param guesser $mimetype_guesser * @param dispatcher $phpbb_dispatcher * @param plupload $plupload + * @param temp $temp * @param user $user */ - public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, user $user) + public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, temp $temp, user $user) { $this->auth = $auth; $this->cache = $cache; @@ -93,6 +98,7 @@ class upload $this->phpbb_dispatcher = $phpbb_dispatcher; $this->plupload = $plupload; $this->storage = $storage; + $this->temp = $temp; $this->user = $user; } @@ -234,7 +240,7 @@ class upload { $source = $this->file->get('filename'); $destination_name = 'thumb_' . $this->file->get('realname'); - $destination = sys_get_temp_dir() . '/' . $destination_name; + $destination = $this->temp->get_temp_dir() . '/' . $destination_name; if (create_thumbnail($source, $destination, $this->file->get('mimetype'))) { diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 2e9018ca19..de6f444251 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -35,7 +35,7 @@ class file extends \phpbb\cache\driver\base global $phpbb_container; $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir'); - $this->filesystem = new \phpbb\filesystem\filesystem(''); + $this->filesystem = new \phpbb\filesystem\filesystem(); if (!is_dir($this->cache_dir)) { diff --git a/phpBB/phpbb/composer/installer.php b/phpBB/phpbb/composer/installer.php index 5038cc7cb8..3a03e29ef5 100644 --- a/phpBB/phpbb/composer/installer.php +++ b/phpBB/phpbb/composer/installer.php @@ -402,7 +402,7 @@ class installer */ public function check_requirements() { - $filesystem = new \phpbb\filesystem\filesystem(''); + $filesystem = new \phpbb\filesystem\filesystem(); return $filesystem->is_writable([ $this->root_path . $this->composer_filename, diff --git a/phpBB/phpbb/db/extractor/base_extractor.php b/phpBB/phpbb/db/extractor/base_extractor.php index 1c49b5b70a..b750f064bb 100644 --- a/phpBB/phpbb/db/extractor/base_extractor.php +++ b/phpBB/phpbb/db/extractor/base_extractor.php @@ -22,9 +22,9 @@ use phpbb\db\extractor\exception\extractor_not_initialized_exception; abstract class base_extractor implements extractor_interface { /** - * @var \phpbb\filesystem\filesystem + * @var \phpbb\filesystem\temp */ - protected $filesystem; + protected $temp; /** * @var \phpbb\request\request_interface @@ -84,12 +84,13 @@ abstract class base_extractor implements extractor_interface /** * Constructor * + * @param \phpbb\filesystem\temp $temp * @param \phpbb\request\request_interface $request * @param \phpbb\db\driver\driver_interface $db */ - public function __construct(\phpbb\filesystem\filesystem $filesystem, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) + public function __construct(\phpbb\filesystem\temp $temp, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db) { - $this->filesystem = $filesystem; + $this->temp = $temp; $this->request = $request; $this->db = $db; $this->fp = null; @@ -163,7 +164,7 @@ abstract class base_extractor implements extractor_interface if ($store === true) { - $file = $this->filesystem->get_temp_dir() . '/' . $filename . $ext; + $file = $this->temp->get_temp_dir() . '/' . $filename . $ext; $this->fp = $open($file, 'w'); diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index b32b06adce..3bfd7dc7cd 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -17,7 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use phpbb\config\config; use phpbb\files\factory; use phpbb\files\filespec; -use phpbb\filesystem\filesystem; +use phpbb\filesystem\temp; use phpbb\language\language; use phpbb\request\request_interface; @@ -29,8 +29,8 @@ class remote extends base /** @var factory Files factory */ protected $factory; - /** @var filesystem Filesystem */ - protected $filesystem; + /** @var filesystem Filesystem temp */ + protected $temp; /** @var language */ protected $language; @@ -41,29 +41,24 @@ class remote extends base /** @var request_interface */ protected $request; - /** @var string phpBB root path */ - protected $phpbb_root_path; - /** * Construct a form upload type * * @param config $config phpBB config * @param factory $factory Files factory - * @param filesystem $filesystem Filesystem + * @param temp $temp Filesystem temp * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object - * @param string $phpbb_root_path phpBB root path */ - public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) + public function __construct(config $config, factory $factory, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request) { $this->config = $config; $this->factory = $factory; - $this->filesystem = $filesystem; + $this->temp = $temp; $this->language = $language; $this->php_ini = $php_ini; $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; } /** @@ -151,7 +146,7 @@ class remote extends base $data = $response->getBody(); - $filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php index 54960b477e..8c2ceb6900 100644 --- a/phpBB/phpbb/files/types/remote_storage.php +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -17,7 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use phpbb\config\config; use phpbb\files\factory; use phpbb\files\filespec; -use phpbb\filesystem\filesystem; +use phpbb\filesystem\temp; use phpbb\language\language; use phpbb\request\request_interface; @@ -29,8 +29,8 @@ class remote_storage extends base /** @var factory Files factory */ protected $factory; - /** @var filesystem Filesystem */ - protected $filesystem; + /** @var temp Filesystem temp */ + protected $temp; /** @var language */ protected $language; @@ -41,29 +41,24 @@ class remote_storage extends base /** @var request_interface */ protected $request; - /** @var string phpBB root path */ - protected $phpbb_root_path; - /** * Construct a form upload type * * @param config $config phpBB config * @param factory $factory Files factory - * @param filesystem $filesystem Filesystem + * @param temp $temp Filesystem temp * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param request_interface $request Request object - * @param string $phpbb_root_path phpBB root path */ - public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) + public function __construct(config $config, factory $factory, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request) { $this->config = $config; $this->factory = $factory; - $this->filesystem = $filesystem; + $this->temp = $temp; $this->language = $language; $this->php_ini = $php_ini; $this->request = $request; - $this->phpbb_root_path = $phpbb_root_path; } /** @@ -150,7 +145,7 @@ class remote_storage extends base $data = $response->getBody(); - $filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-'); + $filename = tempnam($this->temp->get_temp_dir(), unique_id() . '-'); if (!($fp = @fopen($filename, 'wb'))) { diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index ed63282d99..7754a4107b 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -43,24 +43,13 @@ class filesystem implements filesystem_interface protected $symfony_filesystem; /** - * @var string - */ - protected $cache_temp_dir; - - /** - * @var string - */ - protected $temp_dir; - - /** * Constructor */ - public function __construct($cache_temp_dir) + public function __construct() { $this->chmod_info = array(); $this->symfony_filesystem = new \Symfony\Component\Filesystem\Filesystem(); $this->working_directory = null; - $this->cache_temp_dir = $cache_temp_dir; } /** @@ -753,33 +742,4 @@ class filesystem implements filesystem_interface { return helper::resolve_path($path, $prefix, $absolute, $return_array); } - - /** - * Get a temporary directory to write files - * - * @return string returns the directory - */ - public function get_temp_dir() - { - if (!isset($this->temp_dir)) - { - $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; - - // Prevent trying to write to system temp dir in case of open_basedir - // restrictions being in effect - if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir)) - { - $tmp_dir = $this->cache_temp_dir; - - if (!is_dir($tmp_dir)) - { - $this->mkdir($tmp_dir, 0777); - } - } - - $this->temp_dir = helper::realpath($tmp_dir); - } - - return $this->temp_dir; - } } diff --git a/phpBB/phpbb/filesystem/temp.php b/phpBB/phpbb/filesystem/temp.php new file mode 100644 index 0000000000..ffd9cc6973 --- /dev/null +++ b/phpBB/phpbb/filesystem/temp.php @@ -0,0 +1,54 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\filesystem; + +class temp +{ + /** + * @var string + */ + protected $temp_dir; + + /** + * Constructor + */ + public function __construct($filesystem, $cache_temp_dir) + { + $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : ''; + + // Prevent trying to write to system temp dir in case of open_basedir + // restrictions being in effect + if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir)) + { + $tmp_dir = $cache_temp_dir; + + if (!is_dir($tmp_dir)) + { + $filesystem->mkdir($tmp_dir, 0777); + } + } + + $this->temp_dir = helper::realpath($tmp_dir); + } + + /** + * Get a temporary directory to write files + * + * @return string returns the directory + */ + public function get_temp_dir() + { + return $this->temp_dir; + } +} |