From 06526c5547dd8dd7181f49eb89d962f08165ed8d Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sun, 24 Feb 2019 11:53:05 +0100 Subject: [PATCH] Update model/Gui to syncthing v1.0.1 (#334) * Update model/Gui * Add ConfigXml#getGui --- .../nutomic/syncthingandroid/model/Gui.java | 32 ++++++++++++++----- .../syncthingandroid/util/ConfigXml.java | 23 +++++++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/model/Gui.java b/app/src/main/java/com/nutomic/syncthingandroid/model/Gui.java index 41b8fce4..c1fe08d8 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/model/Gui.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/model/Gui.java @@ -1,14 +1,30 @@ package com.nutomic.syncthingandroid.model; +/** + * Sources: + * - https://github.com/syncthing/syncthing/tree/master/lib/config + * - https://github.com/syncthing/syncthing/blob/master/lib/config/guiconfiguration.go + */ public class Gui { - public boolean enabled; - public String address; - public String user; - public String password; - public boolean useTLS; - public String apiKey; - public boolean insecureAdminAccess; - public String theme; + public boolean debugging = false; + public boolean enabled = true; + + /** + * REST: useTLS + * XML: tls + */ + public boolean useTLS = false; + + public String address = "127.0.0.1:8384"; + public String user = "syncthing"; // Default in this app + public String password; // This will be set to the "apiKey" in {@link ConfigXml#} + public String apiKey; // Automatically generated by SyncthingNative + public String theme = "default"; + + // omitEmpty + public boolean insecureAdminAccess = false; + public boolean insecureAllowFrameLoading = false; + public boolean insecureSkipHostCheck = false; public String getBindAddress() { if (address == null) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index 4b19a936..2373c1a3 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -817,6 +817,29 @@ public class ConfigXml { } } + public Gui getGui() { + Gui defaultGui = new Gui(); + Element elementGui = (Element) mConfig.getDocumentElement().getElementsByTagName("gui").item(0); + if (elementGui == null) { + Log.e(TAG, "getGui: elementGui == null. Returning defaults."); + return defaultGui; + } + Gui gui = new Gui(); + gui.debugging = getAttributeOrDefault(elementGui, "debugging", defaultGui.debugging); + gui.enabled = getAttributeOrDefault(elementGui, "enabled", defaultGui.enabled); + gui.useTLS = getAttributeOrDefault(elementGui, "tls", defaultGui.useTLS); + + gui.address = getContentOrDefault(elementGui.getElementsByTagName("address").item(0), defaultGui.address); + gui.user = getContentOrDefault(elementGui.getElementsByTagName("user").item(0), defaultGui.user); + gui.password = getContentOrDefault(elementGui.getElementsByTagName("password").item(0), ""); + gui.apiKey = getContentOrDefault(elementGui.getElementsByTagName("apiKey").item(0), ""); + gui.theme = getContentOrDefault(elementGui.getElementsByTagName("theme").item(0), defaultGui.theme); + gui.insecureAdminAccess = getContentOrDefault(elementGui.getElementsByTagName("insecureAdminAccess").item(0), defaultGui.insecureAdminAccess); + gui.insecureAllowFrameLoading = getContentOrDefault(elementGui.getElementsByTagName("insecureAllowFrameLoading").item(0), defaultGui.insecureAllowFrameLoading); + gui.insecureSkipHostCheck = getContentOrDefault(elementGui.getElementsByTagName("insecureSkipHostCheck").item(0), defaultGui.insecureSkipHostCheck); + return gui; + } + public Options getOptions() { Options defaultOptions = new Options(); Element elementOptions = (Element) mConfig.getDocumentElement().getElementsByTagName("options").item(0);