From c31cb0c057e046ad81acba41abb853ba839d9b4e Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Sat, 21 Jan 2012 05:30:23 +0000
Subject: [PATCH] Initial beginnings of a tunnel creation wizard as per ticket
 #502

---
 .../src/net/i2p/i2ptunnel/web/WizardBean.java | 24 +++++
 apps/i2ptunnel/jsp/web.xml                    |  5 ++
 apps/i2ptunnel/jsp/wizard.jsp                 | 89 +++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/WizardBean.java
 create mode 100644 apps/i2ptunnel/jsp/wizard.jsp

diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/WizardBean.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/WizardBean.java
new file mode 100644
index 0000000000..afac4235e4
--- /dev/null
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/WizardBean.java
@@ -0,0 +1,24 @@
+package net.i2p.i2ptunnel.web;
+
+/**
+ * A temporary data holder for the wizard pages
+ *
+ * Warning - This class is not part of the i2ptunnel API, and at some point
+ * it will be moved from the jar to the war.
+ * Usage by classes outside of i2ptunnel.war is deprecated.
+ */
+public class WizardBean extends IndexBean {
+    private boolean _isClient;
+    public WizardBean() { super(); }
+
+    /**
+     * Whether the tunnel being set up is a client tunnel or not.
+     *
+     */
+    public void setIsClient(String isClient) { 
+        _isClient = Boolean.valueOf(isClient);   
+    }
+    public boolean getIsClient() {
+        return _isClient;
+    }
+}
diff --git a/apps/i2ptunnel/jsp/web.xml b/apps/i2ptunnel/jsp/web.xml
index d333d29367..d8d51c8239 100644
--- a/apps/i2ptunnel/jsp/web.xml
+++ b/apps/i2ptunnel/jsp/web.xml
@@ -18,6 +18,11 @@
         <url-pattern>/edit</url-pattern>
     </servlet-mapping>
 
+    <servlet-mapping>
+        <servlet-name>net.i2p.i2ptunnel.jsp.wizard_jsp</servlet-name>
+        <url-pattern>/wizard</url-pattern>
+    </servlet-mapping>
+
     <session-config>
         <session-timeout>
             30
diff --git a/apps/i2ptunnel/jsp/wizard.jsp b/apps/i2ptunnel/jsp/wizard.jsp
new file mode 100644
index 0000000000..5f77e6ae0b
--- /dev/null
+++ b/apps/i2ptunnel/jsp/wizard.jsp
@@ -0,0 +1,89 @@
+<%
+    // NOTE: Do the header carefully so there is no whitespace before the <?xml... line
+
+%><%@page pageEncoding="UTF-8"
+%><%@page contentType="text/html" import="net.i2p.i2ptunnel.web.WizardBean"
+%><?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<jsp:useBean class="net.i2p.i2ptunnel.web.WizardBean" id="wizardBean" scope="request" />
+<jsp:useBean class="net.i2p.i2ptunnel.web.Messages" id="intl" scope="request" />
+<% String pageStr = request.getParameter("page");
+   int curPage = 1;
+   if (pageStr != null) {
+     try {
+       curPage = Integer.parseInt(pageStr);
+       if (curPage > 7 || curPage <= 0) {
+         curPage = 1;
+       }
+     } catch (NumberFormatException nfe) {
+       curPage = 1;
+     }
+   }
+%>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+    <title><%=intl._("I2P Tunnel Manager - Tunnel Creation Wizard")%></title>
+    
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
+    <link href="/themes/console/images/favicon.ico" type="image/x-icon" rel="shortcut icon" />
+    
+    <% if (wizardBean.allowCSS()) {
+  %><link href="<%=wizardBean.getTheme()%>default.css" rel="stylesheet" type="text/css" /> 
+    <link href="<%=wizardBean.getTheme()%>i2ptunnel.css" rel="stylesheet" type="text/css" />
+    <% }
+  %>
+</head>
+<body id="tunnelWizardPage">
+    <div id="pageHeader">
+    </div>
+
+    <form method="post" action="wizard">
+
+        <div id="wizardPanel" class="panel">
+            <div class="header">
+                <%
+                if (curPage == 1) {
+                  %><h4><%=intl._("Page 1")%></h4><%
+                } %>
+                <input type="hidden" name="page" value="<%=request.getParameter("page")%>" />
+                <input type="hidden" name="nonce" value="<%=wizardBean.getNextNonce()%>" />
+            </div>
+
+            <div class="separator">
+                <hr />
+            </div>
+
+            <%
+            if (curPage == 1) {
+            %><div id="typeField" class="rowItem">
+                <label for="type">
+                    <%=intl._("Tunnel Type")%>:
+                </label>
+                <label><%=intl._("Server Tunnel")%></label>
+                <input value="0" type="radio" id="baseType" name="isClient" class="tickbox" />
+                <label><%=intl._("Client Tunnel")%></label>
+                <input value="1" type="radio" id="baseType" name="isClient" class="tickbox" />
+            </div><%
+            } else {
+            %><input type="hidden" name="isClient" value="<%=wizardBean.getIsClient()%>" /><%
+            } %>
+        </div>
+
+        <div id="globalOperationsPanel" class="panel">
+            <div class="header"></div>
+            <div class="footer">
+                <div class=toolbox">
+                    <button id="controlCancel" class="control" type="submit" name="action" value="" title="Cancel"><%=intl._("Cancel")%></button>
+                    <button id="controlNext" accesskey="N" class="control" type="submit" name="action" value="Next page" title="Next Page"><%=intl._("Next")%>(<span class="accessKey">N</span>)</button>
+                    <button id="controlFinish" accesskey="F" class="control" type="submit" name="action" value="Finish wizard" title="Finish Wizard"><%=intl._("Finish")%>(<span class="accessKey">F</span>)</button>
+                </div>
+            </div>
+        </div>
+
+    </form>
+
+    <div id="pageFooter">
+    </div>
+</body>
+</html>
-- 
GitLab