function crossRepositoryCopy($httpVars) { ConfService::detectRepositoryStreams(true); $mess = ConfService::getMessages(); $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); $files = $selection->getFiles(); $accessType = $this->repository->getAccessType(); $repositoryId = $this->repository->getId(); $plugin = AJXP_PluginsService::findPlugin("access", $accessType); $origWrapperData = $plugin->detectStreamWrapper(true); $origStreamURL = $origWrapperData["protocol"] . "://{$repositoryId}"; $destRepoId = $httpVars["dest_repository_id"]; $destRepoObject = ConfService::getRepositoryById($destRepoId); $destRepoAccess = $destRepoObject->getAccessType(); $plugin = AJXP_PluginsService::findPlugin("access", $destRepoAccess); $destWrapperData = $plugin->detectStreamWrapper(true); $destStreamURL = $destWrapperData["protocol"] . "://{$destRepoId}"; // Check rights if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if (!$loggedUser->canRead($repositoryId) || !$loggedUser->canWrite($destRepoId) || isset($httpVars["moving_files"]) && !$loggedUser->canWrite($repositoryId)) { throw new Exception($mess[364]); } } $messages = array(); foreach ($files as $file) { $origFile = $origStreamURL . $file; $localName = ""; AJXP_Controller::applyHook("dl.localname", array($origFile, &$localName, $origWrapperData["classname"])); $bName = basename($file); if ($localName != "") { $bName = $localName; } $destFile = $destStreamURL . SystemTextEncoding::fromUTF8($httpVars["dest"]) . "/" . $bName; AJXP_Logger::debug("Copying {$origFile} to {$destFile}"); if (!is_file($origFile)) { throw new Exception("Cannot find {$origFile}"); } $origHandler = fopen($origFile, "r"); $destHandler = fopen($destFile, "w"); if ($origHandler === false || $destHandler === false) { $errorMessages[] = AJXP_XMLWriter::sendMessage(null, $mess[114] . " ({$origFile} to {$destFile})", false); continue; } while (!feof($origHandler)) { fwrite($destHandler, fread($origHandler, 4096)); } fflush($destHandler); fclose($origHandler); fclose($destHandler); $messages[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($origFile)) . " " . (isset($httpVars["moving_files"]) ? $mess[74] : $mess[73]) . " " . SystemTextEncoding::toUTF8($destFile); } AJXP_XMLWriter::header(); if (count($errorMessages)) { AJXP_XMLWriter::sendMessage(null, join("\n", $errorMessages), true); } AJXP_XMLWriter::sendMessage(join("\n", $messages), null, true); AJXP_XMLWriter::close(); }
function crossRepositoryCopy($httpVars) { ConfService::detectRepositoryStreams(true); $mess = ConfService::getMessages(); $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); $files = $selection->getFiles(); $accessType = $this->repository->getAccessType(); $repositoryId = $this->repository->getId(); $origStreamURL = "ajxp.{$accessType}://{$repositoryId}"; $destRepoId = $httpVars["dest_repository_id"]; $destRepoObject = ConfService::getRepositoryById($destRepoId); $destRepoAccess = $destRepoObject->getAccessType(); $destStreamURL = "ajxp.{$destRepoAccess}://{$destRepoId}"; // Check rights if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if (!$loggedUser->canRead($repositoryId) || !$loggedUser->canWrite($destRepoId)) { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, "You do not have the right to access one of the repositories!"); AJXP_XMLWriter::close(); exit(1); } } $messages = array(); foreach ($files as $file) { $origFile = $origStreamURL . $file; $destFile = $destStreamURL . $httpVars["dest"] . "/" . basename($file); $origHandler = fopen($origFile, "r"); $destHandler = fopen($destFile, "w"); if ($origHandler === false || $destHandler === false) { $errorMessages[] = AJXP_XMLWriter::sendMessage(null, $mess[114] . " ({$origFile} to {$destFile})", false); continue; } while (!feof($origHandler)) { fwrite($destHandler, fread($origHandler, 4096)); } fflush($destHandler); fclose($origHandler); fclose($destHandler); $messages[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($origFile)) . " " . $mess[73] . " " . SystemTextEncoding::toUTF8($destFile); } AJXP_XMLWriter::header(); if (count($errorMessages)) { AJXP_XMLWriter::sendMessage(null, join("\n", $errorMessages), true); } AJXP_XMLWriter::sendMessage(join("\n", $messages), null, true); AJXP_XMLWriter::close(); exit(0); }
public function crossRepositoryCopy($httpVars) { ConfService::detectRepositoryStreams(true); $mess = ConfService::getMessages(); $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); $files = $selection->getFiles(); $accessType = $this->repository->getAccessType(); $repositoryId = $this->repository->getId(); $plugin = AJXP_PluginsService::findPlugin("access", $accessType); $origWrapperData = $plugin->detectStreamWrapper(true); $origStreamURL = $origWrapperData["protocol"] . "://{$repositoryId}"; $destRepoId = $httpVars["dest_repository_id"]; $destRepoObject = ConfService::getRepositoryById($destRepoId); $destRepoAccess = $destRepoObject->getAccessType(); $plugin = AJXP_PluginsService::findPlugin("access", $destRepoAccess); $plugin->repository = $destRepoObject; $destWrapperData = $plugin->detectStreamWrapper(true); $destStreamURL = $destWrapperData["protocol"] . "://{$destRepoId}"; // Check rights if (AuthService::usersEnabled()) { $loggedUser = AuthService::getLoggedUser(); if (!$loggedUser->canRead($repositoryId) || !$loggedUser->canWrite($destRepoId) || isset($httpVars["moving_files"]) && !$loggedUser->canWrite($repositoryId)) { throw new Exception($mess[364]); } } $srcRepoData = array('base_url' => $origStreamURL, 'wrapper_name' => $origWrapperData['classname'], 'recycle' => $this->repository->getOption("RECYCLE_BIN")); $destRepoData = array('base_url' => $destStreamURL, 'wrapper_name' => $destWrapperData['classname'], 'chmod' => $this->repository->getOption('CHMOD')); $messages = array(); $errorMessages = array(); foreach ($files as $file) { $this->copyOrMoveFile(AJXP_Utils::decodeSecureMagic($httpVars["dest"]), $file, $errorMessages, $messages, isset($httpVars["moving_files"]) ? true : false, $srcRepoData, $destRepoData); } AJXP_XMLWriter::header(); if (count($errorMessages)) { AJXP_XMLWriter::sendMessage(null, join("\n", $errorMessages), true); } AJXP_XMLWriter::sendMessage(join("\n", $messages), null, true); AJXP_XMLWriter::close(); }
/** * See static method * @param Repository $repository * @throws AJXP_Exception|Exception * @return AbstractAccessDriver */ public function loadRepositoryDriverREST(&$repository) { if (isset($repository->driverInstance)) { return $repository->driverInstance; } $accessType = $repository->getAccessType(); $pServ = AJXP_PluginsService::getInstance(); $plugInstance = $pServ->getPluginByTypeName("access", $accessType); // TRIGGER BEFORE INIT META $metaSources = $repository->getOption("META_SOURCES"); if (isset($metaSources) && is_array($metaSources) && count($metaSources)) { $keys = array_keys($metaSources); foreach ($keys as $plugId) { if ($plugId == "") { continue; } $instance = $pServ->getPluginById($plugId); if (!is_object($instance)) { continue; } if (!method_exists($instance, "beforeInitMeta")) { continue; } try { $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId())); $instance->beforeInitMeta($plugInstance, $repository); } catch (Exception $e) { AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage()); $this->errors[] = $e->getMessage(); } } } // INIT MAIN DRIVER $plugInstance->init($repository); try { $plugInstance->initRepository(); } catch (Exception $e) { throw $e; } AJXP_PluginsService::deferBuildingRegistry(); $pServ->setPluginUniqueActiveForType("access", $accessType); // TRIGGER INIT META $metaSources = $repository->getOption("META_SOURCES"); if (isset($metaSources) && is_array($metaSources) && count($metaSources)) { $keys = array_keys($metaSources); foreach ($keys as $plugId) { if ($plugId == "") { continue; } $split = explode(".", $plugId); $instance = $pServ->getPluginById($plugId); if (!is_object($instance)) { continue; } try { $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId())); if (!method_exists($instance, "initMeta")) { throw new Exception("Meta Source {$plugId} does not implement the initMeta method."); } $instance->initMeta($plugInstance); } catch (Exception $e) { AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage()); $this->errors[] = $e->getMessage(); } $pServ->setPluginActive($split[0], $split[1]); } } AJXP_PluginsService::flushDeferredRegistryBuilding(); if (count($this->errors) > 0) { $e = new AJXP_Exception("Error while loading repository feature : " . implode(",", $this->errors)); throw $e; } $repository->driverInstance = $plugInstance; if (isset($_SESSION["REPO_ID"]) && $_SESSION["REPO_ID"] == $repository->getId()) { $this->configs["REPOSITORY"] = $repository; if (is_array($this->configs["REPOSITORIES"])) { $this->configs["REPOSITORIES"][$_SESSION['REPO_ID']] = $repository; } } return $plugInstance; }
/** The publiclet URL making */ function makePubliclet($filePath, $password, $expire) { $data = array("DRIVER" => $this->repository->getAccessType(), "OPTIONS" => NULL, "FILE_PATH" => $filePath, "ACTION" => "download", "EXPIRE_TIME" => $expire ? time() + $expire * 86400 : 0, "PASSWORD" => $password); return $this->writePubliclet($data); }
/** * Will try to get the credentials for a given repository as follow : * + Try to get the credentials from the url parsing * + Try to get them from the user "Wallet" (personal data) * + Try to get them from the repository configuration * + Try to get them from the AJXP_Safe. * * @param array $parsedUrl * @param Repository $repository * @return array */ public static function tryLoadingCredentialsFromSources($parsedUrl, $repository) { $user = $password = ""; $optionsPrefix = ""; if ($repository->getAccessType() == "ftp") { $optionsPrefix = "FTP_"; } // Get USER/PASS // 1. Try from URL if (isset($parsedUrl["user"]) && isset($parsedUrl["pass"])) { $user = rawurldecode($parsedUrl["user"]); $password = rawurldecode($parsedUrl["pass"]); } // 2. Try from user wallet if ($user == "") { $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null) { $wallet = $loggedUser->getPref("AJXP_WALLET"); if (is_array($wallet) && isset($wallet[$repository->getId()][$optionsPrefix . "USER"])) { $user = $wallet[$repository->getId()][$optionsPrefix . "USER"]; $password = $loggedUser->decodeUserPassword($wallet[$repository->getId()][$optionsPrefix . "PASS"]); } } } // 2bis. Wallet is now a custom parameter if ($user == "") { $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null) { $u = $loggedUser->mergedRole->filterParameterValue("access." . $repository->getAccessType(), $optionsPrefix . "USER", $repository->getId(), ""); $p = $loggedUser->mergedRole->filterParameterValue("access." . $repository->getAccessType(), $optionsPrefix . "PASS", $repository->getId(), ""); if (!empty($u) && !empty($p)) { $user = $u; $password = $loggedUser->decodeUserPassword($p); } } } // 3. Try from repository config if ($user == "") { $user = $repository->getOption($optionsPrefix . "USER"); $password = $repository->getOption($optionsPrefix . "PASS"); } // 4. Test if there are encoded credentials available if ($user == "" && $repository->getOption("ENCODED_CREDENTIALS") != "") { list($user, $password) = AJXP_Safe::getCredentialsFromEncodedString($repository->getOption("ENCODED_CREDENTIALS")); } // 5. Try from session $storeCreds = false; if ($repository->getOption("META_SOURCES")) { $options["META_SOURCES"] = $repository->getOption("META_SOURCES"); foreach ($options["META_SOURCES"] as $metaSource) { if (isset($metaSource["USE_SESSION_CREDENTIALS"]) && $metaSource["USE_SESSION_CREDENTIALS"] === true) { $storeCreds = true; break; } } } if ($user == "" && ($repository->getOption("USE_SESSION_CREDENTIALS") || $storeCreds || self::getInstance()->forceSessionCredentials)) { $safeCred = AJXP_Safe::loadCredentials(); if ($safeCred !== false) { $user = $safeCred["user"]; $password = $safeCred["password"]; } } return array("user" => $user, "password" => $password); }
/** * Will try to get the credentials for a given repository as follow : * + Try to get the credentials from the url parsing * + Try to get them from the user "Wallet" (personal data) * + Try to get them from the repository configuration * + Try to get them from the AJXP_Safe. * * @param array $parsedUrl * @param Repository $repository * @return array */ public static function tryLoadingCredentialsFromSources($parsedUrl, $repository) { $user = $password = ""; $optionsPrefix = ""; if ($repository->getAccessType() == "ftp") { $optionsPrefix = "FTP_"; } // Get USER/PASS // 1. Try from URL if (isset($parsedUrl["user"]) && isset($parsedUrl["pass"])) { $user = rawurldecode($parsedUrl["user"]); $password = rawurldecode($parsedUrl["pass"]); } // 2. Try from user wallet if ($user == "") { $loggedUser = AuthService::getLoggedUser(); if ($loggedUser != null) { $wallet = $loggedUser->getPref("AJXP_WALLET"); if (is_array($wallet) && isset($wallet[$repository->getId()][$optionsPrefix . "USER"])) { $user = $wallet[$repository->getId()][$optionsPrefix . "USER"]; $password = $loggedUser->decodeUserPassword($wallet[$repository->getId()][$optionsPrefix . "PASS"]); } } } // 3. Try from repository config if ($user == "") { $user = $repository->getOption($optionsPrefix . "USER"); $password = $repository->getOption($optionsPrefix . "PASS"); } // 4. Test if there are encoded credentials available if ($user == "" && $repository->getOption("ENCODED_CREDENTIALS") != "") { list($user, $password) = AJXP_Safe::getCredentialsFromEncodedString($repository->getOption("ENCODED_CREDENTIALS")); } // 5. Try from session if ($user == "" && ($repository->getOption("USE_SESSION_CREDENTIALS") || self::getInstance()->forceSessionCredentials)) { $safeCred = AJXP_Safe::loadCredentials(); if ($safeCred !== false) { $user = $safeCred["user"]; $password = $safeCred["password"]; } } return array("user" => $user, "password" => $password); }