connector.maximal.php-dist 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?php
  2. error_reporting(0); // Set E_ALL for debuging
  3. // // Optional exec path settings (Default is called with command name only)
  4. // define('ELFINDER_TAR_PATH', '/PATH/TO/tar');
  5. // define('ELFINDER_GZIP_PATH', '/PATH/TO/gzip');
  6. // define('ELFINDER_BZIP2_PATH', '/PATH/TO/bzip2');
  7. // define('ELFINDER_XZ_PATH', '/PATH/TO/xz');
  8. // define('ELFINDER_ZIP_PATH', '/PATH/TO/zip');
  9. // define('ELFINDER_UNZIP_PATH', '/PATH/TO/unzip');
  10. // define('ELFINDER_RAR_PATH', '/PATH/TO/rar');
  11. // define('ELFINDER_UNRAR_PATH', '/PATH/TO/unrar');
  12. // define('ELFINDER_7Z_PATH', '/PATH/TO/7za');
  13. // define('ELFINDER_CONVERT_PATH', '/PATH/TO/convert');
  14. // define('ELFINDER_IDENTIFY_PATH', '/PATH/TO/identify');
  15. // define('ELFINDER_EXIFTRAN_PATH', '/PATH/TO/exiftran');
  16. // define('ELFINDER_JPEGTRAN_PATH', '/PATH/TO/jpegtran');
  17. // define('ELFINDER_FFMPEG_PATH', '/PATH/TO/ffmpeg');
  18. // define('ELFINDER_CONNECTOR_URL', 'URL to this connector script'); // see elFinder::getConnectorUrl()
  19. // define('ELFINDER_DEBUG_ERRORLEVEL', -1); // Error reporting level of debug mode
  20. // // To Enable(true) handling of PostScript files by ImageMagick
  21. // // It is disabled by default as a countermeasure
  22. // // of Ghostscript multiple -dSAFER sandbox bypass vulnerabilities
  23. // // see https://www.kb.cert.org/vuls/id/332928
  24. // define('ELFINDER_IMAGEMAGICK_PS', true);
  25. // ===============================================
  26. // // load composer autoload before load elFinder autoload If you need composer
  27. // // You need to run the composer command in the php directory.
  28. is_readable('./vendor/autoload.php') && require './vendor/autoload.php';
  29. // // elFinder autoload
  30. require './autoload.php';
  31. // ===============================================
  32. // // Enable FTP connector netmount
  33. elFinder::$netDrivers['ftp'] = 'FTP';
  34. // ===============================================
  35. // // Required for Dropbox network mount
  36. // // Installation by composer
  37. // // `composer require kunalvarma05/dropbox-php-sdk` on php directory
  38. // // Enable network mount
  39. // elFinder::$netDrivers['dropbox2'] = 'Dropbox2';
  40. // // Dropbox2 Netmount driver need next two settings. You can get at https://www.dropbox.com/developers/apps
  41. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=dropbox2&host=1"
  42. // define('ELFINDER_DROPBOX_APPKEY', '');
  43. // define('ELFINDER_DROPBOX_APPSECRET', '');
  44. // ===============================================
  45. // // Required for Google Drive network mount
  46. // // Installation by composer
  47. // // `composer require google/apiclient:^2.0` on php directory
  48. // // Enable network mount
  49. // elFinder::$netDrivers['googledrive'] = 'GoogleDrive';
  50. // // GoogleDrive Netmount driver need next two settings. You can get at https://console.developers.google.com
  51. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=googledrive&host=1"
  52. // define('ELFINDER_GOOGLEDRIVE_CLIENTID', '');
  53. // define('ELFINDER_GOOGLEDRIVE_CLIENTSECRET', '');
  54. // // Required case when Google API is NOT added via composer
  55. // define('ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT', '/path/to/google-api-php-client/vendor/autoload.php');
  56. // ===============================================
  57. // // Required for Google Drive network mount with Flysystem
  58. // // Installation by composer
  59. // // `composer require nao-pon/flysystem-google-drive:~1.1 nao-pon/elfinder-flysystem-driver-ext` on php directory
  60. // // Enable network mount
  61. // elFinder::$netDrivers['googledrive'] = 'FlysystemGoogleDriveNetmount';
  62. // // GoogleDrive Netmount driver need next two settings. You can get at https://console.developers.google.com
  63. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=googledrive&host=1"
  64. // define('ELFINDER_GOOGLEDRIVE_CLIENTID', '');
  65. // define('ELFINDER_GOOGLEDRIVE_CLIENTSECRET', '');
  66. // // And "php/.tmp" directory must exist and be writable by PHP.
  67. // ===============================================
  68. // // Required for One Drive network mount
  69. // // * cURL PHP extension required
  70. // // * HTTP server PATH_INFO supports required
  71. // // Enable network mount
  72. // elFinder::$netDrivers['onedrive'] = 'OneDrive';
  73. // // GoogleDrive Netmount driver need next two settings. You can get at https://dev.onedrive.com
  74. // // AND require register redirect url to "YOUR_CONNECTOR_URL/netmount/onedrive/1"
  75. // define('ELFINDER_ONEDRIVE_CLIENTID', '');
  76. // define('ELFINDER_ONEDRIVE_CLIENTSECRET', '');
  77. // ===============================================
  78. // // Required for Box network mount
  79. // // * cURL PHP extension required
  80. // // Enable network mount
  81. // elFinder::$netDrivers['box'] = 'Box';
  82. // // Box Netmount driver need next two settings. You can get at https://developer.box.com
  83. // // AND require register redirect url to "YOUR_CONNECTOR_URL?cmd=netmount&protocol=box&host=1"
  84. // define('ELFINDER_BOX_CLIENTID', '');
  85. // define('ELFINDER_BOX_CLIENTSECRET', '');
  86. // ===============================================
  87. // // Zoho Office Editor APIKey
  88. // // https://www.zoho.com/docs/help/office-apis.html
  89. // define('ELFINDER_ZOHO_OFFICE_APIKEY', '');
  90. // ===============================================
  91. // // Online converter (online-convert.com) APIKey
  92. // // https://apiv2.online-convert.com/docs/getting_started/api_key.html
  93. // define('ELFINDER_ONLINE_CONVERT_APIKEY', '');
  94. // ===============================================
  95. // // Zip Archive editor
  96. // // Installation by composer
  97. // // `composer require nao-pon/elfinder-flysystem-ziparchive-netmount` on php directory
  98. // define('ELFINDER_DISABLE_ZIPEDITOR', false); // set `true` to disable zip editor
  99. // ===============================================
  100. /**
  101. * Simple function to demonstrate how to control file access using "accessControl" callback.
  102. * This method will disable accessing files/folders starting from '.' (dot)
  103. *
  104. * @param string $attr attribute name (read|write|locked|hidden)
  105. * @param string $path absolute file path
  106. * @param string $data value of volume option `accessControlData`
  107. * @param object $volume elFinder volume driver object
  108. * @param bool|null $isDir path is directory (true: directory, false: file, null: unknown)
  109. * @param string $relpath file path relative to volume root directory started with directory separator
  110. * @return bool|null
  111. **/
  112. function access($attr, $path, $data, $volume, $isDir, $relpath) {
  113. $basename = basename($path);
  114. return $basename[0] === '.' // if file/folder begins with '.' (dot)
  115. && strlen($relpath) !== 1 // but with out volume root
  116. ? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
  117. : null; // else elFinder decide it itself
  118. }
  119. /**
  120. * Simple debug function
  121. * Usage: debug($anyVal[, $anyVal2 ...]);
  122. */
  123. function debug() {
  124. $arg = func_get_args();
  125. ob_start();
  126. foreach($arg as $v) {
  127. var_dump($v);
  128. }
  129. $o = ob_get_contents();
  130. ob_end_clean();
  131. file_put_contents('.debug.txt', $o, FILE_APPEND);
  132. }
  133. /**
  134. * Simple logger function.
  135. * Demonstrate how to work with elFinder event api.
  136. *
  137. * @package elFinder
  138. * @author Dmitry (dio) Levashov
  139. **/
  140. class elFinderSimpleLogger {
  141. /**
  142. * Log file path
  143. *
  144. * @var string
  145. **/
  146. protected $file = '';
  147. /**
  148. * constructor
  149. *
  150. * @return void
  151. * @author Dmitry (dio) Levashov
  152. **/
  153. public function __construct($path)
  154. {
  155. $this->file = $path;
  156. $dir = dirname($path);
  157. if (!is_dir($dir)) {
  158. mkdir($dir);
  159. }
  160. }
  161. /**
  162. * Create log record
  163. *
  164. * @param string $cmd command name
  165. * @param array $result command result
  166. * @param array $args command arguments from client
  167. * @param elFinder $elfinder elFinder instance
  168. * @param elFinderVolumeDriver $volume current volume driver instance
  169. * @return void|true
  170. * @author Dmitry (dio) Levashov
  171. **/
  172. public function log($cmd, $result, $args, $elfinder, $volume)
  173. {
  174. $log = $cmd.' ['.date('d.m H:s')."]\n";
  175. if (!empty($result['error'])) {
  176. $log .= "\tERROR: ".implode(' ', $result['error'])."\n";
  177. }
  178. if (!empty($result['warning'])) {
  179. $log .= "\tWARNING: ".implode(' ', $result['warning'])."\n";
  180. }
  181. if (!empty($result['removed'])) {
  182. foreach ($result['removed'] as $file) {
  183. // removed file contain additional field "realpath"
  184. $log .= "\tREMOVED: ".$file['realpath']."\n";
  185. }
  186. }
  187. if (!empty($result['added'])) {
  188. foreach ($result['added'] as $file) {
  189. $log .= "\tADDED: ".$elfinder->realpath($file['hash'])."\n";
  190. }
  191. }
  192. if (!empty($result['changed'])) {
  193. foreach ($result['changed'] as $file) {
  194. $log .= "\tCHANGED: ".$elfinder->realpath($file['hash'])."\n";
  195. }
  196. }
  197. $this->write($log);
  198. }
  199. /**
  200. * Write log into file
  201. *
  202. * @param string $log log record
  203. * @return void
  204. * @author Dmitry (dio) Levashov
  205. **/
  206. protected function write($log)
  207. {
  208. if (($fp = @fopen($this->file, 'a'))) {
  209. fwrite($fp, $log."\n");
  210. fclose($fp);
  211. }
  212. }
  213. } // END class
  214. // Make logger instance
  215. $logger = new elFinderSimpleLogger('.log.txt');
  216. // Documentation for connector options:
  217. // https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
  218. $opts = array(
  219. 'debug' => true, // enable debug mode
  220. 'roots' => array(
  221. // Items volume
  222. array(
  223. 'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
  224. 'path' => '../files/', // path to files (REQUIRED)
  225. 'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
  226. 'trashHash' => 't1_Lw', // elFinder's hash of trash folder
  227. 'winHashFix' => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
  228. 'uploadDeny' => array('all'), // All Mimetypes not allowed to upload
  229. 'uploadAllow' => array('image/x-ms-bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/x-icon', 'text/plain'), // Mimetype `image` and `text/plain` allowed to upload
  230. 'uploadOrder' => array('deny', 'allow'), // allowed Mimetype `image` and `text/plain` only
  231. 'accessControl' => 'access', // disable and hide dot starting files (OPTIONAL)
  232. 'attributes' => array( // additional thumbnail directories
  233. 'pattern' => '~^/\.tmb(?:Cloud|Netmount)$~',
  234. 'read' => false,
  235. 'write' => false,
  236. 'locked' => true,
  237. 'hidden' => true ),
  238. ),
  239. // Trash volume
  240. array(
  241. 'id' => '1',
  242. 'driver' => 'Trash',
  243. 'path' => '../files/.trash/',
  244. 'tmbURL' => dirname($_SERVER['PHP_SELF']) . '/../files/.trash/.tmb/',
  245. 'winHashFix' => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
  246. 'uploadDeny' => array('all'), // Recomend the same settings as the original volume that uses the trash
  247. 'uploadAllow' => array('image/x-ms-bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/x-icon', 'text/plain'), // Same as above
  248. 'uploadOrder' => array('deny', 'allow'), // Same as above
  249. 'accessControl' => 'access', // Same as above
  250. ),
  251. ),
  252. // some bind functions
  253. 'bind' => array(
  254. // enable logger
  255. // '*' => array($logger, 'log'),
  256. 'mkdir mkfile rename duplicate upload rm paste' => array($logger, 'log'),
  257. // enable plugins
  258. 'archive.pre ls.pre mkdir.pre mkfile.pre rename.pre upload.pre' => array(
  259. 'Plugin.Normalizer.cmdPreprocess',
  260. 'Plugin.Sanitizer.cmdPreprocess'
  261. ),
  262. 'upload.presave' => array(
  263. 'Plugin.AutoRotate.onUpLoadPreSave',
  264. 'Plugin.AutoResize.onUpLoadPreSave',
  265. 'Plugin.Watermark.onUpLoadPreSave',
  266. 'Plugin.Normalizer.onUpLoadPreSave',
  267. 'Plugin.Sanitizer.onUpLoadPreSave',
  268. ),
  269. ),
  270. // volume options of netmount volumes
  271. 'optionsNetVolumes' => array(
  272. '*' => array( // "*" is all of netmount volumes
  273. 'tmbURL' => dirname($_SERVER['PHP_SELF']) . '/../files/.tmbNetmount/',
  274. 'tmbPath' => '../files/.tmbNetmount',
  275. 'tmbGcMaxlifeHour' => 1, // 1 hour
  276. 'tmbGcPercentage' => 10, // 10 execute / 100 tmb querys
  277. 'plugin' => array(
  278. 'AutoResize' => array(
  279. 'enable' => false
  280. ),
  281. 'Watermark' => array(
  282. 'enable' => false
  283. ),
  284. 'Normalizer' => array(
  285. 'enable' => false
  286. ),
  287. 'Sanitizer' => array(
  288. 'enable' => false
  289. )
  290. ),
  291. )
  292. ),
  293. );
  294. // Extended other volume types
  295. // To get an access token or refresh token, see the elFinder wiki.
  296. // https://github.com/Studio-42/elFinder/wiki/How-to-get-OAuth-token
  297. // Thumbnail settings for cloud volumes
  298. $tmbConfig = array(
  299. 'tmbPath' => '../files/.tmbCloud',
  300. 'tmbURL' => dirname($_SERVER['PHP_SELF']) . '/../files/.tmbCloud/',
  301. 'tmbGcMaxlifeHour' => 2160, // 90 days
  302. 'tmbGcPercentage' => 5, // 5 execute / 100 tmb querys
  303. );
  304. // MySQL config
  305. $mySqlConfig = array(
  306. 'path' => 1,
  307. 'host' => '127.0.0.1',
  308. 'user' => '', // @String DB user name
  309. 'pass' => '', // @String DB user password
  310. 'db' => '', // @String Database name
  311. 'uploadMaxSize' => '10M', // It should be less than "max_allowed_packet" value of MySQL setting
  312. );
  313. // MySQL volume
  314. $opts['roots'][] = array_merge($tmbConfig, $mySqlConfig, array(
  315. 'driver' => 'MySQL',
  316. 'trashHash' => 'tm1_MQ', // set trash to MySQL trash (tm1_) 1 (MQ)
  317. 'files_table' => 'elfinder_file',
  318. ));
  319. // MySQL trash volume
  320. $opts['roots'][] = array_merge($tmbConfig, $mySqlConfig, array(
  321. 'id' => '1', // volume id became "tm1_"
  322. 'alias' => 'DB Trash',
  323. 'driver' => 'TrashMySQL',
  324. 'files_table' => 'elfinder_trash',
  325. ));
  326. // Volume group
  327. $opts['roots'][] = array(
  328. 'id' => '1', // volume id became "g1_"
  329. 'alias' => 'CloudVolumes',
  330. 'driver' => 'Group',
  331. 'rootCssClass' => 'elfinder-navbar-root-network' // set volume icon
  332. );
  333. // FTP volume
  334. $opts['roots'][] = array_merge($tmbConfig, array(
  335. 'phash' => 'g1_Lw', // set parent to Volume group (g1_) root "/" (Lw)
  336. 'driver' => 'FTP',
  337. 'host' => 'ftp.jaist.ac.jp',
  338. 'user' => 'anonymous',
  339. 'path' => '/',
  340. 'owner' => false,
  341. ));
  342. // To enable the following cloud volumes, first complete the steps
  343. // for enabling each network-mounted volume described earlier in this file.
  344. // Box volume
  345. // Require constant "ELFINDER_BOX_CLIENTID" and "ELFINDER_BOX_CLIENTSECRET"
  346. $opts['roots'][] = array_merge($tmbConfig, array(
  347. 'phash' => 'g1_Lw', // set parent to Volume group (g1_) root "/" (Lw)
  348. 'driver' => 'Box',
  349. 'path' => '/', // or folder id as root
  350. 'accessToken' => '', // @JSON String access token including refresh token
  351. ));
  352. // Dropbox volume
  353. // Require constant "ELFINDER_DROPBOX_APPKEY" and "ELFINDER_DROPBOX_APPSECRET"
  354. $opts['roots'][] = array_merge($tmbConfig, array(
  355. 'phash' => 'g1_Lw', // set parent to Volume group (g1_) root "/" (Lw)
  356. 'driver' => 'Dropbox2',
  357. 'path' => '/', // or folder path as root
  358. 'access_token' => '', // @String your access token
  359. ));
  360. // GoogleDrive volume with refresh token
  361. // Require constant "ELFINDER_GOOGLEDRIVE_CLIENTID" and "ELFINDER_GOOGLEDRIVE_CLIENTSECRET"
  362. $opts['roots'][] = array_merge($tmbConfig, array(
  363. 'phash' => 'g1_Lw', // set parent to Volume group (g1_) root "/" (Lw)
  364. 'driver' => 'GoogleDrive',
  365. 'path' => '/', // or folder id as root
  366. 'refresh_token' => '', // @String your refresh token
  367. ));
  368. // GoogleDrive volume with service account
  369. // Require constant "ELFINDER_GOOGLEDRIVE_CLIENTID" and "ELFINDER_GOOGLEDRIVE_CLIENTSECRET"
  370. $opts['roots'][] = array_merge($tmbConfig, array(
  371. 'phash' => 'g1_Lw', // set parent to Volume group (g1_) root "/" (Lw)
  372. 'driver' => 'GoogleDrive',
  373. 'path' => '/', // or folder id as root
  374. 'serviceAccountConfigFile' => '', // @String path to config json file
  375. ));
  376. // OneDrive volume
  377. // Require constant "ELFINDER_ONEDRIVE_CLIENTID" and "ELFINDER_ONEDRIVE_CLIENTSECRET"
  378. $opts['roots'][] = array_merge($tmbConfig, array(
  379. 'phash' => 'g1_Lw', // set parent to Volume group (g1_) root "/" (Lw)
  380. 'driver' => 'OneDrive',
  381. 'path' => '/', // or folder id as root
  382. 'accessToken' => '', // @JSON String access token including refresh token
  383. ));
  384. // run elFinder
  385. $connector = new elFinderConnector(new elFinder($opts));
  386. $connector->run();