/** * @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'; }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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; }