|
|
|
@ -36,15 +36,33 @@ public class ReplyService {
|
|
|
|
|
@Autowired
|
|
|
|
|
Map<String, String> ipInfoMapping;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
JdbcService jdbcService;
|
|
|
|
|
|
|
|
|
|
public boolean replyToCommand(String command, OutputStream out, String prompt, ServerSession session)
|
|
|
|
|
throws IOException {
|
|
|
|
|
|
|
|
|
|
String cmdHash = DigestUtils.md5Hex(command.trim()).toUpperCase();
|
|
|
|
|
if (StringUtils.equals(command.trim(), "about")) {
|
|
|
|
|
logger.info("[{}] About command detected: {}", cmdHash, command.trim());
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(command.trim(), "my_geolocation")) {
|
|
|
|
|
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)
|
|
|
|
|
.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());
|
|
|
|
|
out.write(String.format("\r\nExiting...\r\n%s", prompt).getBytes());
|
|
|
|
|
return true;
|
|
|
|
|