mirror of https://github.com/zlatinb/muwire
add webui properties with a drop box configuration
parent
1676f81091
commit
fe216ea648
|
@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -28,6 +29,7 @@ public class ConfigurationServlet extends HttpServlet {
|
||||||
INPUT_VALIDATORS.put("uploadSlotsPerUser", new IntegerValidator("Upload slots per user (-1 means unlimited)"));
|
INPUT_VALIDATORS.put("uploadSlotsPerUser", new IntegerValidator("Upload slots per user (-1 means unlimited)"));
|
||||||
INPUT_VALIDATORS.put("downloadLocation", new DirectoryValidator());
|
INPUT_VALIDATORS.put("downloadLocation", new DirectoryValidator());
|
||||||
INPUT_VALIDATORS.put("incompleteLocation", new DirectoryValidator());
|
INPUT_VALIDATORS.put("incompleteLocation", new DirectoryValidator());
|
||||||
|
INPUT_VALIDATORS.put("dropBoxLocation", new DirectoryValidator());
|
||||||
INPUT_VALIDATORS.put("speedSmoothSeconds", new PositiveIntegerValidator("Download speed smoothing interval (seconds)"));
|
INPUT_VALIDATORS.put("speedSmoothSeconds", new PositiveIntegerValidator("Download speed smoothing interval (seconds)"));
|
||||||
INPUT_VALIDATORS.put("inbound.length", new PositiveIntegerValidator("Inbound tunnel length"));
|
INPUT_VALIDATORS.put("inbound.length", new PositiveIntegerValidator("Inbound tunnel length"));
|
||||||
INPUT_VALIDATORS.put("inbound.quantity", new PositiveIntegerValidator("Inbound tunnel quantity"));
|
INPUT_VALIDATORS.put("inbound.quantity", new PositiveIntegerValidator("Inbound tunnel quantity"));
|
||||||
|
@ -37,6 +39,7 @@ public class ConfigurationServlet extends HttpServlet {
|
||||||
INPUT_VALIDATORS.put("defaultFeedItemsToKeep", new IntegerValidator("Number of items to keep on disk (-1 means unlimited)"));
|
INPUT_VALIDATORS.put("defaultFeedItemsToKeep", new IntegerValidator("Number of items to keep on disk (-1 means unlimited)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WebUISettings webSettings;
|
||||||
private Core core;
|
private Core core;
|
||||||
private ServletContext context;
|
private ServletContext context;
|
||||||
|
|
||||||
|
@ -60,6 +63,11 @@ public class ConfigurationServlet extends HttpServlet {
|
||||||
String value = req.getParameter(name);
|
String value = req.getParameter(name);
|
||||||
update(name, value);
|
update(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrintWriter pw = new PrintWriter(new File(core.getHome(), "webui.properties"), "UTF-8");
|
||||||
|
webSettings.write(pw);
|
||||||
|
pw.close();
|
||||||
|
|
||||||
core.saveMuSettings();
|
core.saveMuSettings();
|
||||||
core.saveI2PSettings();
|
core.saveI2PSettings();
|
||||||
context.setAttribute("MWConfigError", null);
|
context.setAttribute("MWConfigError", null);
|
||||||
|
@ -98,6 +106,7 @@ public class ConfigurationServlet extends HttpServlet {
|
||||||
case "uploadSlotsPerUser" : core.getMuOptions().setUploadSlotsPerUser(Integer.parseInt(value)); break;
|
case "uploadSlotsPerUser" : core.getMuOptions().setUploadSlotsPerUser(Integer.parseInt(value)); break;
|
||||||
case "downloadLocation" : core.getMuOptions().setDownloadLocation(getDirectory(value)); break;
|
case "downloadLocation" : core.getMuOptions().setDownloadLocation(getDirectory(value)); break;
|
||||||
case "incompleteLocation" : core.getMuOptions().setIncompleteLocation(getDirectory(value)); break;
|
case "incompleteLocation" : core.getMuOptions().setIncompleteLocation(getDirectory(value)); break;
|
||||||
|
case "dropBoxLocation" : webSettings.setDropBoxLocation(getDirectory(value)); break;
|
||||||
case "shareDownloadedFiles" : core.getMuOptions().setShareDownloadedFiles(true); break;
|
case "shareDownloadedFiles" : core.getMuOptions().setShareDownloadedFiles(true); break;
|
||||||
case "shareHiddenFiles" : core.getMuOptions().setShareHiddenFiles(true); break;
|
case "shareHiddenFiles" : core.getMuOptions().setShareHiddenFiles(true); break;
|
||||||
case "searchComments" : core.getMuOptions().setSearchComments(true); break;
|
case "searchComments" : core.getMuOptions().setSearchComments(true); break;
|
||||||
|
@ -116,7 +125,6 @@ public class ConfigurationServlet extends HttpServlet {
|
||||||
case "defaultFeedUpdateInterval" : core.getMuOptions().setDefaultFeedUpdateInterval(60000 * Long.parseLong(value)); break;
|
case "defaultFeedUpdateInterval" : core.getMuOptions().setDefaultFeedUpdateInterval(60000 * Long.parseLong(value)); break;
|
||||||
case "defaultFeedItemsToKeep" : core.getMuOptions().setDefaultFeedItemsToKeep(Integer.parseInt(value)); break;
|
case "defaultFeedItemsToKeep" : core.getMuOptions().setDefaultFeedItemsToKeep(Integer.parseInt(value)); break;
|
||||||
|
|
||||||
// TODO: ui settings
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,6 +186,7 @@ public class ConfigurationServlet extends HttpServlet {
|
||||||
public void init(ServletConfig config) throws ServletException {
|
public void init(ServletConfig config) throws ServletException {
|
||||||
context = config.getServletContext();
|
context = config.getServletContext();
|
||||||
core = (Core) config.getServletContext().getAttribute("core");
|
core = (Core) config.getServletContext().getAttribute("core");
|
||||||
|
webSettings = (WebUISettings) config.getServletContext().getAttribute("webSettings");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,20 @@ public class InitServlet extends HttpServlet {
|
||||||
else if (!incompleteLocationFile.canWrite())
|
else if (!incompleteLocationFile.canWrite())
|
||||||
throw new Exception("Incomplete files location not writeable");
|
throw new Exception("Incomplete files location not writeable");
|
||||||
|
|
||||||
|
String dropBoxLocation = req.getParameter("dropbox_location");
|
||||||
|
if (dropBoxLocation == null)
|
||||||
|
throw new Exception("DropBox location cannot be blank");
|
||||||
|
File dropBoxLocationFile = new File(dropBoxLocation);
|
||||||
|
if (!dropBoxLocationFile.exists()) {
|
||||||
|
if (!dropBoxLocationFile.mkdirs())
|
||||||
|
throw new Exception("Couldn't create DropBox location");
|
||||||
|
} else if (dropBoxLocationFile.isFile())
|
||||||
|
throw new Exception("DropBox location must point to a directory");
|
||||||
|
else if (!dropBoxLocationFile.canWrite())
|
||||||
|
throw new Exception("DropBox location not writeable");
|
||||||
|
|
||||||
MuWireClient client = (MuWireClient) req.getServletContext().getAttribute("mwClient");
|
MuWireClient client = (MuWireClient) req.getServletContext().getAttribute("mwClient");
|
||||||
client.initMWProps(nickname, downloadLocationFile, incompleteLocationFile);
|
client.initMWProps(nickname, downloadLocationFile, incompleteLocationFile, dropBoxLocationFile);
|
||||||
client.start();
|
client.start();
|
||||||
resp.sendRedirect("/MuWire/index");
|
resp.sendRedirect("/MuWire/index");
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class MuWireClient {
|
||||||
private final ServletContext servletContext;
|
private final ServletContext servletContext;
|
||||||
private final String version;
|
private final String version;
|
||||||
private final String home;
|
private final String home;
|
||||||
private final File mwProps;
|
private final File mwProps, webUIProps;
|
||||||
|
|
||||||
private volatile Core core;
|
private volatile Core core;
|
||||||
private volatile boolean coreLoaded;
|
private volatile boolean coreLoaded;
|
||||||
|
@ -70,6 +70,7 @@ public class MuWireClient {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.home = home;
|
this.home = home;
|
||||||
this.mwProps = new File(home, "MuWire.properties");
|
this.mwProps = new File(home, "MuWire.properties");
|
||||||
|
this.webUIProps = new File(home, "webui.properties");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Throwable {
|
public void start() throws Throwable {
|
||||||
|
@ -87,8 +88,19 @@ public class MuWireClient {
|
||||||
logger.addHandler(new I2PLogHandler(ctx));
|
logger.addHandler(new I2PLogHandler(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(mwProps), StandardCharsets.UTF_8));
|
BufferedReader reader;
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
|
|
||||||
|
if (webUIProps.exists() && webUIProps.isFile()) {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(new FileInputStream(webUIProps), StandardCharsets.UTF_8));
|
||||||
|
props.load(reader);
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
WebUISettings webSettings = new WebUISettings(props);
|
||||||
|
servletContext.setAttribute("webSettings", webSettings);
|
||||||
|
|
||||||
|
reader = new BufferedReader(new InputStreamReader(new FileInputStream(mwProps), StandardCharsets.UTF_8));
|
||||||
|
props = new Properties();
|
||||||
props.load(reader);
|
props.load(reader);
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
||||||
|
@ -113,11 +125,13 @@ public class MuWireClient {
|
||||||
return !mwProps.exists();
|
return !mwProps.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initMWProps(String nickname, File downloadLocation, File incompleteLocation) throws Exception {
|
public void initMWProps(String nickname, File downloadLocation, File incompleteLocation, File dropBoxLocation) throws Exception {
|
||||||
if (!downloadLocation.exists())
|
if (!downloadLocation.exists())
|
||||||
downloadLocation.mkdirs();
|
downloadLocation.mkdirs();
|
||||||
if (!incompleteLocation.exists())
|
if (!incompleteLocation.exists())
|
||||||
incompleteLocation.mkdirs();
|
incompleteLocation.mkdirs();
|
||||||
|
if (!dropBoxLocation.exists())
|
||||||
|
dropBoxLocation.mkdirs();
|
||||||
|
|
||||||
MuWireSettings settings = new MuWireSettings();
|
MuWireSettings settings = new MuWireSettings();
|
||||||
settings.setNickname(nickname);
|
settings.setNickname(nickname);
|
||||||
|
@ -128,6 +142,13 @@ public class MuWireClient {
|
||||||
PrintWriter pw = new PrintWriter(mwProps, "UTF-8");
|
PrintWriter pw = new PrintWriter(mwProps, "UTF-8");
|
||||||
settings.write(pw);
|
settings.write(pw);
|
||||||
pw.close();
|
pw.close();
|
||||||
|
|
||||||
|
WebUISettings webSettings = new WebUISettings();
|
||||||
|
webSettings.setDropBoxLocation(dropBoxLocation);
|
||||||
|
|
||||||
|
pw = new PrintWriter(webUIProps, "UTF-8");
|
||||||
|
webSettings.write(pw);
|
||||||
|
pw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Core getCore() {
|
public Core getCore() {
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.muwire.webui;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class WebUISettings extends Util {
|
||||||
|
|
||||||
|
private File dropBoxLocation;
|
||||||
|
|
||||||
|
|
||||||
|
public File getDropBoxLocation() {
|
||||||
|
return dropBoxLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDropBoxLocation(File dropBoxLocation) {
|
||||||
|
this.dropBoxLocation = dropBoxLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebUISettings() {
|
||||||
|
this(new Properties());
|
||||||
|
}
|
||||||
|
|
||||||
|
WebUISettings(Properties props) {
|
||||||
|
dropBoxLocation = new File(props.getProperty("dropBoxLocation", System.getProperty("user.home")));
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(Writer out) throws IOException {
|
||||||
|
Properties props = new Properties();
|
||||||
|
|
||||||
|
props.setProperty("dropBoxLocation", dropBoxLocation.getAbsolutePath());
|
||||||
|
|
||||||
|
props.store(out, "This file is UTF-8");
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@
|
||||||
String pagetitle=Util._t("Configuration");
|
String pagetitle=Util._t("Configuration");
|
||||||
String helptext = Util._t("Use this page to change MuWire options.");
|
String helptext = Util._t("Use this page to change MuWire options.");
|
||||||
|
|
||||||
|
WebUISettings webSettings = (WebUISettings) application.getAttribute("webSettings");
|
||||||
Core core = (Core) application.getAttribute("core");
|
Core core = (Core) application.getAttribute("core");
|
||||||
|
|
||||||
String inboundLength = core.getI2pOptions().getProperty("inbound.length");
|
String inboundLength = core.getI2pOptions().getProperty("inbound.length");
|
||||||
|
@ -127,6 +128,13 @@ Exception error = (Exception) application.getAttribute("MWConfigError");
|
||||||
<div class="configuration-section">
|
<div class="configuration-section">
|
||||||
<h3><%=Util._t("Sharing")%></h3>
|
<h3><%=Util._t("Sharing")%></h3>
|
||||||
<table>
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><div class="tooltip"><%=Util._t("Drop Box directory")%>
|
||||||
|
<span class="tooltiptext"><%=Util._t("Where to store files you share with drag and drop")%></span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><p align="right"><input type="text" size="30" name="dropBoxLocation" value="<%= webSettings.getDropBoxLocation().getAbsoluteFile()%>"></p></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><div class="tooltip"><%=Util._t("Share downloaded files")%>
|
<td><div class="tooltip"><%=Util._t("Share downloaded files")%>
|
||||||
<span class="tooltiptext"><%=Util._t("Automatically share files you have downloaded with MuWire")%></span>
|
<span class="tooltiptext"><%=Util._t("Automatically share files you have downloaded with MuWire")%></span>
|
||||||
|
|
|
@ -30,8 +30,10 @@
|
||||||
<%
|
<%
|
||||||
String defaultDownloadLocation = System.getProperty("user.home")+File.separator+"Downloads";
|
String defaultDownloadLocation = System.getProperty("user.home")+File.separator+"Downloads";
|
||||||
String defaultIncompletesLocation = System.getProperty("user.home") + File.separator+"MuWire Incompletes";
|
String defaultIncompletesLocation = System.getProperty("user.home") + File.separator+"MuWire Incompletes";
|
||||||
|
String defaultDropBoxLocation = System.getProperty("user.home") + File.separator + "MuWire DropBox";
|
||||||
session.setAttribute("defaultDownloadLocation",defaultDownloadLocation);
|
session.setAttribute("defaultDownloadLocation",defaultDownloadLocation);
|
||||||
session.setAttribute("defaultIncompletesLocation",defaultIncompletesLocation);
|
session.setAttribute("defaultIncompletesLocation",defaultIncompletesLocation);
|
||||||
|
session.setAttribute("defaultDropBoxLocation",defaultDropBoxLocation);
|
||||||
|
|
||||||
Throwable error = (Throwable) application.getAttribute("MWInitError");
|
Throwable error = (Throwable) application.getAttribute("MWInitError");
|
||||||
%>
|
%>
|
||||||
|
@ -55,6 +57,8 @@
|
||||||
<input type='text' name='download_location' value="${defaultDownloadLocation}"><br/>
|
<input type='text' name='download_location' value="${defaultDownloadLocation}"><br/>
|
||||||
<%=Util._t("Directory for storing incomplete files")%>:<br/>
|
<%=Util._t("Directory for storing incomplete files")%>:<br/>
|
||||||
<input type='text' name='incomplete_location' value="${defaultIncompletesLocation}"><br/>
|
<input type='text' name='incomplete_location' value="${defaultIncompletesLocation}"><br/>
|
||||||
|
<%=Util._t("Drop Box for files you share with MuWire")%>:<br/>
|
||||||
|
<input type='text' name='dropbox_location' value="${defaultDropBoxLocation}"><br/>
|
||||||
<input type="submit" value="<%=Util._t("Submit")%>">
|
<input type="submit" value="<%=Util._t("Submit")%>">
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue