46
46
import java .util .Objects ;
47
47
import java .util .Scanner ;
48
48
49
+ import static org .linktechtips .constants .GlobalConstants .CERT_FILE_CHECK ;
49
50
import static org .slf4j .LoggerFactory .getLogger ;
50
51
51
52
@@ -93,6 +94,11 @@ public Main(String configFile) {
93
94
/* Read the system configuration */
94
95
configure ();
95
96
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
+ }
96
102
/* Create the management variables */
97
103
createManageVars ();
98
104
LOGGER .info ("[Management]: Management Variables OK" );
@@ -140,7 +146,7 @@ public void doChecks() {
140
146
serverInterface .sendPing ("*" , data );
141
147
prevLagCheck = now ;
142
148
}
143
- if ((now - prevCertCheck ) > GlobalConstants . CERT_FILE_CHECK ) {
149
+ if ((now - prevCertCheck ) > CERT_FILE_CHECK ) {
144
150
ConfigEntry entry ;
145
151
ConfigGroup sysgroup = configManager .getGroup ("system" );
146
152
if (sysgroup != null ) {
@@ -487,7 +493,7 @@ public static void getConn() {
487
493
Class .forName ("com.mysql.cj.jdbc.Driver" );
488
494
conn = DriverManager .getConnection (sqlurl , sqluser , sqlpassword );
489
495
} catch (ClassNotFoundException | SQLException e ) {
490
- LOGGER .info ("[BetterFSD ]: Exception in get mysql conn" );
496
+ LOGGER .info ("[MySQL ]: Exception in get mysql conn" );
491
497
e .printStackTrace ();
492
498
}
493
499
}
@@ -520,29 +526,33 @@ void readCert() {
520
526
}
521
527
} else if (Objects .equals (mysqlmode , "true" )) {
522
528
getConn ();
523
- LOGGER .info ("[BetterFSD ]: Reading certificates from database" );
529
+ LOGGER .info ("[MySQL ]: Reading certificates from database" );
524
530
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" );
526
532
} else if (sqltable != null ) try {
527
533
String sql = "SELECT * FROM " + sqltable ;
528
534
PreparedStatement ps = conn .prepareStatement (sql );
529
535
ResultSet rs = ps .executeQuery ();
536
+ long now = Support .mgmtime ();
530
537
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
+ }
546
556
}
547
557
}
548
558
for (Certificate temp : Certificate .certs ) {
@@ -552,10 +562,10 @@ void readCert() {
552
562
}
553
563
}
554
564
} catch (SQLException e ) {
555
- LOGGER .error ("[BetterFSD ]: Exception in readCert" );
565
+ LOGGER .error ("[MySQL ]: Exception in readCert" );
556
566
e .printStackTrace ();
557
567
} catch (Exception e ) {
558
- LOGGER .error ("[BetterFSD ]: N/A Exception on reading mysql" );
568
+ LOGGER .error ("[MySQL ]: N/A Exception on reading mysql" );
559
569
e .printStackTrace ();
560
570
}
561
571
}
0 commit comments