]>
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
{
28 void csdb_doauthhistory_real(DBConn
*dbconn
, void *arg
) {
29 struct authhistoryinfo
*ahi
=(struct authhistoryinfo
*)arg
;
30 nick
*np
=getnickbynumeric(ahi
->numeric
);
32 char *ahnick
, *ahuser
, *ahhost
;
33 time_t ahauthtime
, ahdisconnecttime
;
37 char tbuf1
[15], tbuf2
[15], uhbuf
[51];
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
))) {
70 chanservstdmessage(np
, QM_AUTHHISTORYHEADER
);
71 while(dbfetchrow(pgres
)) {
72 if (!UHasHelperPriv(rup
) && (strtoul(dbgetvalue(pgres
, 0), NULL
, 10) != rup
->ID
)) {
77 ahnick
=dbgetvalue(pgres
, 1);
78 ahuser
=dbgetvalue(pgres
, 2);
79 ahhost
=dbgetvalue(pgres
, 3);
80 ahauthtime
=strtoul(dbgetvalue(pgres
, 4), NULL
, 10);
81 ahdisconnecttime
=strtoul(dbgetvalue(pgres
, 5), NULL
, 10);
82 tmp
=gmtime(&ahauthtime
);
83 strftime(tbuf1
, sizeof(tbuf1
), Q9_FORMAT_TIME
, tmp
);
84 if (ahdisconnecttime
) {
85 tmp
=gmtime(&ahdisconnecttime
);
86 strftime(tbuf2
, sizeof(tbuf2
), Q9_FORMAT_TIME
, tmp
);
88 snprintf(uhbuf
,50,"%s!%s@%s", ahnick
, ahuser
, ahhost
);
89 chanservsendmessage(np
, "#%-2d %-50s %-15s %-15s %s", ++count
, uhbuf
, tbuf1
, ahdisconnecttime
?tbuf2
:"never", dbgetvalue(pgres
,6));
91 chanservstdmessage(np
, QM_ENDOFLIST
);
97 void csdb_retreiveauthhistory(nick
*np
, reguser
*rup
, int limit
) {
98 struct authhistoryinfo
*ahi
;
100 ahi
=(struct authhistoryinfo
*)malloc(sizeof(struct authhistoryinfo
));
101 ahi
->numeric
=np
->numeric
;
103 q9a_asyncquery(csdb_doauthhistory_real
, (void *)ahi
,
104 "SELECT userID, nick, username, host, authtime, disconnecttime, quitreason from chanserv.authhistory where "
105 "userID=%u order by authtime desc limit %d", rup
->ID
, limit
);
108 int csa_doauthhistory(void *source
, int cargc
, char **cargv
) {
112 if (!(rup
=getreguserfromnick(sender
)))
116 if (!(trup
=findreguser(sender
, cargv
[0])))
119 /* don't allow non-opers to view oper auth history, but allow helpers to view non-oper history */
120 if ((trup
!= rup
) && ((UHasOperPriv(trup
) && !UHasOperPriv(rup
)) || !UHasHelperPriv(rup
))) {
121 chanservstdmessage(sender
, QM_NOACCESSONUSER
, "authhistory", cargv
[0]);
128 csdb_retreiveauthhistory(sender
, trup
, 10);