Browse Source

Merge pull request #603 from bwitt/re-auth

Re-authenticate for qbittorrent and deluge
pull/605/head
Eric Kok 3 years ago committed by GitHub
parent
commit
62659a98b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/src/main/java/org/transdroid/daemon/IDaemonAdapter.java
  2. 5
      app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeAdapter.java
  3. 6
      app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java

2
app/src/main/java/org/transdroid/daemon/IDaemonAdapter.java

@ -35,4 +35,6 @@ public interface IDaemonAdapter { @@ -35,4 +35,6 @@ public interface IDaemonAdapter {
DaemonSettings getSettings();
long MAX_SESSION_TIME = 30 * 60 * 1000; // 30 minutes
}

5
app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeAdapter.java

@ -150,6 +150,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -150,6 +150,7 @@ public class DelugeAdapter implements IDaemonAdapter {
private DefaultHttpClient httpclient;
private Cookie sessionCookie;
private int version = -1;
private long lastAuthTime = -1;
public DelugeAdapter(DaemonSettings settings) {
this.settings = settings;
@ -476,8 +477,9 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -476,8 +477,9 @@ public class DelugeAdapter implements IDaemonAdapter {
initialise();
// Login first?
if (sessionCookie == null) {
if (sessionCookie == null || System.currentTimeMillis() - lastAuthTime > MAX_SESSION_TIME) {
sessionCookie = null;
// Build login object
String extraPass = settings.getExtraPassword();
if (extraPass == null) {
@ -503,6 +505,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -503,6 +505,7 @@ public class DelugeAdapter implements IDaemonAdapter {
for (Cookie cookie : httpclient.getCookieStore().getCookies()) {
if (cookie.getName().equals(RPC_SESSION_ID)) {
sessionCookie = cookie;
lastAuthTime = System.currentTimeMillis();
break;
}
}

6
app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java

@ -89,6 +89,7 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -89,6 +89,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
private DaemonSettings settings;
private DefaultHttpClient httpclient;
private int version = -1;
private long lastAuthTime = -1;
public QBittorrentAdapter(DaemonSettings settings) {
this.settings = settings;
@ -171,12 +172,14 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -171,12 +172,14 @@ public class QBittorrentAdapter implements IDaemonAdapter {
// Try qBittorrent 4.1 API v2 first
try {
makeRequest(log, "/api/v2/auth/login", usernameParam, passwordParam);
lastAuthTime = System.currentTimeMillis();
} catch (DaemonException ignored) {
}
// If still not authenticated, try the qBittorrent 3.2 API v1 endpoint
if (!isAuthenticated()) {
try {
makeRequest(log, "/login", usernameParam, passwordParam);
lastAuthTime = System.currentTimeMillis();
} catch (DaemonException ignored) {
}
}
@ -187,6 +190,9 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -187,6 +190,9 @@ public class QBittorrentAdapter implements IDaemonAdapter {
}
private boolean isAuthenticated() {
if (System.currentTimeMillis() - lastAuthTime > MAX_SESSION_TIME) {
return false;
}
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
for (Cookie c : cookies) {
if (c.getName().equals("SID")) {

Loading…
Cancel
Save