From 0e8a6f8a79a3389b8b6c2a5d31087ea108d54222 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 10 Feb 2011 16:53:36 +0100 Subject: [PATCH] improve port configuration --- .../sonia/scm/config/ScmConfiguration.java | 54 ++++++++++++++----- .../main/java/sonia/scm/util/HttpUtil.java | 7 ++- .../main/webapp/resources/js/sonia.config.js | 37 +++++++++++-- 3 files changed, 77 insertions(+), 21 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java b/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java index 4f3f4acce9..b87e53f566 100644 --- a/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java +++ b/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java @@ -83,7 +83,8 @@ public class ScmConfiguration this.pluginUrl = other.pluginUrl; this.sslPort = other.sslPort; this.enableSSL = other.enableSSL; - this.port = other.port; + this.enablePortForward = other.enablePortForward; + this.forwardPort = other.forwardPort; this.anonymousAccessEnabled = other.anonymousAccessEnabled; this.adminUsers = other.adminUsers; this.adminGroups = other.adminGroups; @@ -119,9 +120,9 @@ public class ScmConfiguration * * @return */ - public String getPluginUrl() + public int getForwardPort() { - return pluginUrl; + return forwardPort; } /** @@ -130,9 +131,9 @@ public class ScmConfiguration * * @return */ - public int getPort() + public String getPluginUrl() { - return port; + return pluginUrl; } /** @@ -168,6 +169,17 @@ public class ScmConfiguration return anonymousAccessEnabled; } + /** + * Method description + * + * + * @return + */ + public boolean isEnablePortForward() + { + return enablePortForward; + } + /** * Method description * @@ -214,6 +226,17 @@ public class ScmConfiguration this.anonymousAccessEnabled = anonymousAccessEnabled; } + /** + * Method description + * + * + * @param enablePortForward + */ + public void setEnablePortForward(boolean enablePortForward) + { + this.enablePortForward = enablePortForward; + } + /** * Method description * @@ -229,22 +252,22 @@ public class ScmConfiguration * Method description * * - * @param pluginUrl + * @param forwardPort */ - public void setPluginUrl(String pluginUrl) + public void setForwardPort(int forwardPort) { - this.pluginUrl = pluginUrl; + this.forwardPort = forwardPort; } /** * Method description * * - * @param port + * @param pluginUrl */ - public void setPort(int port) + public void setPluginUrl(String pluginUrl) { - this.port = port; + this.pluginUrl = pluginUrl; } /** @@ -282,11 +305,11 @@ public class ScmConfiguration private Set adminUsers; /** Field description */ - @XmlElement(name = "plugin-url") - private String pluginUrl = DEFAULT_PLUGINURL; + private int forwardPort = 80; /** Field description */ - private int port = -1; + @XmlElement(name = "plugin-url") + private String pluginUrl = DEFAULT_PLUGINURL; /** Field description */ private String servername = "localhost"; @@ -294,6 +317,9 @@ public class ScmConfiguration /** Field description */ private boolean enableSSL = false; + /** Field description */ + private boolean enablePortForward = false; + /** Field description */ private int sslPort = 8181; diff --git a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java index b8ad7d45fc..7b955c4f40 100644 --- a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java @@ -97,12 +97,11 @@ public class HttpUtil { port = configuration.getSslPort(); } - else + else if (configuration.isEnablePortForward()) { - port = configuration.getPort(); + port = configuration.getForwardPort(); } - - if (port <= 0) + else { port = request.getLocalPort(); } diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.config.js b/scm-webapp/src/main/webapp/resources/js/sonia.config.js index b16f273fb5..0762e67042 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.config.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.config.js @@ -99,9 +99,21 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{ name: 'servername', allowBlank: false },{ + xtype: 'checkbox', + fieldLabel: 'Enable forwarding (mod_proxy)', + name: 'enablePortForward', + inputValue: 'true', + listeners: { + check: function(){ + Ext.getCmp('serverport').setDisabled( ! this.checked ); + } + } + },{ + id: 'serverport', xtype: 'numberfield', - fieldLabel: 'Serverport', - name: 'port', + fieldLabel: 'Forward Port', + name: 'forwardPort', + disabled: true, allowBlank: false },{ xtype: 'textfield', @@ -118,11 +130,18 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{ xtype: 'checkbox', fieldLabel: 'Enable SSL', name: 'enableSSL', - inputValue: 'true' + inputValue: 'true', + listeners: { + check: function(){ + Ext.getCmp('sslPort').setDisabled( ! this.checked ); + } + } },{ + id: 'sslPort', xtype: 'numberfield', fieldLabel: 'SSL Port', name: 'sslPort', + disabled: true, allowBlank: false },{ xtype : 'textfield', @@ -137,6 +156,12 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{ }], onSubmit: function(values){ + if ( ! values.enableSSL ){ + values.sslPort = Ext.getCmp('sslPort').getValue(); + } + if ( ! values.enablePortForward ){ + values.forwardPort = Ext.getCmp('serverport').getValue(); + } this.el.mask('Submit ...'); Ext.Ajax.request({ url: restUrl + 'config.json', @@ -163,6 +188,12 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{ success: function(response){ var obj = Ext.decode(response.responseText); this.load(obj); + if ( obj.enablePortForward ){ + Ext.getCmp('serverport').setDisabled(false); + } + if ( obj.enableSSL ){ + Ext.getCmp('sslPort').setDisabled(false); + } clearTimeout(tid); el.unmask(); },