Browse Source

Support for adding Xirvik servers by QR code

pull/596/head
Eric Kok 4 years ago
parent
commit
cf8736e23b
  1. 1
      app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
  2. 7
      app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java
  3. 2
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  4. 1
      app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java
  5. 68
      app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java
  6. 1
      app/src/main/java/org/transdroid/core/seedbox/DediseedboxSettings.java
  7. 32
      app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java
  8. 32
      app/src/main/java/org/transdroid/core/seedbox/XirvikSemiSettings.java
  9. 35
      app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java
  10. 73
      app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java
  11. 10
      app/src/main/java/org/transdroid/daemon/DaemonSettings.java
  12. 17
      app/src/main/java/org/transdroid/daemon/util/HttpHelper.java
  13. 3
      app/src/main/res/values/changelog.xml
  14. 2
      app/src/main/res/values/strings.xml

1
app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java

@ -188,6 +188,7 @@ public class ApplicationSettings { @@ -188,6 +188,7 @@ public class ApplicationSettings {
prefs.getString("server_user_" + order, null),
prefs.getString("server_pass_" + order, null),
prefs.getString("server_extrapass_" + order, null),
null,
OS.fromCode(prefs.getString("server_os_" + order, "type_linux")),
prefs.getString("server_downloaddir_" + order, null),
prefs.getString("server_ftpurl_" + order, null),

7
app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java

@ -49,6 +49,7 @@ public class ServerSetting implements SimpleListItem { @@ -49,6 +49,7 @@ public class ServerSetting implements SimpleListItem {
private final String username;
private final String password;
private final String extraPass;
private final String authToken;
private final OS os;
private final String downloadDir;
private final String ftpUrl;
@ -80,6 +81,7 @@ public class ServerSetting implements SimpleListItem { @@ -80,6 +81,7 @@ public class ServerSetting implements SimpleListItem {
* @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 authToken Alternative authentication method via auth token added as custom network header
* @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
@ -87,7 +89,7 @@ public class ServerSetting implements SimpleListItem { @@ -87,7 +89,7 @@ public class ServerSetting implements SimpleListItem {
*/
public ServerSetting(int key, String name, Daemon type, String address, String localAddress, int localPort, String localNetwork, int port,
boolean ssl, boolean localSsl, boolean sslTrustAll, String sslTrustKey, String folder, boolean useAuthentication, String username,
String password, String extraPass, OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout,
String password, String extraPass, String authToken, OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout,
boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent, String excludeFilter, String includeFilter,
boolean isAutoGenerated) {
this.key = key;
@ -107,6 +109,7 @@ public class ServerSetting implements SimpleListItem { @@ -107,6 +109,7 @@ public class ServerSetting implements SimpleListItem {
this.username = username;
this.password = password;
this.extraPass = extraPass;
this.authToken = authToken;
this.os = os;
this.downloadDir = downloadDir;
this.ftpUrl = ftpUrl;
@ -331,7 +334,7 @@ public class ServerSetting implements SimpleListItem { @@ -331,7 +334,7 @@ public class ServerSetting implements SimpleListItem {
}
}
return new DaemonSettings(name, type, addressToUse, portToUse, sslEnable, sslTrustAll, sslTrustKey, folder,
useAuthentication, username, password, extraPass, os, downloadDir, ftpUrl, ftpPassword, timeout,
useAuthentication, username, password, extraPass, authToken, os, downloadDir, ftpUrl, ftpPassword, timeout,
alarmOnFinishedDownload, alarmOnNewTorrent, Integer.toString(key), isAutoGenerated);
}
}

2
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -1077,7 +1077,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -1077,7 +1077,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
try {
// Cookies are taken from the websearchSetting that we already matched against this target URL
DefaultHttpClient httpclient = HttpHelper.createStandardHttpClient(false, null, null, true, null, 10000, null, -1);
DefaultHttpClient httpclient = HttpHelper.createStandardHttpClient(false, null, null, null, true, null, 10000, null, -1);
Map<String, String> cookies = HttpHelper.parseCookiePairs(websearchSetting.getCookies());
String domain = Uri.parse(url).getHost();
for (Entry<String, String> pair : cookies.entrySet()) {

1
app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java

@ -31,6 +31,7 @@ public class BarcodeHelper { @@ -31,6 +31,7 @@ public class BarcodeHelper {
// A 'random' ID to identify QR-encoded settings scan intents
public static final int ACTIVITY_BARCODE_QRSETTINGS = 0x0000c0df;
public static final int ACTIVITY_BARCODE_ADDSERVER = 0x0000c0e0;
private static final Uri SCANNER_MARKET_URI = Uri.parse("market://search?q=pname:com.google.zxing.client.android");
/**

68
app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java

@ -30,8 +30,13 @@ import androidx.preference.ListPreference; @@ -30,8 +30,13 @@ import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceClickListener;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.enums.SnackbarType;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OnActivityResult;
import org.androidannotations.annotations.OptionsItem;
import org.transdroid.R;
import org.transdroid.core.app.search.SearchHelper;
@ -41,13 +46,19 @@ import org.transdroid.core.app.settings.RssfeedSetting; @@ -41,13 +46,19 @@ import org.transdroid.core.app.settings.RssfeedSetting;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.WebsearchSetting;
import org.transdroid.core.gui.TorrentsActivity_;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.settings.RssfeedPreference.OnRssfeedClickedListener;
import org.transdroid.core.gui.settings.ServerPreference.OnServerClickedListener;
import org.transdroid.core.gui.settings.WebsearchPreference.OnWebsearchClickedListener;
import org.transdroid.core.seedbox.SeedboxPreference;
import org.transdroid.core.seedbox.SeedboxPreference.OnSeedboxClickedListener;
import org.transdroid.core.seedbox.SeedboxProvider;
import org.transdroid.core.seedbox.XirvikDediSettings;
import org.transdroid.core.seedbox.XirvikSemiSettings;
import org.transdroid.core.seedbox.XirvikSharedSettings;
import org.transdroid.core.seedbox.XirvikSharedSettingsActivity;
import java.util.ArrayList;
import java.util.List;
@ -68,6 +79,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @@ -68,6 +79,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
protected ApplicationSettings applicationSettings;
@Bean
protected SearchHelper searchHelper;
@Bean
protected Log log;
protected SharedPreferences prefs;
private OnPreferenceClickListener onAddServer = new OnPreferenceClickListener() {
@Override
@ -115,6 +128,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @@ -115,6 +128,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
// Start the configuration activity for this specific chosen seedbox
if (which == 0)
ServerSettingsActivity_.intent(MainSettingsActivity.this).start();
else if (which == SeedboxProvider.values().length + 1)
BarcodeHelper.startBarcodeScanner(this, BarcodeHelper.ACTIVITY_BARCODE_ADDSERVER);
else
startActivity(SeedboxProvider.values()[which - 1].getSettings().getSettingsActivityIntent(MainSettingsActivity.this));
};
@ -251,14 +266,63 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @@ -251,14 +266,63 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
protected Dialog onCreateDialog(int id) {
if (id == DIALOG_ADDSEEDBOX) {
// Open dialog to pick one of the supported seedbox providers (or a normal server)
String[] seedboxes = new String[SeedboxProvider.values().length + 1];
String[] seedboxes = new String[SeedboxProvider.values().length + 2];
seedboxes[0] = getString(R.string.pref_addserver_normal);
for (int i = 0; i < seedboxes.length - 1; i++) {
for (int i = 0; i < seedboxes.length - 2; i++) {
seedboxes[i + 1] = getString(R.string.pref_seedbox_addseedbox, SeedboxProvider.values()[i].getSettings().getName());
}
seedboxes[seedboxes.length - 1] = getString(R.string.pref_seedbox_xirvikviaqr);
return new AlertDialog.Builder(this).setItems(seedboxes, onAddSeedbox).create();
}
return null;
}
@OnActivityResult(BarcodeHelper.ACTIVITY_BARCODE_ADDSERVER)
public void onServerBarcodeScanned(int resultCode, Intent data) {
if (resultCode == RESULT_OK && data != null) {
final String result = data.getStringExtra("SCAN_RESULT");
final String format = data.getStringExtra("SCAN_RESULT_FORMAT");
if (format == null || !format.equals("QR_CODE") || result == null || result.split("\n").length < 3) {
SnackbarManager.show(Snackbar.with(this).text(R.string.pref_seedbox_xirvikscanerror).colorResource(R.color.red)
.type(SnackbarType.MULTI_LINE));
return;
}
onServerBarcodeScanHandled(result.split("\n"));
}
}
protected void onServerBarcodeScanHandled(String[] qrResult) {
final String server = qrResult[0];
final String token = qrResult[2];
switch (qrResult[1]) {
case "P":
XirvikDediSettings xirvikDediSettings = new XirvikDediSettings();
xirvikDediSettings.saveServerSetting(this, server, token);
onResume();
break;
case "N":
XirvikSemiSettings xirvikSemiSettings = new XirvikSemiSettings();
xirvikSemiSettings.saveServerSetting(this, server, token);
onResume();
break;
case "RG":
new XirvikSharedSettingsActivity.RetrieveXirvikAutoConfTask(server, "", "", token) {
@Override
protected void onPostExecute(String result) {
if (result == null) {
log.d(MainSettingsActivity.this, "Could not retrieve the Xirvik shared seedbox RPC mount point setting");
}
XirvikSharedSettings xirvikSharedSettings = new XirvikSharedSettings();
xirvikSharedSettings.saveServerSetting(getApplicationContext(), server, token, result);
onResume();
}
}.execute();
break;
default:
SnackbarManager.show(Snackbar.with(this).text(R.string.pref_seedbox_xirvikscanerror).colorResource(R.color.red).type(SnackbarType.MULTI_LINE));
break;
}
}
}

1
app/src/main/java/org/transdroid/core/seedbox/DediseedboxSettings.java

@ -63,6 +63,7 @@ public class DediseedboxSettings extends SeedboxSettingsImpl implements SeedboxS @@ -63,6 +63,7 @@ public class DediseedboxSettings extends SeedboxSettingsImpl implements SeedboxS
user,
pass,
null,
null,
OS.Linux,
"/",
"ftp://" + user + "@" + server + "/",

32
app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java

@ -20,6 +20,8 @@ import android.content.Context; @@ -20,6 +20,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.OS;
@ -46,6 +48,7 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -46,6 +48,7 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe
Daemon type = Daemon.fromCode(prefs.getString("seedbox_xirvikdedi_client_" + order, null));
String user = prefs.getString("seedbox_xirvikdedi_user_" + order, null);
String pass = prefs.getString("seedbox_xirvikdedi_pass_" + order, null);
String authToken = prefs.getString("seedbox_xirvikdedi_token_" + order, null);
return new ServerSetting(
orderOffset + order,
prefs.getString("seedbox_xirvikdedi_name_" + order, null),
@ -64,6 +67,7 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -64,6 +67,7 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe
user,
pass,
type == Daemon.Deluge ? "deluge" : null,
authToken,
OS.Linux,
type == Daemon.uTorrent ? "/downloads" : null,
"ftp://" + user + "@" + server + "/",
@ -91,7 +95,33 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -91,7 +95,33 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe
public void removeServerSetting(SharedPreferences prefs, int order) {
removeServerSetting(prefs, "seedbox_xirvikdedi_server_", new String[]{"seedbox_xirvikdedi_name_",
"seedbox_xirvikdedi_server_", "seedbox_xirvikdedi_client_", "seedbox_xirvikdedi_user_",
"seedbox_xirvikdedi_pass_"}, order);
"seedbox_xirvikdedi_pass_", "seedbox_xirvikdedi_token_"}, order);
}
public void saveServerSetting(Context context, String server, String token) {
// Get server order
int key = SeedboxProvider.XirvikDedi.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)) + 1;
// Shared preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Check server already exists to replace token
for(int i = 0 ; i <= SeedboxProvider.XirvikDedi.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)) ; i++) {
if(prefs.getString("seedbox_xirvikdedi_server_" + i, "").equals(server)) {
key = i;
}
}
// Store new seedbox pref
prefs.edit()
.putString("seedbox_xirvikdedi_client_" + key, Daemon.toCode(Daemon.rTorrent))
.putString("seedbox_xirvikdedi_name" + key, "QR Server " + key)
.putString("seedbox_xirvikdedi_server_" + key, server)
.putString("seedbox_xirvikdedi_user_" + key, "")
.putString("seedbox_xirvikdedi_pass_" + key, "")
.putString("seedbox_xirvikdedi_token_" + key, token)
.apply();
}
}

32
app/src/main/java/org/transdroid/core/seedbox/XirvikSemiSettings.java

@ -20,6 +20,8 @@ import android.content.Context; @@ -20,6 +20,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.OS;
@ -45,6 +47,7 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -45,6 +47,7 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe
}
String user = prefs.getString("seedbox_xirviksemi_user_" + order, null);
String pass = prefs.getString("seedbox_xirviksemi_pass_" + order, null);
String authToken = prefs.getString("seedbox_xirviksemi_token_" + order, null);
return new ServerSetting(
orderOffset + order,
prefs.getString("seedbox_xirviksemi_name_" + order, null),
@ -63,6 +66,7 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -63,6 +66,7 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe
user,
pass,
null,
authToken,
OS.Linux,
null,
"ftp://" + user + "@" + server + "/downloads",
@ -89,7 +93,33 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -89,7 +93,33 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe
@Override
public void removeServerSetting(SharedPreferences prefs, int order) {
removeServerSetting(prefs, "seedbox_xirviksemi_server_", new String[]{"seedbox_xirviksemi_name_",
"seedbox_xirviksemi_server_", "seedbox_xirviksemi_user_", "seedbox_xirviksemi_pass_"}, order);
"seedbox_xirviksemi_server_", "seedbox_xirviksemi_user_", "seedbox_xirviksemi_pass_", "seedbox_xirviksemi_token_"}, order);
}
public void saveServerSetting(Context context, String server, String token) {
// Get server order
int key = SeedboxProvider.XirvikSemi.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)) + 1;
// Shared preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Check server already exists to replace token
for (int i = 0; i <= SeedboxProvider.XirvikSemi.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)); i++) {
if (prefs.getString("seedbox_xirviksemi_server_" + i, "").equals(server)) {
key = i;
}
}
// Store new seedbox pref
prefs.edit()
.putString("seedbox_xirviksemi_client_" + key, Daemon.toCode(Daemon.rTorrent))
.putString("seedbox_xirviksemi_name" + key, "QR Server " + key)
.putString("seedbox_xirviksemi_server_" + key, server)
.putString("seedbox_xirviksemi_user_" + key, "")
.putString("seedbox_xirviksemi_pass_" + key, "")
.putString("seedbox_xirviksemi_token_" + key, token)
.apply();
}
}

35
app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java

@ -20,6 +20,8 @@ import android.content.Context; @@ -20,6 +20,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.OS;
@ -43,13 +45,15 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox @@ -43,13 +45,15 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox
if (server == null) {
return null;
}
Daemon type = Daemon.fromCode(prefs.getString("seedbox_xirvikshared_client_" + order, null));
String user = prefs.getString("seedbox_xirvikshared_user_" + order, null);
String pass = prefs.getString("seedbox_xirvikshared_pass_" + order, null);
String rpc = prefs.getString("seedbox_xirvikshared_rpc_" + order, null);
String authToken = prefs.getString("seedbox_xirvikshared_token_" + order, null);
return new ServerSetting(
orderOffset + order,
prefs.getString("seedbox_xirvikshared_name_" + order, null),
Daemon.rTorrent,
type,
server,
null,
0,
@ -64,6 +68,7 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox @@ -64,6 +68,7 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox
user,
pass,
null,
authToken,
OS.Linux,
null,
"ftp://" + user + "@" + server + "/downloads",
@ -91,7 +96,33 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox @@ -91,7 +96,33 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox
public void removeServerSetting(SharedPreferences prefs, int order) {
removeServerSetting(prefs, "seedbox_xirvikshared_server_", new String[]{"seedbox_xirvikshared_name_",
"seedbox_xirvikshared_server_", "seedbox_xirvikshared_user_", "seedbox_xirvikshared_pass_",
"seedbox_xirvikshared_rpc_"}, order);
"seedbox_xirvikshared_rpc_", "seedbox_xirvikshared_token_"}, order);
}
public void saveServerSetting(final Context context, String server, String token, String rcp) {
// Get server order
int key = SeedboxProvider.XirvikShared.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)) + 1;
// Shared preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Check server already exists to replace token
for (int i = 0; i <= SeedboxProvider.XirvikShared.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)); i++) {
if (prefs.getString("seedbox_xirvikshared_server_" + i, "").equals(server)) {
key = i;
}
}
// Store new seedbox pref
prefs.edit()
.putString("seedbox_xirvikshared_client_" + key, Daemon.toCode(Daemon.rTorrent))
.putString("seedbox_xirvikshared_name" + key, "QR Server " + key)
.putString("seedbox_xirvikshared_server_" + key, server)
.putString("seedbox_xirvikshared_user_" + key, "")
.putString("seedbox_xirvikshared_pass_" + key, "")
.putString("seedbox_xirvikshared_token_" + key, token)
.putString("seedbox_xirvikshared_rpc_" + key, rcp)
.apply();
}
}

73
app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java

@ -90,38 +90,13 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity { @@ -90,38 +90,13 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity {
excludeFilter.setEnabled(alarmNew || alarmFinished);
includeFilter.setEnabled(alarmNew || alarmFinished);
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
// When the shared server settings change, we also have to update the RPC mount point to use
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(XirvikSharedSettingsActivity.this);
String server = prefs.getString("seedbox_xirvikshared_server_" + key, null);
String user = prefs.getString("seedbox_xirvikshared_user_" + key, null);
String pass = prefs.getString("seedbox_xirvikshared_pass_" + key, null);
// Retrieve the RPC mount point setting from the server itself
DefaultHttpClient httpclient =
HttpHelper.createStandardHttpClient(true, user, pass, true, null, HttpHelper.DEFAULT_CONNECTION_TIMEOUT, server, 443);
String url = "https://" + server + ":443/browsers_addons/transdroid_autoconf.txt";
HttpResponse request = httpclient.execute(new HttpGet(url));
InputStream stream = request.getEntity().getContent();
String folder = HttpHelper.convertStreamToString(stream).trim();
if (folder.startsWith("<?xml")) {
folder = null;
}
stream.close();
return folder;
} catch (Exception e) {
log.d(XirvikSharedSettingsActivity.this, "Could not retrieve the Xirvik shared seedbox RPC mount point setting: " + e.toString());
return null;
}
}
// When the shared server settings change, we also have to update the RPC mount point to use
String server = prefs.getString("seedbox_xirvikshared_server_" + key, null);
String user = prefs.getString("seedbox_xirvikshared_user_" + key, null);
String pass = prefs.getString("seedbox_xirvikshared_pass_" + key, null);
String token = prefs.getString("seedbox_xirvikshared_token_" + key, null);
new RetrieveXirvikAutoConfTask(server, user, pass, token) {
@Override
protected void onPostExecute(String result) {
storeScgiMountFolder(result);
@ -134,6 +109,7 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity { @@ -134,6 +109,7 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity {
Editor edit = PreferenceManager.getDefaultSharedPreferences(XirvikSharedSettingsActivity.this).edit();
EditTextPreference pref = (EditTextPreference) findPreference("seedbox_xirvikshared_rpc_" + key);
if (result == null) {
log.d(this, "Could not retrieve the Xirvik shared seedbox RPC mount point setting");
SnackbarManager.show(Snackbar.with(this).text(R.string.pref_seedbox_xirviknofolder).colorResource(R.color.red));
edit.remove("seedbox_xirvikshared_rpc_" + key);
pref.setSummary("");
@ -157,4 +133,39 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity { @@ -157,4 +133,39 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity {
finish();
}
public static abstract class RetrieveXirvikAutoConfTask extends AsyncTask<Void, Void, String> {
final String server;
final String user;
final String pass;
final String token;
public RetrieveXirvikAutoConfTask(String server, String user, String pass, String token) {
this.server = server;
this.user = user;
this.pass = pass;
this.token = token;
}
@Override
protected String doInBackground(Void... params) {
try {
// Retrieve the RPC mount point setting from the server itself
DefaultHttpClient httpclient =
HttpHelper.createStandardHttpClient(true, user, pass, token, true, null, HttpHelper.DEFAULT_CONNECTION_TIMEOUT, server, 443);
String url = "https://" + server + ":443/browsers_addons/transdroid_autoconf.txt";
HttpResponse request = httpclient.execute(new HttpGet(url));
InputStream stream = request.getEntity().getContent();
String folder = HttpHelper.convertStreamToString(stream).trim();
if (folder.startsWith("<?xml")) {
folder = null;
}
stream.close();
return folder;
} catch (Exception e) {
return null;
}
}
}
}

10
app/src/main/java/org/transdroid/daemon/DaemonSettings.java

@ -38,6 +38,7 @@ public final class DaemonSettings { @@ -38,6 +38,7 @@ public final class DaemonSettings {
final private String username;
final private String password;
final private String extraPass;
final private String authToken;
final private OS os;
final private String downloadDir;
final private String ftpUrl;
@ -49,7 +50,7 @@ public final class DaemonSettings { @@ -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, null,
this(null, null, null, 0, false, false, null, null, false, null, null, null, null,
null, null, null, null, 0, false, false, null, false);
}
@ -74,7 +75,7 @@ public final class DaemonSettings { @@ -74,7 +75,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, String extraPass, OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout,
String username, String password, String extraPass, String authToken, OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout,
boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent, String idString, boolean isAutoGenerated) {
this.name = name;
this.type = type;
@ -88,6 +89,7 @@ public final class DaemonSettings { @@ -88,6 +89,7 @@ public final class DaemonSettings {
this.username = username;
this.password = password;
this.extraPass = extraPass;
this.authToken = authToken;
this.os = os;
this.downloadDir = downloadDir;
this.ftpUrl = ftpUrl;
@ -147,6 +149,10 @@ public final class DaemonSettings { @@ -147,6 +149,10 @@ public final class DaemonSettings {
return extraPass;
}
public String getAuthToken() {
return authToken;
}
public OS getOS() {
return os;
}

17
app/src/main/java/org/transdroid/daemon/util/HttpHelper.java

@ -22,6 +22,7 @@ import android.net.Uri; @@ -22,6 +22,7 @@ import android.net.Uri;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.auth.AuthScope;
@ -37,6 +38,7 @@ import org.apache.http.params.BasicHttpParams; @@ -37,6 +38,7 @@ import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HttpContext;
import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType;
import org.transdroid.daemon.DaemonSettings;
@ -64,6 +66,7 @@ public class HttpHelper { @@ -64,6 +66,7 @@ public class HttpHelper {
* The 'User-Agent' name to send to the server
*/
public static String userAgent = "Transdroid Torrent Connect";
/**
* HTTP request interceptor to allow for GZip-encoded data transfer
*/
@ -101,7 +104,7 @@ public class HttpHelper { @@ -101,7 +104,7 @@ public class HttpHelper {
public static DefaultHttpClient createStandardHttpClient(DaemonSettings settings, boolean userBasicAuth)
throws DaemonException {
return createStandardHttpClient(userBasicAuth && settings.shouldUseAuthentication(), settings.getUsername(),
settings.getPassword(), settings.getSslTrustAll(), settings.getSslTrustKey(),
settings.getPassword(), settings.getAuthToken(), settings.getSslTrustAll(), settings.getSslTrustKey(),
settings.getTimeoutInMilliseconds(), settings.getAddress(), settings.getPort());
}
@ -117,7 +120,7 @@ public class HttpHelper { @@ -117,7 +120,7 @@ public class HttpHelper {
* @return An HttpClient that should be stored locally and reused for every new request
* @throws DaemonException Thrown when information (such as username/password) is missing
*/
public static DefaultHttpClient createStandardHttpClient(boolean userBasicAuth, String username, String password,
public static DefaultHttpClient createStandardHttpClient(boolean userBasicAuth, String username, String password, String authToken,
boolean sslTrustAll, String sslTrustKey, int timeout,
String authAddress, int authPort) throws DaemonException {
@ -156,6 +159,16 @@ public class HttpHelper { @@ -156,6 +159,16 @@ public class HttpHelper {
new UsernamePasswordCredentials(username, password));
}
// Auth token header
if (authToken != null) {
httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader("X-QR-Auth", authToken);
}
});
}
return httpclient;
}

3
app/src/main/res/values/changelog.xml

@ -16,6 +16,9 @@ @@ -16,6 +16,9 @@
-->
<resources>
<string name="system_changelog">
Transdroid 2.5.20\n
- Add Xirvik servers via QR code\n
\n
Transdroid 2.5.19\n
- Dark theme to use black background\n
- Reinstated black widget\n

2
app/src/main/res/values/strings.xml

@ -379,6 +379,8 @@ @@ -379,6 +379,8 @@
<string name="pref_seedbox_client">Torrent client</string>
<string name="pref_seedbox_client_info">Client to connect to</string>
<string name="pref_seedbox_server">Server address</string>
<string name="pref_seedbox_xirvikviaqr">Add Xirvik server via QR</string>
<string name="pref_seedbox_xirvikscanerror">Not a valid Xirvik server QR code</string>
<string name="pref_seedbox_xirvikhint">Like eplus001.xirvik.com</string>
<string name="pref_seedbox_xirvikhint2">Like semixl001a.xirvik.com</string>
<string name="pref_seedbox_xirvikhint3">Like desharedgbit001.xirvik.com</string>

Loading…
Cancel
Save