]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/usercmds/cleanupdb.c
Add cleanupdb channel implementation.
[irc/quakenet/newserv.git] / chanserv / usercmds / cleanupdb.c
index 70785719ed97a57fb6cdb4f3b4a011d33da1b4a5..b66921110ae37b87fa0d63b9d7057a8d0c8bce38 100644 (file)
@@ -8,8 +8,7 @@
  * CMDFUNC: csu_docleanupdb
  * CMDPROTO: int csu_docleanupdb(void *source, int cargc, char **cargv);
  * CMDHELP: Usage: cleanupdb
- * CMDHELP: Removes unused and never used accounts that exceed the idleness
- * CMDHELP: thresholds.
+ * CMDHELP: Cleans up inactive accounts, unused accounts and inactive channels.
  */
 
 #include "../chanserv.h"
 
 int csu_docleanupdb(void *source, int cargc, char **cargv) {
   nick *sender=source;
-  reguser *vrup, *srup;
+  reguser *vrup, *srup, *founder;
   authname *anp;
   int i;
   time_t t;
-  long to_age, unused_age;
-  int expired = 0, unauthed = 0;
+  long to_age, unused_age, maxchan_age;
+  int expired = 0, unauthed = 0, chansvaped = 0;
+  chanindex *cip, *ncip;
+  regchan *rcp;
 
   t = time(NULL);
-  to_age = t - (80 * 3600 * 24);  
-  unused_age = t - (10 * 3600 * 24);
+  to_age = t - (CLEANUP_ACCOUNT_INACTIVE * 3600 * 24);  
+  unused_age = t - (CLEANUP_ACCOUNT_UNUSED * 3600 * 24);
+  maxchan_age = t - (CLEANUP_CHANNEL_INACTIVE * 3600 * 24);
 
+  cs_log(sender, "CLEANUPDB started");
+
+  chanservsendmessage(sender, "Scanning regusers...");
   for (i=0;i<REGUSERHASHSIZE;i++) {
     for (vrup=regusernicktable[i]; vrup; vrup=srup) {
       srup=vrup->nextbyname;
       if (!(anp=findauthname(vrup->ID)))
         continue; /* should maybe raise hell instead */
-        
+
       if(!anp->nicks && !UHasHelperPriv(vrup) && !UIsCleanupExempt(vrup)) {
         if(vrup->lastauth && (vrup->lastauth < to_age)) {
           expired++;
+          cs_log(sender, "CLEANUPDB inactive user %s", vrup->username);
         } else if(!vrup->lastauth && (vrup->created < unused_age)) {
           unauthed++;
+          cs_log(sender, "CLEANUPDB unused user %s", vrup->username);
         } else {
           continue;
         }
@@ -49,7 +56,28 @@ int csu_docleanupdb(void *source, int cargc, char **cargv) {
       }
     }
   }
+
+  chanservsendmessage(sender, "Scanning chanindicies...");
+  for (i=0;i<CHANNELHASHSIZE;i++) {
+    for (cip=chantable[i];cip;cip=ncip) {
+      ncip=cip->next;
+      if (!(rcp=cip->exts[chanservext]))
+        continue;
+
+      if(rcp->lastactive < maxchan_age) {
+        /* don't remove channels with the original founder as an oper */
+        founder=findreguserbyID(rcp->founder);
+        if(founder && UHasOperPriv(founder))
+          continue;
+
+        cs_log(sender, "CLEANUPDB inactive channel %s", cip->name?cip->name->content:"??");
+        cs_removechannel(rcp);
+        chansvaped++;
+      }
+    }
+  }
   
-  chanservsendmessage(sender, "Cleanup complete, %d unused for 80 days, %d didn't auth within 10 days.", expired, unauthed);
+  cs_log(sender, "CLEANUPDB complete %d inactive accounts %d unused accounts %d channels", expired, unauthed, chansvaped);
+  chanservsendmessage(sender, "Cleanup complete, %d accounts inactive for %d days, %d accounts weren't used within %d days, %d channels were inactive for %d days.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, chansvaped, CLEANUP_CHANNEL_INACTIVE);
   return CMD_OK;
 }