Ejemplo n.º 1
0
 public function createGroup($scope, $path)
 {
     xapp_import('xapp.Directory.Utils');
     xapp_import('xapp.Path.Utils');
     xapp_import('xapp.VFS.Local');
     xapp_import('xapp.Commons.Exceptions');
     $fullPath = $this->resolvePath($scope, $path, null, true, false);
     xapp_clog('create driver group : ' . $fullPath . ' for scope ' . $scope . ' and path ' . $path);
     return XApp_File_Utils::mkDir(XApp_Path_Utils::securePath($fullPath));
 }
Ejemplo n.º 2
0
 /**
  * @param	string	The name of the archive file
  * @param	string	Directory to unpack into
  * @return	boolean	True for success
  */
 function extract($archivename, $extractdir)
 {
     require_once dirname(__FILE__) . '/new/File.php';
     require_once dirname(__FILE__) . '/new/Folder.php';
     require_once dirname(__FILE__) . '/new/Archive.php';
     $archive = new xapp_Archive2();
     try {
         $result = $archive->extract(realpath($archivename), realpath($extractdir));
     } catch (Exception $e) {
         xapp_clog('e ' . $e->getMessage());
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Get a file compression adapter.
  *
  * @param   string  $type  The type of adapter (bzip2|gzip|tar|zip).
  *
  * @return  ExtractableInterface  Adapter for the requested type
  *
  * @since   1.0
  * @throws  Exception
  */
 public function getAdapter($type)
 {
     $type = strtolower($type);
     if (!isset($this->adapters[$type])) {
         // Try to load the adapter object
         /* @var  ExtractableInterface  $class */
         $class = 'xapp_' . ucfirst($type);
         xapp_clog('class ' . $class . ' t ' . $type);
         xapp_import('xapp.VFS.Archive.new.' . ucfirst($type));
         if (!class_exists($class) || !$class::isSupported()) {
             throw new Exception(sprintf('Archive adapter "%s" (class "%s") not found or supported.', $type, $class));
         }
         $this->adapters[$type] = new $class($this->options);
     }
     return $this->adapters[$type];
 }
Ejemplo n.º 4
0
 public function extract($mount, $what, &$errors)
 {
     $to = '';
     $this->safeIniSet('memory_limit', '128M');
     @set_time_limit(0);
     require_once realpath(dirname(__FILE__)) . "/Archive/archive.php";
     $this->safeIniSet('memory_limit', '128M');
     @set_time_limit(0);
     $archive = new xFileArchive();
     $root = $this->toRealPath($mount);
     $firstItem = str_replace($mount, '', $what);
     $what = $root . DIRECTORY_SEPARATOR . $firstItem;
     $result = false;
     if (file_exists($what)) {
         $to = dirname($what);
         if (@is_writable($to)) {
             $result = $archive->extract($what, $to);
         }
     }
     xapp_clog('w ' . $result);
     return $result;
     /*
     if ($to == null || $to=='') {
     
     	$firstItem = str_replace($mount,'',$firstItem);
     	$to = $root . DIRECTORY_SEPARATOR . $firstItem . '.zip';
     
     	if(file_exists($to)){
     		$base = basename($to);
     		$ext = '';
     		$dotPos = strrpos($base, ".");
     		if ($dotPos > -1) {
     			$radic = substr($base, 0, $dotPos);
     			$ext = substr($base, $dotPos);
     		}
     
     		$i = 1;
     		$newName = $base;
     		while (file_exists($dstDirectory . "/" . $newName)) {
     			$suffix = "-$i";
     			if (isSet($radic)) {
     				$newName = $radic . $suffix . $ext;
     			} else {
     				$newName = $base . $suffix;
     			}
     			$i++;
     		}
     		$destFile = $dstDirectory . "/" . $newName;
     	}
     
     }
     */
     /*$archive->create($to, $zipSelection, 'zip', '', $root, true);*/
     return $to;
 }
Ejemplo n.º 5
0
 /**
  * @return array
  * @throws Xapp_XFile_Exception
  */
 public function put()
 {
     xapp_import('xapp.Path.Utils');
     xapp_import('xapp.Utils.SystemTextEncoding');
     $vars = array_merge($_GET, $_POST);
     $dstIn = '/';
     $mount = '/';
     if (array_key_exists('dstDir', $vars)) {
         $dstIn = XApp_Path_Utils::decodeSecureMagic($vars['dstDir']);
     }
     if (array_key_exists('mount', $vars)) {
         $mount = preg_replace('@[/\\\\]@', '', XApp_Path_Utils::decodeSecureMagic($vars['mount']));
     }
     if ($dstIn === '.') {
         $dstIn = '/';
     }
     $vfs = $this->getFileSystem($mount);
     $destination = $vfs->toRealPath(XApp_Path_Utils::normalizePath($mount . DIRECTORY_SEPARATOR . $dstIn));
     $errors = array();
     if (!$this->isLocal($mount, $this->getFSResources())) {
         return $this->putRemote($mount, $destination);
     }
     //writable check
     if (!is_writable($destination)) {
         throw new Xapp_XFile_Exception(XAPP_TEXT_FORMATTED('DIRECTORY_NOT_WRITEABLE', array($destination), 55100));
     }
     //parse files
     $fileVars = $_FILES;
     foreach ($fileVars as $boxName => $boxData) {
         if (substr($boxName, 0, 9) != "userfile_") {
             continue;
         }
         $err = self::parseFileDataErrors($boxData);
         if ($err != null) {
             $errorMessage = $err[1];
             $errors[] = XAPP_TEXT_FORMATTED('Error with upload %s', array($errorMessage));
             continue;
         }
         //basic sanitize
         $userfile_name = $boxData["name"];
         $userfile_name = XApp_Path_Utils::sanitizeEx(XApp_SystemTextEncoding::fromPostedFileName($userfile_name), XApp_Path_Utils::SANITIZE_HTML_STRICT);
         $userfile_name = substr($userfile_name, 0, 128);
         //rename if needed!
         $autorename = xapp_get_option(self::AUTO_RENAME);
         if ($autorename) {
             $userfile_name = self::autoRenameForDest($destination, $userfile_name);
         }
         /***
          * file extension check
          */
         $ext = pathinfo(strtolower($userfile_name), PATHINFO_EXTENSION);
         $allowable = explode(',', xapp_get_option(self::UPLOAD_EXTENSIONS, $this));
         if ($ext == '' || $ext == false || !in_array($ext, $allowable)) {
             $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_EXTENSIONS_NOT_ALLOWED', array($userfile_name, $ext));
             xapp_clog('file not allowed');
             continue;
         }
         try {
             //no need anymore
             if (file_exists($destination . "/" . $userfile_name)) {
             }
         } catch (Exception $e) {
             $errorMessage = $e->getMessage();
             $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_UNKOWN_ERROR', array($userfile_name, $errorMessage));
             break;
         }
         if (isset($boxData["input_upload"])) {
             try {
                 $input = fopen("php://input", "r");
                 $output = fopen("{$destination}/" . $userfile_name, "w");
                 $sizeRead = 0;
                 while ($sizeRead < intval($boxData["size"])) {
                     $chunk = fread($input, 4096);
                     $sizeRead += strlen($chunk);
                     fwrite($output, $chunk, strlen($chunk));
                 }
                 fclose($input);
                 fclose($output);
             } catch (Exception $e) {
                 $errorMessage = $e->getMessage();
                 $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_UNKOWN_ERROR', array($userfile_name, $errorMessage));
                 break;
             }
         } else {
             $result = @move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name);
             if (!$result) {
                 $realPath = $destination . DIRECTORY_SEPARATOR . $userfile_name;
                 $result = move_uploaded_file($boxData["tmp_name"], $realPath);
             }
             if (!$result) {
                 $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_UNKOWN_ERROR', array($userfile_name));
                 break;
             }
         }
     }
     return $errors;
 }
Ejemplo n.º 6
0
 /**
  *
  * Runs a node application with the --info argument.
  * @param $serviceResource
  * @return bool|string
  *
  * @TODO : what about npm --help ?
  */
 private function getServiceInfo($serviceResource, $helpArg = '--info')
 {
     $workingPath = $serviceResource->{XAPP_RESOURCE_PATH_ABSOLUTE};
     if (property_exists($serviceResource, 'main')) {
         $nodeapp = $this->fixWindowsPath($serviceResource->main);
         if ($nodeapp != '') {
             $args = array();
             $cmd = "node " . $nodeapp;
             $args[] = $helpArg;
             $result = XApp_Shell_Utils::run($cmd, $args, null, array(XApp_Shell_Utils::OPTION_WORKING_PATH => $workingPath, XApp_Shell_Utils::OPTION_BACKGROUND => false));
             //error_log('running service info for ' . $cmd . ' returns : ' . json_encode($result));
             //try to decode
             $dSerialized = json_decode($result, true);
             if ($dSerialized !== false && is_array($dSerialized)) {
                 if (xo_get(self::REWRITE_HOST, $this) && $dSerialized['host']) {
                     $host = gethostname();
                     $resolved = gethostbyname($host);
                     if (xo_get(self::FORCE_HOST, $this) && strlen(xo_get(self::FORCE_HOST, $this)) > 0) {
                         $resolved = xo_get(self::FORCE_HOST, $this);
                     }
                     if ($resolved && strlen($resolved)) {
                         $dSerialized['host'] = 'http://' . $resolved;
                     }
                 }
                 return $dSerialized;
             } else {
                 xapp_clog('couldn deserialize ' . $result);
             }
             return $result;
         } else {
             return false;
         }
     }
     return false;
 }