From a0499451a5449c76f083b43336431b7d043b425e Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Tue, 31 Aug 2004 21:25:23 +0000
Subject: [PATCH] let windows users install/remove the service through the
 /configservice.jsp page

---
 .../i2p/router/web/ConfigServiceHandler.java  | 26 +++++++++++++++++--
 apps/routerconsole/jsp/configservice.jsp      | 15 +++++------
 readme.html                                   | 10 ++++---
 3 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java
index 6bfacda4b2..0d39c0465a 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java
@@ -1,8 +1,9 @@
 package net.i2p.router.web;
 
+import java.io.IOException;
+
 import net.i2p.router.ClientTunnelSettings;
 import net.i2p.router.Router;
-
 import net.i2p.apps.systray.SysTray;
 import org.tanukisoftware.wrapper.WrapperManager;
 
@@ -39,6 +40,10 @@ public class ConfigServiceHandler extends FormHandler {
         } else if ("Hard restart".equals(_action)) {
             _context.router().shutdown(Router.EXIT_HARD_RESTART);
             addFormNotice("Hard restart requested");
+        } else if ("Run I2P on startup".equals(_action)) {
+            installService();
+        } else if ("Don't run I2P on startup".equals(_action)) {
+            uninstallService();
         } else if ("Dump threads".equals(_action)) {
             try {
                 WrapperManager.requestThreadDump();
@@ -74,4 +79,21 @@ public class ConfigServiceHandler extends FormHandler {
             addFormNotice("Blah blah blah.  whatever.  I'm not going to " + _action);
         }
     }
-}
+    
+    private void installService() {
+        try { 
+            Runtime.getRuntime().exec("install_i2p_service_winnt.bat");
+            addFormNotice("Service installed");
+        } catch (IOException ioe) {
+            addFormError("Warning: unable to install the service - " + ioe.getMessage());
+        }
+    }
+    private void uninstallService() {
+        try { 
+            Runtime.getRuntime().exec("uninstall_i2p_service_winnt.bat");
+            addFormNotice("Service removed");
+        } catch (IOException ioe) {
+            addFormError("Warning: unable to remove the service - " + ioe.getMessage());
+        }
+    }
+}
\ No newline at end of file
diff --git a/apps/routerconsole/jsp/configservice.jsp b/apps/routerconsole/jsp/configservice.jsp
index c701abdab1..338e669bad 100644
--- a/apps/routerconsole/jsp/configservice.jsp
+++ b/apps/routerconsole/jsp/configservice.jsp
@@ -39,18 +39,15 @@
  If you are on windows, you can either enable or disable that icon here. <br />
  <input type="submit" name="action" value="Show systray icon" />
  <input type="submit" name="action" value="Hide systray icon" />
- <!--
+ <% if ( (System.getProperty("os.name") != null) && (System.getProperty("os.name").startsWith("Win")) ) { %>
  <h4>Run on startup</h4>
- On the windows platform, you can control whether I2P is run on startup or not by
- selecting one of the following options - I2P will install (or remove) a service 
- accordingly.  On *nix machines, you need root permissions to add a script
- to be run on startup (we hope you know better than to run I2P as root ;).  To 
- have I2P run (or not run) at startup on *nix machines, please run 
- <code>install_i2p_service_unix</code> or <code>install_i2p_service_unix</code>
- as root.<br />
+ You can control whether I2P is run on startup or not by selecting one of the 
+ following options - I2P will install (or remove) a service accordingly.  You can
+ also run the <code>install_i2p_service_winnt.bat</code> (or 
+ <code>uninstall_i2p_service_winnt.bat</code>) from the command line, if you prefer.<br />
  <input type="submit" name="action" value="Run I2P on startup" />
  <input type="submit" name="action" value="Don't run I2P on startup" />
- -->
+ <% } %>
  <h4>Debugging</h4>
  At times, it may be helpful to debug I2P by getting a thread dump.  To do so, 
  please select the following option and review the thread dumped to 
diff --git a/readme.html b/readme.html
index 9105059672..c4bbb7e31a 100644
--- a/readme.html
+++ b/readme.html
@@ -21,10 +21,12 @@ linked together).</p>
 
 <p>With the I2P install we've bundled some scripts and code (from the cool folks at 
 <a href="http://wrapper.tanukisoftware.org/doc/english/">tanukisoftware</a>) to let you
-run I2P as a service on windows machines (a daemon, for you *nix geeks).  To install it, 
-just run install_i2p_service_winnt.bat (or install_i2p_service_unix, as root).  To uninstall
-it, run uninstall_i2p_service_winnt.bat (or uninstall_i2p_service_unix, as root).  To uninstall
-I2P altogether, simply wipe the I2P installation directory.</p>
+run I2P as a service on windows machines (a daemon, for you *nix geeks).  Windows users can 
+add or remove the I2P service on the <a href="/configservice.jsp">service control page</a>, or
+through the install_i2p_service_winnt.bat and uninstall_i2p_service_winnt.bat scripts.  *nix 
+users can use the install_i2p_service_unix and uninstall_i2p_service_unix scripts included, but
+they must be run as root.  To uninstall I2P altogether, simply wipe the I2P installation 
+directory.</p>
 
 <h2>What next?</h2>
 
-- 
GitLab