Package freenet.clients.http.wizardsteps

Examples of freenet.clients.http.wizardsteps.PersistFields


      currentStep = WIZARD_STEP.valueOf(request.getParam("step", WIZARD_STEP.WELCOME.toString()));
    } catch (IllegalArgumentException e) {
      currentStep = WIZARD_STEP.WELCOME;
    }

    PersistFields persistFields = new PersistFields(request);

    //Skip the browser warning page if using Chrome in incognito mode
    if (currentStep == WIZARD_STEP.BROWSER_WARNING &&
        request.isChrome() && request.isIncognito()) {
      super.writeTemporaryRedirect(ctx, "Skipping unneeded warning",
              persistFields.appendTo(TOADLET_URL+"?step=MISC"));
      return;
    } else if (currentStep == WIZARD_STEP.MISC && persistFields.isUsingPreset()) {
      /*If using a preset, skip the miscellaneous page as both high and low security set those settings.
       * This overrides the persistence fields.*/
      StringBuilder redirectBase = new StringBuilder(TOADLET_URL+"?step=");
      if (persistFields.preset == WIZARD_PRESET.HIGH) {
        redirectBase.append("SECURITY_NETWORK&preset=HIGH&confirm=true&opennet=false&security-levels.networkThreatLevel=HIGH");
      } else /*if (persistFields.preset == WIZARD_PRESET.LOW)*/ {
        redirectBase.append("DATASTORE_SIZE&preset=LOW&opennet=true");
      }
      //addPersistFields() is not used here because the fields are overridden.
      super.writeTemporaryRedirect(ctx, "Skipping to next necessary step", redirectBase.toString());
      return;
    } else if (currentStep == WIZARD_STEP.SECURITY_NETWORK && !request.isParameterSet("opennet")) {
      //If opennet isn't defined when attempting to set network security level, ask again.
      super.writeTemporaryRedirect(ctx, "Need opennet choice",
              persistFields.appendTo(TOADLET_URL+"?step=OPENNET"));
      return;
    } else if (currentStep == WIZARD_STEP.NAME_SELECTION && core.node.isOpennetEnabled()) {
      //Skip node name selection if not in darknet mode.
      super.writeTemporaryRedirect(ctx, "Skip name selection",
              persistFields.appendTo(stepURL(WIZARD_STEP.DATASTORE_SIZE.name())));
      return;
    } else if (currentStep == WIZARD_STEP.COMPLETE) {
      super.writeTemporaryRedirect(ctx, "Wizard complete", WelcomeToadlet.PATH);
      return;
    }
View Full Code Here


      //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)));
  }
View Full Code Here

TOP

Related Classes of freenet.clients.http.wizardsteps.PersistFields

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.