public static serverObjects respond(
      @SuppressWarnings("unused") final RequestHeader header,
      @SuppressWarnings("unused") final serverObjects post,
      @SuppressWarnings("unused") final serverSwitch env) {

    final serverObjects prop = new serverObjects();

    final Collection<String> dirlist =
        FileUtils.getDirListing(ListManager.listsPath, Blacklist.BLACKLIST_FILENAME_FILTER);
    final int lastBlacklistCount = dirlist.size() - 1;

    int blacklistCount = 0;
    if (dirlist != null) {
      for (final String element : dirlist) {
        prop.putXML(PREFIX_LISTS + blacklistCount + POSTFIX_NAME, element);

        prop.put(
            PREFIX_LISTS + blacklistCount + POSTFIX_SHARED,
            ListManager.listSetContains(BLACK_LISTS_SHARED, element));

        int j = 0;
        for (final BlacklistType type : BLACKLIST_TYPE_VALUES) {
          prop.putXML(
              PREFIX_LISTS + blacklistCount + INFIX_TYPES + j + POSTFIX_NAME, type.toString());
          prop.put(
              PREFIX_LISTS + blacklistCount + INFIX_TYPES + j + POSTFIX_VALUE,
              ListManager.listSetContains(type + TYPES_EXT, element));

          prop.put(
              PREFIX_LISTS + blacklistCount + INFIX_TYPES + j + POSTFIX_COMMA, j < lastTypeIndex);

          j++;
        }
        prop.put(PREFIX_LISTS + blacklistCount + POSTFIX_TYPES, BLACKLIST_TYPE_VALUES.length);

        prop.put(
            PREFIX_LISTS + blacklistCount + POSTFIX_COMMA, blacklistCount < lastBlacklistCount);

        blacklistCount++;
      }
    }
    prop.put(LISTS, blacklistCount);

    return prop;
  }
Esempio n. 2
0
  public static serverObjects respond(
      final RequestHeader header, final serverObjects post, final serverSwitch env) {
    final serverObjects prop = new serverObjects();

    // initialize the list manager
    ListManager.switchboard = (Switchboard) env;
    ListManager.listsPath =
        new File(env.getDataPath(), env.getConfig("listManager.listsPath", "DATA/LISTS"));
    String blacklistToUse = null;

    // get the list of supported blacklist types
    final String supportedBlacklistTypesStr = Blacklist.BLACKLIST_TYPES_STRING;
    final String[] supportedBlacklistTypes = supportedBlacklistTypesStr.split(",");

    prop.put(DISABLED + "checked", "1");

    if (post != null) {

      final boolean allowRegex =
          post.get("allowRegex", "off").equalsIgnoreCase("on") ? true : false;
      prop.put(DISABLED + "checked", (allowRegex) ? "1" : "0");

      if (post.containsKey("listNames")) {
        blacklistToUse = post.get("listNames");
        if (blacklistToUse.length() == 0
            || !ListManager.listSetContains("listManager.listsPath", blacklistToUse)) {
          prop.put("results", "2");
        }
      }

      putBlacklists(
          prop,
          FileUtils.getDirListing(ListManager.listsPath, BLACKLIST_FILENAME_FILTER),
          blacklistToUse);

      if (blacklistToUse != null) {
        prop.put("results", "1");

        if (post.containsKey("delete")) {
          prop.put(RESULTS + "modified", "1");
          prop.put(
              RESULTS + "modified_delCount",
              removeEntries(
                  blacklistToUse, supportedBlacklistTypes, getKeysByPrefix(post, "select", true)));
        } else if (post.containsKey("alter")) {
          prop.put(RESULTS + "modified", "2");
          prop.put(
              RESULTS + "modified_alterCount",
              alterEntries(
                  blacklistToUse,
                  supportedBlacklistTypes,
                  getKeysByPrefix(post, "select", false),
                  getValuesByPrefix(post, "entry", false)));
        }

        // list illegal entries
        final Map<String, BlacklistError> illegalEntries =
            getIllegalEntries(blacklistToUse, Switchboard.urlBlacklist, allowRegex);
        prop.put(RESULTS + "blList", blacklistToUse);
        prop.put(RESULTS + "entries", illegalEntries.size());
        prop.putHTML(RESULTS + "blEngine", Switchboard.urlBlacklist.getEngineInfo());
        prop.put(RESULTS + "disabled", (illegalEntries.isEmpty()) ? "1" : "0");
        if (!illegalEntries.isEmpty()) {
          prop.put(RESULTS + DISABLED + "entries", illegalEntries.size());
          int i = 0;
          String key;
          for (final Entry<String, BlacklistError> entry : illegalEntries.entrySet()) {
            key = entry.getKey();
            prop.put(RESULTS + DISABLED + ENTRIES + i + "_error", entry.getValue().getLong());
            prop.putHTML(RESULTS + DISABLED + ENTRIES + i + "_entry", key);
            i++;
          }
        }
      }
    } else {
      prop.put("results", "0");
      putBlacklists(
          prop,
          FileUtils.getDirListing(ListManager.listsPath, BLACKLIST_FILENAME_FILTER),
          blacklistToUse);
    }

    return prop;
  }