Permalink
Browse files

Fix mailer wrongly initialized.

Fix admin API key not yet created - Add button to generate/revoke on in standard dashboard.
  • Loading branch information...
1 parent 5425ab5 commit 81c8fe5f374886b9760a54655cd41a522ad3eb53 @cdujeu cdujeu committed Sep 1, 2016
@@ -125,6 +125,26 @@ public static function findPairForAdminTask($adminTaskId, $userId = ""){
}
/**
+ * @param string $adminTaskId
+ * @param string $userId
+ * @return integer number of deleted keys
+ * @throws PydioException
+ */
+ public static function revokePairForAdminTask($adminTaskId, $userId = ""){
+
+ $keys = self::getStore()->simpleStoreList("keystore", $cursor, "", "serial", '%"ADMIN_TASK_ID";s:' . strlen($adminTaskId) . ':"' . $adminTaskId . '"%');
+ $c = 0;
+ foreach($keys as $kId => $kData){
+ if(empty($userId) || $kData["USER_ID"] === $userId){
+ self::getStore()->simpleStoreClear("keystore", $kId);
+ $c++;
+ }
+ }
+ return $c;
+
+ }
+
+ /**
* @param $serverData
* @param $adminTaskId
* @param $userId
@@ -153,6 +153,10 @@ public static function instanciatePluginFromGlobalParams($globalsArray, $interfa
$globalsArray = array("instance_name" => $globalsArray);
}
+ if (!isSet($globalsArray["instance_name"]) && isSet($globalsArray["group_switch_value"])){
+ $globalsArray["instance_name"] = $globalsArray["group_switch_value"];
+ }
+
if (isSet($globalsArray["instance_name"])) {
$pName = $globalsArray["instance_name"];
unset($globalsArray["instance_name"]);
@@ -90,7 +90,9 @@ public function init(ContextInterface $ctx, $options = [])
if (!empty($pConf)) {
$pService = PluginsService::getInstance($ctx);
$p = ConfService::instanciatePluginFromGlobalParams($pConf, "Pydio\\Mailer\\Core\\Mailer", $pService);
- $pService->setPluginUniqueActiveForType($p->getType(), $p->getName(), $p);
+ if($p !== false){
+ $pService->setPluginUniqueActiveForType($p->getType(), $p->getName(), $p);
+ }
}
}
@@ -55,6 +55,10 @@
<global_param group="CONF_MESSAGE[Server Internals]" type="button" name="MQ_WORKER_SWITCH_ON" choices="run_plugin_action:core.mq:switchWorkerOn" label="CONF_MESSAGE[Start Worker]" description="CONF_MESSAGE[Switch a worker ON]" mandatory="false"/>
<global_param group="CONF_MESSAGE[Server Internals]" type="button" name="MQ_WORKER_SWITCH_OFF" choices="run_plugin_action:core.mq:switchWorkerOff" label="CONF_MESSAGE[Stop Worker]" description="CONF_MESSAGE[Switch a worker OFF]" mandatory="false"/>
+ <global_param group="CONF_MESSAGE[Administrative API Key]" type="legend" name="MQ_LEGEND_ADMIN_KEY" description="CONF_MESSAGE[Pydio Booster uses an administrative API key pair to communicate with the server. If you start it manually, use the buttons below to generate or revoke key pairs. If you start using the admin dashboard, you should not need that.]" label="CONF_MESSAGE[Generate Key]" mandatory="false"/>
+ <global_param group="CONF_MESSAGE[Administrative API Key]" type="button" name="MQ_GENERATE_ADMIN_KEY" choices="run_plugin_action:core.mq:generateAdminKey" label="CONF_MESSAGE[Generate API Key]" description="CONF_MESSAGE[Generate Key]" mandatory="false"/>
+ <global_param group="CONF_MESSAGE[Administrative API Key]" type="button" name="MQ_REVOKE_ADMIN_KEY" choices="run_plugin_action:core.mq:revokeAdminKey" label="CONF_MESSAGE[Revoke existing API Key(s)]" description="CONF_MESSAGE[Revoke Key]" mandatory="false"/>
+
</server_settings>
<class_definition classname="Pydio\Mq\Core\MqManager" filename="plugins/core.mq/vendor/autoload.php"/>
<registry_contributions>
@@ -442,6 +442,53 @@ public function wsAuthenticate(ServerRequestInterface $request, ResponseInterfac
}
+
+ /**
+ * Save an admin key to a file
+ * @param array $params
+ * @param ContextInterface $ctx
+ * @return string
+ */
+ public function generateAdminKey($params, $ctx){
+ $u = $ctx->getUser();
+ if(!$u->isAdmin()){
+ return "ERROR: You are not administrator";
+ }
+ try{
+ $this->getAdminKeyString();
+ return "SUCCESS: Nothing to do, a pair already exists";
+ }catch(PydioException $e){
+ $adminPair = $this->getAdminKeyString($u->getId());
+ $pairFile = $this->getPluginWorkDir(true)."/apikey";
+ $r = file_put_contents($pairFile, $adminPair);
+ if($r === false){
+ return "ERROR: Something went wrong";
+ }else{
+ return "SUCCESS: An API key pair has been written in $pairFile on the server. You can now use it to configure PydioBooster.";
+ }
+ }
+ }
+
+ /**
+ * Save an admin key to a file
+ * @param array $params
+ * @param ContextInterface $ctx
+ * @return string
+ */
+ public function revokeAdminKey($params, $ctx){
+ $u = $ctx->getUser();
+ if(!$u->isAdmin()){
+ return "ERROR: You are not administrator";
+ }
+ $c = ApiKeysService::revokePairForAdminTask("go-upload", $u->getId());
+ if($c > 0){
+ return "SUCCESS: Successfully revoked $c pair of keys. You may have to generate new ones and reload PydioBooster.";
+ }else{
+ return "SUCCESS: Nothing to do, there is no admin key";
+ }
+ }
+
+
/**
* @param string $writeForUserId
* @param string $restrictToIp

0 comments on commit 81c8fe5

Please sign in to comment.