]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: whois | |
5 | * CMDLEVEL: QCMD_AUTHED | |
6 | * CMDARGS: 1 | |
7 | * CMDDESC: Displays information about a user. | |
8 | * CMDFUNC: csu_dowhois | |
9 | * CMDPROTO: int csu_dowhois(void *source, int cargc, char **cargv); | |
50cd26d6 | 10 | * CMDHELP: Usage: WHOIS <user> |
11 | * CMDHELP: Displays information about a user, where: | |
12 | * CMDHELP: user - user to request information for, either the nickname of an active user on | |
13 | * CMDHELP: the network or #accountname. | |
1dd6d55d | 14 | */ |
15 | ||
16 | #include "../chanserv.h" | |
17 | #include "../../lib/irc_string.h" | |
f305c646 | 18 | #include "../../lib/strlfunc.h" |
b7eebdcc | 19 | #include "../../lib/ccassert.h" |
1dd6d55d | 20 | #include <stdio.h> |
21 | #include <string.h> | |
22 | ||
23 | int csu_dowhois(void *source, int cargc, char **cargv) { | |
24 | nick *sender=source; | |
ea4a0a50 | 25 | reguser *rup, *target; |
1dd6d55d | 26 | char buf[200]; |
27 | char nbpos=0; | |
1dd6d55d | 28 | regchanuser *rcup, *rcup2; |
29 | flag_t flagmask, flags; | |
30 | int doneheader=0; | |
23b85e10 | 31 | authname *anp; |
32 | nick *tnp; | |
1dd6d55d | 33 | |
b7eebdcc CP |
34 | CCASSERT(sizeof(buf) > TIMELEN); |
35 | ||
1dd6d55d | 36 | if (!(rup=getreguserfromnick(sender))) |
37 | return CMD_ERROR; | |
38 | ||
39 | if (cargc<1) { | |
40 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "whois"); | |
41 | return CMD_ERROR; | |
42 | } | |
43 | ||
44 | if (!(target=findreguser(sender, cargv[0]))) { | |
23b85e10 | 45 | nick *np; |
1dd6d55d | 46 | |
8ae8bd45 | 47 | if (cs_privcheck(QPRIV_VIEWFULLWHOIS, sender) && (np=getnickbynick(cargv[0]))) { |
23b85e10 | 48 | activeuser *aup=getactiveuserfromnick(np); |
1dd6d55d | 49 | chanservsendmessage(sender, "%s has attempted to auth %d time%s.", np->nick, aup->authattempts, |
50 | aup->authattempts==1?"":"s"); | |
51 | } | |
52 | return CMD_ERROR; | |
53 | } | |
54 | ||
55 | if (cargv[0][0]=='#') { | |
56 | chanservstdmessage(sender, QM_WHOISHEADER_AUTH, target->username); | |
57 | } else { | |
58 | chanservstdmessage(sender, QM_WHOISHEADER_NICK, cargv[0], target->username); | |
59 | } | |
60 | ||
61 | if (rup==target || cs_privcheck(QPRIV_VIEWFULLWHOIS, sender)) { | |
62 | chanservstdmessage(sender, QM_WHOIS_USERID, target->ID); | |
63 | } | |
64 | ||
65 | if (cs_privcheck(QPRIV_VIEWUSERFLAGS, sender)) { | |
347686bd | 66 | flagmask=QUFLAG_ALL & ~(QUFLAG_SUSPENDED | QUFLAG_GLINE | QUFLAG_DELAYEDGLINE); |
67 | if (UIsDev(rup)) | |
68 | flagmask=QUFLAG_ALL; | |
f305c646 CP |
69 | |
70 | if (UHasSuspension(target)) { | |
79313d98 | 71 | char expiresbuf[100]; |
f305c646 CP |
72 | char *reason, *suspendtype, *whom; |
73 | ||
b7eebdcc CP |
74 | CCASSERT(sizeof(expiresbuf) > TIMELEN); |
75 | ||
f305c646 CP |
76 | if(UIsDelayedGline(target)) { |
77 | suspendtype = "delayed gline"; | |
78 | } else if(UIsGline(target)) { | |
79 | suspendtype = "gline"; | |
80 | } else if(UIsSuspended(target)) { | |
81 | suspendtype = "suspended"; | |
82 | } else { | |
83 | suspendtype = "???"; | |
84 | } | |
85 | ||
86 | if(target->suspendexp) { | |
87 | if(time(NULL) >= target->suspendexp) { | |
88 | strlcpy(expiresbuf, "(next auth)", sizeof(expiresbuf)); | |
89 | } else { | |
b7eebdcc | 90 | q9strftime(expiresbuf, sizeof(expiresbuf), target->suspendexp); |
f305c646 CP |
91 | } |
92 | } else { | |
93 | strlcpy(expiresbuf, "(never)", sizeof(expiresbuf)); | |
94 | } | |
f305c646 | 95 | |
a49c6c1c | 96 | if(cs_privcheck(QPRIV_VIEWSUSPENDEDBY, sender)) { |
f305c646 CP |
97 | reguser *trup = findreguserbyID(target->suspendby); |
98 | if(trup) { | |
99 | whom = trup->username; | |
100 | } else { | |
101 | whom = "(unknown)"; | |
102 | } | |
103 | } else { | |
104 | whom = "(hidden)"; | |
105 | } | |
106 | ||
10a1d974 | 107 | if(target->suspendreason) { |
f305c646 CP |
108 | reason = target->suspendreason->content; |
109 | } else { | |
110 | reason = "(none)"; | |
111 | } | |
112 | ||
113 | chanservstdmessage(sender, QM_USERSUSPENDEDTYPE, suspendtype); | |
114 | chanservstdmessage(sender, QM_USERSUSPENDEDBY, whom); | |
115 | chanservstdmessage(sender, QM_USERSUSPENDEDREASON, reason); | |
79313d98 | 116 | chanservstdmessage(sender, QM_USERSUSPENDEDAT, target->suspendtime); |
f305c646 CP |
117 | chanservstdmessage(sender, QM_USERSUSPENDEDEXPIRY, expiresbuf); |
118 | } | |
1dd6d55d | 119 | } else { |
347686bd | 120 | /* Incidentally none of the QM_USERIS* mesages take parameters. Just thought I'd mention it.. */ |
1dd6d55d | 121 | if (UIsAdmin(target)) |
122 | chanservstdmessage(sender, QM_USERISADMIN, target->username); | |
123 | else if (UIsOper(target)) | |
124 | chanservstdmessage(sender, QM_USERISOPER, target->username); | |
125 | else if (UIsHelper(target)) | |
126 | chanservstdmessage(sender, QM_USERISHELPER, target->username); | |
347686bd | 127 | else if (UIsStaff(target)) |
128 | chanservstdmessage(sender, QM_USERISSTAFF, target->username); | |
1dd6d55d | 129 | |
130 | if (UIsDev(target)) | |
131 | chanservstdmessage(sender, QM_USERISDEV, target->username); | |
132 | ||
133 | flagmask=0; | |
134 | } | |
135 | ||
136 | if (rup==target) | |
3a4afcab GB |
137 | flagmask|=(QUFLAG_OPER | QUFLAG_DEV | QUFLAG_HELPER | QUFLAG_ADMIN | |
138 | QUFLAG_INFO | QUFLAG_NOTICE | QUFLAG_STAFF | QUFLAG_ACHIEVEMENTS); | |
1dd6d55d | 139 | |
140 | if (flagmask & target->flags) | |
43583524 | 141 | chanservstdmessage(sender, QM_WHOIS_FLAGS, printflagsornone(flagmask & target->flags, ruflags)); |
1dd6d55d | 142 | |
23b85e10 | 143 | if (!(anp=findauthname(target->ID)) || !anp->nicks) { |
1dd6d55d | 144 | chanservstdmessage(sender, QM_WHOIS_USERS, "(none)"); |
145 | } else { | |
23b85e10 | 146 | for (tnp=anp->nicks; ;tnp=tnp->nextbyauthname) { |
147 | if (nbpos>0 && (!tnp || nbpos+strlen(tnp->nick) > 60)) { | |
1dd6d55d | 148 | chanservstdmessage(sender, QM_WHOIS_USERS, buf); |
149 | nbpos=0; | |
150 | } | |
151 | ||
23b85e10 | 152 | if (!tnp) |
1dd6d55d | 153 | break; |
154 | ||
23b85e10 | 155 | nbpos+=sprintf(buf+nbpos,"%s ",tnp->nick); |
1dd6d55d | 156 | } |
157 | } | |
158 | ||
79313d98 CP |
159 | if (target->created) |
160 | chanservstdmessage(sender, QM_WHOIS_CREATED, target->created); | |
1dd6d55d | 161 | |
cf50e022 CP |
162 | if (target->lastauth == 0) { |
163 | snprintf(buf,sizeof(buf),"(never)"); | |
164 | } else { | |
b7eebdcc | 165 | q9strftime(buf,sizeof(buf),target->lastauth); |
cf50e022 | 166 | } |
1dd6d55d | 167 | chanservstdmessage(sender, QM_WHOIS_LASTAUTH, buf); |
168 | ||
2cc4bf1c | 169 | /* The third clause of this hides user@host of opers from non-opered staff. */ |
170 | if (target->lastuserhost && (rup==target || cs_privcheck(QPRIV_VIEWFULLWHOIS, sender)) && | |
171 | (!UHasOperPriv(target) || UHasOperPriv(rup)) ) { | |
50cd26d6 | 172 | /* Commenting out language until we implement some - splidge |
1dd6d55d | 173 | chanservstdmessage(sender, QM_WHOIS_USERLANG, cslanguages[target->languageid] ? |
50cd26d6 | 174 | cslanguages[target->languageid]->name->content : "(unknown)"); */ |
ffc0f3ab CP |
175 | if(rup==target || cs_privcheck(QPRIV_VIEWREALHOST, sender)) { |
176 | chanservstdmessage(sender, QM_WHOIS_LASTUSERHOST, target->lastuserhost->content); | |
177 | } | |
1dd6d55d | 178 | } |
179 | ||
180 | if (target->email && (rup==target || cs_privcheck(QPRIV_VIEWEMAIL, sender))) { | |
181 | chanservstdmessage(sender, QM_WHOIS_EMAIL, target->email->content); | |
404e71a6 CP |
182 | |
183 | if (target->lastemailchange) | |
184 | chanservstdmessage(sender, QM_WHOIS_EMAILSET, target->lastemailchange); | |
185 | if (target->lastpasschange) | |
186 | chanservstdmessage(sender, QM_WHOIS_PASSSET, target->lastpasschange); | |
1dd6d55d | 187 | } |
188 | ||
3a744b8f | 189 | if (target->info && *target->info->content) { |
1dd6d55d | 190 | chanservstdmessage(sender, QM_WHOIS_INFO, target->info->content); |
191 | } | |
192 | ||
193 | if (target->comment && (cs_privcheck(QPRIV_VIEWCOMMENTS, sender))) { | |
194 | chanservstdmessage(sender, QM_WHOIS_COMMENT, target->comment->content); | |
195 | } | |
196 | ||
197 | for (rcup=target->knownon;rcup;rcup=rcup->nextbyuser) { | |
a19424d6 | 198 | if (!UHasHelperPriv(rup) || (UHasOperPriv(target) && UHasHelperPriv(rup) && !UHasOperPriv(rup))) { |
1dd6d55d | 199 | if (!(rcup2=findreguseronchannel(rcup->chan,rup))) |
200 | continue; | |
201 | ||
50ec21f3 | 202 | if (!CUKnown(rcup2)) |
1dd6d55d | 203 | continue; |
204 | ||
205 | flagmask = (QCUFLAG_OWNER | QCUFLAG_MASTER | QCUFLAG_OP | QCUFLAG_VOICE | QCUFLAG_AUTOVOICE | | |
50ec21f3 | 206 | QCUFLAG_AUTOOP | QCUFLAG_TOPIC | QCUFLAG_KNOWN | QCUFLAG_PROTECT ); |
1dd6d55d | 207 | |
208 | if (CUHasMasterPriv(rcup2)) | |
50ec21f3 | 209 | flagmask |= QCUFLAGS_PUNISH; |
210 | ||
211 | if (rcup2==rcup) | |
212 | flagmask |= QCUFLAGS_PERSONAL; | |
1dd6d55d | 213 | } else { |
214 | flagmask=QCUFLAG_ALL; | |
215 | } | |
216 | ||
217 | if (!(flags=rcup->flags & flagmask)) | |
218 | continue; | |
219 | ||
220 | if (!doneheader) { | |
221 | doneheader=1; | |
222 | chanservstdmessage(sender, QM_WHOIS_CHANHEADER, target->username); | |
223 | } | |
224 | ||
225 | chanservsendmessage(sender, " %-30s %s",rcup->chan->index->name->content,printflags(flags, rcuflags)); | |
226 | } | |
227 | ||
0c393f78 | 228 | chanservstdmessage(sender, QM_ENDOFLIST); |
1dd6d55d | 229 | |
d72584f9 | 230 | if (rup==target) { |
231 | triggerhook(HOOK_CHANSERV_WHOAMI, sender); | |
232 | } else { | |
233 | triggerhook(HOOK_CHANSERV_WHOIS, sender); | |
234 | } | |
235 | ||
1dd6d55d | 236 | return CMD_OK; |
237 | } |