コード例 #1
0
  @FilterWith({XSRFFilter.class, AdminFilter.class})
  public Result renameTarget(
      Context context, @Param("name") String name, @Param("id") Integer targetId) {

    FlashScope flash = context.getFlashScope();
    Group group = context.getAttribute("group", Group.class);

    GoogleTarget target = getTarget(context, targetId);
    if (target == null) {
      flash.error("error.invalidWebsite");
      return Results.redirect(
          router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
    }

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

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

    target.setName(name);
    googleDB.target.rename(target);

    flash.success("google.group.websiteRenamed");
    return Results.redirect(
        router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
  }
コード例 #2
0
  @FilterWith({XSRFFilter.class, AdminFilter.class})
  public Result rename(Context context, @Param("name") String name) {
    FlashScope flash = context.getFlashScope();
    Group group = context.getAttribute("group", Group.class);

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

    group.setName(name);
    baseDB.group.update(group);

    flash.success("google.group.groupRenamed");
    return Results.redirect(
        router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
  }
コード例 #3
0
  @FilterWith({XSRFFilter.class, AdminFilter.class})
  public Result addEvent(
      Context context,
      @Param("day") String day,
      @Param("title") String title,
      @Param("description") String description,
      @Param("redir-search") Integer redirSearchId,
      @Param("redir-target") Integer redirTargetId) {
    FlashScope flash = context.getFlashScope();
    Group group = context.getAttribute("group", Group.class);

    Event event = new Event();
    event.setGroupId(group.getId());
    try {
      event.setDay(LocalDate.parse(day));
    } catch (Exception ex) {
    }

    if (event.getDay() == null) {
      flash.error("error.invalidDate");
      return Results.redirect(
          router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
    }

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

    if (baseDB.event.find(group, event.getDay()) != null) {
      flash.error("google.group.alreadyEventForThisDate");
      return Results.redirect(
          router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
    }

    event.setTitle(title);
    event.setDescription(Jsoup.clean(description == null ? "" : description, Whitelist.basic()));

    if (!baseDB.event.insert(event)) {
      flash.error("error.internalError");
      return Results.redirect(
          router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
    }

    flash.success("google.group.eventInserted");
    if (redirSearchId != null) {
      return Results.redirect(
          router.getReverseRoute(
              GoogleSearchController.class,
              "search",
              "groupId",
              group.getId(),
              "searchId",
              redirSearchId));
    }
    if (redirTargetId != null) {
      return Results.redirect(
          router.getReverseRoute(
              GoogleTargetController.class,
              "target",
              "groupId",
              group.getId(),
              "targetId",
              redirTargetId));
    }

    return Results.redirect(
        router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
  }
コード例 #4
0
  @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()));
  }
コード例 #5
0
  @FilterWith({XSRFFilter.class, AdminFilter.class})
  public Result addSearch(
      Context context,
      @Params("keyword[]") String[] keywords,
      @Params("tld[]") String tlds[],
      @Params("datacenter[]") String[] datacenters,
      @Params("device[]") Integer[] devices,
      @Params("local[]") String[] locals,
      @Params("custom[]") String[] customs) {
    FlashScope flash = context.getFlashScope();
    Group group = context.getAttribute("group", Group.class);

    if (keywords == null
        || tlds == null
        || datacenters == null
        || devices == null
        || locals == null
        || customs == null
        || keywords.length != tlds.length
        || keywords.length != datacenters.length
        || keywords.length != devices.length
        || keywords.length != locals.length
        || keywords.length != customs.length) {
      flash.error("error.invalidParameters");
      return Results.redirect(
          router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
    }

    Set<GoogleSearch> searches = new HashSet<>();

    for (int i = 0; i < keywords.length; i++) {
      GoogleSearch search = new GoogleSearch();

      if (keywords[i].isEmpty()) {
        flash.error("admin.google.keywordEmpty");
        return Results.redirect(
            router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
      }
      search.setKeyword(keywords[i]);

      if (!Validator.isGoogleTLD(tlds[i])) {
        flash.error("admin.google.invalidTLD");
        return Results.redirect(
            router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId()));
      }
      search.setTld(tlds[i]);

      if (!datacenters[i].isEmpty()) {
        if (!Validator.isIPv4(datacenters[i])) {
          flash.error("error.invalidIP");
          return Results.redirect(
              router.getReverseRoute(
                  GoogleGroupController.class, "view", "groupId", group.getId()));
        }
        search.setDatacenter(datacenters[i]);
      }

      if (devices[i] != null && devices[i] >= 0 && devices[i] < GoogleDevice.values().length) {
        search.setDevice(GoogleDevice.values()[devices[i]]);
      } else {
        search.setDevice(GoogleDevice.DESKTOP);
      }

      if (!Validator.isEmpty(locals[i])) {
        search.setLocal(locals[i]);
      }

      if (!Validator.isEmpty(customs[i])) {
        search.setCustomParameters(customs[i]);
      }

      searches.add(search);
    }

    List<GoogleSearch> knownSearches = new ArrayList<>();
    synchronized (searchLock) {
      for (GoogleSearch search : searches) {
        int id = googleDB.search.getId(search);
        if (id > 0) {
          search.setId(id);
          knownSearches.add(search);
        }
      }
      googleDB.search.insert(searches, group.getId());
    }

    googleDB.serpRescan.rescan(null, getTargets(context), knownSearches, false);

    flash.success("google.group.searchInserted");
    return Results.redirect(
        router.getReverseRoute(GoogleGroupController.class, "view", "groupId", group.getId())
            + "#tab-searches");
  }
コード例 #6
0
  @FilterWith(XSRFFilter.class)
  public Result update(
      Context context,
      @Param("targetDisplayMode") String targetDisplayMode,
      @Param("searchDisplayMode") String searchDispayMode,
      @Param("pages") Integer pages,
      @Param("result-per-page") Integer resultPerPage,
      @Param("min-pause") Integer minPause,
      @Param("max-pause") Integer maxPause,
      @Param("maxThreads") Integer maxThreads,
      @Param("fetchRetry") Integer fetchRetry,
      @Param("tld") String tld,
      @Param("datacenter") String datacenter,
      @Param("device") Integer device,
      @Param("local") String local,
      @Param("custom") String custom) {
    FlashScope flash = context.getFlashScope();

    GoogleSettings defaultOptions = new GoogleSettings();
    GoogleSettings options = googleDB.options.get();

    if (pages != null && resultPerPage != null) {
      if (pages * resultPerPage > 1000 || pages * resultPerPage < 1) {
        flash.error("admin.google.invalidPages");
        return Results.redirect(router.getReverseRoute(GoogleSettingsController.class, "settings"));
      }
      options.setPages(pages);
      options.setResultPerPage(resultPerPage);
    }

    if (minPause != null && maxPause != null) {
      if (minPause > maxPause) {
        flash.error("admin.google.invalidPauseRange");
        return Results.redirect(router.getReverseRoute(GoogleSettingsController.class, "settings"));
      }
      options.setMinPauseBetweenPageSec(minPause);
      options.setMaxPauseBetweenPageSec(maxPause);
    }

    if (fetchRetry != null) {
      options.setFetchRetry(fetchRetry);
    }

    if (maxThreads != null) {
      options.setMaxThreads(maxThreads);
    }

    if (!Validator.isEmpty(tld)) {
      if (!Validator.isGoogleTLD(tld)) {
        flash.error("admin.google.invalidTLD");
        return Results.redirect(router.getReverseRoute(GoogleSettingsController.class, "settings"));
      }
      options.setDefaultTld(tld);
    } else {
      options.setDefaultTld(defaultOptions.getDefaultTld());
    }

    if (!Validator.isEmpty(datacenter)) {
      if (!Validator.isIPv4(datacenter)) {
        flash.error("error.invalidIP");
        return Results.redirect(router.getReverseRoute(GoogleSettingsController.class, "settings"));
      }
      options.setDefaultDatacenter(datacenter);
    } else {
      options.setDefaultDatacenter(defaultOptions.getDefaultDatacenter());
    }

    if (device != null && device == 1) {
      options.setDefaultDevice(GoogleDevice.SMARTPHONE);
    } else {
      options.setDefaultDevice(GoogleDevice.DESKTOP);
    }

    if (Validator.isNotEmpty(local)) {
      options.setDefaultLocal(local);
    } else {
      options.setDefaultLocal(defaultOptions.getDefaultLocal());
    }

    if (Validator.isNotEmpty(custom)) {
      options.setDefaultCustomParameters(custom);
    } else {
      options.setDefaultCustomParameters(defaultOptions.getDefaultCustomParameters());
    }

    googleDB.options.update(options);

    flash.success("label.settingsUpdated");
    return Results.redirect(router.getReverseRoute(GoogleSettingsController.class, "settings"));
  }