|
|
@ -36,15 +36,33 @@ public class ReplyService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
Map<String, String> ipInfoMapping;
|
|
|
|
Map<String, String> ipInfoMapping;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
JdbcService jdbcService;
|
|
|
|
|
|
|
|
|
|
|
|
public boolean replyToCommand(String command, OutputStream out, String prompt, ServerSession session)
|
|
|
|
public boolean replyToCommand(String command, OutputStream out, String prompt, ServerSession session)
|
|
|
|
throws IOException {
|
|
|
|
throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
String cmdHash = DigestUtils.md5Hex(command.trim()).toUpperCase();
|
|
|
|
String cmdHash = DigestUtils.md5Hex(command.trim()).toUpperCase();
|
|
|
|
if (StringUtils.equals(command.trim(), "about")) {
|
|
|
|
if (StringUtils.equalsIgnoreCase(command.trim(), "my_geolocation")) {
|
|
|
|
logger.info("[{}] About command detected: {}", cmdHash, command.trim());
|
|
|
|
logger.info("[{}] my_geolocation command detected: {}", cmdHash, command.trim());
|
|
|
|
out.write(String.format("\r\n%s\r\n%s", ipInfoMapping.get(Thread.currentThread().getName()), prompt)
|
|
|
|
out.write(String.format("\r\n%s\r\n%s", ipInfoMapping.get(Thread.currentThread().getName()), prompt)
|
|
|
|
.getBytes());
|
|
|
|
.getBytes());
|
|
|
|
} else if (StringUtils.equals(command.trim(), "exit")) {
|
|
|
|
} else if (StringUtils.equalsIgnoreCase(command.trim(), "whoami")) {
|
|
|
|
|
|
|
|
logger.info("[{}] whoami command detected: {}", cmdHash, command.trim());
|
|
|
|
|
|
|
|
out.write(String.format("\r\n%s\r\n%s", session.getUsername(), prompt).getBytes());
|
|
|
|
|
|
|
|
} else if (StringUtils.equalsIgnoreCase(command.trim(), "online_geolocations")) {
|
|
|
|
|
|
|
|
logger.info("[{}] online_geolocations command detected: {}", cmdHash, command.trim());
|
|
|
|
|
|
|
|
out.write(String.format("\r\n%s\r\n%s", ipInfoMapping.toString(), prompt).getBytes());
|
|
|
|
|
|
|
|
} else if (StringUtils.split(command.trim(), " ").length == 2
|
|
|
|
|
|
|
|
&& StringUtils.equalsIgnoreCase(StringUtils.split(command.trim(), " ")[0], "get_geolocation")) {
|
|
|
|
|
|
|
|
logger.info("[{}] get_geolocation command detected: {}", cmdHash, command.trim());
|
|
|
|
|
|
|
|
out.write(String.format("\r\n%s\r\n%s",
|
|
|
|
|
|
|
|
jdbcService.getRemoteIpInfo(StringUtils.split(command.trim(), " ")[1]), prompt).getBytes());
|
|
|
|
|
|
|
|
} else if (StringUtils.equalsIgnoreCase(command.trim(), "all_geolocations")) {
|
|
|
|
|
|
|
|
logger.info("[{}] all_geolocations command detected: {}", cmdHash, command.trim());
|
|
|
|
|
|
|
|
out.write(String.format("\r\n%s\r\n%s", jdbcService.getAllRemoteIpInfo(), prompt).getBytes());
|
|
|
|
|
|
|
|
} else if (StringUtils.equalsIgnoreCase(command.trim(), "exit")
|
|
|
|
|
|
|
|
|| StringUtils.equalsIgnoreCase(command.trim(), "quit")) {
|
|
|
|
logger.info("[{}] Exiting command detected: {}", cmdHash, command.trim());
|
|
|
|
logger.info("[{}] Exiting command detected: {}", cmdHash, command.trim());
|
|
|
|
out.write(String.format("\r\nExiting...\r\n%s", prompt).getBytes());
|
|
|
|
out.write(String.format("\r\nExiting...\r\n%s", prompt).getBytes());
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|