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", ".");