<?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
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
-<TextView
- android:id="@+id/suckit"
- android:layout_width="fill_parent"
- 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>
+<?xml version="1.0" encoding="utf-8"?>\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:orientation="vertical"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="fill_parent"\r
+ >\r
+<TextView \r
+ android:id="@+id/suckit"\r
+ android:layout_width="fill_parent" \r
+ android:layout_height="wrap_content" \r
+ android:text="@string/hello"\r
+ />\r
+<EditText\r
+ android:id="@+id/entry"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="wrap_content"\r
+ android:background="@android:drawable/editbox_background"\r
+ />\r
+<Button\r
+ android:id="@+id/go"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="Go!"\r
+ />\r
+\r
+</LinearLayout>\r
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="10dp"
- >
-<TextView
- android:id="@+id/prompt"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-<EditText
- android:id="@+id/entry"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@android:drawable/editbox_background"
- android:password="true"
- />
-<LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
-<Button
- android:id="@+id/ok"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="OK"
- />
-<Button
- android:id="@+id/cancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Cancel"
- />
-</LinearLayout>
-</LinearLayout>
+<?xml version="1.0" encoding="utf-8"?>\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:orientation="vertical"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="fill_parent"\r
+ android:padding="10dp"\r
+ >\r
+<TextView \r
+ android:id="@+id/prompt"\r
+ android:layout_width="fill_parent" \r
+ android:layout_height="wrap_content" \r
+ />\r
+<EditText\r
+ android:id="@+id/entry"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="wrap_content"\r
+ android:background="@android:drawable/editbox_background"\r
+ android:password="true"\r
+ />\r
+<LinearLayout\r
+ android:orientation="horizontal"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="wrap_content"\r
+ >\r
+<Button\r
+ android:id="@+id/ok"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="OK"\r
+ />\r
+<Button\r
+ android:id="@+id/cancel"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="wrap_content"\r
+ android:text="Cancel"\r
+ />\r
+</LinearLayout>\r
+</LinearLayout>\r
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="3dp"
- >
-
-<ImageView
- android:id="@+id/image"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_marginRight="10dp"
- />
-
-<LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
-<TextView
- android:id="@+id/headline"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textStyle="bold"
- />
-<ProgressBar
- android:id="@+id/status"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleHorizontal"
- />
-
-</LinearLayout>
-</LinearLayout>
+<?xml version="1.0" encoding="utf-8"?>\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:orientation="horizontal"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="fill_parent"\r
+ android:padding="3dp"\r
+ >\r
+\r
+<ImageView\r
+ android:id="@+id/image"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="fill_parent"\r
+ android:layout_marginRight="10dp"\r
+ />\r
+\r
+<LinearLayout\r
+ android:orientation="vertical"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="wrap_content"\r
+ >\r
+<TextView \r
+ android:id="@+id/headline"\r
+ android:layout_width="fill_parent" \r
+ android:layout_height="wrap_content" \r
+ android:textStyle="bold"\r
+ />\r
+<ProgressBar\r
+ android:id="@+id/status"\r
+ android:layout_width="fill_parent" \r
+ android:layout_height="wrap_content" \r
+ style="?android:attr/progressBarStyleHorizontal"\r
+ />\r
+\r
+</LinearLayout>\r
+</LinearLayout>\r
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="3dp"
- >
-
-<ImageView
- android:id="@+id/image"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_marginRight="10dp"
- />
-
-<LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
-<TextView
- android:id="@+id/headline"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textStyle="bold"
- />
-<TextView
- android:id="@+id/status"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
-
-</LinearLayout>
-</LinearLayout>
+<?xml version="1.0" encoding="utf-8"?>\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:orientation="horizontal"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="fill_parent"\r
+ android:padding="3dp"\r
+ >\r
+\r
+<ImageView\r
+ android:id="@+id/image"\r
+ android:layout_width="wrap_content"\r
+ android:layout_height="fill_parent"\r
+ android:layout_marginRight="10dp"\r
+ />\r
+\r
+<LinearLayout\r
+ android:orientation="vertical"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="wrap_content"\r
+ >\r
+<TextView \r
+ android:id="@+id/headline"\r
+ android:layout_width="fill_parent" \r
+ android:layout_height="wrap_content" \r
+ android:textStyle="bold"\r
+ />\r
+<TextView \r
+ android:id="@+id/status"\r
+ android:layout_width="fill_parent" \r
+ android:layout_height="wrap_content" \r
+ />\r
+\r
+</LinearLayout>\r
+</LinearLayout>\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<resources>
+ <item name="actionCreateSshKey" type="id"/>
+ <item name="actionRemoveSshKey" type="id"/>\r
+ \r
+</resources>
\ No newline at end of file
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <string name="hello">Hello World, Dumload!</string>
+<?xml version="1.0" encoding="utf-8"?>\r
+<resources>\r
+ <string name="hello">Hello World, Dumload!</string>\r
<string name="app_name">dumload</string>
-</resources>
+ <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>\r
+</resources>\r
--- /dev/null
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:title="@string/preferenceTitle" >\r
+\r
+ <PreferenceCategory android:title="@string/prefConnection" >\r
+ <EditTextPreference\r
+ android:key="userName"\r
+ android:summary="@string/prefUsernameSummary"\r
+ android:title="@string/prefUsernameTitle" />\r
+ <EditTextPreference\r
+ android:key="server"\r
+ android:summary="@string/prefServerSummary"\r
+ android:title="@string/prefServerTitle" />\r
+ <EditTextPreference\r
+ android:key="port"\r
+ android:summary="@string/prefPortSummary"\r
+ android:title="@string/prefPortTitle" />\r
+ <EditTextPreference\r
+ android:key="defaultUploadPath"\r
+ android:summary="@string/prefDefaultPathSummary"\r
+ android:title="@string/prefDefaultPathTitle" />\r
+ </PreferenceCategory>\r
+\r
+</PreferenceScreen>
\ No newline at end of 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) {
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;
}
((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
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. */
--- /dev/null
+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();
+ }
+}
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;
mNotificationManager.notify(thenotifid, thenotif);
}
- @Override
public void run()
{
Looper.prepare();
jsch.addIdentity(homedir + "/id_dsa");
} catch (java.lang.Exception e) {
}
- Session s = jsch.getSession("joshua", "nyus.joshuawise.com", 22);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ String server = prefs.getString("server", "").trim();
+ String userName = prefs.getString("userName", "").trim();
+ Integer port = prefs.getInt("serverPort", 22);
+ Log.d("dbg", userName + "@" + server + ":" + port);
+ Session s = jsch.getSession(userName, server, port);
s.setUserInfo(this);
s.connect();
dest = i.getStringExtra("com.joshuawise.dumload.dest");
homedir = getApplicationContext().getFilesDir().getAbsolutePath();
int shits = 0;
+ int giggles = 1;
super.onStart(i, startId);