]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/authhistory.c
e8c09d5e5f0c4bc73d4a24fa9cc79f3b9d3ce5fa
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 "../../pqsql/pqsql.h"
24 struct authhistoryinfo
{
29 void csdb_doauthhistory_real(PGconn
*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
;
38 char tbuf1
[15], tbuf2
[15], uhbuf
[51];
40 pgres
=PQgetResult(dbconn
);
42 if (PQresultStatus(pgres
) != PGRES_TUPLES_OK
) {
43 Error("chanserv", ERR_ERROR
, "Error loading auth history data.");
48 if (PQnfields(pgres
) != 7) {
49 Error("chanserv", ERR_ERROR
, "Auth history data format error.");
63 if (!(rup
=getreguserfromnick(np
))) {
68 chanservstdmessage(np
, QM_AUTHHISTORYHEADER
);
69 for (i
=0; i
<num
; i
++) {
70 if (!UHasHelperPriv(rup
) && (strtoul(PQgetvalue(pgres
, i
, 0), NULL
, 10) != rup
->ID
)) {
75 ahnick
=PQgetvalue(pgres
, i
, 1);
76 ahuser
=PQgetvalue(pgres
, i
, 2);
77 ahhost
=PQgetvalue(pgres
, i
, 3);
78 ahauthtime
=strtoul(PQgetvalue(pgres
, i
, 4), NULL
, 10);
79 ahdisconnecttime
=strtoul(PQgetvalue(pgres
, i
, 5), NULL
, 10);
80 tmp
=localtime(&ahauthtime
);
81 strftime(tbuf1
, 15, "%d/%m/%y %H:%M", tmp
);
82 if (ahdisconnecttime
) {
83 tmp
=localtime(&ahdisconnecttime
);
84 strftime(tbuf2
, 15, "%d/%m/%y %H:%M", tmp
);
86 snprintf(uhbuf
,50,"%s!%s@%s", ahnick
, ahuser
, ahhost
);
87 chanservsendmessage(np
, "#%-2d %-50s %-15s %-15s %s", ++count
, uhbuf
, tbuf1
, ahdisconnecttime
?tbuf2
:"never", PQgetvalue(pgres
,i
,6));
89 chanservstdmessage(np
, QM_ENDOFLIST
);
95 void csdb_retreiveauthhistory(nick
*np
, reguser
*rup
, int limit
) {
96 struct authhistoryinfo
*ahi
;
98 ahi
=(struct authhistoryinfo
*)malloc(sizeof(struct authhistoryinfo
));
99 ahi
->numeric
=np
->numeric
;
101 pqasyncquery(csdb_doauthhistory_real
, (void *)ahi
,
102 "SELECT userID, nick, username, host, authtime, disconnecttime, quitreason from authhistory where "
103 "userID=%u order by authtime desc limit %d", rup
->ID
, limit
);
106 int csa_doauthhistory(void *source
, int cargc
, char **cargv
) {
110 if (!(rup
=getreguserfromnick(sender
)))
114 if (!(trup
=findreguser(sender
, cargv
[0])))
117 /* don't allow non-opers to view oper auth history, but allow helpers to view non-oper history */
118 if ((trup
!= rup
) && ((UHasOperPriv(trup
) && !UHasOperPriv(rup
)) || !UHasHelperPriv(rup
))) {
119 chanservstdmessage(sender
, QM_NOACCESSONUSER
, "authhistory", cargv
[0]);
126 csdb_retreiveauthhistory(sender
, trup
, 10);