Add location prompt and pubkey support
authorJoshua Wise <jwise@andrew.cmu.edu>
Sat, 7 Aug 2010 08:45:55 +0000 (04:45 -0400)
committerJoshua Wise <jwise@andrew.cmu.edu>
Sat, 7 Aug 2010 08:45:55 +0000 (04:45 -0400)
res/layout/main.xml
src/com/joshuawise/dumload/Dumload.java
src/com/joshuawise/dumload/Uploader.java

index da4f82e..9a37aea 100644 (file)
     android:layout_height="wrap_content" 
     android:text="@string/hello"
     />
+<EditText
+    android:id="@+id/entry"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:background="@android:drawable/editbox_background"
+    />
+<Button
+    android:id="@+id/go"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:text="Go!"
+    />
+
 </LinearLayout>
index 0905ac9..f0919b7 100644 (file)
@@ -10,6 +10,9 @@ import android.os.Bundle;
 import android.os.IBinder;
 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 {
@@ -28,27 +31,44 @@ public class Dumload extends Activity {
        
        public void onStart() {
                super.onStart();
+               final Dumload thisact = this;
                
                Intent i = getIntent(); /* i *am* not an intent! */
-               if (i.getAction().equals(Intent.ACTION_SEND))
+               
+               if (!i.getAction().equals(Intent.ACTION_SEND))
                {
-                       Bundle extras = i.getExtras();
-                       Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM);
-                       
-                       Log.e("Dumload", "Got a send -- starting service.");
-                       // Never let an ML programmer touch Java.
-                       android.content.ComponentName cn = getApplicationContext().startService(new Intent().setClass(getApplicationContext(), Uploader.class).setData(uri));
-                       
-                       if (cn == null)
-                               say("Fuuuuuuuuuck.");
-                       else
-                               Log.e("Dumload", "Started service " + cn.toString() + ".");
-                       
-                       TextView tv = (TextView)findViewById(R.id.suckit);
-                       tv.setText("Action was send: "+uri.toString());
-               } else {
-                       TextView tv = (TextView)findViewById(R.id.suckit);
-                       tv.setText("Action was something else");
+                       say("Unknown intent for dumload");
+                       this.finish();
+                       return;
                }
+               
+               Bundle extras = i.getExtras();
+               final Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM);
+               
+               Log.e("Dumload", "Got a send -- starting service.");
+               
+               Button go = (Button)findViewById(R.id.go);
+               go.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View v) {
+                               String s = ((TextView) findViewById(R.id.entry)).getText().toString();
+                               android.content.ComponentName cn = getApplicationContext()
+                                                                    .startService(new Intent()
+                                                                                    .setClass(getApplicationContext(), Uploader.class)
+                                                                                    .setData(uri)
+                                                                                    .putExtra("com.joshuawise.dumload.dest", s));
+                               if (cn == null)
+                                       say("Failed to start uploader.");
+                               else
+                                       Log.e("Dumload", "Started service " + cn.toString() + ".");
+                               finish();
+                       }
+               });
+               
+               String uribase = uri.toString();
+               
+               
+               ((TextView) findViewById(R.id.suckit)).setText("Where to?");
+               ((TextView) findViewById(R.id.entry)).setText("/var/www/" + uribase.substring(uribase.lastIndexOf("/") + 1) + ".jpg");
+               
        }
 }
\ No newline at end of file
index a50a1c2..f1dfc7e 100644 (file)
@@ -35,6 +35,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
        private int thenotifid;
        private Notification thenotif;
        private String headline;
+       private String dest;
        
        private InputStream is;
        
@@ -267,7 +268,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                
                Log.e("Dumload.Uploader[thread]", "This brought to you from the new thread.");
                
-               set_up_notif("Dumload upload in progress");
+               set_up_notif("Dumload upload: " + dest);
                
                try {
                        say("Uploading "+(Integer.toString(is.available()))+" bytes");
@@ -276,12 +277,16 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                
                        JSch jsch = new JSch();
                        jsch.setKnownHosts(homedir + "/known_hosts");
+                       try {
+                               jsch.addIdentity(homedir + "/id_dsa");
+                       } catch (java.lang.Exception e) {
+                       }
                        Session s = jsch.getSession("joshua", "nyus.joshuawise.com", 22);
                        s.setUserInfo(this);
                        s.connect();
                        
                        Channel channel = s.openChannel("exec");
-                       ((ChannelExec)channel).setCommand("scp -t /tmp/lol.jpg");
+                       ((ChannelExec)channel).setCommand("scp -t "+dest);
                        channel.connect();
                        
                        OutputStream scp_out = channel.getOutputStream();
@@ -292,7 +297,13 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                        /* Okay, BS out of the way.  Now go send the file. */
                        expect_ack(scp_in);
                        
-                       scp_out.write(("C0644 " + (Integer.toString(is.available())) + " lol.jpg\n").getBytes());
+                       String stfu;
+                       if (dest.lastIndexOf("/") > 0)
+                               stfu = dest.substring(dest.lastIndexOf("/") + 1);
+                       else
+                               stfu = dest;
+                       
+                       scp_out.write(("C0644 " + (Integer.toString(is.available())) + " "+stfu+"\n").getBytes());
                        scp_out.flush();
                        
                        expect_ack(scp_in);
@@ -323,7 +334,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                        update_notif("Preparing to resize image...");
                        
                        channel = s.openChannel("exec");
-                       ((ChannelExec)channel).setCommand("pscale /tmp/lol.jpg");
+                       ((ChannelExec)channel).setCommand("pscale "+dest);
                        channel.connect();
                        
                        scp_in = channel.getInputStream();
@@ -335,7 +346,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                        channel.disconnect();
                        update_notif("Upload complete.");
                        
-                       sayNullNotification("Dumload upload complete", "Upload complete", "Dumload has finished uploading your file.");
+                       sayNullNotification("Dumload upload complete: " + dest, "Upload complete", "Uploaded: " + dest);
 
                        s.disconnect();
                } catch (Exception e) {
@@ -356,6 +367,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
        public void onStart(Intent i, int startId)
        {
                uri = i.getData();
+               dest = i.getStringExtra("com.joshuawise.dumload.dest");
                homedir = getApplicationContext().getFilesDir().getAbsolutePath();
                int shits = 0;
                
This page took 0.031949 seconds and 4 git commands to generate.