diff options
author | Morten Bøgeskov <source@bogeskov.dk> | 2015-06-04 08:24:34 +0200 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-06-15 12:51:52 -0400 |
commit | 18231200d33b62d2d96286b9bbd84476df5d9189 (patch) | |
tree | 0cef663b566da4c34cf05bb5f720bcda5f6d0455 /src/main/java/com/gitblit/transport/ssh | |
parent | 35a925961d5df5cbdf5ddb7df80b616064b3e0e9 (diff) | |
download | gitblit-18231200d33b62d2d96286b9bbd84476df5d9189.tar.gz gitblit-18231200d33b62d2d96286b9bbd84476df5d9189.zip |
Added git.sshDisplay{Port|Host} to hide port forward.
Running gitblit in a container it's easy to expose the ssh on the default port.
Using git.sshDisplayPort/git.sshDisplayHost you can expose the forwarded address
as the official location.
Diffstat (limited to 'src/main/java/com/gitblit/transport/ssh')
3 files changed, 30 insertions, 11 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java index 0ff5c284..4756d967 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java +++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java @@ -200,14 +200,22 @@ public class SshDaemon { } public String formatUrl(String gituser, String servername, String repository) { - if (sshd.getPort() == DEFAULT_PORT) { + IStoredSettings settings = gitblit.getSettings(); + + int port = sshd.getPort(); + int displayPort = settings.getInteger(Keys.git.sshDisplayPort, port); + String displayServername = settings.getString(Keys.git.sshDisplayHost, ""); + if(displayServername.isEmpty()) { + displayServername = servername; + } + if (displayPort == DEFAULT_PORT) { // standard port - return MessageFormat.format("ssh://{0}@{1}/{2}", gituser, servername, + return MessageFormat.format("ssh://{0}@{1}/{2}", gituser, displayServername, repository); } else { // non-standard port return MessageFormat.format("ssh://{0}@{1}:{2,number,0}/{3}", - gituser, servername, sshd.getPort(), repository); + gituser, displayServername, displayPort, repository); } } diff --git a/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java b/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java index 852756a7..267082ac 100644 --- a/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java +++ b/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java @@ -200,13 +200,18 @@ public class WelcomeShell implements Factory<Command> { } private String formatUrl(String hostname, int port, String username) { - if (port == 22) { + int displayPort = settings.getInteger(Keys.git.sshDisplayPort, port); + String displayHostname = settings.getString(Keys.git.sshDisplayHost, ""); + if(displayHostname.isEmpty()) { + displayHostname = hostname; + } + if (displayPort == 22) { // standard port - return MessageFormat.format("{0}@{1}/REPOSITORY.git", username, hostname); + return MessageFormat.format("{0}@{1}/REPOSITORY.git", username, displayHostname); } else { // non-standard port return MessageFormat.format("ssh://{0}@{1}:{2,number,0}/REPOSITORY.git", - username, hostname, port); + username, displayHostname, displayPort); } } } diff --git a/src/main/java/com/gitblit/transport/ssh/commands/SshCommand.java b/src/main/java/com/gitblit/transport/ssh/commands/SshCommand.java index f18b99bc..06b0e8d8 100644 --- a/src/main/java/com/gitblit/transport/ssh/commands/SshCommand.java +++ b/src/main/java/com/gitblit/transport/ssh/commands/SshCommand.java @@ -16,6 +16,7 @@ */ package com.gitblit.transport.ssh.commands; +import com.gitblit.IStoredSettings; import java.io.IOException; import java.io.PrintWriter; import java.net.MalformedURLException; @@ -73,15 +74,20 @@ public abstract class SshCommand extends BaseCommand { protected String getRepositoryUrl(String repository) { String username = getContext().getClient().getUsername(); - String hostname = getHostname(); - int port = getContext().getGitblit().getSettings().getInteger(Keys.git.sshPort, 0); - if (port == 22) { + IStoredSettings settings = getContext().getGitblit().getSettings(); + String displayHostname = settings.getString(Keys.git.sshDisplayHost, ""); + if(displayHostname.isEmpty()) { + displayHostname = getHostname(); + } + int port = settings.getInteger(Keys.git.sshPort, 0); + int displayPort = settings.getInteger(Keys.git.sshDisplayPort, port); + if (displayPort == 22) { // standard port - return MessageFormat.format("{0}@{1}/{2}.git", username, hostname, repository); + return MessageFormat.format("{0}@{1}/{2}.git", username, displayHostname, repository); } else { // non-standard port return MessageFormat.format("ssh://{0}@{1}:{2,number,0}/{3}", - username, hostname, port, repository); + username, displayHostname, displayPort, repository); } } |