Exemple #1
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';
 }
Exemple #2
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;
 }
Exemple #3
0
 /**
  * @param $selection
  * @param $dst
  * @param array $move
  * @return array
  */
 public function copy($selection, $dst, $options)
 {
     $success = array();
     $error = array();
     if ($dst === '.') {
         $dst = '/';
     }
     $options = (array) $options;
     $inclusion = $options['include'];
     $exclusion = $options['exclude'];
     $mode = $options['mode'];
     $hints = $options['hints'];
     if (!$inclusion) {
         $inclusion = array();
     }
     if (!$hints) {
         $hints = array();
     }
     if (!$exclusion) {
         $exclusion = array();
     }
     if (!$mode) {
         $mode = 1504;
     }
     if (!count($inclusion)) {
         $inclusion = array('*', '.*');
     }
     /**
      * Local/Remote to Local/Remote
      */
     if ($this->isRemoteOperation($selection[0], $dst)) {
         $remoteMount = $this->isRemote(XApp_Path_Utils::getMount($selection[0]), $this->getFSResources()) ? XApp_Path_Utils::getMount($selection[0]) : XApp_Path_Utils::getMount($dst);
         $localMount = $this->isLocal(XApp_Path_Utils::getMount($selection[0]), $this->getFSResources()) ? XApp_Path_Utils::getMount($selection[0]) : XApp_Path_Utils::getMount($dst);
         $incoming = $this->isLocal(XApp_Path_Utils::getMount($dst), $this->getFSResources()) ? true : false;
         $remoteVFS = $this->getFileSystem($remoteMount);
         $localVFS = $this->getFileSystem($localMount);
         $localDirectory = $localVFS->toRealPath('/' . $localMount . '/');
         $adapterClass = '\\League\\Flysystem\\Adapter\\Local';
         $localFilesystem = new League\Flysystem\Filesystem(new $adapterClass($localDirectory));
         $mountManager = $remoteVFS->getMountManager();
         $mountManager->mountFilesystem($localMount, $localFilesystem);
         $relativePartDestination = XApp_Path_Utils::getRelativePart($dst);
         if ($incoming) {
             $tmp = $remoteMount;
             $remoteMount = $localMount;
             $localMount = $tmp;
         }
         foreach ($selection as $selectedFile) {
             $relativePart = XApp_Path_Utils::getRelativePart($selection[0]);
             $mountManager->put($remoteMount . '://' . $relativePartDestination . '/' . basename($selectedFile), $mountManager->read($localMount . '://' . $relativePart));
         }
         return true;
     } else {
         if ($this->isRemoteToRemoteOperation($selection[0], $dst)) {
             $remoteMountSrc = XApp_Path_Utils::getMount($selection[0]);
             $remoteSrcVFS = $this->getFileSystem($remoteMountSrc);
             $remoteMountDst = XApp_Path_Utils::getMount($dst);
             $mountManager = $remoteSrcVFS->getMountManager();
             //two different remote file systems:
             if ($remoteMountSrc !== $remoteMountDst) {
                 $remoteResource = $this->isRemote($remoteMountDst, $this->getFSResources());
                 if ($remoteResource) {
                     $dstAdapter = $remoteSrcVFS->createAdapter($remoteResource);
                     $dstFileSystem = new League\Flysystem\Filesystem($dstAdapter);
                     $mountManager->mountFilesystem($remoteMountDst, $dstFileSystem);
                 }
             }
             $relativePartDestination = XApp_Path_Utils::getRelativePart($dst);
             foreach ($selection as $selectedFile) {
                 $relativePart = XApp_Path_Utils::getRelativePart($selection[0]);
                 $mountManager->put($remoteMountDst . '://' . $relativePartDestination . '/' . basename($selectedFile), $mountManager->read($remoteMountSrc . '://' . $relativePart));
             }
             return true;
         }
     }
     $vfs = $this->getFileSystem();
     $vfs->copy($selection, $dst, null, $inclusion, $exclusion, $error, $success, $mode);
     return self::toRPCError(count($error) > 0 ? 1 : 0, $error);
 }
Exemple #4
0
 /**
  * @param $mount
  * @param $path
  * @link http://192.168.1.37:81/xapp-commander-standalone/docroot/index.php?debug=true&view=smdCall&service=XCOM_Directory_Service.get&mount=root&path=./index.php&callback=asd
  * @param bool $attachment
  * @return mixed
  */
 public function get($path, $attachment = false, $send = true, $width = null, $time = null)
 {
     if (base64_encode(base64_decode($path, true)) === $path) {
         $path = base64_decode($path);
     } else {
         echo '$data is NOT valid';
     }
     $path = urldecode($path);
     $mount = XApp_Path_Utils::getMount($path);
     $path = XApp_Path_Utils::getRelativePart($path);
     $vfs = $this->getFileSystem($mount);
     $content = $vfs->get(XApp_Path_Utils::normalizePath($mount), XApp_Path_Utils::securePath(XApp_Path_Utils::normalizePath($path, true, false)), $attachment, array(XApp_File_Utils::OPTION_SEND => $send, XApp_File_Utils::OPTION_RESIZE_TO => $width, XApp_File_Utils::OPTION_PREVENT_CACHE => isset($time)));
     if ($attachment === true) {
         exit;
     }
     return $content;
 }