@@ -525,16 +525,35 @@ void readCert() {
525525 LOGGER .error ("[BetterFSD]: sqltable is empty. Please check your config file" );
526526 } else if (sqltable != null ) try {
527527 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 );
528+ PreparedStatement ps = conn .prepareStatement (sql );
529+ ResultSet rs = ps .executeQuery ();
530+ 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 );
546+ }
534547 }
535- preparedStatement .close ();
536- resultSet .close ();
537- conn .close ();
548+ for (Certificate temp : Certificate .certs ) {
549+ if (temp .getLiveCheck () == 0 ) {
550+ serverInterface .sendCert ("*" , ProtocolConstants .CERT_DELETE , temp , null );
551+ temp .close ();
552+ }
553+ }
554+ } catch (SQLException e ) {
555+ LOGGER .error ("[BetterFSD]: Exception in readCert" );
556+ e .printStackTrace ();
538557 } catch (Exception e ) {
539558 LOGGER .error ("[BetterFSD]: N/A Exception on reading mysql" );
540559 e .printStackTrace ();
0 commit comments