]> Joshua Wise's Git repositories - dumload.git/commitdiff
Merge git://git.asmw.org/dumload
authorJoshua Wise <joshua@joshuawise.com>
Sun, 4 Mar 2012 10:52:23 +0000 (02:52 -0800)
committerJoshua Wise <joshua@joshuawise.com>
Sun, 4 Mar 2012 10:52:23 +0000 (02:52 -0800)
.gitignore [new file with mode: 0644]
AndroidManifest.xml
res/values/ids.xml [new file with mode: 0644]
res/values/strings.xml
res/xml/preferences.xml [new file with mode: 0644]
src/com/joshuawise/dumload/Dumload.java
src/com/joshuawise/dumload/NotifSlave.java
src/com/joshuawise/dumload/Preferences.java [new file with mode: 0644]
src/com/joshuawise/dumload/Uploader.java

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..da3c794
--- /dev/null
@@ -0,0 +1,7 @@
+.classpath
+.project
+build.xml
+.settings
+project.properties
+local.properties
+proguard.cfg
index b24610e9305e2201f8b2a220bda1995be6a6d5a4..e3e7b93c495e5f2b6366b68752a216953209ed43 100644 (file)
@@ -1,30 +1,51 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-      package="com.joshuawise.dumload"
-      android:versionCode="1"
-      android:versionName="1.0">
-    <application android:icon="@drawable/icon" android:label="Dumload">
-        <activity android:name=".Dumload"
-                  android:label="@string/app_name">
+    package="com.joshuawise.dumload"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-permission android:name="android.permission.INTERNET" >
+    </uses-permission>
+    <uses-permission android:name="android.permission.STATUS_BAR" >
+    </uses-permission>
+    <uses-permission android:name="android.permission.VIBRATE" >
+    </uses-permission>
+
+    <application
+        android:icon="@drawable/icon"
+        android:label="Dumload" >
+        <activity
+            android:name=".Dumload"
+            android:label="@string/app_name" >
             <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            
+                <category android:name="android.intent.category.DEFAULT" />
 
-</intent-filter>
-        <intent-filter><action android:name="android.intent.action.SEND"></action>
-        <category android:name="android.intent.category.DEFAULT" />
-<data android:mimeType="image/jpeg"></data>
-</intent-filter>
-</activity>
+                <action android:name="android.intent.action.SEND" >
+                </action>
 
-<service android:name=".Uploader"><intent-filter><action android:name="com.joshuawise.dumload.Uploader" /></intent-filter></service>
-<activity android:name=".NotifSlave"><intent-filter><action android:name="com.joshuawise.dumload.NotifSlave" /></intent-filter></activity>
-    </application>
+                <data android:mimeType="image/jpeg" >
+                </data>
+            </intent-filter>
+        </activity>
+
+        <service android:name=".Uploader" >
+            <intent-filter>
+                <action android:name="com.joshuawise.dumload.Uploader" />
+            </intent-filter>
+        </service>
 
+        <activity android:name=".NotifSlave" >
+            <intent-filter>
+                <action android:name="com.joshuawise.dumload.NotifSlave" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".Preferences" >
+            <intent-filter>
+                <category android:name="android.intent.category.LAUNCHER" />
 
+                <action android:name="android.intent.action.MAIN" />
+            </intent-filter>
+        </activity>
+    </application>
 
-<uses-permission android:name="android.permission.INTERNET"></uses-permission>
-<uses-permission android:name="android.permission.STATUS_BAR"></uses-permission>
-<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
-</manifest> 
\ No newline at end of file
+</manifest>
\ No newline at end of file
diff --git a/res/values/ids.xml b/res/values/ids.xml
new file mode 100644 (file)
index 0000000..0161d2f
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <item name="actionCreateSshKey" type="id"/>
+    <item name="actionRemoveSshKey" type="id"/>
+    
+</resources>
\ No newline at end of file
index 4606407c988ac52e95ade8b73f91b53ffec16cce..df7427e096a50dc2b39fc427f63950a235299d04 100644 (file)
@@ -2,4 +2,20 @@
 <resources>
     <string name="hello">Hello World, Dumload!</string>
     <string name="app_name">dumload</string>
+    <string name="prefSshServerTitle">SSH server</string>
+    <string name="preferenceTitle">Preferences</string>
+    <string name="prefConnection">Connection preferences</string>
+    <string name="prefServerTitle">Server</string>
+    <string name="prefServerSummary">The SSH server to connect to</string>
+    <string name="prefUsernameTitle">Username</string>
+    <string name="prefUsernameSummary">The username to use for the ssh connection</string>
+    <string name="prefPortTitle">Port</string>
+    <string name="prefPortSummary">The SSH port on the remote server</string>
+    <string name="prefDefaultPathTitle">Default remote path</string>
+    <string name="prefDefaultPathSummary">Uploads are put in this directory on the remote server by default</string>
+    <string name="prefCrypto">Cryptography</string>
+    <string name="menuGenSshKey">Generate a new SSH key</string>
+    <string name="menuDelSshKey">Remove generated SSH key</string>
+    <string name="msgNoGenKeyFound">No generated SSH key was found.</string>
+    <string name="msgKeyExists">A generated key already exists.</string>
 </resources>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
new file mode 100644 (file)
index 0000000..089ff31
--- /dev/null
@@ -0,0 +1,23 @@
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+    android:title="@string/preferenceTitle" >
+
+    <PreferenceCategory android:title="@string/prefConnection" >
+        <EditTextPreference
+            android:key="userName"
+            android:summary="@string/prefUsernameSummary"
+            android:title="@string/prefUsernameTitle" />
+        <EditTextPreference
+            android:key="server"
+            android:summary="@string/prefServerSummary"
+            android:title="@string/prefServerTitle" />
+        <EditTextPreference
+            android:key="port"
+            android:summary="@string/prefPortSummary"
+            android:title="@string/prefPortTitle" />
+        <EditTextPreference
+            android:key="defaultUploadPath"
+            android:summary="@string/prefDefaultPathSummary"
+            android:title="@string/prefDefaultPathTitle" />
+    </PreferenceCategory>
+
+</PreferenceScreen>
\ No newline at end of file
index 9cabe94cbab5a3075f5362c3f33117447e0e43f7..c625b3aee0f96a86f3dca6d33bb2fcda660d0c02 100644 (file)
 
 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
index ce6bc6f2356a942f6aec58d90d6f8b43ce840e82..197e62684a05fa7a26a06dfc1e65468a0d28e80e 100644 (file)
 
 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 (file)
index 0000000..ad825b9
--- /dev/null
@@ -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<Void, Void, String> {
+
+               @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();
+       }
+}
index 12f71e280bf08ab896d237d2b2e8ee179b7d4f1e..6aa3317fdcd6ea5e03571f67f3f43d943c2e7791 100644 (file)
@@ -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);
                
This page took 0.042075 seconds and 4 git commands to generate.