Package freenet.pluginmanager

Examples of freenet.pluginmanager.PluginManager$PluginProgress


    writeNodeFile();

    // Initialize the plugin manager
    Logger.normal(this, "Initializing Plugin Manager");
    System.out.println("Initializing Plugin Manager");
    pluginManager = new PluginManager(this, lastVersion);

    shutdownHook.addEarlyJob(new NativeThread("Shutdown plugins", NativeThread.HIGH_PRIORITY, true) {
      @Override
      public void realRun() {
        pluginManager.stop(SECONDS.toMillis(30)); // FIXME make it configurable??
View Full Code Here


    if(path.startsWith("/")) path = path.substring(1);
    if(path.startsWith("plugins/")) path = path.substring("plugins/".length());

    if(logMINOR) Logger.minor(this, "Pproxy received POST on "+path);

    final PluginManager pm = node.pluginManager;

    if(path.length()>0)
    {
      // Plugins handle their own formPassword checking.
      try
      {
        String plugin = null;
        // split path into plugin class name and 'daa' path for plugin
        int to = path.indexOf('/');
        if(to == -1)
        {
          plugin = path;
        }
        else
        {
          plugin = path.substring(0, to);
        }

        writeHTMLReply(ctx, 200, "OK", pm.handleHTTPPost(plugin, request));
      }
      catch (RedirectPluginHTTPException e) {
        writeTemporaryRedirect(ctx, e.message, e.newLocation);
      }
      catch (NotFoundPluginHTTPException e) {
        sendErrorPage(ctx, NotFoundPluginHTTPException.code, e.message, e.location);
      }
      catch (AccessDeniedPluginHTTPException e) {
        sendErrorPage(ctx, AccessDeniedPluginHTTPException.code, e.message, e.location);
      }
      catch (DownloadPluginHTTPException e) {
        // FIXME: maybe it ought to be defined like sendErrorPage : in toadlets

        MultiValueTable<String, String> head = new MultiValueTable<String, String>();
        head.put("Content-Disposition", "attachment; filename=\"" + e.filename + '"');
        ctx.sendReplyHeaders(DownloadPluginHTTPException.CODE, "Found", head, e.mimeType, e.data.length);
        ctx.writeData(e.data);
      }
      catch(PluginHTTPException e)
      {
        sendErrorPage(ctx, PluginHTTPException.code, e.message, e.location);
      }
      catch(Throwable t)
      {
        writeInternalError(t, ctx);
      }
    }
    else
    {
      if(!ctx.checkFormPassword(request)) return;
     
      PageMaker pageMaker = ctx.getPageMaker();
     
      if (request.isPartSet("submit-official")) {
        final String pluginName = request.getPartAsStringFailsafe("plugin-name", 40);
        final String pluginSource = request.getPartAsStringFailsafe("pluginSource", 10);
       
        node.executor.execute(new Runnable() {
          @Override
          public void run() {
            pm.startPluginOfficial(pluginName, true, true, "https".equals(pluginSource));
          }
        });
       
        headers.put("Location", ".");
        ctx.sendReplyHeaders(302, "Found", headers, null, 0);
        return;
      }
      if (request.isPartSet("submit-other")) {
        final String pluginName = request.getPartAsStringFailsafe("plugin-url", 200);
        final boolean fileonly = "on".equalsIgnoreCase(request.getPartAsStringFailsafe("fileonly", 20));
       
        node.executor.execute(new Runnable() {
          @Override
          public void run() {
            if (fileonly)
              pm.startPluginFile(pluginName, true);
            else
              pm.startPluginURL(pluginName, true);
          }
        });

        headers.put("Location", ".");
        ctx.sendReplyHeaders(302, "Found", headers, null, 0);
        return;
      }
      if (request.isPartSet("submit-freenet")) {
        final String pluginName = request.getPartAsStringFailsafe("plugin-uri", 300);
       
        node.executor.execute(new Runnable() {
          @Override
          public void run() {
            pm.startPluginFreenet(pluginName, true);
          }
        });

        headers.put("Location", ".");
        ctx.sendReplyHeaders(302, "Found", headers, null, 0);
        return;
      }
      if (request.isPartSet("cancel")){
        headers.put("Location", "/plugins/");
        ctx.sendReplyHeaders(302, "Found", headers, null, 0);
        return;
      }
      if (request.getPartAsStringFailsafe("unloadconfirm", MAX_PLUGIN_NAME_LENGTH).length() > 0) {
        String pluginThreadName = request.getPartAsStringFailsafe("unloadconfirm", MAX_PLUGIN_NAME_LENGTH);
        String pluginSpecification = getPluginSpecification(pm, pluginThreadName);
        pm.killPlugin(pluginThreadName, MAX_THREADED_UNLOAD_WAIT_TIME, false);
        if (request.isPartSet("purge")) {
          pm.removeCachedCopy(pluginSpecification);
        }
        PageNode page = pageMaker.getPageNode(l10n("plugins"), ctx);
        HTMLNode pageNode = page.outer;
        HTMLNode contentNode = page.content;
        HTMLNode infobox = contentNode.addChild("div", "class", "infobox infobox-success");
        infobox.addChild("div", "class", "infobox-header", l10n("pluginUnloaded"));
        HTMLNode infoboxContent = infobox.addChild("div", "class", "infobox-content");
        infoboxContent.addChild("#", l10n("pluginUnloadedWithName", "name", pluginThreadName));
        infoboxContent.addChild("br");
        infoboxContent.addChild("a", "href", "/plugins/", l10n("returnToPluginPage"));
        writeHTMLReply(ctx, 200, "OK", pageNode.generate());
        return;
      }if (request.getPartAsStringFailsafe("unload", MAX_PLUGIN_NAME_LENGTH).length() > 0) {
        PageNode page = pageMaker.getPageNode(l10n("plugins"), ctx);
        HTMLNode pageNode = page.outer;
        HTMLNode contentNode = page.content;
        HTMLNode infobox = contentNode.addChild("div", "class", "infobox infobox-query");
        infobox.addChild("div", "class", "infobox-header", l10n("unloadPluginTitle"));
        HTMLNode infoboxContent = infobox.addChild("div", "class", "infobox-content");
        infoboxContent.addChild("#", l10n("unloadPluginWithName", "name", request.getPartAsStringFailsafe("unload", MAX_PLUGIN_NAME_LENGTH)));
        HTMLNode unloadForm =
          ctx.addFormChild(infoboxContent, "/plugins/", "unloadPluginConfirmForm");
        unloadForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "unloadconfirm", request.getPartAsStringFailsafe("unload", MAX_PLUGIN_NAME_LENGTH) });
        HTMLNode tempNode = unloadForm.addChild("p");
        tempNode.addChild("input", new String[] { "type", "name" }, new String[] { "checkbox", "purge" });
        tempNode.addChild("#", l10n("unloadPurge"));
        tempNode = unloadForm.addChild("p");
        tempNode.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "confirm", l10n("unload") });
        tempNode.addChild("#", " ");
        tempNode.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", NodeL10n.getBase().getString("Toadlet.cancel") });
        writeHTMLReply(ctx, 200, "OK", pageNode.generate());
        return;
      } else if (request.getPartAsStringFailsafe("reload", MAX_PLUGIN_NAME_LENGTH).length() > 0) {
        PageNode page = pageMaker.getPageNode(l10n("plugins"), ctx);
        HTMLNode pageNode = page.outer;
        HTMLNode contentNode = page.content;
        HTMLNode reloadContent = pageMaker.getInfobox("infobox infobox-query", l10n("reloadPluginTitle"), contentNode, "plugin-reload", true);
        reloadContent.addChild("p", l10n("reloadExplanation"));
        reloadContent.addChild("p", l10n("reloadWarning"));
        HTMLNode reloadForm = ctx.addFormChild(reloadContent, "/plugins/", "reloadPluginConfirmForm");
        reloadForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "reloadconfirm", request.getPartAsStringFailsafe("reload", MAX_PLUGIN_NAME_LENGTH) });
        HTMLNode tempNode = reloadForm.addChild("p");
        tempNode.addChild("input", new String[] { "type", "name" }, new String[] { "checkbox", "purge" });
        tempNode.addChild("#", l10n("reloadPurgeWarning"));
        tempNode = reloadForm.addChild("p");
        tempNode.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "confirm", l10n("reload") });
        tempNode.addChild("#", " ");
        tempNode.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", NodeL10n.getBase().getString("Toadlet.cancel") });
       
        writeHTMLReply(ctx, 200, "OK", pageNode.generate());
        return;
      } else if (request.getPartAsStringFailsafe("update", MAX_PLUGIN_NAME_LENGTH).length() > 0) {
        // Deploy the plugin update
        final String pluginFilename = request.getPartAsStringFailsafe("update", MAX_PLUGIN_NAME_LENGTH);

        if (!pm.isPluginLoaded(pluginFilename)) {
          sendErrorPage(ctx, 404, l10n("pluginNotFoundUpdatingTitle"),
              l10n("pluginNotFoundUpdating", "name", pluginFilename));
        } else {
          node.nodeUpdater.deployPluginWhenReady(pluginFilename);

          headers.put("Location", ".");
          ctx.sendReplyHeaders(302, "Found", headers, null, 0);
        }
        return;
       
      }else if (request.getPartAsStringFailsafe("reloadconfirm", MAX_PLUGIN_NAME_LENGTH).length() > 0) {
        boolean purge = request.isPartSet("purge");
        String pluginThreadName = request.getPartAsStringFailsafe("reloadconfirm", MAX_PLUGIN_NAME_LENGTH);
        final String fn = getPluginSpecification(pm, pluginThreadName);

        if (fn == null) {
          sendErrorPage(ctx, 404, l10n("pluginNotFoundReloadTitle"),
              l10n("pluginNotFoundReload"));
        } else {
          pm.killPlugin(pluginThreadName, MAX_THREADED_UNLOAD_WAIT_TIME, true);
          if (purge) {
            pm.removeCachedCopy(fn);
          }
          node.executor.execute(new Runnable() {

            @Override
            public void run() {
              // FIXME
              pm.startPluginAuto(fn, true);
            }
           
          });

          headers.put("Location", ".");
View Full Code Here

    // remove leading / and plugins/ from path
    if(path.startsWith("/")) path = path.substring(1);
    if(path.startsWith("plugins/")) path = path.substring("plugins/".length());

    PluginManager pm = node.pluginManager;

    if(logMINOR)
      Logger.minor(this, "Pproxy fetching "+path);
    try {
      if (path.equals("")) {
            if(!ctx.checkFullAccess(this))
                return;

        Iterator<PluginProgress> loadingPlugins = pm.getStartingPlugins().iterator();

        PageNode page = ctx.getPageMaker().getPageNode(l10n("plugins"), ctx);
        boolean advancedModeEnabled = ctx.isAdvancedModeEnabled();
        HTMLNode pageNode = page.outer;
        if (loadingPlugins.hasNext()) {
          /* okay, add a refresh. */
          page.headNode.addChild("meta", new String[] { "http-equiv", "content" }, new String[] { "refresh", "10; url=" });
        }
        HTMLNode contentNode = page.content;

        contentNode.addChild(ctx.getAlertManager().createSummary());

        /* find which plugins have already been loaded. */
        List<OfficialPluginDescription> availablePlugins = pm.findAvailablePlugins();
        for(PluginInfoWrapper pluginInfoWrapper: pm.getPlugins()) {
          String pluginName = pluginInfoWrapper.getPluginClassName();
          String shortPluginName = pluginName.substring(pluginName.lastIndexOf('.') + 1);

          /* FIXME: Workaround the "Freemail" plugin show duplicate problem
           * The "Freemail" plugin is show on "Aviliable Plugin" even
           * if it is loaded. However fixing the plugin itself may break
           * running it as standalone application. */
          if (shortPluginName.equals("FreemailPlugin")) shortPluginName = "Freemail"; // DOH!

          availablePlugins.remove(pm.isOfficialPlugin(shortPluginName));
        }
        while (loadingPlugins.hasNext()) {
          PluginProgress pluginProgress = loadingPlugins.next();
          String pluginName = pluginProgress.getName();
          availablePlugins.remove(pm.isOfficialPlugin(pluginName));
        }

        /* sort available plugins into groups. */
        SortedMap<String, List<OfficialPluginDescription>> groupedAvailablePlugins = new TreeMap<String, List<OfficialPluginDescription>>();
        for (OfficialPluginDescription pluginDescription : availablePlugins) {
          if (!advancedModeEnabled && (pluginDescription.advanced || pluginDescription.experimental || pluginDescription.deprecated)) {
            continue;
          }
          String translatedGroup = l10n("pluginGroup." + pluginDescription.group);
          if (!groupedAvailablePlugins.containsKey(translatedGroup)) {
            groupedAvailablePlugins.put(translatedGroup, new ArrayList<OfficialPluginDescription>());
          }
          groupedAvailablePlugins.get(translatedGroup).add(pluginDescription);
        }
        for (List<OfficialPluginDescription> pluginDescriptions : groupedAvailablePlugins.values()) {
          Collections.sort(pluginDescriptions, new Comparator<OfficialPluginDescription>() {
            /**
             * {@inheritDoc}
             */
            @Override
            public int compare(OfficialPluginDescription o1, OfficialPluginDescription o2) {
              return o1.name.compareTo(o2.name);
            }
          });
        }

        showStartingPlugins(pm, contentNode);
        showPluginList(ctx, pm, contentNode, advancedModeEnabled);
        showOfficialPluginLoader(ctx, contentNode, groupedAvailablePlugins, pm, advancedModeEnabled);
        showUnofficialPluginLoader(ctx, contentNode);
        showFreenetPluginLoader(ctx, contentNode);

        writeHTMLReply(ctx, 200, "OK", pageNode.generate());
      } else {
        // split path into plugin class name and 'data' path for plugin
        int to = path.indexOf('/');
        String plugin;
        if (to == -1) {
          plugin = path;
        } else {
          plugin = path.substring(0, to);
        }

        // Plugin may need to know where it was accessed from, so it can e.g. produce relative URLs.
        //writeReply(ctx, 200, "text/html", "OK", mkPage("plugin", pm.handleHTTPGet(plugin, data)));
        writeHTMLReply(ctx, 200, "OK", pm.handleHTTPGet(plugin, request));       
      }

      //FetchResult result = fetch(key);
      //writeReply(ctx, 200, result.getMimeType(), "OK", result.asBucket());
    } catch (RedirectPluginHTTPException e) {
View Full Code Here

    }
    textBuilder.append("\n");

    // showStartingPlugins
    textBuilder.append("Plugins:\n");
    PluginManager pm = node.pluginManager;
    if (!pm.getPlugins().isEmpty()) {
      textBuilder.append(baseL10n.getString("PluginToadlet.pluginListTitle")).append("\n");
      for(PluginInfoWrapper pi: pm.getPlugins()) {
        long ver = pi.getPluginLongVersion();
        if (ver != -1)
          textBuilder.append(pi.getFilename()).append(" (").append(pi.getPluginClassName()).append(") - " ).append(pi.getPluginVersion()+ " ("+ver+")").append(" ").append(pi.getThreadName()).append("\n");
        else
          textBuilder.append(pi.getFilename()).append(" (").append(pi.getPluginClassName()).append(") - ").append(pi.getPluginVersion()).append(" ").append(pi.getThreadName()).append("\n");
View Full Code Here

TOP

Related Classes of freenet.pluginmanager.PluginManager$PluginProgress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.