]>
Commit | Line | Data |
---|---|---|
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); | |
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. | |
22 | */ | |
23 | ||
24 | #include "../chanserv.h" | |
25 | #include "../../lib/irc_string.h" | |
26 | #include <stdio.h> | |
27 | #include <string.h> | |
28 | ||
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 | ||
45 | int csu_dosuspenduser(void *source, int cargc, char **cargv) { | |
46 | nick *sender=source; | |
47 | reguser *rup=getreguserfromnick(sender); | |
48 | reguser *vrup; | |
49 | char *flag; | |
50 | char *victim; | |
51 | char *dur_p; | |
52 | char *reason; | |
53 | int kill=1, gline=0, email=0, password=0, hitcount=0; | |
54 | time_t expires=0; | |
55 | int duration=0; | |
56 | char expiresbuf[TIMELEN]=""; | |
57 | int dgwait; | |
58 | ||
59 | if (!rup) | |
60 | return CMD_ERROR; | |
61 | ||
62 | if (cargc < 1) { | |
63 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
64 | return CMD_ERROR; | |
65 | } | |
66 | ||
67 | if (cargv[0][0] == '-') { | |
68 | flag=cargv[0]; | |
69 | if (!(victim=strchr(flag, ' '))) { | |
70 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
71 | return CMD_ERROR; | |
72 | } | |
73 | *(victim++)='\0'; | |
74 | if (!(dur_p=strchr(victim, ' '))) { | |
75 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
76 | return CMD_ERROR; | |
77 | } | |
78 | *(dur_p++)='\0'; | |
79 | if ((reason=strchr(dur_p, ' '))) { | |
80 | *(reason++)='\0'; | |
81 | if ((duration=durationtolong(dur_p))) { | |
82 | if ((duration < 86400) || (duration > 2592000)) { | |
83 | chanservstdmessage(sender, QM_INVALIDDURATION); | |
84 | return CMD_ERROR; | |
85 | } | |
86 | expires=time(0)+duration; | |
87 | } | |
88 | else { | |
89 | *(reason-1)=' '; | |
90 | reason=dur_p; | |
91 | expires=0; | |
92 | } | |
93 | } | |
94 | else { | |
95 | reason=dur_p; | |
96 | expires=0; | |
97 | } | |
98 | ||
99 | if (!ircd_strcmp(flag, "-nokill")) { | |
100 | kill=0; | |
101 | } | |
102 | else if (!ircd_strcmp(flag, "-gline")) { | |
103 | gline=1; | |
104 | } | |
105 | else if (!ircd_strcmp(flag, "-instantgline")) { | |
106 | gline=2; | |
107 | } | |
108 | else if (!ircd_strcmp(flag, "-email")) { | |
109 | email=1; | |
110 | } | |
111 | else if (!ircd_strcmp(flag, "-password")) { | |
112 | password=1; | |
113 | } | |
114 | else { | |
115 | chanservstdmessage(sender, QM_INVALIDCHANLEVCHANGE); | |
116 | return CMD_ERROR; | |
117 | } | |
118 | } | |
119 | else { | |
120 | victim=cargv[0]; | |
121 | if (!(dur_p=strchr(victim, ' '))) { | |
122 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduser"); | |
123 | return CMD_ERROR; | |
124 | } | |
125 | *(dur_p++)='\0'; | |
126 | if ((reason=strchr(dur_p, ' '))) { | |
127 | *(reason++)='\0'; | |
128 | if ((duration=durationtolong(dur_p))) { | |
129 | if ((duration < 86400) || (duration > 2592000)) { | |
130 | chanservstdmessage(sender, QM_INVALIDDURATION); | |
131 | return CMD_ERROR; | |
132 | } | |
133 | expires=time(0)+duration; | |
134 | } | |
135 | else { | |
136 | *(reason-1)=' '; | |
137 | reason=dur_p; | |
138 | expires=0; | |
139 | } | |
140 | } | |
141 | else { | |
142 | reason=dur_p; | |
143 | expires=0; | |
144 | } | |
145 | } | |
146 | ||
147 | if (expires) | |
148 | q9strftime(expiresbuf,sizeof(expiresbuf),expires); | |
149 | ||
150 | if (email) { | |
151 | int i; | |
152 | ||
153 | for (i=0;i<REGUSERHASHSIZE;i++) { | |
154 | for (vrup=regusernicktable[i]; vrup; vrup=vrup->nextbyname) { | |
155 | if (!strcasecmp(vrup->email->content, victim)) { | |
156 | if (UHasSuspension(vrup)) | |
157 | continue; | |
158 | ||
159 | if (UHasStaffPriv(vrup)) | |
160 | continue; | |
161 | ||
162 | hitcount++; | |
163 | vrup->flags|=QUFLAG_SUSPENDED; | |
164 | vrup->suspendby=rup->ID; | |
165 | vrup->suspendexp=expires; | |
166 | vrup->suspendtime=time(NULL); | |
167 | vrup->suspendreason=getsstring(reason, strlen(reason)+1); | |
168 | ||
169 | killtheusers(sender,vrup); | |
170 | csdb_updateuser(vrup); | |
171 | } | |
172 | } | |
173 | } | |
174 | ||
175 | chanservwallmessage("%s (%s) bulk suspended <%s>, hit %d account/s (expires: %s)", sender->nick, rup->username, victim, hitcount, expires?expiresbuf:"never"); | |
176 | } | |
177 | else if (password) { | |
178 | int i; | |
179 | ||
180 | for (i=0;i<REGUSERHASHSIZE;i++) { | |
181 | for (vrup=regusernicktable[i]; vrup; vrup=vrup->nextbyname) { | |
182 | if (!strcmp(vrup->password, victim)) { | |
183 | if (UHasSuspension(vrup)) | |
184 | continue; | |
185 | ||
186 | if (UHasStaffPriv(vrup)) | |
187 | continue; | |
188 | ||
189 | hitcount++; | |
190 | vrup->flags|=QUFLAG_SUSPENDED; | |
191 | vrup->suspendby=rup->ID; | |
192 | vrup->suspendexp=expires; | |
193 | vrup->suspendtime=time(NULL); | |
194 | vrup->suspendreason=getsstring(reason, strlen(reason)+1); | |
195 | ||
196 | killtheusers(sender,vrup); | |
197 | csdb_updateuser(vrup); | |
198 | } | |
199 | } | |
200 | } | |
201 | ||
202 | chanservwallmessage("%s (%s) bulk suspended password \"%s\", hit %d account/s (expires: %s)", sender->nick, rup->username, victim, hitcount, expires?expiresbuf:"never"); | |
203 | } | |
204 | else { | |
205 | if (!(vrup=findreguser(sender, victim))) | |
206 | return CMD_ERROR; | |
207 | ||
208 | if (!ircd_strcmp(vrup->username, rup->username)) { | |
209 | chanservsendmessage(sender, "You can't suspend yourself, silly."); | |
210 | return CMD_ERROR; | |
211 | } | |
212 | ||
213 | if (UHasSuspension(vrup)) { | |
214 | chanservstdmessage(sender, QM_USERALREADYSUSPENDED); | |
215 | return CMD_ERROR; | |
216 | } | |
217 | ||
218 | if (UHasStaffPriv(vrup)) { | |
219 | char buf[200]; | |
220 | snprintf(buf, sizeof(buf), "suspenduser on %s", vrup->username); | |
221 | chanservstdmessage(sender, QM_NOACCESS, buf); | |
222 | chanservwallmessage("%s (%s) FAILED to suspend %s", sender->nick, rup->username, vrup->username); | |
223 | return CMD_ERROR; | |
224 | } | |
225 | ||
226 | if (gline == 2) | |
227 | vrup->flags|=QUFLAG_GLINE; | |
228 | else if (gline == 1) | |
229 | vrup->flags|=QUFLAG_DELAYEDGLINE; | |
230 | else | |
231 | vrup->flags|=QUFLAG_SUSPENDED; | |
232 | vrup->suspendby=rup->ID; | |
233 | vrup->suspendexp=expires; | |
234 | vrup->suspendtime=time(NULL); | |
235 | vrup->suspendreason=getsstring(reason, strlen(reason)+1); | |
236 | ||
237 | chanservwallmessage("%s (%s) %s %s (expires: %s)", sender->nick, rup->username, (gline)?((gline == 2)?"instantly glined":"delayed glined"):"suspended", vrup->username, expires?expiresbuf:"never"); | |
238 | if (gline) { | |
239 | dgwait=(gline==2)?0:rand()%900; | |
240 | chanservsendmessage(sender, "Scheduling delayed GLINE for account %s in %d %s", | |
241 | vrup->username, (dgwait>60)?(dgwait/60):dgwait, (dgwait>60)?"minutes":"seconds"); | |
242 | deleteschedule(NULL, &chanservdgline, (void*)vrup); | |
243 | scheduleoneshot(time(NULL)+dgwait, &chanservdgline, (void*)vrup); | |
244 | } | |
245 | else if (kill) { | |
246 | hitcount += killtheusers(sender,vrup); | |
247 | } | |
248 | ||
249 | csdb_updateuser(vrup); | |
250 | } | |
251 | ||
252 | return CMD_OK; | |
253 | } |