]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: suspenduser | |
5 | * CMDLEVEL: QCMD_OPER | |
6 | * CMDARGS: 1 | |
7 | * CMDDESC: Suspend/Delay GLINE/Instantly GLINE a user. | |
8 | * CMDFUNC: csu_dosuspenduser | |
9 | * CMDPROTO: int csu_dosuspenduser(void *source, int cargc, char **cargv); | |
94e4d2f4 CP |
10 | * CMDHELP: Usage: suspenduser <username> [<duration>] <reason> |
11 | * CMDHELP: -nokill <username> [<duration>] <reason> | |
12 | * CMDHELP: -gline <username> [<duration>] <reason> | |
13 | * CMDHELP: -instantgline <username> [<duration>] <reason> | |
14 | * CMDHELP: -password <password> [<duration>] <reason> | |
15 | * CMDHELP: -email <email address> [<duration>] <reason> | |
16 | * CMDHELP: Suspends one or more users, either based on username, email | |
17 | * CMDHELP: address or password. | |
18 | * CMDHELP: By default the user will be immediately disconnected unless | |
19 | * CMDHELP: nokill is specified. | |
20 | * CMDHELP: gline will gline the user at some random period of time after | |
21 | * CMDHELP: they auth, instantgline will gline them the moment they auth. | |
1dd6d55d | 22 | */ |
23 | ||
24 | #include "../chanserv.h" | |
25 | #include "../../lib/irc_string.h" | |
26 | #include <stdio.h> | |
27 | #include <string.h> | |
28 | ||
23b85e10 | 29 | static int killtheusers(nick *sender, reguser *rup) { |
30 | int count=0; | |
31 | authname *anp; | |
32 | ||
33 | if (!(anp=findauthname(rup->ID))) | |
34 | return 0; | |
35 | ||
36 | while (anp->nicks) { | |
37 | chanservstdmessage(sender, QM_DISCONNECTINGUSER, anp->nicks->nick, rup->username); | |
38 | chanservkillstdmessage(anp->nicks, QM_SUSPENDKILL); | |
39 | count++; | |
40 | } | |
41 | ||
42 | return count; | |
43 | } | |
44 | ||
1dd6d55d | 45 | int csu_dosuspenduser(void *source, int cargc, char **cargv) { |
46 | nick *sender=source; | |
47 | reguser *rup=getreguserfromnick(sender); | |
48 | reguser *vrup; | |
23b85e10 | 49 | char *flag; |
50 | char *victim; | |
51 | char *dur_p; | |
52 | char *reason; | |
1dd6d55d | 53 | int kill=1, gline=0, email=0, password=0, hitcount=0; |
54 | time_t expires=0; | |
55 | int duration=0; | |
23b85e10 | 56 | struct tm *tmp; |
1dd6d55d | 57 | char buf[200]=""; |
58 | int dgwait; | |
59 | ||
60 | if (!rup) | |
61 | return CMD_ERROR; | |
62 | ||
63 | if (cargc < 1) { | |
64 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
65 | return CMD_ERROR; | |
66 | } | |
67 | ||
68 | if (cargv[0][0] == '-') { | |
69 | flag=cargv[0]; | |
70 | if (!(victim=strchr(flag, ' '))) { | |
71 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
72 | return CMD_ERROR; | |
73 | } | |
74 | *(victim++)='\0'; | |
75 | if (!(dur_p=strchr(victim, ' '))) { | |
76 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
77 | return CMD_ERROR; | |
78 | } | |
79 | *(dur_p++)='\0'; | |
80 | if ((reason=strchr(dur_p, ' '))) { | |
81 | *(reason++)='\0'; | |
82 | if ((duration=durationtolong(dur_p))) { | |
83 | if ((duration < 86400) || (duration > 2592000)) { | |
84 | chanservstdmessage(sender, QM_INVALIDDURATION); | |
85 | return CMD_ERROR; | |
86 | } | |
87 | expires=time(0)+duration; | |
88 | } | |
89 | else { | |
90 | *(reason-1)=' '; | |
91 | reason=dur_p; | |
92 | expires=0; | |
93 | } | |
94 | } | |
95 | else { | |
96 | reason=dur_p; | |
97 | expires=0; | |
98 | } | |
99 | ||
100 | if (!ircd_strcmp(flag, "-nokill")) { | |
101 | kill=0; | |
102 | } | |
103 | else if (!ircd_strcmp(flag, "-gline")) { | |
104 | gline=1; | |
105 | } | |
106 | else if (!ircd_strcmp(flag, "-instantgline")) { | |
107 | gline=2; | |
108 | } | |
109 | else if (!ircd_strcmp(flag, "-email")) { | |
110 | email=1; | |
111 | } | |
112 | else if (!ircd_strcmp(flag, "-password")) { | |
113 | password=1; | |
114 | } | |
115 | else { | |
116 | chanservstdmessage(sender, QM_INVALIDCHANLEVCHANGE); | |
117 | return CMD_ERROR; | |
118 | } | |
119 | } | |
120 | else { | |
121 | victim=cargv[0]; | |
122 | if (!(dur_p=strchr(victim, ' '))) { | |
123 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
124 | return CMD_ERROR; | |
125 | } | |
126 | *(dur_p++)='\0'; | |
127 | if ((reason=strchr(dur_p, ' '))) { | |
128 | *(reason++)='\0'; | |
129 | if ((duration=durationtolong(dur_p))) { | |
130 | if ((duration < 86400) || (duration > 2592000)) { | |
131 | chanservstdmessage(sender, QM_INVALIDDURATION); | |
132 | return CMD_ERROR; | |
133 | } | |
134 | expires=time(0)+duration; | |
135 | } | |
136 | else { | |
137 | *(reason-1)=' '; | |
138 | reason=dur_p; | |
139 | expires=0; | |
140 | } | |
141 | } | |
142 | else { | |
143 | reason=dur_p; | |
144 | expires=0; | |
145 | } | |
146 | } | |
147 | ||
148 | if (expires) { | |
149 | tmp=gmtime(&expires); | |
79313d98 | 150 | strftime(buf,sizeof(buf),Q9_FORMAT_TIME,tmp); |
1dd6d55d | 151 | } |
152 | ||
153 | if (email) { | |
154 | int i; | |
155 | ||
156 | for (i=0;i<REGUSERHASHSIZE;i++) { | |
157 | for (vrup=regusernicktable[i]; vrup; vrup=vrup->nextbyname) { | |
847c4170 | 158 | if (!strcasecmp(vrup->email->content, victim)) { |
1dd6d55d | 159 | if (UHasSuspension(vrup)) |
160 | continue; | |
161 | ||
372e4f1d | 162 | if (UHasStaffPriv(vrup)) |
1dd6d55d | 163 | continue; |
164 | ||
165 | hitcount++; | |
166 | vrup->flags|=QUFLAG_SUSPENDED; | |
167 | vrup->suspendby=rup->ID; | |
168 | vrup->suspendexp=expires; | |
c1e6c982 | 169 | vrup->suspendtime=time(NULL); |
1dd6d55d | 170 | vrup->suspendreason=getsstring(reason, strlen(reason)+1); |
171 | ||
23b85e10 | 172 | killtheusers(sender,vrup); |
1dd6d55d | 173 | csdb_updateuser(vrup); |
174 | } | |
175 | } | |
176 | } | |
177 | ||
178 | chanservwallmessage("%s (%s) bulk suspended <%s>, hit %d account/s (expires: %s)", sender->nick, rup->username, victim, hitcount, expires?buf:"never"); | |
179 | } | |
180 | else if (password) { | |
181 | int i; | |
182 | ||
183 | for (i=0;i<REGUSERHASHSIZE;i++) { | |
184 | for (vrup=regusernicktable[i]; vrup; vrup=vrup->nextbyname) { | |
185 | if (!strcmp(vrup->password, victim)) { | |
186 | if (UHasSuspension(vrup)) | |
187 | continue; | |
188 | ||
372e4f1d | 189 | if (UHasStaffPriv(vrup)) |
1dd6d55d | 190 | continue; |
191 | ||
192 | hitcount++; | |
193 | vrup->flags|=QUFLAG_SUSPENDED; | |
194 | vrup->suspendby=rup->ID; | |
195 | vrup->suspendexp=expires; | |
c1e6c982 | 196 | vrup->suspendtime=time(NULL); |
1dd6d55d | 197 | vrup->suspendreason=getsstring(reason, strlen(reason)+1); |
198 | ||
23b85e10 | 199 | killtheusers(sender,vrup); |
1dd6d55d | 200 | csdb_updateuser(vrup); |
201 | } | |
202 | } | |
203 | } | |
204 | ||
205 | chanservwallmessage("%s (%s) bulk suspended password \"%s\", hit %d account/s (expires: %s)", sender->nick, rup->username, victim, hitcount, expires?buf:"never"); | |
206 | } | |
207 | else { | |
208 | if (!(vrup=findreguser(sender, victim))) | |
209 | return CMD_ERROR; | |
210 | ||
211 | if (!ircd_strcmp(vrup->username, rup->username)) { | |
212 | chanservsendmessage(sender, "You can't suspend yourself, silly."); | |
213 | return CMD_ERROR; | |
214 | } | |
215 | ||
216 | if (UHasSuspension(vrup)) { | |
217 | chanservstdmessage(sender, QM_USERALREADYSUSPENDED); | |
218 | return CMD_ERROR; | |
219 | } | |
220 | ||
372e4f1d | 221 | if (UHasStaffPriv(vrup)) { |
1dd6d55d | 222 | snprintf(buf, 199, "suspenduser on %s", vrup->username); |
223 | chanservstdmessage(sender, QM_NOACCESS, buf); | |
224 | chanservwallmessage("%s (%s) FAILED to suspend %s", sender->nick, rup->username, vrup->username); | |
225 | return CMD_ERROR; | |
226 | } | |
227 | ||
228 | if (gline == 2) | |
229 | vrup->flags|=QUFLAG_GLINE; | |
230 | else if (gline == 1) | |
231 | vrup->flags|=QUFLAG_DELAYEDGLINE; | |
232 | else | |
233 | vrup->flags|=QUFLAG_SUSPENDED; | |
234 | vrup->suspendby=rup->ID; | |
235 | vrup->suspendexp=expires; | |
c1e6c982 | 236 | vrup->suspendtime=time(NULL); |
1dd6d55d | 237 | vrup->suspendreason=getsstring(reason, strlen(reason)+1); |
238 | ||
239 | chanservwallmessage("%s (%s) %s %s (expires: %s)", sender->nick, rup->username, (gline)?((gline == 2)?"instantly glined":"delayed glined"):"suspended", vrup->username, expires?buf:"never"); | |
240 | if (gline) { | |
241 | dgwait=(gline==2)?0:rand()%900; | |
242 | chanservsendmessage(sender, "Scheduling delayed GLINE for account %s in %d %s", | |
243 | vrup->username, (dgwait>60)?(dgwait/60):dgwait, (dgwait>60)?"minutes":"seconds"); | |
244 | deleteschedule(NULL, &chanservdgline, (void*)vrup); | |
245 | scheduleoneshot(time(NULL)+dgwait, &chanservdgline, (void*)vrup); | |
246 | } | |
247 | else if (kill) { | |
23b85e10 | 248 | hitcount += killtheusers(sender,vrup); |
1dd6d55d | 249 | } |
250 | ||
251 | csdb_updateuser(vrup); | |
252 | } | |
253 | ||
254 | return CMD_OK; | |
255 | } |