//Failed to parse enum value, default to welcome.
//TODO: Should this be an error page instead?
currentStep = WIZARD_STEP.WELCOME;
}
PersistFields persistFields = new PersistFields(request);
String redirectTarget;
if (currentStep.equals(WIZARD_STEP.WELCOME) &&
(request.isPartSet("presetLow") || request.isPartSet("presetHigh") || request.isPartSet("presetNone"))) {
/*Apply presets and UPnP is enabled first to allow it time to load (and thus enable
autodetection) before hitting the bandwidth page. This also effectively sets the preset field.*/
StringBuilder redirectTo = new StringBuilder(TOADLET_URL+"?step=BROWSER_WARNING&incognito=");
redirectTo.append(request.getPartAsStringFailsafe("incognito", 5));
//Translate button name to preset value on the query string.
if (request.isPartSet("presetLow")) {
//Low security preset
stepMISC.setUPnP(true);
stepMISC.setAutoUpdate(true);
redirectTo.append("&preset=LOW&opennet=true");
stepSECURITY_NETWORK.setThreatLevel(SecurityLevels.NETWORK_THREAT_LEVEL.LOW);
stepSECURITY_PHYSICAL.setThreatLevel(SecurityLevels.PHYSICAL_THREAT_LEVEL.NORMAL,
stepSECURITY_PHYSICAL.getCurrentLevel());
} else if (request.isPartSet("presetHigh")) {
//High security preset
stepMISC.setUPnP(true);
stepMISC.setAutoUpdate(true);
redirectTo.append("&preset=HIGH&opennet=false");
}
super.writeTemporaryRedirect(ctx, "Wizard set preset", redirectTo.toString());
return;
} else if (request.isPartSet("back")) {
//User chose back, return to previous page.
redirectTarget = getPreviousStep(currentStep, persistFields.preset).name();
} else {
try {
redirectTarget = steps.get(currentStep).postStep(request);
//Opennet step can change the persisted value for opennet.
if (currentStep == WIZARD_STEP.OPENNET) {
try {
HTTPRequest newRequest = new HTTPRequestImpl(new URI(
stepURL(redirectTarget)), "GET");
//Only continue if a value for opennet has been selected.
if (newRequest.isPartSet("opennet")) {
redirectTarget = WIZARD_STEP.SECURITY_NETWORK.name();
persistFields = new PersistFields(persistFields.preset, newRequest);
}
} catch (URISyntaxException e) {
Logger.error(this, "Unexpected invalid query string from OPENNET step! "+e, e);
redirectTarget = WIZARD_STEP.WELCOME.name();
}
}
} catch (IOException e) {
String title;
if (e.getMessage().equals("cantWriteNewMasterKeysFile")) {
//Recognized as being unable to write to the master keys file.
title = NodeL10n.getBase().getString("SecurityLevels.cantWriteNewMasterKeysFileTitle");
} else {
//Some other error.
title = NodeL10n.getBase().getString("Toadlet.internalErrorPleaseReport");
}
//Very loud error message, with descriptive title and header if possible.
StringBuilder msg = new StringBuilder("<html><head><title>").append(title).
append("</title></head><body><h1>").append(title).append("</h1><pre>");
//Print stack trace.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.flush();
msg.append(sw.toString()).append("</pre>");
//Include internal exception if one exists.
Throwable internal = e.getCause();
if (internal != null) {
msg.append("<h1>").
append(NodeL10n.getBase().getString("Toadlet.internalErrorPleaseReport")).
append("</h1>").append("<pre>");
sw = new StringWriter();
pw = new PrintWriter(sw);
internal.printStackTrace(pw);
pw.flush();
msg.append(sw.toString()).append("</pre>");
}
msg.append("</body></html>");
writeHTMLReply(ctx, 500, "Internal Error", msg.toString());
return;
}
}
super.writeTemporaryRedirect(ctx, "Wizard redirect", stepURL(persistFields.appendTo(redirectTarget)));
}