From f8f63757380e1e9cb033d88d9b72654187c28703 Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 13 Nov 2018 17:46:18 +0000 Subject: [PATCH] New install setup wizard Work in progress, run on first install disabled. Language and bw settings should work, other panes todo. --- .../router/web/helpers/ConfigNetHandler.java | 4 +- .../web/helpers/SummaryBarRenderer.java | 6 + .../i2p/router/web/helpers/WizardHandler.java | 102 ++++++++ .../i2p/router/web/helpers/WizardHelper.java | 15 ++ apps/routerconsole/jsp/index.jsp | 30 ++- apps/routerconsole/jsp/welcome.jsp | 244 ++++++++++++++++++ 6 files changed, 394 insertions(+), 7 deletions(-) create mode 100644 apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHandler.java create mode 100644 apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java create mode 100644 apps/routerconsole/jsp/welcome.jsp diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHandler.java index 91d061668..acd2c23b8 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/ConfigNetHandler.java @@ -477,8 +477,8 @@ public class ConfigNetHandler extends FormHandler { _context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART); } - private static final int DEF_BURST_PCT = 10; - private static final int DEF_BURST_TIME = 20; + static final int DEF_BURST_PCT = 10; + static final int DEF_BURST_TIME = 20; /** * @return changed diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/SummaryBarRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/SummaryBarRenderer.java index 5f1a43caa..5e6b8595e 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/SummaryBarRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/SummaryBarRenderer.java @@ -185,6 +185,12 @@ class SummaryBarRenderer { .append(_t("A short guide to the sidebar's network reachability notification")) .append("\">") .append(nbsp(_t("Reachability"))) + .append("\n" + + + "") + .append(nbsp(_t("Setup"))) .append("\n" + " changes = new HashMap(); + boolean updated = updateRates(changes); + if (updated) { + boolean saved = _context.router().saveConfig(changes, null); + if (saved) // needed? + addFormNotice(_t("Configuration saved successfully")); + else + addFormError(_t("Error saving the configuration (applied but not saved) - please see the error logs")); + } + } + } else { + addFormError(_t("Unsupported") + ": " + _action); + } + } + + /** + * Modified from ConfigNetHandler + * @return changed + */ + private boolean updateRates(Map changes) { + boolean updated = false; + boolean bwUpdated = false; + String sharePct = getJettyString("sharePercentage"); + String inboundRate = getJettyString("inboundrate"); + String outboundRate = getJettyString("outboundrate"); + + if (sharePct != null) { + String old = _context.router().getConfigSetting(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE); + if ( (old == null) || (!old.equals(sharePct)) ) { + changes.put(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE, sharePct); + addFormNotice(_t("Updating bandwidth share percentage")); + updated = true; + } + } + if ((inboundRate != null) && (inboundRate.length() > 0) && + !inboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, + Integer.toString(FIFOBandwidthRefiller.DEFAULT_INBOUND_BURST_BANDWIDTH)))) { + try { + float rate = Integer.parseInt(inboundRate) / 1.024f; + float kb = ConfigNetHandler.DEF_BURST_TIME * rate; + changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, Integer.toString(Math.round(rate))); + changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, Integer.toString(Math.round(kb))); + rate -= Math.min(rate * ConfigNetHandler.DEF_BURST_PCT / 100, 50); + changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, Integer.toString(Math.round(rate))); + bwUpdated = true; + } catch (NumberFormatException nfe) { + addFormError(_t("Invalid bandwidth")); + } + } + if ((outboundRate != null) && (outboundRate.length() > 0) && + !outboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, + Integer.toString(FIFOBandwidthRefiller.DEFAULT_OUTBOUND_BURST_BANDWIDTH)))) { + try { + float rate = Integer.parseInt(outboundRate) / 1.024f; + float kb = ConfigNetHandler.DEF_BURST_TIME * rate; + changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, Integer.toString(Math.round(rate))); + changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, Integer.toString(Math.round(kb))); + rate -= Math.min(rate * ConfigNetHandler.DEF_BURST_PCT / 100, 50); + changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, Integer.toString(Math.round(rate))); + bwUpdated = true; + } catch (NumberFormatException nfe) { + addFormError(_t("Invalid bandwidth")); + } + } + if (bwUpdated) { + addFormNotice(_t("Updated bandwidth limits")); + updated = true; + } + return updated; + } +} diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java new file mode 100644 index 000000000..8420e139d --- /dev/null +++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java @@ -0,0 +1,15 @@ +package net.i2p.router.web.helpers; + +import net.i2p.router.web.HelperBase; + +/** + * The new user wizard. + * + * @since 0.9.38 + */ +public class WizardHelper extends HelperBase { + + public void complete() { + _context.router().saveConfig("routerconsole.welcomeWizardComplete", "true"); + } +} diff --git a/apps/routerconsole/jsp/index.jsp b/apps/routerconsole/jsp/index.jsp index b8705c2bb..10010d181 100644 --- a/apps/routerconsole/jsp/index.jsp +++ b/apps/routerconsole/jsp/index.jsp @@ -21,11 +21,31 @@ buf.append(req); if (!req.endsWith("/")) buf.append('/'); - boolean oldHome = net.i2p.I2PAppContext.getGlobalContext().getBooleanProperty("routerconsole.oldHomePage"); - if (oldHome) - buf.append("console"); - else - buf.append("home"); + net.i2p.I2PAppContext ctx = net.i2p.I2PAppContext.getGlobalContext(); + boolean oldHome = ctx.getBooleanProperty("routerconsole.oldHomePage"); + boolean wizRun = ctx.getBooleanProperty("routerconsole.welcomeWizardComplete"); + String firstVersion = ctx.getProperty("router.firstVersion"); + String tgt; + final boolean ENABLE_WIZARD_ON_FIRST_RUN = false; + if (oldHome) { + tgt = "console"; + } else if (ENABLE_WIZARD_ON_FIRST_RUN && (wizRun || firstVersion == null)) { + // wizard already run + tgt = "home"; + } else { + String version = net.i2p.CoreVersion.VERSION; + if (version.equals("0.9.37")) { + // dev builds, force everyone to run it once for testing + tgt = "welcome"; + } else if (version.equals(firstVersion)) { + // first install 38 or later, still on same version + tgt = "welcome"; + } else { + // they already upgraded + tgt = "home"; + } + } + buf.append(tgt); String query = request.getQueryString(); if (query != null) buf.append('?').append(query); diff --git a/apps/routerconsole/jsp/welcome.jsp b/apps/routerconsole/jsp/welcome.jsp new file mode 100644 index 000000000..505680724 --- /dev/null +++ b/apps/routerconsole/jsp/welcome.jsp @@ -0,0 +1,244 @@ +<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%><% + // page ID + final int LAST_PAGE = 7; + String pg = request.getParameter("page"); + int ipg; + if (pg == null) { + ipg = 1; + } else { + try { + ipg = Integer.parseInt(pg); + if (request.getParameter("prev") != null) { + // previous button handling + if (ipg == 6) + ipg = 3; + else + ipg -= 2; + } + if (ipg <= 0 || ipg > LAST_PAGE) { + ipg = 1; + } else if (ipg == 4 && request.getParameter("skipbw") != null) { + ipg++; // skip bw test + } + } catch (NumberFormatException nfe) { + ipg = 1; + } + } + + // detect completion + boolean done = request.getParameter("done") != null || request.getParameter("skip") != null; + if (done) { + // tell wizard helper we're done + String i2pcontextId = request.getParameter("i2p.contextId"); + try { + if (i2pcontextId != null) { + session.setAttribute("i2p.contextId", i2pcontextId); + } else { + i2pcontextId = (String) session.getAttribute("i2p.contextId"); + } + } catch (IllegalStateException ise) {} + wizhelper.setContextId(i2pcontextId); + wizhelper.complete(); + + // redirect to /home + response.setStatus(307); + String req = request.getRequestURL().toString(); + int slash = req.indexOf("/welcome"); + if (slash >= 0) + req = req.substring(0, slash) + "/home"; + else // shouldn't happen + req = "http://127.0.0.1:7657/home"; + response.setHeader("Location", req); + // force commitment + response.getOutputStream().close(); + return; + } +%> + +<%@include file="css.jsi" %> +<%=intl.title("New Install Wizard")%> +<% + if (ipg == 4) { +%> + + +<% + } +%> + +<% + if (ipg == 4) { +%> + +<% + } else { +%> + +<% + } +%> +

<%=intl._t("New Install Wizard")%> <%=ipg%>/<%=LAST_PAGE%>

+
+ +<%@include file="formhandler.jsi" %> +
+ + + +<% + + if (ipg == 1) { + // language selection +%> + + +<%-- needed for CSS: --%>
+<%-- needed for lang setting in css.jsi: --%> +

<%=uihelper._t("Router Console Language")%>

+
+ +
+<% + + } else if (ipg == 2) { + // I2P Philosophy + // license info? +%> +

<%=intl._t("Why I2P?")%>

+

TODO

+<% + + } else if (ipg == 3) { + // Overview of bandwidth test +%> +

<%=intl._t("Bandwidth Test")%>

+

+<%=intl._t("I2P will now test your internet connection to identify the optimal speed settings.")%> +<%=intl._t("Applying these settings will maximize your download speed using the third-party M-Lab service.")%> +<%=intl._t("M-Lab collects and publishes the IP address of the client that conducted the measurement.")%> +<%=intl._t("FIXME! This is necessary to understand and describe experimental results, including to identify which Internet service provider the test was conducted from.")%> +<%=intl._t("Please review the M-Lab privacy policies linked below.")%> +<%=intl._t("If you do not wish to run the M-Lab bandwidth test, you may skip it by clicking the button below.")%> +

+<%=intl._t("M-Lab Privacy Policy")%> +
<%=intl._t("M-Lab Name Server Privacy Policy")%> +

+ + +<% + + } else if (ipg == 4) { + // Bandwidth test in progress (w/ AJAX) +%> +

<%=intl._t("Bandwidth Test in Progress")%>

+

TODO

+<% + + } else if (ipg == 5) { + // Bandwidth test results + // and/or manual bw entry? +%> + + +

<%=intl._t("Bandwidth Test Results")%>

+ + +
+Test results go here +
+

<%=intl._t("Bandwidth Configuration")%>

+ + + + +<%-- display burst, set standard, handler will fix up --%> + + + + + +
+<%=intl._t("I2P will work best if you configure your rates to match the speed of your internet connection.")%> +
" > +<%=intl._t("KBps In")%> +()
" > +<%=intl._t("KBps Out")%> +()
<%=intl._t("Share")%>() +
+<% int share = Math.round(nethelper.getShareBandwidth() * 1.024f); + if (share < 12) { + out.print(""); + out.print(intl._t("NOTE")); + out.print(": "); + out.print(intl._t("You have configured I2P to share only {0} KBps.", share)); + out.print("\n"); + + out.print(intl._t("I2P requires at least 12KBps to enable sharing. ")); + out.print(intl._t("Please enable sharing (participating in tunnels) by configuring more bandwidth. ")); + out.print(intl._t("It improves your anonymity by creating cover traffic, and helps the network.")); + } else { + out.print(intl._t("You have configured I2P to share {0} KBps.", share)); + out.print("\n"); + + out.print(intl._t("The higher the share bandwidth the more you improve your anonymity and help the network.")); + } +%>
+<% + + } else if (ipg == 6) { + // Browser setup +%> +

<%=intl._t("Browser Setup")%>

+

TODO

+<% + + } else if (ipg == LAST_PAGE) { + // Done +%> +

<%=intl._t("Finished")%>

+

TODO

+<% + + } else { +%> +

unknown wizard page

+<% + } +%> +
+
+<% + if (ipg != 1) { +%> +" > +<% + } + if (ipg != LAST_PAGE) { +%> +" > +<% + if (ipg == 3) { +%> +" > +<% + } else if (ipg == 4) { +%> +" > +<% + } +%> +" > +<% + } else { +%> +" > +<% + } +%> +
+ +