]>
Commit | Line | Data |
---|---|---|
7ac9dbae P |
1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: cleanupdb | |
85174237 | 5 | * CMDLEVEL: QCMD_DEV |
7ac9dbae | 6 | * CMDARGS: 0 |
85174237 | 7 | * CMDDESC: Clean up database. |
7ac9dbae P |
8 | * CMDFUNC: csu_docleanupdb |
9 | * CMDPROTO: int csu_docleanupdb(void *source, int cargc, char **cargv); | |
85174237 | 10 | * CMDHELP: Usage: cleanupdb |
a6f1f6b6 | 11 | * CMDHELP: Cleans up inactive accounts, unused accounts and inactive channels. |
7ac9dbae P |
12 | */ |
13 | ||
14 | #include "../chanserv.h" | |
15 | #include "../../lib/irc_string.h" | |
16 | #include <stdio.h> | |
17 | #include <string.h> | |
18 | ||
19 | int csu_docleanupdb(void *source, int cargc, char **cargv) { | |
20 | nick *sender=source; | |
a6f1f6b6 | 21 | reguser *vrup, *srup, *founder; |
23b85e10 | 22 | authname *anp; |
7ac9dbae | 23 | int i; |
cf50e022 | 24 | time_t t; |
a6f1f6b6 CP |
25 | long to_age, unused_age, maxchan_age; |
26 | int expired = 0, unauthed = 0, chansvaped = 0; | |
27 | chanindex *cip, *ncip; | |
28 | regchan *rcp; | |
cf50e022 CP |
29 | |
30 | t = time(NULL); | |
a6f1f6b6 CP |
31 | to_age = t - (CLEANUP_ACCOUNT_INACTIVE * 3600 * 24); |
32 | unused_age = t - (CLEANUP_ACCOUNT_UNUSED * 3600 * 24); | |
33 | maxchan_age = t - (CLEANUP_CHANNEL_INACTIVE * 3600 * 24); | |
7ac9dbae | 34 | |
a6f1f6b6 CP |
35 | cs_log(sender, "CLEANUPDB started"); |
36 | ||
37 | chanservsendmessage(sender, "Scanning regusers..."); | |
7ac9dbae P |
38 | for (i=0;i<REGUSERHASHSIZE;i++) { |
39 | for (vrup=regusernicktable[i]; vrup; vrup=srup) { | |
40 | srup=vrup->nextbyname; | |
23b85e10 | 41 | if (!(anp=findauthname(vrup->ID))) |
42 | continue; /* should maybe raise hell instead */ | |
a6f1f6b6 | 43 | |
cf50e022 CP |
44 | if(!anp->nicks && !UHasHelperPriv(vrup) && !UIsCleanupExempt(vrup)) { |
45 | if(vrup->lastauth && (vrup->lastauth < to_age)) { | |
46 | expired++; | |
a6f1f6b6 | 47 | cs_log(sender, "CLEANUPDB inactive user %s", vrup->username); |
cf50e022 CP |
48 | } else if(!vrup->lastauth && (vrup->created < unused_age)) { |
49 | unauthed++; | |
a6f1f6b6 | 50 | cs_log(sender, "CLEANUPDB unused user %s", vrup->username); |
cf50e022 CP |
51 | } else { |
52 | continue; | |
53 | } | |
54 | ||
7ac9dbae | 55 | cs_removeuser(vrup); |
7ac9dbae P |
56 | } |
57 | } | |
58 | } | |
a6f1f6b6 CP |
59 | |
60 | chanservsendmessage(sender, "Scanning chanindicies..."); | |
61 | for (i=0;i<CHANNELHASHSIZE;i++) { | |
62 | for (cip=chantable[i];cip;cip=ncip) { | |
63 | ncip=cip->next; | |
64 | if (!(rcp=cip->exts[chanservext])) | |
65 | continue; | |
66 | ||
67 | if(rcp->lastactive < maxchan_age) { | |
68 | /* don't remove channels with the original founder as an oper */ | |
69 | founder=findreguserbyID(rcp->founder); | |
70 | if(founder && UHasOperPriv(founder)) | |
71 | continue; | |
72 | ||
73 | cs_log(sender, "CLEANUPDB inactive channel %s", cip->name?cip->name->content:"??"); | |
74 | cs_removechannel(rcp); | |
75 | chansvaped++; | |
76 | } | |
77 | } | |
78 | } | |
7ac9dbae | 79 | |
a6f1f6b6 CP |
80 | cs_log(sender, "CLEANUPDB complete %d inactive accounts %d unused accounts %d channels", expired, unauthed, chansvaped); |
81 | 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); | |
80d2de64 | 82 | return CMD_OK; |
7ac9dbae | 83 | } |