From 7701693d3736a7761a2bfc10a0ed606dfd98d2ae Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 17 Feb 2010 18:12:46 +0000
Subject: [PATCH]     * Plugins:       - Fix plugin start button       - Change
 signer prop to match docs       - Tweaks

---
 .../i2p/router/web/ConfigClientsHandler.java  | 31 +++++++++++++++----
 .../i2p/router/web/ConfigClientsHelper.java   | 14 ++++++---
 .../src/net/i2p/router/web/PluginStarter.java |  6 ++--
 .../i2p/router/web/PluginUpdateHandler.java   | 20 ++++++------
 4 files changed, 47 insertions(+), 24 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java
index 1fd1191265..26ca7aefbc 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java
@@ -51,10 +51,15 @@ public class ConfigClientsHandler extends FormHandler {
             try {
                 appnum = Integer.parseInt(app);
             } catch (NumberFormatException nfe) {}
-            if (appnum >= 0)
+            if (appnum >= 0) {
                 startClient(appnum);
-            else
-                startWebApp(app);
+            } else {
+                List<String> plugins = PluginStarter.getPlugins();
+                if (plugins.contains(app))
+                    startPlugin(app);
+                else
+                    startWebApp(app);
+            }
             return;
         }
 
@@ -117,10 +122,15 @@ public class ConfigClientsHandler extends FormHandler {
             try {
                 appnum = Integer.parseInt(app);
             } catch (NumberFormatException nfe) {}
-            if (appnum >= 0)
+            if (appnum >= 0) {
                 startClient(appnum);
-            else
-                startWebApp(app);
+            } else {
+                List<String> plugins = PluginStarter.getPlugins();
+                if (plugins.contains(app))
+                    startPlugin(app);
+                else
+                    startWebApp(app);
+            }
         } else {
             addFormError(_("Unsupported") + ' ' + _action + '.');
         }
@@ -315,4 +325,13 @@ public class ConfigClientsHandler extends FormHandler {
         } catch (InterruptedException ie) {}
     }
 
+    private void startPlugin(String app) {
+        try {
+            PluginStarter.startPlugin(_context, app);
+            addFormNotice(_("Started plugin {0}", app));
+        } catch (Throwable e) {
+            addFormError(_("Error starting plugin {0}", app) + ": " + e);
+            _log.error("Error starting plugin " + app,  e);
+        }
+    }
 }
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java
index a096df5f08..d66e37e23f 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java
@@ -86,16 +86,20 @@ public class ConfigClientsHelper extends HelperBase {
                 String app = name.substring(PluginStarter.PREFIX.length(), name.lastIndexOf(PluginStarter.ENABLED));
                 String val = props.getProperty(name);
                 Properties appProps = PluginStarter.pluginProperties(_context, app);
+                if (appProps.size() <= 0)
+                    continue;
                 StringBuilder desc = new StringBuilder(256);
                 desc.append("<table border=\"0\">")
                     .append("<tr><td><b>").append(_("Version")).append("<td>").append(stripHTML(appProps, "version"))
                     .append("<tr><td><b>")
                     .append(_("Signed by")).append("<td>");
-                String s = stripHTML(appProps, "keyName");
-                if (s.indexOf("@") > 0)
-                    desc.append("<a href=\"mailto:").append(s).append("\">").append(s).append("</a>");
-                else
-                    desc.append(s);
+                String s = stripHTML(appProps, "signer");
+                if (s != null) {
+                    if (s.indexOf("@") > 0)
+                        desc.append("<a href=\"mailto:").append(s).append("\">").append(s).append("</a>");
+                    else
+                        desc.append(s);
+                }
                 s = stripHTML(appProps, "date");
                 if (s != null) {
                     long ms = 0;
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
index 76920fc68b..154b9c1eb4 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java
@@ -301,9 +301,9 @@ public class PluginStarter implements Runnable {
         for (String name : names) {
             Properties props = pluginProperties(ctx, name);
             String pubkey = props.getProperty("key");
-            String keyName = props.getProperty("keyName");
-            if (pubkey != null && keyName != null && pubkey.length() == 172 && keyName.length() > 0)
-                rv.put(pubkey, keyName);
+            String signer = props.getProperty("signer");
+            if (pubkey != null && signer != null && pubkey.length() == 172 && signer.length() > 0)
+                rv.put(pubkey, signer);
         }
         return rv;
     }
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java
index fb54235e4f..1a4f14c674 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java
@@ -174,11 +174,11 @@ public class PluginUpdateHandler extends UpdateHandler {
 
             // ok, now we check sigs and deal with a bad sig
             String pubkey = props.getProperty("key");
-            String keyName = props.getProperty("keyName");
-            if (pubkey == null || keyName == null || pubkey.length() != 172 || keyName.length() <= 0) {
+            String signer = props.getProperty("signer");
+            if (pubkey == null || signer == null || pubkey.length() != 172 || signer.length() <= 0) {
                 f.delete();
                 to.delete();
-                //updateStatus("<b>" + "Plugin contains an invalid key" + ' ' + pubkey + ' ' + keyName + "</b>");
+                //updateStatus("<b>" + "Plugin contains an invalid key" + ' ' + pubkey + ' ' + signer + "</b>");
                 updateStatus("<b>" + _("Plugin from {0} contains an invalid key", url) + "</b>");
                 return;
             }
@@ -193,9 +193,9 @@ public class PluginUpdateHandler extends UpdateHandler {
 
             if (up.haveKey(pubkey)) {
                 // the key is already in the TrustedUpdate keyring
-                // verify the sig and verify that it is signed by the keyName in the plugin.config file
+                // verify the sig and verify that it is signed by the signer in the plugin.config file
                 String signingKeyName = up.verifyAndGetSigner(f);
-                if (!keyName.equals(signingKeyName)) {
+                if (!signer.equals(signingKeyName)) {
                     f.delete();
                     to.delete();
                     updateStatus("<b>" + _("Plugin signature verification of {0} failed", url) + "</b>");
@@ -203,7 +203,7 @@ public class PluginUpdateHandler extends UpdateHandler {
                 }
             } else {
                 // add to keyring...
-                if(!up.addKey(pubkey, keyName)) {
+                if(!up.addKey(pubkey, signer)) {
                     // bad or duplicate key
                     f.delete();
                     to.delete();
@@ -211,9 +211,9 @@ public class PluginUpdateHandler extends UpdateHandler {
                     return;
                 }
                 // ...and try the verify again
-                // verify the sig and verify that it is signed by the keyName in the plugin.config file
+                // verify the sig and verify that it is signed by the signer in the plugin.config file
                 String signingKeyName = up.verifyAndGetSigner(f);
-                if (!keyName.equals(signingKeyName)) {
+                if (!signer.equals(signingKeyName)) {
                     f.delete();
                     to.delete();
                     updateStatus("<b>" + _("Plugin signature verification of {0} failed", url) + "</b>");
@@ -278,9 +278,9 @@ public class PluginUpdateHandler extends UpdateHandler {
                     return;
                 }
                 String oldPubkey = oldProps.getProperty("key");
-                String oldKeyName = oldProps.getProperty("keyName");
+                String oldKeyName = oldProps.getProperty("signer");
                 String oldAppName = props.getProperty("name");
-                if ((!pubkey.equals(oldPubkey)) || (!keyName.equals(oldKeyName)) || (!appName.equals(oldAppName))) {
+                if ((!pubkey.equals(oldPubkey)) || (!signer.equals(oldKeyName)) || (!appName.equals(oldAppName))) {
                     to.delete();
                     updateStatus("<b>" + _("Signature of downloaded plugin does not match installed plugin") + "</b>");
                     return;
-- 
GitLab