|
|
|
@ -112,19 +112,7 @@ public class ReplyService {
|
|
|
|
|
String reply = hashReplies.getProperty(o.get().getRight(), "").replace("\\r", "\r").replace("\\n", "\n")
|
|
|
|
|
.replace("\\t", "\t");
|
|
|
|
|
if (reply.isEmpty()) {
|
|
|
|
|
logger.info("[{}] Execute cmd for real: {} ({})", cmdHash, command.trim(), o.get());
|
|
|
|
|
ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
|
|
|
|
|
try {
|
|
|
|
|
CommandLine cmdLine = CommandLine.parse(command.trim());
|
|
|
|
|
DefaultExecutor executor = DefaultExecutor.builder().get();
|
|
|
|
|
PumpStreamHandler streamHandler = new PumpStreamHandler(tempOut);
|
|
|
|
|
executor.setStreamHandler(streamHandler);
|
|
|
|
|
int exitValue = executor.execute(cmdLine);
|
|
|
|
|
logger.info("[{}] Result: {} ({})", cmdHash, command.trim(), exitValue);
|
|
|
|
|
reply = new String(tempOut.toByteArray()).replace("\n", "\r\n");
|
|
|
|
|
} catch (ExecuteException e) {
|
|
|
|
|
logger.info("[{}] Execute cmd failed: {} ({})", cmdHash, command.trim(), o.get(), e);
|
|
|
|
|
}
|
|
|
|
|
reply = executeShellCommand(command.trim());
|
|
|
|
|
out.write(String.format("\r\n%s\r\n%s", reply, prompt).getBytes());
|
|
|
|
|
} else {
|
|
|
|
|
logger.info("[{}] Known pattern detected: {} ({})", cmdHash, command.trim(), o.get());
|
|
|
|
@ -139,4 +127,22 @@ public class ReplyService {
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String executeShellCommand(String command) throws IOException {
|
|
|
|
|
String cmdHash = DigestUtils.md5Hex(command.trim()).toUpperCase();
|
|
|
|
|
logger.info("[{}] Execute cmd for real: {}", cmdHash, command.trim());
|
|
|
|
|
ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
|
|
|
|
|
try {
|
|
|
|
|
CommandLine cmdLine = CommandLine.parse(command.trim());
|
|
|
|
|
DefaultExecutor executor = DefaultExecutor.builder().get();
|
|
|
|
|
PumpStreamHandler streamHandler = new PumpStreamHandler(tempOut);
|
|
|
|
|
executor.setStreamHandler(streamHandler);
|
|
|
|
|
int exitValue = executor.execute(cmdLine);
|
|
|
|
|
logger.info("[{}] Result: {} ({})", cmdHash, command.trim(), exitValue);
|
|
|
|
|
return new String(tempOut.toByteArray()).replace("\n", "\r\n");
|
|
|
|
|
} catch (ExecuteException e) {
|
|
|
|
|
logger.info("[{}] Execute cmd failed: {}", cmdHash, command.trim(), e);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|