Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ext-ftp to requirements #4270

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3180,16 +3180,6 @@ parameters:
count: 15
path: app/code/core/Mage/Catalog/Model/Resource/Setup.php

-
message: "#^Parameter \\#1 \\$categoryIds of method Mage_Catalog_Model_Resource_Url\\:\\:_getCategories\\(\\) expects array\\|int, null given\\.$#"
count: 1
path: app/code/core/Mage/Catalog/Model/Resource/Url.php

-
message: "#^Parameter \\#1 \\$productIds of method Mage_Catalog_Model_Resource_Url\\:\\:_getProducts\\(\\) expects array\\|int, null given\\.$#"
count: 1
path: app/code/core/Mage/Catalog/Model/Resource/Url.php

-
message: "#^Parameter \\#3 \\$storeId of method Mage_Catalog_Model_Resource_Url\\:\\:_getProductAttribute\\(\\) expects string, int given\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ext-ctype": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-ftp": "*",
"ext-gd": "*",
"ext-hash": "*",
"ext-iconv": "*",
Expand Down
3 changes: 2 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions lib/Mage/System/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected function checkConnected()
public function mdkir($name)
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_mkdir($this->_conn, $name);
}

Expand All @@ -70,14 +71,19 @@ public function mkdirRecursive($path, $mode = 0777)
$dir = explode('/', $path);
$path = '';
$ret = true;
// phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed,Ecg.Performance.Loop.ArraySize
for ($i = 0; $i < count($dir); $i++) {
$path .= '/' . $dir[$i];
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
if (!@ftp_chdir($this->_conn, $path)) {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
@ftp_chdir($this->_conn, '/');
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
if (!@ftp_mkdir($this->_conn, $path)) {
$ret = false;
break;
} else {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
@ftp_chmod($this->_conn, $mode, $path);
}
}
Expand All @@ -98,6 +104,7 @@ public function mkdirRecursive($path, $mode = 0777)
public function login($login = 'anonymous', $password = '[email protected]')
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
$res = @ftp_login($this->_conn, $login, $password);
if (!$res) {
throw new Exception('Invalid login credentials');
Expand All @@ -116,6 +123,7 @@ public function login($login = 'anonymous', $password = '[email protected]')
*/
public function validateConnectionString($string)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
$data = @parse_url($string);
if (false === $data) {
throw new Exception("Connection string invalid: '{$string}'");
Expand All @@ -139,6 +147,7 @@ public function connect($string, $timeout = 900)
$params = $this->validateConnectionString($string);
$port = isset($params['port']) ? (int) $params['port'] : 21;

// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$this->_conn = ftp_connect($params['host'], $port, $timeout);

if (!$this->_conn) {
Expand Down Expand Up @@ -170,6 +179,7 @@ public function connect($string, $timeout = 900)
public function fput($remoteFile, $handle, $mode = FTP_BINARY, $startPos = 0)
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_fput($this->_conn, $remoteFile, $handle, $mode, $startPos);
}

Expand All @@ -185,6 +195,7 @@ public function fput($remoteFile, $handle, $mode = FTP_BINARY, $startPos = 0)
public function put($remoteFile, $localFile, $mode = FTP_BINARY, $startPos = 0)
{
$this->checkConnected();
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
return ftp_put($this->_conn, $remoteFile, $localFile, $mode, $startPos);
}

Expand Down Expand Up @@ -221,6 +232,7 @@ public function getcwd()
public function raw($cmd)
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_raw($this->_conn, $cmd);
}

Expand All @@ -240,17 +252,21 @@ public function upload($remote, $local, $dirMode = 0777, $ftpMode = FTP_BINARY)
{
$this->checkConnected();

// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if (!file_exists($local)) {
throw new Exception("Local file doesn't exist: {$local}");
}
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if (!is_readable($local)) {
throw new Exception("Local file is not readable: {$local}");
}
// phpcs:ignore Ecg.Security.DiscouragedFunction.Discouraged
if (is_dir($local)) {
throw new Exception("Directory given instead of file: {$local}");
}

$globalPathMode = substr($remote, 0, 1) == '/';
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$dirname = dirname($remote);
$cwd = $this->getcwd();
if (false === $cwd) {
Expand Down Expand Up @@ -295,6 +311,7 @@ public function download($remote, $local, $ftpMode = FTP_BINARY)
public function pasv($pasv)
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_pasv($this->_conn, (bool) $pasv);
}

Expand All @@ -308,6 +325,7 @@ public function pasv($pasv)
public function close()
{
if ($this->_conn) {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
@ftp_close($this->_conn);
}
}
Expand All @@ -324,6 +342,7 @@ public function close()
public function chmod($mode, $remoteFile)
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_chmod($this->_conn, $mode, $remoteFile);
}

Expand All @@ -338,6 +357,7 @@ public function chmod($mode, $remoteFile)
public function chdir($dir)
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_chdir($this->_conn, $dir);
}

Expand All @@ -351,6 +371,7 @@ public function chdir($dir)
public function cdup()
{
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_cdup($this->_conn);
}

Expand All @@ -369,6 +390,7 @@ public function get($localFile, $remoteFile, $fileMode = FTP_BINARY, $resumeOffs
{
$remoteFile = $this->correctFilePath($remoteFile);
$this->checkConnected();
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_get($this->_conn, $localFile, $remoteFile, $fileMode, $resumeOffset);
}

Expand All @@ -384,6 +406,7 @@ public function nlist($dir = '/')
{
$this->checkConnected();
$dir = $this->correctFilePath($dir);
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_nlist($this->_conn, $dir);
}

Expand All @@ -400,6 +423,7 @@ public function rawlist($dir = '/', $recursive = false)
{
$this->checkConnected();
$dir = $this->correctFilePath($dir);
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_rawlist($this->_conn, $dir, $recursive);
}

Expand Down Expand Up @@ -442,7 +466,9 @@ public function fileExists($path, $excludeIfIsDir = true)
$path = $this->correctFilePath($path);
$globalPathMode = substr($path, 0, 1) == '/';

// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$file = basename($path);
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$dir = $globalPathMode ? dirname($path) : $this->getcwd() . '/' . $path;
$data = $this->ls($dir);
foreach ($data as $row) {
Expand Down Expand Up @@ -521,6 +547,7 @@ public function delete($file)
{
$this->checkConnected();
$file = $this->correctFilePath($file);
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_delete($this->_conn, $file);
}
}
25 changes: 25 additions & 0 deletions lib/Varien/Io/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,26 @@ public function open(array $args = [])
$this->_config = $args;

if (empty($this->_config['ssl'])) {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
$this->_conn = @ftp_connect($this->_config['host'], $this->_config['port'], $this->_config['timeout']);
} else {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
$this->_conn = @ftp_ssl_connect($this->_config['host'], $this->_config['port'], $this->_config['timeout']);
}
if (!$this->_conn) {
$this->_error = self::ERROR_INVALID_CONNECTION;
throw new Varien_Io_Exception('Could not establish FTP connection, invalid host or port');
}

// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
if (!@ftp_login($this->_conn, $this->_config['user'], $this->_config['password'])) {
$this->_error = self::ERROR_INVALID_LOGIN;
$this->close();
throw new Varien_Io_Exception('Invalid user name or password');
}

if (!empty($this->_config['path'])) {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
if (!@ftp_chdir($this->_conn, $this->_config['path'])) {
$this->_error = self::ERROR_INVALID_PATH;
$this->close();
Expand All @@ -124,6 +128,7 @@ public function open(array $args = [])
}

if (!empty($this->_config['passive'])) {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
if (!@ftp_pasv($this->_conn, true)) {
$this->_error = self::ERROR_INVALID_MODE;
$this->close();
Expand All @@ -143,6 +148,7 @@ public function open(array $args = [])
*/
public function close()
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_close($this->_conn);
}

Expand All @@ -157,8 +163,10 @@ public function close()
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
public function mkdir($dir, $mode = 0777, $recursive = true)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_mkdir($this->_conn, $dir);
}

Expand All @@ -170,8 +178,10 @@ public function mkdir($dir, $mode = 0777, $recursive = true)
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
public function rmdir($dir, $recursive = false)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_rmdir($this->_conn, $dir);
}

Expand All @@ -184,6 +194,7 @@ public function rmdir($dir, $recursive = false)
*/
public function pwd()
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_pwd($this->_conn);
}

Expand All @@ -197,6 +208,7 @@ public function pwd()
*/
public function cd($dir)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_chdir($this->_conn, $dir);
}

Expand All @@ -210,6 +222,7 @@ public function cd($dir)
public function read($filename, $dest = null)
{
if (is_string($dest)) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$result = ftp_get($this->_conn, $dest, $filename, $this->_config['file_mode']);
} else {
if (is_resource($dest)) {
Expand All @@ -221,11 +234,13 @@ public function read($filename, $dest = null)
return false;
}

// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$result = ftp_fget($this->_conn, $stream, $filename, $this->_config['file_mode']);

if (is_null($dest)) {
fseek($stream, 0);
$result = '';
// phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed,Ecg.Security.ForbiddenFunction.Found
for ($result = ''; $s = fread($stream, 4096); $result .= $s);
fclose($stream);
}
Expand All @@ -242,9 +257,12 @@ public function read($filename, $dest = null)
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
public function write($filename, $src, $mode = null)
{
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if (is_string($src) && is_readable($src)) {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_put($this->_conn, $filename, $src, $this->_config['file_mode']);
} else {
if (is_string($src)) {
Expand All @@ -258,6 +276,7 @@ public function write($filename, $src, $mode = null)
return false;
}

// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$result = ftp_fput($this->_conn, $filename, $stream, $this->_config['file_mode']);
if (is_string($src)) {
fclose($stream);
Expand All @@ -276,6 +295,7 @@ public function write($filename, $src, $mode = null)
*/
public function rm($filename)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_delete($this->_conn, $filename);
}

Expand All @@ -290,6 +310,7 @@ public function rm($filename)
*/
public function mv($src, $dest)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_rename($this->_conn, $src, $dest);
}

Expand All @@ -304,14 +325,17 @@ public function mv($src, $dest)
*/
public function chmod($filename, $mode)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
return @ftp_chmod($this->_conn, $mode, $filename);
}

/**
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
public function ls($grep = null)
{
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
$ls = @ftp_nlist($this->_conn, '.');

$list = [];
Expand All @@ -328,6 +352,7 @@ public function ls($grep = null)
protected function _tmpFilename($new = false)
{
if ($new || !$this->_tmpFilename) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$this->_tmpFilename = tempnam(md5(uniqid(rand(), true)), '');
}
return $this->_tmpFilename;
Expand Down
Loading