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" %> + + +
+Welcome to MuWire! Please select a nickname and download locations
+