public function initRepository() { if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $smbclientPath = $this->driverConf["SMBCLIENT"]; define('SMB4PHP_SMBCLIENT', $smbclientPath); $smbtmpPath = $this->driverConf["SMB_PATH_TMP"]; define('SMB4PHP_SMBTMP', $smbtmpPath); require_once $this->getBaseDir() . "/smb.php"; $create = $this->repository->getOption("CREATE"); $recycle = $this->repository->getOption("RECYCLE_BIN"); $this->detectStreamWrapper(true); $this->urlBase = "pydio://" . $this->repository->getId(); if ($recycle != "" && !is_dir($this->urlBase . "/" . $recycle)) { @mkdir($this->urlBase . "/" . $recycle); if (!is_dir($this->urlBase . "/" . $recycle)) { throw new AJXP_Exception("Cannot create recycle bin folder. Please check repository configuration or that your folder is writeable!"); } } if ($recycle != "") { RecycleBinManager::init($this->urlBase, "/" . $recycle); } }
/** * Test Repository * * @param Repository $repo * @return Boolean */ public function doRepositoryTest($repo) { if ($repo->accessType != 'fs') { return -1; } // Check the destination path $this->failedInfo = ""; $safePath = $repo->getOption("PATH", true); if (strstr($safePath, "AJXP_USER") !== false) { return TRUE; } // CANNOT TEST THIS CASE! $path = $repo->getOption("PATH", false); $createOpt = $repo->getOption("CREATE"); $create = $createOpt == "true" || $createOpt === true ? true : false; if (!$create && !@is_dir($path)) { $this->failedInfo .= "Selected repository path " . $path . " doesn't exist, and the CREATE option is false"; return FALSE; } /* else if ($create && !is_writeable($path)) { $this->failedInfo .= "Selected repository path ".$path." isn't writeable"; return FALSE; }*/ // Do more tests here return TRUE; }
public function initRepository() { if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } if (!function_exists('ssh2_connect')) { throw new Exception("You must have the php ssh2 extension active!"); } ConfService::setConf("PROBE_REAL_SIZE", false); $path = $this->repository->getOption("PATH"); $recycle = $this->repository->getOption("RECYCLE_BIN"); $this->detectStreamWrapper(true); $this->urlBase = "pydio://" . $this->repository->getId(); restore_error_handler(); if (!file_exists($this->urlBase)) { if ($this->repository->getOption("CREATE")) { $test = @mkdir($this->urlBase); if (!$test) { throw new AJXP_Exception("Cannot create path ({$path}) for your repository! Please check the configuration."); } } else { throw new AJXP_Exception("Cannot find base path ({$path}) for your repository! Please check the configuration!"); } } if ($recycle != "") { RecycleBinManager::init($this->urlBase, "/" . $recycle); } }
function initRepository() { if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $wrapperData = $this->detectStreamWrapper(true); AJXP_Logger::debug("Detected wrapper data", $wrapperData); $this->wrapperClassName = $wrapperData["classname"]; $this->urlBase = $wrapperData["protocol"] . "://" . $this->repository->getId(); $consumerKey = $this->repository->getOption("CONSUMER_KEY"); $consumerSecret = $this->repository->getOption("CONSUMER_SECRET"); $oauth = new Dropbox_OAuth_PEAR($consumerKey, $consumerSecret); // TOKENS IN SESSION? if (!empty($_SESSION["OAUTH_DROPBOX_TOKENS"])) { return; } // TOKENS IN FILE ? $tokens = $this->getTokens($this->repository->getId()); if (!empty($tokens)) { $_SESSION["OAUTH_DROPBOX_TOKENS"] = $tokens; return; } // OAUTH NEGOCIATION if (isset($_SESSION['DROPBOX_NEGOCIATION_STATE'])) { $state = $_SESSION['DROPBOX_NEGOCIATION_STATE']; } else { $state = 1; } switch ($state) { case 1: $tokens = $oauth->getRequestToken(); //print_r($tokens); // Note that if you want the user to automatically redirect back, you can // add the 'callback' argument to getAuthorizeUrl. //echo "Step 2: You must now redirect the user to:\n"; $_SESSION['DROPBOX_NEGOCIATION_STATE'] = 2; $_SESSION['oauth_tokens'] = $tokens; throw new Exception("Please go to <a style=\"text-decoration:underline;\" target=\"_blank\" href=\"" . $oauth->getAuthorizeUrl() . "\">" . $oauth->getAuthorizeUrl() . "</a> to authorize the access to your dropbox. Then try again to switch to this repository."); case 2: $oauth->setToken($_SESSION['oauth_tokens']); $tokens = $oauth->getAccessToken(); $_SESSION['DROPBOX_NEGOCIATION_STATE'] = 3; $_SESSION['OAUTH_DROPBOX_TOKENS'] = $tokens; $this->setTokens($this->repository->getId(), $tokens); return; } throw new Exception("Impossible to find the tokens for accessing the dropbox repository"); }
/** * initRepository */ public function initRepository() { if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } ConfService::setConf("PROBE_REAL_SIZE", false); require_once $this->getBaseDir() . "/SFTPPSL_StreamWrapper.php"; $create = $this->repository->getOption("CREATE"); $path = $this->repository->getOption("PATH"); $wrapperData = $this->detectStreamWrapper(true); $this->wrapperClassName = $wrapperData["classname"]; $this->urlBase = $wrapperData["protocol"] . "://" . $this->repository->getId(); }
public function delete($selectedFiles, &$logMessages) { $repoData = array('base_url' => $this->urlBase, 'chmod' => $this->repository->getOption('CHMOD_VALUE'), 'recycle' => $this->repository->getOption('RECYCLE_BIN')); $mess = ConfService::getMessages(); foreach ($selectedFiles as $selectedFile) { if ($selectedFile == "" || $selectedFile == DIRECTORY_SEPARATOR) { return $mess[120]; } $fileToDelete = $this->urlBase . $selectedFile; if (!file_exists($fileToDelete)) { $logMessages[] = $mess[100] . " " . SystemTextEncoding::toUTF8($selectedFile); continue; } $node = new AJXP_Node($fileToDelete); $node->setLeaf(!is_dir($fileToDelete)); $this->deldir($fileToDelete, $repoData); if ($node->isLeaf()) { $logMessages[] = "{$mess['38']} " . SystemTextEncoding::toUTF8($selectedFile) . " {$mess['44']}."; } else { $logMessages[] = "{$mess['34']} " . SystemTextEncoding::toUTF8($selectedFile) . " {$mess['44']}."; } AJXP_Controller::applyHook("node.change", [$node]); } return null; }
function deldir($location) { if (is_dir($location)) { $all = opendir($location); while ($file = readdir($all)) { if (is_dir("{$location}/{$file}") && $file != ".." && $file != ".") { $this->deldir("{$location}/{$file}"); if (file_exists("{$location}/{$file}")) { rmdir("{$location}/{$file}"); } unset($file); } elseif (!is_dir("{$location}/{$file}")) { if (file_exists("{$location}/{$file}")) { unlink("{$location}/{$file}"); } unset($file); } } closedir($all); rmdir($location); } else { if (file_exists("{$location}")) { $test = @unlink("{$location}"); if (!$test) { throw new Exception("Cannot delete file " . $location); } } } if (basename(dirname($location)) == $this->repository->getOption("RECYCLE_BIN")) { // DELETING FROM RECYCLE RecycleBinManager::deleteFromRecycle($location); } }
function initRepository() { if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $smbclientPath = $this->driverConf["SMBCLIENT"]; define('SMB4PHP_SMBCLIENT', $smbclientPath); require_once $this->getBaseDir() . "/smb.php"; $create = $this->repository->getOption("CREATE"); $recycle = $this->repository->getOption("RECYCLE_BIN"); $wrapperData = $this->detectStreamWrapper(true); $this->wrapperClassName = $wrapperData["classname"]; $this->urlBase = $wrapperData["protocol"] . "://" . $this->repository->getId(); }
public function initRepository() { @(include_once "HTTP/WebDAV/Client.php"); if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } if (!class_exists('HTTP_WebDAV_Client_Stream')) { throw new Exception("You must have Pear HTTP/WebDAV/Client package installed to use this access driver!"); } $create = $this->repository->getOption("CREATE"); $path = $this->repository->getOption("PATH"); $recycle = $this->repository->getOption("RECYCLE_BIN"); ConfService::setConf("PROBE_REAL_SIZE", false); /* if ($create == true) { if(!is_dir($path)) @mkdir($path); if (!is_dir($path)) { throw new AJXP_Exception("Cannot create root path for repository (".$this->repository->getDisplay()."). Please check repository configuration or that your folder is writeable!"); } if ($recycle!= "" && !is_dir($path."/".$recycle)) { @mkdir($path."/".$recycle); if (!is_dir($path."/".$recycle)) { throw new AJXP_Exception("Cannot create recycle bin folder. Please check repository configuration or that your folder is writeable!"); } } } else { if (!is_dir($path)) { throw new AJXP_Exception("Cannot find base path ($path) for your repository! Please check the configuration!"); } } */ $wrapperData = $this->detectStreamWrapper(true); $this->wrapperClassName = $wrapperData["classname"]; $this->urlBase = $wrapperData["protocol"] . "://" . $this->repository->getId(); if (!is_dir($this->urlBase)) { if (webdavAccessWrapper::$lastException) { throw webdavAccessWrapper::$lastException; } throw new AJXP_Exception("Cannot connect to the WebDAV server ({$path}). Please check the configuration!"); } if ($recycle != "") { RecycleBinManager::init($this->urlBase, "/" . $recycle); } }
public function initRepository() { if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $this->detectStreamWrapper(true); $this->urlBase = "pydio://" . $this->repository->getId(); if ($this->repository->getOption("MAILBOX") != "") { //$this->urlBase .= "/INBOX"; } /* if (!file_exists($this->urlBase)) { throw new AJXP_Exception("Cannot find base path for your repository! Please check the configuration!"); } */ }
public function initRepository() { include_once "libraryLoader.php"; if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $path = $this->repository->getOption("PATH"); $recycle = $this->repository->getOption("RECYCLE_BIN"); ConfService::setConf("PROBE_REAL_SIZE", false); $wrapperData = $this->detectStreamWrapper(true); $this->wrapperClassName = $wrapperData["classname"]; $this->urlBase = $wrapperData["protocol"] . "://" . $this->repository->getId(); if ($recycle != "") { RecycleBinManager::init($this->urlBase, "/" . $recycle); } }
/** * Repository Initialization * */ public function initRepository() { $this->detectStreamWrapper(true); if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $client = new Client(['base_url' => $this->repository->getOption("HOST")]); // Params $recycle = $this->repository->getOption("RECYCLE_BIN"); // Config ConfService::setConf("PROBE_REAL_SIZE", false); $this->urlBase = "pydio://" . $this->repository->getId(); if ($recycle != "") { RecycleBinManager::init($this->urlBase, "/" . $recycle); } }
/** * @param Repository $repoObject * @param boolean $registerStream * @return \AccessS3\S3Client */ protected static function getClientForRepository($repoObject, $registerStream = true) { require_once "aws.phar"; if (!isset(self::$clients[$repoObject->getId()])) { // Get a client $options = array('key' => $repoObject->getOption("API_KEY"), 'secret' => $repoObject->getOption("SECRET_KEY")); $signatureVersion = $repoObject->getOption("SIGNATURE_VERSION"); if (!empty($signatureVersion)) { $options['signature'] = $signatureVersion; } $baseURL = $repoObject->getOption("STORAGE_URL"); if (!empty($baseURL)) { $options["base_url"] = $baseURL; } $region = $repoObject->getOption("REGION"); if (!empty($region)) { $options["region"] = $region; } $proxy = $repoObject->getOption("PROXY"); if (!empty($proxy)) { $options['request.options'] = array('proxy' => $proxy); } $apiVersion = $repoObject->getOption("API_VERSION"); if ($apiVersion === "") { $apiVersion = "latest"; } //SDK_VERSION IS A GLOBAL PARAM ConfService::getConfStorageImpl()->_loadPluginConfig("access.s3", $globalOptions); $sdkVersion = $globalOptions["SDK_VERSION"]; //$repoObject->driverInstance->driverConf['SDK_VERSION']; if ($sdkVersion !== "v2" && $sdkVersion !== "v3") { $sdkVersion = "v2"; } if ($sdkVersion === "v3") { require_once __DIR__ . DIRECTORY_SEPARATOR . "class.pydioS3Client.php"; $s3Client = new \AccessS3\S3Client(["version" => $apiVersion, "region" => $region, "credentials" => $options]); $s3Client->registerStreamWrapper($repoObject->getId()); } else { $s3Client = Aws\S3\S3Client::factory($options); if ($repoObject->getOption("VHOST_NOT_SUPPORTED")) { // Use virtual hosted buckets when possible require_once "ForcePathStyleListener.php"; $s3Client->addSubscriber(new \Aws\S3\ForcePathStyleStyleListener()); } $s3Client->registerStreamWrapper(); } self::$clients[$repoObject->getId()] = $s3Client; } return self::$clients[$repoObject->getId()]; }
/** Cypher the publiclet object data and write to disk. @param $data The publiclet data array to write The data array must have the following keys: - DRIVER The driver used to get the file's content - OPTIONS The driver options to be successfully constructed (usually, the user and password) - FILE_PATH The path to the file's content - PASSWORD If set, the written publiclet will ask for this password before sending the content - ACTION If set, action to perform - USER If set, the AJXP user - EXPIRE_TIME If set, the publiclet will deny downloading after this time, and probably self destruct. @return the URL to the downloaded file */ function writePubliclet($data) { if (!defined('PUBLIC_DOWNLOAD_FOLDER') || !is_dir(PUBLIC_DOWNLOAD_FOLDER)) { return "ERROR : Public URL folder does not exist!"; } if (!function_exists("mcrypt_create_iv")) { return "ERROR : MCrypt must be installed to use publiclets!"; } if ($data["PASSWORD"] && !is_file(PUBLIC_DOWNLOAD_FOLDER . "/allz.css")) { @copy(INSTALL_PATH . "/" . AJXP_THEME_FOLDER . "/css/allz.css", PUBLIC_DOWNLOAD_FOLDER . "/allz.css"); @copy(INSTALL_PATH . "/" . AJXP_THEME_FOLDER . "/images/actions/22/dialog_ok_apply.png", PUBLIC_DOWNLOAD_FOLDER . "/dialog_ok_apply.png"); @copy(INSTALL_PATH . "/" . AJXP_THEME_FOLDER . "/images/actions/16/public_url.png", PUBLIC_DOWNLOAD_FOLDER . "/public_url.png"); } if (!is_file(PUBLIC_DOWNLOAD_FOLDER . "/index.html")) { @copy(INSTALL_PATH . "/server/index.html", PUBLIC_DOWNLOAD_FOLDER . "/index.html"); } $data["PLUGIN_ID"] = $this->id; $data["BASE_DIR"] = $this->baseDir; $data["REPOSITORY"] = $this->repository; if (AuthService::usersEnabled()) { $data["OWNER_ID"] = AuthService::getLoggedUser()->getId(); } // Force expanded path in publiclet $data["REPOSITORY"]->addOption("PATH", $this->repository->getOption("PATH")); if ($data["ACTION"] == "") { $data["ACTION"] = "download"; } // Create a random key $data["FINAL_KEY"] = md5(mt_rand() . time()); // Cypher the data with a random key $outputData = serialize($data); // Hash the data to make sure it wasn't modified $hash = md5($outputData); // The initialisation vector is only required to avoid a warning, as ECB ignore IV $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); // We have encoded as base64 so if we need to store the result in a database, it can be stored in text column $outputData = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $hash, $outputData, MCRYPT_MODE_ECB, $iv)); // Okay, write the file: $fileData = "<" . "?" . "php \n" . ' require_once("' . str_replace("\\", "/", INSTALL_PATH) . '/publicLet.inc.php"); ' . "\n" . ' $id = str_replace(".php", "", basename(__FILE__)); ' . "\n" . ' $cypheredData = base64_decode("' . $outputData . '"); ' . "\n" . ' $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); ' . "\n" . ' $inputData = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $id, $cypheredData, MCRYPT_MODE_ECB, $iv)); ' . "\n" . ' if (md5($inputData) != $id) { header("HTTP/1.0 401 Not allowed, script was modified"); exit(); } ' . "\n" . ' // Ok extract the data ' . "\n" . ' $data = unserialize($inputData); AbstractAccessDriver::loadPubliclet($data); ?' . '>'; if (@file_put_contents(PUBLIC_DOWNLOAD_FOLDER . "/" . $hash . ".php", $fileData) === FALSE) { return "Can't write to PUBLIC URL"; } require_once INSTALL_PATH . "/server/classes/class.PublicletCounter.php"; PublicletCounter::reset($hash); if (defined('PUBLIC_DOWNLOAD_URL') && PUBLIC_DOWNLOAD_URL != "") { return rtrim(PUBLIC_DOWNLOAD_URL, "/") . "/" . $hash . ".php"; } else { $http_mode = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://'; $fullUrl = $http_mode . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']); return str_replace("\\", "/", $fullUrl . rtrim(str_replace(INSTALL_PATH, "", PUBLIC_DOWNLOAD_FOLDER), "/") . "/" . $hash . ".php"); } }
public function getTokens() { if ($this->repository->getOption("DROPBOX_OAUTH_TOKENS") !== null && is_array($this->repository->getOption("DROPBOX_OAUTH_TOKENS"))) { return $this->repository->getOption("DROPBOX_OAUTH_TOKENS"); } $repositoryId = $this->repository->getId(); if (AuthService::usersEnabled()) { $u = AuthService::getLoggedUser(); $userId = $u->getId(); if ($u->getResolveAsParent()) { $userId = $u->getParent(); } } else { $userId = "shared"; } return AJXP_Utils::loadSerialFile(AJXP_DATA_PATH . "/plugins/access.dropbox/" . $repositoryId . "_" . $userId . "_tokens"); }
/** Cypher the publiclet object data and write to disk. @param $data The publiclet data array to write The data array must have the following keys: - DRIVER The driver used to get the file's content - OPTIONS The driver options to be successfully constructed (usually, the user and password) - FILE_PATH The path to the file's content - PASSWORD If set, the written publiclet will ask for this password before sending the content - ACTION If set, action to perform - USER If set, the AJXP user - EXPIRE_TIME If set, the publiclet will deny downloading after this time, and probably self destruct. @return the URL to the downloaded file */ function writePubliclet($data) { if (!defined('PUBLIC_DOWNLOAD_FOLDER') || !is_dir(PUBLIC_DOWNLOAD_FOLDER)) { return "Public URL folder does not exist!"; } if ($data["PASSWORD"] && !is_file(PUBLIC_DOWNLOAD_FOLDER . "/GradientBg.gif")) { @copy(INSTALL_PATH . "/client/images/GradientBg.gif", PUBLIC_DOWNLOAD_FOLDER . "/GradientBg.gif"); @copy(INSTALL_PATH . "/client/images/locationBg.gif", PUBLIC_DOWNLOAD_FOLDER . "/locationBg.gif"); } $data["DRIVER_NAME"] = $this->driverName; $data["XML_FILE_PATH"] = $this->xmlFilePath; $data["REPOSITORY"] = $this->repository; // Force expanded path in publiclet $data["REPOSITORY"]->addOption("PATH", $this->repository->getOption("PATH")); if ($data["ACTION"] == "") { $data["ACTION"] = "download"; } // Create a random key $data["FINAL_KEY"] = md5(mt_rand() . time()); // Cypher the data with a random key $outputData = serialize($data); // Hash the data to make sure it wasn't modified $hash = md5($outputData); // The initialisation vector is only required to avoid a warning, as ECB ignore IV $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); // We have encoded as base64 so if we need to store the result in a database, it can be stored in text column $outputData = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $hash, $outputData, MCRYPT_MODE_ECB, $iv)); // Okay, write the file: $fileData = "<" . "?" . "php \n" . ' require_once("' . str_replace("\\", "/", INSTALL_PATH) . '/publicLet.inc.php"); ' . "\n" . ' $id = str_replace(".php", "", basename(__FILE__)); ' . "\n" . ' $cypheredData = base64_decode("' . $outputData . '"); ' . "\n" . ' $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); ' . "\n" . ' $inputData = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $id, $cypheredData, MCRYPT_MODE_ECB, $iv)); ' . "\n" . ' if (md5($inputData) != $id) { header("HTTP/1.0 401 Not allowed, script was modified"); exit(); } ' . "\n" . ' // Ok extract the data ' . "\n" . ' $data = unserialize($inputData); AbstractAccessDriver::loadPubliclet($data); ?' . '>'; if (@file_put_contents(PUBLIC_DOWNLOAD_FOLDER . "/" . $hash . ".php", $fileData) === FALSE) { return "Can't write to PUBLIC URL"; } if (defined('PUBLIC_DOWNLOAD_URL') && PUBLIC_DOWNLOAD_URL != "") { return rtrim(PUBLIC_DOWNLOAD_URL, "/") . "/" . $hash . ".php"; } else { $http_mode = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://'; $fullUrl = $http_mode . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']); return str_replace("\\", "/", $fullUrl . rtrim(str_replace(INSTALL_PATH, "", PUBLIC_DOWNLOAD_FOLDER), "/") . "/" . $hash . ".php"); } }
public function initRepository() { require_once $this->getBaseDir() . "/aS3StreamWrapper/lib/wrapper/aS3StreamWrapper.class.php"; if (!in_array("s3", stream_get_wrappers())) { $wrapper = new aS3StreamWrapper(); $wrapper->register(array('protocol' => 's3', 'acl' => AmazonS3::ACL_OWNER_FULL_CONTROL, 'key' => $this->repository->getOption("API_KEY"), 'secretKey' => $this->repository->getOption("SECRET_KEY"), 'region' => $this->repository->getOption("REGION"))); } if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $path = $this->repository->getOption("PATH"); $recycle = $this->repository->getOption("RECYCLE_BIN"); ConfService::setConf("PROBE_REAL_SIZE", false); $wrapperData = $this->detectStreamWrapper(true); $this->wrapperClassName = $wrapperData["classname"]; $this->urlBase = $wrapperData["protocol"] . "://" . $this->repository->getId(); if ($recycle != "") { RecycleBinManager::init($this->urlBase, "/" . $recycle); } }
/** * Get the repository options, filtered in various maners * @param string $oName * @param bool $safe Do not filter * @return mixed|string */ function getOption($oName, $safe = false) { if (isset($this->options[$oName])) { $value = $this->options[$oName]; if (!$safe) { $value = AJXP_VarsFilter::filter($value); } return $value; } if ($this->inferOptionsFromParent) { if (!isset($this->parentTemplateObject)) { $this->parentTemplateObject = ConfService::getRepositoryById($this->parentId); } if (isset($this->parentTemplateObject)) { return $this->parentTemplateObject->getOption($oName, $safe); } } return ""; }
/** * @param string $repoId * @param Repository $repoObject * @param array $exposed * @param array $streams * @param AbstractAjxpUser $loggedUser * @param string $accessStatus * @return string * @throws Exception */ public static function repositoryToXML($repoId, $repoObject, $exposed, $streams, $loggedUser, $accessStatus = "") { $statusString = " repository_type=\"" . $repoObject->getRepositoryType() . "\""; if (empty($accessStatus)) { $accessStatus = $repoObject->getAccessStatus(); } if (!empty($accessStatus)) { $statusString .= " access_status=\"{$accessStatus}\" "; } else { if ($loggedUser != null) { $lastConnected = $loggedUser->getArrayPref("repository_last_connected", $repoId); if (!empty($lastConnected)) { $statusString .= " last_connection=\"{$lastConnected}\" "; } } } $streamString = ""; if (in_array($repoObject->accessType, $streams)) { $streamString = "allowCrossRepositoryCopy=\"true\""; } if ($repoObject->getUniqueUser()) { $streamString .= " user_editable_repository=\"true\" "; } if ($repoObject->hasContentFilter()) { $streamString .= " hasContentFilter=\"true\""; } $slugString = ""; $slug = $repoObject->getSlug(); if (!empty($slug)) { $slugString = "repositorySlug=\"{$slug}\""; } $isSharedString = ""; $currentUserIsOwner = false; $ownerLabel = null; if ($repoObject->hasOwner()) { $uId = $repoObject->getOwner(); if (AuthService::usersEnabled() && AuthService::getLoggedUser()->getId() == $uId) { $currentUserIsOwner = true; } $label = ConfService::getUserPersonalParameter("USER_DISPLAY_NAME", $uId, "core.conf", $uId); $ownerLabel = $label; $isSharedString = 'owner="' . AJXP_Utils::xmlEntities($label) . '"'; } if ($repoObject->securityScope() == "USER" || $currentUserIsOwner) { $streamString .= " userScope=\"true\""; } $descTag = ""; $public = false; if (!empty($_SESSION["CURRENT_MINISITE"])) { $public = true; } $description = $repoObject->getDescription($public, $ownerLabel); if (!empty($description)) { $descTag = '<description>' . AJXP_Utils::xmlEntities($description, true) . '</description>'; } $roleString = ""; if ($loggedUser != null) { $merged = $loggedUser->mergedRole; $params = array(); foreach ($exposed as $exposed_prop) { $metaOptions = $repoObject->getOption("META_SOURCES"); if (!isset($metaOptions[$exposed_prop["PLUGIN_ID"]])) { continue; } $value = $exposed_prop["DEFAULT"]; if (isset($metaOptions[$exposed_prop["PLUGIN_ID"]][$exposed_prop["NAME"]])) { $value = $metaOptions[$exposed_prop["PLUGIN_ID"]][$exposed_prop["NAME"]]; } $value = $merged->filterParameterValue($exposed_prop["PLUGIN_ID"], $exposed_prop["NAME"], $repoId, $value); if ($value !== null) { if ($value === true || $value === false) { $value = $value === true ? "true" : "false"; } $params[] = '<repository_plugin_param plugin_id="' . $exposed_prop["PLUGIN_ID"] . '" name="' . $exposed_prop["NAME"] . '" value="' . AJXP_Utils::xmlEntities($value) . '"/>'; $roleString .= str_replace(".", "_", $exposed_prop["PLUGIN_ID"]) . "_" . $exposed_prop["NAME"] . '="' . AJXP_Utils::xmlEntities($value) . '" '; } } $roleString .= 'acl="' . $merged->getAcl($repoId) . '"'; if ($merged->hasMask($repoId)) { $roleString .= ' hasMask="true" '; } } return "<repo access_type=\"" . $repoObject->accessType . "\" id=\"" . $repoId . "\"{$statusString} {$streamString} {$slugString} {$isSharedString} {$roleString}><label>" . SystemTextEncoding::toUTF8(AJXP_Utils::xmlEntities($repoObject->getDisplay())) . "</label>" . $descTag . $repoObject->getClientSettings() . "</repo>"; }
/** * * Try to reapply correct permissions * @param oct $mode * @param Repository $repoObject * @param Function $remoteDetectionCallback */ public static function fixPermissions(&$stat, $repoObject, $remoteDetectionCallback = null) { $fixPermPolicy = $repoObject->getOption("FIX_PERMISSIONS"); $loggedUser = AuthService::getLoggedUser(); if ($loggedUser == null) { return; } $sessionKey = md5($repoObject->getId() . "-" . $loggedUser->getId() . "-fixPermData"); if (!isset($_SESSION[$sessionKey])) { if ($fixPermPolicy == "detect_remote_user_id" && $remoteDetectionCallback != null) { list($uid, $gid) = call_user_func($remoteDetectionCallback, $repoObject); if ($uid != null && $gid != null) { $_SESSION[$sessionKey] = array("uid" => $uid, "gid" => $gid); } } else { if (substr($fixPermPolicy, 0, strlen("file:")) == "file:") { $filePath = AJXP_VarsFilter::filter(substr($fixPermPolicy, strlen("file:"))); if (file_exists($filePath)) { // GET A GID/UID FROM FILE $lines = file($filePath); foreach ($lines as $line) { $res = explode(":", $line); if ($res[0] == $loggedUser->getId()) { $uid = $res[1]; $gid = $res[2]; $_SESSION[$sessionKey] = array("uid" => $uid, "gid" => $gid); break; } } } } } // If not set, set an empty anyway if (!isset($_SESSION[$sessionKey])) { $_SESSION[$sessionKey] = array(null, null); } } else { $data = $_SESSION[$sessionKey]; if (!empty($data)) { if (isset($data["uid"])) { $uid = $data["uid"]; } if (isset($data["gid"])) { $gid = $data["gid"]; } } } $p = $stat["mode"]; $st = sprintf("%07o", $p & 7777770); AJXP_Logger::debug("FIX PERM DATA ({$fixPermPolicy}, {$st})" . $p, sprintf("%o", $p & 0777)); if ($p != NULL) { $isdir = $p & 040000 ? true : false; $changed = false; if (isset($uid) && $stat["uid"] == $uid || $fixPermPolicy == "user") { AJXP_Logger::debug("upgrading abit to ubit"); $changed = true; $p = $p & 7777770; if ($p & 0x100) { $p += 04; } if ($p & 0x80) { $p += 02; } if ($p & 0x40) { $p += 01; } } else { if (isset($gid) && $stat["gid"] == $gid || $fixPermPolicy == "group") { AJXP_Logger::debug("upgrading abit to gbit"); $changed = true; $p = $p & 7777770; if ($p & 0x20) { $p += 04; } if ($p & 0x10) { $p += 02; } if ($p & 0x8) { $p += 01; } } } if ($isdir && $changed) { $p += 040000; } $stat["mode"] = $stat[2] = $p; AJXP_Logger::debug("FIXED PERM DATA ({$fixPermPolicy})", sprintf("%o", $p & 0777)); } }
/** * 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; }
public function makeSharedRepositoryOptions($httpVars, $repository) { $newOptions = parent::makeSharedRepositoryOptions($httpVars, $repository); $newOptions["CONTAINER"] = $this->repository->getOption("CONTAINER"); return $newOptions; }
/** * We have to override the standard copyOrMoveFile, as feof() does * not seem to work with ssh2.ftp stream... * Maybe something to search hear http://www.mail-archive.com/php-general@lists.php.net/msg169992.html? * * @param string $destDir * @param string $srcFile * @param array $error * @param array $success * @param boolean $move */ function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move = false) { $mess = ConfService::getMessages(); $destFile = $this->urlBase . $destDir . "/" . basename($srcFile); $realSrcFile = $this->urlBase . $srcFile; if (!file_exists($realSrcFile)) { $error[] = $mess[100] . $srcFile; return; } if (dirname($realSrcFile) == dirname($destFile)) { if ($move) { $error[] = $mess[101]; return; } else { $base = basename($srcFile); $i = 1; if (is_file($realSrcFile)) { $dotPos = strrpos($base, "."); if ($dotPos > -1) { $radic = substr($base, 0, $dotPos); $ext = substr($base, $dotPos); } } // auto rename file $i = 1; $newName = $base; while (file_exists($this->urlBase . $destDir . "/" . $newName)) { $suffix = "-{$i}"; if (isset($radic)) { $newName = $radic . $suffix . $ext; } else { $newName = $base . $suffix; } $i++; } $destFile = $this->urlBase . $destDir . "/" . $newName; } } if (!is_file($realSrcFile)) { $errors = array(); $succFiles = array(); if ($move) { if (file_exists($destFile)) { $this->deldir($destFile); } $res = rename($realSrcFile, $destFile); } else { $dirRes = $this->dircopy($realSrcFile, $destFile, $errors, $succFiles); } if (count($errors) || isset($res) && $res !== true) { $error[] = $mess[114]; return; } } else { if ($move) { if (file_exists($destFile)) { unlink($destFile); } $res = rename($realSrcFile, $destFile); AJXP_Controller::applyHook("move.metadata", array($realSrcFile, $destFile, false)); } else { try { // BEGIN OVERRIDING list($connection, $remote_base_path) = sftpAccessWrapper::getSshConnection($realSrcFile); $remoteSrc = $remote_base_path . $srcFile; $remoteDest = $remote_base_path . $destDir; AJXP_Logger::debug("SSH2 CP", array("cmd" => 'cp ' . $remoteSrc . ' ' . $remoteDest)); ssh2_exec($connection, 'cp ' . $remoteSrc . ' ' . $remoteDest); AJXP_Controller::applyHook("move.metadata", array($realSrcFile, $destFile, true)); // END OVERRIDING } catch (Exception $e) { $error[] = $e->getMessage(); return; } } } if ($move) { // Now delete original // $this->deldir($realSrcFile); // both file and dir $messagePart = $mess[74] . " " . SystemTextEncoding::toUTF8($destDir); if (RecycleBinManager::recycleEnabled() && $destDir == RecycleBinManager::getRelativeRecycle()) { RecycleBinManager::fileToRecycle($srcFile); $messagePart = $mess[123] . " " . $mess[122]; } if (isset($dirRes)) { $success[] = $mess[117] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $messagePart . " (" . SystemTextEncoding::toUTF8($dirRes) . " " . $mess[116] . ") "; } else { $success[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $messagePart; } } else { if (RecycleBinManager::recycleEnabled() && $destDir == "/" . $this->repository->getOption("RECYCLE_BIN")) { RecycleBinManager::fileToRecycle($srcFile); } if (isset($dirRes)) { $success[] = $mess[117] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $mess[73] . " " . SystemTextEncoding::toUTF8($destDir) . " (" . SystemTextEncoding::toUTF8($dirRes) . " " . $mess[116] . ")"; } else { $success[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $mess[73] . " " . SystemTextEncoding::toUTF8($destDir); } } }
/** * @param array $data * @param AbstractAccessDriver $accessDriver * @param Repository $repository */ public function storeSafeCredentialsIfNeeded(&$data, $accessDriver, $repository) { $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 ($storeCreds || $accessDriver->hasMixin("credentials_consumer")) { $cred = AJXP_Safe::tryLoadingCredentialsFromSources(array(), $repository); if (isset($cred["user"]) && isset($cred["password"])) { $data["SAFE_USER"] = $cred["user"]; $data["SAFE_PASS"] = $cred["password"]; } } }
/** * @param String $pluginId * @param Repository $repository * @param String $optionName * @param bool $safe * @return Mixed */ public static function getFilteredRepositoryOption($pluginId, $repository, $optionName, $safe = false) { $logged = self::getLoggedUser(); $test = null; if ($logged != null) { $test = $logged->mergedRole->filterParameterValue($pluginId, $optionName, $repository->getId(), null); if (!empty($test) && !$safe) { $test = AJXP_VarsFilter::filter($test); } } if (empty($test)) { return $repository->getOption($optionName, $safe); } else { return $test; } }
/** * Get ssh2 connection * * @param Repository $repoObject * @return Resource */ protected static function getSftpResource($repoObject) { if (isset(self::$sftpResource) && self::$resourceRepoId == $repoObject->getId()) { return self::$sftpResource; } $callbacks = array('disconnect' => "disconnectedSftp", 'ignore' => "ignoreSftp", 'debug' => "debugSftp", 'macerror' => "macerrorSftp"); $remote_serv = $repoObject->getOption("SERV"); $remote_port = $repoObject->getOption("PORT"); $credentials = AJXP_Safe::tryLoadingCredentialsFromSources(array(), $repoObject); $remote_user = $credentials["user"]; $remote_pass = $credentials["password"]; $connection = ssh2_connect($remote_serv, intval($remote_port), array(), $callbacks); ssh2_auth_password($connection, $remote_user, $remote_pass); self::$sftpResource = ssh2_sftp($connection); self::$resourceRepoId = $repoObject->getId(); return self::$sftpResource; }
/** Cypher the publiclet object data and write to disk. * @param Array $data The publiclet data array to write The data array must have the following keys: - DRIVER The driver used to get the file's content - OPTIONS The driver options to be successfully constructed (usually, the user and password) - FILE_PATH The path to the file's content - PASSWORD If set, the written publiclet will ask for this password before sending the content - ACTION If set, action to perform - USER If set, the AJXP user - EXPIRE_TIME If set, the publiclet will deny downloading after this time, and probably self destruct. * - AUTHOR_WATCH If set, will post notifications for the publiclet author each time the file is loaded * @param AbstractAccessDriver $accessDriver * @param Repository $repository * @return array An array containing the hash (0) and the generated url (1) */ public function writePubliclet(&$data, $accessDriver, $repository) { $downloadFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"); if (!is_dir($downloadFolder)) { return "ERROR : Public URL folder does not exist!"; } if (!function_exists("mcrypt_create_iv")) { return "ERROR : MCrypt must be installed to use publiclets!"; } $this->initPublicFolder($downloadFolder); $data["PLUGIN_ID"] = $accessDriver->getId(); $data["BASE_DIR"] = $accessDriver->getBaseDir(); //$data["REPOSITORY"] = $repository; if (AuthService::usersEnabled()) { $data["OWNER_ID"] = AuthService::getLoggedUser()->getId(); } $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 ($storeCreds || $accessDriver->hasMixin("credentials_consumer")) { $cred = AJXP_Safe::tryLoadingCredentialsFromSources(array(), $repository); if (isset($cred["user"]) && isset($cred["password"])) { $data["SAFE_USER"] = $cred["user"]; $data["SAFE_PASS"] = $cred["password"]; } } // Force expanded path in publiclet $copy = clone $repository; $copy->addOption("PATH", $repository->getOption("PATH")); $data["REPOSITORY"] = $copy; if ($data["ACTION"] == "") { $data["ACTION"] = "download"; } // Create a random key $data["FINAL_KEY"] = md5(mt_rand() . time()); // Cypher the data with a random key $outputData = serialize($data); // Hash the data to make sure it wasn't modified $hash = $this->computeHash($outputData, $downloadFolder); // md5($outputData); $outputData = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $hash, $outputData, MCRYPT_MODE_ECB)); $fileData = "<" . "?" . "php \n" . ' require_once("' . str_replace("\\", "/", AJXP_INSTALL_PATH) . '/publicLet.inc.php"); ' . "\n" . ' $id = str_replace(".php", "", basename(__FILE__)); ' . "\n" . ' $cypheredData = base64_decode("' . $outputData . '"); ' . "\n" . ' $inputData = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $id, $cypheredData, MCRYPT_MODE_ECB), "\\0"); ' . "\n" . ' if (!ShareCenter::checkHash($inputData, $id)) { header("HTTP/1.0 401 Not allowed, script was modified"); exit(); } ' . "\n" . ' // Ok extract the data ' . "\n" . ' $data = unserialize($inputData); ShareCenter::loadPubliclet($data); '; if (@file_put_contents($downloadFolder . "/" . $hash . ".php", $fileData) === FALSE) { return "Can't write to PUBLIC URL"; } @chmod($downloadFolder . "/" . $hash . ".php", 0755); PublicletCounter::reset($hash); $url = $this->buildPublicletLink($hash); $this->logInfo("New Share", array("file" => "'" . $copy->display . ":/" . $data['FILE_PATH'] . "'", "url" => $url, "expiration" => $data['EXPIRE_TIME'], "limit" => $data['DOWNLOAD_LIMIT'], "repo_uuid" => $copy->uuid)); AJXP_Controller::applyHook("node.share.create", array('type' => 'file', 'repository' => &$copy, 'accessDriver' => &$accessDriver, 'data' => &$data, 'url' => $url)); return array($hash, $url); }
/** * Get the repository options, filtered in various maners * @param string $oName * @param bool $safe Do not filter * @param AbstractAjxpUser $resolveUser * @return mixed|string */ public function getOption($oName, $safe = false, $resolveUser = null) { if (!$safe && $this->inferOptionsFromParent) { if (!isset($this->parentTemplateObject)) { $this->parentTemplateObject = ConfService::getRepositoryById($this->parentId); } if (isset($this->parentTemplateObject)) { $value = $this->parentTemplateObject->getOption($oName, $safe); if (is_string($value) && strstr($value, "AJXP_ALLOW_SUB_PATH") !== false) { $val = rtrim(str_replace("AJXP_ALLOW_SUB_PATH", "", $value), "/") . "/" . $this->options[$oName]; return AJXP_Utils::securePath($val); } } } if (isset($this->options[$oName])) { $value = $this->options[$oName]; if (!$safe) { $value = AJXP_VarsFilter::filter($value, $resolveUser); } return $value; } if ($this->inferOptionsFromParent) { if (!isset($this->parentTemplateObject)) { $this->parentTemplateObject = ConfService::getRepositoryById($this->parentId); } if (isset($this->parentTemplateObject)) { return $this->parentTemplateObject->getOption($oName, $safe); } } return ""; }
/** * * Try to reapply correct permissions * @param array $stat * @param Repository $repoObject * @param callable $remoteDetectionCallback * @internal param \oct $mode */ public static function fixPermissions(&$stat, $repoObject, $remoteDetectionCallback = null) { $fixPermPolicy = $repoObject->getOption("FIX_PERMISSIONS"); $loggedUser = AuthService::getLoggedUser(); if ($loggedUser == null) { return; } $sessionKey = md5($repoObject->getId() . "-" . $loggedUser->getId() . "-fixPermData"); if (!isset($_SESSION[$sessionKey])) { if ($fixPermPolicy == "detect_remote_user_id" && $remoteDetectionCallback != null) { list($uid, $gid) = call_user_func($remoteDetectionCallback, $repoObject); if ($uid != null && $gid != null) { $_SESSION[$sessionKey] = array("uid" => $uid, "gid" => $gid); } } else { if (substr($fixPermPolicy, 0, strlen("file:")) == "file:") { $filePath = AJXP_VarsFilter::filter(substr($fixPermPolicy, strlen("file:"))); if (file_exists($filePath)) { // GET A GID/UID FROM FILE $lines = file($filePath); foreach ($lines as $line) { $res = explode(":", $line); if ($res[0] == $loggedUser->getId()) { $uid = $res[1]; $gid = $res[2]; $_SESSION[$sessionKey] = array("uid" => $uid, "gid" => $gid); break; } } } } } // If not set, set an empty anyway if (!isset($_SESSION[$sessionKey])) { $_SESSION[$sessionKey] = array(null, null); } } else { $data = $_SESSION[$sessionKey]; if (!empty($data)) { if (isset($data["uid"])) { $uid = $data["uid"]; } if (isset($data["gid"])) { $gid = $data["gid"]; } } } $p = $stat["mode"]; //$st = sprintf("%07o", ($p & 7777770)); //AJXP_Logger::debug("FIX PERM DATA ($fixPermPolicy, $st)".$p,sprintf("%o", ($p & 000777))); if ($p != NULL) { /* decoct returns a string, it's more convenient to manipulate as we know the structure of the octal form of stat["mode"] - first two or three chars => file type (dir: 40, file: 100, symlink: 120) - three remaining characters => file permissions (1st char: user, 2nd char: group, 3rd char: others) */ $p = decoct($p); $lastInd = intval($p[0]) == 4 ? 4 : 5; $otherPerms = decbin(intval($p[$lastInd])); $actualPerms = $otherPerms; if (isset($uid) && $stat["uid"] == $uid || $fixPermPolicy == "user") { AJXP_Logger::debug(__CLASS__, __FUNCTION__, "upgrading abit to ubit"); $userPerms = decbin(intval($p[$lastInd - 2])); $actualPerms |= $userPerms; } else { if (isset($gid) && $stat["gid"] == $gid || $fixPermPolicy == "group") { AJXP_Logger::debug(__CLASS__, __FUNCTION__, "upgrading abit to gbit"); $groupPerms = decbin(intval($p[$lastInd - 1])); $actualPerms |= $groupPerms; } } $test = bindec($actualPerms); $p[$lastInd] = $test; $stat["mode"] = $stat[2] = octdec($p); //AJXP_Logger::debug(__CLASS__,__FUNCTION__,"FIXED PERM DATA ($fixPermPolicy)",sprintf("%o", ($p & 000777))); } }
/** * 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); }