diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index d9c82330..97977d75 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,4 +1,4 @@
-#Fri Jan 10 16:57:53 CET 2014
+#Sun Jan 12 12:44:14 MSK 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
diff --git a/kdeconnect-android.iml b/kdeconnect-android.iml
index c9ffcad7..5b5faa6c 100644
--- a/kdeconnect-android.iml
+++ b/kdeconnect-android.iml
@@ -73,16 +73,11 @@
+
-
-
-
-
-
-
diff --git a/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java b/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java
index 74142a37..853eeab7 100644
--- a/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java
+++ b/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java
@@ -1,17 +1,24 @@
package org.kde.kdeconnect.Plugins.SftpPlugin;
+import android.content.Context;
import android.util.Log;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.Session;
import org.apache.sshd.server.Command;
+import org.apache.sshd.server.FileSystemFactory;
+import org.apache.sshd.server.FileSystemView;
import org.apache.sshd.server.PasswordAuthenticator;
+import org.apache.sshd.server.SshFile;
import org.apache.sshd.server.command.ScpCommandFactory;
-import org.apache.sshd.server.filesystem.NativeFileSystemFactory;
+import org.apache.sshd.server.filesystem.NativeFileSystemView;
+import org.apache.sshd.server.filesystem.NativeSshFile;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.sftp.SftpSubsystem;
+import java.io.File;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
@@ -48,11 +55,12 @@ class SimpleSftpServer {
private final SshServer sshd = SshServer.setUpDefaultServer();
- public void init() {
+ public void init(Context ctx) {
passwordAuth.setUser(USER);
- sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("key.ser"));
+ sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(ctx.getFilesDir() + "/sftpd.ser"));
- sshd.setFileSystemFactory(new NativeFileSystemFactory());
+ //sshd.setFileSystemFactory(new NativeFileSystemFactory());
+ sshd.setFileSystemFactory(new SecureFileSystemFactory());
//sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" }));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setSubsystemFactories(Arrays.>asList(new SftpSubsystem.Factory()));
@@ -112,72 +120,58 @@ class SimpleSftpServer {
}
-// =======================================
-// Comented to be example of customization od SSHD
-// =======================================
+ class SecureFileSystemFactory implements FileSystemFactory {
-// static class SecureFileSystemFactory implements FileSystemFactory {
-// //
-// public SecureFileSystemFactory() {
-// }
-// //
-// @Override
-// public FileSystemView createFileSystemView(final Session username) {
-// final String userName = username.getUsername();
-// final String home = "/mnt/sdcard/";
-// return new SecureFileSystemView(home, userName, false);
-// }
-// }
+ public SecureFileSystemFactory() {}
-// static class SecureFileSystemView extends NativeFileSystemView {
-// // the first and the last character will always be '/'
-// // It is always with respect to the root directory.
-// private String currDir = "/";
-// private String rootDir = "/";
-// private String userName;
-// private boolean isReadOnly = true;
-// private boolean caseInsensitive = false;
-// //
-// public SecureFileSystemView(final String rootDir, final String userName, final boolean isReadOnly) {
-// super(userName);
-// this.rootDir = NativeSshFile.normalizeSeparateChar(rootDir);
-// this.userName = userName;
-// this.isReadOnly = isReadOnly;
-// }
-// //
-// @Override
-// public SshFile getFile(final String file) {
-// return getFile(currDir, file);
-// }
-//
-// @Override
-// public SshFile getFile(final SshFile baseDir, final String file) {
-// return getFile(baseDir.getAbsolutePath(), file);
-// }
-//
-// //
-// protected SshFile getFile(final String dir, final String file) {
-// // get actual file object
-// String physicalName = NativeSshFile.getPhysicalName("/", dir, file, caseInsensitive);
-// File fileObj = new File(rootDir, physicalName); // chroot
-//
-// // strip the root directory and return
-// String userFileName = physicalName.substring("/".length() - 1);
-// return new SecureSshFile(userFileName, fileObj, userName, isReadOnly);
-// }
-// }
-//
-// static class SecureSshFile extends NativeSshFile {
-// final boolean isReadOnly;
-// //
-// public SecureSshFile(final String fileName, final File file, final String userName, final boolean isReadOnly) {
-// super(fileName, file, userName);
-// this.isReadOnly = isReadOnly;
-// }
-// //
-// public boolean isWritable() {
-// if (isReadOnly)
-// return false;
-// return super.isWritable();
-// }
-// }
\ No newline at end of file
+ @Override
+ public FileSystemView createFileSystemView(final Session username) {
+ final String base = "/";
+ return new SecureFileSystemView(base, username.getUsername());
+ }
+ }
+
+ class SecureFileSystemView extends NativeFileSystemView {
+ // the first and the last character will always be '/'
+ // It is always with respect to the root directory.
+ private String currDir = "/";
+ private String rootDir = "/";
+ private String userName;
+ private boolean caseInsensitive = false;
+ //
+ public SecureFileSystemView(final String rootDir, final String userName) {
+ super(userName);
+ this.rootDir = NativeSshFile.normalizeSeparateChar(rootDir);
+ this.userName = userName;
+ }
+ //
+ @Override
+ public SshFile getFile(final String file) {
+ Log.e("getFile:", file);
+ return getFile(currDir, file);
+ }
+
+ @Override
+ public SshFile getFile(final SshFile baseDir, final String file) {
+ Log.e("getFile2:", baseDir.getAbsolutePath() + " -- " + file);
+ return getFile(baseDir.getAbsolutePath(), file);
+ }
+
+ //
+ protected SshFile getFile(final String dir, final String file) {
+ // get actual file object
+ String physicalName = NativeSshFile.getPhysicalName("/", dir, file, caseInsensitive);
+ File fileObj = new File(rootDir, physicalName); // chroot
+
+ // strip the root directory and return
+ String userFileName = physicalName.substring("/".length() - 1);
+ return new SecureSshFile(this, userFileName, fileObj, userName);
+ }
+ }
+
+ class SecureSshFile extends NativeSshFile {
+ //
+ public SecureSshFile(final SecureFileSystemView view, final String fileName, final File file, final String userName) {
+ super(fileName, file, userName);
+ }
+ }
\ No newline at end of file
diff --git a/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java
index 630bfa8d..39487c77 100644
--- a/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java
+++ b/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java
@@ -42,7 +42,7 @@ public class SftpPlugin extends Plugin {
@Override
public boolean onCreate() {
- server.init();
+ server.init(context);
return true;
}