public void handleMethodGET(URI uri, HTTPRequest req, ToadletContext ctx) throws ToadletContextClosedException, IOException, RedirectException { String requestId = req.getParam("requestId"); String originalRequestId = req.getParam("originalRequestId"); boolean result = ((SimpleToadletServer) ctx.getContainer()).pushDataManager.failover(originalRequestId, requestId); if (logMINOR) { Logger.minor(this, "Failover from:" + originalRequestId + " to:" + requestId + " with result:" + result); } writeHTMLReply(ctx, 200, "OK", result ? UpdaterConstants.SUCCESS : UpdaterConstants.FAILURE); }
/** * Returns a Hashtable of all URL parameters. * @param request contains URL parameters * @return Hashtable of all GET params. */ private Hashtable<String, String> readGET (HTTPRequest request) { Hashtable<String, String> set = new Hashtable<String, String>(); for (String key : request.getParameterNames()) { set.put(key, request.getParam(key)); } return set; }
/** * Returns a Hashtable of all POST parts up to a length of 1024*1024 characters. * @param request contains POST parts * @return set a Hashtable of all POST parts. */ private Hashtable<String, String> readPOST (HTTPRequest request) { Hashtable<String, String> set = new Hashtable<String, String>(); for (String key : request.getParts()) { set.put(key, request.getPartAsStringFailsafe(key, MAX_POST_SIZE)); } return set; }
private boolean parseOpennet(HTTPRequest request) { String opennetRaw; if (request.hasParameters()) { opennetRaw = request.getParam("opennet", "false"); } else { opennetRaw = request.getPartAsStringFailsafe("opennet", 5); } return Fields.stringToBool(opennetRaw, false); }
if (path.equals("/") && req.isParameterSet("newbookmark") && !forBaseHref) { String bookmark_key = req.getParam("newbookmark"); String bookmark_desc = req.getParam("desc"); String bookmark_activelink = req.getParam("hasAnActivelink", "");
private String selectedValue(HTTPRequest request) { if (request.isParameterSet(filenameField()) && (request.isParameterSet(selectDir) || request.isParameterSet(selectFile))) { //Request is a GET. return request.getParam(filenameField()); } else if (request.isPartSet(filenameField()) && (request.isPartSet(selectDir) || request.isPartSet(selectFile))) { //Request is a POST. return request.getPartAsStringFailsafe(filenameField(), MAX_POST_SIZE); } return null; }
/** * Doesn't make any changes, just passes result on to SECURITY_NETWORK. * @param request Checked for "opennet" value. */ @Override public String postStep(HTTPRequest request) { if (request.isPartSet("opennet")) { return FirstTimeWizardToadlet.WIZARD_STEP.SECURITY_NETWORK+"&opennet="+ request.getPartAsStringFailsafe("opennet", 5); } else { //Nothing selected when "next" clicked. Display choice again. return FirstTimeWizardToadlet.WIZARD_STEP.OPENNET.name(); } } }
/** * Validates whether the request contains a formPassword which matches {@link NodeClientCore#formPassword}. See the JavaDoc there for an explanation * of the purpose of this mechanism. * * <p><b>ATTENTION</b>: It is critically important to use this function when processing requests which "change the server state". Other words for this * would be requests which change your database or "write" requests. * Requests which only read values from the server don't have to validate the form password.</p> * * <p>To produce a form which already contains the password, use {@link PluginRespirator#addFormChild(freenet.support.HTMLNode, String, String)}.</p> * * @return true if the form password is valid */ protected boolean isFormPassword(HTTPRequest req) { String passwd = req.getParam("formPassword", null); if (passwd == null) passwd = req.getPartAsStringFailsafe("formPassword", 32); return (passwd != null) && passwd.equals(pluginContext.clientCore.formPassword); }
public void handleMethodPOST(URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, IOException { String url = request.getPartAsStringFailsafe(magicHTTPEscapeString, MAX_URL_LENGTH); MultiValueTable<String, String> headers = new MultiValueTable<String, String>(); //If the user clicked cancel, or the URL is not defined, return to the main page. //TODO: This will mean the beginning of the first time wizard if it's still in progress. //TODO: Is it worth it to fix that? if (request.getPartAsStringFailsafe("Go", 32).isEmpty() || url.isEmpty()) { url = WelcomeToadlet.PATH; } headers.put("Location", url); ctx.sendReplyHeaders(302, "Found", headers, null, 0); }
currentStep = WIZARD_STEP.valueOf(request.getParam("step", WIZARD_STEP.WELCOME.toString())); } catch (IllegalArgumentException e) { currentStep = WIZARD_STEP.WELCOME; request.isChrome() && request.isIncognito()) { super.writeTemporaryRedirect(ctx, "Skipping unneeded warning", persistFields.appendTo(TOADLET_URL+"?step=MISC")); } else if (currentStep == WIZARD_STEP.SECURITY_NETWORK && !request.isParameterSet("opennet")) {
if (request.isPartSet("insert-local")) { String keyType = request.getPartAsStringFailsafe("keytype", 10); if ("CHK".equals(keyType)) { insertURI = new FreenetURI("CHK@"); } else if("specify".equals(keyType)) { try { String u = request.getPartAsStringFailsafe("key", MAX_KEY_LENGTH); insertURI = new FreenetURI(u); if(logMINOR) "&compress="+String.valueOf(request.getPartAsStringFailsafe("compress", 128).length() > 0)+ "&compatibilityMode="+request.getPartAsStringFailsafe("compatibilityMode", 100)+ "&overrideSplitfileKey="+request.getPartAsStringFailsafe("overrideSplitfileKey", 65)); ctx.sendReplyHeaders(302, "Found", responseHeaders, null, 0); return; } else if (request.isPartSet("select-location")) { try { throw new RedirectException(LocalDirectoryConfigToadlet.basePath()+"/downloads/"); if(request.isPartSet("delete_request") && (request.getPartAsStringFailsafe("delete_request", 128).length() > 0)) { for(String part : request.getParts()) { if(!part.startsWith("identifier-")) continue; part = part.substring("identifier-".length()); if(part.length() > 50) continue; // It's just a number String identifier = request.getPartAsStringFailsafe("identifier-"+part, MAX_IDENTIFIER_LENGTH);
if (request.getPartAsStringFailsafe("updateconfirm", 32).length() > 0) { if(!ctx.checkFormPassword(request)) return; Logger.normal(this, "Node is updating/restarting"); node.getNodeUpdater().arm(); } else if (request.getPartAsStringFailsafe("update", 32).length() > 0) { PageNode page = ctx.getPageMaker().getPageNode(l10n("nodeUpdateConfirmTitle"), ctx); HTMLNode pageNode = page.outer; updateForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"submit", "updateconfirm", l10n("update")}); writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } else if (request.isPartSet("getThreadDump")) { if(!ctx.checkFormPassword(request)) return; PageNode page = ctx.getPageMaker().getPageNode(l10n("threadDumpTitle"), ctx); } else if (request.isPartSet("disable")) { if(!ctx.checkFormPassword(request)) return; int validAlertsRemaining = 0; UserAlert[] alerts = ctx.getAlertManager().getAlerts(); for (UserAlert alert: alerts) { if (request.getIntPart("disable", -1) == alert.hashCode()) { } else if (request.isPartSet("key") && request.isPartSet("filename")) { if(!ctx.checkFormPassword(request)) return; FreenetURI key = new FreenetURI(request.getPartAsStringFailsafe("key", Short.MAX_VALUE)); String type = request.getPartAsStringFailsafe("content-type", 128); if (type == null) { type = "text/plain";
if(logMINOR) Logger.minor(this, "UA = "+ua+" accept = "+accept); final boolean canSendProgress = isBrowser(ua) && !ctx.disableProgressPage() && (accept == null || accept.indexOf("text/html") > -1) && !httprequest.isParameterSet("forcedownload"); int maxRetries = httprequest.getIntParam("max-retries", -2); maxSizeDownload = MAX_LENGTH_WITH_PROGRESS; if(!restricted) { if(httprequest.isParameterSet("max-size")) { maxSize = maxSizeDownload = httprequest.getLongParam("max-size", defaultMaxSize); overrideSize = true; if (httprequest.isParameterSet("key")) { String k = httprequest.getParam("key"); FreenetURI newURI; try { String requestedMimeType = httprequest.getParam("type"); String location = getLink(newURI, requestedMimeType, maxSize, httprequest.getParam("force", null), httprequest.isParameterSet("forcedownload"), maxRetries, overrideSize); writeTemporaryRedirect(ctx, null, location); return; String forceString = httprequest.getParam("force"); long now = System.currentTimeMillis(); boolean force = false; if (!force && !httprequest.isParameterSet("forcedownload")) fctx.filterData = true; else if(logMINOR) Logger.minor(this, "Content filter disabled via request parameter");
if (request.isPartSet("add")) { String urltext = request.getPartAsStringFailsafe("url", 200); urltext = urltext.trim(); String reftext = request.getPartAsStringFailsafe("ref", Integer.MAX_VALUE); reftext = reftext.trim(); if (reftext.length() < 200) { reftext = request.getPartAsStringFailsafe("reffile", Integer.MAX_VALUE); reftext = reftext.trim(); privateComment = request.getPartAsStringFailsafe("peerPrivateNote", 250).trim(); String trustS = request.getPartAsStringFailsafe("trust", 10); FRIEND_TRUST trust = null; if(trustS != null && !trustS.equals("")) trust = FRIEND_TRUST.valueOf(trustS); String visibilityS = request.getPartAsStringFailsafe("visibility", 10); FRIEND_VISIBILITY visibility = null; if(visibilityS != null && !visibilityS.equals("")) } else { this.sendErrorPage(ctx, 200, l10n("failedToAddNodeTitle"), l10n("noRefOrURL"), !isOpennet()); request.freeParts(); return; request.freeParts();
String path=request.getPath(); if (request.isPartSet("submit-official")) { final String pluginName = request.getPartAsStringFailsafe("plugin-name", 40); final String pluginSource = request.getPartAsStringFailsafe("pluginSource", 10); if (request.isPartSet("submit-other")) { final String pluginName = request.getPartAsStringFailsafe("plugin-url", 200); final boolean fileonly = "on".equalsIgnoreCase(request.getPartAsStringFailsafe("fileonly", 20)); if (request.isPartSet("submit-freenet")) { final String pluginName = request.getPartAsStringFailsafe("plugin-uri", 300); 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); writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; }if (request.getPartAsStringFailsafe("unload", MAX_PLUGIN_NAME_LENGTH).length() > 0) { PageNode page = pageMaker.getPageNode(l10n("plugins"), ctx);
return; if(request.isPartSet("translating_for")) { final String translateFor = request.getPartAsStringFailsafe("translating_for", 255); boolean toTranslateOnly = request.isPartSet("toTranslateOnly"); if(request.getPartAsStringFailsafe("translation_update", 32).length() > 0){ String key = request.getPartAsStringFailsafe("key", 256); this.base.setOverride(key, new String(BucketTools.toByteArray(request.getPart("trans")), "UTF-8").trim()); if("on".equalsIgnoreCase(request.getPartAsStringFailsafe("gotoNext", 7))) { KeyIterator it = base.getDefaultLanguageTranslation().keyIterator(""); } else if(request.getPartAsStringFailsafe("remove_confirmed", 32).length() > 0) { String key = request.getPartAsStringFailsafe("remove_confirm", 256).trim(); this.base.setOverride(key, "");
if (request.isPartSet("confirm-reset-to-defaults")) { PageNode page = ctx.getPageMaker().getPageNode( l10n("confirmResetTitle"), ctx); String subconfig = request.getPartAsStringFailsafe("subconfig", MAX_PARAM_VALUE_SIZE); formNode.addChild("input", for (String part : request.getParts()) { if (part.startsWith(subconfig)) { formNode.addChild( "hidden", part, request.getPartAsStringFailsafe(part, MAX_PARAM_VALUE_SIZE) }); if (request.isPartSet(LocalFileBrowserToadlet.selectDir) || request.isPartSet("decline-default-reset")) { handleMethodGET(uri, request, ctx); return; paramsBuilder.append('?'); String value; for (String key : request.getParts()) { value = request.getPartAsStringFailsafe(key, MAX_PARAM_VALUE_SIZE); if (key.startsWith("select-directory.")) { paramsBuilder
/** * {@inheritDoc} */ @Override public Object get(TemplateContext templateContext, Object object, String member) { Object parentValue = super.get(templateContext, object, member); if (parentValue != null) { return parentValue; } HTTPRequest httpRequest = (HTTPRequest) object; return httpRequest.getHeader(member); }
if(request.isPartSet("n2nm-browse")) if (request.isPartSet("n2nm-upload") || request.isPartSet(LocalFileBrowserToadlet.selectFile) || request.isPartSet("send")) { File filename = null; String message = request.getPartAsStringFailsafe("message", 5 * 1024); message = message.trim(); if (message.length() > 1024) { HTMLNode peerTableInfobox = contentNode.addChild("div", "class", "infobox infobox-normal"); DarknetPeerNode[] peerNodes = node.getDarknetConnections(); if(request.isPartSet(LocalFileBrowserToadlet.selectFile)) { String fnam = request.getPartAsStringFailsafe("filename", 1024); if(fnam != null && fnam.length() > 0) { filename = new File(fnam); peerTableHeaderRow.addChild("th", l10n("sendStatus")); for (DarknetPeerNode pn: peerNodes) { if (request.isPartSet("node_" + pn.hashCode())) { int status; } else if(request.isPartSet("n2nm-upload")) { try{ HTTPUploadedFile file = request.getUploadedFile("n2nm-upload"); if(!file.getFilename().equals("")) { long size = request.getUploadedFile("n2nm-upload").getData().size(); if(size > 0) { long limit = maxSize(); status = pn.sendFileOffer(request.getUploadedFile("n2nm-upload"), message);