diff --git a/.gitignore b/.gitignore
index da7a791..a9cac65 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
/.project
/.settings/
/logs/
+/data/
diff --git a/conf/springboot.yml b/conf/springboot.yml
index 6fd22eb..b9a5160 100644
--- a/conf/springboot.yml
+++ b/conf/springboot.yml
@@ -7,3 +7,6 @@ ssh-server:
regex-mapping:
location: "conf/regex-mapping.properties"
+spring:
+ datasource:
+ url: "jdbc:h2:file:./data/remote-ip-info-db"
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d4b8507..d8b115c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.example.sshd
echo-sshd-server
- 1.3.0
+ 1.4.0
ECHO SSH SERVER
Learning Apache Mina SSHD library
@@ -13,10 +13,11 @@
3.3.2
+ 17
2.0.25
0.14.0
- 1.78.1
2.13.0
+ 1.4.0
@@ -33,6 +34,20 @@
org.springframework.boot
spring-boot-starter-log4j2
+
+ org.springframework.boot
+ spring-boot-starter-data-jdbc
+
+
+ com.h2database
+ h2
+ runtime
+
+
+ org.apache.commons
+ commons-exec
+ ${commons-exec.version}
+
commons-codec
commons-codec
@@ -47,16 +62,6 @@
sshd-core
${sshd.version}
-
- org.bouncycastle
- bcprov-jdk18on
- ${bouncycastle.version}
-
-
- org.bouncycastle
- bcpkix-jdk18on
- ${bouncycastle.version}
-
commons-io
commons-io
@@ -77,8 +82,8 @@
org.apache.maven.plugins
maven-compiler-plugin
-
- 17
+
+ ${java.version}
diff --git a/src/main/java/com/example/sshd/core/EchoSessionListener.java b/src/main/java/com/example/sshd/core/EchoSessionListener.java
index 28f5788..f842e9a 100644
--- a/src/main/java/com/example/sshd/core/EchoSessionListener.java
+++ b/src/main/java/com/example/sshd/core/EchoSessionListener.java
@@ -1,6 +1,7 @@
package com.example.sshd.core;
import java.net.InetSocketAddress;
+import java.util.List;
import java.util.Map;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
@@ -15,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
+import com.example.sshd.service.JdbcService;
+
@Component
public class EchoSessionListener implements SessionListener {
@@ -30,6 +33,9 @@ public class EchoSessionListener implements SessionListener {
@Autowired
CloseableHttpAsyncClient asyncClient;
+ @Autowired
+ JdbcService jdbcService;
+
@Value("${ssh-server.ip-info-api.url:http://ip-api.com/json/%s}")
private String ipInfoApiUrl;
@@ -48,6 +54,12 @@ public class EchoSessionListener implements SessionListener {
}
logger.info("new session: {} -> {}", remoteIpAddress, session);
remoteSessionMapping.put(remoteIpAddress, session);
+ if (!ipInfoMapping.containsKey(remoteIpAddress)) {
+ List