Skip to content

Commit 2358a53

Browse files
authored
feat: improved logging for sftp & one sidebar issue fixed (#1224)
1 parent 9ebd7dd commit 2358a53

File tree

2 files changed

+89
-24
lines changed

2 files changed

+89
-24
lines changed

src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
public class Sftp extends CordovaPlugin {
4444

45+
private static final String TAG = "SFTP";
4546
private SshClient ssh;
4647
private SftpClient sftp;
4748
private Context context;
@@ -93,6 +94,10 @@ public void run() {
9394
int port = args.optInt(1);
9495
String username = args.optString(2);
9596
String password = args.optString(3);
97+
Log.d(
98+
TAG,
99+
"Connecting to " + host + ":" + port + " as " + username
100+
);
96101
ssh = SshClientBuilder.create()
97102
.withHostname(host)
98103
.withPort(port)
@@ -103,27 +108,48 @@ public void run() {
103108
if (ssh.isConnected()) {
104109
connectionID = username + "@" + host;
105110

106-
sftp = SftpClientBuilder.create().withClient(ssh).build();
111+
try {
112+
sftp = SftpClientBuilder.create().withClient(ssh).build();
113+
} catch (IOException | SshException e) {
114+
ssh.close();
115+
callback.error(
116+
"Failed to initialize SFTP subsystem: " + errMessage(e)
117+
);
118+
Log.e(TAG, "Failed to initialize SFTP subsystem", e);
119+
return;
120+
}
107121

108122
try {
109123
sftp.getSubsystemChannel().setCharsetEncoding("UTF-8");
110124
} catch (UnsupportedEncodingException | SshException e) {
111125
// Fallback to default encoding if UTF-8 fails
126+
Log.w(
127+
TAG,
128+
"Failed to set UTF-8 encoding, falling back to default",
129+
e
130+
);
112131
}
113132
callback.success();
114-
Log.d("connectUsingPassword", "Connected successfully");
133+
Log.d(TAG, "Connected successfully to " + connectionID);
115134
return;
116135
}
117136

118-
callback.error("Cannot connect");
119-
} catch (
120-
UnresolvedAddressException
121-
| SshException
122-
| IOException
123-
| PermissionDeniedException e
124-
) {
125-
callback.error(errMessage(e));
126-
Log.e("connectUsingPassword", "Cannot connect", e);
137+
callback.error("Failed to establish SSH connection");
138+
} catch (UnresolvedAddressException e) {
139+
callback.error("Cannot resolve host address");
140+
Log.e(TAG, "Cannot resolve host address", e);
141+
} catch (PermissionDeniedException e) {
142+
callback.error("Authentication failed: " + e.getMessage());
143+
Log.e(TAG, "Authentication failed", e);
144+
} catch (SshException e) {
145+
callback.error("SSH error: " + errMessage(e));
146+
Log.e(TAG, "SSH error", e);
147+
} catch (IOException e) {
148+
callback.error("I/O error: " + errMessage(e));
149+
Log.e(TAG, "I/O error", e);
150+
} catch (Exception e) {
151+
callback.error("Unexpected error: " + errMessage(e));
152+
Log.e(TAG, "Unexpected error", e);
127153
}
128154
}
129155
}
@@ -150,37 +176,73 @@ public void run() {
150176
ContentResolver contentResolver = context.getContentResolver();
151177
InputStream in = contentResolver.openInputStream(uri);
152178

179+
SshKeyPair keyPair = null;
180+
try {
181+
keyPair = SshKeyUtils.getPrivateKey(in, passphrase);
182+
} catch (InvalidPassphraseException e) {
183+
callback.error("Invalid passphrase for key file");
184+
Log.e(TAG, "Invalid passphrase for key file", e);
185+
return;
186+
} catch (IOException e) {
187+
callback.error("Could not read key file: " + errMessage(e));
188+
Log.e(TAG, "Could not read key file", e);
189+
return;
190+
}
191+
153192
ssh = SshClientBuilder.create()
154193
.withHostname(host)
155194
.withPort(port)
156195
.withUsername(username)
157-
.withIdentities(SshKeyUtils.getPrivateKey(in, passphrase))
196+
.withIdentities(keyPair)
158197
.build();
159198

160199
if (ssh.isConnected()) {
161200
connectionID = username + "@" + host;
162-
sftp = SftpClientBuilder.create().withClient(ssh).build();
201+
try {
202+
sftp = SftpClientBuilder.create().withClient(ssh).build();
203+
} catch (IOException | SshException e) {
204+
ssh.close();
205+
callback.error(
206+
"Failed to initialize SFTP subsystem: " + errMessage(e)
207+
);
208+
Log.e(TAG, "Failed to initialize SFTP subsystem", e);
209+
return;
210+
}
163211

164212
try {
165213
sftp.getSubsystemChannel().setCharsetEncoding("UTF-8");
166214
} catch (UnsupportedEncodingException | SshException e) {
167215
// Fallback to default encoding if UTF-8 fails
216+
Log.w(
217+
TAG,
218+
"Failed to set UTF-8 encoding, falling back to default",
219+
e
220+
);
168221
}
169222
callback.success();
223+
Log.d(TAG, "Connected successfully to " + connectionID);
170224
return;
171225
}
172226

173-
callback.error("Cannot connect");
174-
} catch (
175-
InvalidPassphraseException
176-
| UnresolvedAddressException
177-
| SshException
178-
| IOException
179-
| SecurityException
180-
| PermissionDeniedException e
181-
) {
182-
callback.error(errMessage(e));
183-
Log.e("connectUsingKeyFile", "Cannot connect", e);
227+
callback.error("Failed to establish SSH connection");
228+
} catch (UnresolvedAddressException e) {
229+
callback.error("Cannot resolve host address");
230+
Log.e(TAG, "Cannot resolve host address", e);
231+
} catch (PermissionDeniedException e) {
232+
callback.error("Authentication failed: " + e.getMessage());
233+
Log.e(TAG, "Authentication failed", e);
234+
} catch (SshException e) {
235+
callback.error("SSH error: " + errMessage(e));
236+
Log.e(TAG, "SSH error", e);
237+
} catch (IOException e) {
238+
callback.error("I/O error: " + errMessage(e));
239+
Log.e(TAG, "I/O error", e);
240+
} catch (SecurityException e) {
241+
callback.error("Security error: " + errMessage(e));
242+
Log.e(TAG, "Security error", e);
243+
} catch (Exception e) {
244+
callback.error("Unexpected error: " + errMessage(e));
245+
Log.e(TAG, "Unexpected error", e);
184246
}
185247
}
186248
}

src/sidebarApps/extensions/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ async function uninstall(id) {
538538
searchInput.value = "";
539539
$searchResult.content = "";
540540
updateHeight($searchResult);
541+
if ($installed.collapsed) {
542+
$installed.expand();
543+
}
541544
}
542545

543546
// Show Ad If Its Free Version, interstitial Ad(iad) is loaded.

0 commit comments

Comments
 (0)