From: Joshua Wise Date: Sun, 4 Mar 2012 10:52:23 +0000 (-0800) Subject: Merge git://git.asmw.org/dumload X-Git-Url: http://git.joshuawise.com/dumload.git/commitdiff_plain/b45fc5e03d952cfe09a7efb8a16019a42b9091b9?hp=184c5221975a8ceafb2b61b75776ac10fbc7e0c4 Merge git://git.asmw.org/dumload --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da3c794 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.classpath +.project +build.xml +.settings +project.properties +local.properties +proguard.cfg diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b24610e..e3e7b93 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,30 +1,51 @@ - - + package="com.joshuawise.dumload" + android:versionCode="1" + android:versionName="1.0" > + + + + + + + + + + - - - + - - - - - - + + - - - + + + + + + + + + + + + + + + + + + + + + + - - - - \ No newline at end of file + \ No newline at end of file diff --git a/res/values/ids.xml b/res/values/ids.xml new file mode 100644 index 0000000..0161d2f --- /dev/null +++ b/res/values/ids.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 4606407..df7427e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2,4 +2,20 @@ Hello World, Dumload! dumload + SSH server + Preferences + Connection preferences + Server + The SSH server to connect to + Username + The username to use for the ssh connection + Port + The SSH port on the remote server + Default remote path + Uploads are put in this directory on the remote server by default + Cryptography + Generate a new SSH key + Remove generated SSH key + No generated SSH key was found. + A generated key already exists. diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml new file mode 100644 index 0000000..089ff31 --- /dev/null +++ b/res/xml/preferences.xml @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/com/joshuawise/dumload/Dumload.java b/src/com/joshuawise/dumload/Dumload.java index 9cabe94..c625b3a 100644 --- a/src/com/joshuawise/dumload/Dumload.java +++ b/src/com/joshuawise/dumload/Dumload.java @@ -16,22 +16,22 @@ package com.joshuawise.dumload; -import java.io.InputStream; - import android.app.Activity; -import android.app.Service; import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.os.IBinder; +import android.preference.PreferenceManager; +import android.util.Log; +import android.view.View; +import android.widget.Button; import android.widget.TextView; import android.widget.Toast; -import android.widget.TextView; -import android.widget.Button; -import android.view.View; -import android.util.Log; public class Dumload extends Activity { + + private SharedPreferences prefs; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { @@ -49,12 +49,16 @@ public class Dumload extends Activity { super.onStart(); final Dumload thisact = this; + prefs = PreferenceManager.getDefaultSharedPreferences(this); + Intent i = getIntent(); /* i *am* not an intent! */ if (!i.getAction().equals(Intent.ACTION_SEND)) { - say("Unknown intent for dumload"); - this.finish(); +// say("Unknown intent for dumload"); +// this.finish(); + Intent pi = new Intent(this, Preferences.class); + startActivity(pi); return; } @@ -84,7 +88,7 @@ public class Dumload extends Activity { ((TextView) findViewById(R.id.suckit)).setText("Where to?"); - ((TextView) findViewById(R.id.entry)).setText("/var/www/" + uribase.substring(uribase.lastIndexOf("/") + 1) + ".jpg"); + ((TextView) findViewById(R.id.entry)).setText(prefs.getString("defaultUploadPath", "/var/www/") + uribase.substring(uribase.lastIndexOf("/") + 1) + ".jpg"); } } \ No newline at end of file diff --git a/src/com/joshuawise/dumload/NotifSlave.java b/src/com/joshuawise/dumload/NotifSlave.java index ce6bc6f..197e626 100644 --- a/src/com/joshuawise/dumload/NotifSlave.java +++ b/src/com/joshuawise/dumload/NotifSlave.java @@ -16,24 +16,19 @@ package com.joshuawise.dumload; -import java.io.InputStream; - import android.app.Activity; -import android.app.Service; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; -import android.os.IBinder; -import android.widget.TextView; -import android.widget.Button; +import android.os.Message; +import android.os.Messenger; +import android.util.Log; import android.view.View; +import android.widget.Button; +import android.widget.TextView; import android.widget.Toast; -import android.util.Log; -import android.os.Messenger; -import android.os.Message; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; public class NotifSlave extends Activity { /** Called when the activity is first created. */ diff --git a/src/com/joshuawise/dumload/Preferences.java b/src/com/joshuawise/dumload/Preferences.java new file mode 100644 index 0000000..ad825b9 --- /dev/null +++ b/src/com/joshuawise/dumload/Preferences.java @@ -0,0 +1,102 @@ +package com.joshuawise.dumload; + +import java.io.File; + +import android.content.SharedPreferences; +import android.os.AsyncTask; +import android.os.Bundle; +import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; +import android.view.Menu; +import android.view.MenuItem; +import android.view.Window; +import android.widget.Toast; + +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.KeyPair; + +public class Preferences extends PreferenceActivity { + + private class KeygenTask extends AsyncTask { + + @Override + protected String doInBackground(Void... params) { + String ret = null; + String homedir = getFilesDir().getAbsolutePath(); + String filename = homedir + "/id_dsa_generated"; + File file = new File(filename); + if (file.exists()) { + return getString(R.string.msgKeyExists); + } else { + JSch jsch = new JSch(); + int type = KeyPair.DSA; + try { + KeyPair kpair = KeyPair.genKeyPair(jsch, type); + // TODO: query for a passphrase + kpair.setPassphrase(""); + kpair.writePrivateKey(filename); + kpair.writePublicKey(filename + ".pub", "generated by dumload"); + ret = "Fingerprint: " + kpair.getFingerPrint(); + kpair.dispose(); + } catch (Exception e) { + System.out.println(e); + } + } + return ret; + } + + @Override + protected void onPostExecute(String result) { + setProgressBarIndeterminateVisibility(false); + Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show(); + super.onPostExecute(result); + } + + } + + @Override + public void onCreate(Bundle savedInstanceState) { + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + super.onCreate(savedInstanceState); + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.preferences); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + + menu.add(Menu.NONE, R.id.actionCreateSshKey, Menu.NONE, + getString(R.string.menuGenSshKey)); + menu.add(Menu.NONE, R.id.actionRemoveSshKey, Menu.NONE, + getString(R.string.menuDelSshKey)); + return true; + } + + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.actionCreateSshKey: + generateDSAKeyPair(); + break; + case R.id.actionRemoveSshKey: + String homedir = getFilesDir().getAbsolutePath(); + String filename = homedir + "/id_dsa_generated"; + File file = new File(filename); + if (file.exists()) { + file.delete(); + Toast.makeText(this, + "Deleted", + Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(this, getString(R.string.msgNoGenKeyFound), Toast.LENGTH_SHORT).show(); + } + } + return false; + } + + private void generateDSAKeyPair() { + setProgressBarIndeterminateVisibility(true); + KeygenTask t = new KeygenTask(); + t.execute(); + } +} diff --git a/src/com/joshuawise/dumload/Uploader.java b/src/com/joshuawise/dumload/Uploader.java index 12f71e2..6aa3317 100644 --- a/src/com/joshuawise/dumload/Uploader.java +++ b/src/com/joshuawise/dumload/Uploader.java @@ -19,28 +19,32 @@ package com.joshuawise.dumload; import java.io.InputStream; import java.io.OutputStream; -import com.jcraft.jsch.*; -import java.lang.Boolean; - -import android.app.Activity; -import android.app.Service; -import android.content.Intent; +import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; +import android.app.Service; import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.os.IBinder; -import android.widget.TextView; -import android.widget.Toast; -import android.util.Log; -import android.app.NotificationManager; -import android.app.Notification; import android.os.Handler; -import android.os.Messenger; +import android.os.IBinder; import android.os.Looper; import android.os.Message; +import android.os.Messenger; import android.os.SystemClock; +import android.preference.PreferenceManager; +import android.util.Log; import android.widget.RemoteViews; +import android.widget.Toast; + +import com.jcraft.jsch.Channel; +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.Session; +import com.jcraft.jsch.UIKeyboardInteractive; +import com.jcraft.jsch.UserInfo; public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardInteractive { private Uri uri; @@ -277,7 +281,6 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI mNotificationManager.notify(thenotifid, thenotif); } - @Override public void run() { Looper.prepare(); @@ -297,7 +300,16 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI jsch.addIdentity(homedir + "/id_dsa"); } catch (java.lang.Exception e) { } - Session s = jsch.getSession("joshua", "nyus.joshuawise.com", 22); + try { + jsch.addIdentity(homedir + "/id_dsa_generated"); + } catch (java.lang.Exception e) { + } + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + String server = prefs.getString("server", "").trim(); + String userName = prefs.getString("userName", "").trim(); + Integer port = Integer.valueOf(prefs.getString("port", "22")); + Log.d("dbg", userName + "@" + server + ":" + port); + Session s = jsch.getSession(userName, server, port); s.setUserInfo(this); s.connect(); @@ -386,6 +398,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI dest = i.getStringExtra("com.joshuawise.dumload.dest"); homedir = getApplicationContext().getFilesDir().getAbsolutePath(); int shits = 0; + int giggles = 1; super.onStart(i, startId);