Skip to content

Commit 0d3c57e

Browse files
committed
mysql done(test pass)
1 parent 6e5c337 commit 0d3c57e

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<dependency>
5858
<groupId>ch.qos.logback</groupId>
5959
<artifactId>logback-classic</artifactId>
60-
<version>1.4.4</version>
60+
<version>1.2.3</version>
6161
</dependency>
6262
<dependency>
6363
<groupId>org.apache.commons</groupId>

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

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.Objects;
4747
import java.util.Scanner;
4848

49+
import static org.linktechtips.constants.GlobalConstants.CERT_FILE_CHECK;
4950
import static org.slf4j.LoggerFactory.getLogger;
5051

5152

@@ -93,6 +94,11 @@ public Main(String configFile) {
9394
/* Read the system configuration */
9495
configure();
9596
LOGGER.info("[Config]: Read System Configuration OK");
97+
if (mysqlmode.equals("true")) {
98+
LOGGER.info("[MySQL]: RUN ON MySQL Mode");
99+
}else{
100+
LOGGER.info("[BetterFSD]: RUN ON File Mode");
101+
}
96102
/* Create the management variables */
97103
createManageVars();
98104
LOGGER.info("[Management]: Management Variables OK");
@@ -140,7 +146,7 @@ public void doChecks() {
140146
serverInterface.sendPing("*", data);
141147
prevLagCheck = now;
142148
}
143-
if ((now - prevCertCheck) > GlobalConstants.CERT_FILE_CHECK) {
149+
if ((now - prevCertCheck) > CERT_FILE_CHECK) {
144150
ConfigEntry entry;
145151
ConfigGroup sysgroup = configManager.getGroup("system");
146152
if (sysgroup != null) {
@@ -487,7 +493,7 @@ public static void getConn() {
487493
Class.forName("com.mysql.cj.jdbc.Driver");
488494
conn = DriverManager.getConnection(sqlurl, sqluser, sqlpassword);
489495
} catch (ClassNotFoundException | SQLException e) {
490-
LOGGER.info("[BetterFSD]: Exception in get mysql conn");
496+
LOGGER.info("[MySQL]: Exception in get mysql conn");
491497
e.printStackTrace();
492498
}
493499
}
@@ -520,29 +526,33 @@ void readCert() {
520526
}
521527
} else if (Objects.equals(mysqlmode, "true")) {
522528
getConn();
523-
LOGGER.info("[BetterFSD]: Reading certificates from database");
529+
LOGGER.info("[MySQL]: Reading certificates from database");
524530
if (StringUtils.isEmpty(sqltable)) {
525-
LOGGER.error("[BetterFSD]: sqltable is empty. Please check your config file");
531+
LOGGER.error("[MySQL]: sqltable is empty. Please check your config file");
526532
} else if (sqltable != null) try {
527533
String sql = "SELECT * FROM " + sqltable;
528534
PreparedStatement ps = conn.prepareStatement(sql);
529535
ResultSet rs = ps.executeQuery();
536+
long now = Support.mgmtime();
530537
while (rs.next()) {
531-
String cid = rs.getString("cid");
532-
int level = rs.getInt("level");
533-
String pwd = rs.getString("password");
534-
Certificate tempcert = Certificate.getCert(cid);
535-
if (tempcert == null) {
536-
tempcert = new Certificate(cid, pwd, level, Support.mgmtime(), Server.myServer.getIdent());
537-
int mode = ProtocolConstants.CERT_ADD;
538-
if (serverInterface != null) serverInterface.sendCert("*", mode, tempcert, null);
539-
} else {
540-
tempcert.setLiveCheck(1);
541-
if (tempcert.getPassword().equalsIgnoreCase(pwd) && level == tempcert.getLevel())
542-
return;
543-
tempcert.configure(pwd, level, Support.mgmtime(), Server.myServer.getIdent());
544-
int mode = ProtocolConstants.CERT_MODIFY;
545-
if (serverInterface != null) serverInterface.sendCert("*", mode, tempcert, null);
538+
if ((now - prevCertCheck) >= CERT_FILE_CHECK) {
539+
prevCertCheck = now;
540+
String cid = rs.getString("cid");
541+
int level = rs.getInt("level");
542+
String pwd = rs.getString("password");
543+
Certificate tempcert = Certificate.getCert(cid);
544+
if (tempcert == null) {
545+
tempcert = new Certificate(cid, pwd, level, Support.mgmtime(), Server.myServer.getIdent());
546+
int mode = ProtocolConstants.CERT_ADD;
547+
if (serverInterface != null) serverInterface.sendCert("*", mode, tempcert, null);
548+
} else {
549+
tempcert.setLiveCheck(1);
550+
if (tempcert.getPassword().equalsIgnoreCase(pwd) && level == tempcert.getLevel())
551+
return;
552+
tempcert.configure(pwd, level, Support.mgmtime(), Server.myServer.getIdent());
553+
int mode = ProtocolConstants.CERT_MODIFY;
554+
if (serverInterface != null) serverInterface.sendCert("*", mode, tempcert, null);
555+
}
546556
}
547557
}
548558
for (Certificate temp : Certificate.certs) {
@@ -552,10 +562,10 @@ void readCert() {
552562
}
553563
}
554564
} catch (SQLException e) {
555-
LOGGER.error("[BetterFSD]: Exception in readCert");
565+
LOGGER.error("[MySQL]: Exception in readCert");
556566
e.printStackTrace();
557567
} catch (Exception e) {
558-
LOGGER.error("[BetterFSD]: N/A Exception on reading mysql");
568+
LOGGER.error("[MySQL]: N/A Exception on reading mysql");
559569
e.printStackTrace();
560570
}
561571
}

0 commit comments

Comments
 (0)