Author: toad
Date: 2008-09-03 18:19:35 +0000 (Wed, 03 Sep 2008)
New Revision: 22376
Modified:
trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
Log:
Replace the question about opennet with the 3 questions about security levels.
Modified: trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
2008-09-03 17:49:23 UTC (rev 22375)
+++ trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java
2008-09-03 18:19:35 UTC (rev 22376)
@@ -17,6 +17,10 @@
import freenet.l10n.L10n;
import freenet.node.Node;
import freenet.node.NodeClientCore;
+import freenet.node.SecurityLevels;
+import freenet.node.SecurityLevels.FRIENDS_THREAT_LEVEL;
+import freenet.node.SecurityLevels.NETWORK_THREAT_LEVEL;
+import freenet.node.SecurityLevels.PHYSICAL_THREAT_LEVEL;
import freenet.pluginmanager.FredPluginBandwidthIndicator;
import freenet.support.Fields;
import freenet.support.HTMLNode;
@@ -36,7 +40,9 @@
private enum WIZARD_STEP {
WELCOME,
- OPENNET,
+ SECURITY_NETWORK,
+ SECURITY_FRIENDS,
+ SECURITY_PHYSICAL,
NAME_SELECTION,
BANDWIDTH,
DATASTORE_SIZE,
@@ -62,26 +68,84 @@
WIZARD_STEP currentStep =
WIZARD_STEP.valueOf(request.getParam("step", WIZARD_STEP.WELCOME.toString()));
- if(currentStep == WIZARD_STEP.OPENNET) {
- HTMLNode pageNode =
ctx.getPageMaker().getPageNode(l10n("step1Title"), false, ctx);
+ if(currentStep == WIZARD_STEP.SECURITY_NETWORK) {
+ HTMLNode pageNode =
ctx.getPageMaker().getPageNode(l10n("networkSecurityPageTitle"), false, ctx);
HTMLNode contentNode =
ctx.getPageMaker().getContentNode(pageNode);
- HTMLNode opennetInfobox = contentNode.addChild("div",
"class", "infobox infobox-normal");
- HTMLNode opennetInfoboxHeader =
opennetInfobox.addChild("div", "class", "infobox-header");
- HTMLNode opennetInfoboxContent =
opennetInfobox.addChild("div", "class", "infobox-content");
+ HTMLNode infobox = contentNode.addChild("div", "class",
"infobox infobox-normal");
+ HTMLNode infoboxHeader = infobox.addChild("div",
"class", "infobox-header");
+ HTMLNode infoboxContent = infobox.addChild("div",
"class", "infobox-content");
- opennetInfoboxHeader.addChild("#",
l10n("connectToStrangers"));
- opennetInfoboxContent.addChild("p",
l10n("connectToStrangersLong"));
- opennetInfoboxContent.addChild("p",
l10n("enableOpennet"));
- HTMLNode opennetForm =
ctx.addFormChild(opennetInfoboxContent, ".", "opennetForm");
- HTMLNode opennetDiv = opennetForm.addChild("div",
"class", "opennetDiv");
- opennetDiv.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "radio", "enableOpennet", "true" },
l10n("opennetYes"));
- opennetDiv.addChild("br");
- opennetDiv.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "radio", "enableOpennet", "false" },
l10n("opennetNo"));
- opennetForm.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "submit", "opennetF",
L10n.getString("FirstTimeWizardToadlet.continue")});
- opennetForm.addChild("input", new String[] { "type",
"name", "value" }, new String[] { "submit", "cancel",
L10n.getString("Toadlet.cancel")});
+ infoboxHeader.addChild("#",
l10nSec("networkThreatLevelShort"));
+ infoboxContent.addChild("p",
l10nSec("networkThreatLevel"));
+ HTMLNode form = ctx.addFormChild(infoboxContent, ".",
"networkSecurityForm");
+ HTMLNode div = form.addChild("div", "class",
"opennetDiv");
+ String controlName =
"security-levels.networkThreatLevel";
+ for(NETWORK_THREAT_LEVEL level :
NETWORK_THREAT_LEVEL.values()) {
+ HTMLNode input;
+ input = div.addChild("p").addChild("input", new
String[] { "type", "name", "value" }, new String[] { "radio", controlName,
level.name() });
+ input.addChild("b",
l10nSec("networkThreatLevel.name."+level));
+ input.addChild("#", ": ");
+ L10n.addL10nSubstitution(input,
"SecurityLevels.networkThreatLevel.choice."+level, new String[] { "bold",
"/bold" }, new String[] { "<b>", "</b>" });
+ HTMLNode inner =
input.addChild("p").addChild("i");
+ L10n.addL10nSubstitution(inner,
"SecurityLevels.networkThreatLevel.desc."+level, new String[] { "bold", "/bold"
}, new String[] { "<b>", "</b>" });
+ }
+ form.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "networkSecurityF",
L10n.getString("FirstTimeWizardToadlet.continue")});
+ form.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "cancel",
L10n.getString("Toadlet.cancel")});
this.writeHTMLReply(ctx, 200, "OK",
pageNode.generate());
return;
+ } else if(currentStep == WIZARD_STEP.SECURITY_FRIENDS) {
+ HTMLNode pageNode =
ctx.getPageMaker().getPageNode(l10n("friendsSecurityPageTitle"), false, ctx);
+ HTMLNode contentNode =
ctx.getPageMaker().getContentNode(pageNode);
+
+ HTMLNode infobox = contentNode.addChild("div", "class",
"infobox infobox-normal");
+ HTMLNode infoboxHeader = infobox.addChild("div",
"class", "infobox-header");
+ HTMLNode infoboxContent = infobox.addChild("div",
"class", "infobox-content");
+
+ infoboxHeader.addChild("#",
l10nSec("friendsThreatLevelShort"));
+ infoboxContent.addChild("p",
l10nSec("friendsThreatLevel"));
+ HTMLNode form = ctx.addFormChild(infoboxContent, ".",
"friendsSecurityForm");
+ HTMLNode div = form.addChild("div", "class",
"opennetDiv");
+ String controlName =
"security-levels.friendsThreatLevel";
+ for(FRIENDS_THREAT_LEVEL level :
FRIENDS_THREAT_LEVEL.values()) {
+ HTMLNode input;
+ input = div.addChild("p").addChild("input", new
String[] { "type", "name", "value" }, new String[] { "radio", controlName,
level.name() });
+ input.addChild("b",
l10nSec("friendsThreatLevel.name."+level));
+ input.addChild("#", ": ");
+ L10n.addL10nSubstitution(input,
"SecurityLevels.friendsThreatLevel.choice."+level, new String[] { "bold",
"/bold" }, new String[] { "<b>", "</b>" });
+ HTMLNode inner =
input.addChild("p").addChild("i");
+ L10n.addL10nSubstitution(inner,
"SecurityLevels.friendsThreatLevel.desc."+level, new String[] { "bold", "/bold"
}, new String[] { "<b>", "</b>" });
+ }
+ form.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "friendsSecurityF",
L10n.getString("FirstTimeWizardToadlet.continue")});
+ form.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "cancel",
L10n.getString("Toadlet.cancel")});
+ this.writeHTMLReply(ctx, 200, "OK",
pageNode.generate());
+ return;
+ } else if(currentStep == WIZARD_STEP.SECURITY_PHYSICAL) {
+ HTMLNode pageNode =
ctx.getPageMaker().getPageNode(l10n("physicalSecurityPageTitle"), false, ctx);
+ HTMLNode contentNode =
ctx.getPageMaker().getContentNode(pageNode);
+
+ HTMLNode infobox = contentNode.addChild("div", "class",
"infobox infobox-normal");
+ HTMLNode infoboxHeader = infobox.addChild("div",
"class", "infobox-header");
+ HTMLNode infoboxContent = infobox.addChild("div",
"class", "infobox-content");
+
+ infoboxHeader.addChild("#",
l10nSec("physicalThreatLevelShort"));
+ infoboxContent.addChild("p",
l10nSec("physicalThreatLevel"));
+ HTMLNode form = ctx.addFormChild(infoboxContent, ".",
"physicalSecurityForm");
+ HTMLNode div = form.addChild("div", "class",
"opennetDiv");
+ String controlName =
"security-levels.physicalThreatLevel";
+ for(PHYSICAL_THREAT_LEVEL level :
PHYSICAL_THREAT_LEVEL.values()) {
+ HTMLNode input;
+ input = div.addChild("p").addChild("input", new
String[] { "type", "name", "value" }, new String[] { "radio", controlName,
level.name() });
+ input.addChild("b",
l10nSec("physicalThreatLevel.name."+level));
+ input.addChild("#", ": ");
+ L10n.addL10nSubstitution(input,
"SecurityLevels.physicalThreatLevel.choice."+level, new String[] { "bold",
"/bold" }, new String[] { "<b>", "</b>" });
+ HTMLNode inner =
input.addChild("p").addChild("i");
+ L10n.addL10nSubstitution(inner,
"SecurityLevels.physicalThreatLevel.desc."+level, new String[] { "bold",
"/bold" }, new String[] { "<b>", "</b>" });
+ }
+ form.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "physicalSecurityF",
L10n.getString("FirstTimeWizardToadlet.continue")});
+ form.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "cancel",
L10n.getString("Toadlet.cancel")});
+ this.writeHTMLReply(ctx, 200, "OK",
pageNode.generate());
+ return;
} else if(currentStep == WIZARD_STEP.NAME_SELECTION) {
// Attempt to skip one step if possible: opennet nodes
don't need a name
if(Boolean.valueOf(request.getParam("opennet"))) {
@@ -224,7 +288,7 @@
HTMLNode firstParagraph = welcomeInfoboxContent.addChild("p");
firstParagraph.addChild("#", l10n("welcomeInfoboxContent1"));
HTMLNode secondParagraph = welcomeInfoboxContent.addChild("p");
- secondParagraph.addChild("a", "href",
"?step="+WIZARD_STEP.OPENNET).addChild("#",
L10n.getString("FirstTimeWizardToadlet.clickContinue"));
+ secondParagraph.addChild("a", "href",
"?step="+WIZARD_STEP.SECURITY_NETWORK).addChild("#",
L10n.getString("FirstTimeWizardToadlet.clickContinue"));
HTMLNode thirdParagraph = welcomeInfoboxContent.addChild("p");
thirdParagraph.addChild("a", "href", "/").addChild("#",
l10n("skipWizard"));
@@ -232,6 +296,14 @@
this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
}
+ private String l10nSec(String key) {
+ return L10n.getString("SecurityLevels."+key);
+ }
+
+ private String l10nSec(String key, String pattern, String value) {
+ return L10n.getString("SecurityLevels."+key, pattern, value);
+ }
+
@Override
public void handlePost(URI uri, HTTPRequest request, ToadletContext
ctx) throws ToadletContextClosedException, IOException {
@@ -248,30 +320,31 @@
return;
}
-
- if(request.isPartSet("enableOpennet")) {
- String isOpennetEnabled =
request.getPartAsString("enableOpennet", 255);
- boolean enable;
- try {
- enable = Fields.stringToBool(isOpennetEnabled);
- } catch (NumberFormatException e) {
- Logger.error(this, "Invalid opennetEnabled:
"+isOpennetEnabled, e);
- super.writeTemporaryRedirect(ctx, "step1",
TOADLET_URL+"?step="+WIZARD_STEP.OPENNET);
- return;
- }
- try {
- config.get("node.opennet").set("enabled",
enable);
- } catch (InvalidConfigValueException e) {
- Logger.error(this, "Should not happen setting
opennet.enabled=" + enable + " please report: " + e, e);
- super.writeTemporaryRedirect(ctx, "step1",
TOADLET_URL+"?step="+WIZARD_STEP.OPENNET);
- return;
- } catch (NodeNeedRestartException e) {
- Logger.error(this, "Should not happen setting
opennet.enabled=" + enable + " please report: " + e, e);
- super.writeTemporaryRedirect(ctx, "step1",
TOADLET_URL + "?step=" + WIZARD_STEP.OPENNET);
- return;
- }
- super.writeTemporaryRedirect(ctx, "step1",
TOADLET_URL+"?step="+WIZARD_STEP.NAME_SELECTION+"&opennet="+enable);
- return;
+ if(request.isPartSet("security-levels.networkThreatLevel")) {
+ // We don't require a confirmation here, since it's one
page at a time, so there's less information to
+ // confuse the user, and we don't know whether the node
has friends yet etc.
+ // FIXME should we have confirmation here???
+ String networkThreatLevel =
request.getPartAsString("security-levels.networkThreatLevel", 128);
+ NETWORK_THREAT_LEVEL newThreatLevel =
SecurityLevels.parseNetworkThreatLevel(networkThreatLevel);
+ core.node.securityLevels.setThreatLevel(newThreatLevel);
+ super.writeTemporaryRedirect(ctx, "step1",
TOADLET_URL+"?step="+WIZARD_STEP.SECURITY_FRIENDS);
+ } else
if(request.isPartSet("security-levels.friendsThreatLevel")) {
+ // We don't require a confirmation here, since it's one
page at a time, so there's less information to
+ // confuse the user, and we don't know whether the node
has friends yet etc.
+ // FIXME should we have confirmation here???
+ String friendsThreatLevel =
request.getPartAsString("security-levels.friendsThreatLevel", 128);
+ FRIENDS_THREAT_LEVEL newThreatLevel =
SecurityLevels.parseFriendsThreatLevel(friendsThreatLevel);
+ core.node.securityLevels.setThreatLevel(newThreatLevel);
+ super.writeTemporaryRedirect(ctx, "step1",
TOADLET_URL+"?step="+WIZARD_STEP.SECURITY_PHYSICAL);
+ } else
if(request.isPartSet("security-levels.physicalThreatLevel")) {
+ // We don't require a confirmation here, since it's one
page at a time, so there's less information to
+ // confuse the user, and we don't know whether the node
has friends yet etc.
+ // FIXME should we have confirmation here???
+ String physicalThreatLevel =
request.getPartAsString("security-levels.physicalThreatLevel", 128);
+ PHYSICAL_THREAT_LEVEL newThreatLevel =
SecurityLevels.parsePhysicalThreatLevel(physicalThreatLevel);
+ core.node.securityLevels.setThreatLevel(newThreatLevel);
+ core.storeConfig();
+ super.writeTemporaryRedirect(ctx, "step1",
TOADLET_URL+"?step="+WIZARD_STEP.NAME_SELECTION+"&opennet="+core.node.isOpennetEnabled());
} else if(request.isPartSet("nnameF")) {
String selectedNName = request.getPartAsString("nname",
128);
try {
Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2008-09-03
17:49:23 UTC (rev 22375)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2008-09-03
18:19:35 UTC (rev 22376)
@@ -289,6 +289,9 @@
FirstTimeWizardToadlet.memory.512M=512MiB - if you have lots of RAM
FirstTimeWizardToadlet.memoryLimit=Memory usage
FirstTimeWizardToadlet.memoryLimitLong=How much memory would you like to allow
Freenet to use? If you have many downloads or uploads queued, Freenet will need
more memory. We suggest you not set this below 128MB unless you are really
short of RAM. If you have 1GB or more, you should probably set this to at least
256MB. This will take effect after restarting Freenet.
+FirstTimeWizardToadlet.networkSecurityPageTitle=Freenet first time wizard! -
Network security settings
+FirstTimeWizardToadlet.friendsSecurityPageTitle=Freenet first time wizard! -
Friends security settings
+FirstTimeWizardToadlet.physicalSecurityPageTitle=Freenet first time wizard! -
Physical security settings
FirstTimeWizardToadlet.step1Title=Freenet first time wizard! - Friends and
strangers
FirstTimeWizardToadlet.step2Title=Freenet first time wizard! - Choose a node
name
FirstTimeWizardToadlet.step3Title=Freenet first time wizard! - Bandwidth limits