diff options
Diffstat (limited to 'src/org/theb/ssh')
-rw-r--r-- | src/org/theb/ssh/HostDbProvider.java | 29 | ||||
-rw-r--r-- | src/org/theb/ssh/HostEditor.java | 115 | ||||
-rw-r--r-- | src/org/theb/ssh/HostsList.java | 98 | ||||
-rw-r--r-- | src/org/theb/ssh/PasswordDialog.java | 2 | ||||
-rw-r--r-- | src/org/theb/ssh/Pubkey.java | 2 | ||||
-rw-r--r-- | src/org/theb/ssh/SecureShell.java | 1 | ||||
-rw-r--r-- | src/org/theb/ssh/TouchEntropy.java | 2 | ||||
-rw-r--r-- | src/org/theb/ssh/TrileadConnectionThread.java | 46 |
8 files changed, 183 insertions, 112 deletions
diff --git a/src/org/theb/ssh/HostDbProvider.java b/src/org/theb/ssh/HostDbProvider.java index ecb0eed..f3bdbd5 100644 --- a/src/org/theb/ssh/HostDbProvider.java +++ b/src/org/theb/ssh/HostDbProvider.java @@ -43,7 +43,7 @@ public class HostDbProvider extends ContentProvider { private static final String TAG = "HostDbProvider"; private static final String DATABASE_NAME = "ssh_hosts.db"; - private static final int DATABASE_VERSION = 2; + private static final int DATABASE_VERSION = 3; private static HashMap<String, String> HOSTS_LIST_PROJECTION_MAP; @@ -61,9 +61,15 @@ public class HostDbProvider extends ContentProvider { @Override public void onCreate(SQLiteDatabase db) { - db.execSQL("CREATE TABLE hosts (_id INTEGER PRIMARY KEY," - + "hostname TEXT," + "username TEXT," + "port INTEGER," - + "hostkey TEXT" + ")"); + db.execSQL("CREATE TABLE hosts (_id INTEGER PRIMARY KEY," + + "nickname TEXT," + + "hostname TEXT," + + "username TEXT," + + "port INTEGER," + + "emulation TEXT," + + "scrollback INTEGER," + + "hostkey TEXT" + + ")"); } @Override @@ -127,6 +133,10 @@ public class HostDbProvider extends ContentProvider { throw new IllegalArgumentException("Unknown Insert " + uri); } */ + if (values.containsKey(HostDb.Hosts.NICKNAME) == false) { + values.put(HostDb.Hosts.NICKNAME, ""); + } + if (values.containsKey(HostDb.Hosts.HOSTNAME) == false) { values.put(HostDb.Hosts.HOSTNAME, ""); } @@ -143,6 +153,14 @@ public class HostDbProvider extends ContentProvider { values.put(HostDb.Hosts.HOSTKEY, ""); } + if (values.containsKey(HostDb.Hosts.EMULATION) == false) { + values.put(HostDb.Hosts.EMULATION, ""); + } + + if (values.containsKey(HostDb.Hosts.SCROLLBACK) == false) { + values.put(HostDb.Hosts.SCROLLBACK, ""); + } + rowID = mDB.insert("hosts", "host", values); if (rowID > 0) { Uri newUri = ContentUris.withAppendedId(HostDb.Hosts.CONTENT_URI, rowID); @@ -228,9 +246,12 @@ public class HostDbProvider extends ContentProvider { HOSTS_LIST_PROJECTION_MAP = new HashMap<String, String>(); HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts._ID, "_id"); + HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts.NICKNAME, "nickname"); HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts.HOSTNAME, "hostname"); HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts.USERNAME, "username"); HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts.PORT, "port"); HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts.HOSTKEY, "hostkey"); + HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts.EMULATION, "emulation"); + HOSTS_LIST_PROJECTION_MAP.put(HostDb.Hosts.SCROLLBACK, "scrollback"); } } diff --git a/src/org/theb/ssh/HostEditor.java b/src/org/theb/ssh/HostEditor.java index d9618eb..ed0d101 100644 --- a/src/org/theb/ssh/HostEditor.java +++ b/src/org/theb/ssh/HostEditor.java @@ -18,6 +18,7 @@ */ package org.theb.ssh; +import org.theb.ssh.R; import org.theb.provider.HostDb; import android.app.Activity; @@ -31,29 +32,26 @@ import android.view.WindowManager; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; +import android.widget.Spinner; public class HostEditor extends Activity { - public static final String EDIT_HOST_ACTION = - "com.theb.ssh.action.EDIT_HOST"; + public static final String EDIT_HOST_ACTION = "com.theb.ssh.action.EDIT_HOST"; - private static final String[] PROJECTION = new String[] { - HostDb.Hosts._ID, // 0 - HostDb.Hosts.HOSTNAME, // 1 - HostDb.Hosts.USERNAME, // 2 - HostDb.Hosts.PORT, // 3 - HostDb.Hosts.HOSTKEY, // 4 - }; + private static final String[] PROJECTION = new String[] { HostDb.Hosts._ID, + HostDb.Hosts.NICKNAME, HostDb.Hosts.HOSTNAME, + HostDb.Hosts.USERNAME, HostDb.Hosts.PORT, HostDb.Hosts.EMULATION, + HostDb.Hosts.SCROLLBACK, }; + + private static final int INDEX_NICKNAME = 1, INDEX_HOSTNAME = 2, + INDEX_USERNAME = 3, INDEX_PORT = 4, INDEX_EMULATION = 5, + INDEX_SCROLLBACK = 6; - static final int HOSTNAME_INDEX = 1; - private static final int USERNAME_INDEX = 2; - private static final int PORT_INDEX = 3; // Set up distinct states that the activity can be run in. private static final int STATE_EDIT = 0; private static final int STATE_INSERT = 1; - private EditText mHostname; - private EditText mUsername; - private EditText mPort; + private EditText mNickname, mHostname, mUsername, mPort, mScrollback; + private Spinner mEmulation; // Cursor that will provide access to the host data we are editing private Cursor mCursor; @@ -64,37 +62,20 @@ public class HostEditor extends Activity { @Override public void onCreate(Bundle savedValues) { super.onCreate(savedValues); - - // TODO: update or remove - // Have the system blur any windows behind this one. - //getWindow().setFlags(WindowManager.LayoutParams.BLUR_BEHIND_FLAG, - // WindowManager.LayoutParams.BLUR_BEHIND_FLAG); - - // Apply a tint to any windows behind this one. Doing a tint this - // way is more efficient than using a translucent background. Note - // that the tint color really should come from a resource. - WindowManager.LayoutParams lp = getWindow().getAttributes(); - //lp.tintBehind = 0x60000820; - getWindow().setAttributes(lp); - - this.setContentView(R.layout.host_editor); + this.setContentView(R.layout.act_hosteditor); // Set up click handlers for text fields and button - mHostname = (EditText) findViewById(R.id.hostname); - mUsername = (EditText) findViewById(R.id.username); - mPort = (EditText) findViewById(R.id.port); - - Button addButton = (Button) findViewById(R.id.add); - addButton.setOnClickListener(mCommitListener); - - Button cancelButton = (Button) findViewById(R.id.cancel); - cancelButton.setOnClickListener(mCancelListener); - - final Intent intent = getIntent(); + this.mNickname = (EditText) findViewById(R.id.edit_nickname); + this.mHostname = (EditText) findViewById(R.id.edit_hostname); + this.mUsername = (EditText) findViewById(R.id.edit_username); + this.mPort = (EditText) findViewById(R.id.edit_port); + this.mEmulation = (Spinner) findViewById(R.id.edit_emulation); + this.mScrollback = (EditText) findViewById(R.id.edit_scrollback); // Do some setup based on the action being performed. - + final Intent intent = getIntent(); final String action = intent.getAction(); + if (Intent.ACTION_INSERT.equals(action)) { mState = STATE_INSERT; mURI = getContentResolver().insert(intent.getData(), null); @@ -103,8 +84,7 @@ public class HostEditor extends Activity { // this activity. A RESULT_CANCELED will be sent back to the // original activity if they requested a result. if (mURI == null) { - Log.e("Notes", "Failed to insert new note into " - + getIntent().getData()); + Log.e("Notes", "Failed to insert new note into " + getIntent().getData()); finish(); return; } @@ -119,13 +99,10 @@ public class HostEditor extends Activity { // Get the URI of the host whose properties we want to edit mURI = getIntent().getData(); - - // If were editing, change the Ok button to be Change instead. - addButton.setText(R.string.button_change); } // Get a cursor to access the host data - mCursor = managedQuery(mURI, PROJECTION, null, null); + this.mCursor = managedQuery(mURI, PROJECTION, null, null); } @Override @@ -133,17 +110,16 @@ public class HostEditor extends Activity { super.onResume(); // Initialize the text with the host data - if (mCursor != null) { + if(mCursor != null) { mCursor.moveToFirst(); - String hostname = mCursor.getString(HOSTNAME_INDEX); - mHostname.setText(hostname); - - String username = mCursor.getString(USERNAME_INDEX); - mUsername.setText(username); + this.mNickname.setText(mCursor.getString(this.INDEX_NICKNAME)); + this.mHostname.setText(mCursor.getString(this.INDEX_HOSTNAME)); + this.mUsername.setText(mCursor.getString(this.INDEX_USERNAME)); + this.mPort.setText(mCursor.getString(this.INDEX_PORT)); + //this.emulation.setText(cursor.getString(this.INDEX_EMULATION)); + this.mScrollback.setText(mCursor.getString(this.INDEX_SCROLLBACK)); - String port = mCursor.getString(PORT_INDEX); - mPort.setText(port); } } @@ -152,17 +128,24 @@ public class HostEditor extends Activity { super.onPause(); // Write the text back into the cursor - if (mCursor != null) { + if(mCursor != null) { + String nickname = mNickname.getText().toString(); + mCursor.updateString(INDEX_NICKNAME, nickname); + String hostname = mHostname.getText().toString(); - mCursor.updateString(HOSTNAME_INDEX, hostname); + mCursor.updateString(INDEX_HOSTNAME, hostname); String username = mUsername.getText().toString(); - mCursor.updateString(USERNAME_INDEX, username); + mCursor.updateString(INDEX_USERNAME, username); String portStr = mPort.getText().toString(); int port = Integer.parseInt(portStr); - mCursor.updateInt(PORT_INDEX, port); + mCursor.updateInt(INDEX_PORT, port); + String scrollbackStr = mScrollback.getText().toString(); + int scrollback = Integer.parseInt(scrollbackStr); + mCursor.updateInt(INDEX_SCROLLBACK, scrollback); + if (isFinishing() && ((hostname.length() == 0) || (username.length() == 0) @@ -197,18 +180,4 @@ public class HostEditor extends Activity { } } - OnClickListener mCommitListener = new OnClickListener() { - public void onClick(View v) { - // When the user clicks, just finish this activity. - // onPause will be called, and we save our data there. - finish(); - } - }; - - OnClickListener mCancelListener = new OnClickListener() { - public void onClick(View v) { - cancelEdit(); - finish(); - } - }; } diff --git a/src/org/theb/ssh/HostsList.java b/src/org/theb/ssh/HostsList.java index fc62baf..703d09c 100644 --- a/src/org/theb/ssh/HostsList.java +++ b/src/org/theb/ssh/HostsList.java @@ -18,18 +18,27 @@ */ package org.theb.ssh; +import org.connectbot.Console; +import org.connectbot.service.TerminalBridge; +import org.connectbot.service.TerminalManager; +import org.theb.ssh.R; import org.theb.provider.HostDb; +import com.trilead.ssh2.Connection; + import android.app.Dialog; import android.app.ListActivity; import android.content.ComponentName; import android.content.ContentUris; import android.content.Context; import android.content.Intent; +import android.content.ServiceConnection; import android.database.Cursor; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; +import android.os.IBinder; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; @@ -55,6 +64,7 @@ public class HostsList extends ListActivity { HostDb.Hosts.HOSTNAME, HostDb.Hosts.USERNAME, HostDb.Hosts.PORT, + HostDb.Hosts.NICKNAME }; private Cursor mCursor; @@ -78,26 +88,59 @@ public class HostsList extends ListActivity { String label; TextView textView = (TextView) view; - label = cursor.getString(2) - + "@" - + cursor.getString(1); - - int port = cursor.getInt(3); - if (port != 22) { - label = label + ":" + String.valueOf(port); - } +// label = cursor.getString(2) + "@" + cursor.getString(1); +// int port = cursor.getInt(3); +// if (port != 22) { +// label = label + ":" + String.valueOf(port); +// } + label = cursor.getString(4); textView.setText(label); } } + + + + + public TerminalManager bound = null; + + private ServiceConnection connection = new ServiceConnection() { + public void onServiceConnected(ComponentName className, IBinder service) { + Log.d(this.getClass().toString(), "yay we bound to our terminalmanager"); + bound = ((TerminalManager.TerminalBinder) service).getService(); + + // TODO: update our green bulb icons by checking for existing bridges + // open up some test sessions +// try { +// bound.openConnection("192.168.254.230", 22, "connectbot", "b0tt", "screen", 100); +// bound.openConnection("192.168.254.230", 22, "connectbot", "b0tt", "screen", 100); +// bound.openConnection("192.168.254.230", 22, "connectbot", "b0tt", "screen", 100); +// } catch(Exception e) { +// e.printStackTrace(); +// } + + } + + public void onServiceDisconnected(ComponentName className) { + Log.d(this.getClass().toString(), "oops our terminalmanager was lost"); + bound = null; + } + }; + + /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT); + // start the terminal manager service and bind locally + this.startService(new Intent(this, TerminalManager.class)); + this.bindService(new Intent(this, TerminalManager.class), connection, Context.BIND_AUTO_CREATE); + + + //setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT); Intent intent = getIntent(); if (intent.getData() == null) { @@ -267,7 +310,42 @@ public class HostsList extends ListActivity { setResult(RESULT_OK, intent); } else { // Launch activity to view/edit the currently selected item - startActivity(new Intent(Intent.ACTION_PICK, url)); + //startActivity(new Intent(Intent.ACTION_PICK, url)); + + // collect all connection details + Cursor cursor = managedQuery(url, new String[] { "nickname", + "username", "hostname", "port", "emulation", "scrollback", + "hostkey" }, null, null); + cursor.moveToFirst(); + + // try finding an already-open bridge for this connection + String nickname = cursor.getString(0); + TerminalBridge bridge = bound.findBridge(nickname); + if(bridge == null) { + // too bad, looks like we have to open the bridge ourselves + String username = cursor.getString(1); + String hostname = cursor.getString(2); + int port = cursor.getInt(3); + String emulation = cursor.getString(4); + int scrollback = cursor.getInt(5); + String hostkey = cursor.getString(6); + + try { + //Connection conn; + //bound.openConnection(conn, nickname, emulation, scrollback); + bound.openConnection(nickname, hostname, port, username, "moocow", "screen", 100); + } catch(Exception e) { + e.printStackTrace(); + } + + + } + + // open the console view and select this specific terminal + Intent intent = new Intent(this, Console.class); + intent.putExtra(Intent.EXTRA_TEXT, nickname); + this.startActivity(intent); + } } diff --git a/src/org/theb/ssh/PasswordDialog.java b/src/org/theb/ssh/PasswordDialog.java index 91da6b0..adcca36 100644 --- a/src/org/theb/ssh/PasswordDialog.java +++ b/src/org/theb/ssh/PasswordDialog.java @@ -18,6 +18,8 @@ */ package org.theb.ssh; +import org.theb.ssh.R; + import android.app.Activity; import android.content.Intent; import android.os.Bundle; diff --git a/src/org/theb/ssh/Pubkey.java b/src/org/theb/ssh/Pubkey.java index 9dffe08..95abba7 100644 --- a/src/org/theb/ssh/Pubkey.java +++ b/src/org/theb/ssh/Pubkey.java @@ -26,6 +26,8 @@ import java.security.SecureRandom; import java.security.Security; import java.util.concurrent.Semaphore; +import org.theb.ssh.R; + import android.app.Activity; import android.content.Intent; import android.os.Bundle; diff --git a/src/org/theb/ssh/SecureShell.java b/src/org/theb/ssh/SecureShell.java index 68738f0..e2bb4f4 100644 --- a/src/org/theb/ssh/SecureShell.java +++ b/src/org/theb/ssh/SecureShell.java @@ -21,6 +21,7 @@ package org.theb.ssh; import java.io.IOException; import java.io.OutputStream; +import org.theb.ssh.R; import org.theb.provider.HostDb; import com.trilead.ssh2.ConnectionMonitor; diff --git a/src/org/theb/ssh/TouchEntropy.java b/src/org/theb/ssh/TouchEntropy.java index bf2d737..fc633b0 100644 --- a/src/org/theb/ssh/TouchEntropy.java +++ b/src/org/theb/ssh/TouchEntropy.java @@ -1,5 +1,7 @@ package org.theb.ssh; +import org.theb.ssh.R; + import android.app.Activity; import android.content.Context; import android.content.Intent; diff --git a/src/org/theb/ssh/TrileadConnectionThread.java b/src/org/theb/ssh/TrileadConnectionThread.java index 1e51afc..b874756 100644 --- a/src/org/theb/ssh/TrileadConnectionThread.java +++ b/src/org/theb/ssh/TrileadConnectionThread.java @@ -41,12 +41,12 @@ public class TrileadConnectionThread extends ConnectionThread { private Semaphore sPass; - protected FeedbackUI ui; + //protected FeedbackUI ui; protected Terminal term; public TrileadConnectionThread(FeedbackUI ui, Terminal term, String hostname, String username, int port) { super(ui, hostname, username, port); - this.ui = ui; + //this.ui = ui; this.term = term; this.hostname = hostname; this.username = username; @@ -80,14 +80,13 @@ public class TrileadConnectionThread extends ConnectionThread { public void run() { connection = new Connection(hostname, port); - connection.addConnectionMonitor((ConnectionMonitor) ui); - - ui.setWaiting(true, "Connection", "Connecting to " + hostname + "..."); + //connection.addConnectionMonitor((ConnectionMonitor) ui); + //ui.setWaiting(true, "Connection", "Connecting to " + hostname + "..."); try { connection.connect(new InteractiveHostKeyVerifier()); - ui.setWaiting(true, "Authenticating", "Trying to authenticate..."); + //ui.setWaiting(true, "Authenticating", "Trying to authenticate..."); // boolean enableKeyboardInteractive = true; // boolean enableDSA = true; @@ -100,21 +99,21 @@ public class TrileadConnectionThread extends ConnectionThread { */ if (connection.isAuthMethodAvailable(username, "password")) { - ui.setWaiting(true, "Authenticating", - "Trying to authenticate using password..."); + //ui.setWaiting(true, "Authenticating","Trying to authenticate using password..."); // Set a semaphore that is unset by the returning dialog. - sPass = new Semaphore(0); - ui.askPassword(); - - // Wait for the user to answer. - sPass.acquire(); - sPass = null; - if (password == null) - continue; - - boolean res = connection.authenticateWithPassword(username, - password); +// sPass = new Semaphore(0); +// ui.askPassword(); +// +// // Wait for the user to answer. +// sPass.acquire(); +// sPass = null; +// if (password == null) +// continue; + + password = "b0tt"; + + boolean res = connection.authenticateWithPassword(username, password); password = null; if (res == true) break; @@ -126,7 +125,7 @@ public class TrileadConnectionThread extends ConnectionThread { "No supported authentication methods available."); } - ui.setWaiting(true, "Session", "Requesting shell..."); + //ui.setWaiting(true, "Session", "Requesting shell..."); session = connection.openSession(); @@ -141,12 +140,9 @@ public class TrileadConnectionThread extends ConnectionThread { // stderr = session.getStderr(); stdOut = session.getStdout(); - ui.setWaiting(false, null, null); + //ui.setWaiting(false, null, null); } catch (IOException e) { - ui.setWaiting(false, null, null); - return; - } catch (InterruptedException e) { - // This thread is coming to an end. Let us exit. + //ui.setWaiting(false, null, null); return; } |