Permalink
Browse files

Generate config files and trigger download

  • Loading branch information...
1 parent 4a055dd commit 07be14e8333af44446d7959eb987066d6eca18a8 @cdujeu cdujeu committed Aug 30, 2016
@@ -15,6 +15,8 @@
<global_param group="CONF_MESSAGE[Pydio Booster]" name="CLI_PYDIO" type="string" label="CONF_MESSAGE[Command-line Pydio]" description="CONF_MESSAGE[On specific hosts, you may have to use a specific path to access the pydio command line]" mandatory="false" default="pydio"/>
<global_param group="CONF_MESSAGE[Pydio Booster]" name="WS_ACTIVE" type="boolean" description="CONF_MESSAGE[WebSocket Server provides a server-to-client messaging feature, avoiding regular polling from browsers and sync applications, thus reducing the server load.]" label="CONF_MESSAGE[WebSocket Server]" default="true" expose="true"/>
<global_param group="CONF_MESSAGE[Pydio Booster]" name="UPLOAD_ACTIVE" description="CONF_MESSAGE[Pydio Upload Server is a unique feature used to delegate file uploads to our dedicated binary, that will send the files directly to the storage.]" label="CONF_MESSAGE[Upload Server]" type="boolean" expose="true"/>
+ <global_param group="CONF_MESSAGE[Pydio Booster]" type="legend" name="PYDIO_BOOSTER_DOWNLOAD_LEGEND" label="CONF_MESSAGE[Legend]" description="CONF_MESSAGE[Configuration files are generated each time your start the process, using the options saved in this plugin. If you handle the process manually, use the button below to download updated version of the files, and start process using '-conf /path/to/pydioconf' parameter.]" mandatory="false"/>
+ <global_param group="CONF_MESSAGE[Pydio Booster]" type="button" name="PYDIO_BOOSTER_DOWNLOAD_CONF" choices="run_client_action:download_booster_conf" label="CONF_MESSAGE[Regenerate Config files and Download]" description="CONF_MESSAGE[Regenerate Config files and Download]" mandatory="false"/>
<global_param group="CONF_MESSAGE[Network Main Configurations]" name="BOOSTER_MAIN_HOST" type="string" label="CONF_MESSAGE[Host]" description="CONF_MESSAGE[Host]" expose="true" default="127.0.0.1"/>
<global_param group="CONF_MESSAGE[Network Main Configurations]" name="BOOSTER_MAIN_PORT" type="string" label="CONF_MESSAGE[Port]" description="CONF_MESSAGE[Port]" expose="true" default="8090"/>
@@ -114,13 +116,27 @@
</processing>
</action>
<action name="tail_booster_log">
+ <rightsContext adminOnly="true" noUser="false" read="true" userLogged="true" write="false"/>
<processing>
<serverCallback methodName="tailBoosterLogs" restParams="/offset">
<input_param name="offset" type="integer"
description="Offset where to start tail, other last 20 lines"/>
</serverCallback>
</processing>
</action>
+ <action name="download_booster_conf">
+ <gui src="" text="" title="">
+ <context dir="true" recycle="false" selection="false"/>
+ </gui>
+ <rightsContext adminOnly="true" noUser="false" read="true" userLogged="true" write="false"/>
+ <processing>
+ <clientCallback><![CDATA[
+ var url = pydio.Parameters.get("ajxpServerAccess") + '&get_action=download_booster_conf';
+ document.location.href = url;
+ ]]></clientCallback>
+ <serverCallback methodName="pydioBoosterDownloadConf" restParams="/"/>
+ </processing>
+ </action>
</actions>
<hooks>
<serverCallback methodName="publishNodeChange" hookName="node.change" defer="true"/>
@@ -99,6 +99,10 @@ public function tailLogs($offset = 0){
];
}
+ if($offset > 0 && filesize($fileName) < $offset){
+ $offset = 0;
+ }
+
if($offset > 0){
$f = fopen($fileName, "rb");
$output = stream_get_contents($f, -1, $offset);
@@ -123,7 +127,7 @@ public function generatePydioBoosterJson($params, $adminKeyString){
list($tokenP, $tokenS) = explode(":", $adminKeyString);
return [
"scheduler" => [
- "host" => ApplicationState::detectServerURL(true),
+ "host" => rtrim(ApplicationState::detectServerURL(true, true), "/"),
"tokenP" => $tokenP,
"tokenS" => $tokenS,
"minutes" => 2
@@ -147,7 +151,7 @@ public function generatePydioBoosterFile($params, $adminKeyString) {
$hosts = [];
// Getting URLs of the Pydio system
- $serverURL = ApplicationState::detectServerURL(true);
+ $serverURL = rtrim(ApplicationState::detectServerURL(true, true), "/");
$tokenURL = $serverURL . "?get_action=keystore_generate_auth_token";
// Websocket Server Config
@@ -26,11 +26,11 @@
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Filter\AJXP_Permission;
-use Pydio\Core\Controller\CliRunner;
use Pydio\Core\Controller\Controller;
use Pydio\Core\Exception\AuthRequiredException;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Http\Message\XMLMessage;
+use Pydio\Core\Http\Response\FileReaderResponse;
use Pydio\Core\Http\Response\SerializableResponseStream;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\PluginFramework\PluginsService;
@@ -40,12 +40,10 @@
use Pydio\Core\Services\ConfService;
use Pydio\Core\Services\RepositoryService;
use Pydio\Core\Services\UsersService;
-use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Vars\StringHelper;
use Pydio\Core\Controller\XMLWriter;
use Pydio\Core\PluginFramework\Plugin;
-use Pydio\Core\Controller\UnixProcess;
use Pydio\Core\Utils\Vars\VarsFilter;
use Pydio\Mq\Core\Booster\BoosterManager;
use Pydio\Mq\Core\Message\ConsumeChannelMessage;
@@ -559,6 +557,39 @@ public function getPydioBoosterStatus($params){
return $this->getBoosterManager()->getPydioBoosterStatus($params);
}
+ /**
+ * @param ServerRequestInterface $requestInterface
+ * @param ResponseInterface $responseInterface
+ * @throws AuthRequiredException
+ */
+ public function pydioBoosterDownloadConf(ServerRequestInterface $requestInterface, ResponseInterface &$responseInterface){
+
+ /** @var ContextInterface $ctx */
+ $ctx = $requestInterface->getAttribute("ctx");
+ if(!$ctx->hasUser() || !$ctx->getUser()->isAdmin()){
+ // Additional check, should never get there.
+ throw new AuthRequiredException();
+ }
+ $adminKeyString = $this->getAdminKeyString($ctx->getUser()->getId());
+ $jsonFile = $this->getBoosterManager()->savePydioBoosterFile($this->getConfigs(), $adminKeyString);
+ $baseDir = dirname($jsonFile);
+ $caddyFile = $baseDir. DIRECTORY_SEPARATOR . "pydiocaddy";
+ require_once (AJXP_INSTALL_PATH ."/". AJXP_BIN_FOLDER_REL . "/lib/pclzip.lib.php");
+ $zipFile = $baseDir.DIRECTORY_SEPARATOR."configs.zip";
+ if(file_exists($zipFile)){
+ @unlink($zipFile);
+ }
+ $zip = new \PclZip($baseDir.DIRECTORY_SEPARATOR."configs.zip");
+ $zip->add([$jsonFile, $caddyFile], PCLZIP_OPT_REMOVE_ALL_PATH);
+ $reader = new FileReaderResponse($baseDir.DIRECTORY_SEPARATOR."configs.zip");
+ $reader->setPostReadCallback(function () use ($zipFile){
+ @unlink($zipFile);
+ });
+ $reader->setHeaderType("force-download");
+ $responseInterface = $responseInterface->withBody($reader);
+
+ }
+
/**
* @param ServerRequestInterface $requestInterface

0 comments on commit 07be14e

Please sign in to comment.