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; }
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)); } }
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; }
/** * 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(); } }