Пример #1
0
  public CommandRequestInterface doNukeCheck(CommandRequest request) {
    String path = VirtualFileSystem.fixPath(request.getArgument());

    if (!path.startsWith(VirtualFileSystem.separator)) {
      // Create full path
      if (request.getCurrentDirectory().isRoot()) {
        path = VirtualFileSystem.separator + path;
      } else {
        path = request.getCurrentDirectory().getPath() + VirtualFileSystem.separator + path;
      }
    }

    NukeData nd = NukeBeans.getNukeBeans().findPath(path);

    if (nd != null) {
      // This path exist in nukelog
      request.setAllowed(false);
      request.setDeniedResponse(
          new CommandResponse(
              530,
              "Access denied - " + nd.getPath() + " already nuked for '" + nd.getReason() + "'"));
    }

    return request;
  }
Пример #2
0
  public CommandResponse doSITE_NUKESCLEAN(CommandRequest request) {
    CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK");

    if (NukeBeans.getNukeBeans().getAll().isEmpty()) {
      response.addComment("Nukelog empty.");
    }

    ArrayList<String> entriesToRemove = new ArrayList<String>();

    for (NukeData nd : NukeBeans.getNukeBeans().getAll()) {
      // Construct new path with [NUKED]-
      String newPath = VirtualFileSystem.fixPath(nd.getPath());
      String fixedName =
          "[NUKED]-" + newPath.substring(newPath.lastIndexOf(VirtualFileSystem.separator) + 1);
      newPath =
          newPath.substring(0, newPath.lastIndexOf(VirtualFileSystem.separator) + 1) + fixedName;

      try {
        request.getCurrentDirectory().getDirectoryUnchecked(newPath);
        // Still here? .. all ok then, just continue with next item in nukelog
      } catch (FileNotFoundException e) {
        // Dir was deleted/wiped, lets remove it from nukelog.
        // Add path to list so we can delete it after going through entire nukelog
        entriesToRemove.add(nd.getPath());
      } catch (ObjectNotValidException e) {
        return new CommandResponse(550, newPath + " is not a directory");
      }
    }

    if (entriesToRemove.isEmpty()) {
      response.addComment("No entries to delete from nukelog.");
    } else {
      int deleted = 0;
      for (String path : entriesToRemove) {
        try {
          NukeBeans.getNukeBeans().remove(path);
          deleted++;
        } catch (ObjectNotFoundException e) {
          response.addComment("Error removing nukelog entry: " + path);
        }
      }
      response.addComment("Removed " + deleted + " invalid entries from the nukelog.");
    }

    return response;
  }
Пример #3
0
  public CommandResponse doSITE_NUKES(CommandRequest request) {
    CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK");

    ReplacerEnvironment env = new ReplacerEnvironment();

    SectionInterface section =
        GlobalContext.getGlobalContext().getSectionManager().getSection(request.getArgument());

    if (request.hasArgument() && section.getName().equalsIgnoreCase("")) {
      return new CommandResponse(501, "Invalid section!");
    }

    if (NukeBeans.getNukeBeans().getAll().isEmpty()) {
      response.addComment(
          request
              .getSession()
              .jprintf(_bundle, _keyPrefix + "nukes.empty", env, request.getUser()));
    }

    for (NukeData nd : NukeBeans.getNukeBeans().getAll()) {
      if (nd.getPath().startsWith(request.getArgument(), 1)) {
        env.add("path", nd.getPath());
        env.add("multiplier", nd.getMultiplier());
        env.add("usersnuked", nd.getNukees().size());
        env.add("size", nd.getSize());
        env.add("reason", nd.getReason());
        env.add("amount", nd.getAmount());
        env.add("nuker", nd.getUser());
        response.addComment(
            request.getSession().jprintf(_bundle, _keyPrefix + "nukes", env, request.getUser()));
      }
    }

    if (response.getComment().isEmpty()) {
      env.add("section", section.getName());
      response.addComment(
          request
              .getSession()
              .jprintf(_bundle, _keyPrefix + "nukes.empty.section", env, request.getUser()));
    }

    return response;
  }
Пример #4
0
  /**
   * USAGE: site unnuke <directory> <message> Unnuke a directory.
   *
   * <p>ex. site unnuke shit NOT CRAP
   *
   * <p>This will unnuke the directory 'shit' with the comment 'NOT CRAP'.
   *
   * <p>NOTE: You can enclose the directory in braces if you have spaces in the name ex. site unnuke
   * {My directory name} justcause
   *
   * <p>You need to configure glftpd to keep nuked files if you want to unnuke. See the section
   * about glftpd.conf.
   *
   * @throws ImproperUsageException
   */
  public CommandResponse doSITE_UNNUKE(CommandRequest request) throws ImproperUsageException {
    if (!request.hasArgument()) {
      throw new ImproperUsageException();
    }

    StringTokenizer st = new StringTokenizer(request.getArgument());

    Session session = request.getSession();

    DirectoryHandle currentDir = request.getCurrentDirectory();
    User user = session.getUserNull(request.getUser());
    String toName = st.nextToken();
    String toDir;
    String nukeName;

    if (!toName.startsWith(VirtualFileSystem.separator)) {
      // Not a full path, let's make it one and append [NUKED]- if needed.
      if (toName.startsWith("[NUKED]-")) {
        nukeName = toName;
        toName = toName.substring(8);
      } else {
        nukeName = "[NUKED]-" + toName;
      }
      if (request.getCurrentDirectory().isRoot()) {
        boolean searchIndex =
            request.getProperties().getProperty("search", "true").equalsIgnoreCase("true");
        if (searchIndex) {
          // Get dirs from index system
          ArrayList<DirectoryHandle> dirsToUnNuke;
          try {
            dirsToUnNuke = NukeUtils.findNukeDirs(currentDir, user, nukeName);
          } catch (FileNotFoundException e) {
            logger.warn(e);
            return new CommandResponse(550, e.getMessage());
          }

          ReplacerEnvironment env = new ReplacerEnvironment();

          if (dirsToUnNuke.isEmpty()) {
            env.add("searchstr", nukeName);
            return new CommandResponse(
                550, session.jprintf(_bundle, _keyPrefix + "unnuke.search.empty", env, user));
          } else if (dirsToUnNuke.size() == 1) {
            toDir = dirsToUnNuke.get(0).getParent().getPath() + VirtualFileSystem.separator;
          } else {
            CommandResponse response = new CommandResponse(200);

            for (DirectoryHandle nukeDir : dirsToUnNuke) {
              try {
                env.add("name", nukeDir.getName());
                env.add("path", nukeDir.getPath());
                env.add("owner", nukeDir.getUsername());
                env.add("group", nukeDir.getGroup());
                env.add("size", Bytes.formatBytes(nukeDir.getSize()));
                response.addComment(
                    session.jprintf(_bundle, _keyPrefix + "unnuke.search.item", env, user));
              } catch (FileNotFoundException e) {
                logger.warn(
                    "Dir deleted after index search?, skip and continue: " + nukeDir.getPath());
              }
            }

            response.addComment(
                session.jprintf(_bundle, _keyPrefix + "unnuke.search.end", env, user));

            // Return matching dirs and let user decide what to unnuke
            return response;
          }
        } else {
          toDir = VirtualFileSystem.separator;
        }
      } else {
        toDir = currentDir.getPath() + VirtualFileSystem.separator;
      }
    } else {
      // Full path to Nuked dir provided, append [NUKED]- if needed.
      toDir = VirtualFileSystem.fixPath(toName);
      toName = toDir.substring(toDir.lastIndexOf(VirtualFileSystem.separator) + 1);
      toDir = toDir.substring(0, toDir.lastIndexOf(VirtualFileSystem.separator) + 1);
      if (toName.startsWith("[NUKED]-")) {
        nukeName = toName;
        toName = toName.substring(8);
      } else {
        nukeName = "[NUKED]-" + toName;
      }
    }

    String reason;

    if (st.hasMoreTokens()) {
      reason = st.nextToken("").trim();
    } else {
      reason = "";
    }

    DirectoryHandle nukeDir;

    try {
      nukeDir = currentDir.getDirectory(toDir + nukeName, user);
    } catch (FileNotFoundException e) {
      // Maybe dir was deleted/wiped, lets remove it from nukelog.
      try {
        NukeBeans.getNukeBeans().remove(toDir + toName);
      } catch (ObjectNotFoundException ex) {
        return new CommandResponse(
            500, toDir + nukeName + " doesnt exist and no nukelog for this path was found.");
      }
      return new CommandResponse(
          200, toDir + nukeName + " doesnt exist, removed nuke from nukelog.");
    } catch (ObjectNotValidException e) {
      return new CommandResponse(550, toDir + nukeName + " is not a directory");
    }

    NukeData nd;
    try {
      nd = NukeUtils.unnuke(nukeDir, reason);
    } catch (NukeException e) {
      return new CommandResponse(500, "Unnuke failed: " + e.getMessage());
    }

    CommandResponse response = new CommandResponse(200, "Unnuke succeeded");

    NukeEvent nukeEvent = new NukeEvent(session.getUserNull(request.getUser()), "UNNUKE", nd);
    GlobalContext.getEventService().publishAsync(nukeEvent);

    ReplacerEnvironment env = new ReplacerEnvironment();

    String section = GlobalContext.getGlobalContext().getSectionManager().lookup(nukeDir).getName();
    env.add("section", section);
    env.add("dir", nukeDir.getName());
    env.add("path", nukeDir.getPath());
    env.add("relpath", nukeDir.getPath().replaceAll("/" + section + "/", ""));
    env.add("multiplier", nd.getMultiplier());
    env.add("nukedamount", Bytes.formatBytes(nd.getAmount()));
    env.add("reason", reason);
    env.add("size", Bytes.formatBytes(nd.getSize()));

    if (session instanceof BaseFtpConnection) {
      response.addComment(session.jprintf(_bundle, _keyPrefix + "unnuke", env, user));
      for (NukedUser nukeeObj : NukeBeans.getNukeeList(nd)) {
        ReplacerEnvironment nukeeenv = new ReplacerEnvironment();
        User nukee;
        try {
          nukee =
              GlobalContext.getGlobalContext()
                  .getUserManager()
                  .getUserByName(nukeeObj.getUsername());
        } catch (NoSuchUserException e1) {
          // Unable to get user, does not exist.. skip announce for this user
          continue;
        } catch (UserFileException e1) {
          // Error in user file.. skip announce for this user
          continue;
        }

        long debt =
            NukeUtils.calculateNukedAmount(
                nukeeObj.getAmount(),
                nukee.getKeyedMap().getObjectFloat(UserManagement.RATIO),
                nd.getMultiplier());
        nukeeenv.add("nukedamount", Bytes.formatBytes(debt));
        response.addComment(
            session.jprintf(_bundle, _keyPrefix + "unnuke.nukees", nukeeenv, nukee));
      }
    }

    return response;
  }