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

Commit 9ac73a7

Browse files
committed
Add a constant for pydio booster task identifier
1 parent f1e2b3c commit 9ac73a7

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

core/src/conf/bootstrap_context.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
define("HASH_SALT_INDEX", 2);
9292
define("HASH_PBKDF2_INDEX", 3);
9393

94+
// Used to identify the booster admin tasks
95+
define("PYDIO_BOOSTER_TASK_IDENTIFIER", "pydio-booster");
96+
9497
// CAN BE SWITCHED TO TRUE TO MAKE THE SECURE TOKEN MORE SAFE
9598
// MAKE SURE YOU HAVE PHP.5.3, OPENSSL, AND THAT IT DOES NOT DEGRADE PERFORMANCES
9699
define("USE_OPENSSL_RANDOM", false);

core/src/core/src/pydio/Core/Http/Response/FileReaderResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ protected function sendToAccelerator($accelConfiguration, $localPathOrNode, $ser
442442

443443
// Pydio Agent acceleration - We make sure that request was really proxied by Agent, by checking a specific header.
444444
if($accelConfiguration === "pydio" && array_key_exists("HTTP_X_PYDIO_DOWNLOAD_SUPPORTED", $serverParams)
445-
&& ApiKeysService::requestHasValidHeadersForAdminTask($serverParams, "go-upload")) {
445+
&& ApiKeysService::requestHasValidHeadersForAdminTask($serverParams, PYDIO_BOOSTER_TASK_IDENTIFIER)) {
446446

447447
if ($localPathOrNode instanceof AJXP_Node) {
448448
$options = MetaStreamWrapper::getResolvedOptionsForNode($localPathOrNode);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,18 @@ public static function generatePairForAuthfront($userId, $deviceId = "", $device
8686
* @throws PydioException
8787
* @throws \Exception
8888
*/
89-
public static function generatePairForAdminTask($adminTaskId, $userId, $restrictToIP = ""){
89+
public static function generatePairForAdminTask($adminTaskId, $userId = "", $restrictToIP = ""){
9090

9191
$store = self::getStore();
9292
$token = StringHelper::generateRandomString();
9393
$private = StringHelper::generateRandomString();
9494
$data = [
95-
"USER_ID" => $userId,
9695
"PRIVATE" => $private,
9796
"ADMIN_TASK_ID" => $adminTaskId
9897
];
98+
if(!empty($userId)){
99+
$data["USER_ID"] = $userId;
100+
}
99101
if(!empty($restrictToIP)){
100102
$data["RESTRICT_TO_IP"] = $restrictToIP;
101103
}
@@ -154,7 +156,7 @@ public static function requestHasValidHeadersForAdminTask($serverData, $adminTas
154156
return false;
155157
}
156158
list($t, $p) = explode(":", trim($serverData['HTTP_X_PYDIO_ADMIN_AUTH']));
157-
$existingKey = self::findPairForAdminTask("go-upload", $userId);
159+
$existingKey = self::findPairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER);
158160
if($existingKey === null || $existingKey['p'] !== $p || $existingKey['t'] !== $t){
159161
Logger::error(__CLASS__, __FUNCTION__, "Invalid tokens for admin task $adminTaskId");
160162
return false;

core/src/plugins/core.mq/src/MqManager.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public function generateAdminKey($params, $ctx){
467467
$this->getAdminKeyString();
468468
return "SUCCESS: Nothing to do, a pair already exists";
469469
}catch(PydioException $e){
470-
$adminPair = $this->getAdminKeyString($u->getId());
470+
$adminPair = $this->getAdminKeyString(true);
471471
$pairFile = $this->getPluginWorkDir(true)."/apikey";
472472
$r = file_put_contents($pairFile, $adminPair);
473473
if($r === false){
@@ -489,7 +489,7 @@ public function revokeAdminKey($params, $ctx){
489489
if(!$u->isAdmin()){
490490
return "ERROR: You are not administrator";
491491
}
492-
$c = ApiKeysService::revokePairForAdminTask("go-upload", $u->getId());
492+
$c = ApiKeysService::revokePairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER, $u->getId());
493493
if($c > 0){
494494
return "SUCCESS: Successfully revoked $c pair of keys. You may have to generate new ones and reload PydioBooster.";
495495
}else{
@@ -499,21 +499,21 @@ public function revokeAdminKey($params, $ctx){
499499

500500

501501
/**
502-
* @param string $writeForUserId
502+
* @param bool $createIfNotExists
503503
* @param string $restrictToIp
504504
* @throws PydioException
505505
* @return string
506506
*/
507-
protected function getAdminKeyString($writeForUserId = "", $restrictToIp = ""){
507+
protected function getAdminKeyString($createIfNotExists = false, $restrictToIp = ""){
508508

509-
if($writeForUserId){
510-
$adminKey = ApiKeysService::findPairForAdminTask("go-upload", $writeForUserId);
509+
if($createIfNotExists){
510+
$adminKey = ApiKeysService::findPairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER);
511511
if($adminKey === null){
512-
$adminKey = ApiKeysService::generatePairForAdminTask("go-upload", $writeForUserId, $restrictToIp);
512+
$adminKey = ApiKeysService::generatePairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER, "", $restrictToIp);
513513
}
514514
$adminKeyString = $adminKey["t"].":".$adminKey["p"];
515515
}else{
516-
$adminKey = ApiKeysService::findPairForAdminTask("go-upload");
516+
$adminKey = ApiKeysService::findPairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER);
517517
if($adminKey === null){
518518
throw new PydioException("Cannot find any key pair for admin access, something went wrong!");
519519
}

core/src/plugins/uploader.html/SimpleUpload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
131131

132132
if($externalUploadStatus === ExternalUploadedFile::STATUS_REQUEST_OPTIONS){
133133

134-
if(!ApiKeysService::requestHasValidHeadersForAdminTask($request->getServerParams(), "go-upload")){
134+
if(!ApiKeysService::requestHasValidHeadersForAdminTask($request->getServerParams(), PYDIO_BOOSTER_TASK_IDENTIFIER)){
135135
throw new AuthRequiredException();
136136
}
137137

0 commit comments

Comments
 (0)