]> Joshua Wise's Git repositories - dumload.git/blobdiff - src/com/joshuawise/dumload/Uploader.java
A few icon tweaks
[dumload.git] / src / com / joshuawise / dumload / Uploader.java
index a50a1c24f2a7fa13c20e083b5e434208d008c209..6aa3317fdcd6ea5e03571f67f3f43d943c2e7791 100644 (file)
@@ -1,30 +1,50 @@
+/* Uploader.java
+ * Back-end upload logic for Dumload.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 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;
@@ -35,6 +55,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;
        
@@ -260,14 +281,13 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                mNotificationManager.notify(thenotifid, thenotif);
        }
        
-       @Override
        public void run()
        {
                Looper.prepare();
                
                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 +296,25 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                
                        JSch jsch = new JSch();
                        jsch.setKnownHosts(homedir + "/known_hosts");
-                       Session s = jsch.getSession("joshua", "nyus.joshuawise.com", 22);
+                       try {
+                               jsch.addIdentity(homedir + "/id_dsa");
+                       } catch (java.lang.Exception e) {
+                       }
+                       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();
                        
                        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 +325,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 +362,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 +374,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,8 +395,10 @@ 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;
+               int giggles = 1;
                
                super.onStart(i, startId);
                
This page took 0.028234 seconds and 4 git commands to generate.