]>
Commit | Line | Data |
---|---|---|
183b8e2f P |
1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: accounthistory | |
5 | * CMDLEVEL: QCMD_OPER | |
6 | * CMDARGS: 1 | |
7 | * CMDDESC: View password/email history for an account. | |
8 | * CMDFUNC: csa_doaccounthistory | |
9 | * CMDPROTO: int csa_doaccounthistory(void *source, int cargc, char **cargv); | |
85174237 CP |
10 | * CMDHELP: Usage: accounthistory <account> |
11 | * CMDHELP: Shows password/email history for the specified account. | |
183b8e2f P |
12 | */ |
13 | ||
14 | #include "../chanserv.h" | |
15 | #include "../../lib/irc_string.h" | |
ee8cd7d0 | 16 | #include "../../dbapi/dbapi.h" |
6b2ca929 | 17 | |
183b8e2f P |
18 | #include <stdio.h> |
19 | #include <string.h> | |
20 | ||
ee8cd7d0 | 21 | void csdb_doaccounthistory_real(DBConn *dbconn, void *arg) { |
c54295ef | 22 | nick *np=getnickbynumeric((unsigned long)arg); |
6b2ca929 | 23 | reguser *rup; |
6b2ca929 | 24 | char *oldpass, *newpass, *oldemail, *newemail; |
ea4a0a50 | 25 | time_t changetime; |
ee8cd7d0 CP |
26 | DBResult *pgres; |
27 | int count=0; | |
b7eebdcc | 28 | char tbuf[TIMELEN]; |
6b2ca929 | 29 | |
b3565978 CP |
30 | if(!dbconn) |
31 | return; | |
32 | ||
ee8cd7d0 | 33 | pgres=dbgetresult(dbconn); |
6b2ca929 | 34 | |
ee8cd7d0 | 35 | if (!dbquerysuccessful(pgres)) { |
6b2ca929 | 36 | Error("chanserv", ERR_ERROR, "Error loading account history data."); |
37 | return; | |
38 | } | |
39 | ||
ee8cd7d0 | 40 | if (dbnumfields(pgres) != 7) { |
6b2ca929 | 41 | Error("chanserv", ERR_ERROR, "Account history data format error."); |
ee8cd7d0 | 42 | dbclear(pgres); |
6b2ca929 | 43 | return; |
44 | } | |
45 | ||
6b2ca929 | 46 | if (!np) { |
ee8cd7d0 | 47 | dbclear(pgres); |
6b2ca929 | 48 | return; |
49 | } | |
50 | ||
51 | if (!(rup=getreguserfromnick(np)) || !UHasOperPriv(rup)) { | |
52 | Error("chanserv", ERR_ERROR, "No reguser pointer or oper privs in account history."); | |
ee8cd7d0 | 53 | dbclear(pgres); |
6b2ca929 | 54 | return; |
55 | } | |
56 | ||
b7eebdcc CP |
57 | /* @TIMELEN */ |
58 | chanservsendmessage(np, "Number: Time: Old password: New password: Old email: New email:"); | |
ee8cd7d0 | 59 | while(dbfetchrow(pgres)) { |
ea4a0a50 | 60 | /*userID=strtoul(dbgetvalue(pgres, 0), NULL, 10);*/ |
ee8cd7d0 | 61 | changetime=strtoul(dbgetvalue(pgres, 1), NULL, 10); |
ea4a0a50 | 62 | /*authtime=strtoul(dbgetvalue(pgres, 2), NULL, 10);*/ |
ee8cd7d0 CP |
63 | oldpass=dbgetvalue(pgres, 3); |
64 | newpass=dbgetvalue(pgres, 4); | |
65 | oldemail=dbgetvalue(pgres, 5); | |
66 | newemail=dbgetvalue(pgres, 6); | |
b7eebdcc CP |
67 | q9strftime(tbuf, sizeof(tbuf), changetime); |
68 | chanservsendmessage(np, "#%-6d %-19s %-14s %-14s %-30s %s", ++count, tbuf, oldpass, newpass, oldemail, newemail); /* @TIMELEN */ | |
6b2ca929 | 69 | } |
70 | chanservstdmessage(np, QM_ENDOFLIST); | |
71 | ||
ee8cd7d0 | 72 | dbclear(pgres); |
6b2ca929 | 73 | } |
74 | ||
75 | void csdb_retreiveaccounthistory(nick *np, reguser *rup, int limit) { | |
b3565978 | 76 | q9u_asyncquery(csdb_doaccounthistory_real, (void *)np->numeric, |
522e2b8c | 77 | "SELECT userID, changetime, authtime, oldpassword, newpassword, oldemail, newemail from chanserv.accounthistory where " |
6b2ca929 | 78 | "userID=%u order by changetime desc limit %d", rup->ID, limit); |
79 | } | |
80 | ||
183b8e2f P |
81 | int csa_doaccounthistory(void *source, int cargc, char **cargv) { |
82 | reguser *rup, *trup; | |
83 | nick *sender=source; | |
84 | ||
85 | if (!(rup=getreguserfromnick(sender))) | |
86 | return CMD_ERROR; | |
87 | ||
88 | if (cargc < 1) { | |
89 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "accounthistory"); | |
90 | return CMD_ERROR; | |
91 | } | |
92 | ||
93 | if (!(trup=findreguser(sender, cargv[0]))) | |
94 | return CMD_ERROR; | |
95 | ||
96 | if ((rup != trup) && UHasOperPriv(trup) && !UHasAdminPriv(rup)) { | |
97 | chanservstdmessage(sender, QM_NOACCESS, "accounthistory", cargv[0]); | |
98 | return CMD_ERROR; | |
99 | } | |
100 | ||
101 | csdb_retreiveaccounthistory(sender, trup, 10); | |
102 | ||
103 | return CMD_OK; | |
104 | } |