@@ -21,6 +21,7 @@ public class Sync {
2121 public volatile static boolean lastGeneralSyncSuccessful = false ;
2222 public static volatile boolean versionCompatible = false ;
2323 public volatile boolean success = false ;
24+ public volatile static boolean delayUpdate = false ;
2425 /** Stores a partial list of mappings from the operator reference name in the WebCTRL database to the operator username in the PostgreSQL database. */
2526 private final static HashMap <String ,String > refusernameCache = new HashMap <String ,String >();
2627 /**
@@ -30,7 +31,7 @@ public Sync(Event event, String... args){
3031 synchronized (Sync .class ){
3132 if (Initializer .stop && event !=Event .SHUTDOWN ){ return ; }
3233 try {
33- final boolean debug = "true" .equalsIgnoreCase (settings .get ("debug" ));
34+ boolean debug = "true" .equalsIgnoreCase (settings .get ("debug" ));
3435 final String url = "jdbc:postgresql://" +Config .connectionURL ;
3536 final String username = Config .username ;
3637 final String password = Config .password ;
@@ -72,6 +73,9 @@ public Sync(Event event, String... args){
7273 try (
7374 Statement s = con .createStatement ();
7475 ){
76+ if (debug ){
77+ Initializer .log (args [0 ]);
78+ }
7579 fillCache (args [0 ],s );
7680 }
7781 }
@@ -92,11 +96,18 @@ public Sync(Event event, String... args){
9296 for (int i =1 ;i <args .length ;++i ){
9397 if (Initializer .stop ){ return ; }
9498 if (debug ){
95- Initializer .log (args [i ]);
99+ if (args [i ].startsWith ("INSERT INTO webctrl.operator_whitelist" ) && !args [i ].contains ("{SSHA512}" )){
100+ Initializer .log ("INSERT INTO webctrl.operator_whitelist VALUES (***);" );
101+ }else {
102+ Initializer .log (args [i ]);
103+ }
96104 }
97105 s .executeUpdate (args [i ]);
98106 }
99107 con .commit ();
108+ if (debug ){
109+ Initializer .log (args [0 ]);
110+ }
100111 fillCache (args [0 ],s );
101112 }
102113 con .commit ();
@@ -133,7 +144,9 @@ public Sync(Event event, String... args){
133144 PreparedStatement s = con .prepareStatement ("DELETE FROM webctrl.operator_blacklist WHERE \" username\" = ?;" );
134145 ){
135146 s .setString (1 ,data .username );
136- s .executeUpdate ();
147+ if (s .executeUpdate ()>0 && debug ){
148+ Initializer .log ("Deleted " +data .username +" from operator_blacklist." );
149+ }
137150 }
138151 }
139152 try (
@@ -163,7 +176,9 @@ public Sync(Event event, String... args){
163176 PreparedStatement s = con .prepareStatement ("INSERT INTO webctrl.operator_blacklist VALUES(?);" );
164177 ){
165178 s .setString (1 ,oldUsername );
166- s .executeUpdate ();
179+ if (s .executeUpdate ()>0 && debug ){
180+ Initializer .log ("Inserted " +oldUsername +" into operator_blacklist." );
181+ }
167182 }
168183 }
169184 con .commit ();
@@ -211,23 +226,40 @@ public void execute(SystemAccess sys){
211226 }
212227 con .commit ();
213228 settings = map ;
229+ final boolean d = "true" .equalsIgnoreCase (map .get ("debug" ));
230+ if (d ^debug ){
231+ debug = d ;
232+ Initializer .log ("Debug mode " +(d ?"en" :"dis" )+"abled." );
233+ }
214234 v = map .get ("version" );
215235 final int ver = Utility .compareVersions (Initializer .addonVersion ,v );
216236 versionCompatible = ver >=0 ;
217- if (!versionCompatible ){
237+ if (versionCompatible ){
238+ delayUpdate = false ;
239+ }else {
218240 String update = map .get ("auto_update" );
219241 if (update !=null ){
220242 update = update .trim ();
221243 }
222244 if (update !=null && (update .equalsIgnoreCase ("true" ) || update .equalsIgnoreCase ("1" ))){
223- HelperAPI .selfUpdate ();
224- Initializer .log ("Attempting auto-update from v" +Initializer .addonVersion +" to v" +v );
225- Initializer .stop = true ;
226- success = true ;
245+ if (delayUpdate ){
246+ delayUpdate = false ;
247+ Initializer .log ("Warning - Infinite self-update loop detected." , true );
248+ }else if (HelperAPI .selfUpdate ()){
249+ Initializer .log ("Attempting auto-update from v" +Initializer .addonVersion +" to v" +v );
250+ Initializer .stop = true ;
251+ success = true ;
252+ return ;
253+ }else {
254+ Initializer .log ("Warning - Self-update function failed." , true );
255+ }
227256 }else {
228- Initializer .status = "Version Mismatch: " +Initializer .addonVersion +" != " +v ;
257+ String s = "Version Mismatch: " +Initializer .addonVersion +" != " +v ;
258+ Initializer .status = s ;
259+ if (debug ){
260+ Initializer .log (s );
261+ }
229262 }
230- return ;
231263 }
232264 }
233265 if (Initializer .stop ){ return ; }
@@ -475,7 +507,7 @@ public void execute(SystemAccess sys){
475507 if (!(t instanceof InterruptedException )){
476508 final String s = "Sync error during: " +event .name ();
477509 Initializer .status = s ;
478- Initializer .log (s );
510+ Initializer .log (s , true );
479511 Initializer .log (t );
480512 }
481513 }finally {
@@ -504,7 +536,7 @@ private int newServer(Connection con) throws Throwable {
504536 }
505537 if (ID <0 ){
506538 con .rollback ();
507- Initializer .log ("Failed to automatically set server ID." );
539+ Initializer .log ("Failed to automatically set server ID." , true );
508540 return -1 ;
509541 }else {
510542 con .commit ();
0 commit comments