protected function parseUrl($url, $forceLogin = false) { // URL MAY BE ajxp.ftp://username:password@host/path $urlParts = AJXP_Utils::safeParseUrl($url); $this->repositoryId = $urlParts["host"]; $repository = ConfService::getRepositoryById($this->repositoryId); if ($repository == null) { throw new Exception("Cannot find repository for dynamic ftp authentification."); } $credentials = AJXP_Safe::tryLoadingCredentialsFromSources($urlParts, $repository); $this->user = $credentials["user"]; $this->password = $credentials["password"]; if ($this->user == "") { throw new AJXP_Exception("Cannot find user/pass for FTP access!"); } if ($repository->getOption("DYNAMIC_FTP") == "TRUE" && isset($_SESSION["AJXP_DYNAMIC_FTP_DATA"])) { $data = $_SESSION["AJXP_DYNAMIC_FTP_DATA"]; $this->host = $data["FTP_HOST"]; $this->path = $data["PATH"]; $this->secure = $data["FTP_SECURE"] == "TRUE" ? true : false; $this->port = $data["FTP_PORT"] != "" ? intval($data["FTP_PORT"]) : ($this->secure ? 22 : 21); $this->ftpActive = $data["FTP_DIRECT"] == "TRUE" ? true : false; $this->repoCharset = $data["CHARSET"]; } else { $this->host = $repository->getOption("FTP_HOST"); $this->path = $repository->getOption("PATH"); $this->secure = $repository->getOption("FTP_SECURE") == "TRUE" ? true : false; $this->port = $repository->getOption("FTP_PORT") != "" ? intval($repository->getOption("FTP_PORT")) : ($this->secure ? 22 : 21); $this->ftpActive = $repository->getOption("FTP_DIRECT") == "TRUE" ? true : false; $this->repoCharset = $repository->getOption("CHARSET"); } // Test Connexion and server features global $_SESSION; $cacheKey = $repository->getId() . "_ftpCharset"; if (!isset($_SESSION[$cacheKey]) || !strlen($_SESSION[$cacheKey]) || $forceLogin) { $features = $this->getServerFeatures(); $ctxCharset = ConfService::getContextCharset(); if (empty($ctxCharset)) { ConfService::setContextCharset($features["charset"]); $_SESSION[$cacheKey] = $features["charset"]; } else { $_SESSION[$cacheKey] = $ctxCharset; } } return $urlParts; }
/** * Try to detect the current encoding (cached in session) * @static * @return string */ public static function getEncoding() { if (self::$currentCharsetValue == null) { $charset = ConfService::getContextCharset(); if (!empty($charset)) { // Check if the session get an assigned charset encoding (it's the case for remote SSH for example) self::$currentCharsetValue = $charset; } else { // Get the current locale (expecting the filesystem is in the same locale, as the standard says) self::$currentCharsetValue = self::parseCharset(setlocale(LC_CTYPE, 0)); } } return self::$currentCharsetValue; }