Skip to content

Commit

Permalink
[php] Update elFinderVolumeSFTPphpseclib.class.php (#3483)
Browse files Browse the repository at this point in the history
Currently, this class does not work with symlinks at all.  Permissions also don't work properly.  Using Flysystem is not an option for me because that requires PHP v8.  I ended up creating my own `SFTP3phpseclib.class.php`.  I have edited this file with some of the changes I made to get symlinks sort of working.  I am still testing it so this is just a start.  It took me a long time to figure out how to get symlinks to show up so maybe this will help others struggling with this.  I am using phpseclib v3 so I only tested these changes with that library.

I made a bunch of changes to get permissions working properly.  I may include that in a separate pull request after I test it more.
  • Loading branch information
sdwru authored Aug 26, 2022
1 parent f0e372c commit cfc0b3b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions php/elFinderVolumeSFTPphpseclib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,13 @@ protected function parseRaw($raw, $base, $nameOnly = false)

$name = $info['filename'];

if (preg_match('|(.+)\-\>(.+)|', $name, $m)) {
$name = trim($m[1]);
if ($info['type'] === 3)) {
// check recursive processing
if ($this->cacheDirTarget && $this->_joinPath($base, $name) !== $this->cacheDirTarget) {
return array();
}
if (!$nameOnly) {
$target = trim($m[2]);
$target = $this->connect->readlink($name);
if (substr($target, 0, 1) !== $this->separator) {
$target = $this->getFullPath($target, $base);
}
Expand All @@ -281,8 +280,19 @@ protected function parseRaw($raw, $base, $nameOnly = false)
$owner_computed = isset($stat['isowner']) ? $stat['isowner'] : $this->options['owner'];
$perm = $this->parsePermissions($info['permissions'], $owner_computed);
$stat['name'] = $name;
$stat['mime'] = $info['type'] == NET_SFTP_TYPE_DIRECTORY ? 'directory' : $this->mimetype($stat['name'], true);
$stat['size'] = $stat['mime'] == 'directory' ? 0 : $info['size'];
if ($info['type'] === NET_SFTP_TYPE_DIRECTORY) {
$stat['mime'] = 'directory';
$stat['size'] = 0;

} elseif ($info['type'] === NET_SFTP_TYPE_SYMLINK) {
$stat['mime'] = 'symlink';
$stat['size'] = 0;

} else {
$stat['mime'] = $this->mimetype($stat['name'], true);
$stat['size'] = $info['size'];
}

$stat['read'] = $perm['read'];
$stat['write'] = $perm['write'];

Expand Down Expand Up @@ -347,6 +357,8 @@ protected function cacheDir($path)
if (empty($stat['hidden'])) {
if (!$hasDir && $stat['mime'] === 'directory') {
$hasDir = true;
} elseif (!$hasDir && $stat['mime'] === 'symlink') {
$hasDir = true;
}
$this->dirsCache[$path][] = $p;
}
Expand Down Expand Up @@ -520,6 +532,9 @@ protected function _subdirs($path)
if ($name && $name !== '.' && $name !== '..' && $info['type'] == NET_SFTP_TYPE_DIRECTORY) {
return true;
}
if ($name && $name !== '.' && $name !== '..' && $info['type'] == NET_SFTP_TYPE_SYMLINK) {
//return true;
}
}

return false;
Expand Down

0 comments on commit cfc0b3b

Please sign in to comment.