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

Commit

Permalink
Add a constant for pydio booster task identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 29, 2016
1 parent f1e2b3c commit 9ac73a7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions core/src/conf/bootstrap_context.php
Expand Up @@ -91,6 +91,9 @@
define("HASH_SALT_INDEX", 2);
define("HASH_PBKDF2_INDEX", 3);

// Used to identify the booster admin tasks
define("PYDIO_BOOSTER_TASK_IDENTIFIER", "pydio-booster");

// CAN BE SWITCHED TO TRUE TO MAKE THE SECURE TOKEN MORE SAFE
// MAKE SURE YOU HAVE PHP.5.3, OPENSSL, AND THAT IT DOES NOT DEGRADE PERFORMANCES
define("USE_OPENSSL_RANDOM", false);
Expand Down
Expand Up @@ -442,7 +442,7 @@ protected function sendToAccelerator($accelConfiguration, $localPathOrNode, $ser

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

if ($localPathOrNode instanceof AJXP_Node) {
$options = MetaStreamWrapper::getResolvedOptionsForNode($localPathOrNode);
Expand Down
8 changes: 5 additions & 3 deletions core/src/core/src/pydio/Core/Services/ApiKeysService.php
Expand Up @@ -86,16 +86,18 @@ public static function generatePairForAuthfront($userId, $deviceId = "", $device
* @throws PydioException
* @throws \Exception
*/
public static function generatePairForAdminTask($adminTaskId, $userId, $restrictToIP = ""){
public static function generatePairForAdminTask($adminTaskId, $userId = "", $restrictToIP = ""){

$store = self::getStore();
$token = StringHelper::generateRandomString();
$private = StringHelper::generateRandomString();
$data = [
"USER_ID" => $userId,
"PRIVATE" => $private,
"ADMIN_TASK_ID" => $adminTaskId
];
if(!empty($userId)){
$data["USER_ID"] = $userId;
}
if(!empty($restrictToIP)){
$data["RESTRICT_TO_IP"] = $restrictToIP;
}
Expand Down Expand Up @@ -154,7 +156,7 @@ public static function requestHasValidHeadersForAdminTask($serverData, $adminTas
return false;
}
list($t, $p) = explode(":", trim($serverData['HTTP_X_PYDIO_ADMIN_AUTH']));
$existingKey = self::findPairForAdminTask("go-upload", $userId);
$existingKey = self::findPairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER);
if($existingKey === null || $existingKey['p'] !== $p || $existingKey['t'] !== $t){
Logger::error(__CLASS__, __FUNCTION__, "Invalid tokens for admin task $adminTaskId");
return false;
Expand Down
16 changes: 8 additions & 8 deletions core/src/plugins/core.mq/src/MqManager.php
Expand Up @@ -467,7 +467,7 @@ public function generateAdminKey($params, $ctx){
$this->getAdminKeyString();
return "SUCCESS: Nothing to do, a pair already exists";
}catch(PydioException $e){
$adminPair = $this->getAdminKeyString($u->getId());
$adminPair = $this->getAdminKeyString(true);
$pairFile = $this->getPluginWorkDir(true)."/apikey";
$r = file_put_contents($pairFile, $adminPair);
if($r === false){
Expand All @@ -489,7 +489,7 @@ public function revokeAdminKey($params, $ctx){
if(!$u->isAdmin()){
return "ERROR: You are not administrator";
}
$c = ApiKeysService::revokePairForAdminTask("go-upload", $u->getId());
$c = ApiKeysService::revokePairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER, $u->getId());
if($c > 0){
return "SUCCESS: Successfully revoked $c pair of keys. You may have to generate new ones and reload PydioBooster.";
}else{
Expand All @@ -499,21 +499,21 @@ public function revokeAdminKey($params, $ctx){


/**
* @param string $writeForUserId
* @param bool $createIfNotExists
* @param string $restrictToIp
* @throws PydioException
* @return string
*/
protected function getAdminKeyString($writeForUserId = "", $restrictToIp = ""){
protected function getAdminKeyString($createIfNotExists = false, $restrictToIp = ""){

if($writeForUserId){
$adminKey = ApiKeysService::findPairForAdminTask("go-upload", $writeForUserId);
if($createIfNotExists){
$adminKey = ApiKeysService::findPairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER);
if($adminKey === null){
$adminKey = ApiKeysService::generatePairForAdminTask("go-upload", $writeForUserId, $restrictToIp);
$adminKey = ApiKeysService::generatePairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER, "", $restrictToIp);
}
$adminKeyString = $adminKey["t"].":".$adminKey["p"];
}else{
$adminKey = ApiKeysService::findPairForAdminTask("go-upload");
$adminKey = ApiKeysService::findPairForAdminTask(PYDIO_BOOSTER_TASK_IDENTIFIER);
if($adminKey === null){
throw new PydioException("Cannot find any key pair for admin access, something went wrong!");
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/uploader.html/SimpleUpload.php
Expand Up @@ -131,7 +131,7 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \

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

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

Expand Down

0 comments on commit 9ac73a7

Please sign in to comment.