/** * Initialize the stream from the given path. * * @param string $path * @param $streamType * @param bool $storeOpenContext * @param bool $skipZip * @return mixed Real path or -1 if currentListing contains the listing : original path converted to real path * @throws AJXP_Exception * @throws Exception */ protected static function initPath($path, $streamType, $storeOpenContext = false, $skipZip = false) { $path = self::unPatchPathForBaseDir($path); $url = AJXP_Utils::safeParseUrl($path); $repoId = $url["host"]; $test = trim($url["path"], "/"); $atRoot = empty($test); $repoObject = ConfService::getRepositoryById($repoId); if (!isset($repoObject)) { throw new Exception("Cannot find repository with id " . $repoId); } $split = UserSelection::detectZip($url["path"]); $insideZip = false; if ($split && $streamType == "file" && $split[1] != "/") { $insideZip = true; } if ($split && $streamType == "dir") { $insideZip = true; } if ($skipZip) { $insideZip = false; } $resolveUser = null; if (isset($url["user"]) && AuthService::usersEnabled()) { $resolveUser = ConfService::getConfStorageImpl()->createUserObject($url["user"]); } $resolvedPath = realpath(SystemTextEncoding::toStorageEncoding($repoObject->getOption("PATH", false, $resolveUser))); //var_dump($path); //var_dump($skipZip); // Inside a zip : copy the file to a tmp file and return a reference to it if ($insideZip) { $zipPath = $split[0]; $localPath = $split[1]; require_once AJXP_BIN_FOLDER . "/pclzip.lib.php"; //print($streamType.$path); if ($streamType == "file") { if (self::$crtZip == null || !is_array(self::$currentListingKeys)) { $tmpDir = AJXP_Utils::getAjxpTmpDir() . DIRECTORY_SEPARATOR . md5(time() - rand()); mkdir($tmpDir); $tmpFileName = $tmpDir . DIRECTORY_SEPARATOR . basename($localPath); AJXP_Logger::debug(__CLASS__, __FUNCTION__, "Tmp file {$tmpFileName}"); register_shutdown_function(array("fsAccessWrapper", "removeTmpFile"), $tmpDir, $tmpFileName); $crtZip = new PclZip(AJXP_Utils::securePath($resolvedPath . $repoObject->resolveVirtualRoots($zipPath))); $content = $crtZip->listContent(); if (is_array($content)) { foreach ($content as $item) { $fName = AJXP_Utils::securePath($item["stored_filename"]); if ($fName == $localPath || "/" . $fName == $localPath) { $localPath = $fName; break; } } } $crtZip->extract(PCLZIP_OPT_BY_NAME, $localPath, PCLZIP_OPT_PATH, $tmpDir, PCLZIP_OPT_REMOVE_ALL_PATH); AJXP_Logger::debug(__CLASS__, __FUNCTION__, "Extracted " . $path . " to " . dirname($localPath)); if ($storeOpenContext) { self::$crtZip = $crtZip; } return $tmpFileName; } else { $key = basename($localPath); if (array_key_exists($key, self::$currentListing)) { self::$currentFileKey = $key; return -1; } else { throw new AJXP_Exception("Cannot find key"); } } } else { $crtZip = new PclZip(AJXP_Utils::securePath($resolvedPath . $repoObject->resolveVirtualRoots($zipPath))); $liste = $crtZip->listContent(); if (!is_array($liste)) { $liste = array(); } if ($storeOpenContext) { self::$crtZip = $crtZip; } $folders = array(); $files = array(); $builtFolders = array(); if ($localPath[strlen($localPath) - 1] != "/") { $localPath .= "/"; } foreach ($liste as $item) { $stored = $item["stored_filename"]; if ($stored[0] != "/") { $stored = "/" . $stored; } $pathPos = strpos($stored, $localPath); if ($pathPos !== false) { $afterPath = substr($stored, $pathPos + strlen($localPath)); if ($afterPath != "" && substr_count($afterPath, "/") < 2) { $statValue = array(); if (substr_count($afterPath, "/") == 0) { $statValue[2] = $statValue["mode"] = $item["folder"] ? 040555 : 0100555; $statValue[7] = $statValue["size"] = $item["size"]; $statValue[8] = $statValue["atime"] = $item["mtime"]; $statValue[9] = $statValue["mtime"] = $item["mtime"]; $statValue[10] = $statValue["ctime"] = $item["mtime"]; if (strpos($afterPath, "/") == strlen($afterPath) - 1) { $afterPath = substr($afterPath, 0, strlen($afterPath) - 1); } //$statValue["filename"] = $zipPath.$localPath.$afterPath; if ($item["folder"]) { $folders[$afterPath] = $statValue; } else { $files[$afterPath] = $statValue; } } else { $arr = explode("/", $afterPath); $afterPath = array_shift($arr); if (isset($folders[$afterPath]) || isset($builtFolders[$afterPath])) { continue; } $statValue[2] = $statValue["mode"] = 040555; $statValue[7] = $statValue["size"] = 0; $statValue[8] = $statValue["atime"] = $item["mtime"]; $statValue[9] = $statValue["mtime"] = $item["mtime"]; $statValue[10] = $statValue["ctime"] = $item["mtime"]; $builtFolders[$afterPath] = $statValue; } } } } self::$currentListing = array_merge($folders, $builtFolders, $files); self::$currentListingKeys = array_keys(self::$currentListing); self::$currentListingIndex = 0; return -1; } } else { if ($atRoot) { $virtual = $repoObject->listVirtualRoots(); if (count($virtual)) { self::$currentListing = array(); foreach ($virtual as $rootKey => $rootValue) { $statValue = array(); $statValue[2] = $statValue["mode"] = 040000; //($rootValue["right"] == "rw" ? "00040000" : "00070000"); self::$currentListing[$rootKey] = $statValue; } self::$currentListingKeys = array_keys(self::$currentListing); self::$currentListingIndex = 0; return -1; } } return $resolvedPath . $repoObject->resolveVirtualRoots($url["path"]); } }
public function makeSharedRepositoryOptions($httpVars, $repository) { $newOptions = array("PATH" => SystemTextEncoding::toStorageEncoding($repository->getOption("PATH")) . AJXP_Utils::decodeSecureMagic($httpVars["file"]), "CREATE" => isset($httpVars["inherit_recycle"]) ? $repository->getOption("CREATE") : false, "RECYCLE_BIN" => isset($httpVars["inherit_recycle"]) ? $repository->getOption("RECYCLE_BIN") : "", "DEFAULT_RIGHTS" => ""); if ($repository->getOption("USE_SESSION_CREDENTIALS") === true) { $newOptions["ENCODED_CREDENTIALS"] = AJXP_Safe::getEncodedCredentialString(); } return $newOptions; }
/** * @param AJXP_Node $node * @param String|null $direction "UP", "DOWN" * @return array() */ private function findMirrorNodesInShares($node, $direction) { $result = array(); if ($direction !== "UP") { $upmetas = array(); $this->getShareStore()->getMetaManager()->collectSharesInParent($node, $upmetas); foreach ($upmetas as $metadata) { if (is_array($metadata) && !empty($metadata["shares"])) { foreach ($metadata["shares"] as $sId => $sData) { $type = $sData["type"]; if ($type == "file") { continue; } $wsId = $sId; if ($type == "minisite") { $minisiteData = $this->getShareStore()->loadShare($sId); if (empty($minisiteData) || !isset($minisiteData["REPOSITORY"])) { continue; } $wsId = $minisiteData["REPOSITORY"]; } else { if ($type == "ocs_remote") { continue; } } $sharedNode = $metadata["SOURCE_NODE"]; $sharedPath = substr($node->getPath(), strlen($sharedNode->getPath())); $sharedNodeUrl = $node->getScheme() . "://" . $wsId . $sharedPath; $result[$wsId] = array(new AJXP_Node($sharedNodeUrl), "DOWN"); $this->logDebug('MIRROR NODES', 'Found shared in parent - register node ' . $sharedNodeUrl); } } } } if ($direction !== "DOWN") { if ($node->getRepository()->hasParent()) { $parentRepoId = $node->getRepository()->getParentId(); $parentRepository = ConfService::getRepositoryById($parentRepoId); if (!empty($parentRepository) && !$parentRepository->isTemplate) { $currentRoot = $node->getRepository()->getOption("PATH"); $owner = $node->getRepository()->getOwner(); $resolveUser = null; if ($owner != null) { $resolveUser = ConfService::getConfStorageImpl()->createUserObject($owner); } $parentRoot = $parentRepository->getOption("PATH", false, $resolveUser); $relative = substr($currentRoot, strlen($parentRoot)); $relative = SystemTextEncoding::toStorageEncoding($relative); $parentNodeURL = $node->getScheme() . "://" . $parentRepoId . $relative . $node->getPath(); $this->logDebug("action.share", "Should trigger on " . $parentNodeURL); $parentNode = new AJXP_Node($parentNodeURL); if ($owner != null) { $parentNode->setUser($owner); } $result[$parentRepoId] = array($parentNode, "UP"); } } } return $result; }
public function makeSharedRepositoryOptions($httpVars, $repository) { $newOptions = array("PATH" => SystemTextEncoding::toStorageEncoding($repository->getOption("PATH")) . AJXP_Utils::decodeSecureMagic($httpVars["file"]), "CREATE" => $repository->getOption("CREATE"), "RECYCLE_BIN" => isset($httpVars["inherit_recycle"]) ? $repository->getOption("RECYCLE_BIN") : "", "DEFAULT_RIGHTS" => "", "DATA_TEMPLATE" => ""); if ($repository->getOption("USE_SESSION_CREDENTIALS") === true) { $newOptions["ENCODED_CREDENTIALS"] = AJXP_Safe::getEncodedCredentialString(); } $customData = array(); foreach ($httpVars as $key => $value) { if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") { $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value; } } if (count($customData)) { $newOptions["PLUGINS_DATA"] = $customData; } if ($repository->getOption("META_SOURCES")) { $newOptions["META_SOURCES"] = $repository->getOption("META_SOURCES"); foreach ($newOptions["META_SOURCES"] as $index => &$data) { if (isset($data["USE_SESSION_CREDENTIALS"]) && $data["USE_SESSION_CREDENTIALS"] === true) { $newOptions["META_SOURCES"][$index]["ENCODED_CREDENTIALS"] = AJXP_Safe::getEncodedCredentialString(); } } AJXP_Controller::applyHook("workspace.share_metasources", array(&$newOptions["META_SOURCES"])); } return $newOptions; }