ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/info.C
Revision: 1.10
Committed: Sat Sep 22 14:27:27 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +5 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# User Rev Content
1 pippijn 1.9 /**
2     * info.C: This file contains code for the NickServ INFO functions.
3     *
4     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5     * Rights to this code are as documented in COPYING.
6     *
7     *
8     * Portions of this file were derived from sources bearing the following license:
9 pippijn 1.4 * Copyright © 2005-2006 William Pitcock, et al.
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.10 * $Id: info.C,v 1.9 2007-09-16 18:54:43 pippijn Exp $
13 pippijn 1.1 */
14    
15     #include "atheme.h"
16 pippijn 1.10 #include <util/time.h>
17     #include <util/time.h>
18 pippijn 1.4 #include <ermyth/module.h>
19 pippijn 1.1 #include <account/mynick.h>
20     #include <account/myuser.h>
21    
22 pippijn 1.10 static char const rcsid[] = "$Id: info.C,v 1.9 2007-09-16 18:54:43 pippijn Exp $";
23 pippijn 1.1
24 pippijn 1.10 REGISTER_MODULE ("nickserv/info", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25 pippijn 1.1
26     static void ns_cmd_info (sourceinfo_t *si, int parc, char *parv[]);
27    
28 pippijn 1.4 command_t const ns_info = { "INFO", N_("Displays information on registrations."), AC_NONE, 2, ns_cmd_info };
29 pippijn 1.1
30 pippijn 1.4 E cmdvec ns_cmdtree;
31     E helpvec ns_helptree;
32 pippijn 1.1
33 pippijn 1.4 bool
34     _modinit (module *m)
35 pippijn 1.1 {
36     ns_cmdtree << ns_info;
37     help_addentry (ns_helptree, "INFO", "help/nickserv/info", NULL);
38 pippijn 1.4
39     return true;
40 pippijn 1.1 }
41    
42     void
43     _moddeinit ()
44     {
45     ns_cmdtree >> ns_info;
46     help_delentry (ns_helptree, "INFO");
47     }
48    
49     static void
50     ns_cmd_info (sourceinfo_t *si, int parc, char *parv[])
51     {
52     myuser_t *mu;
53     mynick_t *mn = NULL;
54     user_t *u;
55     char *name = parv[0];
56 pippijn 1.4 char buf[BUFSIZE], strfbuf[32], lastlogin[32], *p;
57 pippijn 1.1 struct tm tm, tm2;
58 pippijn 1.7 metadata *md;
59 pippijn 1.1 node_t *n;
60    
61     if (!name)
62     {
63 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO");
64     command_fail (si, fault::needmoreparams, _("Syntax: INFO <nickname>"));
65 pippijn 1.1 return;
66     }
67    
68 pippijn 1.5 if (!(mu = myuser_t::find_ext (name)))
69 pippijn 1.1 {
70 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name);
71 pippijn 1.1 return;
72     }
73    
74     tm = *localtime (&mu->registered);
75     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
76     tm2 = *localtime (&mu->lastlogin);
77     strftime (lastlogin, sizeof (lastlogin) - 1, "%b %d %H:%M:%S %Y", &tm2);
78    
79     command_success_nodata (si, _("Information on \2%s\2:"), mu->name);
80    
81     command_success_nodata (si, _("Registered: %s (%s ago)"), strfbuf, time_ago (mu->registered));
82 pippijn 1.4
83     if ((md = mu->find_metadata ("private:host:vhost")))
84     {
85     strlcpy (buf, md->value, sizeof buf);
86     if ((md = mu->find_metadata ("private:usercloak")))
87     {
88     p = strchr (buf, '@');
89     if (p == NULL)
90     p = buf;
91     else
92     p++;
93     strlcpy (p, md->value, sizeof buf - (p - buf));
94     }
95     command_success_nodata (si, _("Last address: %s"), buf);
96     }
97    
98     if (has_priv (si, PRIV_USER_AUSPEX))
99     {
100     if ((md = mu->find_metadata ("private:host:actual")))
101     command_success_nodata (si, _("Last real address: %s"), md->value);
102     }
103    
104 pippijn 1.1 if (mu->logins.empty ())
105     command_success_nodata (si, _("Last seen: %s (%s ago)"), lastlogin, time_ago (mu->lastlogin));
106     else if (mu == si->smu || has_priv (si, PRIV_USER_AUSPEX))
107     {
108     myuser_t::login_vector::iterator it, it_end;
109     buf[0] = '\0';
110     for (it = mu->logins.begin (), it_end = mu->logins.end (); it != it_end; ++it)
111     {
112     if (strlen (buf) > 80)
113     {
114     command_success_nodata (si, _("Logins from: %s"), buf);
115     buf[0] = '\0';
116     }
117     if (buf[0])
118     strcat (buf, " ");
119     strcat (buf, (*it)->nick);
120     }
121     if (buf[0])
122     command_success_nodata (si, _("Logins from: %s"), buf);
123     }
124     else
125     command_success_nodata (si, _("Logins from: <hidden>"));
126    
127     if (!nicksvs.no_nick_ownership)
128     {
129     /* describe queried nick */
130 pippijn 1.8 mn = mynick_t::find (*name == '=' ? name + 1 : name);
131 pippijn 1.1 if (mn != NULL && mn->owner == mu)
132     {
133     tm = *localtime (&mn->registered);
134     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
135     command_success_nodata (si, _("Nick %s registered: %s (%s ago)"), mn->nick, strfbuf, time_ago (mn->registered));
136     u = user_find_named (mn->nick);
137     if (u != NULL && u->myuser == mu)
138     command_success_nodata (si, _("Nick %s is currently online"), mn->nick);
139     else
140     {
141     tm = *localtime (&mn->lastseen);
142     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
143     command_success_nodata (si, _("Nick %s last seen: %s (%s ago)"), mn->nick, strfbuf, time_ago (mn->lastseen));
144     }
145     }
146     /* list registered nicks if privileged */
147     if (mu == si->smu || has_priv (si, PRIV_USER_AUSPEX))
148     {
149     buf[0] = '\0';
150     LIST_FOREACH (n, mu->nicks.head)
151     {
152     if (strlen (buf) > 80)
153     {
154     command_success_nodata (si, _("Registered nicks: %s"), buf);
155     buf[0] = '\0';
156     }
157     if (buf[0])
158     strcat (buf, " ");
159     strcat (buf, ((mynick_t *) (n->data))->nick);
160     }
161     if (buf[0])
162     command_success_nodata (si, _("Registered nicks: %s"), buf);
163     }
164     }
165    
166     if (!(mu->flags & MU_HIDEMAIL) || (si->smu == mu || has_priv (si, PRIV_USER_AUSPEX)))
167     command_success_nodata (si, _("Email: %s%s"), mu->email, (mu->flags & MU_HIDEMAIL) ? " (hidden)" : "");
168    
169     *buf = '\0';
170    
171 pippijn 1.7 if (mu->flags & MU_HIDEMAIL)
172 pippijn 1.1 strcat (buf, "HideMail");
173    
174 pippijn 1.7 if (mu->flags & MU_HOLD)
175 pippijn 1.1 {
176     if (*buf)
177     strcat (buf, ", ");
178    
179     strcat (buf, "Hold");
180     }
181 pippijn 1.7 if (mu->flags & MU_NEVEROP)
182 pippijn 1.1 {
183     if (*buf)
184     strcat (buf, ", ");
185    
186     strcat (buf, "NeverOp");
187     }
188 pippijn 1.7 if (mu->flags & MU_NOOP)
189 pippijn 1.1 {
190     if (*buf)
191     strcat (buf, ", ");
192    
193     strcat (buf, "NoOp");
194     }
195 pippijn 1.7 if (mu->flags & MU_NOMEMO)
196 pippijn 1.1 {
197     if (*buf)
198     strcat (buf, ", ");
199    
200     strcat (buf, "NoMemo");
201     }
202 pippijn 1.7 if (mu->flags & MU_EMAILMEMOS)
203 pippijn 1.1 {
204     if (*buf)
205     strcat (buf, ", ");
206    
207     strcat (buf, "EMailMemos");
208     }
209    
210     if (*buf)
211     command_success_nodata (si, _("Flags: %s"), buf);
212    
213     if (mu->soper && (mu == si->smu || has_priv (si, PRIV_VIEWPRIVS)))
214     {
215     command_success_nodata (si, _("Oper class: %s"), mu->soper->operclass ? mu->soper->operclass->name : mu->soper->classname);
216     }
217    
218     if (has_priv (si, PRIV_USER_AUSPEX) && (md = mu->find_metadata ("private:freeze:freezer")))
219     {
220 pippijn 1.4 char const * const setter = md->value;
221 pippijn 1.1 time_t ts;
222    
223     md = mu->find_metadata ("private:freeze:reason");
224 pippijn 1.4 char const * const reason = md != NULL ? md->value : "unknown";
225 pippijn 1.1
226     md = mu->find_metadata ("private:freeze:timestamp");
227     ts = md != NULL ? atoi (md->value) : 0;
228    
229     tm = *localtime (&ts);
230     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
231    
232     command_success_nodata (si, _("%s was \2FROZEN\2 by %s on %s (%s)"), mu->name, setter, strfbuf, reason);
233     }
234    
235     if (has_priv (si, PRIV_USER_AUSPEX) && (md = mu->find_metadata ("private:mark:setter")))
236     {
237 pippijn 1.4 char const * const setter = md->value;
238 pippijn 1.1 time_t ts;
239    
240     md = mu->find_metadata ("private:mark:reason");
241 pippijn 1.4 char const * const reason = md != NULL ? md->value : "unknown";
242 pippijn 1.1
243     md = mu->find_metadata ("private:mark:timestamp");
244     ts = md != NULL ? atoi (md->value) : 0;
245    
246     tm = *localtime (&ts);
247     strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm);
248    
249     command_success_nodata (si, _("%s was \2MARKED\2 by %s on %s (%s)"), mu->name, setter, strfbuf, reason);
250     }
251    
252 pippijn 1.7 if (mu->flags & MU_WAITAUTH)
253 pippijn 1.1 command_success_nodata (si, _("%s has not completed registration verification"), mu->name);
254    
255 pippijn 1.4 mn->callback.info (mn, mu, si);
256 pippijn 1.1
257     command_success_nodata (si, _("*** \2End of Info\2 ***"));
258    
259     logcommand (si, CMDLOG_GET, "INFO %s", mu->name);
260     }