]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/usercmds/suspenduser.c
CHANSERV: require user to have QPRIV_VIEWWALLMESSAGE to see walls (i.e. must be opere...
[irc/quakenet/newserv.git] / chanserv / usercmds / suspenduser.c
CommitLineData
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 29static 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 45int 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;
b7eebdcc 56 char expiresbuf[TIMELEN]="";
1dd6d55d 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 }
dae08100 98
1dd6d55d 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
dae08100
CP
147 if(!checkreason(sender, reason))
148 return CMD_ERROR;
149
b7eebdcc
CP
150 if (expires)
151 q9strftime(expiresbuf,sizeof(expiresbuf),expires);
1dd6d55d 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
dae08100
CP
178 chanservwallmessage("%s (%s) bulk suspended <%s>, hit %d account/s (expires: %s), reason: %s", sender->nick, rup->username, victim, hitcount, expires?expiresbuf:"never", reason);
179 cs_log(sender, "SUSPENDUSER (bulk by email: %s, hit: %d) expires: %s, reason: %s", victim, hitcount, expires?expiresbuf:"never", reason);
1dd6d55d 180 }
181 else if (password) {
182 int i;
183
184 for (i=0;i<REGUSERHASHSIZE;i++) {
185 for (vrup=regusernicktable[i]; vrup; vrup=vrup->nextbyname) {
186 if (!strcmp(vrup->password, victim)) {
187 if (UHasSuspension(vrup))
188 continue;
189
372e4f1d 190 if (UHasStaffPriv(vrup))
1dd6d55d 191 continue;
192
193 hitcount++;
194 vrup->flags|=QUFLAG_SUSPENDED;
195 vrup->suspendby=rup->ID;
196 vrup->suspendexp=expires;
c1e6c982 197 vrup->suspendtime=time(NULL);
1dd6d55d 198 vrup->suspendreason=getsstring(reason, strlen(reason)+1);
199
23b85e10 200 killtheusers(sender,vrup);
1dd6d55d 201 csdb_updateuser(vrup);
202 }
203 }
204 }
205
dae08100
CP
206 chanservwallmessage("%s (%s) bulk suspended password \"%s\", hit %d account/s (expires: %s), reason: %s", sender->nick, rup->username, victim, hitcount, expires?expiresbuf:"never", reason);
207 cs_log(sender, "SUSPENDUSER (bulk by password: %s, hit: %d) expires: %s, reason: %s", victim, hitcount, expires?expiresbuf:"never", reason);
1dd6d55d 208 }
209 else {
210 if (!(vrup=findreguser(sender, victim)))
211 return CMD_ERROR;
212
213 if (!ircd_strcmp(vrup->username, rup->username)) {
214 chanservsendmessage(sender, "You can't suspend yourself, silly.");
215 return CMD_ERROR;
216 }
217
218 if (UHasSuspension(vrup)) {
219 chanservstdmessage(sender, QM_USERALREADYSUSPENDED);
220 return CMD_ERROR;
221 }
222
372e4f1d 223 if (UHasStaffPriv(vrup)) {
b7eebdcc 224 char buf[200];
dae08100 225 snprintf(buf, sizeof(buf), "suspenduser on %s (reason: %s)", vrup->username, reason);
1dd6d55d 226 chanservstdmessage(sender, QM_NOACCESS, buf);
dae08100 227 chanservwallmessage("%s (%s) FAILED to suspend %s (reason: %s)", sender->nick, rup->username, vrup->username, reason);
1dd6d55d 228 return CMD_ERROR;
229 }
230
231 if (gline == 2)
232 vrup->flags|=QUFLAG_GLINE;
233 else if (gline == 1)
234 vrup->flags|=QUFLAG_DELAYEDGLINE;
235 else
236 vrup->flags|=QUFLAG_SUSPENDED;
237 vrup->suspendby=rup->ID;
238 vrup->suspendexp=expires;
c1e6c982 239 vrup->suspendtime=time(NULL);
1dd6d55d 240 vrup->suspendreason=getsstring(reason, strlen(reason)+1);
241
dae08100
CP
242 chanservwallmessage("%s (%s) %s %s (expires: %s), reason: %s", sender->nick, rup->username, (gline)?((gline == 2)?"instantly glined":"delayed glined"):"suspended", vrup->username, expires?expiresbuf:"never", reason);
243 cs_log(sender, "SUSPENDUSER %s %s (expires: %s), reason: %s", (gline)?((gline == 2)?"instantly glined":"delayed glined"):"suspended", vrup->username, expires?expiresbuf:"never", reason);
244
1dd6d55d 245 if (gline) {
246 dgwait=(gline==2)?0:rand()%900;
247 chanservsendmessage(sender, "Scheduling delayed GLINE for account %s in %d %s",
248 vrup->username, (dgwait>60)?(dgwait/60):dgwait, (dgwait>60)?"minutes":"seconds");
249 deleteschedule(NULL, &chanservdgline, (void*)vrup);
250 scheduleoneshot(time(NULL)+dgwait, &chanservdgline, (void*)vrup);
251 }
252 else if (kill) {
23b85e10 253 hitcount += killtheusers(sender,vrup);
1dd6d55d 254 }
255
256 csdb_updateuser(vrup);
257 }
258
259 return CMD_OK;
260}