Esempio n. 1
0
  @FilterWith(XSRFFilter.class)
  public Result generate(
      Context context,
      @Param("groups") Integer groups,
      @Param("searchPerGroup") Integer searchPerGroup,
      @Param("targetPerGroup") Integer targetPerGroup) {
    FlashScope flash = context.getFlashScope();

    if (groups == null
        || groups < 1
        || searchPerGroup == null
        || searchPerGroup < 1
        || targetPerGroup == null
        || targetPerGroup < 1) {
      flash.put("error", "error.invalidParameters");
      return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    }

    for (int i = 0; i < groups; i++) {
      Group group = new Group(Group.Module.GOOGLE, "group#" + i);
      baseDB.group.insert(group);

      List<GoogleSearch> searches = new ArrayList<>();
      for (int j = 0; j < searchPerGroup; j++) {
        GoogleSearch search = new GoogleSearch("search#" + j + "#" + group.getName());
        search.setTld("com");
        searches.add(search);
      }
      googleDB.search.insert(searches, group.getId());

      List<GoogleTarget> targets = new ArrayList<>();
      for (int j = 0; j < targetPerGroup; j++) {
        int targetFakeId = j + 1;
        GoogleTarget target =
            new GoogleTarget(
                group.getId(),
                "target#" + targetFakeId + "#" + group.getName(),
                PatternType.REGEX,
                "^https?://www.site" + targetFakeId + ".com.+");
        targets.add(target);
      }
      googleDB.target.insert(targets);
    }

    flash.put("warning", "admin.debug.generated");
    return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
  }
Esempio n. 2
0
  @FilterWith(XSRFFilter.class)
  public Result wipeRankings(Context context) {
    FlashScope flash = context.getFlashScope();

    googleDB.targetSummary.wipe();
    googleDB.rank.wipe();
    googleDB.serp.wipe();
    baseDB.run.wipe();

    flash.put("warning", "admin.debug.rankingsWiped");
    return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
  }
  @FilterWith({XSRFFilter.class, AdminFilter.class})
  public Result addTarget(
      Context context,
      @Param("target-radio") String targetType,
      @Params("name[]") String[] names,
      @Params("pattern[]") String[] patterns) {
    FlashScope flash = context.getFlashScope();
    Group group = context.getAttribute("group", Group.class);

    if (targetType == null
        || names == null
        || names.length == 0
        || patterns == null
        || patterns.length == 0
        || names.length != patterns.length) {
      flash.error("error.invalidParameters");
      return Results.redirect(
          router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
    }

    Set<GoogleTarget> targets = new HashSet<>();
    for (int i = 0; i < names.length; i++) {
      String name = names[i];
      String pattern = patterns[i];

      if (name != null) {
        name = name.replaceAll("(^\\s+)|(\\s+$)", "");
      }

      if (pattern != null) {
        pattern = pattern.replaceAll("(^\\s+)|(\\s+$)", "");
      }

      if (Validator.isEmpty(name)) {
        flash.error("error.invalidName");
        return Results.redirect(
            router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
      }

      PatternType type = null;
      try {
        type = PatternType.valueOf(targetType);
      } catch (Exception ex) {
        flash.error("error.invalidTargetType");
        return Results.redirect(
            router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
      }

      if (PatternType.DOMAIN.equals(type) || PatternType.SUBDOMAIN.equals(type)) {
        try {
          pattern = IDN.toASCII(pattern);
        } catch (Exception ex) {
          pattern = null;
        }
      }

      if (!GoogleTarget.isValidPattern(type, pattern)) {
        flash.error("error.invalidPattern");
        return Results.redirect(
            router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
      }

      targets.add(new GoogleTarget(group.getId(), name, type, pattern));
    }

    if (googleDB.target.insert(targets) < 1) {
      flash.error("error.internalError");
      return Results.redirect(
          router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
    }
    googleDB.serpRescan.rescan(null, targets, getSearches(context), true);

    Run runningGoogleTask = taskManager.getRunningGoogleTask();
    if (runningGoogleTask != null) {
      flash.put(
          "warning",
          msg.get(
                  "google.group.websiteInsertedWhileRun",
                  context,
                  Optional.absent(),
                  runningGoogleTask.getId())
              .or(""));
    } else {
      flash.success("google.group.websiteInserted");
    }

    return Results.redirect(
        router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
  }