Skip to content

Update to 2.10.3 #1

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

Open
wants to merge 2 commits into
base: 2.9.x
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion mftp/README/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MONSTA FTP TERMS & CONDITIONS
ONSTA FTP TERMS & CONDITIONS

1. PREAMBLE

Expand Down
2 changes: 1 addition & 1 deletion mftp/application/api/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.1
2.10.3
2 changes: 1 addition & 1 deletion mftp/application/api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

try {
$request = json_decode($_POST['request'], true);

if ($request['actionName'] == 'fetchFile' || $request['actionName'] == 'downloadMultipleFiles') {
switch ($request['actionName']) {
case 'fetchFile':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public function getConfiguration($connectionType, $rawConfiguration = null) {
return self::getFTPConfiguration($rawConfiguration);
case 'sftp':
return self::getSFTPConfiguration($rawConfiguration);
case '':
case null:
return self::getFTPConfiguration($rawConfiguration);
default:
throw new InvalidArgumentException("Unknown connection type '$connectionType' in getConfiguration");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require_once(dirname(__FILE__) . "/../../lib/helpers.php");
require_once(dirname(__FILE__) . "/ConnectionFactory.php");
require_once(dirname(__FILE__) . "/../../vendor/autoload.php");
require_once(dirname(__FILE__) . "/ArchiveExtractor.php");

use \wapmorgan\UnifiedArchive\UnifiedArchive;

Expand Down
53 changes: 36 additions & 17 deletions mftp/application/api/file_sources/connection/ConnectionBase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
require_once(dirname(__FILE__) . "/../../lib/helpers.php");
require_once(dirname(__FILE__) . "/../../lib/logging.php");
require_once(dirname(__FILE__) . '/../Validation.php');
require_once(dirname(__FILE__) . '/../PathOperations.php');
require_once(dirname(__FILE__) . '/RecursiveFileFinder.php');
Expand Down Expand Up @@ -184,7 +185,7 @@ public function getProtocolName() {
}

protected function getLastError() {
if(!is_null($this->lastError)) {
if (!is_null($this->lastError)) {
$lastError = $this->lastError;
$this->lastError = null;
return $lastError;
Expand Down Expand Up @@ -463,10 +464,13 @@ public function deleteMultiple($remotePathsAndTypes) {
$remotePath = $remotePathAndType[0];
$isDirectory = $remotePathAndType[1];

if ($isDirectory)
if ($isDirectory) {
$this->deleteDirectory($remotePath);
else
mftpActionLog("Delete directory", $this, dirname($remotePath), monstaBasename($remotePath), "");
} else {
$this->deleteFile($remotePath);
mftpActionLog("Delete file", $this, dirname($remotePath), monstaBasename($remotePath), "");
}
}
}

Expand Down Expand Up @@ -502,8 +506,26 @@ public function changePermissions($mode, $remotePath) {

Validation::validatePermissionMask($mode, false);

if (!$this->handleChangePermissions($mode, $remotePath))
$this->handleOperationError('CHANGE_PERMISSIONS_OPERATION', $remotePath, $this->getLastError());
if (!$this->handleChangePermissions($mode, $remotePath)) {
//$this->handleOperationError('CHANGE_PERMISSIONS_OPERATION', $remotePath, $this->getLastError());
}
}

/**
* @param $path
* @return bool
*/
public function isDirectory($path) {
$this->ensureConnectedAndAuthenticated('IS_DIRECTORY');

try {
$this->listDirectory($path);
return true;
} catch (Exception $e) {
// failure should just means it's a file
}

return false;
}

/**
Expand All @@ -515,25 +537,22 @@ public function changePermissions($mode, $remotePath) {
public function copy($source, $destination) {
$this->ensureConnectedAndAuthenticated('COPY_OPERATION');

$isDirectory = false;

$newPermissions = array();
/*
do the permissions update at the end, otherwise the copy may fail if a parent directory is made unreadable
store the dest permissions here
*/

try {
$this->listDirectory($source);
$isDirectory = true;
} catch (Exception $e) {
// failure just means it's a file
}
$isDirectory = $this->isDirectory($source);

if (!$isDirectory) {
//mftpActionLog("Copy file", $this->connection, dirname($source), monstaBasename($source) . " to " . $destination, "");

$sources = array(array($source, null));
$destinations = array($destination);
} else {
//mftpActionLog("Copy folder", $this->connection, dirname($source), monstaBasename($source) . " to " . $destination, "");
$fileFinder = new RecursiveFileFinder($this, $source);
$sources = $fileFinder->findFilesAndDirectoriesInPaths();
$destinations = array();
Expand Down Expand Up @@ -654,7 +673,7 @@ protected function handleFetchServerCapabilities() {
}

protected function getCapabilitiesArrayValue($capabilitiesKey) {
if(is_null($this->serverCapabilitiesArray)) {
if (is_null($this->serverCapabilitiesArray)) {
return null;
}

Expand All @@ -663,17 +682,17 @@ protected function getCapabilitiesArrayValue($capabilitiesKey) {
}

private function populateServerCapabilitiesArray() {
$serverCapabilities = new ServerCapabilities(PathOperations::join(MONSTA_CONFIG_DIR_PATH , "server_capabilities.php"));
$serverCapabilities = new ServerCapabilities(PathOperations::join(MONSTA_CONFIG_DIR_PATH, "server_capabilities.php"));

$capabilitiesArray = $serverCapabilities->getServerCapabilities($this->getProtocolName(),
$this->configuration->getHost(), $this->configuration->getPort());

if(is_null($capabilitiesArray)) {
if (is_null($capabilitiesArray)) {
$capabilitiesArray = $this->handleFetchServerCapabilities();

if(!is_null($capabilitiesArray)) {
if (!is_null($capabilitiesArray)) {
$serverCapabilities->setServerCapabilities($this->getProtocolName(),
$this->configuration->getHost(), $this->configuration->getPort(), $capabilitiesArray);
$this->configuration->getHost(), $this->configuration->getPort(), $capabilitiesArray);
}
}

Expand Down
71 changes: 31 additions & 40 deletions mftp/application/api/file_sources/connection/MockConnection.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<?php

require_once(dirname(__FILE__) . '/ConnectionBase.php');
require_once(dirname(__FILE__) . '/../connection/StatOutputListItem.php');

class MockStatOutputListItem extends StatOutputListItem {
public function __construct($name, $fileStat) {
parent::__construct($name, $fileStat);
if($name == 'src')
$this->link = true;
}

}
require_once(dirname(__FILE__) . '/MockStatOutputListItem.php');

class MockConnection extends ConnectionBase {
protected $protocolName = 'Mock';
Expand Down Expand Up @@ -137,20 +128,20 @@ class MockConnection extends ConnectionBase {

private $localFixturesList = array(
array(
"name" => "perm-update",
"dev" => 16777220,
"ino" => 34731845,
"mode" => 0666,
"nlink" => 1,
"uid" => 501,
"gid" => 20,
"rdev" => 0,
"size" => 17,
"atime" => 1464002544,
"mtime" => 1458871912,
"ctime" => 1458871912,
"blksize" => 4096,
"blocks" => 8
"name" => "perm-update",
"dev" => 16777220,
"ino" => 34731845,
"mode" => 0666,
"nlink" => 1,
"uid" => 501,
"gid" => 20,
"rdev" => 0,
"size" => 17,
"atime" => 1464002544,
"mtime" => 1458871912,
"ctime" => 1458871912,
"blksize" => 4096,
"blocks" => 8
)
);

Expand Down Expand Up @@ -179,20 +170,20 @@ protected function handleAuthentication() {
$mockUsernameLength = strlen(MOCK_DEFAULT_USERNAME);

return substr($this->configuration->getUsername(), 0, $mockUsernameLength) == MOCK_DEFAULT_USERNAME
&& $this->configuration->getPassword() == MOCK_DEFAULT_PASSWORD;
&& $this->configuration->getPassword() == MOCK_DEFAULT_PASSWORD;
}

protected function postAuthentication() {
// pass
}

protected function handleListDirectory($path, $showHidden) {
if($path == "/to-copy")
if ($path == "/to-copy")
throw new Exception("This is not a directory");

$dirList = array();

if($path == '/local-fixtures/')
if ($path == '/local-fixtures/')
$dirSource = $this->localFixturesList;
else
$dirSource = $this->linkedFixturesList;
Expand Down Expand Up @@ -223,20 +214,20 @@ protected function handleDownloadFile($transferOperation) {
}

protected function handleUploadFile($transferOperation) {
if($transferOperation->getRemotePath() == '/local-fixtures/no-perms') {
if ($transferOperation->getRemotePath() == '/local-fixtures/no-perms') {
$this->setPermissionDeniedError();
return false;
}

$fileContents = @file_get_contents($transferOperation->getLocalPath());
if($fileContents === FALSE)
if ($fileContents === FALSE)
return FALSE;
$this->fixtures[$transferOperation->getRemotePath()] = $fileContents;
return true;
}

protected function handleDeleteFile($remotePath) {
if($remotePath == '/local-fixtures/readonly/file') {
if ($remotePath == '/local-fixtures/readonly/file') {
$this->setPermissionDeniedError();
return false;
}
Expand All @@ -254,7 +245,7 @@ protected function handleMakeDirectory($remotePath) {
return false;
}

if ($remotePath == "/local-fixtures"){
if ($remotePath == "/local-fixtures") {
@trigger_error("File exists");
return false;
}
Expand All @@ -263,12 +254,12 @@ protected function handleMakeDirectory($remotePath) {
}

protected function handleDeleteDirectory($remotePath) {
if($remotePath == '/idontexist') {
if ($remotePath == '/idontexist') {
$this->checkFileNotFound($remotePath);
return false;
}

if($remotePath == '/local-fixtures/readonly/directory') {
if ($remotePath == '/local-fixtures/readonly/directory') {
$this->setPermissionDeniedError();
return false;
}
Expand All @@ -278,7 +269,7 @@ protected function handleDeleteDirectory($remotePath) {

protected function handleRename($source, $destination) {
$res = $this->handleCopy($source, $destination);
if($res === false)
if ($res === false)
return false;
unset($this->fixtures[$source]);
return true;
Expand All @@ -290,21 +281,21 @@ protected function handleChangePermissions($mode, $remotePath) {
return false;
}

if($remotePath == '/local-fixtures/perm-update')
if ($remotePath == '/local-fixtures/perm-update')
$this->localFixturesList[0]['mode'] = $mode;
else if(!$this->checkFileNotFound($remotePath))
else if (!$this->checkFileNotFound($remotePath))
return false;

return true;
}

protected function handleCopy($source, $destination) {
if($source == '/local-fixtures/readonly/file') {
if ($source == '/local-fixtures/readonly/file') {
$this->setPermissionDeniedError();
return false;
}

if(!$this->checkFileNotFound($source))
if (!$this->checkFileNotFound($source))
return false;

$contents = $this->fixtures[$source];
Expand All @@ -314,9 +305,9 @@ protected function handleCopy($source, $destination) {

public function deleteDirectory($remotePath) {
$this->ensureConnectedAndAuthenticated('DELETE_DIRECTORY_OPERATION');
if(!$this->handleDeleteDirectory($remotePath))
if (!$this->handleDeleteDirectory($remotePath))
$this->handleOperationError('DELETE_DIRECTORY_OPERATION', $remotePath, $this->getLastError());

}

private function setPermissionDeniedError() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require_once(dirname(__FILE__) . '/StatOutputListItem.php');


class MockStatOutputListItem extends StatOutputListItem {
public function __construct($name, $fileStat) {
parent::__construct($name, $fileStat);
if ($name == 'src')
$this->link = true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ protected function handleUploadFile($transferOperation) {
mftpLog(LOG_WARNING, "SFTPSecLib failed to put '{$transferOperation->getRemotePath()}' to '{$transferOperation->getLocalPath()}': {$this->lastError['message']}");
}

if ($transferSuccess && !is_null($transferOperation->getCreateMode()))
$this->changePermissions($transferOperation->getCreateMode(), $transferOperation->getRemotePath());
if (method_exists($transferOperation, 'getCreateMode')) {
if ( $transferSuccess && !is_null($transferOperation->getCreateMode()) ) {
$this->changePermissions($transferOperation->getCreateMode(), $transferOperation->getRemotePath());
}
}

return $transferSuccess;
}
Expand Down Expand Up @@ -104,7 +107,7 @@ protected function handleMakeDirectory($remotePath) {
}

protected function handleDeleteDirectory($remotePath) {
$deleteSuccess = $this->connection->delete($remotePath, true);
$deleteSuccess = $this->connection->rmdir($remotePath);

if ($deleteSuccess)
mftpLog(LOG_DEBUG, "SFTPSecLib deleted directory '$remotePath'");
Expand Down Expand Up @@ -147,7 +150,6 @@ protected function statRemoteFile($remotePath) {
}

protected function authenticateByPassword() {
// TODO: Implement authenticateByPassword() method.
$authSuccess = $this->connection->login($this->configuration->getRemoteUsername(),
$this->configuration->getPassword());

Expand Down
15 changes: 13 additions & 2 deletions mftp/application/api/file_sources/connection/PHPSeclibListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ public function __construct($itemName, $itemStat) {
$this->groupPermissions = new IntegerPermissionSet(($permissionBits >> 3) & 0x7);
$this->otherPermissions = new IntegerPermissionSet($permissionBits & 0x7);
$this->linkCount = null;
$this->ownerUserName = isset($itemStat['uid']) ? $itemStat['uid'] : null;
$this->ownerGroupName = isset($itemStat['gid']) ? $itemStat['gid'] : null;

if (isset($itemStat['uname'])) {
$this->ownerUserName = $itemStat['uname'];
} else {
$this->ownerUserName = isset($itemStat['uid']) ? $itemStat['uid'] : null;
}

if (isset($itemStat['gname'])) {
$this->ownerGroupName = $itemStat['gname'];
} else {
$this->ownerGroupName = isset($itemStat['gid']) ? $itemStat['gid'] : null;
}

$this->size = isset($itemStat['size']) ? $itemStat['size'] : 0;
$this->modificationDate = $itemStat['mtime'];
}
Expand Down
Loading