From 5e21d397e07b42ed40c0575f1c1aacefccdcf9be Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Mon, 27 Aug 2012 17:03:21 +0200 Subject: [PATCH] Added support for Deluge's web interface password as seperate values from the HTTP auth password and username (see issue 260). --- android/res/values/changelog.xml | 3 +++ android/res/values/strings.xml | 2 ++ .../preferences/SeedstuffSettings.java | 2 +- .../preferences/SeedM8Settings.java | 3 +++ .../preferences/XirvikSettings.java | 6 ++--- .../transdroid/preferences/Preferences.java | 4 ++++ .../preferences/PreferencesServer.java | 22 +++++++++++++++++-- lib/src/org/transdroid/daemon/Daemon.java | 8 +++++-- .../org/transdroid/daemon/DaemonSettings.java | 20 ++++++++++++----- .../daemon/Deluge/DelugeAdapter.java | 11 +++++++--- 10 files changed, 64 insertions(+), 17 deletions(-) diff --git a/android/res/values/changelog.xml b/android/res/values/changelog.xml index bae96748..7ab71a39 100644 --- a/android/res/values/changelog.xml +++ b/android/res/values/changelog.xml @@ -2,7 +2,10 @@ Transdroid 1.1.6\n +- Added BitComet support, by Sergey (SeNS)\n - Improved label support, by Alexey Rogovoy\n +- Added GZipped content support in RSS feeds\n +- Allow Deluge users to enter a password for HTTP authentication\n \n Transdroid 1.1.5\n - AndFTP alias:// support and file-in-root fix\n diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index bfb8d23a..7fa20152 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -138,7 +138,9 @@ Use authentication You\'ll need a username and password Username +Username for HTTP authentication Password +Deluge web password Server OS SCGI folder Usually is /RPC2 diff --git a/android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java b/android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java index d8e813cd..03ebddc7 100644 --- a/android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java +++ b/android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java @@ -80,7 +80,7 @@ public class SeedstuffSettings { List daemons = new ArrayList(); // rTorrent daemons.add(new DaemonSettings(getName(), Daemon.rTorrent, getServer(), RTORRENT_PORT, true, true, null, - RTORRENT_FOLDER_PART + getUsername(), true, getUsername(), getPassword(), OS.Linux, + RTORRENT_FOLDER_PART + getUsername(), true, getUsername(), getPassword(), null, OS.Linux, "/rtorrent/downloads/", "ftp://" + getName() + "@" + getServer() + FTP_PORT + "/rtorrents/downloads/", getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(), shouldAlarmOnNewTorrent(), "" + startID++, true)); diff --git a/android/src/com/seedm8/transdroid/preferences/SeedM8Settings.java b/android/src/com/seedm8/transdroid/preferences/SeedM8Settings.java index 01a83d2f..a099ba12 100644 --- a/android/src/com/seedm8/transdroid/preferences/SeedM8Settings.java +++ b/android/src/com/seedm8/transdroid/preferences/SeedM8Settings.java @@ -111,6 +111,7 @@ public class SeedM8Settings { true, getUsername(), getDelugePassword(), + getDelugePassword(), OS.Linux, null, "sftp://" + getServer() + "/home/" + getUsername() + "/private/deluge/data/", @@ -134,6 +135,7 @@ public class SeedM8Settings { true, getUsername(), getTransmissionPassword(), + null, OS.Linux, null, "sftp://" + getServer() + "/home/" + getUsername() + "/private/transmission/data/", @@ -157,6 +159,7 @@ public class SeedM8Settings { true, "rutorrent", getRtorrentPassword(), + null, OS.Linux, null, "sftp://" + getUsername() + "@" + getServer() + "/home/" + getUsername() + "/private/rtorrent/data/", diff --git a/android/src/com/xirvik/transdroid/preferences/XirvikSettings.java b/android/src/com/xirvik/transdroid/preferences/XirvikSettings.java index 5792b7a5..a01319fe 100644 --- a/android/src/com/xirvik/transdroid/preferences/XirvikSettings.java +++ b/android/src/com/xirvik/transdroid/preferences/XirvikSettings.java @@ -93,7 +93,7 @@ public class XirvikSettings { getName() + (isDedi? " Torrentflux-b4rt": ""), Daemon.Tfb4rt, getServer(), TFB4RT_PORT, true, true, null, - TFB4RT_FOLDER, true, getUsername(), getPassword(), + TFB4RT_FOLDER, true, getUsername(), getPassword(), null, OS.Linux, "/", "ftp://" + getName() + ":" + getServer() + "/", getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(), shouldAlarmOnNewTorrent(), "" + startID++, true)); @@ -104,7 +104,7 @@ public class XirvikSettings { getName() + (isDedi? " rTorrent": ""), Daemon.rTorrent, getServer(), RTORRENT_PORT, true, true, null, - getFolder(), true, getUsername(), getPassword(), + getFolder(), true, getUsername(), getPassword(), null, OS.Linux, "/", "ftp://" + getName() + ":" + getServer() + "/", getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(), shouldAlarmOnNewTorrent(), "" + startID++, true)); @@ -115,7 +115,7 @@ public class XirvikSettings { getName() + " uTorrent", Daemon.uTorrent, getServer(), UTORRENT_PORT, false, false, null, - null, true, getUsername(), getPassword(), + null, true, getUsername(), getPassword(), null, OS.Linux, "/", "ftp://" + getName() + ":" + getServer() + "/", getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(), shouldAlarmOnNewTorrent(), "" + startID++, true)); diff --git a/android/src/org/transdroid/preferences/Preferences.java b/android/src/org/transdroid/preferences/Preferences.java index d9d1f191..96f1a2e0 100644 --- a/android/src/org/transdroid/preferences/Preferences.java +++ b/android/src/org/transdroid/preferences/Preferences.java @@ -100,6 +100,7 @@ public class Preferences { public static final String KEY_PREF_AUTH = "transdroid_server_auth"; public static final String KEY_PREF_USER = "transdroid_server_user"; public static final String KEY_PREF_PASS = "transdroid_server_pass"; + public static final String KEY_PREF_EXTRAPASS = "transdroid_server_extrapass"; public static final String KEY_PREF_OS = "transdroid_server_os"; public static final String KEY_PREF_DOWNLOADDIR = "transdroid_server_downloaddir"; public static final String KEY_PREF_FTPURL = "transdroid_server_ftpurl"; @@ -186,6 +187,7 @@ public class Preferences { editor.putBoolean(KEY_PREF_AUTH + toId, prefs.getBoolean(KEY_PREF_AUTH + fromId, false)); editor.putString(KEY_PREF_USER + toId, prefs.getString(KEY_PREF_USER + fromId, null)); editor.putString(KEY_PREF_PASS + toId, prefs.getString(KEY_PREF_PASS + fromId, null)); + editor.putString(KEY_PREF_EXTRAPASS + toId, prefs.getString(KEY_PREF_EXTRAPASS + fromId, null)); editor.putString(KEY_PREF_OS + toId, prefs.getString(KEY_PREF_OS + fromId, "type_windows")); editor.putString(KEY_PREF_DOWNLOADDIR + toId, prefs.getString(KEY_PREF_DOWNLOADDIR + fromId, null)); editor.putString(KEY_PREF_FTPURL + toId, prefs.getString(KEY_PREF_FTPURL + fromId, null)); @@ -204,6 +206,7 @@ public class Preferences { editor.remove(KEY_PREF_AUTH + delId); editor.remove(KEY_PREF_USER + delId); editor.remove(KEY_PREF_PASS + delId); + editor.remove(KEY_PREF_EXTRAPASS + delId); editor.remove(KEY_PREF_OS + delId); editor.remove(KEY_PREF_DOWNLOADDIR + delId); editor.remove(KEY_PREF_FTPURL + delId); @@ -928,6 +931,7 @@ public class Preferences { prefs.getBoolean(KEY_PREF_AUTH + postfix, false), prefs.getString(KEY_PREF_USER + postfix, null), prefs.getString(KEY_PREF_PASS + postfix, null), + prefs.getString(KEY_PREF_EXTRAPASS + postfix, null), OS.fromCode(prefs.getString(KEY_PREF_OS + postfix, "type_windows")), prefs.getString(KEY_PREF_DOWNLOADDIR + postfix, null), prefs.getString(KEY_PREF_FTPURL + postfix, null), diff --git a/android/src/org/transdroid/preferences/PreferencesServer.java b/android/src/org/transdroid/preferences/PreferencesServer.java index 2f9ed683..df52c1e7 100644 --- a/android/src/org/transdroid/preferences/PreferencesServer.java +++ b/android/src/org/transdroid/preferences/PreferencesServer.java @@ -60,6 +60,7 @@ public class PreferencesServer extends PreferenceActivity { private TransdroidCheckBoxPreference auth; private TransdroidEditTextPreference user; private TransdroidEditTextPreference pass; + private TransdroidEditTextPreference extraPass; private TransdroidListPreference os; private TransdroidEditTextPreference downloadDir; private TransdroidEditTextPreference ftpUrl; @@ -75,6 +76,7 @@ public class PreferencesServer extends PreferenceActivity { private boolean authValue = false; private String userValue = null; //private String passValue = null; + //private String extraPassValue = null; private boolean sslValue = false; private boolean sslTAValue = false; @@ -107,6 +109,7 @@ public class PreferencesServer extends PreferenceActivity { authValue = prefs.getBoolean(Preferences.KEY_PREF_AUTH + serverPostfix, false); userValue = prefs.getString(Preferences.KEY_PREF_USER + serverPostfix, null); //passValue = prefs.getString(Preferences.KEY_PREF_PASS + serverPostfix, null); + //extraPassValue = prefs.getString(Preferences.KEY_PREF_EXTRAPASS + serverPostfix, null); sslValue = prefs.getBoolean(Preferences.KEY_PREF_SSL + serverPostfix, false); //sslTAValue = prefs.getBoolean(Preferences.KEY_PREF_SSL_TRUST_ALL + serverPostfix, false); @@ -159,7 +162,7 @@ public class PreferencesServer extends PreferenceActivity { port.setDialogTitle(R.string.pref_port); port.setOnPreferenceChangeListener(updateHandler); getPreferenceScreen().addItemFromInflater(port); - + // Auth auth = new TransdroidCheckBoxPreference(this); auth.setTitle(R.string.pref_auth); @@ -204,6 +207,16 @@ public class PreferencesServer extends PreferenceActivity { folder.setDialogTitle(R.string.pref_folder); folder.setOnPreferenceChangeListener(updateHandler); getPreferenceScreen().addItemFromInflater(folder); + // ExtraUser + extraPass = new TransdroidEditTextPreference(this); + extraPass.setTitle(R.string.pref_extrapass); + extraPass.setKey(Preferences.KEY_PREF_EXTRAPASS + serverPostfix); + extraPass.getEditText().setSingleLine(); + extraPass.getEditText().setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); + extraPass.getEditText().setTransformationMethod(new PasswordTransformationMethod()); + extraPass.setDialogTitle(R.string.pref_extrapass); + extraPass.setOnPreferenceChangeListener(updateHandler); + getPreferenceScreen().addItemFromInflater(extraPass); // Advanced PreferenceCategory advanced = new PreferenceCategory(this); @@ -322,6 +335,8 @@ public class PreferencesServer extends PreferenceActivity { userValue = (String) newValue; } else if (preference == pass) { //passValue = (String) newValue; + } else if (preference == extraPass) { + //extraPassValue = (String) newValue; } else if (preference == ssl) { sslValue = (Boolean) newValue; } else if (preference == sslTrustAll) { @@ -391,8 +406,9 @@ public class PreferencesServer extends PreferenceActivity { // Use daemon factory to see if the newly selected daemon supports the feature // Then set the availability of the options according to the (other) settings Daemon daemonType = Daemon.fromCode(daemonValue); - user.setEnabled(authValue && (daemonType == null? true: Daemon.supportsUsername(Daemon.fromCode(daemonValue)))); + user.setEnabled(authValue); pass.setEnabled(authValue); + extraPass.setEnabled(Daemon.supportsExtraPassword(Daemon.fromCode(daemonValue))); sslTrustAll.setEnabled(sslValue); folder.setEnabled(daemonType == null? false: Daemon.supportsCustomFolder(daemonType)); downloadDir.setEnabled(daemonType == null? false: Daemon.needsManualPathSpecified(daemonType)); @@ -410,6 +426,8 @@ public class PreferencesServer extends PreferenceActivity { port.setSummary(portValue == null? getText(R.string.pref_port_info).toString().trim() + " " + Daemon.getDefaultPortNumber(daemonType, sslValue): portValue); auth.setSummary(R.string.pref_auth_info); + user.setTitle(daemonType != null && Daemon.supportsUsernameForHttp(Daemon.fromCode(daemonValue)) ? getString(R.string.pref_user_forhttp) + : getString(R.string.pref_user)); user.setSummary(userValue == null? "": userValue); if (daemonType == Daemon.rTorrent) { diff --git a/lib/src/org/transdroid/daemon/Daemon.java b/lib/src/org/transdroid/daemon/Daemon.java index bc60071d..0aa81fd0 100644 --- a/lib/src/org/transdroid/daemon/Daemon.java +++ b/lib/src/org/transdroid/daemon/Daemon.java @@ -270,8 +270,12 @@ public enum Daemon { return type == uTorrent || type == BitTorrent || type == Deluge; } - public static boolean supportsUsername(Daemon type) { - return !(type == Deluge); + public static boolean supportsExtraPassword(Daemon type) { + return type == Deluge; + } + + public static boolean supportsUsernameForHttp(Daemon type) { + return type == Deluge; } } diff --git a/lib/src/org/transdroid/daemon/DaemonSettings.java b/lib/src/org/transdroid/daemon/DaemonSettings.java index 99368309..517c96ac 100644 --- a/lib/src/org/transdroid/daemon/DaemonSettings.java +++ b/lib/src/org/transdroid/daemon/DaemonSettings.java @@ -38,6 +38,7 @@ public final class DaemonSettings { final private boolean useAuthentication; final private String username; final private String password; + final private String extraPass; final private OS os; final private String downloadDir; final private String ftpUrl; @@ -49,7 +50,7 @@ public final class DaemonSettings { final private boolean isAutoGenerated; protected DaemonSettings() { - this(null, null, null, 0, false, false, null, null, false, null, null, + this(null, null, null, 0, false, false, null, null, false, null, null, null, null, null, null, null, 0, false, false, null, false); } @@ -64,6 +65,7 @@ public final class DaemonSettings { * @param useAuthentication Whether to use basic authentication * @param username The user name to provide during authentication * @param password The password to provide during authentication + * @param extraPass The Deluge web interface password * @param downloadDir The default download directory (which may also be used as base directory for file paths) * @param ftpUrl The partial URL to connect to when requesting FTP-style transfers * @param timeout The number of seconds to wait before timing out a connection attempt @@ -72,7 +74,7 @@ public final class DaemonSettings { */ public DaemonSettings(String name, Daemon type, String address, int port, boolean ssl, boolean sslTrustAll, String sslTrustKey, String folder, boolean useAuthentication, - String username, String password, OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout, + String username, String password, String extraPass, OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout, boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent, String idString, boolean isAutoGenerated) { this.name = name; @@ -86,6 +88,7 @@ public final class DaemonSettings { this.useAuthentication = useAuthentication; this.username = username; this.password = password; + this.extraPass = extraPass; this.os = os; this.downloadDir = downloadDir; this.ftpUrl = ftpUrl; @@ -130,6 +133,9 @@ public final class DaemonSettings { public String getPassword() { return password; } + public String getExtraPassword() { + return extraPass; + } public OS getOS() { return os; } @@ -165,11 +171,13 @@ public final class DaemonSettings { public String getHumanReadableIdentifier() { if (isAutoGenerated) { // Hide the 'implementation details'; just give the username and server - return (this.shouldUseAuthentication() && Daemon.supportsUsername(getType())? this.getUsername() + "@": "") + getAddress(); + return (this.shouldUseAuthentication() && this.getUsername() != null && !this.getUsername().isEmpty() ? this + .getUsername() + "@" : "") + getAddress(); } - return (this.ssl ? "https://" : "http://") + ((this.shouldUseAuthentication() && Daemon.supportsUsername(getType()))? this.getUsername() + "@": "") + - getAddress() + ":" + getPort() + - (Daemon.supportsCustomFolder(getType()) && getFolder() != null? getFolder(): ""); + return (this.ssl ? "https://" : "http://") + + (this.shouldUseAuthentication() && this.getUsername() != null && !this.getUsername().isEmpty() ? this + .getUsername() + "@" : "") + getAddress() + ":" + getPort() + + (Daemon.supportsCustomFolder(getType()) && getFolder() != null ? getFolder() : ""); } @Override diff --git a/lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java b/lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java index 0eb07c7f..77e33c99 100644 --- a/lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java +++ b/lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java @@ -430,9 +430,13 @@ public class DelugeAdapter implements IDaemonAdapter { if (sessionCookie == null) { // Build login object + String extraPass = settings.getExtraPassword(); + if (extraPass == null || extraPass.isEmpty()) { + extraPass = settings.getPassword(); + } JSONObject loginRequest = new JSONObject(); loginRequest.put(RPC_METHOD, RPC_METHOD_LOGIN); - loginRequest.put(RPC_PARAMS, (new JSONArray()).put(settings.getPassword())); + loginRequest.put(RPC_PARAMS, (new JSONArray()).put(extraPass)); loginRequest.put(RPC_ID, 1); // Set POST URL and data @@ -520,7 +524,7 @@ public class DelugeAdapter implements IDaemonAdapter { */ private void initialise() throws DaemonException { - httpclient = HttpHelper.createStandardHttpClient(settings, false); + httpclient = HttpHelper.createStandardHttpClient(settings, settings.getUsername() != null && !settings.getUsername().isEmpty()); httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor); httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor); @@ -624,8 +628,9 @@ public class DelugeAdapter implements IDaemonAdapter { return 2; case High: return 3; + default: + return 1; } - return 1; } private TorrentStatus convertDelugeState(String state) {