From b1c367777d688c78cf8bdc3f1ed142ee724b062d Mon Sep 17 00:00:00 2001
From: zzz <zzz@i2pmail.org>
Date: Thu, 16 Sep 2021 10:50:57 -0400
Subject: [PATCH] Console: Add constants for wizard page numbers

to make it easier to add/remove/reorder pages later
---
 .../i2p/router/web/helpers/WizardHandler.java | 12 +++--
 .../i2p/router/web/helpers/WizardHelper.java  |  8 ++++
 apps/routerconsole/jsp/welcome.jsp            | 48 ++++++++++++-------
 3 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHandler.java
index 3651248999..af2a1e8e68 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHandler.java
@@ -41,13 +41,19 @@ public class WizardHandler extends FormHandler {
             // note that the page is the page we are on now,
             // which is the page after the one the settings were on.
             String page = getJettyString("page");
+            int ipage = 1;
+            if (page != null) {
+                try {
+                    ipage = Integer.parseInt(page);
+                } catch (NumberFormatException nfe) {}
+            }
             if (getJettyString("lang") != null) {
                 // Saved in CSSHelper, assume success
                 addFormNoticeNoEscape(_t("Console language saved."));
             }
-            if ("3".equals(page)) {
+            if (ipage == WizardHelper.PAGE_TEST) {
                 startNDT();
-            } else if ("4".equals(page)) {
+            } else if (ipage == WizardHelper.PAGE_RESULTS) {
                 synchronized (_helper) {
                     if (_helper.isNDTSuccessful()) {
                         addFormNotice(_t("Bandwidth test completed successfully"));
@@ -60,7 +66,7 @@ public class WizardHandler extends FormHandler {
                         addFormError(_t("Bandwidth test did not complete"));
                     }
                 }
-            } else if ("5".equals(page)) {
+            } else if (ipage == WizardHelper.PAGE_BROWSER) {
                 Map<String, String> changes = new HashMap<String, String>();
                 boolean updated = updateRates(changes);
                 if (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
index aa24388279..b3fcfef6ea 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/WizardHelper.java
@@ -21,6 +21,14 @@ public class WizardHelper extends HelperBase {
     public static final String PROP_COMPLETE = "routerconsole.welcomeWizardComplete";
     // scale bw test results by this for limiter settings
     public static final float BW_SCALE = 0.75f;
+    // pages
+    public static final int PAGE_LANG = 1;
+    public static final int PAGE_CHECK = 2;
+    public static final int PAGE_TEST = 3;
+    public static final int PAGE_RESULTS = 4;
+    public static final int PAGE_BROWSER = 5;
+    public static final int PAGE_DONE = 6;
+
     // KBps
     private static final float MIN_DOWN_BW = 32.0f;
     private static final float MIN_UP_BW = 12.0f;
diff --git a/apps/routerconsole/jsp/welcome.jsp b/apps/routerconsole/jsp/welcome.jsp
index 00a864a07a..988b351052 100644
--- a/apps/routerconsole/jsp/welcome.jsp
+++ b/apps/routerconsole/jsp/welcome.jsp
@@ -4,7 +4,21 @@
     // The MLabHelper singleton will prevent multiple simultaneous tests, even across sessions.
 
     // page ID
-    final int LAST_PAGE = 6;
+    // 1: Select language
+    // 2: Check internet connection
+    // 3: Bandwidth test in progress
+    // 4: Bandwidth test results
+    // 5: Browser setup
+    // 6: Done
+    final int PAGE_LANG = net.i2p.router.web.helpers.WizardHelper.PAGE_LANG;
+    final int PAGE_CHECK = net.i2p.router.web.helpers.WizardHelper.PAGE_CHECK;
+    final int PAGE_TEST = net.i2p.router.web.helpers.WizardHelper.PAGE_TEST;
+    final int PAGE_RESULTS = net.i2p.router.web.helpers.WizardHelper.PAGE_RESULTS;
+    final int PAGE_BROWSER = net.i2p.router.web.helpers.WizardHelper.PAGE_BROWSER;
+    final int PAGE_DONE = net.i2p.router.web.helpers.WizardHelper.PAGE_DONE;
+
+    final int FIRST_PAGE = PAGE_LANG;
+    final int LAST_PAGE = PAGE_DONE;
     String pg = request.getParameter("page");
     int ipg;
     if (pg == null) {
@@ -14,18 +28,18 @@
             ipg = Integer.parseInt(pg);
             if (request.getParameter("prev") != null) {
                 // previous button handling
-                if (ipg == 5)
-                    ipg = 2;
+                if (ipg == PAGE_BROWSER)
+                    ipg = PAGE_CHECK;
                 else
                     ipg -= 2;
             }
-            if (ipg <= 0 || ipg > LAST_PAGE) {
-                ipg = 1;
-            } else if (ipg == 3 && request.getParameter("skipbw") != null) {
+            if (ipg < FIRST_PAGE || ipg > LAST_PAGE) {
+                ipg = FIRST_PAGE;
+            } else if (ipg == PAGE_TEST && request.getParameter("skipbw") != null) {
                 ipg++;  // skip bw test
             }
         } catch (NumberFormatException nfe) {
-            ipg = 1;
+            ipg = FIRST_PAGE;
         }
     }
 
@@ -64,7 +78,7 @@
 <%=intl.title("New Install Wizard")%>
 <%
     wizhelper.setContextId(i2pcontextId);
-    if (ipg == 3) {
+    if (ipg == PAGE_TEST) {
 %>
 <script src="/js/welcomeajax.js?<%=net.i2p.CoreVersion.VERSION%>" type="text/javascript"></script>
 <script nonce="<%=cspNonce%>" type="text/javascript">
@@ -85,7 +99,7 @@
 /* @license-end */
 </script>
 <%
-    }  // ipg == 3
+    }  // ipg == PAGE_TEST
 %>
 </head><body>
 <div id="wizard" class="overlay">
@@ -104,7 +118,7 @@
 <input type="hidden" name="action" value="blah" >
 <input type="hidden" name="page" value="<%=(ipg + 1)%>" >
 <%
-    if (ipg == 1) {
+    if (ipg == PAGE_LANG) {
         // language selection
 %>
 <jsp:useBean class="net.i2p.router.web.helpers.ConfigUIHelper" id="uihelper" scope="request" />
@@ -140,7 +154,7 @@
 </div>
 <%
 
-    } else if (ipg == 2) {
+    } else if (ipg == PAGE_CHECK) {
         // Overview of bandwidth test
 %>
 <div class="clickableProgression">
@@ -176,7 +190,7 @@
 </div>
 <%
 
-    } else if (ipg == 3) {
+    } else if (ipg == PAGE_TEST) {
         // Bandwidth test in progress (w/ AJAX)
 %>
 <div class="clickableProgression">
@@ -209,7 +223,7 @@
 </div>
 <%
 
-    } else if (ipg == 4) {
+    } else if (ipg == PAGE_RESULTS) {
         // Bandwidth test results
         // and/or manual bw entry?
 %>
@@ -298,7 +312,7 @@
 </div>
 <%
 
-    } else if (ipg == 5) {
+    } else if (ipg == PAGE_BROWSER) {
         // Browser setup
 %>
 <div class="clickableProgression">
@@ -379,7 +393,7 @@
 <div class="wizardbuttons wizard">
 <table class="configtable wizard"><tr class="wizard"><td class="optionsave wizard">
 <%
-    if (ipg != 1) {
+    if (ipg != FIRST_PAGE) {
 %>
 <input type="submit" class="back wizardbutton" name="prev" value="<%=intl._t("Previous")%>" >
 <%
@@ -388,11 +402,11 @@
 %>
 <input type="submit" class="cancel wizardbutton" name="skip" value="<%=intl._t("Skip Setup")%>" >
 <%
-        if (ipg == 2) {
+        if (ipg == PAGE_CHECK) {
 %>
 <input type="submit" class="cancel wizardbutton" name="skipbw" value="<%=intl._t("Skip Bandwidth Test")%>" >
 <%
-        } else if (ipg == 3) {
+        } else if (ipg == PAGE_TEST) {
 %>
 <input type="submit" class="cancel wizardbutton" name="cancelbw" value="<%=intl._t("Cancel Bandwidth Test")%>" >
 <%
-- 
GitLab