/* * Prehook method for SLAVE ADDIP * Gets the ip, and preforms checks. */ public CommandRequestInterface doIpSecuritySLAVEPreCheck(CommandRequest request) { if (!request.hasArgument()) { return request; } String argument = request.getArgument(); StringTokenizer arguments = new StringTokenizer(argument); if (!arguments.hasMoreTokens()) { return request; } String slavename = arguments.nextToken(); RemoteSlave rslave = null; try { rslave = GlobalContext.getGlobalContext().getSlaveManager().getRemoteSlave(slavename); } catch (ObjectNotFoundException e) { request.setDeniedResponse(new CommandResponse(200, "Slave Not Found: " + slavename)); request.setAllowed(false); return request; } if (arguments.hasMoreTokens()) { String command = arguments.nextToken(); if (command.equalsIgnoreCase("addmask")) { if (arguments.countTokens() != 1) { return request; } HostMask newMask = new HostMask(arguments.nextToken().replace(",", "")); String _maskident = newMask.getIdentMask(); String _maskHostMask = newMask.getHostMask(); boolean _allowed = IpSecurityManager.getIpSecurity() .checkIP(_maskident, _maskHostMask, rslave.getMasks().size(), null); if ((!_allowed) && (!_maskHostMask.equals("127.0.0.1"))) { request.setAllowed(false); CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); response.addComment(IpSecurityManager.getIpSecurity().outputConfs(null)); request.setDeniedResponse(response); return request; } } } return request; }
/** * Usage: site slave slavename [set,addmask,delmask] * * @throws ImproperUsageException */ public CommandResponse doSITE_SLAVE(CommandRequest request) throws ImproperUsageException { Session session = request.getSession(); CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); ReplacerEnvironment env = new ReplacerEnvironment(); if (!request.hasArgument()) { throw new ImproperUsageException(); } String argument = request.getArgument(); StringTokenizer arguments = new StringTokenizer(argument); if (!arguments.hasMoreTokens()) { throw new ImproperUsageException(); } String slavename = arguments.nextToken(); env.add("slavename", slavename); RemoteSlave rslave = null; try { rslave = GlobalContext.getGlobalContext().getSlaveManager().getRemoteSlave(slavename); } catch (ObjectNotFoundException e) { response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.notfound", env, request.getUser())); return response; } if (!arguments.hasMoreTokens()) { if (!rslave.getMasks().isEmpty()) { env.add("masks", rslave.getMasks()); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.masks", env, request.getUser())); } response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.data.header", request.getUser())); Map<Object, Object> props = rslave.getProperties(); for (Entry<Object, Object> entry : props.entrySet()) { env.add("key", entry.getKey()); env.add("value", entry.getValue()); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.data", env, request.getUser())); } return response; } String command = arguments.nextToken(); if (command.equalsIgnoreCase("set")) { if (arguments.countTokens() != 2) { throw new ImproperUsageException(); } String key = arguments.nextToken(); String value = arguments.nextToken(); rslave.setProperty(key, value); env.add("key", key); env.add("value", value); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.set.success", env, request.getUser())); return response; } else if (command.equalsIgnoreCase("unset")) { if (arguments.countTokens() != 1) { throw new ImproperUsageException(); } String key = arguments.nextToken(); env.add("key", key); String value; try { value = rslave.removeProperty(key); } catch (KeyNotFoundException e) { response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.unset.failure", env, request.getUser())); return response; } env.add("value", value); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.unset.success", env, request.getUser())); return response; } else if (command.equalsIgnoreCase("addmask")) { if (arguments.countTokens() != 1) { throw new ImproperUsageException(); } String mask = arguments.nextToken(); env.add("mask", mask); try { rslave.addMask(mask); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.addmask.success", env, request.getUser())); return response; } catch (DuplicateElementException e) { response = new CommandResponse( 501, session.jprintf( _bundle, _keyPrefix + "slave.addmask.dupe", env, request.getUser())); return response; } } else if (command.equalsIgnoreCase("delmask")) { if (arguments.countTokens() != 1) { throw new ImproperUsageException(); } String mask = arguments.nextToken(); env.add("mask", mask); if (rslave.removeMask(mask)) { return new CommandResponse( 200, session.jprintf(_bundle, _keyPrefix + "slave.delmask.success", env, request.getUser())); } return new CommandResponse( 501, session.jprintf(_bundle, _keyPrefix + "slave.delmask.failed", env, request.getUser())); } else if (command.equalsIgnoreCase("shutdown")) { rslave.shutdown(); return StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); } throw new ImproperUsageException(); }