Exemplo n.º 1
0
  // PROTOBUF
  private CommandInfo ParseCommand(Command command, ClientManager clientManager) {
    CommandInfo cmdInfo = new CommandInfo();
    java.util.HashMap eventList = new java.util.HashMap();
    SyncEventsCommandProtocol.SyncEventsCommand syncEventsCommand = command.getSyncEventsCommand();
    java.util.ArrayList<EventIdCommand> eventIds =
        (java.util.ArrayList) syncEventsCommand.getEventIdsList();
    com.alachisoft.tayzgrid.caching.EventId cacheEventId = null;

    for (EventIdCommand eventId : eventIds) {
      cacheEventId = new com.alachisoft.tayzgrid.caching.EventId();
      cacheEventId.setEventUniqueID(eventId.getEventUniqueId());
      cacheEventId.setEventCounter(eventId.getEventCounter());
      cacheEventId.setOperationCounter(eventId.getOperationCounter());
      cacheEventId.setEventType((EventType.forValue(eventId.getEventType())));
      cacheEventId.setQueryChangeType((QueryChangeType.forValue(eventId.getQueryChangeType())));
      cacheEventId.setQueryId(eventId.getQueryId());

      if (cacheEventId.getQueryId() != null) {
        cacheEventId.setQueryId(null);
      }

      eventList.put(cacheEventId, null);
    }
    cmdInfo.EventsList = eventList;
    cmdInfo.RequestId = Long.toString(syncEventsCommand.getRequestId());
    return cmdInfo;
  }
Exemplo n.º 2
0
  /**
   * List all the available MobArena commands for the CommandSender.
   *
   * @param sender a player or the console
   */
  private void showHelp(CommandSender sender) {
    StringBuilder user = new StringBuilder();
    StringBuilder admin = new StringBuilder();

    for (Command cmd : commands.values()) {
      CommandInfo info = cmd.getClass().getAnnotation(CommandInfo.class);
      if (!PermHandler.hasPerm(sender, info.permission())) continue;

      StringBuilder buffy;
      if (info.permission().contains("admin")) buffy = admin;
      else buffy = user;

      buffy
          .append("\n")
          .append(ChatColor.RESET)
          .append(info.usage())
          .append(" ")
          .append(ChatColor.YELLOW)
          .append(info.desc());
    }

    if (admin.length() == 0) {
      Messenger.sendMessage(sender, "Available Commands: " + user.toString());
    } else {
      Messenger.sendMessage(sender, "User Commands: " + user.toString());
      Messenger.sendMessage(sender, "Admin Commands: " + admin.toString());
    }
  }
Exemplo n.º 3
0
  /**
   * Show the usage and description messages of a command to a player. The usage will only be shown,
   * if the player has permission for the command.
   *
   * @param cmd a Command
   * @param sender a CommandSender
   */
  private void showUsage(Command cmd, CommandSender sender, boolean prefix) {
    CommandInfo info = cmd.getClass().getAnnotation(CommandInfo.class);
    if (!PermHandler.hasPerm(sender, info.permission())) return;

    sender.sendMessage(
        (prefix ? "Usage: " : "") + info.usage() + " " + ChatColor.YELLOW + info.desc());
  }
Exemplo n.º 4
0
    public CommandInfo clone() {
      CommandInfo varCopy = new CommandInfo();

      varCopy.EventsList = this.EventsList;
      varCopy.CommandVersion = this.CommandVersion;
      varCopy.RequestId = this.RequestId;

      return varCopy;
    }
Exemplo n.º 5
0
 private void sendSpecificHelp(CommandSender sender, String rootCommand, String modifier)
     throws CommandException {
   CommandInfo info = getCommand(rootCommand, modifier);
   if (info == null)
     throw new CommandException(CommandMessages.COMMAND_MISSING, rootCommand + " " + modifier);
   Messaging.send(sender, format(info.getCommandAnnotation(), rootCommand));
   String help = Messaging.tryTranslate(info.getCommandAnnotation().help());
   if (help.isEmpty()) return;
   Messaging.send(sender, ChatColor.AQUA + help);
 }
 @Override
 public void processCommand(ICommandSender var1, String[] var2) {
   try {
     CommandInfo inf = (new CommandInfo());
     inf.setInfo(0, 0);
     FunctionHandler.instance.delCommand(inf, this.getCommandSenderAsPlayer(var1));
   } catch (Exception e) {
     this.getCommandSenderAsPlayer(var1).addChatMessage("Delete Command Failed!(Unknown Reason)");
   }
 }
Exemplo n.º 7
0
  /**
   * Register a command. The Command's CommandInfo annotation is queried to find its pattern string,
   * which is used to map the commands.
   *
   * @param c a Command
   */
  public void register(Class<? extends Command> c) {
    CommandInfo info = c.getAnnotation(CommandInfo.class);
    if (info == null) return;

    try {
      commands.put(info.pattern(), c.newInstance());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 8
0
 private List<String> getLines(CommandSender sender, String baseCommand) {
   // Ensures that commands with multiple modifiers are only added once
   Set<CommandInfo> processed = Sets.newHashSet();
   List<String> lines = new ArrayList<String>();
   for (CommandInfo info : getCommands(baseCommand)) {
     Command command = info.getCommandAnnotation();
     if (processed.contains(info)
         || (!sender.hasPermission("citizens.admin")
             && !sender.hasPermission("citizens." + command.permission()))) continue;
     lines.add(format(command, baseCommand));
     if (command.modifiers().length > 1) {
       processed.add(info);
     }
   }
   return lines;
 }
Exemplo n.º 9
0
  /**
   * This will execute the given command with given session and session is not closed at the end.
   *
   * @param commandInfo
   * @param session
   * @param commandOutput
   * @throws SSHApiException
   */
  public static Session executeCommand(
      CommandInfo commandInfo, Session session, CommandOutput commandOutput)
      throws SSHApiException {

    String command = commandInfo.getCommand();

    Channel channel = null;
    try {
      if (!session.isConnected()) {
        session.connect();
      }
      channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);
    } catch (JSchException e) {
      session.disconnect();

      throw new SSHApiException("Unable to execute command - ", e);
    }

    channel.setInputStream(null);
    ((ChannelExec) channel).setErrStream(commandOutput.getStandardError());
    try {
      channel.connect();
    } catch (JSchException e) {

      channel.disconnect();
      session.disconnect();
      throw new SSHApiException("Unable to retrieve command output. Command - " + command, e);
    }

    commandOutput.onOutput(channel);
    // Only disconnecting the channel, session can be reused
    channel.disconnect();
    return session;
  }
Exemplo n.º 10
0
 private Command instantiateCommand() throws ModuleException {
   try {
     return info.createInstance();
   } catch (final InstantiableException exc) {
     throw new ModuleException(exc);
   }
 }
Exemplo n.º 11
0
 private void assignPresets() {
   final Map<String, Object> presets = info.getPresets();
   for (final String name : presets.keySet()) {
     final Object value = presets.get(name);
     setInput(name, value);
     setResolved(name, true);
   }
 }
Exemplo n.º 12
0
  // 向前台发送楼层统计信息[ztl 20140909]
  public void SendCommandValue(CommandInfo commandInfo) {
    //		logger.info(commandInfo);

    if (logger.isTraceEnabled()) {
      //			logger.trace("Sending commandInfo " + commandInfo);
    }
    if (this.brokerAvailable.get()) {
      this.messagingTemplate.convertAndSend("/topic/buildinfo." + commandInfo.getP1(), commandInfo);
    }
  }
Exemplo n.º 13
0
  /**
   * A convenience method that takes a CommandInfo object and instantiates the corresponding
   * command, usually a JavaBean component.
   *
   * <p>This method calls the CommandInfo's <code>getCommandObject</code> method with the <code>
   * ClassLoader</code> used to load the <code>javax.activation.DataHandler</code> class itself.
   *
   * @param cmdinfo the CommandInfo corresponding to a command
   * @return the instantiated command object
   */
  public Object getBean(CommandInfo cmdinfo) {
    Object bean = null;

    try {
      // make the bean
      ClassLoader cld = null;
      // First try the "application's" class loader.
      cld = SecuritySupport.getContextClassLoader();
      if (cld == null) cld = this.getClass().getClassLoader();
      bean = cmdinfo.getCommandObject(this, cld);
    } catch (IOException e) {
    } catch (ClassNotFoundException e) {
    }

    return bean;
  }
Exemplo n.º 14
0
 public boolean register(List<CommandInfo> registered) {
   CommandMap commandMap = getCommandMap();
   if (registered == null || commandMap == null) {
     return false;
   }
   for (CommandInfo command : registered) {
     DynamicPluginCommand cmd =
         new DynamicPluginCommand(
             command.getAliases(),
             command.getDesc(),
             "/" + command.getAliases()[0] + " " + command.getUsage(),
             executor,
             command.getRegisteredWith(),
             plugin);
     cmd.setPermissions(command.getPermissions());
     commandMap.register(plugin.getDescription().getName(), cmd);
   }
   return true;
 }
Exemplo n.º 15
0
  public void buildDogCommand() {
    if (commands != null) {
      for (CommandInfo info : commands) {
        HouseCommandParse.getInstanse().removeContent(info.getCommandName());
      }
    }
    commands = getCommands();

    if (commands != null) {
      for (CommandInfo info : commands) {
        LogManager.e("dog's command :" + info.getCommandName());
        HouseCommandParse.getInstanse()
            .addContent(info.getCommandName(), info.getCommandContent(), DogClient.TYPE);
      }
    }
  }
Exemplo n.º 16
0
 @Override
 public Object getOutput(final String name) {
   final CommandModuleItem<?> item = info.getOutput(name);
   return ClassUtils.getValue(item.getField(), command);
 }
Exemplo n.º 17
0
  /**
   * This will not reuse any session, it will create the session and close it at the end
   *
   * @param commandInfo Encapsulated information about command. E.g :- executable name parameters
   *     etc ...
   * @param serverInfo The SSHing server information.
   * @param authenticationInfo Security data needs to be communicated with remote server.
   * @param commandOutput The output of the command.
   * @param configReader configuration required for ssh/gshissh connection
   * @throws SSHApiException throw exception when error occurs
   */
  public static void executeCommand(
      CommandInfo commandInfo,
      ServerInfo serverInfo,
      AuthenticationInfo authenticationInfo,
      CommandOutput commandOutput,
      ConfigReader configReader)
      throws SSHApiException {

    if (authenticationInfo instanceof GSIAuthenticationInfo) {
      System.setProperty(
          X509_CERT_DIR,
          (String)
              ((GSIAuthenticationInfo) authenticationInfo).getProperties().get("X509_CERT_DIR"));
    }

    JSch jsch = new ExtendedJSch();

    log.debug(
        "Connecting to server - "
            + serverInfo.getHost()
            + ":"
            + serverInfo.getPort()
            + " with user name - "
            + serverInfo.getUserName());

    Session session;

    try {
      session =
          jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort());
    } catch (JSchException e) {
      throw new SSHApiException(
          "An exception occurred while creating SSH session."
              + "Connecting server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    java.util.Properties config = configReader.getProperties();
    session.setConfig(config);

    // =============================================================
    // Handling vanilla SSH pieces
    // =============================================================
    if (authenticationInfo instanceof SSHPasswordAuthentication) {
      String password =
          ((SSHPasswordAuthentication) authenticationInfo)
              .getPassword(serverInfo.getUserName(), serverInfo.getHost());

      session.setUserInfo(new SSHAPIUIKeyboardInteractive(password));

      // TODO figure out why we need to set password to session
      session.setPassword(password);

    } else if (authenticationInfo instanceof SSHPublicKeyFileAuthentication) {
      SSHPublicKeyFileAuthentication sshPublicKeyFileAuthentication =
          (SSHPublicKeyFileAuthentication) authenticationInfo;

      String privateKeyFile =
          sshPublicKeyFileAuthentication.getPrivateKeyFile(
              serverInfo.getUserName(), serverInfo.getHost());

      logDebug("The private key file for vanilla SSH " + privateKeyFile);

      String publicKeyFile =
          sshPublicKeyFileAuthentication.getPrivateKeyFile(
              serverInfo.getUserName(), serverInfo.getHost());

      logDebug("The public key file for vanilla SSH " + publicKeyFile);

      Identity identityFile;

      try {
        identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, jsch);
      } catch (JSchException e) {
        throw new SSHApiException(
            "An exception occurred while initializing keys using files. "
                + "(private key and public key)."
                + "Connecting server - "
                + serverInfo.getHost()
                + ":"
                + serverInfo.getPort()
                + " connecting user name - "
                + serverInfo.getUserName()
                + " private key file - "
                + privateKeyFile
                + ", public key file - "
                + publicKeyFile,
            e);
      }

      // Add identity to identity repository
      GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch);
      identityRepository.add(identityFile);

      // Set repository to session
      session.setIdentityRepository(identityRepository);

      // Set the user info
      SSHKeyPasswordHandler sshKeyPasswordHandler =
          new SSHKeyPasswordHandler((SSHKeyAuthentication) authenticationInfo);

      session.setUserInfo(sshKeyPasswordHandler);

    } else if (authenticationInfo instanceof SSHPublicKeyAuthentication) {

      SSHPublicKeyAuthentication sshPublicKeyAuthentication =
          (SSHPublicKeyAuthentication) authenticationInfo;

      Identity identityFile;

      try {
        String name = serverInfo.getUserName() + "_" + serverInfo.getHost();
        identityFile =
            GSISSHIdentityFile.newInstance(
                name,
                sshPublicKeyAuthentication.getPrivateKey(
                    serverInfo.getUserName(), serverInfo.getHost()),
                sshPublicKeyAuthentication.getPublicKey(
                    serverInfo.getUserName(), serverInfo.getHost()),
                jsch);
      } catch (JSchException e) {
        throw new SSHApiException(
            "An exception occurred while initializing keys using byte arrays. "
                + "(private key and public key)."
                + "Connecting server - "
                + serverInfo.getHost()
                + ":"
                + serverInfo.getPort()
                + " connecting user name - "
                + serverInfo.getUserName(),
            e);
      }

      // Add identity to identity repository
      GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch);
      identityRepository.add(identityFile);

      // Set repository to session
      session.setIdentityRepository(identityRepository);

      // Set the user info
      SSHKeyPasswordHandler sshKeyPasswordHandler =
          new SSHKeyPasswordHandler((SSHKeyAuthentication) authenticationInfo);

      session.setUserInfo(sshKeyPasswordHandler);
    }

    // Not a good way, but we dont have any choice
    if (session instanceof ExtendedSession) {
      if (authenticationInfo instanceof GSIAuthenticationInfo) {
        ((ExtendedSession) session)
            .setAuthenticationInfo((GSIAuthenticationInfo) authenticationInfo);
      }
    }

    try {
      session.connect();
    } catch (JSchException e) {
      throw new SSHApiException(
          "An exception occurred while connecting to server."
              + "Connecting server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    String command = commandInfo.getCommand();

    Channel channel;
    try {
      channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);
    } catch (JSchException e) {
      session.disconnect();

      throw new SSHApiException(
          "Unable to execute command - "
              + command
              + " on server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    channel.setInputStream(null);
    ((ChannelExec) channel).setErrStream(commandOutput.getStandardError());

    try {
      channel.connect();
    } catch (JSchException e) {

      channel.disconnect();
      session.disconnect();

      throw new SSHApiException(
          "Unable to retrieve command output. Command - "
              + command
              + " on server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    commandOutput.onOutput(channel);

    channel.disconnect();
    session.disconnect();
  }
Exemplo n.º 18
0
  @Override
  public boolean onCommand(
      CommandSender sender, org.bukkit.command.Command bcmd, String label, String[] args) {
    // Grab the base and arguments.
    String base = bcmd.getName();
    // String base = (args.length > 0 ? args[0] : "");
    String last = (args.length > 0 ? args[args.length - 1] : "");

    // If there's no base argument, show a helpful message.
    if (base.equals("")) {
      Messenger.sendMessage(sender, "/rpge help|?");
      return true;
    }

    // The help command is a little special
    if (base.equals("?") || base.equalsIgnoreCase("help")) {
      showHelp(sender);
      return true;
    }

    // Get all commands that match the base.
    List<Command> matches = getMatchingCommands(base);

    // If there's more than one match, display them.
    if (matches.size() > 1) {
      Messenger.sendMessage(sender, "Multiple command matches");
      for (Command cmd : matches) {
        showUsage(cmd, sender, false);
      }
      return true;
    }

    // If there are no matches at all, notify.
    if (matches.size() == 0) {
      Messenger.sendMessage(sender, "Command not found");
      return true;
    }

    // Grab the only match.
    Command command = matches.get(0);
    CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);

    // First check if the sender has permission.
    if (!PermHandler.hasPerm(sender, info.permission())) {
      Messenger.sendMessage(sender, "No Permission");
      return true;
    }

    // Check if the last argument is a ?, in which case, display usage and description
    if (last.equals("?") || last.equals("help")) {
      showUsage(command, sender, true);
      return true;
    }

    // Otherwise, execute the command!
    String[] params = args; // trimFirstArg(args);
    if (!command.execute(plugin, sender, params)) {
      showUsage(command, sender, true);
    }
    return true;
  }
Exemplo n.º 19
0
 @Override
 public void setOutput(final String name, final Object value) {
   final CommandModuleItem<?> item = info.getOutput(name);
   ClassUtils.setValue(item.getField(), command, value);
 }