Example #1
0
 /**
  * Directory listing
  * @link http://localhost/xide/code/php/xide-php/server/xide/service.php?service=XApp_Directory_Service.ls&callback=asdF&path=/ws/&recursive=true
  * @param string $path
  * @param bool $recursive
  * @param null $options
  * @return array
  */
 public function ls($mount = 'ws', $path = '/', $options = null)
 {
     $recursive = false;
     $vfs = $this->getFileSystem($mount);
     /**
      * variable normalization
      */
     $basePath = XApp_Path_Utils::normalizePath($mount, false, false);
     if ($basePath === '' || $basePath === '.') {
         $basePath = 'ws';
     }
     $path = XApp_Path_Utils::normalizePath($path, false, false);
     $scanPath = $basePath . DIRECTORY_SEPARATOR . $path;
     $scanPath = XApp_Path_Utils::normalizePath($scanPath, false, false);
     if (!$options) {
         /*
         			$options= xapp_has_option(self::DEFAULT_NODE_FIELDS) ? xapp_get_option(self::DEFAULT_NODE_FIELDS,$this) :  Array(
         				XApp_File_Utils::OPTION_DIR_LIST_FIELDS=>
         					XAPP_XFILE_SHOW_MIME|
         					XAPP_XFILE_SHOW_SIZE|
         					XAPP_XFILE_SHOW_PERMISSIONS|
         					XAPP_XFILE_SHOW_ISREADONLY|
         					XAPP_XFILE_SHOW_ISDIR);
         */
         $options = array(XApp_File_Utils::OPTION_DIR_LIST_FIELDS => XAPP_XFILE_SHOW_MIME | XAPP_XFILE_SHOW_SIZE | XAPP_XFILE_SHOW_PERMISSIONS | XAPP_XFILE_SHOW_ISREADONLY | XAPP_XFILE_SHOW_ISDIR);
     }
     $items = $vfs->ls(XApp_Path_Utils::normalizePath($scanPath, false), $recursive, $options);
     return $items;
 }
Example #2
0
 public static function getParents($workspace, $path)
 {
     $parentPath = $workspace . DIRECTORY_SEPARATOR . $path . '..';
     $result = array();
     /*echo('$parentPath : ' . $parentPath . '<br/>') ;*/
     $originalPath = XApp_Path_Utils::normalizePath($path);
     $completePath = realpath($workspace . DIRECTORY_SEPARATOR . $path);
     if (is_file($completePath)) {
         /*echo('is file : complete path ' . $path . '<br/>') ;*/
         /***
          * maqetta wants the root item for the file
          */
         $firstItem = array();
         $parts = explode('/', $path);
         $firstItem['name'] = '';
         $firstItemPath = realpath($workspace . DIRECTORY_SEPARATOR . dirname($path));
         /*echo('<br/>first item path '.$workspace . DIRECTORY_SEPARATOR . dirname($path).'<br/>');*/
         $firstItem['isDir'] = is_dir($firstItemPath);
         $firstItem['readOnly'] = is_writable($firstItemPath) ? true : false;
         $firstItem['members'] = self::getMembers($workspace, realpath($workspace . DIRECTORY_SEPARATOR));
         $firstItem['isDirty'] = false;
         $result[] = $firstItem;
         /***
          * as next we need the full list for the first item;
          */
         $firstItemList = array();
         $firstItemList['name'] = $parts[0];
         $firstItemList['members'] = self::getMembers($workspace, realpath($workspace . DIRECTORY_SEPARATOR . $parts[0]), $parts[0]);
         $result[] = $firstItemList;
     } elseif (is_dir($completePath)) {
         $parentPath = realpath($workspace . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . '..');
         $result = array();
         $item = array();
         $item['name'] = str_replace($parentPath, '', $workspace);
         $item['members'] = self::getMembers($workspace, $parentPath);
         $result[] = $item;
         return $result;
     }
     /*echo('workspace : ' . $workspace);*/
     //echo('$parentPath : ' . $parentPath . '<br/>');
     /*xapp_dump($dirList);*/
     /*
     $result =array();
     $item =array();
     $item['name'] = str_replace($parentPath,'',$workspace);
     $item['members'] = self::getMembers($workspace,$parentPath);
     $result[]=$item;
     */
     return $result;
 }
Example #3
0
 function mkDir($mount, $relativePath)
 {
     return XApp_File_Utils::mkDir(XApp_Path_Utils::securePath(self::toAbsolutePath($mount) . DIRECTORY_SEPARATOR . $relativePath));
 }
Example #4
0
 /**
  * @param $shellType {string}
  * @param $cmdBase64 {string}
  * @param $cwd
  * @return string
  */
 public function run($shellType = 'sh', $cmdBase64, $cwd = null)
 {
     //error_log('run ' . $shellType . ' cmd ' . $cmdBase64 . ' in ' .$cwd);
     //determine real fs path
     if ($this->directoryService) {
         $mount = XApp_Path_Utils::getMount($cwd);
         $rel = XApp_Path_Utils::getRelativePart($cwd);
         $vfs = null;
         if ($mount) {
             $vfs = $this->directoryService->getFileSystem($mount);
             if ($vfs) {
                 $fullPath = $vfs->toRealPath($mount . DIRECTORY_SEPARATOR . $rel);
                 if (file_exists($fullPath)) {
                     $cwd = $fullPath;
                 }
             }
         }
     }
     $code = base64_decode($cmdBase64);
     if ($shellType === 'sh') {
         $code = escapeshellcmd($code);
         $res = $this->runBash($code, $cwd);
         return $res;
     }
     return 'not implemented';
 }
Example #5
0
 public function resolvePath($scopeName, $path, $rootVariable = '__ROOT__', $secure = true, $merge = true)
 {
     xapp_import('xapp.Path.Utils');
     $scope = $this->getScope($scopeName);
     $rootVariable = $rootVariable ?: '__ROOT__';
     $path = XApp_Path_Utils::securePath($path);
     if ($scope) {
         $root = $scope->resolveAbsolute($rootVariable) . DIRECTORY_SEPARATOR;
         if ($secure === true) {
             if ($merge == true) {
                 return XApp_Path_Utils::securePath(XApp_Path_Utils::merge($root, XApp_Path_Utils::normalizePath($path)));
             } else {
                 return XApp_Path_Utils::securePath($root . XApp_Path_Utils::normalizePath($path, false, false));
             }
         } else {
             return XApp_Path_Utils::merge($root, XApp_Path_Utils::normalizePath($path, false, false));
         }
     } else {
         throw new ErrorException("scope:" . $scopeName . "does not exist", 1390101);
     }
 }
Example #6
0
 /**
  * @param $mount
  * @param $selection
  * @param string $type
  * @return mixed
  */
 public function downloadTo($url, $mount, $to)
 {
     xapp_import('xapp.Path.Utils');
     xapp_import('xapp.File.Utils');
     xapp_import('xapp.Commons.ErrorHandler');
     xapp_import('xapp.Utils.Download');
     xapp_import('xapp.Utils.SystemTextEncoding');
     $success = array();
     $error = array();
     $mount = XApp_Path_Utils::getMount($mount);
     $vfs = $this->getFileSystem($mount);
     $realSrcFile = '' . $url;
     XApp_ErrorHandler::start();
     if ($this->isLocal($mount, $this->getFSResources())) {
         $srcFile = '' . XApp_Path_Utils::decodeSecureMagic($to);
         $destFile = $vfs->toRealPath($mount . DIRECTORY_SEPARATOR . $srcFile);
         if (is_dir($destFile) && (!file_exists($destFile) || !is_file($destFile))) {
             $destDirectory = '' . $destFile;
             //default file name
             $fileName = 'remoteFile.download';
             //try to get a file name from the url through parse_url(pathinfo())
             $urlParts = parse_url($url);
             if ($urlParts['path']) {
                 $pathInfo = pathinfo($urlParts['path']);
                 if ($pathInfo['basename']) {
                     $fileName = $pathInfo['basename'];
                 }
             }
             $destFile = XApp_File_Utils::unique_filename($destFile, $fileName);
             $destFile = $destDirectory . DIRECTORY_SEPARATOR . $destFile;
             touch($destFile);
         }
         try {
             $srcPath = XApp_Download::download($realSrcFile);
             if (!file_exists($srcPath)) {
                 return self::toRPCError(1, 'Error downloading ' . $srcPath . ' Error : ' . $srcPath);
             }
             $src = fopen($srcPath, "r");
             $dest = fopen($destFile, "w");
             if ($dest !== false) {
                 while (!feof($src)) {
                     stream_copy_to_stream($src, $dest, 4096);
                 }
                 fclose($dest);
             }
             fclose($src);
             @unlink($srcPath);
         } catch (Exception $e) {
             return self::toRPCError(1, $e->getMessage());
         }
     } else {
         $mountManager = $vfs->getMountManager();
         $to = XApp_Path_Utils::normalizePath($to, false, false);
         $to = $mount . '://' . $to;
         $to = $vfs->cleanSlashesRemote($to);
         try {
             $src = fopen($realSrcFile, "r");
             while (!feof($src)) {
                 $mountManager->updateStream($to, $src);
             }
             fclose($src);
         } catch (Exception $e) {
             return self::toRPCError(1, $e->getMessage());
         }
     }
     /*
     $errors = XApp_ErrorHandler::stop();
     if($errors){
     	xapp_clog($errors);
     	$this->logger->log(json_encode($errors));
     }
     */
     /*xapp_clog($errors);*/
     return true;
 }
Example #7
0
 /**
  * @param $path
  * @return string
  */
 public function toFlyPath($path)
 {
     $path = XApp_Path_Utils::normalizePath($path);
     $mount = XApp_Path_Utils::getMount($path);
     $relativePath = XApp_Path_Utils::getRelativePart($path);
     return $mount . '://' . $relativePath;
 }
Example #8
0
 /**
  * @param $src
  * @param $dst
  *
  * @return bool
  */
 public function isRemoteOperation($src, $dst)
 {
     $srcType = $this->getResourceType(XApp_Path_Utils::getMount($src));
     $dstType = $this->getResourceType(XApp_Path_Utils::getMount($dst));
     return $dst && $dstType && $srcType != $dstType;
 }
Example #9
0
 public function deleteFile($path)
 {
     $vfs = $this->_getFileSystem();
     $success = array();
     $error = array();
     $vfs->deleteFile(XApp_Path_Utils::securePath(XApp_Path_Utils::normalizePath($path, true, false)), null, $error, $success);
 }