Skip to content

Commit

Permalink
Merge pull request Studio-42#673 from mailtoartem/2.x
Browse files Browse the repository at this point in the history
Change ftp_scan_dir from 'private' to 'protected' to add ability to reim...
  • Loading branch information
dio-el-claire committed Nov 26, 2013
2 parents 40f9de2 + b69acff commit edc5b1d
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 14 deletions.
23 changes: 22 additions & 1 deletion js/commands/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,30 @@ elFinder.prototype.commands.open = function() {
w = 'width='+parseInt(2*$(window).width()/3)+',height='+parseInt(2*$(window).height()/3);
}

if (!window.open(url, '_blank', w + ',top=50,left=50,scrollbars=yes,resizable=yes')) {
var wnd = window.open('', 'new_window', w + ',top=50,left=50,scrollbars=yes,resizable=yes');
if (!wnd) {
return dfrd.reject('errPopup');
}

var form = document.createElement("form");
form.action = fm.options.url;
form.method = 'POST';
form.target = 'new_window';
form.style.display = 'none';
var params = $.extend({}, fm.options.customData, {
cmd: 'file',
target: file.hash
});
$.each(params, function(key, val)
{
var input = document.createElement("input");
input.name = key;
input.value = val;
form.appendChild(input);
});

document.body.appendChild(form);
form.submit();
}
return dfrd.resolve(hashes);
}
Expand Down
42 changes: 29 additions & 13 deletions php/elFinderVolumeFTP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,14 +981,22 @@ protected function _extract($path, $arc)
$remoteDirectory = dirname($path);
chdir($tmpDir);
$command = escapeshellcmd($arc['cmd'] . ' ' . $arc['argc'] . ' "' . $basename . '"');
exec($command, $output, $return_value);
unlink($basename);
if ($return_value != 0) {
$this->setError(elFinder::ERROR_EXTRACT_EXEC, 'Command failed '.escapeshellarg($command));
$this->deleteDir($tmpDir); //cleanup
return false;
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);


$process = proc_open($command, $descriptorspec, $pipes, $cwd);

if (is_resource($process)) {
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}

unlink($basename);
$filesToProcess = elFinderVolumeFTP::listFilesInDirectory($tmpDir, true);
if(!$filesToProcess) {
$this->setError(elFinder::ERROR_EXTRACT_EXEC, $tmpDir." is not a directory");
Expand Down Expand Up @@ -1092,12 +1100,20 @@ protected function _archive($dir, $files, $name, $arc)
$file_names_string = $file_names_string . '"' . $filename . '" ';
}
$command = escapeshellcmd($arc['cmd'] . ' ' . $arc['argc'] . ' "' . $name . '" ' . $file_names_string);

$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);

exec($command, $output, $return_value);
if ($return_value != 0) {
$this->setError(elFinder::ERROR_ARCHIVE_EXEC, 'Command failed '.escapeshellarg($command));
$this->deleteDir($tmpDir); //cleanup
return false;

$process = proc_open($command, $descriptorspec, $pipes, $cwd);

if (is_resource($process)) {
fclose($pipes[0]);
fclose($pipes[1]);
$return_value = proc_close($process);
}

$remoteArchiveFile = $dir . DIRECTORY_SEPARATOR . $name;
Expand Down Expand Up @@ -1136,7 +1152,7 @@ private function tempDir()
$this->setError(elFinder::ERROR_CREATING_TEMP_DIR, $this->tmp);
return false;
}
$success = mkdir($tempPath, 0755, true);
$success = mkdir($tempPath, 0700, true);
if (!$success) {
$this->setError(elFinder::ERROR_CREATING_TEMP_DIR, $this->tmp);
return false;
Expand All @@ -1154,7 +1170,7 @@ private function tempDir()
* <li>$item['type'] - either 'f' for file or 'd' for directory</li>
* </ul>
*/
private function ftp_scan_dir($remote_directory)
protected function ftp_scan_dir($remote_directory)
{
$buff = ftp_rawlist($this->connect, $remote_directory, true);
$next_folder = false;
Expand Down
134 changes: 134 additions & 0 deletions php/elFinderVolumeFTPIIS.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

/**
* Simple elFinder driver for IIS FTP
*
**/
class elFinderVolumeFTPIIS extends elFinderVolumeFTP {

/**
* Connect to ftp server
*
* @return bool
**/
protected function connect() {
if (!($this->connect = ftp_connect($this->options['host'], $this->options['port'], $this->options['timeout']))) {
return $this->setError('Unable to connect to FTP server '.$this->options['host']);
}
if (!ftp_login($this->connect, $this->options['user'], $this->options['pass'])) {
$this->umount();
return $this->setError('Unable to login into '.$this->options['host']);
}

// switch off extended passive mode - may be usefull for some servers
//@ftp_exec($this->connect, 'epsv4 off' );
// enter passive mode if required
$this->options['mode'] = 'active';
ftp_pasv($this->connect, $this->options['mode'] == 'passive');

// enter root folder
if (!ftp_chdir($this->connect, $this->root))
{
$this->umount();
return $this->setError('Unable to open root folder.');
}

$stat = array();
$stat['name'] = $this->root;
$stat['mime'] = 'directory';
$this->filesCache[$this->root] = $stat;
$this->cacheDir($this->root);

return true;
}

/**
* Parse line from ftp_rawlist() output and return file stat (array)
*
* @param string $raw line from ftp_rawlist() output
* @return array
**/
protected function parseRaw($raw) {
$info = preg_split("/\s+/", $raw, 9);
$stat = array();

$stat['name'] = join(" ", array_slice($info, 3, 9));
$stat['read'] = true;
if ($info[2] == '<DIR>')
{
$stat['size'] = 0;
$stat['mime'] = 'directory';
}
else
{
$stat['size'] = $info[2];
$stat['mime'] = $this->mimetype($stat['name']);
}

return $stat;
}

/**
* Cache dir contents
*
* @param string $path dir path
* @return void
**/
protected function cacheDir($path) {
$this->dirsCache[$path] = array();

if (preg_match('/\'|\"/', $path)) {
foreach (ftp_nlist($this->connect, $path) as $p) {
if (($stat = $this->_stat($p)) &&empty($stat['hidden'])) {
// $files[] = $stat;
$this->dirsCache[$path][] = $p;
}
}
return;
}
foreach (ftp_rawlist($this->connect, $path) as $raw) {
if (($stat = $this->parseRaw($raw))) {
$p = $path.DIRECTORY_SEPARATOR.$stat['name'];
// $files[] = $stat;
$this->dirsCache[$path][] = $p;
//$stat['name'] = $p;
$this->filesCache[$p] = $stat;
}
}
}

protected function _stat($path) {
$stat = array();

$stat = $this->filesCache[$path];

if (empty($stat))
{
$this->cacheDir($this->_dirname($path));
$stat = $this->filesCache[$path];

}

return $stat;
}


protected function ftp_scan_dir($remote_directory)
{
$buff = ftp_rawlist($this->connect, $remote_directory, true);
$items = array();
foreach ($buff as $str) {
$info = preg_split("/\s+/", $str, 9);
$remote_file_path = $remote_directory . DIRECTORY_SEPARATOR . join(" ", array_slice($info, 3, 9));
$item = array();
$item['type'] = $info[2] == '<DIR>' ? 'd' : 'f';
$item['path'] = $remote_file_path;
$items[] = $item;

if ($item['type'] == 'd')
$items = array_merge($items, $this->ftp_scan_dir($item['path']));
}
return $items;
}
} // END class

0 comments on commit edc5b1d

Please sign in to comment.