Skip to content

Commit fef96ef

Browse files
committed
mysql done
1 parent d67f396 commit fef96ef

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

fsd.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ mode=normal
4949
certificates=cert.txt
5050
mysqlmode=false
5151
#sqlurl=jdbc:mysql://主机名或IP地址:端口号/数据库名称
52+
#sqltable=BetterFSD
5253
#sqluser=41857486
5354
#sqlpassword=74867486
5455
maxclients=200

src/main/java/org/linktechtips/Main.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.linktechtips.process.network.SystemInterface;
2828
import org.linktechtips.support.Support;
2929
import org.slf4j.Logger;
30-
import java.sql.Connection;
31-
import java.sql.DriverManager;
30+
31+
import java.sql.*;
3232

3333
import java.io.File;
3434
import java.io.FileOutputStream;
@@ -64,6 +64,7 @@ public class Main {
6464
private String whazzupjsonFile;
6565
private String mysqlmode;
6666
private static String sqlurl;
67+
private static String sqltable;
6768
private static String sqluser;
6869
private static String sqlpassword;
6970
private static Connection conn = null;
@@ -433,6 +434,9 @@ private void configure() {
433434
if ((entry = system.getEntry("sqlurl")) != null) {
434435
sqlurl = entry.getData();
435436
}
437+
if ((entry = system.getEntry("sqltable")) != null) {
438+
sqltable = entry.getData();
439+
}
436440
if ((entry = system.getEntry("sqluser")) != null) {
437441
sqluser = entry.getData();
438442
}
@@ -448,11 +452,8 @@ private void configure() {
448452
whazzupjsonFile = entry.getData();
449453
}
450454
}
451-
452455
configMyServer();
453-
454456
readCert();
455-
456457
}
457458

458459
void handleCidLine(@NotNull String line) {
@@ -481,16 +482,14 @@ void handleCidLine(@NotNull String line) {
481482
}
482483
if (serverInterface != null) serverInterface.sendCert("*", mode, tempcert, null);
483484
}
484-
public static Connection getConn() {
485+
public static void getConn() {
485486
try {
486487
Class.forName("com.mysql.cj.jdbc.Driver");
487488
conn = DriverManager.getConnection(sqlurl, sqluser, sqlpassword);
488-
LOGGER.info("[BetterFSD]: Database connection established");
489-
} catch (Exception e) {
490-
LOGGER.error("[BetterFSD]: N/A Exception on loading mysql");
489+
} catch (ClassNotFoundException | SQLException e) {
490+
LOGGER.info("[BetterFSD]: Exception in get mysql conn");
491491
e.printStackTrace();
492492
}
493-
return conn;
494493
}
495494
void readCert() {
496495
if (Objects.equals(mysqlmode, "false")) {
@@ -521,6 +520,25 @@ void readCert() {
521520
}
522521
} else if (Objects.equals(mysqlmode, "true")) {
523522
getConn();
523+
LOGGER.info("[BetterFSD]: Reading certificates from database");
524+
if (StringUtils.isEmpty(sqltable)) {
525+
LOGGER.error("[BetterFSD]: sqltable is empty. Please check your config file");
526+
} else if (sqltable != null) try {
527+
String sql = "SELECT * FROM " + sqltable;
528+
PreparedStatement preparedStatement = conn.prepareStatement(sql);
529+
ResultSet resultSet = preparedStatement.executeQuery();
530+
while (resultSet.next()) {
531+
Certificate tempcert = new Certificate(resultSet.getString("cid"), resultSet.getString("password"),
532+
resultSet.getInt("level"), Support.mgmtime(), Server.myServer.getIdent());
533+
serverInterface.sendCert("*", ProtocolConstants.CERT_ADD, tempcert, null);
534+
}
535+
preparedStatement.close();
536+
resultSet.close();
537+
conn.close();
538+
} catch (Exception e) {
539+
LOGGER.error("[BetterFSD]: N/A Exception on reading mysql");
540+
e.printStackTrace();
541+
}
524542
}
525543
}
526544

0 commit comments

Comments
 (0)