2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 05:37:43 +00:00

moved to updated gradle and Android Studio

This commit is contained in:
Samoilenko Yuri 2014-01-13 00:15:17 +04:00 committed by Albert Vaca
parent a57dc71ad1
commit 52c7581f42
4 changed files with 68 additions and 79 deletions

View File

@ -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

View File

@ -73,16 +73,11 @@
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="sshd-core-0.8.0" level="project" />
<orderEntry type="library" exported="" name="slf4j-api-1.6.6" level="project" />
<orderEntry type="library" exported="" name="mina-core-2.0.7" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.0.1" level="project" />
<orderEntry type="library" exported="" name="ComAndroidSupportAppcompatV71901.aar" level="project" />
<orderEntry type="library" name="bcprov-jdk16-145" level="project" />
<orderEntry type="library" name="tomcat-apr-5.5.23" level="project" />
<orderEntry type="library" name="sshd-core-0.7.0" level="project" />
<orderEntry type="library" exported="" name="mina-core-2.0.7" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.0.1" level="project" />
<orderEntry type="library" exported="" name="ComAndroidSupportAppcompatV71901.aar" level="project" />
<orderEntry type="library" exported="" name="bcprov-jdk16-1.45" level="project" />
<orderEntry type="library" exported="" name="sshd-core-0.7.0" level="project" />
<orderEntry type="library" exported="" name="tomcat-apr-5.5.15" level="project" />

View File

@ -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.<NamedFactory<Command>>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();
// }
// }
@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);
}
}

View File

@ -42,7 +42,7 @@ public class SftpPlugin extends Plugin {
@Override
public boolean onCreate() {
server.init();
server.init(context);
return true;
}