]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authcmds/authhistory.c
44f32a278a105cfb68edd88462ba789744828697
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
;
36 char tbuf1
[TIMELEN
], tbuf2
[TIMELEN
], uhbuf
[NICKLEN
+HOSTLEN
+USERLEN
+5];
43 pgres
=dbgetresult(dbconn
);
45 if (!dbquerysuccessful(pgres
)) {
46 Error("chanserv", ERR_ERROR
, "Error loading auth history data.");
51 if (dbnumfields(pgres
) != 7) {
52 Error("chanserv", ERR_ERROR
, "Auth history data format error.");
64 if (!(rup
=getreguserfromnick(np
))) {
69 chanservstdmessage(np
, QM_AUTHHISTORYHEADER
); /* @TIMELEN */
70 while(dbfetchrow(pgres
)) {
71 if (!UHasHelperPriv(rup
) && (strtoul(dbgetvalue(pgres
, 0), NULL
, 10) != rup
->ID
)) {
76 ahnick
=dbgetvalue(pgres
, 1);
77 ahuser
=dbgetvalue(pgres
, 2);
78 ahhost
=dbgetvalue(pgres
, 3);
79 ahauthtime
=strtoul(dbgetvalue(pgres
, 4), NULL
, 10);
80 ahdisconnecttime
=strtoul(dbgetvalue(pgres
, 5), NULL
, 10);
82 q9strftime(tbuf1
, sizeof(tbuf1
), ahauthtime
);
84 q9strftime(tbuf2
, sizeof(tbuf2
), ahdisconnecttime
);
86 snprintf(uhbuf
,sizeof(uhbuf
),"%s!%s@%s", ahnick
, ahuser
, ahhost
);
87 chanservsendmessage(np
, "#%-2d %-50s %-19s %-19s %s", ++count
, uhbuf
, tbuf1
, ahdisconnecttime
?tbuf2
:"never", dbgetvalue(pgres
,6)); /* @TIMELEN */
89 chanservstdmessage(np
, QM_ENDOFLIST
);
95 void csdb_retreiveauthhistory(nick
*np
, reguser
*rup
, int limit
) {
96 struct authhistoryinfo
*ahi
;
100 sprintf(limitstr
, " limit %d",limit
);
105 ahi
=(struct authhistoryinfo
*)malloc(sizeof(struct authhistoryinfo
));
106 ahi
->numeric
=np
->numeric
;
108 q9a_asyncquery(csdb_doauthhistory_real
, (void *)ahi
,
109 "SELECT userID, nick, username, host, authtime, disconnecttime, quitreason from chanserv.authhistory where "
110 "userID=%u order by authtime desc%s", rup
->ID
, limitstr
);
113 int csa_doauthhistory(void *source
, int cargc
, char **cargv
) {
117 unsigned int limit
=10;
119 if (!(rup
=getreguserfromnick(sender
)))
123 if (!ircd_strcmp(cargv
[0], "-a")) {
124 if (UHasOperPriv(rup
))
132 if (!(trup
=findreguser(sender
, cargv
[arg
])))
135 /* if target != command issuer */
137 /* only opers and helpers can view authhistory of other users */
138 if (!UHasHelperPriv(rup
)) {
139 chanservstdmessage(sender
, QM_NOACCESSONUSER
, "authhistory", cargv
[arg
]);
143 /* and only opers can view opers history */
144 if (UHasOperPriv(trup
) && !UHasOperPriv(rup
)) {
145 chanservwallmessage("%s (%s) just FAILED using AUTHHISTORY on %s", sender
->nick
, rup
->username
, trup
->username
);
146 chanservstdmessage(sender
, QM_NOACCESSONUSER
, "authhistory", cargv
[arg
]);
151 chanservwallmessage("%s (%s) used AUTHHISTORY on %s", sender
->nick
, rup
->username
, trup
->username
);
157 csdb_retreiveauthhistory(sender
, trup
, limit
);