private void addSectionsFromConf( Properties cfg, String prop, ArrayList<SectionInterface> sections) { sections.clear(); for (int i = 1; ; i++) { String section = cfg.getProperty(prop + i); if (section == null) break; SectionInterface sec = GlobalContext.getGlobalContext().getSectionManager().getSection(section); if (!sec.getBaseDirectory() .getPath() .equals(GlobalContext.getGlobalContext().getRoot().getPath())) { sections.add(sec); } } }
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; }
public CommandResponse doSITE_PRE(CommandRequest request) throws ImproperUsageException { if (!request.hasArgument()) { throw new ImproperUsageException(); } String[] args = request.getArgument().split(" "); if (args.length != 2) { return StandardCommandManager.genericResponse("RESPONSE_501_SYNTAX_ERROR"); } SectionInterface section = GlobalContext.getGlobalContext().getSectionManager().getSection(args[1]); if (section.getName().equals("")) { return new CommandResponse( 500, "Invalid section, see SITE SECTIONS for a list of available sections"); } User user = request.getSession().getUserNull(request.getUser()); DirectoryHandle preDir; String path = VirtualFileSystem.fixPath(args[0]); if (!(path.startsWith(VirtualFileSystem.separator))) { // Not a full path, let's make it one if (request.getCurrentDirectory().isRoot()) { path = VirtualFileSystem.separator + path; } else { path = request.getCurrentDirectory().getPath() + VirtualFileSystem.separator + path; } } try { preDir = request.getCurrentDirectory().getDirectory(path, user); } catch (FileNotFoundException e) { return StandardCommandManager.genericResponse("RESPONSE_550_REQUESTED_ACTION_NOT_TAKEN"); } catch (ObjectNotValidException e) { return StandardCommandManager.genericResponse( "RESPONSE_553_REQUESTED_ACTION_NOT_TAKEN_FILE_EXISTS"); } ConfigInterface config = GlobalContext.getConfig(); if (!config.checkPathPermission("pre", user, preDir)) { return StandardCommandManager.genericResponse("RESPONSE_530_ACCESS_DENIED"); } DirectoryHandle toInode = new DirectoryHandle( section.getCurrentDirectory().getPath() + VirtualFileSystem.separator + preDir.getName()); if (toInode.exists()) { return new CommandResponse(500, "Directory already exist in target section"); } CommandResponse response = new CommandResponse(250, request.getCommand().toUpperCase() + " command successful."); // AWARD CREDITS HashMap<User, Long> awards = new HashMap<User, Long>(); preAwardCredits(preDir, awards); for (Map.Entry<User, Long> entry : awards.entrySet()) { User owner = entry.getKey(); if (StatsManager.getStatsManager().getCreditCheckRatio(preDir, owner) == 0) { Long award = entry.getValue(); owner.updateCredits(award); response.addComment("Awarded " + Bytes.formatBytes(award) + " to " + owner.getName()); } } recursiveRemoveOwnership(preDir, System.currentTimeMillis()); int files = getFiles(preDir); long bytes = 0; try { bytes = preDir.getSize(); } catch (FileNotFoundException e) { logger.warn("FileNotFoundException ", e); } try { preDir.renameToUnchecked(toInode); } catch (FileNotFoundException e) { logger.warn("FileNotFoundException on renameTo()", e); return new CommandResponse(500, "FileNotFound - " + e.getMessage()); } catch (IOException e) { logger.warn("IOException on renameTo()", e); return new CommandResponse(500, "IOException - " + e.getMessage()); } preDir = toInode; GlobalContext.getEventService() .publishAsync( new PreEvent(preDir, section, Integer.toString(files), Bytes.formatBytes(bytes))); response.setObject(PREDIR, preDir); return response; }