Permalink
Browse files

Pydio 7 websocket server config and upload

  • Loading branch information...
1 parent 6564518 commit 0a09ff375b44b74c429ad70c69c3d82ef4e644a6 @ghecquet ghecquet committed Jun 3, 2016
@@ -38,5 +38,6 @@
<global_param name="GZIP_LIMIT" group="CONF_MESSAGE[Compression Features]" type="string" label="CONF_MESSAGE[Gzip Limit]" description="CONF_MESSAGE[If activated, a default limit should be set above when files are no more compressed.]" mandatory="false" default="1048576"/>
<global_param name="NODENAME_MAX_LENGTH" expose="true" group="CONF_MESSAGE[Miscellaneous]" type="integer" label="CONF_MESSAGE[Filename length]" description="CONF_MESSAGE[Maximum characters length of new files or folders]" mandatory="false" default="255"/>
<global_param name="AJXP_TMP_DIR" group="CONF_MESSAGE[Miscellaneous]" type="string" label="CONF_MESSAGE[Temporary Folder]" description="CONF_MESSAGE[This is necessary only if you have errors concerning the tmp dir access or writeability : most probably, they are due to PHP SAFE MODE (should disappear in php6) or various OPEN_BASEDIR restrictions. In that case, create and set writeable a tmp folder somewhere at the root of your hosting (but above the web/ or www/ or http/ if possible!!) and enter here the full path to this folder]" mandatory="false" default=""/>
+ <global_param name="CLI_PYDIO" group="CONF_MESSAGE[Command Line]" 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"/>
</server_settings>
</ajxpcore>
@@ -194,13 +194,13 @@ public function sendInstantMessage($xmlContent, $repositoryId, $targetUserId = n
$input["NODE_PATHES"] = $nodePathes;
}
- $host = $this->getFilteredOption("WS_SERVER_HOST");
- $port = $this->getFilteredOption("WS_SERVER_PORT");
+ $host = $this->getFilteredOption("NSQ_HOST");
+ $port = $this->getFilteredOption("NSQ_PORT");
if(!empty($host) && !empty($port)){
if(empty($this->nsqClient)){
// Publish on NSQ
$this->nsqClient = new nsqphp;
- $this->nsqClient->publishTo($host, 1);
+ $this->nsqClient->publishTo(join(":", [$host, $port]), 1);
}
$this->nsqClient->publish('im', new \nsqphp\Message\Message(json_encode($input)));
}
@@ -212,13 +212,13 @@ public function sendInstantMessage($xmlContent, $repositoryId, $targetUserId = n
public function sendTaskMessage($content){
$this->logInfo("Core.mq", "Should now publish a message to NSQ :". json_encode($content));
- $host = $this->getFilteredOption("WS_SERVER_HOST");
- $port = $this->getFilteredOption("WS_SERVER_PORT");
+ $host = $this->getFilteredOption("NSQ_HOST");
+ $port = $this->getFilteredOption("NSQ_PORT");
if(!empty($host) && !empty($port)){
// Publish on NSQ
try{
$nsq = new nsqphp;
- $nsq->publishTo($host, 1);
+ $nsq->publishTo(join(":", [$host, $port]), 1);
$nsq->publish('task', new \nsqphp\Message\Message(json_encode($content)));
$this->logInfo("Core.mq", "Published a message to NSQ :". json_encode($content));
}catch (Exception $e){
@@ -362,49 +362,149 @@ public function switchWorkerOn($params)
if ($process != null) {
$pId = $process->getPid();
$wDir = $this->getPluginWorkDir(true);
- file_put_contents($wDir.DIRECTORY_SEPARATOR."worker-pid", $pId);
+ file_put_contents($pidFile, $pId);
return "SUCCESS: Started worker with process ID $pId";
}
return "SUCCESS: Started worker Server";
}
public function switchWorkerOff($params){
- return $this->switchWebSocketOff($params, "worker");
+ return $this->switchOff($params, "worker");
}
public function getWorkerStatus($params){
- return $this->getWebSocketStatus($params, "worker");
+ return $this->getStatus($params, "worker");
}
- public function switchWebSocketOn($params)
- {
+ // Handler testing the generation of the caddy file to spot any error
+ public function getCaddyFile($params) {
+ $error = "OK";
+
+ set_error_handler(function ($e) use (&$error) {
+ $error = $e;
+ }, E_WARNING);
+
+ $data = $this->generateCaddyFile($params);
+
+ // Generate the caddyfile
+ file_put_contents("/tmp/testcaddy", $data);
+
+ restore_error_handler();
+
+ return $error;
+ }
+
+ public function generateCaddyFile($params) {
+ $data = "";
+
+ $hosts = [];
+
+ // Getting URLs of the Pydio system
+ $serverURL = Utils::detectServerURL();
+ $tokenURL = $serverURL . "?get_action=keystore_generate_auth_token";
+ $authURL = $serverURL . "/api/pydio/ws_authenticate";
+
+ // Websocket
+ $host = $params["WS_HOST"];
+ $port = $params["WS_PORT"];
+ $secure = $params["WS_SECURE"];
+ $path = "/" . trim($params["WS_PATH"], "/");
+
+ $key = "http" . ($secure ? "s" : "") . "://" . $host . ":" . $port;
+ $hosts[$key] = array_merge(
+ (array) $hosts[$key],
+ [
+ "pydioauth" => [$path, $authURL, $tokenURL. "&device=websocket"],
+ "pydiows" => [$path]
+ ]
+ );
+
+ // Upload
+ $host = $params["UPLOAD_HOST"];
+ $port = $params["UPLOAD_PORT"];
+ $secure = $params["UPLOAD_SECURE"];
+ $path = "/" . trim($params["UPLOAD_PATH"], "/");
+
+ $key = "http" . ($secure ? "s" : "") . "://" . $host . ":" . $port;
+ $hosts[$key] = array_merge(
+ (array) $hosts[$key],
+ [
+ "header" => [$path, "{\n" .
+ "\tAccess-Control-Allow-Origin ". $serverURL ."\n" .
+ "\tAccess-Control-Request-Headers *\n" .
+ "\tAccess-Control-Allow-Methods POST\n" .
+ "\tAccess-Control-Allow-Headers Range\n" .
+ "\tAccess-Control-Allow-Credentials true\n" .
+ "}"
+ ],
+ "pydioupload" => [$path, $tokenURL . "&device=upload"]
+ ]
+ );
+
+ foreach ($hosts as $host => $config) {
+ $data .= $host . " {\n";
+
+ foreach ($config as $key => $value) {
+ $data .= "\t" . $key . " " . join($value, " ") . "\n";
+ }
+
+ $data .= "}\n";
+ }
+
+ return $data;
+ }
+
+ public function saveCaddyFile($params) {
+ $data = $this->generateCaddyFile($params);
+
$wDir = $this->getPluginWorkDir(true);
- $pidFile = $wDir.DIRECTORY_SEPARATOR."ws-pid";
+ $caddyFile = $wDir.DIRECTORY_SEPARATOR."pydiocaddy";
+
+ // Generate the caddyfile
+ file_put_contents($caddyFile, $data);
+
+ return $caddyFile;
+ }
+
+ public function switchCaddyOn($params) {
+
+ $caddyFile = $this->saveCaddyFile($params);
+
+ $wDir = $this->getPluginWorkDir(true);
+ $pidFile = $wDir.DIRECTORY_SEPARATOR."caddy-pid";
if (file_exists($pidFile)) {
$pId = file_get_contents($pidFile);
$unixProcess = new UnixProcess();
$unixProcess->setPid($pId);
$status = $unixProcess->status();
if ($status) {
- throw new Exception("Web Socket server seems to already be running!");
+ throw new Exception("Caddy server seems to already be running!");
}
}
- $host = escapeshellarg($params["WS_SERVER_BIND_HOST"]);
- $port = escapeshellarg($params["WS_SERVER_BIND_PORT"]);
- $path = escapeshellarg($params["WS_SERVER_PATH"]);
- $cmd = ConfService::getCoreConf("CLI_PHP")." ws-server.php -host=".$host." -port=".$port." -path=".$path;
- chdir(AJXP_INSTALL_PATH.DIRECTORY_SEPARATOR.AJXP_PLUGINS_FOLDER.DIRECTORY_SEPARATOR."core.mq");
+
+ chdir($wDir);
+
+ $cmd = "env TMPDIR=/tmp ". ConfService::getCoreConf("CLI_PYDIO")." -conf ".$caddyFile . " 2>&1 | tee pydio.out";
+
$process = Controller::runCommandInBackground($cmd, null);
if ($process != null) {
$pId = $process->getPid();
$wDir = $this->getPluginWorkDir(true);
- file_put_contents($wDir.DIRECTORY_SEPARATOR."ws-pid", $pId);
+ file_put_contents($pidFile, $pId);
return "SUCCESS: Started WebSocket Server with process ID $pId";
}
return "SUCCESS: Started WebSocket Server";
}
- public function switchWebSocketOff($params, $type = "ws")
+ public function switchCaddyOff($params){
+ return $this->switchOff($params, "caddy");
+ }
+
+ public function getCaddyStatus($params){
+ return $this->getStatus($params, "caddy");
+ }
+
+ public function switchOff($params, $type = "ws")
{
$wDir = $this->getPluginWorkDir(true);
$pidFile = $wDir.DIRECTORY_SEPARATOR."$type-pid";
@@ -420,7 +520,7 @@ public function switchWebSocketOff($params, $type = "ws")
return "SUCCESS: Killed $type Server";
}
- public function getWebSocketStatus($params, $type = "ws")
+ public function getStatus($params, $type = "ws")
{
$wDir = $this->getPluginWorkDir(true);
$pidFile = $wDir.DIRECTORY_SEPARATOR."$type-pid";
@@ -434,7 +534,5 @@ public function getWebSocketStatus($params, $type = "ws")
if($status) return "ON";
else return "OFF";
}
-
}
-
}
@@ -62,7 +62,7 @@ Class.create("PydioInstantMessenger", {
},
initForRepoId:function(repoId){
- if(window.WebSocket && this.configs.get("WS_SERVER_ACTIVE")){
+ if(window.WebSocket && this.configs.get("WS_ACTIVE")){
if(this.ws) {
if(!repoId){
@@ -80,7 +80,7 @@ Class.create("PydioInstantMessenger", {
}
}else{
if(repoId){
- var url = "ws"+(this.configs.get("WS_SERVER_SECURE")?"s":"")+"://"+this.configs.get("WS_SERVER_HOST")+":"+this.configs.get("WS_SERVER_PORT")+this.configs.get("WS_SERVER_PATH");
+ var url = "ws"+(this.configs.get("WS_SECURE")?"s":"")+"://"+this.configs.get("WS_HOST")+":"+this.configs.get("WS_PORT")+"/"+this.configs.get("WS_PATH");
this.ws = new WebSocket(url);
this.ws.onmessage = function(event){
var obj = parseXml(event.data);
@@ -128,7 +128,7 @@ Class.create("PydioInstantMessenger", {
console.error("Switching back to polling");
}
delete this.ws;
- this.configs.set("WS_SERVER_ACTIVE", false);
+ this.configs.set("WS_ACTIVE", false);
this.initForRepoId(repoId);
}.bind(this);
@@ -137,7 +137,7 @@ Class.create("PydioInstantMessenger", {
console.error("Cannot login to websocket server, switching back to polling");
}
delete this.ws;
- this.configs.set("WS_SERVER_ACTIVE", false);
+ this.configs.set("WS_ACTIVE", false);
this.initForRepoId(repoId);
}.bind(this);
}
@@ -11,18 +11,30 @@
<global_param group="CONF_MESSAGE[Inner Messaging]" type="plugin_instance:mq" name="UNIQUE_MS_INSTANCE" label="CONF_MESSAGE[MQ Instance]" description="CONF_MESSAGE[Choose the plugin]" mandatory="false" default="mq.serial"/>
<global_param group="CONF_MESSAGE[Inner Messaging]" description="CONF_MESSAGE[Post the notification in a temporary queue. You must set up the scheduler accordingly to make sure the queue is then consumed on a regularly basis.]" label="CONF_MESSAGE[Queue notifications]" name="USE_QUEUE" type="boolean" default="false"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket server is running]" label="CONF_MESSAGE[WebSocket]" name="WS_SERVER_ACTIVE" type="boolean" expose="true"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket client connect address]" label="CONF_MESSAGE[WS Client Address]" name="WS_SERVER_HOST" type="string" expose="true"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket client connect port]" label="CONF_MESSAGE[WS Client Port]" name="WS_SERVER_PORT" type="string" expose="true" default="8090"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket client secure connection]" label="CONF_MESSAGE[WS Client SSL]" name="WS_SERVER_SECURE" type="boolean" expose="true" default="false"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket server bind address]" label="CONF_MESSAGE[WS Server Host]" name="WS_SERVER_BIND_HOST" type="string" expose="true"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket server bind port]" label="CONF_MESSAGE[WS Server Port]" name="WS_SERVER_BIND_PORT" type="string" expose="true" default="8090"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket handler path]" label="CONF_MESSAGE[WS Path]" name="WS_SERVER_PATH" type="string" expose="true"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket admin key]" label="CONF_MESSAGE[WS Key]" name="WS_SERVER_ADMIN" type="string"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" type="monitor" name="WS_STATUS" choices="run_plugin_action:core.mq:getWebSocketStatus" label="CONF_MESSAGE[WebSocket Server Status]" description="CONF_MESSAGE[Try to detect if the server is running correctly]" mandatory="false"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" type="button" name="SWITCH_WS_ON" choices="run_plugin_action:core.mq:switchWebSocketOn" label="CONF_MESSAGE[Run WebSocket Server]" description="CONF_MESSAGE[Switch the WS server ON]" mandatory="false"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" type="button" name="SWITCH_WS_OFF" choices="run_plugin_action:core.mq:switchWebSocketOff" label="CONF_MESSAGE[Stop WebSocket Server]" description="CONF_MESSAGE[Switch the WS server OFF]" mandatory="false"/>
- <global_param group="CONF_MESSAGE[WebSocket Server]" type="integer" name="POLLER_FREQUENCY" label="CONF_MESSAGE[Alternative poller frequency]" description="CONF_MESSAGE[If WebSocket server is not running, a polling mechanism will replace it. Fix the frequency of refresh, in seconds.]" mandatory="true" default="15" expose="true"/>
+ <global_param group="CONF_MESSAGE[Caddy]" type="monitor" name="CADDYFILE_VALID" choices="run_plugin_action:core.mq:getCaddyFile" label="CONF_MESSAGE[Caddyfile Format]" description="CONF_MESSAGE[Caddyfile format is valid ?]" mandatory="false"/>
+ <global_param group="CONF_MESSAGE[Caddy]" type="monitor" name="CADDY_STATUS" choices="run_plugin_action:core.mq:getCaddyStatus" label="CONF_MESSAGE[Caddy Status]" description="CONF_MESSAGE[Caddyfile is running ?]" mandatory="false"/>
+
+ <global_param group="CONF_MESSAGE[Caddy]" type="button" name="CADDY_SWITCH_ON" choices="run_plugin_action:core.mq:switchCaddyOn" label="CONF_MESSAGE[Start Caddy]" description="CONF_MESSAGE[Switch Caddy ON]" mandatory="false"/>
+ <global_param group="CONF_MESSAGE[Caddy]" type="button" name="CADDY_SWITCH_OFF" choices="run_plugin_action:core.mq:switchCaddyOff" label="CONF_MESSAGE[Stop Caddy]" description="CONF_MESSAGE[Switch Caddy OFF]" mandatory="false"/>
+
+ <global_param group="CONF_MESSAGE[WebSocket]" description="CONF_MESSAGE[WebSocket server is running]" label="CONF_MESSAGE[WebSocket]" name="WS_ACTIVE" type="boolean" expose="true"/>
+
+ <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket host]" label="CONF_MESSAGE[WS Hostname]" name="WS_HOST" type="string" expose="true" default="localhost"/>
+ <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket port]" label="CONF_MESSAGE[WS Port]" name="WS_PORT" type="string" expose="true" default="8090"/>
+ <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket secure]" label="CONF_MESSAGE[WS Client SSL]" name="WS_SECURE" type="boolean" expose="true" default="false"/>
+ <global_param group="CONF_MESSAGE[WebSocket Server]" description="CONF_MESSAGE[WebSocket path]" label="CONF_MESSAGE[WS Path]" name="WS_PATH" type="string" expose="true" default="ws"/>
+
+
+ <global_param group="CONF_MESSAGE[Upload]" description="CONF_MESSAGE[Upload server is running]" label="CONF_MESSAGE[Upload]" name="UPLOAD_ACTIVE" type="boolean" expose="true"/>
+
+ <global_param group="CONF_MESSAGE[Upload Server]" description="CONF_MESSAGE[Upload Server host]" label="CONF_MESSAGE[Upload Server host]" name="UPLOAD_HOST" type="string" expose="true" default="localhost"/>
+ <global_param group="CONF_MESSAGE[Upload Server]" description="CONF_MESSAGE[Upload Server port]" label="CONF_MESSAGE[Upload Server port]" name="UPLOAD_PORT" type="string" expose="true" default="8090"/>
+ <global_param group="CONF_MESSAGE[Upload Server]" description="CONF_MESSAGE[Upload Server secure]" label="CONF_MESSAGE[Upload Server secure]" name="UPLOAD_SECURE" type="boolean" expose="true" default="false"/>
+ <global_param group="CONF_MESSAGE[Upload Server]" description="CONF_MESSAGE[Upload Server path]" label="CONF_MESSAGE[Upload Server path]" name="UPLOAD_PATH" type="string" expose="true" default="io"/>
+
+ <global_param group="CONF_MESSAGE[NSQ Messaging]" description="CONF_MESSAGE[NSQ Host]" label="CONF_MESSAGE[NSQ Host]" name="NSQ_HOST" type="string" expose="true" default="localhost" />
+ <global_param group="CONF_MESSAGE[NSQ Messaging]" description="CONF_MESSAGE[NSQ Port]" label="CONF_MESSAGE[NSQ Port]" name="NSQ_PORT" type="string" expose="true" default="4150"/>
+
<global_param group="CONF_MESSAGE[Workers]" type="boolean" name="MQ_USE_WORKERS" label="CONF_MESSAGE[Use Workers]" description="CONF_MESSAGE[Send commands in background to workers waiting to execute them]" mandatory="false" default="false"/>
<global_param group="CONF_MESSAGE[Workers]" type="monitor" name="MQ_WORKER_STATUS" choices="run_plugin_action:core.mq:getWorkerStatus" label="CONF_MESSAGE[Worker Status]" description="CONF_MESSAGE[Try to detect if the worker is responding]" mandatory="false"/>
<global_param group="CONF_MESSAGE[Workers]" 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"/>
Oops, something went wrong.

0 comments on commit 0a09ff3

Please sign in to comment.