diff --git a/src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java b/src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java index 45881995c..57dfd6b0c 100644 --- a/src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java +++ b/src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java @@ -42,6 +42,7 @@ public class Sftp extends CordovaPlugin { + private static final String TAG = "SFTP"; private SshClient ssh; private SftpClient sftp; private Context context; @@ -93,6 +94,10 @@ public void run() { int port = args.optInt(1); String username = args.optString(2); String password = args.optString(3); + Log.d( + TAG, + "Connecting to " + host + ":" + port + " as " + username + ); ssh = SshClientBuilder.create() .withHostname(host) .withPort(port) @@ -103,27 +108,48 @@ public void run() { if (ssh.isConnected()) { connectionID = username + "@" + host; - sftp = SftpClientBuilder.create().withClient(ssh).build(); + try { + sftp = SftpClientBuilder.create().withClient(ssh).build(); + } catch (IOException | SshException e) { + ssh.close(); + callback.error( + "Failed to initialize SFTP subsystem: " + errMessage(e) + ); + Log.e(TAG, "Failed to initialize SFTP subsystem", e); + return; + } try { sftp.getSubsystemChannel().setCharsetEncoding("UTF-8"); } catch (UnsupportedEncodingException | SshException e) { // Fallback to default encoding if UTF-8 fails + Log.w( + TAG, + "Failed to set UTF-8 encoding, falling back to default", + e + ); } callback.success(); - Log.d("connectUsingPassword", "Connected successfully"); + Log.d(TAG, "Connected successfully to " + connectionID); return; } - callback.error("Cannot connect"); - } catch ( - UnresolvedAddressException - | SshException - | IOException - | PermissionDeniedException e - ) { - callback.error(errMessage(e)); - Log.e("connectUsingPassword", "Cannot connect", e); + callback.error("Failed to establish SSH connection"); + } catch (UnresolvedAddressException e) { + callback.error("Cannot resolve host address"); + Log.e(TAG, "Cannot resolve host address", e); + } catch (PermissionDeniedException e) { + callback.error("Authentication failed: " + e.getMessage()); + Log.e(TAG, "Authentication failed", e); + } catch (SshException e) { + callback.error("SSH error: " + errMessage(e)); + Log.e(TAG, "SSH error", e); + } catch (IOException e) { + callback.error("I/O error: " + errMessage(e)); + Log.e(TAG, "I/O error", e); + } catch (Exception e) { + callback.error("Unexpected error: " + errMessage(e)); + Log.e(TAG, "Unexpected error", e); } } } @@ -150,37 +176,73 @@ public void run() { ContentResolver contentResolver = context.getContentResolver(); InputStream in = contentResolver.openInputStream(uri); + SshKeyPair keyPair = null; + try { + keyPair = SshKeyUtils.getPrivateKey(in, passphrase); + } catch (InvalidPassphraseException e) { + callback.error("Invalid passphrase for key file"); + Log.e(TAG, "Invalid passphrase for key file", e); + return; + } catch (IOException e) { + callback.error("Could not read key file: " + errMessage(e)); + Log.e(TAG, "Could not read key file", e); + return; + } + ssh = SshClientBuilder.create() .withHostname(host) .withPort(port) .withUsername(username) - .withIdentities(SshKeyUtils.getPrivateKey(in, passphrase)) + .withIdentities(keyPair) .build(); if (ssh.isConnected()) { connectionID = username + "@" + host; - sftp = SftpClientBuilder.create().withClient(ssh).build(); + try { + sftp = SftpClientBuilder.create().withClient(ssh).build(); + } catch (IOException | SshException e) { + ssh.close(); + callback.error( + "Failed to initialize SFTP subsystem: " + errMessage(e) + ); + Log.e(TAG, "Failed to initialize SFTP subsystem", e); + return; + } try { sftp.getSubsystemChannel().setCharsetEncoding("UTF-8"); } catch (UnsupportedEncodingException | SshException e) { // Fallback to default encoding if UTF-8 fails + Log.w( + TAG, + "Failed to set UTF-8 encoding, falling back to default", + e + ); } callback.success(); + Log.d(TAG, "Connected successfully to " + connectionID); return; } - callback.error("Cannot connect"); - } catch ( - InvalidPassphraseException - | UnresolvedAddressException - | SshException - | IOException - | SecurityException - | PermissionDeniedException e - ) { - callback.error(errMessage(e)); - Log.e("connectUsingKeyFile", "Cannot connect", e); + callback.error("Failed to establish SSH connection"); + } catch (UnresolvedAddressException e) { + callback.error("Cannot resolve host address"); + Log.e(TAG, "Cannot resolve host address", e); + } catch (PermissionDeniedException e) { + callback.error("Authentication failed: " + e.getMessage()); + Log.e(TAG, "Authentication failed", e); + } catch (SshException e) { + callback.error("SSH error: " + errMessage(e)); + Log.e(TAG, "SSH error", e); + } catch (IOException e) { + callback.error("I/O error: " + errMessage(e)); + Log.e(TAG, "I/O error", e); + } catch (SecurityException e) { + callback.error("Security error: " + errMessage(e)); + Log.e(TAG, "Security error", e); + } catch (Exception e) { + callback.error("Unexpected error: " + errMessage(e)); + Log.e(TAG, "Unexpected error", e); } } } diff --git a/src/sidebarApps/extensions/index.js b/src/sidebarApps/extensions/index.js index 7674f2d81..7bd813ad8 100644 --- a/src/sidebarApps/extensions/index.js +++ b/src/sidebarApps/extensions/index.js @@ -538,6 +538,9 @@ async function uninstall(id) { searchInput.value = ""; $searchResult.content = ""; updateHeight($searchResult); + if ($installed.collapsed) { + $installed.expand(); + } } // Show Ad If Its Free Version, interstitial Ad(iad) is loaded.