private function getSource(FileEvent $e) { $source = $e->getSource(); if (!$source instanceof IShareableFile) { throw new EyeInvalidArgumentException('Source of event is not a IShareableFile.'); } return $source; }
private function onExtract() { $data = $this->request->data; if (!array_key_exists("item", $data)) { throw $this->invalidRequestException(); } $overwrite = isset($data['overwrite']) ? $data['overwrite'] : FALSE; $archive = $this->item($data["item"]); $this->env->filesystem()->assertRights($archive, FilesystemController::PERMISSION_LEVEL_READ, "extract"); $parent = NULL; if (isset($data["folder"])) { $this->item($data["folder"]); } else { $parent = $archive->parent(); } $this->env->filesystem()->assertRights($parent, FilesystemController::PERMISSION_LEVEL_READWRITE, "extract"); $name = str_replace(".", "_", basename($archive->internalPath())); $target = $parent->folderWithName($name); if ($target->exists() and !$overwrite) { throw new ServiceException("DIR_ALREADY_EXISTS", $target); } //$target = $parent->internalPath() . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR; $this->env->filesystem()->validateAction(FileEvent::CREATE_ITEM, $target); $this->env->filesystem()->triggerActionInterceptor(FileEvent::CREATE_ITEM, $target); if ($target->exists() and $overwrite) { $target->delete(); } $this->env->filesystem()->createItem($target); $this->archiveManager()->extract($archive->internalPath(), $target->internalPath()); $this->env->events()->onEvent(FileEvent::createItem($target)); $this->response()->success(array()); }
public function onAction($ac, $item) { if (FileEvent::DOWNLOAD != $ac or $item == NULL or !$item->isFile()) { return; } $user = $this->env->session()->user(); if (!$user) { return; } $excludeUsers = $this->getSetting("exclude_users"); if ($excludeUsers != NULL) { if (in_array($user["id"], $excludeUsers)) { Logging::logDebug("User excluded, ignoring: " . $user["id"]); return; } } $excludeGroups = $this->getSetting("exclude_groups"); if ($excludeGroups != NULL) { $groups = $this->env->session()->userGroups(); if ($groups != NULL) { foreach ($groups as $g) { if (in_array($g["id"], $excludeGroups)) { Logging::logDebug("User group excluded, ignoring: " . $g["id"]); return; } } } } $type = $item->extension(); if (!$type or strlen($type) == 0) { return; } $types = $this->getSetting("types"); if ($types == NULL or !array_key_exists($type, $types)) { return; } $watermark = $this->getWatermarkText($item, $user); if (!$watermark) { return; } $marker = $this->getMarker($type, $types[$type]); if (!$marker) { return; } $original = $item->internalPath(); $file = $this->getTempFile($item, $type); Logging::logDebug("Watermarking [" . $original . "] -> temp [" . $file . "], mark [" . $watermark . "]"); $marked = $marker->mark($original, $file, $watermark); if (!$marked) { return; } $handle = @fopen($file, "rb"); if (!$handle) { throw new ServiceException("REQUEST_FAILED", "Could not open file for reading: " . $file); } //TODO range support $mobile = ($this->env->request()->hasParam("m") and strcmp($this->env->request()->param("m"), "1") == 0); $this->env->events()->onEvent(FileEvent::download($item)); $this->env->response()->download($item->name(), $type, $mobile, $handle); unlink($file); return TRUE; }
public function uploadFrom($folder, $name, $stream, $src = '[Unknown]') { $this->assertUploadFileType($name); $this->assertRights($folder, self::PERMISSION_LEVEL_READWRITE, "upload"); $targetItem = $folder->createFile($name); if (Logging::isDebug()) { Logging::logDebug("Upload from {$src} ({$name}) to " . $targetItem->id()); } $targetItem->write($stream, FALSE); $this->env->events()->onEvent(FileEvent::upload($targetItem)); }
private function onDownloadCompressed() { $data = $this->request->data; if (!array_key_exists("items", $data)) { throw $this->invalidRequestException(); } if (!is_array($data['items']) || count($data['items']) < 1) { throw $this->invalidRequestException(); } $items = array(); foreach ($data['items'] as $i) { $items[] = $this->item($i); } if (count($items) == 0) { throw $this->invalidRequestException(); } $this->env->filesystem()->assertRights($items, Authentication::RIGHTS_READ, "download compressed"); $a = $this->archiveManager()->compress($items); $id = uniqid(); $this->env->session()->param("archive_" . $id, $a); if (is_array($items)) { $this->env->events()->onEvent(MultiFileEvent::download($items)); } else { $this->env->events()->onEvent(FileEvent::download($items)); } $this->response()->success(array("id" => $id)); }
private function processDeleteFolders() { if (count($this->path) < 1 or count($this->path) > 2) { throw $this->invalidRequestException(); } $roots = $this->env->filesystem()->getRootFoldersByKey(TRUE); // configuration/folders if (count($this->path) == 1) { $data = $this->request->data; if (!isset($data['ids'])) { throw $this->invalidRequestException(); } $ids = $data['ids']; if (!$ids or !is_array($ids) or count($ids) == 0) { throw $this->invalidRequestException(); } foreach ($ids as $id) { if (!array_key_exists($id, $roots)) { throw $this->invalidRequestException("Invalid root " . $id); } $folder = $roots[$id]; $this->env->configuration()->removeFolder($id); } $this->response()->success(TRUE); return; } $id = $this->path[1]; if (!array_key_exists($id, $roots)) { throw $this->invalidRequestException("Invalid root " . $id); } $folder = $roots[$id]; if ($this->request->hasParam("delete") and strcasecmp("true", $this->request->param("delete")) == 0) { $this->env->filesystem()->delete($folder, TRUE); } $this->env->configuration()->removeFolder($id); $this->env->events()->onEvent(FileEvent::delete($folder)); $this->response()->success($this->getSessionFolderInfo()); }
public function fileWritten(FileEvent $e) { $file = $e->getSource(); $meta = null; $activity = null; $by = null; self::initContext($file, $meta, $activity, $by); // On virtual files, creating a file by adding content consist in 2 different operations and // therefore may create 2 different activities, so we avoid that by the following condition // checking that the creation of the file has been performed more than 5 seconds ago. $lastActivity = end($activity); if (is_array($lastActivity) && $lastActivity['type'] == 'creation' && $e->getTimeStamp() - $lastActivity['time'] < 5) { return; } $activity[] = array('type' => 'edition', 'by' => $by->getId(), 'time' => $e->getTimeStamp()); $meta->set('activity', $activity); $meta->set(EyeosAbstractVirtualFile::METADATA_KEY_MODIFICATIONTIME, $e->getTimeStamp()); $file->setMeta($meta); }
public function fileWritten(FileEvent $e) { if ($e->getSource() instanceof EyeUserFile) { SearchFileRecollPlugin::callRecollIndex($e->getSource()->getRealFile(), '-i'); } }
public function fileWritten(FileEvent $e) { //Logger::getLogger('sebas')->error('MetadataWritten:' . $e->getSource()->getPath()); $apiManager = new ApiManager(); $path = $e->getSource()->getPath(); $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $userName = $user->getName(); $cloud = $this->isCloud($path, $userName); $resourceUrl = null; if ($cloud->isCloud) { $pathU1db = substr($path, strlen($cloud->path)); $lenfinal = strrpos($pathU1db, $e->getSource()->getName()); $posfinal = $lenfinal > 1 ? $lenfinal - strlen($pathU1db) - 1 : $lenfinal - strlen($pathU1db); $pathParent = substr($pathU1db, 0, $posfinal); $folder = NULL; if ($pathParent !== '/') { $pos = strrpos($pathParent, '/'); $folder = substr($pathParent, $pos + 1); $pathParent = substr($pathParent, 0, $pos + 1); } $parentId = false; if ($folder !== NULL) { $path = $pathParent . $folder . '/'; $lista = new stdClass(); $lista->cloud = $cloud->name; $lista->path = $pathParent; $lista->filename = $folder; $lista->user_eyeos = $user->getId(); $u1db = json_decode($apiManager->callProcessU1db('parent', $lista)); if ($u1db !== NULL && count($u1db) > 0) { $parentId = $u1db[0]->id; if (isset($u1db[0]->resource_url)) { $resourceUrl = new stdClass(); $resourceUrl->resource_url = $u1db[0]->resource_url; $resourceUrl->token = new stdClass(); $resourceUrl->token->key = $u1db[0]->access_token_key; $resourceUrl->token->secret = $u1db[0]->access_token_secret; if ($parentId === 'null') { $parentId = 0; } } } } else { $parentId = '0'; $path = $pathParent; } if ($parentId !== false) { $pathAbsolute = AdvancedPathLib::getPhpLocalHackPath($e->getSource()->getRealFile()->getAbsolutePath()); $token = $_SESSION['access_token_' . $cloud->name . '_v2']; if ($resourceUrl) { $token = $resourceUrl->token; $resourceUrl = $resourceUrl->resource_url; } $result = $apiManager->createMetadata($cloud->name, $token, $user->getId(), true, $e->getSource()->getName(), $parentId, $path, $pathAbsolute, $resourceUrl); if ($result['status'] == 'OK') { $params = array($e->getSource()->getParentPath(), $e->getSource()->getPath()); $message = new ClientBusMessage('file', 'refreshStackSync', $params); ClientMessageBusController::getInstance()->queueMessage($message); } else { if ($result['error'] == 403) { $path = $this->cleanCloud($cloud->name, $user); $params = array($path, $cloud->name); $message = new ClientBusMessage('file', 'permissionDenied', $params); ClientMessageBusController::getInstance()->queueMessage($message); } } } } }