Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 345dac8

Browse files
committed
Embed CURRENT_MINISITE session key in ApplicationState, save / load in middlewares.
Update DL links for public links
1 parent fef670f commit 345dac8

File tree

17 files changed

+70
-31
lines changed

17 files changed

+70
-31
lines changed

core/src/core/src/pydio/Core/Http/Middleware/SessionMiddleware.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Pydio\Core\Http\Server;
2424
use Pydio\Core\Model\ContextInterface;
2525
use Pydio\Core\Services\SessionService;
26+
use Pydio\Core\Utils\ApplicationState;
2627

2728
defined('AJXP_EXEC') or die('Access not allowed');
2829

@@ -75,6 +76,10 @@ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface $r
7576
SessionService::close();
7677
});
7778

79+
if(SessionService::has(SessionService::CTX_MINISITE_HASH)){
80+
ApplicationState::setStateMinisite(SessionService::fetch(SessionService::CTX_MINISITE_HASH));
81+
}
82+
7883
return Server::callNextMiddleWare($requestInterface, $responseInterface, $next);
7984

8085
}

core/src/core/src/pydio/Core/Serializer/RepositoryXML.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Pydio\Core\Model\UserInterface;
2727
use Pydio\Core\PluginFramework\PluginsService;
2828
use Pydio\Core\Services\UsersService;
29+
use Pydio\Core\Utils\ApplicationState;
2930
use Pydio\Core\Utils\Vars\StringHelper;
3031

3132
defined('AJXP_EXEC') or die('Access not allowed');
@@ -132,9 +133,7 @@ protected function repositoryToXML($repoObject, $isActive, $exposed, $streams, $
132133
}
133134

134135
$descTag = "";
135-
$public = false;
136-
if(!empty($_SESSION["CURRENT_MINISITE"])) $public = true;
137-
$description = $repoObject->getDescription($public, $ownerLabel);
136+
$description = $repoObject->getDescription(ApplicationState::hasMinisiteHash(), $ownerLabel);
138137
if (!empty($description)) {
139138
$descTag = '<description>'. StringHelper::xmlEntities($description, true) .'</description>';
140139
}

core/src/core/src/pydio/Core/Serializer/UserXML.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Pydio\Core\PluginFramework\PluginsService;
2525
use Pydio\Core\Services\ConfService;
2626
use Pydio\Core\Services\UsersService;
27+
use Pydio\Core\Utils\ApplicationState;
2728

2829
defined('AJXP_EXEC') or die('Access not allowed');
2930

@@ -126,7 +127,7 @@ protected function writeRepositoriesData(ContextInterface $ctx)
126127
}
127128

128129
foreach ($accessible as $repoId => $repoObject) {
129-
if(!isSet($_SESSION["CURRENT_MINISITE"]) && $repoObject->hasContentFilter()){
130+
if(!ApplicationState::hasMinisiteHash() && $repoObject->hasContentFilter()){
130131
continue;
131132
}
132133
$accessStatus = '';

core/src/core/src/pydio/Core/Services/SessionService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class SessionService implements RepositoriesCache
4141
const LANGUAGES_KEY = "PYDIO_LANGUAGES";
4242
const CTX_LANGUAGE_KEY = "PYDIO_CTX_LANGUAGE";
4343
const CTX_CHARSET_KEY = "PYDIO_CTX_CHARSET";
44+
const CTX_MINISITE_HASH = "PYDIO_CTX_MINISITE";
4445

4546
private static $sessionName = PYDIO_SESSION_NAME;
4647

core/src/core/src/pydio/Core/Utils/ApplicationState.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class ApplicationState
4242
*/
4343
private static $sapiType = "session";
4444

45+
/**
46+
* @var string
47+
*/
48+
private static $minisiteHash = null;
49+
4550
/**
4651
* @param string $restBase
4752
*/
@@ -75,6 +80,27 @@ public static function sapiUsesSession(){
7580
return !self::sapiIsCli() && self::$restBase === null;
7681
}
7782

83+
/**
84+
* @param $hash
85+
*/
86+
public static function setStateMinisite($hash){
87+
self::$minisiteHash = $hash;
88+
}
89+
90+
/**
91+
* @return bool
92+
*/
93+
public static function hasMinisiteHash(){
94+
return self::$minisiteHash !== null;
95+
}
96+
97+
/**
98+
* @return string
99+
*/
100+
public static function getMinisiteHash(){
101+
return self::$minisiteHash;
102+
}
103+
78104
/**
79105
* Check if data/cache/first_run_passed file exists or not
80106
* @return bool

core/src/plugins/action.powerfs/PowerFSController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PowerFSController extends Plugin
5050

5151
public function performChecks()
5252
{
53-
if (class_exists("\\Pydio\\Share\\ShareCenter") && \Pydio\Share\ShareCenter::currentContextIsLinkDownload()) {
53+
if(ApplicationState::hasMinisiteHash() && ApplicationState::getSapiRestBase() !== null){
5454
throw new Exception("Disable during link download");
5555
}
5656
}

core/src/plugins/action.share/manifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@
227227
if(staticClass.getRESTPreviewLinks){
228228
var links = staticClass.getRESTPreviewLinks(node);
229229
$H(links).each(function(pair){
230-
modal.getForm().down("#additional_links").insert(tpl.evaluate({title:pair.key,link:document.location.href.split('?').shift() + "?dl=true&ct=true"+pair.value}));
230+
modal.getForm().down("#additional_links").insert(tpl.evaluate({title:pair.key,link:document.location.href.split('?').shift() + "/dl"+node.getPath()+"?ct=true"+pair.value}));
231231
});
232232
}
233233
}
234-
var dlLink = document.location.href.split('?').shift() + "?dl=true&file=" + encodeURIComponent(node.getPath());
234+
var dlLink = document.location.href.split('?').shift() + "/dl" + node.getPath();
235235
modal.getForm().down("#additional_links").insert(tpl.evaluate({title:MessageHash['share_center.60'],link:dlLink}));
236236
}
237237
]]></dialogOnOpen>
@@ -253,7 +253,7 @@
253253
</action>
254254
<action name="download">
255255
<pre_processing>
256-
<serverCallback methodName="preProcessDownload" applyCondition="$apply=isSet($_SESSION['CURRENT_MINISITE']);"/>
256+
<serverCallback methodName="preProcessDownload" applyCondition="$apply=\Pydio\Core\Services\SessionService::has(\Pydio\Core\Services\SessionService::CTX_MINISITE_HASH);"/>
257257
</pre_processing>
258258
</action>
259259
</actions>

core/src/plugins/action.share/src/Http/MinisiteAuthMiddleware.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R
9292
}
9393

9494
if($sessions){
95-
$_SESSION["CURRENT_MINISITE"] = $hash;
95+
SessionService::save(SessionService::CTX_MINISITE_HASH, $hash);
96+
ApplicationState::setStateMinisite($hash);
9697
}
9798
if(!empty($ctx) && $ctx->hasUser() && isSet($shareData["REPOSITORY"])){
9899
$repoObject = UsersService::getRepositoryWithPermission($ctx->getUser(), $shareData["REPOSITORY"]);

core/src/plugins/action.share/src/ShareCenter.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -533,17 +533,19 @@ protected function toggleWatchOnSharedRepository($childRepoId, $userId, $toggle
533533
*/
534534
public function preProcessDownload(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface){
535535

536-
if(isSet($_SESSION["CURRENT_MINISITE"])){
537-
$hash = $_SESSION["CURRENT_MINISITE"];
538-
$share = $this->getShareStore()->loadShareObject($hash);
539-
if(!empty($share)){
540-
if($share->isExpired()){
541-
throw new \Exception('Link is expired');
542-
}
543-
if($share->hasDownloadLimit()){
544-
$share->incrementDownloadCount();
545-
$share->save();
546-
}
536+
if(!ApplicationState::hasMinisiteHash()) {
537+
return;
538+
}
539+
540+
$hash = ApplicationState::getMinisiteHash();
541+
$share = $this->getShareStore()->loadShareObject($hash);
542+
if(!empty($share)){
543+
if($share->isExpired()){
544+
throw new \Exception('Link is expired');
545+
}
546+
if($share->hasDownloadLimit()){
547+
$share->incrementDownloadCount();
548+
$share->save();
547549
}
548550
}
549551

core/src/plugins/authfront.cas/CasAuthFrontend.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Pydio\Core\Services\RolesService;
3333
use Pydio\Core\Services\SessionService;
3434
use Pydio\Core\Services\UsersService;
35+
use Pydio\Core\Utils\ApplicationState;
3536
use Pydio\Core\Utils\DBHelper;
3637
use Pydio\Log\Core\Logger;
3738

@@ -82,7 +83,7 @@ function tryToLogUser(ServerRequestInterface &$request, ResponseInterface &$resp
8283
{
8384
$httpVars = $request->getParsedBody();
8485

85-
if (isset($_SESSION["CURRENT_MINISITE"])) {
86+
if (ApplicationState::hasMinisiteHash()) {
8687
return false;
8788
}
8889

core/src/plugins/authfront.session_login/SessionLoginFrontend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function logUserFromSession(\Psr\Http\Message\ServerRequestInterface &
8181

8282
}
8383

84-
if (ConfService::getGlobalConf("ALLOW_GUEST_BROWSING", "auth") && !isSet($_SESSION["CURRENT_MINISITE"])) {
84+
if (ConfService::getGlobalConf("ALLOW_GUEST_BROWSING", "auth") && !ApplicationState::hasMinisiteHash()) {
8585

8686
$authDriver = ConfService::getAuthDriverImpl();
8787
if (!$authDriver->userExists("guest")) {

core/src/plugins/core.notifications/Notification.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ protected function replaceVars($tplString, $mess, $rich = true)
165165
*/
166166
public function getMainLink()
167167
{
168-
if(isSet($_SESSION["CURRENT_MINISITE"]) && class_exists("\\Pydio\\Share\\ShareCenter")){
169-
$hash = $_SESSION["CURRENT_MINISITE"];
168+
if(ApplicationState::hasMinisiteHash() && class_exists("\\Pydio\\Share\\ShareCenter")){
169+
$hash = ApplicationState::getMinisiteHash();
170170
$shareCenter = \Pydio\Share\ShareCenter::getShareCenter($this->getContext());
171171
if(!empty($shareCenter)){
172172
return $shareCenter->getPublicAccessManager()->buildPublicLink($hash);
@@ -251,7 +251,7 @@ private function computeLocationType(){
251251
$crtUserId = "shared";
252252
$crtUser = $this->getNode()->hasUser() ? $this->getNode()->getUser() : null;
253253
if($crtUser != null) $crtUserId = $crtUser->getId();
254-
if(isSet($_SESSION["CURRENT_MINISITE"])){
254+
if(ApplicationState::hasMinisiteHash()){
255255
if($repo->hasContentFilter()){
256256
$type = "minisite.file";
257257
}else{

core/src/plugins/editor.diaporama/class.Diaporama.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,8 @@ Class.create("Diaporama", AbstractEditor, {
719719

720720
getRESTPreviewLinks:function(node){
721721
return {
722-
"Original image": "&file=" + encodeURIComponent(node.getPath()),
723-
"Thumbnail (200px)": "&get_thumb=true&dimension=200&file=" + encodeURIComponent(node.getPath())
722+
"Original image": "",
723+
"Thumbnail (200px)": "&get_thumb=true&dimension=200"
724724
};
725725
},
726726

core/src/plugins/editor.imagick/class.IMagickPreviewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Class.create("IMagickPreviewer", Diaporama, {
172172

173173
getRESTPreviewLinks:function(node){
174174
return {
175-
"First Page Thumbnail": "&file=" + encodeURIComponent(node.getPath())
175+
"First Page Thumbnail": ""
176176
};
177177
},
178178

core/src/plugins/editor.soundmanager/class.SMPlayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ soundManager.setup({\n\
243243
},
244244

245245
getRESTPreviewLinks:function(node){
246-
return {"MP3 Stream": "&file=" + encodeURIComponent(node.getPath())};
246+
return {"MP3 Stream": ""};
247247
},
248248

249249
getPreview : function(ajxpNode, rich){

core/src/plugins/editor.video/class.VideoPreviewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ preload="auto" width="#{WIDTH}" height="#{HEIGHT}" data-setup="{}">\n\
9292
},
9393

9494
getRESTPreviewLinks:function(node){
95-
return {"Video Stream": "&file=" + encodeURIComponent(node.getPath())};
95+
return {"Video Stream": ""};
9696
},
9797

9898

core/src/plugins/gui.ios/MobileNativeRedirect.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace Pydio\Gui;
2323

2424
use Exception;
25+
use Pydio\Core\Utils\ApplicationState;
2526
use Pydio\Core\Utils\Http\UserAgent;
2627

2728
use Pydio\Core\PluginFramework\Plugin;
@@ -37,7 +38,9 @@ class MobileNativeRedirect extends Plugin
3738
{
3839
public function performChecks()
3940
{
40-
if (isSet($_SESSION["CURRENT_MINISITE"])) throw new Exception("Disabled for minisites");
41+
if (ApplicationState::hasMinisiteHash()) {
42+
throw new Exception("Disabled for minisites");
43+
}
4144
if (UserAgent::userAgentIsWindowsPhone()) {
4245
throw new Exception("No native app for windows phone");
4346
}

0 commit comments

Comments
 (0)