aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2008-11-07 19:22:58 +0000
committerKenny Root <kenny@the-b.org>2008-11-07 19:22:58 +0000
commita15922f44e480a8a6c09741507b1af00d1468d3b (patch)
treeb3f070ca023a39e5439326d620432c9d9aa1f5e9 /src
parent706a57a55373b68604acc9a54ddcf5fd8f47d9d2 (diff)
downloadconnectbot-a15922f44e480a8a6c09741507b1af00d1468d3b.tar.gz
connectbot-a15922f44e480a8a6c09741507b1af00d1468d3b.tar.bz2
connectbot-a15922f44e480a8a6c09741507b1af00d1468d3b.zip
* Allow changing tunnels on connected hosts
* "Port forwards" menu item in ConsoleActivity goes to PortForwardListActivity now * Allow users to delete tunnels
Diffstat (limited to 'src')
-rw-r--r--src/org/connectbot/ConsoleActivity.java30
-rw-r--r--src/org/connectbot/PortForwardListActivity.java87
-rw-r--r--src/org/connectbot/service/TerminalBridge.java1
-rw-r--r--src/org/connectbot/service/TerminalManager.java2
-rw-r--r--src/org/connectbot/util/HostDatabase.java16
5 files changed, 99 insertions, 37 deletions
diff --git a/src/org/connectbot/ConsoleActivity.java b/src/org/connectbot/ConsoleActivity.java
index ee24993..98ff46c 100644
--- a/src/org/connectbot/ConsoleActivity.java
+++ b/src/org/connectbot/ConsoleActivity.java
@@ -59,7 +59,6 @@ import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
-import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -67,8 +66,9 @@ import android.widget.ViewFlipper;
import de.mud.terminal.vt320;
public class ConsoleActivity extends Activity {
-
public final static String TAG = ConsoleActivity.class.toString();
+
+ protected static final int REQUEST_EDIT = 1;
protected ViewFlipper flip = null;
protected TerminalManager bound = null;
@@ -158,7 +158,7 @@ public class ConsoleActivity extends Activity {
if(!(view instanceof TerminalView)) return null;
return ((TerminalView)view).bridge.nickname;
}
-
+
public Handler promptHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -664,27 +664,9 @@ public class ConsoleActivity extends Activity {
portForward.setEnabled(activeTerminal && authenticated);
portForward.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
- // show dialog to create portForward for this host
- final TerminalView terminal = (TerminalView)view;
-
- // build dialog to prompt user about updating
- final View portForwardView = inflater.inflate(R.layout.dia_portforward, null, false);
- ((RadioButton)portForwardView.findViewById(R.id.portforward_local)).setChecked(true);
- new AlertDialog.Builder(ConsoleActivity.this)
- .setView(portForwardView)
- .setPositiveButton(R.string.portforward_pos, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- String nickname = ((TextView)portForwardView.findViewById(R.id.nickname)).getText().toString();
- String type = ((RadioButton)portForwardView.findViewById(R.id.portforward_local)).isChecked()
- ? HostDatabase.PORTFORWARD_LOCAL : HostDatabase.PORTFORWARD_REMOTE;
- String source = ((TextView)portForwardView.findViewById(R.id.portforward_source)).getText().toString();
- String dest = ((TextView)portForwardView.findViewById(R.id.portforward_destination)).getText().toString();
-
- createPortForward(terminal, nickname, type, source, dest);
- }
- })
- .setNegativeButton(R.string.portforward_neg, null).create().show();
-
+ Intent intent = new Intent(ConsoleActivity.this, PortForwardListActivity.class);
+ intent.putExtra(Intent.EXTRA_TITLE, bound.hostdb.findHostByNickname(getCurrentNickname()));
+ ConsoleActivity.this.startActivityForResult(intent, REQUEST_EDIT);
return true;
}
});
diff --git a/src/org/connectbot/PortForwardListActivity.java b/src/org/connectbot/PortForwardListActivity.java
index 3bee861..cd9ca97 100644
--- a/src/org/connectbot/PortForwardListActivity.java
+++ b/src/org/connectbot/PortForwardListActivity.java
@@ -21,16 +21,21 @@ package org.connectbot;
import java.util.List;
import org.connectbot.bean.PortForwardBean;
+import org.connectbot.service.TerminalBridge;
+import org.connectbot.service.TerminalManager;
import org.connectbot.util.HostDatabase;
import android.app.AlertDialog;
import android.app.ListActivity;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
+import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.ContextMenu;
@@ -60,14 +65,18 @@ public class PortForwardListActivity extends ListActivity {
protected Cursor hosts;
protected List<PortForwardBean> portForwards;
+ protected ServiceConnection connection = null;
+ protected TerminalBridge hostBridge = null;
protected LayoutInflater inflater = null;
private long hostId;
-
+
@Override
public void onStart() {
super.onStart();
+ this.bindService(new Intent(this, TerminalManager.class), connection, Context.BIND_AUTO_CREATE);
+
if(this.hostdb == null)
this.hostdb = new HostDatabase(this);
}
@@ -76,6 +85,8 @@ public class PortForwardListActivity extends ListActivity {
public void onStop() {
super.onStop();
+ this.unbindService(connection);
+
if(this.hostdb != null) {
this.hostdb.close();
this.hostdb = null;
@@ -92,11 +103,30 @@ public class PortForwardListActivity extends ListActivity {
// connect with hosts database and populate list
this.hostdb = new HostDatabase(this);
+ final String hostNickname = hostdb.findNicknameById(hostId);
this.setTitle(String.format("%s: %s (%s)",
getResources().getText(R.string.app_name),
getResources().getText(R.string.title_port_forwards_list),
- hostdb.findNicknameById(hostId)));
+ hostNickname));
+
+ connection = new ServiceConnection() {
+ public void onServiceConnected(ComponentName className, IBinder service) {
+ TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService();
+
+ for (TerminalBridge bridge: bound.bridges) {
+ if (bridge.nickname.equals(hostNickname)) {
+ hostBridge = bridge;
+ Log.d(TAG, "Found host bridge; using that instead of database");
+ break;
+ }
+ }
+ }
+
+ public void onServiceDisconnected(ComponentName name) {
+ hostBridge = null;
+ }
+ };
this.updateList();
@@ -133,6 +163,11 @@ public class PortForwardListActivity extends ListActivity {
sourcePortEdit.getText().toString(),
destEdit.getText().toString());
+ if (hostBridge != null) {
+ hostBridge.addPortForward(pfb);
+ hostBridge.enablePortForward(pfb);
+ }
+
if (!hostdb.savePortForward(pfb))
throw new Exception("Could not save port forward");
@@ -196,6 +231,12 @@ public class PortForwardListActivity extends ListActivity {
pfb.setSourcePort(Integer.parseInt(sourcePortEdit.getText().toString()));
pfb.setDest(destEdit.getText().toString());
+ // Use the new settings for the existing connection.
+ if (hostBridge != null) {
+ hostBridge.disablePortForward(pfb);
+ hostBridge.enablePortForward(pfb);
+ }
+
if (!hostdb.savePortForward(pfb))
throw new Exception("Could not save port forward");
@@ -211,6 +252,33 @@ public class PortForwardListActivity extends ListActivity {
return true;
}
});
+
+ MenuItem delete = menu.add(R.string.portforward_delete);
+ delete.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ public boolean onMenuItemClick(MenuItem item) {
+ // prompt user to make sure they really want this
+ new AlertDialog.Builder(PortForwardListActivity.this)
+ .setMessage(getString(R.string.delete_message, pfb.getNickname()))
+ .setPositiveButton(R.string.delete_pos, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ try {
+ // Delete the port forward from the host if needed.
+ if (hostBridge != null)
+ hostBridge.removePortForward(pfb);
+
+ hostdb.deletePortForward(pfb);
+ } catch (Exception e) {
+ Log.e(TAG, "Could not delete port forward", e);
+ }
+
+ updateHandler.sendEmptyMessage(-1);
+ }
+ })
+ .setNegativeButton(R.string.delete_neg, null).create().show();
+
+ return true;
+ }
+ });
}
public Handler updateHandler = new Handler() {
@@ -220,15 +288,16 @@ public class PortForwardListActivity extends ListActivity {
}
};
- protected void updateList() {
- if (this.hostdb == null) return;
-
- this.portForwards = this.hostdb.getPortForwardsForHost(hostId);
-
+ protected void updateList() {
+ if (hostBridge != null) {
+ this.portForwards = hostBridge.getPortForwards();
+ } else {
+ if (this.hostdb == null) return;
+ this.portForwards = this.hostdb.getPortForwardsForHost(hostId);
+ }
+
PortForwardAdapter adapter = new PortForwardAdapter(this, this.portForwards);
this.setListAdapter(adapter);
-
- //this.startManagingCursor(portForwards);
}
class PortForwardAdapter extends ArrayAdapter<PortForwardBean> {
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
index 9bf4790..22411fa 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -25,7 +25,6 @@ import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
diff --git a/src/org/connectbot/service/TerminalManager.java b/src/org/connectbot/service/TerminalManager.java
index 54f7ec1..336d1fa 100644
--- a/src/org/connectbot/service/TerminalManager.java
+++ b/src/org/connectbot/service/TerminalManager.java
@@ -62,7 +62,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
protected Resources res;
- protected HostDatabase hostdb;
+ public HostDatabase hostdb;
protected PubkeyDatabase pubkeydb;
protected SharedPreferences prefs;
diff --git a/src/org/connectbot/util/HostDatabase.java b/src/org/connectbot/util/HostDatabase.java
index 59d6326..dd003fe 100644
--- a/src/org/connectbot/util/HostDatabase.java
+++ b/src/org/connectbot/util/HostDatabase.java
@@ -417,8 +417,7 @@ public class HostDatabase extends SQLiteOpenHelper {
/**
* Update the parameters of a port forward in the database.
- * @param port forwardId ID of port forward in database
- * @param values
+ * @param pfb {@link PortForwardBean} to save
* @return true on success
*/
public boolean savePortForward(PortForwardBean pfb) {
@@ -438,4 +437,17 @@ public class HostDatabase extends SQLiteOpenHelper {
return success;
}
+
+ /**
+ * Deletes a port forward from the database.
+ * @param pfb {@link PortForwardBean} to delete
+ */
+ public void deletePortForward(PortForwardBean pfb) {
+ if (pfb.getId() < 0)
+ return;
+
+ SQLiteDatabase db = this.getWritableDatabase();
+ db.delete(TABLE_PORTFORWARDS, "_id = ?", new String[] { String.valueOf(pfb.getId()) });
+ db.close();
+ }
}