Skip to content

Commit e7dc77b

Browse files
committed
mysql init
1 parent 79a9187 commit e7dc77b

File tree

3 files changed

+70
-31
lines changed

3 files changed

+70
-31
lines changed

fsd.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ password=disable
4747
location=Nowhere
4848
mode=normal
4949
certificates=cert.txt
50+
mysqlmode=false
51+
#sqlurl=jdbc:mysql://主机名或IP地址:端口号/数据库名称
52+
#sqluser=41857486
53+
#sqlpassword=74867486
5054
maxclients=200
5155
whazzup=whazzup.txt
5256
whazzupjson=whazzup.json

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@
8080
<artifactId>http</artifactId>
8181
<version>20070405</version>
8282
</dependency>
83+
<dependency>
84+
<groupId>mysql</groupId>
85+
<artifactId>mysql-connector-java</artifactId>
86+
<version>8.0.30</version>
87+
</dependency>
8388
</dependencies>
8489
<build>
8590
<defaultGoal>compile</defaultGoal>

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

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
package org.linktechtips;
77

8+
import org.apache.commons.lang3.StringUtils;
9+
import org.apache.commons.lang3.math.NumberUtils;
10+
import org.jetbrains.annotations.NotNull;
811
import org.linktechtips.constants.*;
912
import org.linktechtips.httpapi.httpApiManage;
1013
import org.linktechtips.manager.Manage;
@@ -23,9 +26,6 @@
2326
import org.linktechtips.process.network.ServerInterface;
2427
import org.linktechtips.process.network.SystemInterface;
2528
import org.linktechtips.support.Support;
26-
import org.apache.commons.lang3.StringUtils;
27-
import org.apache.commons.lang3.math.NumberUtils;
28-
import org.jetbrains.annotations.NotNull;
2929
import org.slf4j.Logger;
3030

3131
import java.io.File;
@@ -41,6 +41,7 @@
4141
import java.nio.file.attribute.BasicFileAttributes;
4242
import java.util.ArrayList;
4343
import java.util.List;
44+
import java.util.Objects;
4445
import java.util.Scanner;
4546

4647
import static org.slf4j.LoggerFactory.getLogger;
@@ -59,13 +60,18 @@ public class Main {
5960
private String certFile;
6061
private String whazzupFile;
6162
private String whazzupjsonFile;
63+
private String mysqlmode;
64+
private String sqlurl;
65+
private String sqluser;
66+
private String sqlpassword;
6267
private long timer;
6368
private long prevNotify;
6469
private long prevLagCheck;
6570
private long certFileStat;
6671
private int fileOpen;
6772
private long prevCertCheck;
6873
private long prevWhazzup;
74+
6975
public Main(String configFile) {
7076
LOGGER.info("[BetterFSD]: Booting Server");
7177
pManager = new PMan();
@@ -99,7 +105,7 @@ public Main(String configFile) {
99105
service.PlugunVersion()));
100106
service.PluginService();
101107
}
102-
LOGGER.info(String.format("[Plugins]: %s plugins loaded successfully",services.size()));
108+
LOGGER.info(String.format("[Plugins]: %s plugins loaded successfully", services.size()));
103109
} catch (MalformedURLException e) {
104110
LOGGER.error("[Plugins]: Failed to load plugins");
105111
e.printStackTrace();
@@ -110,8 +116,10 @@ public Main(String configFile) {
110116
prevWhazzup = Support.mtime();
111117
fileOpen = 0;
112118
}
119+
113120
public void close() {
114121
}
122+
115123
/* Here we do timeout checks. This function is triggered every second to
116124
reduce the load on the server */
117125
public void doChecks() {
@@ -396,20 +404,38 @@ private void configure() {
396404
if ((entry = system.getEntry("systemport")) != null) {
397405
systemPort = entry.getInt();
398406
}
399-
if ((entry = system.getEntry("certificates")) != null) {
400-
certFile = entry.getData();
407+
if ((entry = system.getEntry("mysqlmode")) != null) {
408+
mysqlmode = entry.getData();
409+
if (Objects.equals(mysqlmode, "false")) {
410+
if ((entry = system.getEntry("certificates")) != null) {
411+
certFile = entry.getData();
412+
}
413+
} else if (Objects.equals(mysqlmode, "true")) {
414+
if ((entry = system.getEntry("sqlurl")) != null) {
415+
sqlurl = entry.getData();
416+
}
417+
if ((entry = system.getEntry("sqluser")) != null) {
418+
sqluser = entry.getData();
419+
}
420+
if ((entry = system.getEntry("sqlpassword")) != null) {
421+
sqlpassword = entry.getData();
422+
}
423+
}
401424
}
402425
if ((entry = system.getEntry("whazzup")) != null) {
403426
whazzupFile = entry.getData();
404427
}
405428
if ((entry = system.getEntry("whazzupjson")) != null) {
406-
whazzupjsonFile= entry.getData();
429+
whazzupjsonFile = entry.getData();
407430
}
408-
}
409-
configMyServer();
410-
readCert();
411431
}
412432

433+
configMyServer();
434+
435+
readCert();
436+
437+
}
438+
413439
void handleCidLine(@NotNull String line) {
414440
Certificate tempcert;
415441
int mode, level;
@@ -438,30 +464,34 @@ void handleCidLine(@NotNull String line) {
438464
}
439465

440466
void readCert() {
441-
if (StringUtils.isBlank(certFile)) return;
467+
if (Objects.equals(mysqlmode, "false")) {
468+
if (StringUtils.isBlank(certFile)) return;
442469

443-
List<String> lines;
444-
File file = new File(certFile);
445-
try {
446-
lines = Files.readAllLines(Paths.get(certFile), StandardCharsets.UTF_8);
447-
} catch (IOException e) {
448-
LOGGER.error(String.format("[BetterFSD]: Could not open certificate file '%s'",
449-
file.getAbsolutePath()), e);
450-
return;
451-
}
470+
List<String> lines;
471+
File file = new File(certFile);
472+
try {
473+
lines = Files.readAllLines(Paths.get(certFile), StandardCharsets.UTF_8);
474+
} catch (IOException e) {
475+
LOGGER.error(String.format("[BetterFSD]: Could not open certificate file '%s'",
476+
file.getAbsolutePath()), e);
477+
return;
478+
}
452479

453-
for (Certificate temp : Certificate.certs) {
454-
temp.setLiveCheck(0);
455-
}
456-
LOGGER.info(String.format("[BetterFSD]: Reading certificates from '%s'", certFile));
457-
for (String line : lines) {
458-
handleCidLine(line);
459-
}
460-
for (Certificate temp : Certificate.certs) {
461-
if (temp.getLiveCheck() == 0) {
462-
serverInterface.sendCert("*", ProtocolConstants.CERT_DELETE, temp, null);
463-
temp.close();
480+
for (Certificate temp : Certificate.certs) {
481+
temp.setLiveCheck(0);
482+
}
483+
LOGGER.info(String.format("[BetterFSD]: Reading certificates from '%s'", certFile));
484+
for (String line : lines) {
485+
handleCidLine(line);
486+
}
487+
for (Certificate temp : Certificate.certs) {
488+
if (temp.getLiveCheck() == 0) {
489+
serverInterface.sendCert("*", ProtocolConstants.CERT_DELETE, temp, null);
490+
temp.close();
491+
}
464492
}
493+
} else if (Objects.equals(mysqlmode, "true")) {
494+
//TODO
465495
}
466496
}
467497

0 commit comments

Comments
 (0)