コード例 #1
0
ファイル: FileTree.php プロジェクト: xamiro-dev/xamiro
 public function ls($path = null)
 {
     xapp_import('xapp.Directory.Utils');
     xapp_import('xapp.VFS.Local');
     //we listen to VFS messages
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_META_CREATED, $this, "_onItem");
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_ADD, $this, "_addNode");
     //create a single scope for now
     //prepare vfs
     $vfsItems = array();
     //mount one item at root, the system scope.
     $vfsItems[] = array('name' => 'root', 'path' => $path . DIRECTORY_SEPARATOR);
     //vfs ctor
     $this->_vfs = XApp_VFS_Local::factory($vfsItems);
     //vfs dir scanning options
     $directoryOptions = array(XApp_Directory_Utils::OPTION_ONLY_DIRS => false, XApp_Directory_Utils::OPTION_ONLY_FILES => false, XApp_Directory_Utils::OPTION_RECURSIVE => true, XApp_Directory_Utils::OPTION_CLEAR_PATH => true);
     //prepare result
     $this->_currentNodes = array();
     $this->_currentNodes['items'] = array();
     //fire vfs
     $items = $this->_vfs->ls('root/', true, array(XApp_File_Utils::OPTION_DIR_LIST_FIELDS => XAPP_XFILE_SHOW_ISDIR, XApp_File_Utils::OPTION_DIR_LIST => $directoryOptions, XApp_Directory_Utils::OPTION_INCLUDE_LIST => array('*')));
     //complete tree-store data
     $this->_currentNodes['identifier'] = 'path';
     $this->_currentNodes['label'] = 'name';
     return $this->_currentNodes;
 }
コード例 #2
0
ファイル: Local.php プロジェクト: xamiro-dev/xamiro
 public function ls($path = '/', $recursive = false, $options = array())
 {
     xapp_import('xapp.Xapp.Hook');
     xapp_import('xapp.File.Utils');
     xapp_import('xapp.Commons.ErrorHandler');
     $options = (array) $options;
     // Default options
     if (!isset($options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS])) {
         $options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS] = 0;
     }
     // Default option : emit new node
     if (!isset($options[XApp_File_Utils::OPTION_EMIT])) {
         $options[XApp_File_Utils::OPTION_EMIT] = true;
     }
     //default scan options
     $get_list_options = array(XApp_Directory_Utils::OPTION_CLEAR_PATH => true, XApp_Directory_Utils::OPTION_RECURSIVE => $recursive);
     //overwrite from options
     if (isset($options[XApp_File_Utils::OPTION_DIR_LIST])) {
         $get_list_options = $options[XApp_File_Utils::OPTION_DIR_LIST];
     }
     //default include & exclude list
     $inclusionMask = XApp_File_Utils::defaultInclusionPatterns();
     $exclusionMask = XApp_File_Utils::defaultExclusionPatterns();
     /*
     //overwrite include from options
     if (isset($options[XApp_Directory_Utils::OPTION_INCLUDE_LIST])) {
     	if (is_string($options[XApp_Directory_Utils::OPTION_INCLUDE_LIST])) {
     		$inclusionMask = explode(',', $options[XApp_Directory_Utils::OPTION_INCLUDE_LIST]);
     	} else {
     		if (is_array($options[XApp_Directory_Utils::OPTION_INCLUDE_LIST])) {
     			$inclusionMask = $options[XApp_Directory_Utils::OPTION_INCLUDE_LIST];
     		}
     	}
     }
     */
     if (isset($options[XApp_Directory_Utils::OPTION_INCLUDE_LIST])) {
         //	$inclusionMask = $options[XApp_Directory_Utils::OPTION_INCLUDE_LIST];
     }
     //overwrite excludes from options
     if (isset($options[XApp_Directory_Utils::OPTION_EXCLUDE_LIST])) {
         //		$exclusionMask = explode(',', $options[XApp_Directory_Utils::OPTION_EXCLUDE_LIST]);
     }
     //XApp_ErrorHandler::start();
     $list = $this->getFilteredDirList($path, $inclusionMask, $exclusionMask, $get_list_options);
     $ret_list = array();
     /***
      * Use 'readOnly' from the paths's resource information
      */
     $isReadOnly = null;
     foreach ($list as $item_name) {
         $item = new stdClass();
         $item->{XAPP_NODE_FIELD_NAME} = $item_name;
         if ($path != "/") {
             self::add_ls_file_information($this->toRealPath($path . DIRECTORY_SEPARATOR . $item_name), $item, $options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS]);
             //tell plugins, if anyone doesnt want the item, skip it
             $addItem = Xapp_Hook::trigger(self::EVENT_ON_NODE_ADD, array('item' => $item));
             if ($addItem === false) {
                 continue;
             }
             //tell plugins, if anyone doesnt want the item, skip it
             if ($options[XApp_File_Utils::OPTION_EMIT] === true) {
                 $item = Xapp_Hook::trigger(self::EVENT_ON_NODE_META_CREATED, array('item' => $item));
                 if ($item === null) {
                     continue;
                 }
             }
             //now overwrite readOnly flag
             if ($isReadOnly != null && ($options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS] & XAPP_XFILE_SHOW_ISREADONLY) == XAPP_XFILE_SHOW_ISREADONLY) {
                 $item->{XAPP_NODE_FIELD_READ_ONLY} = $isReadOnly;
             }
             //tell plugins
             Xapp_Hook::trigger(self::EVENT_ON_NODE_ADDED, array('item' => $item));
         }
         $ret_list[] = $item;
     }
     /*
     		error_log('test',E_WARNING);
     		$error = XApp_ErrorHandler::stop();
     		xapp_clog($error);*/
     return $ret_list;
 }
コード例 #3
0
ファイル: Service.php プロジェクト: xamiro-dev/xamiro
 public function ls($mount = 'ws', $path = '/', $options = null)
 {
     xapp_import('xapp.Xapp.Hook');
     $recursive = false;
     //sanitize
     $basePath = XApp_Path_Utils::normalizePath($mount, false, false);
     if ($basePath === '' || $basePath === '.') {
         $basePath = 'root';
     }
     $path = XApp_Path_Utils::normalizePath($path, false, false);
     $options = (array) $options;
     $scanPath = $basePath . DIRECTORY_SEPARATOR . $path;
     $scanPath = XApp_Path_Utils::normalizePath($scanPath, false, false);
     $vfs = $this->getFileSystem($scanPath);
     //defaults
     if (!$options) {
         $options = array(XApp_File_Utils::OPTION_DIR_LIST_FIELDS => XAPP_XFILE_SHOW_SIZE | XAPP_XFILE_SHOW_PERMISSIONS | XAPP_XFILE_SHOW_ISREADONLY | XAPP_XFILE_SHOW_ISDIR | XAPP_XFILE_SHOW_OWNER | XAPP_XFILE_SHOW_TIME | XAPP_XFILE_SHOW_MIME);
     }
     //hook into meta data creation for custom completion
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_META_CREATED, $this, "_onItem", '', array('parentPath' => $path, 'mount' => $basePath, 'remote' => $vfs->remote, 'options' => $options));
     //hook into 'node add' for custom node rejection
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_ADD, $this, "_addNode", '', array('mount' => $basePath, 'owner' => $this, 'options' => $options, 'remote' => $vfs->remote));
     $result = null;
     try {
         $vfs->ls(XApp_Path_Utils::normalizePath($scanPath, false), $recursive, $options);
     } catch (Exception $e) {
         return $this->toRPCError(1, $e->getMessage());
     }
     //prepare root object
     $rootObject = new stdClass();
     $fullPath = $vfs->toRealPath($basePath);
     if (!file_exists($fullPath)) {
         xapp_import('xapp.File.Utils');
         $res = XApp_File_Utils::mkDir($fullPath, 0755, true);
         if ($res == false) {
             return $this->toRPCError(1, 'Sorry, couldnt create directory');
         }
     }
     $vfs->add_ls_file_information($vfs->toRealPath($basePath), $rootObject, XAPP_XFILE_SHOW_SIZE | XAPP_XFILE_SHOW_PERMISSIONS | XAPP_XFILE_SHOW_ISREADONLY | XAPP_XFILE_SHOW_TIME | XAPP_XFILE_SHOW_MIME);
     //corrections
     $rootName = '' . $path;
     $rootPath = '' . $path;
     if ($rootName === '' || $rootName === '/') {
         $rootName = '.';
     }
     if ($rootPath === '' || $rootPath === '/') {
         $rootPath = '.';
     } else {
         $rootPath = './' . $path;
     }
     $rootPath = str_replace('//', '/', $rootPath);
     if ($this->isWindows()) {
         //whatever
         $rootPath = str_replace('././', './', $rootName);
     }
     $rootName = basename($rootName);
     $rootName = str_replace('/', '', $rootName);
     //prepare Dojo store root structure
     $result = array('status' => 200, 'total' => 1, 'items' => array());
     $result['items'][] = array('children' => $this->_currentItems, '_EX' => true, 'size' => 0, 'name' => $rootName, 'path' => $rootPath, 'mount' => $basePath, 'directory' => true);
     return $result;
 }
コード例 #4
0
ファイル: Service.php プロジェクト: xamiro-dev/xamiro
 public function onBeforeCall(Xapp_Rpc_Server $server, array $params)
 {
     parent::init();
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_META_CREATED, $this, "_onItem");
 }
コード例 #5
0
ファイル: Remote.php プロジェクト: xamiro-dev/xamiro
 public function ls($path = '/', $recursive = false, $options = array())
 {
     xapp_import('xapp.Xapp.Hook');
     //1.extract mount name from path
     $parsed = parse_url($path);
     $path = $parsed['path'];
     $path_parts = explode('/', $path);
     $basePath = $path_parts[1];
     //2. get the FS Adapter from the mount manager
     $fs = $this->getFilesystem($basePath);
     //3. build the internal path, it should look now like  'ftp://httpdocs'
     $fsPath = $path_parts[1] . '://';
     $fsPath .= $this->getPathPrefix() . '/';
     for ($i = 2; $i < count($path_parts); $i++) {
         $fsPath .= '/' . $path_parts[$i];
     }
     //error_log($fsPath);
     $fsPath = str_replace(':////', '://', $fsPath);
     $fsPath = str_replace(':///', '://', $fsPath);
     $fsPath = str_replace('///', '/', $fsPath);
     // Default options
     if (!isset($options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS])) {
         $options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS] = 0;
     }
     // Default option : emit new node
     if (!isset($options[XApp_File_Utils::OPTION_EMIT])) {
         $options[XApp_File_Utils::OPTION_EMIT] = true;
     }
     //default scan options
     $get_list_options = array(XApp_Directory_Utils::OPTION_CLEAR_PATH => true, XApp_Directory_Utils::OPTION_RECURSIVE => $recursive);
     //overwrite from options
     if (isset($options[XApp_File_Utils::OPTION_DIR_LIST])) {
         $get_list_options = $options[XApp_File_Utils::OPTION_DIR_LIST];
     }
     //default include & exclude list
     $inclusionMask = XApp_File_Utils::defaultInclusionPatterns();
     $exclusionMask = XApp_File_Utils::defaultExclusionPatterns();
     //overwrite include from options
     if (isset($options[XApp_Directory_Utils::OPTION_INCLUDE_LIST])) {
         $inclusionMask = $options[XApp_Directory_Utils::OPTION_INCLUDE_LIST];
     }
     //overwrite excludes from options
     if (isset($options[XApp_Directory_Utils::OPTION_EXCLUDE_LIST])) {
         $exclusionMask = $options[XApp_Directory_Utils::OPTION_EXCLUDE_LIST];
     }
     $list = $this->_lsRemote($this->getMountManager(), $fsPath);
     //$list=$this->getFilteredDirList($path,$inclusionMask,$exclusionMask,$get_list_options);
     $ret_list = array();
     //xapp_dump($list);
     /***
      * Use 'readOnly' from the paths's resource information
      */
     $isReadOnly = null;
     /*
     if (($options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS] & XAPP_XFILE_SHOW_ISREADONLY)==XAPP_XFILE_SHOW_ISREADONLY){
         error_log('is read only');
         $instance = self::instance();
         $resource = $instance->toResource($path);
         if($resource!==null && xapp_property_exists($resource,'readOnly')){
             $isReadOnly=$resource->{XAPP_NODE_FIELD_READ_ONLY};
         }
     }
     */
     foreach ($list as $itemIn) {
         $item = new stdClass();
         $item->{XAPP_NODE_FIELD_NAME} = $itemIn[XAPP_NODE_FIELD_NAME];
         $item->{XAPP_NODE_FIELD_IS_DIRECTORY} = $itemIn['type'] === 'dir';
         if ($path != "/") {
             if (array_key_exists('size', $itemIn)) {
                 $item->{XAPP_NODE_FIELD_SIZE} = XApp_File_Utils::formatSizeUnits($itemIn[XAPP_NODE_FIELD_SIZE]);
             }
             if (array_key_exists(XAPP_NODE_FIELD_TIME, $itemIn)) {
                 $item->{XAPP_NODE_FIELD_TIME} = $itemIn[XAPP_NODE_FIELD_TIME];
             }
             if ($itemIn['type'] === 'file') {
                 $item->{XAPP_NODE_FIELD_MIME} = XApp_File_Utils::guessMime($itemIn[XAPP_NODE_FIELD_NAME]);
             }
             $item->{XAPP_NODE_FIELD_PERMISSIONS} = 'Unknown';
             $item->{XAPP_NODE_FIELD_OWNER} = array('user' => array('name' => 'Unknown'), 'group' => array('name' => 'Unknown'));
             //tell plugins, if anyone doesnt want the item, skip it
             $addItem = Xapp_Hook::trigger(self::EVENT_ON_NODE_ADD, array('item' => $item));
             if ($addItem === false) {
                 continue;
             }
             //tell plugins, if anyone doesnt want the item, skip it
             if ($options[XApp_File_Utils::OPTION_EMIT] === true) {
                 $item = Xapp_Hook::trigger(self::EVENT_ON_NODE_META_CREATED, array('item' => $item));
                 if ($item === null) {
                     continue;
                 }
             }
             //now overwrite readOnly flag
             if ($isReadOnly != null && ($options[XApp_File_Utils::OPTION_DIR_LIST_FIELDS] & XAPP_XFILE_SHOW_ISREADONLY) == XAPP_XFILE_SHOW_ISREADONLY) {
                 $item->{XAPP_NODE_FIELD_READ_ONLY} = $isReadOnly;
             }
             //tell plugins
             Xapp_Hook::trigger(self::EVENT_ON_NODE_ADDED, array('item' => $item));
         }
         $ret_list[] = $item;
     }
     return $ret_list;
 }
コード例 #6
0
ファイル: ServiceManager.php プロジェクト: xamiro-dev/xamiro
 private function completeServiceResource($resource, $fields = array())
 {
     $emits = xo_get(self::EMITS, $this) === true;
     // Defaults
     if (!isset($fields[self::FIELD_STATUS])) {
         $fields[self::FIELD_STATUS] = true;
     }
     if (!isset($fields[self::FIELD_INFO])) {
         $fields[self::FIELD_INFO] = true;
     }
     if (!isset($fields[self::FIELD_CLIENTS])) {
         $fields[self::FIELD_CLIENTS] = true;
     }
     if (!isset($fields[self::FIELD_CHILD_PROCESSES])) {
         $fields[self::FIELD_CHILD_PROCESSES] = true;
     }
     if (!isset($fields[self::FIELD_OPTIONS])) {
         $fields[self::FIELD_OPTIONS] = false;
     }
     $resource->clients = 0;
     $resource->status = self::SERVICE_STATUS_UNKNOWN;
     //default to unknown
     //check status
     if ($fields[self::FIELD_STATUS] === true && property_exists($resource, 'port') && property_exists($resource, 'host')) {
         if (xo_get(self::REWRITE_HOST, $this) && property_exists($resource, 'host')) {
             //$resolved = '192.168.1.37'; //$this->getVariableDelegate()->resolveAbsolute(xapp_property_get($service,'SERVER_IP'));
             $host = gethostname();
             $resolved = gethostbyname($host);
             if (xo_get(self::FORCE_HOST, $this) && strlen(xo_get(self::FORCE_HOST, $this)) > 0) {
                 //error_log('force host : ' . xo_get(self::FORCE_HOST,$this));
                 $resolved = xo_get(self::FORCE_HOST, $this);
             }
             if ($resolved && strlen($resolved)) {
                 $resource->host = $resolved;
             }
         }
         if (self::_isTCPListening($resource->host, $resource->port)) {
             $resource->status = self::SERVICE_STATUS_ONLINE;
         } else {
             $resource->status = self::SERVICE_STATUS_OFFLINE;
         }
     }
     //check info
     if ($fields[self::FIELD_INFO] === true) {
         $info = $this->getServiceInfo($resource);
         if ($info) {
             $resource->info = $info;
             //can be string or object
         }
     }
     //check options
     if ($fields[self::FIELD_OPTIONS] === true && property_exists($resource, 'main') && property_exists($resource, 'has') && property_exists($resource->has, 'options')) {
         $options = $this->getServiceOptions($resource, $resource->has->options);
         if ($options) {
             $resource->options = $options;
             //can be string or object
         }
     }
     //list child processes
     if ($fields[self::FIELD_CHILD_PROCESSES] === true && $resource->status == self::SERVICE_STATUS_ONLINE && isset($resource->main)) {
         //get processes for command "node", filtered by "resource->main"
         $ps_list = XApp_Shell_Utils::getProcesses("node", array(XApp_Shell_Utils::OPTION_FILTER_PROCESSES => $resource->main, XApp_Shell_Utils::OPTION_RETURN_PROCESSES_TREE => true));
         $resource->clients = count($ps_list);
         $resource->ps_tree = $ps_list;
     }
     //tell everyone
     if ($emits) {
         Xapp_Hook::trigger(self::EVENT_ON_NODE_META_CREATED, array('item' => $resource));
     }
 }
コード例 #7
0
ファイル: UserManager.php プロジェクト: xamiro-dev/xamiro
 /**
  * Removes the user from memory, permanent storage (if set) and session storage (if set)
  *
  * @param $userName
  */
 public function removeUser($userName)
 {
     if (isset($this->_users->{$userName})) {
         // Trigger HOOK_REMOVE_USER
         Xapp_Hook::trigger(self::HOOK_REMOVE_USER, array('user' => $this->getUser($userName), 'userName' => $userName, 'instance' => $this));
         unset($this->_users->{$userName});
         $this->save();
         // re-init session storage if initialized, removing the user from the authenticator
         $this->refreshSessionStorage();
     }
 }