aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/com/tigervnc/vncviewer/CConn.java9
-rw-r--r--java/com/tigervnc/vncviewer/Parameters.java5
-rw-r--r--java/com/tigervnc/vncviewer/Tunnel.java39
3 files changed, 25 insertions, 28 deletions
diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java
index 3aee46d5..75f6b74b 100644
--- a/java/com/tigervnc/vncviewer/CConn.java
+++ b/java/com/tigervnc/vncviewer/CConn.java
@@ -128,15 +128,20 @@ public class CConn extends CConnection implements
int localPort = TcpSocket.findFreeTcpPort();
if (localPort == 0)
throw new Exception("Could not obtain free TCP port");
- Tunnel.createTunnel(this, localPort);
+ String gatewayHost = Tunnel.getSshHost();
+ if (gatewayHost.isEmpty())
+ gatewayHost = getServerName();
+ Tunnel.createTunnel(gatewayHost, getServerName(),
+ getServerPort(), localPort);
sock = new TcpSocket("localhost", localPort);
+ vlog.info("connected to localhost port "+localPort);
} else {
sock = new TcpSocket(getServerName(), getServerPort());
+ vlog.info("connected to host "+getServerName()+" port "+getServerPort());
}
} catch (java.lang.Exception e) {
throw new Exception(e.getMessage());
}
- vlog.info("connected to host "+getServerName()+" port "+getServerPort());
} else {
String name = sock.getPeerEndpoint();
if (listenMode.getValue())
diff --git a/java/com/tigervnc/vncviewer/Parameters.java b/java/com/tigervnc/vncviewer/Parameters.java
index 2f8a585f..aa4be90a 100644
--- a/java/com/tigervnc/vncviewer/Parameters.java
+++ b/java/com/tigervnc/vncviewer/Parameters.java
@@ -183,11 +183,6 @@ public class Parameters {
"specified in an applet parameter or on the command line",
false);
- public static StringParameter vncServerName
- = new StringParameter("Server",
- "The VNC server <host>[:<dpyNum>] or <host>::<port>",
- "");
-
public static BoolParameter acceptBell
= new BoolParameter("AcceptBell",
"Produce a system beep when requested to by the server.",
diff --git a/java/com/tigervnc/vncviewer/Tunnel.java b/java/com/tigervnc/vncviewer/Tunnel.java
index 2e19160a..ecb048b7 100644
--- a/java/com/tigervnc/vncviewer/Tunnel.java
+++ b/java/com/tigervnc/vncviewer/Tunnel.java
@@ -52,18 +52,10 @@ public class Tunnel {
private final static String DEFAULT_VIA_TEMPLATE
= "-f -L %L:%H:%R %G sleep 20";
- public static void createTunnel(CConn cc, int localPort) throws Exception {
- int remotePort;
- String gatewayHost;
- String remoteHost;
-
- remotePort = cc.getServerPort();
- gatewayHost = cc.getServerName();
- remoteHost = "localhost";
- if (!via.getValue().isEmpty()) {
- gatewayHost = getSshHost();
- remoteHost = cc.getServerName();
- }
+ public static void createTunnel(String gatewayHost,
+ String remoteHost,
+ int remotePort,
+ int localPort) throws Exception {
String pattern = extSSHArgs.getValue();
if (pattern == null || pattern.isEmpty()) {
@@ -102,12 +94,12 @@ public class Tunnel {
public static String getSshHost() {
String sshHost = via.getValue();
- if (sshHost.isEmpty())
- return vncServerName.getValue();
- int end = sshHost.indexOf(":");
- if (end < 0)
- end = sshHost.length();
- sshHost = sshHost.substring(sshHost.indexOf("@")+1, end);
+ if (!sshHost.isEmpty()) {
+ int end = sshHost.indexOf(":");
+ if (end < 0)
+ end = sshHost.length();
+ sshHost = sshHost.substring(sshHost.indexOf("@")+1, end);
+ }
return sshHost;
}
@@ -132,7 +124,8 @@ public class Tunnel {
return sshKeyFile.getValue();
String[] ids = { "id_dsa", "id_rsa" };
for (String id : ids) {
- File f = new File(FileUtils.getHomeDir()+".ssh/"+id);
+ File f = new File(FileUtils.getHomeDir()+".ssh"+
+ FileUtils.getFileSeparator()+id);
if (f.exists() && f.canRead())
return(f.getAbsolutePath());
}
@@ -154,7 +147,8 @@ public class Tunnel {
// NOTE: jsch does not support all ciphers. User may be
// prompted to accept host key authenticy even if
// the key is in the known_hosts file.
- File knownHosts = new File(FileUtils.getHomeDir()+".ssh/known_hosts");
+ File knownHosts = new File(FileUtils.getHomeDir()+".ssh"+
+ FileUtils.getFileSeparator()+"known_hosts");
if (knownHosts.exists() && knownHosts.canRead())
jsch.setKnownHosts(knownHosts.getAbsolutePath());
ArrayList<File> privateKeys = new ArrayList<File>();
@@ -196,7 +190,10 @@ public class Tunnel {
if (session.getConfig("StrictHostKeyChecking") == null)
session.setConfig("StrictHostKeyChecking", "ask");
session.connect();
- session.setPortForwardingL(localPort, remoteHost, remotePort);
+ if (gatewayHost.equals(remoteHost))
+ session.setPortForwardingL(localPort, new String("localhost"), remotePort);
+ else
+ session.setPortForwardingL(localPort, remoteHost, remotePort);
} catch (java.lang.Exception e) {
throw new Exception(e.getMessage());
}