コード例 #1
0
ファイル: elFinder.class.php プロジェクト: nao-pon/xelfinder
 /**
  * Save network volumes config.
  *
  * @param  array  $volumes  volumes config
  * @return void
  * @author Dmitry (dio) Levashov
  */
 protected function saveNetVolumes($volumes)
 {
     $this->session->set('netvolume', $volumes);
 }
コード例 #2
0
 /**
  * Get server side available archivers
  * 
  * @param bool $use_cache
  * @return array
  */
 protected function getArchivers($use_cache = true)
 {
     $sessionKey = 'ARCHIVERS_CACHE';
     if ($use_cache && isset($this->sessionCache[$sessionKey]) && is_array($this->sessionCache[$sessionKey])) {
         return $this->sessionCache[$sessionKey];
     }
     $arcs = array('create' => array(), 'extract' => array());
     if (function_exists('proc_open')) {
         $this->procExec('tar --version', $o, $ctar);
         if ($ctar == 0) {
             $arcs['create']['application/x-tar'] = array('cmd' => 'tar', 'argc' => '-cf', 'ext' => 'tar');
             $arcs['extract']['application/x-tar'] = array('cmd' => 'tar', 'argc' => '-xf', 'ext' => 'tar');
             unset($o);
             $test = $this->procExec('gzip --version', $o, $c);
             if ($c == 0) {
                 $arcs['create']['application/x-gzip'] = array('cmd' => 'tar', 'argc' => '-czf', 'ext' => 'tgz');
                 $arcs['extract']['application/x-gzip'] = array('cmd' => 'tar', 'argc' => '-xzf', 'ext' => 'tgz');
             }
             unset($o);
             $test = $this->procExec('bzip2 --version', $o, $c);
             if ($c == 0) {
                 $arcs['create']['application/x-bzip2'] = array('cmd' => 'tar', 'argc' => '-cjf', 'ext' => 'tbz');
                 $arcs['extract']['application/x-bzip2'] = array('cmd' => 'tar', 'argc' => '-xjf', 'ext' => 'tbz');
             }
             unset($o);
             $test = $this->procExec('xz --version', $o, $c);
             if ($c == 0) {
                 $arcs['create']['application/x-xz'] = array('cmd' => 'tar', 'argc' => '-cJf', 'ext' => 'xz');
                 $arcs['extract']['application/x-xz'] = array('cmd' => 'tar', 'argc' => '-xJf', 'ext' => 'xz');
             }
         }
         unset($o);
         $this->procExec('zip -v', $o, $c);
         if ($c == 0) {
             $arcs['create']['application/zip'] = array('cmd' => 'zip', 'argc' => '-r9', 'ext' => 'zip');
         }
         unset($o);
         $this->procExec('unzip --help', $o, $c);
         if ($c == 0) {
             $arcs['extract']['application/zip'] = array('cmd' => 'unzip', 'argc' => '', 'ext' => 'zip');
         }
         unset($o);
         $this->procExec('rar --version', $o, $c);
         if ($c == 0 || $c == 7) {
             $arcs['create']['application/x-rar'] = array('cmd' => 'rar', 'argc' => 'a -inul', 'ext' => 'rar');
             $arcs['extract']['application/x-rar'] = array('cmd' => 'rar', 'argc' => 'x -y', 'ext' => 'rar');
         } else {
             unset($o);
             $test = $this->procExec('unrar', $o, $c);
             if ($c == 0 || $c == 7) {
                 $arcs['extract']['application/x-rar'] = array('cmd' => 'unrar', 'argc' => 'x -y', 'ext' => 'rar');
             }
         }
         unset($o);
         $this->procExec('7za --help', $o, $c);
         if ($c == 0) {
             $arcs['create']['application/x-7z-compressed'] = array('cmd' => '7za', 'argc' => 'a', 'ext' => '7z');
             $arcs['extract']['application/x-7z-compressed'] = array('cmd' => '7za', 'argc' => 'x -y', 'ext' => '7z');
             if (empty($arcs['create']['application/zip'])) {
                 $arcs['create']['application/zip'] = array('cmd' => '7za', 'argc' => 'a -tzip', 'ext' => 'zip');
             }
             if (empty($arcs['extract']['application/zip'])) {
                 $arcs['extract']['application/zip'] = array('cmd' => '7za', 'argc' => 'x -tzip -y', 'ext' => 'zip');
             }
             if (empty($arcs['create']['application/x-tar'])) {
                 $arcs['create']['application/x-tar'] = array('cmd' => '7za', 'argc' => 'a -ttar', 'ext' => 'tar');
             }
             if (empty($arcs['extract']['application/x-tar'])) {
                 $arcs['extract']['application/x-tar'] = array('cmd' => '7za', 'argc' => 'x -ttar -y', 'ext' => 'tar');
             }
         } else {
             if (substr(PHP_OS, 0, 3) === 'WIN') {
                 // check `7z` for Windows server.
                 unset($o);
                 $this->procExec('7z', $o, $c);
                 if ($c == 0) {
                     $arcs['create']['application/x-7z-compressed'] = array('cmd' => '7z', 'argc' => 'a', 'ext' => '7z');
                     $arcs['extract']['application/x-7z-compressed'] = array('cmd' => '7z', 'argc' => 'x -y', 'ext' => '7z');
                     if (empty($arcs['create']['application/zip'])) {
                         $arcs['create']['application/zip'] = array('cmd' => '7z', 'argc' => 'a -tzip', 'ext' => 'zip');
                     }
                     if (empty($arcs['extract']['application/zip'])) {
                         $arcs['extract']['application/zip'] = array('cmd' => '7z', 'argc' => 'x -tzip -y', 'ext' => 'zip');
                     }
                     if (empty($arcs['create']['application/x-tar'])) {
                         $arcs['create']['application/x-tar'] = array('cmd' => '7z', 'argc' => 'a -ttar', 'ext' => 'tar');
                     }
                     if (empty($arcs['extract']['application/x-tar'])) {
                         $arcs['extract']['application/x-tar'] = array('cmd' => '7z', 'argc' => 'x -ttar -y', 'ext' => 'tar');
                     }
                 }
             }
         }
     }
     // Use PHP ZipArchive Class
     if (class_exists('ZipArchive', false)) {
         if (empty($arcs['create']['application/zip'])) {
             $arcs['create']['application/zip'] = array('cmd' => 'phpfunction', 'argc' => array('self', 'zipArchiveZip'), 'ext' => 'zip');
         }
         if (empty($arcs['extract']['application/zip'])) {
             $arcs['extract']['application/zip'] = array('cmd' => 'phpfunction', 'argc' => array('self', 'zipArchiveUnzip'), 'ext' => 'zip');
         }
     }
     $this->sessionCache[$sessionKey] = $arcs;
     $this->session->set($this->id, $this->sessionCache);
     return $arcs;
 }
コード例 #3
0
 /**
  * "Mount" volume.
  * Return true if volume available for read or write,
  * false - otherwise
  *
  * @param array $opts
  * @return bool
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  */
 public function mount(array $opts)
 {
     $this->options = array_merge($this->options, $opts);
     if (!isset($this->options['path']) || $this->options['path'] === '') {
         return $this->setError('Path undefined.');
     }
     if (!$this->session) {
         return $this->setError('Session wrapper dose not set. Need to `$volume->setSession(elFinderSessionInterface);` before mount.');
     }
     if (!$this->session instanceof elFinderSessionInterface) {
         return $this->setError('Session wrapper instance must be "elFinderSessionInterface".');
     }
     $this->id = $this->driverId . (!empty($this->options['id']) ? $this->options['id'] : elFinder::$volumesCnt++) . '_';
     $this->root = $this->normpathCE($this->options['path']);
     $this->separator = isset($this->options['separator']) ? $this->options['separator'] : DIRECTORY_SEPARATOR;
     $this->systemRoot = isset($this->options['systemRoot']) ? $this->options['systemRoot'] : $this->separator;
     // set server encoding
     if (!empty($this->options['encoding']) && strtoupper($this->options['encoding']) !== 'UTF-8') {
         $this->encoding = $this->options['encoding'];
     } else {
         $this->encoding = null;
     }
     $argInit = !empty($this->ARGS['init']);
     // session cache
     if ($argInit) {
         $this->session->set($this->id, array());
     }
     $this->sessionCache = $this->session->get($this->id, array());
     // default file attribute
     $this->defaults = array('read' => isset($this->options['defaults']['read']) ? !!$this->options['defaults']['read'] : true, 'write' => isset($this->options['defaults']['write']) ? !!$this->options['defaults']['write'] : true, 'locked' => isset($this->options['defaults']['locked']) ? !!$this->options['defaults']['locked'] : false, 'hidden' => isset($this->options['defaults']['hidden']) ? !!$this->options['defaults']['hidden'] : false);
     // root attributes
     $this->attributes[] = array('pattern' => '~^' . preg_quote($this->separator) . '$~', 'locked' => true, 'hidden' => false);
     // set files attributes
     if (!empty($this->options['attributes']) && is_array($this->options['attributes'])) {
         foreach ($this->options['attributes'] as $a) {
             // attributes must contain pattern and at least one rule
             if (!empty($a['pattern']) || count($a) > 1) {
                 $this->attributes[] = $a;
             }
         }
     }
     if (!empty($this->options['accessControl']) && is_callable($this->options['accessControl'])) {
         $this->access = $this->options['accessControl'];
     }
     $this->today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
     $this->yesterday = $this->today - 86400;
     if (!$this->init()) {
         return false;
     }
     // check some options is arrays
     $this->uploadAllow = isset($this->options['uploadAllow']) && is_array($this->options['uploadAllow']) ? $this->options['uploadAllow'] : array();
     $this->uploadDeny = isset($this->options['uploadDeny']) && is_array($this->options['uploadDeny']) ? $this->options['uploadDeny'] : array();
     $this->options['uiCmdMap'] = isset($this->options['uiCmdMap']) && is_array($this->options['uiCmdMap']) ? $this->options['uiCmdMap'] : array();
     if (is_string($this->options['uploadOrder'])) {
         // telephat_mode on, compatibility with 1.x
         $parts = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow');
         $this->uploadOrder = array(trim($parts[0]), trim($parts[1]));
     } else {
         // telephat_mode off
         $this->uploadOrder = !empty($this->options['uploadOrder']) ? $this->options['uploadOrder'] : array('deny', 'allow');
     }
     if (!empty($this->options['uploadMaxSize'])) {
         $size = '' . $this->options['uploadMaxSize'];
         $unit = strtolower(substr($size, strlen($size) - 1));
         $n = 1;
         switch ($unit) {
             case 'k':
                 $n = 1024;
                 break;
             case 'm':
                 $n = 1048576;
                 break;
             case 'g':
                 $n = 1073741824;
         }
         $this->uploadMaxSize = intval($size) * $n;
     }
     // Set maximum to PHP_INT_MAX
     if (!defined('PHP_INT_MAX')) {
         define('PHP_INT_MAX', 2147483647);
     }
     if ($this->uploadMaxSize < 1 || $this->uploadMaxSize > PHP_INT_MAX) {
         $this->uploadMaxSize = PHP_INT_MAX;
     }
     $this->disabled = isset($this->options['disabled']) && is_array($this->options['disabled']) ? array_values(array_diff($this->options['disabled'], array('open'))) : array();
     $this->cryptLib = $this->options['cryptLib'];
     $this->mimeDetect = $this->options['mimeDetect'];
     // find available mimetype detect method
     $type = strtolower($this->options['mimeDetect']);
     $type = preg_match('/^(finfo|mime_content_type|internal|auto)$/i', $type) ? $type : 'auto';
     $regexp = '/text\\/x\\-(php|c\\+\\+)/';
     if (($type == 'finfo' || $type == 'auto') && class_exists('finfo', false)) {
         $tmpFileInfo = explode(';', finfo_file(finfo_open(FILEINFO_MIME), __FILE__));
     } else {
         $tmpFileInfo = false;
     }
     $type = 'internal';
     if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) {
         $type = 'finfo';
         $this->finfo = finfo_open(FILEINFO_MIME);
     } elseif (($type == 'mime_content_type' || $type == 'auto') && function_exists('mime_content_type')) {
         $_mimetypes = explode(';', mime_content_type(__FILE__));
         if (preg_match($regexp, array_shift($_mimetypes))) {
             $type = 'mime_content_type';
         }
     }
     $this->mimeDetect = $type;
     // load mimes from external file for mimeDetect == 'internal'
     // based on Alexey Sukhotin idea and patch: http://elrte.org/redmine/issues/163
     // file must be in file directory or in parent one
     if ($this->mimeDetect == 'internal' && !self::$mimetypesLoaded) {
         self::$mimetypesLoaded = true;
         $this->mimeDetect = 'internal';
         $file = false;
         if (!empty($this->options['mimefile']) && file_exists($this->options['mimefile'])) {
             $file = $this->options['mimefile'];
         } elseif (elFinder::$defaultMimefile && file_exists(elFinder::$defaultMimefile)) {
             $file = elFinder::$defaultMimefile;
         } elseif (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mime.types')) {
             $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mime.types';
         } elseif (file_exists(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'mime.types')) {
             $file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'mime.types';
         }
         if ($file && file_exists($file)) {
             $mimecf = file($file);
             foreach ($mimecf as $line_num => $line) {
                 if (!preg_match('/^\\s*#/', $line)) {
                     $mime = preg_split('/\\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
                     for ($i = 1, $size = count($mime); $i < $size; $i++) {
                         if (!isset(self::$mimetypes[$mime[$i]])) {
                             self::$mimetypes[$mime[$i]] = $mime[0];
                         }
                     }
                 }
             }
         }
     }
     $this->rootName = empty($this->options['alias']) ? $this->basenameCE($this->root) : $this->options['alias'];
     // This get's triggered if $this->root == '/' and alias is empty.
     // Maybe modify _basename instead?
     if ($this->rootName === '') {
         $this->rootName = $this->separator;
     }
     $root = $this->stat($this->root);
     if (!$root) {
         return $this->setError('Root folder does not exist.');
     }
     if (!$root['read'] && !$root['write']) {
         return $this->setError('Root folder has not read and write permissions.');
     }
     if ($root['read']) {
         // check startPath - path to open by default instead of root
         $startPath = $this->options['startPath'] ? $this->normpathCE($this->options['startPath']) : '';
         if ($startPath) {
             $start = $this->stat($startPath);
             if (!empty($start) && $start['mime'] == 'directory' && $start['read'] && empty($start['hidden']) && $this->inpathCE($startPath, $this->root)) {
                 $this->startPath = $startPath;
                 if (substr($this->startPath, -1, 1) == $this->options['separator']) {
                     $this->startPath = substr($this->startPath, 0, -1);
                 }
             }
         }
     } else {
         $this->options['URL'] = '';
         $this->options['tmbURL'] = '';
         $this->options['tmbPath'] = '';
         // read only volume
         array_unshift($this->attributes, array('pattern' => '/.*/', 'read' => false));
     }
     $this->treeDeep = $this->options['treeDeep'] > 0 ? (int) $this->options['treeDeep'] : 1;
     $this->tmbSize = $this->options['tmbSize'] > 0 ? (int) $this->options['tmbSize'] : 48;
     $this->URL = $this->options['URL'];
     if ($this->URL && preg_match("|[^/?&=]\$|", $this->URL)) {
         $this->URL .= '/';
     }
     if (strtolower($this->options['dirUrlOwn']) === 'auto') {
         $this->options['dirUrlOwn'] = $this->URL ? false : true;
     } else {
         $this->options['dirUrlOwn'] = (bool) $this->options['dirUrlOwn'];
     }
     $this->tmbURL = !empty($this->options['tmbURL']) ? $this->options['tmbURL'] : '';
     if ($this->tmbURL && $this->tmbURL !== 'self' && preg_match("|[^/?&=]\$|", $this->tmbURL)) {
         $this->tmbURL .= '/';
     }
     $this->nameValidator = !empty($this->options['acceptedName']) && (is_string($this->options['acceptedName']) || is_callable($this->options['acceptedName'])) ? $this->options['acceptedName'] : '';
     $this->_checkArchivers();
     // manual control archive types to create
     if (!empty($this->options['archiveMimes']) && is_array($this->options['archiveMimes'])) {
         foreach ($this->archivers['create'] as $mime => $v) {
             if (!in_array($mime, $this->options['archiveMimes'])) {
                 unset($this->archivers['create'][$mime]);
             }
         }
     }
     // manualy add archivers
     if (!empty($this->options['archivers']['create']) && is_array($this->options['archivers']['create'])) {
         foreach ($this->options['archivers']['create'] as $mime => $conf) {
             if (strpos($mime, 'application/') === 0 && !empty($conf['cmd']) && isset($conf['argc']) && !empty($conf['ext']) && !isset($this->archivers['create'][$mime])) {
                 $this->archivers['create'][$mime] = $conf;
             }
         }
     }
     if (!empty($this->options['archivers']['extract']) && is_array($this->options['archivers']['extract'])) {
         foreach ($this->options['archivers']['extract'] as $mime => $conf) {
             if (strpos($mime, 'application/') === 0 && !empty($conf['cmd']) && isset($conf['argc']) && !empty($conf['ext']) && !isset($this->archivers['extract'][$mime])) {
                 $this->archivers['extract'][$mime] = $conf;
             }
         }
     }
     if (!empty($this->options['noSessionCache']) && is_array($this->options['noSessionCache'])) {
         foreach ($this->options['noSessionCache'] as $_key) {
             $this->sessionCaching[$_key] = false;
             unset($this->sessionCache[$_key]);
         }
     }
     $this->configure();
     // Normarize disabled (array_merge`for type array of JSON)
     $this->disabled = array_values(array_unique($this->disabled));
     // fix sync interval
     if ($this->options['syncMinMs'] !== 0) {
         $this->options['syncMinMs'] = max($this->options[$this->options['syncChkAsTs'] ? 'tsPlSleep' : 'lsPlSleep'] * 1000, intval($this->options['syncMinMs']));
     }
     return $this->mounted = true;
 }