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

Commit e7f44ab

Browse files
committed
Move OptionsHelper to core.mq
1 parent be01894 commit e7f44ab

File tree

3 files changed

+166
-13
lines changed

3 files changed

+166
-13
lines changed

core/src/plugins/core.mq/manifest.xml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
<global_param group="CONF_MESSAGE[Main Configurations]" name="BOOSTER_MAIN_HOST" type="string" label="CONF_MESSAGE[Host]" description="CONF_MESSAGE[Host]" expose="true" default="127.0.0.1"/>
1515
<global_param group="CONF_MESSAGE[Main Configurations]" name="BOOSTER_MAIN_PORT" type="string" label="CONF_MESSAGE[Port]" description="CONF_MESSAGE[Port]" expose="true" default="8090"/>
1616
<global_param group="CONF_MESSAGE[Main Configurations]" name="BOOSTER_MAIN_SECURE" type="boolean" label="CONF_MESSAGE[SSL]" description="CONF_MESSAGE[Use secure connection]" expose="true" default="true"/>
17-
<global_param group="CONF_MESSAGE[Main Configurations]" name="NSQ_PORT" type="string" label="CONF_MESSAGE[NSQ Port]" description="CONF_MESSAGE[NSQ Port]" default="4150"/>
17+
<global_param group="CONF_MESSAGE[Main Configurations]" name="NSQ_HOST" type="string" label="CONF_MESSAGE[NSQ Host]" description="CONF_MESSAGE[NSQ Host for internal messaging. Leave default value if booster is on the same server]" default="0.0.0.0" />
18+
<global_param group="CONF_MESSAGE[Main Configurations]" name="NSQ_PORT" type="string" label="CONF_MESSAGE[NSQ Port]" description="CONF_MESSAGE[NSQ Port for internal messaging]" default="4150"/>
1819
<global_param group="CONF_MESSAGE[Main Configurations]" name="BOOSTER_INTERNAL_CONNECTION" type="group_switch:booster_internal_connection" label="CONF_MESSAGE[Internal Connection]" description="CONF_MESSAGE[If different from default host/port]" default="same" mandatory="true"/>
1920
<global_param group_switch_name="booster_internal_connection" group_switch_label="Same as external" group_switch_value="same" name="booster_internal_connection" type="hidden" label="same" description="custom" default="same"/>
2021
<global_param group_switch_name="booster_internal_connection" group_switch_label="Custom" group_switch_value="custom" name="booster_internal_connection" type="hidden" label="custom" description="custom" default="custom"/>
2122
<global_param group_switch_name="booster_internal_connection" group_switch_label="Custom" group_switch_value="custom" name="BOOSTER_INTERNAL_HOST" type="string" label="CONF_MESSAGE[Internal Host (if LAN IP is different from outside-world IP).]" description="CONF_MESSAGE[Internal Host]" default="127.0.0.1"/>
2223
<global_param group_switch_name="booster_internal_connection" group_switch_label="Custom" group_switch_value="custom" name="BOOSTER_INTERNAL_PORT" type="string" label="CONF_MESSAGE[Internal Port (if LAN Port is different from outside-world Port).]" description="CONF_MESSAGE[Internal Host]" default="8090"/>
2324

25+
<global_param group="CONF_MESSAGE[Main Configurations]" name="SERVER_INTERNAL_URL" type="group_switch:server_internal_url" label="CONF_MESSAGE[Server Internal URL]" description="CONF_MESSAGE[Use this if the booster needs to communicate with the server through a different host/port than the value defined in Application Core Options]" default="same" mandatory="true"/>
26+
<global_param group_switch_name="server_internal_url" group_switch_label="Same as application" group_switch_value="same" name="server_internal_url" type="hidden" label="same" description="custom" default="same"/>
27+
<global_param group_switch_name="server_internal_url" group_switch_label="Custom" group_switch_value="custom" name="server_internal_url" type="hidden" label="custom" description="custom" default="custom"/>
28+
<global_param group_switch_name="server_internal_url" group_switch_label="Custom" group_switch_value="custom" name="SERVER_INTERNAL_ADDRESS" type="string" label="CONF_MESSAGE[Pydio Server internal URL]" description="CONF_MESSAGE[Pydio Server URL, if LAN IP is different from outside-world IP. Set up full http url here, including http:// or https://]"/>
29+
2430
<global_param group="CONF_MESSAGE[Advanced Configurations]" name="BOOSTER_ADV_WS_LEGEND" type="legend" label="" description="Customize URL's depending on the features."/>
2531

2632
<global_param group="CONF_MESSAGE[Advanced Configurations]" name="BOOSTER_WS_ADVANCED" type="group_switch:booster_ws_advanced" label="CONF_MESSAGE[Websocket Network Configuration]" description="CONF_MESSAGE[Use custom URL's for websocket feature]" expose="true" default="same" mandatory="true"/>
2733
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Use main configurations" group_switch_value="same" name="booster_ws_advanced" type="hidden" label="same" description="same" default="same"/>
2834
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" name="booster_ws_advanced" type="hidden" label="custom" description="custom" default="custom"/>
2935
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[WebSocket host]" label="CONF_MESSAGE[WS Hostname]" name="WS_HOST" type="string" expose="true" default="localhost"/>
3036
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[WebSocket port]" label="CONF_MESSAGE[WS Port]" name="WS_PORT" type="string" expose="true" default="8090"/>
31-
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[WebSocket host]" label="CONF_MESSAGE[WS Hostname]" name="WS_HOST_INTERNAL" type="string" expose="false" default="localhost"/>
32-
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[WebSocket port]" label="CONF_MESSAGE[WS Port]" name="WS_PORT_INTERNAL" type="string" expose="false" default="8090"/>
37+
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[WebSocket host (internal)]" label="CONF_MESSAGE[WS Hostname (internal)]" name="WS_HOST_INTERNAL" type="string" expose="false" default="localhost"/>
38+
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[WebSocket port (internal)]" label="CONF_MESSAGE[WS Port (internal)]" name="WS_PORT_INTERNAL" type="string" expose="false" default="8090"/>
3339
<global_param group_switch_name="booster_ws_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[WebSocket secure]" label="CONF_MESSAGE[WS Client SSL]" name="WS_SECURE" type="boolean" expose="true" default="false"/>
3440
<global_param group="CONF_MESSAGE[Advanced Configurations]" description="CONF_MESSAGE[WebSocket path]" label="CONF_MESSAGE[WS Path]" name="WS_PATH" type="string" expose="true" default="ws"/>
3541

@@ -38,16 +44,11 @@
3844
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" name="booster_upload_advanced" type="hidden" label="custom" description="custom" default="custom"/>
3945
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[Upload Server host]" label="CONF_MESSAGE[Upload Server host]" name="UPLOAD_HOST" type="string" expose="true" default="localhost"/>
4046
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[Upload Server port]" label="CONF_MESSAGE[Upload Server port]" name="UPLOAD_PORT" type="string" expose="true" default="8090"/>
41-
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[Upload Server host]" label="CONF_MESSAGE[Upload Server host]" name="UPLOAD_HOST_INTERNAL" type="string" expose="false" default="localhost"/>
42-
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[Upload Server port]" label="CONF_MESSAGE[Upload Server port]" name="UPLOAD_PORT_INTERNAL" type="string" expose="false" default="8090"/>
47+
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[Upload Server host (internal)]" label="CONF_MESSAGE[Upload Server host (internal)]" name="UPLOAD_HOST_INTERNAL" type="string" expose="false" default="localhost"/>
48+
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[Upload Server port (internal)]" label="CONF_MESSAGE[Upload Server port (internal)]" name="UPLOAD_PORT_INTERNAL" type="string" expose="false" default="8090"/>
4349
<global_param group_switch_name="booster_upload_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[Upload Server secure]" label="CONF_MESSAGE[Upload Server secure]" name="UPLOAD_SECURE" type="boolean" expose="true" default="false"/>
4450
<global_param group="CONF_MESSAGE[Advanced Configurations]" description="CONF_MESSAGE[Upload Server path]" label="CONF_MESSAGE[Upload Server path]" name="UPLOAD_PATH" type="string" expose="true" default="io"/>
4551

46-
<global_param group="CONF_MESSAGE[Advanced Configurations]" name="BOOSTER_NSQ_ADVANCED" type="group_switch:booster_nsq_advanced" label="CONF_MESSAGE[Messaging Service Network Configuration]" description="CONF_MESSAGE[Use custom URL for nsq service]" default="same" mandatory="true"/>
47-
<global_param group_switch_name="booster_nsq_advanced" group_switch_label="Use main configurations" group_switch_value="same" name="booster_nsq_advanced" type="hidden" label="same" description="same" default="same"/>
48-
<global_param group_switch_name="booster_nsq_advanced" group_switch_label="Customize" group_switch_value="custom" name="booster_nsq_advanced" type="hidden" label="custom" description="custom" default="custom"/>
49-
<global_param group_switch_name="booster_nsq_advanced" group_switch_label="Customize" group_switch_value="custom" description="CONF_MESSAGE[NSQ Host]" label="CONF_MESSAGE[NSQ Host]" name="NSQ_HOST" type="string" default="localhost" />
50-
5152
<global_param group="CONF_MESSAGE[Server Internals]" type="plugin_instance:mq" name="UNIQUE_MS_INSTANCE" label="CONF_MESSAGE[MQ Instance]" description="CONF_MESSAGE[Choose the plugin, sql should be the default value]" mandatory="false" default="mq.sql"/>
5253
<global_param group="CONF_MESSAGE[Server Internals]" 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"/>
5354
<global_param group="CONF_MESSAGE[Server Internals]" type="boolean" name="MQ_USE_WORKERS" label="CONF_MESSAGE[Use Workers (experimental)]" description="CONF_MESSAGE[Send commands in background to workers waiting to execute them]" mandatory="false" default="false"/>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function init(ContextInterface $ctx, $options = [])
105105
public function exposeConfigInManifest($configName, $configValue)
106106
{
107107
// Do not expose those
108-
if(in_array($configName, ["WS_HOST", "WS_PORT", "UPLOAD_HOST", "UPLOAD_PORT"])){
108+
if(in_array($configName, ["NSQ_HOST", "NSQ_PORT"])){
109109
return;
110110
}
111111
if(is_array($configValue)){
@@ -290,8 +290,10 @@ private function _sendMessage(ContextInterface $ctx, $topic, $content) {
290290
if(!$wsActive){
291291
return;
292292
}
293-
$host = $this->getContextualOption($ctx, "NSQ_HOST");
294-
$port = $this->getContextualOption($ctx, "NSQ_PORT");
293+
294+
$configs = $this->getConfigs();
295+
$host = OptionsHelper::getNetworkOption($configs, OptionsHelper::OPTION_HOST, OptionsHelper::FEATURE_MESSAGING, OptionsHelper::SCOPE_EXTERNAL);
296+
$port = intval(OptionsHelper::getNetworkOption($configs, OptionsHelper::OPTION_PORT, OptionsHelper::FEATURE_MESSAGING, OptionsHelper::SCOPE_EXTERNAL));
295297

296298
if(!empty($host) && !empty($port)){
297299

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
/*
3+
* Copyright 2007-2016 Abstrium <contact (at) pydio.com>
4+
* This file is part of Pydio.
5+
*
6+
* Pydio is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Pydio is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* The latest code can be found at <https://pydio.com/>.
20+
*/
21+
namespace Pydio\Mq\Core;
22+
23+
use Pydio\Core\Services\ApplicationState;
24+
25+
defined('AJXP_EXEC') or die('Access not allowed');
26+
27+
/**
28+
* Helper for parsing core options
29+
* @package Pydio\Mq\Core
30+
*/
31+
class OptionsHelper
32+
{
33+
const OPTION_HOST = 'HOST';
34+
const OPTION_PORT = 'PORT';
35+
const OPTION_SECURE = 'SECURE';
36+
37+
const FEATURE_MAIN = 'main';
38+
const FEATURE_WS = 'WS';
39+
const FEATURE_UPLOAD = 'UPLOAD';
40+
const FEATURE_DOWNLOAD = 'DOWNLOAD';
41+
const FEATURE_MESSAGING = 'NSQ';
42+
const FEATURE_SERVER_URL = 'SERVER';
43+
44+
const SCOPE_EXTERNAL = 'external';
45+
const SCOPE_INTERNAL = 'internal';
46+
47+
/**
48+
*
49+
* @param array $options
50+
* @param string $type
51+
* @param string $feature
52+
* @param string $scope
53+
* @return mixed
54+
*/
55+
public static function getNetworkOption($options, $type = self::OPTION_HOST, $feature = self::FEATURE_WS, $scope = self::SCOPE_EXTERNAL){
56+
57+
if($feature === self::FEATURE_MAIN) {
58+
59+
if ($scope === self::SCOPE_INTERNAL) {
60+
// Check if it's the same as external
61+
if (isSet($options["BOOSTER_INTERNAL_CONNECTION"]) && $options["BOOSTER_INTERNAL_CONNECTION"]["group_switch_value"] === "same") {
62+
return self::getNetworkOption($options, $type, $feature, self::SCOPE_EXTERNAL);
63+
} else {
64+
return $options["BOOSTER_INTERNAL_CONNECTION"]["BOOSTER_INTERNAL_" . $type];
65+
}
66+
} else {
67+
68+
return $options["BOOSTER_MAIN_" . $type];
69+
70+
}
71+
72+
} else if ($feature === self::FEATURE_MESSAGING) {
73+
74+
if ($type === self::OPTION_HOST) return $options["NSQ_HOST"];
75+
else if ($type === self::OPTION_PORT) return $options["NSQ_PORT"];
76+
77+
} else if ($feature === self::FEATURE_SERVER_URL){
78+
79+
if (isSet($options["SERVER_INTERNAL_URL"]) && isSet($options["SERVER_INTERNAL_URL"]["group_switch_value"]) && $options["SERVER_INTERNAL_URL"]["group_switch_value"] === "custom") {
80+
$url = $options["SERVER_INTERNAL_URL"]["SERVER_INTERNAL_ADDRESS"];
81+
} else{
82+
$url = ApplicationState::detectServerURL(true, true);
83+
}
84+
return rtrim($url, "/");
85+
86+
} else {
87+
88+
$switchOptionName = "BOOSTER_". $feature. "_ADVANCED";
89+
if(isSet($options[$switchOptionName]) && $options[$switchOptionName]["group_switch_value"] === "same"){
90+
91+
return self::getNetworkOption($options, $type, self::FEATURE_MAIN, $scope);
92+
93+
}else{
94+
95+
return $options[$switchOptionName][$feature."_".$type.($scope === self::SCOPE_INTERNAL ? "_INTERNAL" : "")];
96+
97+
}
98+
99+
}
100+
101+
}
102+
103+
/**
104+
* Check if there is a specific setup for internal IP/PORT for this feature
105+
* @param $options
106+
* @param string $feature
107+
* @return bool
108+
*/
109+
public static function featureHasInternalSetting($options, $feature = self::FEATURE_WS){
110+
111+
if( $feature === self::FEATURE_MAIN ){
112+
113+
if(isSet($options["BOOSTER_INTERNAL_CONNECTION"]) && $options["BOOSTER_INTERNAL_CONNECTION"]["group_switch_value"] === "same"){
114+
return false;
115+
}
116+
$externalHost = $options["BOOSTER_MAIN_HOST"];
117+
$internalHost = $options["BOOSTER_INTERNAL_CONNECTION"]["BOOSTER_INTERNAL_HOST"];
118+
$externalPort = $options["BOOSTER_MAIN_PORT"];
119+
$internalPort = $options["BOOSTER_INTERNAL_CONNECTION"]["BOOSTER_INTERNAL_PORT"];
120+
121+
if( ( !empty($externalHost) && $externalHost !== $internalHost ) || ( !empty($externalPort) && $externalPort !== $internalPort )){
122+
return true;
123+
}else{
124+
return false;
125+
}
126+
127+
128+
}else{
129+
$switchOptionName = "BOOSTER_". $feature. "_ADVANCED";
130+
if(isSet($options[$switchOptionName]) && $options[$switchOptionName]["group_switch_value"] === "same"){
131+
// check main options
132+
return self::featureHasInternalSetting($options, self::FEATURE_MAIN);
133+
}else{
134+
$externalHost = $options[$switchOptionName][$feature."_HOST"];
135+
$internalHost = $options[$switchOptionName][$feature."_HOST_INTERNAL"];
136+
$externalPort = $options[$switchOptionName][$feature."_PORT"];
137+
$internalPort = $options[$switchOptionName][$feature."_PORT_INTERNAL"];
138+
if( ( !empty($externalHost) && $externalHost !== $internalHost ) || ( !empty($externalPort) && $externalPort !== $internalPort )){
139+
return true;
140+
}else{
141+
return false;
142+
}
143+
}
144+
145+
}
146+
147+
148+
}
149+
150+
}

0 commit comments

Comments
 (0)