示例#1
0
  /**
   * The servlet method that responds to an HTTP POST.
   *
   * <p>This method interprets the posted parameters as a new script and stores it either as an
   * anonymizer script or a profile. It returns a text/plain string containing the "OK" if the store
   * succeeded, or an error message if it failed.
   *
   * <p>Note: This method is designed to be called by an AJAX method in the Javascript of the
   * anonymizer configurator page.
   *
   * @param req The HttpRequest provided by the servlet container.
   * @param res The HttpResponse provided by the servlet container.
   */
  public void doPost(HttpRequest req, HttpResponse res) {

    // Make sure the user is authorized to do this.
    if (!req.userHasRole("admin") || !req.isReferredFrom(context)) {
      res.setResponseCode(res.forbidden);
      res.send();
      return;
    }

    if (req.hasParameter("suppress")) home = "";

    // Set up the response
    res.disableCaching();
    res.setContentType("txt");

    // Get the possible query parameters
    // and get the script file, if one is specified
    int p = -1;
    int s = -1;
    File file = null;
    try {
      p = Integer.parseInt(req.getParameter("p"));
      s = Integer.parseInt(req.getParameter("s"));
      file = getScriptFile(p, s);
    } catch (Exception ex) {
    }

    // Get the XML text to store
    String xml = req.getParameter("xml");
    if (xml != null) xml = xml.trim();
    else xml = "";

    // Figure out what kind of POST this is
    Path path = new Path(req.getPath());
    int len = path.length();

    if ((len == 3) && (path.element(1).equals("profile")) && !xml.equals("")) {
      // This is a request to store a specific profile.
      File profileFile = new File(savedProfiles, filter(path.element(2)));
      if (FileUtil.setText(profileFile, FileUtil.utf8, xml)) res.write("OK");
      else res.write("Unable to store " + profileFile);
    } else if ((len == 2) && path.element(1).equals("script") && (file != null)) {
      // This is a request to save a specific script.
      // Don't force the extension on scripts because that
      // might invalidate the reference in the config file.
      if (FileUtil.setText(file, FileUtil.utf8, xml)) {
        res.write("OK");
        logger.debug("Successfully stored the posted script to " + file);
      } else {
        res.write("Unable to store " + file);
        logger.debug("Unable to store the posted script to " + file);
      }
    } else res.setResponseCode(res.notimplemented);
    res.send();
  }
示例#2
0
  /**
   * The servlet method that responds to an HTTP GET. This method returns a summary page containing
   * information on the pipeline or stage specified by the p and s query parameters.
   *
   * @param req The HttpServletRequest provided by the servlet container.
   * @param res The HttpServletResponse provided by the servlet container.
   */
  public void doGet(HttpRequest req, HttpResponse res) {
    super.loadParameters(req);

    // Get the parameters.
    int x = StringUtil.getInt(req.getParameter("plugin"), -1);

    // Return the page
    res.write(getPage(p, s, x));
    res.setContentType("html");
    res.disableCaching();
    res.send();
  }
示例#3
0
  /** Delete the MIRCdocuments corresponding to a list of URLs, and then return the query page. */
  public void doGet(HttpRequest req, HttpResponse res) throws Exception {

    String urlsParam = req.getParameter("urls");

    if (req.isFromAuthenticatedUser() && (urlsParam != null)) {

      MircConfig mc = MircConfig.getInstance();
      File mircRoot = mc.getRootDirectory();
      User user = req.getUser();

      String[] urls = urlsParam.split("\\|");
      for (String url : urls) {
        if (mc.isLocal(url)) {
          int k = url.indexOf("/storage/");
          if (k != -1) {
            url = url.substring(k + 1);
            int kk = url.indexOf("?");
            if (kk > 0) url = url.substring(0, kk);

            Path path = new Path(url);
            String ssid = path.element(1);
            String docref = path.subpath(2).substring(1);

            url.replace("/", File.separator);
            File mdFile = new File(mircRoot, url);

            MircDocument md = new MircDocument(mdFile);
            boolean ok = md.authorizes("delete", user);

            if (ok) StorageServiceAdmin.deleteDocument(ssid, docref);
          }
        }
      }
    }
    res.redirect("/query");
  }
示例#4
0
  /**
   * The servlet method that responds to an HTTP GET.
   *
   * @param req The HttpServletRequest provided by the servlet container.
   * @param res The HttpServletResponse provided by the servlet container.
   */
  public void doGet(HttpRequest req, HttpResponse res) {

    // Make sure the user is authorized to do this.
    if (!req.userHasRole("admin")) {
      res.setResponseCode(res.forbidden);
      res.send();
      return;
    }

    if (req.hasParameter("suppress")) home = "";

    // Disable caching of the response
    res.disableCaching();

    // Get the possible query parameters
    // and get the script file, if one is specified
    int p = -1;
    int s = -1;
    File file = null;
    try {
      p = Integer.parseInt(req.getParameter("p"));
      s = Integer.parseInt(req.getParameter("s"));
      file = getScriptFile(p, s);
    } catch (Exception ex) {
    }

    // Figure out what kind of GET this is
    Path path = new Path(req.getPath());
    int len = path.length();

    if ((len == 1) && (file == null)) {
      // This is a request for the script selection page
      res.setContentType("html");
      res.write(getListPage());
    } else if ((len == 1) && (file != null)) {
      // This is a request for the editor for the script specified by p and s
      res.setContentType("html");
      res.write(getScriptPage(p, s, file));
    } else if ((len == 2) && path.element(1).equals("profiles")) {
      // This is a request for a list of all the stored profiles
      res.setContentType("xml");
      res.write(getProfilesXML());
    } else if ((len == 4) && path.element(1).equals("profile")) {
      // This is a request for a profile specified in the URL path
      res.setContentType("xml");
      res.write(getProfileXML(path.element(2), path.element(3)));
    } else if ((len == 2) && path.element(1).equals("script")) {
      // This is a request for the script specified by p and s
      res.setContentType("xml");
      res.write(getScriptXML(file));
    } else res.setResponseCode(res.notfound);
    res.send();
  }