Permalink
Browse files

Move OptionsHelper to core.mq

  • Loading branch information...
1 parent be01894 commit e7f44ab0d8ebcc48081644945bc0154cbf60ef17 @cdujeu cdujeu committed Oct 11, 2016
@@ -14,22 +14,28 @@
<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"/>
<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"/>
<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"/>
- <global_param group="CONF_MESSAGE[Main Configurations]" name="NSQ_PORT" type="string" label="CONF_MESSAGE[NSQ Port]" description="CONF_MESSAGE[NSQ Port]" default="4150"/>
+ <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" />
+ <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"/>
<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"/>
<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"/>
<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"/>
<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"/>
<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"/>
+ <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"/>
+ <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"/>
+ <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"/>
+ <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://]"/>
+
<global_param group="CONF_MESSAGE[Advanced Configurations]" name="BOOSTER_ADV_WS_LEGEND" type="legend" label="" description="Customize URL's depending on the features."/>
<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"/>
<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"/>
<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"/>
<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"/>
<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"/>
- <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"/>
- <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"/>
+ <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"/>
+ <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"/>
<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"/>
<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"/>
@@ -38,16 +44,11 @@
<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"/>
<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"/>
<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"/>
- <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"/>
- <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"/>
+ <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"/>
+ <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"/>
<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"/>
<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"/>
- <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"/>
- <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"/>
- <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"/>
- <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" />
-
<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"/>
<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"/>
<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"/>
@@ -105,7 +105,7 @@ public function init(ContextInterface $ctx, $options = [])
public function exposeConfigInManifest($configName, $configValue)
{
// Do not expose those
- if(in_array($configName, ["WS_HOST", "WS_PORT", "UPLOAD_HOST", "UPLOAD_PORT"])){
+ if(in_array($configName, ["NSQ_HOST", "NSQ_PORT"])){
return;
}
if(is_array($configValue)){
@@ -290,8 +290,10 @@ private function _sendMessage(ContextInterface $ctx, $topic, $content) {
if(!$wsActive){
return;
}
- $host = $this->getContextualOption($ctx, "NSQ_HOST");
- $port = $this->getContextualOption($ctx, "NSQ_PORT");
+
+ $configs = $this->getConfigs();
+ $host = OptionsHelper::getNetworkOption($configs, OptionsHelper::OPTION_HOST, OptionsHelper::FEATURE_MESSAGING, OptionsHelper::SCOPE_EXTERNAL);
+ $port = intval(OptionsHelper::getNetworkOption($configs, OptionsHelper::OPTION_PORT, OptionsHelper::FEATURE_MESSAGING, OptionsHelper::SCOPE_EXTERNAL));
if(!empty($host) && !empty($port)){
@@ -0,0 +1,150 @@
+<?php
+/*
+ * Copyright 2007-2016 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <https://pydio.com/>.
+ */
+namespace Pydio\Mq\Core;
+
+use Pydio\Core\Services\ApplicationState;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+/**
+ * Helper for parsing core options
+ * @package Pydio\Mq\Core
+ */
+class OptionsHelper
+{
+ const OPTION_HOST = 'HOST';
+ const OPTION_PORT = 'PORT';
+ const OPTION_SECURE = 'SECURE';
+
+ const FEATURE_MAIN = 'main';
+ const FEATURE_WS = 'WS';
+ const FEATURE_UPLOAD = 'UPLOAD';
+ const FEATURE_DOWNLOAD = 'DOWNLOAD';
+ const FEATURE_MESSAGING = 'NSQ';
+ const FEATURE_SERVER_URL = 'SERVER';
+
+ const SCOPE_EXTERNAL = 'external';
+ const SCOPE_INTERNAL = 'internal';
+
+ /**
+ *
+ * @param array $options
+ * @param string $type
+ * @param string $feature
+ * @param string $scope
+ * @return mixed
+ */
+ public static function getNetworkOption($options, $type = self::OPTION_HOST, $feature = self::FEATURE_WS, $scope = self::SCOPE_EXTERNAL){
+
+ if($feature === self::FEATURE_MAIN) {
+
+ if ($scope === self::SCOPE_INTERNAL) {
+ // Check if it's the same as external
+ if (isSet($options["BOOSTER_INTERNAL_CONNECTION"]) && $options["BOOSTER_INTERNAL_CONNECTION"]["group_switch_value"] === "same") {
+ return self::getNetworkOption($options, $type, $feature, self::SCOPE_EXTERNAL);
+ } else {
+ return $options["BOOSTER_INTERNAL_CONNECTION"]["BOOSTER_INTERNAL_" . $type];
+ }
+ } else {
+
+ return $options["BOOSTER_MAIN_" . $type];
+
+ }
+
+ } else if ($feature === self::FEATURE_MESSAGING) {
+
+ if ($type === self::OPTION_HOST) return $options["NSQ_HOST"];
+ else if ($type === self::OPTION_PORT) return $options["NSQ_PORT"];
+
+ } else if ($feature === self::FEATURE_SERVER_URL){
+
+ if (isSet($options["SERVER_INTERNAL_URL"]) && isSet($options["SERVER_INTERNAL_URL"]["group_switch_value"]) && $options["SERVER_INTERNAL_URL"]["group_switch_value"] === "custom") {
+ $url = $options["SERVER_INTERNAL_URL"]["SERVER_INTERNAL_ADDRESS"];
+ } else{
+ $url = ApplicationState::detectServerURL(true, true);
+ }
+ return rtrim($url, "/");
+
+ } else {
+
+ $switchOptionName = "BOOSTER_". $feature. "_ADVANCED";
+ if(isSet($options[$switchOptionName]) && $options[$switchOptionName]["group_switch_value"] === "same"){
+
+ return self::getNetworkOption($options, $type, self::FEATURE_MAIN, $scope);
+
+ }else{
+
+ return $options[$switchOptionName][$feature."_".$type.($scope === self::SCOPE_INTERNAL ? "_INTERNAL" : "")];
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Check if there is a specific setup for internal IP/PORT for this feature
+ * @param $options
+ * @param string $feature
+ * @return bool
+ */
+ public static function featureHasInternalSetting($options, $feature = self::FEATURE_WS){
+
+ if( $feature === self::FEATURE_MAIN ){
+
+ if(isSet($options["BOOSTER_INTERNAL_CONNECTION"]) && $options["BOOSTER_INTERNAL_CONNECTION"]["group_switch_value"] === "same"){
+ return false;
+ }
+ $externalHost = $options["BOOSTER_MAIN_HOST"];
+ $internalHost = $options["BOOSTER_INTERNAL_CONNECTION"]["BOOSTER_INTERNAL_HOST"];
+ $externalPort = $options["BOOSTER_MAIN_PORT"];
+ $internalPort = $options["BOOSTER_INTERNAL_CONNECTION"]["BOOSTER_INTERNAL_PORT"];
+
+ if( ( !empty($externalHost) && $externalHost !== $internalHost ) || ( !empty($externalPort) && $externalPort !== $internalPort )){
+ return true;
+ }else{
+ return false;
+ }
+
+
+ }else{
+ $switchOptionName = "BOOSTER_". $feature. "_ADVANCED";
+ if(isSet($options[$switchOptionName]) && $options[$switchOptionName]["group_switch_value"] === "same"){
+ // check main options
+ return self::featureHasInternalSetting($options, self::FEATURE_MAIN);
+ }else{
+ $externalHost = $options[$switchOptionName][$feature."_HOST"];
+ $internalHost = $options[$switchOptionName][$feature."_HOST_INTERNAL"];
+ $externalPort = $options[$switchOptionName][$feature."_PORT"];
+ $internalPort = $options[$switchOptionName][$feature."_PORT_INTERNAL"];
+ if( ( !empty($externalHost) && $externalHost !== $internalHost ) || ( !empty($externalPort) && $externalPort !== $internalPort )){
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ }
+
+
+ }
+
+}

0 comments on commit e7f44ab

Please sign in to comment.