From 622635201a9ce81fd085aa6af6958589c3f55466 Mon Sep 17 00:00:00 2001 From: Konstantin Kliakhandler Date: Wed, 28 Aug 2013 02:05:37 +0300 Subject: [PATCH 1/3] Applied the patch for http proxy. From https://code.google.com/p/connectbot/issues/detail?id=610 By: Bjarni R. Einarsson --- res/values/strings.xml | 5 ++ res/xml/host_prefs.xml | 7 +++ src/sk/vx/connectbot/bean/HostBean.java | 8 ++++ .../vx/connectbot/service/TerminalBridge.java | 1 + .../vx/connectbot/transport/AbsTransport.java | 4 ++ src/sk/vx/connectbot/transport/SSH.java | 48 +++++++++++++++++++ src/sk/vx/connectbot/util/HostDatabase.java | 7 +++ 7 files changed, 80 insertions(+) diff --git a/res/values/strings.xml b/res/values/strings.xml index 852bd5a..a689e54 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -278,6 +278,11 @@ "This may help with slower networks" + + "Use HTTP Proxy" + + "The host:port of an HTTP proxy" + "Start shell session" diff --git a/res/xml/host_prefs.xml b/res/xml/host_prefs.xml index 3059dee..f8ff58b 100644 --- a/res/xml/host_prefs.xml +++ b/res/xml/host_prefs.xml @@ -72,6 +72,13 @@ android:title="@string/hostpref_compression_title" android:summary="@string/hostpref_compression_summary" /> + + 0) { + Log.d(TAG, "Want HTTP Proxy: "+httpproxy, null); + try { + URL u; + if (httpproxy.startsWith("http://")) { + u = new URL(httpproxy); + } else { + u = new URL("http://" + httpproxy); + } + connection.setProxyData(new HTTPProxyData( + u.getHost(), + u.getPort(), + u.getUserInfo(), + u.getAuthority())); + bridge.outputLine("Connecting via proxy: "+httpproxy); + } catch (MalformedURLException e) { + Log.e(TAG, "Could not parse proxy "+httpproxy, e); + + // Display the reason in the text. + bridge.outputLine("Bad proxy URL: "+httpproxy); + + onDisconnect(); + return; + } + } + try { /* Uncomment when debugging SSH protocol: DebugLogger logger = new DebugLogger() { @@ -454,6 +485,14 @@ public class SSH extends AbsTransport implements ConnectionMonitor, InteractiveC connectionInfo.serverToClientCryptoAlgorithm, connectionInfo.serverToClientMACAlgorithm)); } + } catch (HTTPProxyException e) { + Log.e(TAG, "Failed to connect to HTTP Proxy", e); + + // Display the reason in the text. + bridge.outputLine("Failed to connect to HTTP Proxy."); + + onDisconnect(); + return; } catch (IOException e) { Log.e(TAG, "Problem in SSH connection thread during authentication", e); @@ -550,6 +589,8 @@ public class SSH extends AbsTransport implements ConnectionMonitor, InteractiveC Map options = new HashMap(); options.put("compression", Boolean.toString(compression)); + if (httpproxy != null) + options.put("httpproxy", httpproxy); return options; } @@ -558,6 +599,8 @@ public class SSH extends AbsTransport implements ConnectionMonitor, InteractiveC public void setOptions(Map options) { if (options.containsKey("compression")) compression = Boolean.parseBoolean(options.get("compression")); + if (options.containsKey("httpproxy")) + httpproxy = options.get("httpproxy"); } public static String getProtocolName() { @@ -896,6 +939,11 @@ public class SSH extends AbsTransport implements ConnectionMonitor, InteractiveC this.compression = compression; } + @Override + public void setHttpproxy(String httpproxy) { + this.httpproxy = httpproxy; + } + public static String getFormatHint(Context context) { return String.format("%s@%s:%s", context.getString(R.string.format_username), diff --git a/src/sk/vx/connectbot/util/HostDatabase.java b/src/sk/vx/connectbot/util/HostDatabase.java index 0c90bd9..c6ac409 100644 --- a/src/sk/vx/connectbot/util/HostDatabase.java +++ b/src/sk/vx/connectbot/util/HostDatabase.java @@ -66,6 +66,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper { public final static String FIELD_HOST_DELKEY = "delkey"; public final static String FIELD_HOST_FONTSIZE = "fontsize"; public final static String FIELD_HOST_COMPRESSION = "compression"; + public final static String FIELD_HOST_HTTPPROXY = "httpproxy" public final static String FIELD_HOST_ENCODING = "encoding"; public final static String FIELD_HOST_STAYCONNECTED = "stayconnected"; public final static String FIELD_HOST_WANTX11FORWARD = "wantx11forward"; @@ -173,6 +174,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper { + FIELD_HOST_FONTSIZE + " INTEGER, " + FIELD_HOST_WANTSESSION + " TEXT DEFAULT '" + Boolean.toString(true) + "', " + FIELD_HOST_COMPRESSION + " TEXT DEFAULT '" + Boolean.toString(false) + "', " + + FIELD_HOST_HTTPPROXY + " TEXT, " + FIELD_HOST_ENCODING + " TEXT DEFAULT '" + ENCODING_DEFAULT + "', " + FIELD_HOST_STAYCONNECTED + " TEXT, " + FIELD_HOST_WANTX11FORWARD + " TEXT DEFAULT '" + Boolean.toString(false) + "', " @@ -274,6 +276,9 @@ public class HostDatabase extends RobustSQLiteOpenHelper { + " ADD COLUMN " + FIELD_HOST_X11HOST + " TEXT DEFAULT '" + X11HOST_DEFAULT + "'"); db.execSQL("ALTER TABLE " + TABLE_HOSTS + " ADD COLUMN " + FIELD_HOST_X11PORT + " INTEGER DEFAULT " + X11PORT_DEFAULT); + case 23: + db.execSQL("ALTER TABLE " + TABLE_HOSTS + + " ADD COLUMN " + FIELD_HOST_HTTPPROXY + " TEXT"); } } @@ -390,6 +395,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper { COL_DELKEY = c.getColumnIndexOrThrow(FIELD_HOST_DELKEY), COL_FONTSIZE = c.getColumnIndexOrThrow(FIELD_HOST_FONTSIZE), COL_COMPRESSION = c.getColumnIndexOrThrow(FIELD_HOST_COMPRESSION), + COL_HTTPPROXY = c.getColumnIndexOrThrow(FIELD_HOST_HTTPPROXY), COL_ENCODING = c.getColumnIndexOrThrow(FIELD_HOST_ENCODING), COL_STAYCONNECTED = c.getColumnIndexOrThrow(FIELD_HOST_STAYCONNECTED), COL_WANTX11FORWARD = c.getColumnIndexOrThrow(FIELD_HOST_WANTX11FORWARD), @@ -415,6 +421,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper { host.setDelKey(c.getString(COL_DELKEY)); host.setFontSize(c.getInt(COL_FONTSIZE)); host.setCompression(Boolean.valueOf(c.getString(COL_COMPRESSION))); + host.setHttpproxy(c.getString(COL_HTTPPROXY)); host.setEncoding(c.getString(COL_ENCODING)); host.setStayConnected(Boolean.valueOf(c.getString(COL_STAYCONNECTED))); host.setWantX11Forward(Boolean.valueOf(c.getString(COL_WANTX11FORWARD))); From 90bf7273e80ad97ee77a6fa85d91930e0b3a7ff4 Mon Sep 17 00:00:00 2001 From: Konstantin Kliakhandler Date: Wed, 28 Aug 2013 03:20:33 +0300 Subject: [PATCH 2/3] Fixed typo. --- src/sk/vx/connectbot/util/HostDatabase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sk/vx/connectbot/util/HostDatabase.java b/src/sk/vx/connectbot/util/HostDatabase.java index c6ac409..7155dad 100644 --- a/src/sk/vx/connectbot/util/HostDatabase.java +++ b/src/sk/vx/connectbot/util/HostDatabase.java @@ -66,7 +66,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper { public final static String FIELD_HOST_DELKEY = "delkey"; public final static String FIELD_HOST_FONTSIZE = "fontsize"; public final static String FIELD_HOST_COMPRESSION = "compression"; - public final static String FIELD_HOST_HTTPPROXY = "httpproxy" + public final static String FIELD_HOST_HTTPPROXY = "httpproxy"; public final static String FIELD_HOST_ENCODING = "encoding"; public final static String FIELD_HOST_STAYCONNECTED = "stayconnected"; public final static String FIELD_HOST_WANTX11FORWARD = "wantx11forward"; From 53e85307b17c9d2556291315c0c1ce6f0d4ce6fb Mon Sep 17 00:00:00 2001 From: sprig Date: Tue, 17 Sep 2013 10:46:36 +0200 Subject: [PATCH 3/3] updated the hostdatabase version to 24 --- src/sk/vx/connectbot/util/HostDatabase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sk/vx/connectbot/util/HostDatabase.java b/src/sk/vx/connectbot/util/HostDatabase.java index 7155dad..648119a 100644 --- a/src/sk/vx/connectbot/util/HostDatabase.java +++ b/src/sk/vx/connectbot/util/HostDatabase.java @@ -46,7 +46,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper { public final static String TAG = "ConnectBot.HostDatabase"; public final static String DB_NAME = "hosts"; - public final static int DB_VERSION = 23; + public final static int DB_VERSION = 24; public final static String TABLE_HOSTS = "hosts"; public final static String FIELD_HOST_NICKNAME = "nickname";