diff --git a/plug/build.gradle b/plug/build.gradle index 7afd1515..8047e22f 100644 --- a/plug/build.gradle +++ b/plug/build.gradle @@ -133,6 +133,6 @@ task sign { webappConfig.dependsOn pluginDir clientsConfig.dependsOn webappConfig pack.dependsOn webappConfig -pluginZip.dependsOn(webappConfig,pluginConfig,clientsConfig,pack) +pluginZip.dependsOn(webappConfig,pluginConfig,pack) sign.dependsOn pluginZip assemble.dependsOn sign diff --git a/webui/build.gradle b/webui/build.gradle index b8987cf0..1d7fc6f8 100644 --- a/webui/build.gradle +++ b/webui/build.gradle @@ -50,6 +50,7 @@ task generateWebXML { def templateText = template.text def jasper = new File("$buildDir/tmp_jsp/web.xml.jasper") templateText = templateText.replaceAll("__JASPER__", jasper.text) + templateText = templateText.replaceAll("__VERSION__", project.version) def webXml = new File("$buildDir/tmp_jsp/web.xml") webXml.text = templateText } diff --git a/webui/src/main/java/com/muwire/webui/MuWireClient.java b/webui/src/main/java/com/muwire/webui/MuWireClient.java index 6c34ef53..79a4dc54 100644 --- a/webui/src/main/java/com/muwire/webui/MuWireClient.java +++ b/webui/src/main/java/com/muwire/webui/MuWireClient.java @@ -16,79 +16,23 @@ import net.i2p.app.ClientAppState; import net.i2p.router.RouterContext; import net.i2p.router.app.RouterApp; -public class MuWireClient implements RouterApp { +public class MuWireClient { private final RouterContext ctx; - private final ClientAppManager mgr; private final String version; private final String home; private final File mwProps; - private ClientAppState state; - private volatile Core core; - public MuWireClient(RouterContext ctx, ClientAppManager mgr, String[]args) { + public MuWireClient(RouterContext ctx, String home, String version) { this.ctx = ctx; - this.mgr = mgr; - String version = null; - String home = null; - for (String arg : args) { - String [] split = arg.split("="); - if (split[0].equals("version")) - version = split[1]; - else if (split[0].equals("home")) - home = split[1]; - } this.version = version; this.home = home; this.mwProps = new File(home, "MuWire.properties"); - this.state = ClientAppState.INITIALIZED; - mgr.register(this); } - @Override - public void startup() throws Throwable { - changeState(ClientAppState.STARTING, null, null); - try { - start(); - changeState(ClientAppState.RUNNING, null, null); - } catch (Exception bad) { - changeState(ClientAppState.START_FAILED, "Failed to start", bad); - stop(); - } - } - - @Override - public void shutdown(String[] args) throws Throwable { - if (state == ClientAppState.STOPPED) - return; - changeState(ClientAppState.STOPPING,null,null); - stop(); - changeState(ClientAppState.STOPPED, null, null); - } - - private synchronized void changeState(ClientAppState state, String msg, Exception e) { - this.state = state; - mgr.notify(this, state, msg, e); - } - - @Override - public synchronized ClientAppState getState() { - return state; - } - - @Override - public String getName() { - return "MuWire"; - } - - @Override - public String getDisplayName() { - return "MuWire"; - } - - private void start() throws Throwable { + public void start() throws Throwable { if (needsMWInit()) return; @@ -102,7 +46,7 @@ public class MuWireClient implements RouterApp { core.startServices(); } - private void stop() throws Throwable { + public void stop() throws Throwable { Core core = this.core; if (core == null) return; diff --git a/webui/src/main/java/com/muwire/webui/MuWireServlet.java b/webui/src/main/java/com/muwire/webui/MuWireServlet.java index f390e93e..ffc07c33 100644 --- a/webui/src/main/java/com/muwire/webui/MuWireServlet.java +++ b/webui/src/main/java/com/muwire/webui/MuWireServlet.java @@ -1,14 +1,56 @@ package com.muwire.webui; +import java.io.File; +import java.io.IOException; + import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.i2p.I2PAppContext; +import net.i2p.router.RouterContext; public class MuWireServlet extends HttpServlet { + private volatile MuWireClient client; + @Override public void init(ServletConfig config) throws ServletException { super.init(config); + RouterContext ctx = (RouterContext) I2PAppContext.getGlobalContext(); + + String home = ctx.getConfigDir()+File.separator+"plugins"+File.separator+"MuWire"; + String version = config.getInitParameter("version"); + + client = new MuWireClient(ctx, home, version); + try { + client.start(); + } catch (Throwable bad) { + throw new ServletException(bad); + } + config.getServletContext().setAttribute("mwClient", client); } + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + req.getSession().setAttribute("mwClient", client); + if (client.needsMWInit()) { + resp.sendRedirect("/MuWire/MuWire.jsp"); + } else { + resp.setContentType("text/html"); + resp.getWriter().println("MW is initialized +<%@ page import="java.io.File" %> + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + + + MuWire + + + <% + String defaultDownloadLocation = System.getProperty("user.home")+File.separator+"Downloads"; + String defaultIncompletesLocation = System.getProperty("user.home") + File.separator+"MuWire Incompletes"; + session.setAttribute("defaultDownloadLocation",defaultDownloadLocation); + session.setAttribute("defaultIncompletesLocation",defaultIncompletesLocation); + %> + +

Welcome to MuWire! Please select a nickname and download locations

+
+ Nickname: +
+ Directory for saving downloaded files: +
+ Directory for storing incomplete files: +
+ + + diff --git a/webui/src/main/webapp/index.html b/webui/src/main/webapp/index.html deleted file mode 100644 index 95b7b90a..00000000 --- a/webui/src/main/webapp/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/webui/src/main/webapp/index.jsp b/webui/src/main/webapp/index.jsp deleted file mode 100644 index b9d0d7d2..00000000 --- a/webui/src/main/webapp/index.jsp +++ /dev/null @@ -1,38 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> -<%@ page import="java.io.File" %> - -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> - - - - MuWire - - - - - - <% - String defaultDownloadLocation = System.getProperty("user.home")+File.separator+"Downloads"; - String defaultIncompletesLocation = System.getProperty("user.home") + File.separator+"MuWire Incompletes"; - session.setAttribute("defaultDownloadLocation",defaultDownloadLocation); - session.setAttribute("defaultIncompletesLocation",defaultIncompletesLocation); - %> - - -

Welcome to MuWire! Please select a nickname and download locations

- - Nickname: -
- Directory for saving downloaded files: -
- Directory for storing incomplete files: -
- -
- -

MW doesn't need initing

-
- - diff --git a/webui/src/main/webapp/init.jsp b/webui/src/main/webapp/init.jsp index d42ee558..325d9360 100644 --- a/webui/src/main/webapp/init.jsp +++ b/webui/src/main/webapp/init.jsp @@ -1,23 +1,19 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.File" %> - -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page import="com.muwire.webui.MuWireClient" %> - - <% String nickname = request.getParameter("nickname"); String downloadLocation = request.getParameter("download_location"); String incompleteLocation = request.getParameter("incomplete_location"); - session.setAttribute("downloadLocation", new File(downloadLocation)); - session.setAttribute("incompleteLocation", new File(incompleteLocation)); - session.setAttribute("nickname",nickname); + MuWireClient client = (MuWireClient) session.getAttribute("mwClient"); + client.initMWProps(nickname, new File(downloadLocation), new File(incompleteLocation)); + client.start(); %> - - + diff --git a/webui/templates/web.xml.template b/webui/templates/web.xml.template index 3da6cd49..3d2d4b21 100644 --- a/webui/templates/web.xml.template +++ b/webui/templates/web.xml.template @@ -9,11 +9,16 @@ com.muwire.webui.MuWireServlet com.muwire.webui.MuWireServlet + 1 + + version + __VERSION__ + com.muwire.webui.MuWireServlet - / + /index.jsp