55
66package org .linktechtips ;
77
8+ import org .apache .commons .lang3 .StringUtils ;
9+ import org .apache .commons .lang3 .math .NumberUtils ;
10+ import org .jetbrains .annotations .NotNull ;
811import org .linktechtips .constants .*;
912import org .linktechtips .httpapi .httpApiManage ;
1013import org .linktechtips .manager .Manage ;
2326import org .linktechtips .process .network .ServerInterface ;
2427import org .linktechtips .process .network .SystemInterface ;
2528import 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 ;
2929import org .slf4j .Logger ;
3030
3131import java .io .File ;
4141import java .nio .file .attribute .BasicFileAttributes ;
4242import java .util .ArrayList ;
4343import java .util .List ;
44+ import java .util .Objects ;
4445import java .util .Scanner ;
4546
4647import 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