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