display errors on invalid config input

This commit is contained in:
Zlatin Balevsky
2019-12-15 15:06:18 +00:00
parent e595fa97e8
commit 4ab4785539
2 changed files with 26 additions and 10 deletions

View File

@ -1,10 +1,13 @@
package com.muwire.webui;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Enumeration;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -15,20 +18,26 @@ import com.muwire.core.Core;
public class ConfigurationServlet extends HttpServlet {
private Core core;
private ServletContext context;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
clearAllBooleans();
Enumeration<String> patameterNames = req.getParameterNames();
while(patameterNames.hasMoreElements()) {
String name = patameterNames.nextElement();
String value = req.getParameter(name);
update(name, value);
try {
clearAllBooleans();
Enumeration<String> patameterNames = req.getParameterNames();
while(patameterNames.hasMoreElements()) {
String name = patameterNames.nextElement();
String value = req.getParameter(name);
update(name, value);
}
core.saveMuSettings();
core.saveI2PSettings();
context.setAttribute("MWConfigError", null);
} catch (Exception e) {
context.setAttribute("MWConfigError", e);
}
core.saveMuSettings();
core.saveI2PSettings();
resp.sendRedirect("/MuWire/ConfigurationPage");
}
@ -70,6 +79,7 @@ public class ConfigurationServlet extends HttpServlet {
@Override
public void init(ServletConfig config) throws ServletException {
context = config.getServletContext();
core = (Core) config.getServletContext().getAttribute("core");
}

View File

@ -18,6 +18,8 @@ String inboundLength = core.getI2pOptions().getProperty("inbound.length");
String inboundQuantity = core.getI2pOptions().getProperty("inbound.quantity");
String outboundLength = core.getI2pOptions().getProperty("outbound.length");
String outboundQuantity = core.getI2pOptions().getProperty("outbound.quantity");
Exception error = (Exception) application.getAttribute("MWConfigError");
%>
<html>
@ -31,6 +33,10 @@ String outboundQuantity = core.getI2pOptions().getProperty("outbound.quantity");
<%@include file="sidebar.jsi"%>
</aside>
<section class="main foldermain">
<% if (error != null) { %>
<div class="warning"><%=error%></div>
<% } %>
<form action="/MuWire/Configuration" method="post">
<div class="configuration-section">
<h3><%=Util._t("Search")%></h3>