Add support to convert plain path to authorised when opening smb / sftp deeplink

This commit is contained in:
Vishal Nehra
2022-06-10 04:08:27 +05:30
parent bd297be116
commit d2c3574bc0
5 changed files with 61 additions and 8 deletions
+8
View File
@@ -49,6 +49,14 @@ Support
<a href="https://www.paypal.me/vishalnehra"><img width="20%" src="paypal.svg" alt="PayPal"></a>
<a href="https://liberapay.com/Team-Amaze/donate"><img src="https://upload.wikimedia.org/wikipedia/commons/2/27/Liberapay_logo_v2_white-on-yellow.svg" alt="Liberapay" width="80px" ></a>
Or buy the [Cloud Plugin](https://play.google.com/store/apps/details?id=com.filemanager.amazecloud) supports Google Drive™, Dropbox, OneDrive and Box accounts.
Try our app - [Amaze File Utilities](https://play.google.com/store/apps/details?id=com.amaze.fileutilities)
1. List videos / images / music documents in your device in a interactive UI where you're able to group / sort and quickly jump to any headers.
2. Open videos / images / music / documents (pdf / docx / epub) with inbuilt player.
3. Share / delete / cast on your tv
4. Analyse internal storage for junk files, duplicate files, large videos / old downloads / screenshots or recordings.
5. Analyse and group images between memes, low light / blurry / selfies / group pics.
7. Transfer files directly between two mobile devices on same wifi network using high speed peer to peer network
8. Gesture support in image / video player, play in background, picture in picture mode, download subtitles within the player.
Warning
---
@@ -1457,13 +1457,19 @@ public class HybridFile {
AtomicReference<String> md5 = new AtomicReference<>(activity.getString(R.string.calculating));
AtomicReference<String> sha256 =
new AtomicReference<>(activity.getString(R.string.calculating));
AtomicReference<String> pathToDisplay = new AtomicReference<>();
pathToDisplay.set(path);
if (isSftp() || isSmb()) {
LOG.debug("convert authorised path to simple path for display");
pathToDisplay.set(parseAndFormatUriForDisplay(path));
}
AtomicReference<String> dialogContent =
new AtomicReference<>(
String.format(
activity.getResources().getString(R.string.open_file_confirmation),
getName(activity),
path,
pathToDisplay.get(),
Formatter.formatShortFileSize(activity, length(activity)),
md5.get(),
sha256.get()));
@@ -1479,7 +1485,7 @@ public class HybridFile {
String.format(
activity.getResources().getString(R.string.open_file_confirmation),
getName(activity),
path,
pathToDisplay.get(),
Formatter.formatShortFileSize(activity, length(activity)),
md5.get(),
sha256.get()));
@@ -1494,7 +1500,7 @@ public class HybridFile {
String.format(
activity.getResources().getString(R.string.open_file_confirmation),
getName(activity),
path,
pathToDisplay.get(),
Formatter.formatShortFileSize(activity, length(activity)),
md5.get(),
sha256.get()));
@@ -28,6 +28,7 @@ import java.io.File;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
@@ -246,6 +247,33 @@ public abstract class SshClientUtils {
return hostPath.indexOf('/') == -1 ? "/" : hostPath.substring(hostPath.indexOf('/'));
}
/**
* Converts plain path smb://127.0.0.1/test.pdf to authorized path
* smb://test:123@127.0.0.1/test.pdf from server list
*
* @param path
* @return
*/
public static String formatPlainServerPathToAuthorised(ArrayList<String[]> servers, String path) {
synchronized (servers) {
for (String[] serverEntry : servers) {
Uri inputUri = Uri.parse(path);
Uri serverUri = Uri.parse(serverEntry[1]);
if (serverUri.getAuthority().contains(inputUri.getAuthority())) {
String output =
inputUri
.buildUpon()
.encodedAuthority(serverUri.getEncodedAuthority())
.build()
.toString();
LOG.info("build authorised path {} from plain path {}", output, path);
return output;
}
}
return path;
}
}
/**
* Disconnects the given {@link SSHClient} but wrap all exceptions beneath, so callers are free
* from the hassles of handling thrown exceptions.
@@ -98,6 +98,7 @@ import com.amaze.filemanager.filesystem.MakeFileOperation;
import com.amaze.filemanager.filesystem.PasteHelper;
import com.amaze.filemanager.filesystem.RootHelper;
import com.amaze.filemanager.filesystem.files.FileUtils;
import com.amaze.filemanager.filesystem.ssh.SshClientUtils;
import com.amaze.filemanager.filesystem.ssh.SshConnectionPool;
import com.amaze.filemanager.ui.ExtensionsKt;
import com.amaze.filemanager.ui.activities.superclasses.PermissionsActivity;
@@ -470,6 +471,14 @@ public class MainActivity extends PermissionsActivity
if (!isCloudRefresh) {
goToMain(null);
}
if (file.isSmb() || file.isSftp()) {
String authorisedPath =
SshClientUtils.formatPlainServerPathToAuthorised(dataUtils.getServers(), path);
file.setPath(authorisedPath);
LOG.info(
"Opening smb file from deeplink, modify plain path to authorised path {}",
authorisedPath);
}
file.openFile(this, true);
}
} else if (!isCloudRefresh) {
@@ -584,7 +593,7 @@ public class MainActivity extends PermissionsActivity
*/
path = Utils.sanitizeInput(uri.getQueryParameter("path"));
} else {
Log.w(getClass().getSimpleName(), getString(R.string.error_cannot_find_way_open));
LOG.warn(getString(R.string.error_cannot_find_way_open));
}
} else if (actionIntent.equals(Intent.ACTION_SEND)) {
@@ -25,6 +25,9 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amaze.filemanager.adapters.data.LayoutElementParcelable;
import com.amaze.filemanager.application.AppConfig;
import com.amaze.filemanager.fileoperations.filesystem.OpenMode;
@@ -40,7 +43,6 @@ import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import androidx.annotation.Nullable;
@@ -50,7 +52,7 @@ import androidx.annotation.Nullable;
// Central data being used across activity,fragments and classes
public class DataUtils {
private static final String TAG = DataUtils.class.getSimpleName();
private static final Logger LOG = LoggerFactory.getLogger(DataUtils.class);
private ConcurrentRadixTree<VoidValue> hiddenfiles =
new ConcurrentRadixTree<>(new DefaultCharArrayNodeFactory());
@@ -352,7 +354,7 @@ public class DataUtils {
try {
return getHiddenFiles().getValueForExactKey(path) != null;
} catch (IllegalStateException e) {
Log.w(TAG, e);
LOG.warn("failed to get hidden file", e);
return false;
}
}
@@ -411,7 +413,7 @@ public class DataUtils {
tree.put(path, item.getItemId());
return true;
} catch (IllegalStateException e) {
Log.w(TAG, e);
LOG.warn("failed to put drawer path", e);
return false;
}
}