]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/authhistory.c
1 /* Automatically generated by refactor.pl.
5 * CMDLEVEL: QCMD_AUTHED
7 * CMDDESC: View auth history for an account.
8 * CMDFUNC: csa_doauthhistory
9 * CMDPROTO: int csa_doauthhistory(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: AUTHHISTORY
11 * CMDHELP: Displays details of the last 10 logins with your account. Details include
12 * CMDHELP: hostmask, login time, disconnect time and reason.
15 #include "../chanserv.h"
16 #include "../authlib.h"
17 #include "../../lib/irc_string.h"
18 #include "../../dbapi/dbapi.h"
23 struct authhistoryinfo
{
29 void csdb_doauthhistory_real(DBConn
*dbconn
, void *arg
) {
30 struct authhistoryinfo
*ahi
=(struct authhistoryinfo
*)arg
;
31 nick
*np
=getnickbynumeric(ahi
->numeric
);
33 char *ahnick
, *ahuser
, *ahhost
;
34 time_t ahauthtime
, ahdisconnecttime
;
37 char tbuf1
[TIMELEN
], tbuf2
[TIMELEN
], uhbuf
[NICKLEN
+HOSTLEN
+USERLEN
+5];
44 pgres
=dbgetresult(dbconn
);
46 if (!dbquerysuccessful(pgres
)) {
47 Error("chanserv", ERR_ERROR
, "Error loading auth history data.");
52 if (dbnumfields(pgres
) != 7) {
53 Error("chanserv", ERR_ERROR
, "Auth history data format error.");
65 if (!(rup
=getreguserfromnick(np
))) {
71 chanservstdmessage(np
, QM_AUTHHISTORYHEADER
); /* @TIMELEN */
72 while(dbfetchrow(pgres
)) {
73 if (!UHasHelperPriv(rup
) && (strtoul(dbgetvalue(pgres
, 0), NULL
, 10) != rup
->ID
)) {
78 ahnick
=dbgetvalue(pgres
, 1);
79 ahuser
=dbgetvalue(pgres
, 2);
80 ahhost
=dbgetvalue(pgres
, 3);
81 ahauthtime
=strtoul(dbgetvalue(pgres
, 4), NULL
, 10);
82 ahdisconnecttime
=strtoul(dbgetvalue(pgres
, 5), NULL
, 10);
84 q9strftime(tbuf1
, sizeof(tbuf1
), ahauthtime
);
86 q9strftime(tbuf2
, sizeof(tbuf2
), ahdisconnecttime
);
88 snprintf(uhbuf
,sizeof(uhbuf
),"%s!%s@%s", ahnick
, ahuser
, ahi
->realhost
? ahhost
: "(hidden)");
89 chanservsendmessage(np
, "#%-2d %-50s %-19s %-19s %s", ++count
, uhbuf
, tbuf1
, ahdisconnecttime
?tbuf2
:"never", dbgetvalue(pgres
,6)); /* @TIMELEN */
91 chanservstdmessage(np
, QM_ENDOFLIST
);
97 void csdb_retreiveauthhistory(nick
*np
, reguser
*rup
, int limit
, int realhost
) {
98 struct authhistoryinfo
*ahi
;
102 sprintf(limitstr
, " limit %d",limit
);
107 ahi
=(struct authhistoryinfo
*)malloc(sizeof(struct authhistoryinfo
));
108 ahi
->numeric
=np
->numeric
;
110 ahi
->realhost
=realhost
;
111 q9a_asyncquery(csdb_doauthhistory_real
, (void *)ahi
,
112 "SELECT userID, nick, username, host, authtime, disconnecttime, quitreason from chanserv.authhistory where "
113 "userID=%u order by authtime desc%s", rup
->ID
, limitstr
);
116 int csa_doauthhistory(void *source
, int cargc
, char **cargv
) {
120 unsigned int limit
=10;
123 if (!(rup
=getreguserfromnick(sender
)))
127 if (!ircd_strcmp(cargv
[0], "-a")) {
128 if (UHasOperPriv(rup
))
136 if (!(trup
=findreguser(sender
, cargv
[arg
])))
139 /* if target != command issuer */
141 /* only opers and helpers can view authhistory of other users */
142 if (!UHasHelperPriv(rup
)) {
143 chanservstdmessage(sender
, QM_NOACCESSONUSER
, "authhistory", cargv
[arg
]);
147 /* and only opers can view opers history */
148 if (UHasOperPriv(trup
) && !UHasOperPriv(rup
)) {
149 chanservwallmessage("%s (%s) just FAILED using AUTHHISTORY on %s", sender
->nick
, rup
->username
, trup
->username
);
150 chanservstdmessage(sender
, QM_NOACCESSONUSER
, "authhistory", cargv
[arg
]);
154 if(cs_privcheck(QPRIV_VIEWREALHOST
, sender
)) {
161 chanservwallmessage("%s (%s) used AUTHHISTORY on %s", sender
->nick
, rup
->username
, trup
->username
);
170 csdb_retreiveauthhistory(sender
, trup
, limit
, realhost
);