Permalink
Browse files

Fix legacy links vs new URI option

  • Loading branch information...
1 parent 9dafdf6 commit cf73c5d8ab71ae7603f2c079bccbe4eb16fbdab3 @cdujeu cdujeu committed Sep 2, 2016
@@ -231,15 +231,18 @@ public static function publicRoute($serverBase, $route, $params){
if(strpos($hash, "--") !== false){
list($hash, $lang) = explode("--", $hash);
}
+ if(strpos($hash, ".php") !== false){
+ $hash = array_shift(explode(".php", $hash));
+ }
ConfService::init();
ConfService::start();
if(isSet($lang)){
$_GET["lang"] = $lang;
}
- if(isSet($params["download_file"])){
+ if(isSet($params["optional"])){
$_GET["dl"] = true;
- $_GET["file"] = "/".$params["download_file"];
+ $_GET["file"] = "/".$params["optional"];
}
ConfService::getAuthDriverImpl();
@@ -38,14 +38,18 @@
use Pydio\Log\Core\Logger;
use Pydio\OCS\Model\TargettedLink;
use Pydio\Share\Model\ShareLink;
+use Pydio\Share\ShareCenter;
defined('AJXP_EXEC') or die( 'Access not allowed');
-
+/**
+ * Class ShareStore
+ * @package Pydio\Share\Store
+ */
class ShareStore {
var $sqlSupported = false;
- var $downloadFolder;
+ var $legacyPublicFolder;
/**
* @var int
*/
@@ -70,7 +74,7 @@ class ShareStore {
*/
public function __construct(ContextInterface $context, $downloadFolder, $hashMinLength = 32){
$this->context = $context;
- $this->downloadFolder = $downloadFolder;
+ $this->legacyPublicFolder = $downloadFolder;
$this->hashMinLength = $hashMinLength;
$storage = ConfService::getConfStorageImpl();
if($storage->getId() == "conf.sql") {
@@ -79,6 +83,9 @@ public function __construct(ContextInterface $context, $downloadFolder, $hashMin
}
}
+ /**
+ * @return int
+ */
public function getHashMinLength(){
return $this->hashMinLength;
}
@@ -111,7 +118,7 @@ public function storeShare($parentRepositoryId, $shareData, $type="minisite", $e
if($existingHash){
$hash = $existingHash;
}else{
- $hash = $this->computeHash($data, $this->downloadFolder);
+ $hash = $this->computeHash($data, $this->legacyPublicFolder);
}
$shareData["SHARE_TYPE"] = $type;
@@ -164,7 +171,7 @@ public function loadShareObject($hash){
*/
public function loadShare($hash){
- $dlFolder = $this->downloadFolder;
+ $dlFolder = $this->legacyPublicFolder;
$file = $dlFolder."/".$hash.".php";
if(!is_file($file)) {
if($this->sqlSupported){
@@ -175,6 +182,7 @@ public function loadShare($hash){
}
return [];
}
+ class_alias("Pydio\\Share\\ShareCenter", "ShareCenter");
$lines = file($file);
$inputData = '';
// Necessary for the eval
@@ -188,19 +196,8 @@ public function loadShare($hash){
$code = $lines[3] . $lines[4] . $lines[5];
eval($code);
if(empty($inputData)) return false;
- $dataModified = !$this->checkHash($inputData, $hash); //(md5($inputData) != $id);
$publicletData = @unserialize($inputData);
$publicletData["PUBLICLET_PATH"] = $file;
- /*
- if($this->sqlSupported){
- // Move old file to DB-storage
- $type = (isset($publicletData["REPOSITORY"]) ? "minisite" : "publiclet");
- $this->createGenericLoader();
- $shareData["SHARE_TYPE"] = $type;
- $this->confStorage->simpleStoreSet("share", $hash, $publicletData, "serial");
- unlink($file);
- }
- */
return $publicletData;
@@ -212,7 +209,7 @@ public function loadShare($hash){
* @return bool
*/
public function shareIsLegacy($hash){
- $dlFolder = $this->downloadFolder;
+ $dlFolder = $this->legacyPublicFolder;
$file = $dlFolder."/".$hash.".php";
return is_file($file);
}
@@ -283,28 +280,6 @@ public function listShares($limitToUser = '', $parentRepository = '', &$cursor =
$parentRepository);
}
- // Get hardcoded files
- /*
- $files = glob(ConfService::getGlobalConf("PUBLIC_DOWNLOAD_FOLDER")."/*.php");
- if($files === false) return $dbLets;
- foreach ($files as $file) {
- if(basename($file) == "share.php") continue;
- $ar = explode(".", basename($file));
- $id = array_shift($ar);
- $publicletData = $this->loadShare($id);
- if($publicletData === false) continue;
- if (!empty($limitToUser) && ( !isSet($publicletData["OWNER_ID"]) || $publicletData["OWNER_ID"] != $limitToUser )) {
- continue;
- }
- if(!empty($parentRepository) && ( (is_string($publicletData["REPOSITORY"]) && $publicletData["REPOSITORY"] != $parentRepository)
- || (is_object($publicletData["REPOSITORY"]) && $publicletData["REPOSITORY"]->getUniqueId() != $parentRepository ) )){
- continue;
- }
- $publicletData["SHARE_TYPE"] = "file";
- $dbLets[$id] = $publicletData;
- }
- */
-
// Update share_type and filter if necessary
foreach($dbLets as $id => &$shareData){
if($shareData === false){
@@ -685,7 +660,7 @@ public function shareExists($type, $element)
} else if($type == "ocs_remote"){
return true;
} else if ($type == "file" || $type == "minisite") {
- $fileExists = is_file($this->downloadFolder."/".$element.".php");
+ $fileExists = is_file($this->legacyPublicFolder."/".$element.".php");
if($fileExists) {
return true;
}
@@ -755,7 +730,7 @@ public function clearExpiredFiles($currentUser = true)
}
/**
- * Find all expired legacy publiclets and remove them.
+ * Delete an expired publiclets.
* @param $elementId
* @param $data
* @throws \Exception
@@ -64,7 +64,6 @@ public function buildPublicLink($hash)
*/
public function buildPublicDlURL()
{
- $downloadFolder = ConfService::getGlobalConf("PUBLIC_DOWNLOAD_FOLDER");
$dlURL = ConfService::getGlobalConf("PUBLIC_DOWNLOAD_URL");
if (!empty($dlURL)) {
$parts = parse_url($dlURL);
@@ -76,7 +75,7 @@ public function buildPublicDlURL()
}
} else {
$fullUrl = ApplicationState::detectServerURL(true);
- return str_replace("\\", "/", rtrim($fullUrl, "/").rtrim(str_replace(AJXP_INSTALL_PATH, "", $downloadFolder), "/"));
+ return str_replace("\\", "/", rtrim($fullUrl, "/")."/".trim(ConfService::getGlobalConf("PUBLIC_BASE_URI"), "/"));
}
}
@@ -90,33 +89,4 @@ public function computeMinisiteToServerURL()
return ApplicationState::getTravelPath($minisite, $server);
}
- /**
- * Get download folder path from configuration
- * @return string
- */
- public function getPublicDownloadFolder(){
- return ConfService::getGlobalConf("PUBLIC_DOWNLOAD_FOLDER");
- }
-
- /**
- * Build download folder URL from configuration and current URL
- * @return string|null
- */
- public function getPublicDownloadUrl(){
- $downloadFolder = ConfService::getGlobalConf("PUBLIC_DOWNLOAD_FOLDER");
- $dlURL = ConfService::getGlobalConf("PUBLIC_DOWNLOAD_URL");
- if (!empty($dlURL)) {
- $parts = parse_url($dlURL);
- if($parts['scheme']) {
- return rtrim($dlURL, "/");
- } else {
- $host = ApplicationState::detectServerURL();
- return rtrim($host, "/")."/".trim($dlURL, "/");
- }
- } else {
- $fullUrl = ApplicationState::detectServerURL(true);
- return str_replace("\\", "/", rtrim($fullUrl, "/").rtrim(str_replace(AJXP_INSTALL_PATH, "", $downloadFolder), "/"));
- }
- }
-
}
@@ -19,9 +19,10 @@
<global_param name="APPLICATION_TITLE" group="CONF_MESSAGE[Main]" type="string" label="CONF_MESSAGE[App Title]" description="CONF_MESSAGE[Your application title]" mandatory="true" default="Pydio" expose="true"/>
<global_param name="DEFAULT_LANGUAGE" group="CONF_MESSAGE[Main]" type="select" choices="AJXP_AVAILABLE_LANGUAGES" label="CONF_MESSAGE[Default Language]" description="CONF_MESSAGE[Default language when a user does not have set his/her own.]" mandatory="true" default="en"/>
<global_param name="SERVER_URL" group="CONF_MESSAGE[Main]" type="string" label="CONF_MESSAGE[Server URL]" description="CONF_MESSAGE[Server URL used to build share links and notifications. It will be detected if empty.]" mandatory="false"/>
- <global_param name="PUBLIC_DOWNLOAD_FOLDER" group="CONF_MESSAGE[Sharing]" type="string" label="CONF_MESSAGE[Download Folder]" description="CONF_MESSAGE[Absolute path to the public folder where temporary download links will be created. Setting this empty will disable the sharing feature.]" mandatory="false" default="AJXP_INSTALL_PATH/public"/>
+ <global_param name="PUBLIC_BASE_URI" group="CONF_MESSAGE[Sharing]" type="string" label="CONF_MESSAGE[Public Base URI]" description="CONF_MESSAGE[URI where to serve the public links]" mandatory="true" default="/public"/>
+ <global_param name="PUBLIC_DOWNLOAD_FOLDER" group="CONF_MESSAGE[Sharing]" type="string" label="CONF_MESSAGE[Download Folder (Legacy)]" description="CONF_MESSAGE[Absolute path to the public folder where temporary download links will be created. This is used for legacy purpose, newly created links do not use it anymore, but use the Base URI instead.]" mandatory="false" default="AJXP_INSTALL_PATH/data/public"/>
<!-- MAKE SURE NOT TO CHANGE ORDER OF name AND default ATTRIBUTES, CAN BE REPLACED BY INSTALLERS -->
- <global_param name="PUBLIC_DOWNLOAD_URL" default="" group="CONF_MESSAGE[Sharing]" type="string" label="CONF_MESSAGE[Download URL]" description="CONF_MESSAGE[If not inferred directly from the current ajaxplorer URI plus the public download folder name, replace the public access URL here.]" mandatory="false"/>
+ <global_param name="PUBLIC_DOWNLOAD_URL" default="" group="CONF_MESSAGE[Sharing]" type="string" label="CONF_MESSAGE[Download URL]" description="CONF_MESSAGE[If not inferred directly from the current pydio URL plus the public base URI, replace the public access URL here.]" mandatory="false"/>
<global_param name="WEBDAV_ENABLE" group="CONF_MESSAGE[WebDAV Server]" type="boolean" label="CONF_MESSAGE[Enable WebDAV]" description="CONF_MESSAGE[Enable the webDAV support. Please READ THE DOC to safely use this feature.]" mandatory="false" default="false"/>
<global_param name="WEBDAV_BASEURI" group="CONF_MESSAGE[WebDAV Server]" type="string" label="CONF_MESSAGE[Shares URI]" description="CONF_MESSAGE[Common URI to access the shares. Please READ THE DOC to safely use this feature.]" mandatory="false" default="/pydio/shares"/>
<global_param name="WEBDAV_BASEHOST" group="CONF_MESSAGE[WebDAV Server]" type="string" label="CONF_MESSAGE[Shares Host]" description="CONF_MESSAGE[Host used in webDAV protocol. Should be detected by default. Please READ THE DOC to safely use this feature.]" mandatory="false" default=""/>
@@ -50,7 +50,7 @@
"/public":{
"methods": "*",
"routes": [
- "/public/{hash}/dl/{download_file}",
+ "/public/{hash}/dl/[{optional:.+}]",
"/public/{hash}",
"/public[{optional:.+}]"
],

0 comments on commit cf73c5d

Please sign in to comment.