-
Notifications
You must be signed in to change notification settings - Fork 3
/
connector-dist.php
115 lines (97 loc) · 3.84 KB
/
connector-dist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
error_reporting(0); // Set E_ALL for debuging
define('ELFINDER_TMB_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'.tmb');
define('ELFINDER_TMP_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'.tmp');
// ELFINDER CORE
include_once dirname(__FILE__).DIRECTORY_SEPARATOR. 'php' .DIRECTORY_SEPARATOR.'elFinderConnector.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR. 'php' .DIRECTORY_SEPARATOR.'elFinder.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR. 'php' .DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR. 'php' .DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR. 'php' .DIRECTORY_SEPARATOR.'elFinderVolumeSFTP.class.php';
// PCLZIP LIB
require dirname(__FILE__). DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'pclzip' . DIRECTORY_SEPARATOR . 'pclzip.lib.php';
// PHPSECLIB
require dirname(__FILE__). DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'phpseclib' . DIRECTORY_SEPARATOR . 'SSH2.php';
require dirname(__FILE__). DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'phpseclib' . DIRECTORY_SEPARATOR . 'SFTP.php';
require dirname(__FILE__). DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . 'phpseclib' . DIRECTORY_SEPARATOR . 'SFTP_StreamWrapper.php';
/**
* Simple function to demonstrate how to control file access using "accessControl" callback.
* This method will disable accessing files/folders starting from '.' (dot) AND SYMLINKS
*
* @param string $attr attribute name (read|write|locked|hidden)
* @param string $path file path relative to volume root directory started with directory separator
* @return bool|null
**/
function access($attr, $path, $data, $volume) {
return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot)
|| is_link($path) // Disable symlinks
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
: null; // else elFinder decide it itself
}
/**
* Copy a file, or recursively copy a folder and its contents
* @param string $source Source path
* @param string $dest Destination path
* @param string $permissions New folder creation permissions
* @return bool Returns true on success, false on failure
*/
function xcopy($source, $dest, $permissions = 0755)
{
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
}
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest, $permissions);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
xcopy("$source/$entry", "$dest/$entry");
}
// Clean up
$dir->close();
return true;
}
/**
* http://php.net/manual/en/function.rmdir.php#98622
*/
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
$opts = array(
'roots' => array(
array(
'driver' => 'SFTP',
'alias' => 'Remote-FS',
'path' => 'sftp://user:pass@ip:22/home/user',
'separator' => '/',
'accessControl' => 'access',
'tmbPath' => ELFINDER_TMB_PATH,
'tmpPath' => ELFINDER_TMP_PATH
)
)
);
// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();
?>