1 |
/** |
2 |
* info.C: This file contains code for the ChanServ 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 |
* Copyright © 2005 William Pitcock, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: info.C,v 1.8 2007-09-16 18:54:42 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <util/time.h> |
17 |
#include <util/time.h> |
18 |
#include <util/numeric.h> |
19 |
#include <libermyth.h> |
20 |
#include <ermyth/module.h> |
21 |
#include <account/myuser.h> |
22 |
#include <account/mychan.h> |
23 |
|
24 |
static char const rcsid[] = "$Id: info.C,v 1.8 2007-09-16 18:54:42 pippijn Exp $"; |
25 |
|
26 |
REGISTER_MODULE ("chanserv/info", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
27 |
|
28 |
static void cs_cmd_info (sourceinfo_t *si, int parc, char *parv[]); |
29 |
|
30 |
command_t const cs_info = { "INFO", N_("Displays information on registrations."), AC_NONE, 1, cs_cmd_info }; |
31 |
|
32 |
E cmdvec cs_cmdtree; |
33 |
E helpvec cs_helptree; |
34 |
|
35 |
bool |
36 |
_modinit (module *m) |
37 |
{ |
38 |
cs_cmdtree << cs_info; |
39 |
help_addentry (cs_helptree, "INFO", "help/chanserv/info", NULL); |
40 |
|
41 |
return true; |
42 |
} |
43 |
|
44 |
void |
45 |
_moddeinit () |
46 |
{ |
47 |
cs_cmdtree >> cs_info; |
48 |
help_delentry (cs_helptree, "INFO"); |
49 |
} |
50 |
|
51 |
static void |
52 |
cs_cmd_info (sourceinfo_t *si, int parc, char *parv[]) |
53 |
{ |
54 |
mychan_t *mc; |
55 |
char *name = parv[0]; |
56 |
char buf[BUFSIZE], strfbuf[32]; |
57 |
struct tm tm; |
58 |
metadata *md; |
59 |
char *p, *q, *qq; |
60 |
int dir; |
61 |
|
62 |
if (!name) |
63 |
{ |
64 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO"); |
65 |
command_fail (si, fault::needmoreparams, _("Syntax: INFO <#channel>")); |
66 |
return; |
67 |
} |
68 |
|
69 |
if (*name != '#') |
70 |
{ |
71 |
command_fail (si, fault::badparams, STR_INVALID_PARAMS, "INFO"); |
72 |
command_fail (si, fault::badparams, _("Syntax: INFO <#channel>")); |
73 |
return; |
74 |
} |
75 |
|
76 |
if (!(mc = mychan_t::find (name))) |
77 |
{ |
78 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name); |
79 |
return; |
80 |
} |
81 |
|
82 |
if (!has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:close:closer"))) |
83 |
{ |
84 |
command_fail (si, fault::noprivs, _("\2%s\2 has been closed down by the %s administration."), mc->name, me.netname); |
85 |
return; |
86 |
} |
87 |
|
88 |
tm = *localtime (&mc->registered); |
89 |
strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); |
90 |
|
91 |
command_success_nodata (si, _("Information on \2%s\2:"), mc->name); |
92 |
|
93 |
command_success_nodata (si, _("Founder : %s"), mc->founder_names ()); |
94 |
|
95 |
command_success_nodata (si, _("Registered : %s (%s ago)"), strfbuf, time_ago (mc->registered)); |
96 |
|
97 |
if (NOW - mc->used >= 86400) |
98 |
{ |
99 |
tm = *localtime (&mc->used); |
100 |
strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); |
101 |
command_success_nodata (si, _("Last used : %s (%s ago)"), strfbuf, time_ago (mc->used)); |
102 |
} |
103 |
|
104 |
md = mc->find_metadata ("private:mlockext"); |
105 |
if (mc->mlock_on || mc->mlock_off || mc->mlock_limit || mc->mlock_key || md) |
106 |
{ |
107 |
char params[BUFSIZE]; |
108 |
|
109 |
if (md != NULL && strlen (md->value) > 450) |
110 |
{ |
111 |
/* Be safe */ |
112 |
command_success_nodata (si, _("Mode lock is too long, not entirely shown")); |
113 |
md = NULL; |
114 |
} |
115 |
|
116 |
*buf = 0; |
117 |
*params = 0; |
118 |
dir = MTYPE_NUL; |
119 |
|
120 |
if (mc->mlock_on) |
121 |
{ |
122 |
if (dir != MTYPE_ADD) |
123 |
dir = MTYPE_ADD, strcat (buf, "+"); |
124 |
strcat (buf, flags_to_string (mc->mlock_on)); |
125 |
|
126 |
} |
127 |
|
128 |
if (mc->mlock_limit) |
129 |
{ |
130 |
if (dir != MTYPE_ADD) |
131 |
dir = MTYPE_ADD, strcat (buf, "+"); |
132 |
strcat (buf, "l"); |
133 |
strcat (params, " "); |
134 |
strcat (params, itoa (mc->mlock_limit)); |
135 |
} |
136 |
|
137 |
if (mc->mlock_key) |
138 |
{ |
139 |
if (dir != MTYPE_ADD) |
140 |
dir = MTYPE_ADD, strcat (buf, "+"); |
141 |
strcat (buf, "k"); |
142 |
strcat (params, " *"); |
143 |
} |
144 |
|
145 |
if (md) |
146 |
{ |
147 |
p = md->value; |
148 |
q = buf + strlen (buf); |
149 |
while (*p != '\0') |
150 |
{ |
151 |
if (p[1] != ' ' && p[1] != '\0') |
152 |
{ |
153 |
if (dir != MTYPE_ADD) |
154 |
dir = MTYPE_ADD, *q++ = '+'; |
155 |
*q++ = *p++; |
156 |
strcat (params, " "); |
157 |
qq = params + strlen (params); |
158 |
while (*p != '\0' && *p != ' ') |
159 |
*qq++ = *p++; |
160 |
*qq = '\0'; |
161 |
} |
162 |
else |
163 |
{ |
164 |
p++; |
165 |
while (*p != '\0' && *p != ' ') |
166 |
p++; |
167 |
} |
168 |
while (*p == ' ') |
169 |
p++; |
170 |
} |
171 |
*q = '\0'; |
172 |
} |
173 |
|
174 |
if (mc->mlock_off) |
175 |
{ |
176 |
if (dir != MTYPE_DEL) |
177 |
dir = MTYPE_DEL, strcat (buf, "-"); |
178 |
strcat (buf, flags_to_string (mc->mlock_off)); |
179 |
if (mc->mlock_off & CMODE_LIMIT) |
180 |
strcat (buf, "l"); |
181 |
if (mc->mlock_off & CMODE_KEY) |
182 |
strcat (buf, "k"); |
183 |
} |
184 |
|
185 |
if (md) |
186 |
{ |
187 |
p = md->value; |
188 |
q = buf + strlen (buf); |
189 |
while (*p != '\0') |
190 |
{ |
191 |
if (p[1] == ' ' || p[1] == '\0') |
192 |
{ |
193 |
if (dir != MTYPE_DEL) |
194 |
dir = MTYPE_DEL, *q++ = '-'; |
195 |
*q++ = *p; |
196 |
} |
197 |
p++; |
198 |
while (*p != '\0' && *p != ' ') |
199 |
p++; |
200 |
while (*p == ' ') |
201 |
p++; |
202 |
} |
203 |
*q = '\0'; |
204 |
} |
205 |
|
206 |
if (*buf) |
207 |
command_success_nodata (si, _("Mode lock : %s%s"), buf, params); |
208 |
} |
209 |
|
210 |
|
211 |
if ((md = mc->find_metadata ("url"))) |
212 |
command_success_nodata (si, "URL : %s", md->value); |
213 |
|
214 |
if ((md = mc->find_metadata ("email"))) |
215 |
command_success_nodata (si, "Email : %s", md->value); |
216 |
|
217 |
*buf = '\0'; |
218 |
|
219 |
if (MC_HOLD & mc->flags) |
220 |
strcat (buf, "HOLD"); |
221 |
|
222 |
if (MC_SECURE & mc->flags) |
223 |
{ |
224 |
if (*buf) |
225 |
strcat (buf, " "); |
226 |
|
227 |
strcat (buf, "SECURE"); |
228 |
} |
229 |
|
230 |
if (MC_VERBOSE & mc->flags) |
231 |
{ |
232 |
if (*buf) |
233 |
strcat (buf, " "); |
234 |
|
235 |
strcat (buf, "VERBOSE"); |
236 |
} |
237 |
if (MC_VERBOSE_OPS & mc->flags) |
238 |
{ |
239 |
if (*buf) |
240 |
strcat (buf, " "); |
241 |
|
242 |
strcat (buf, "VERBOSE_OPS"); |
243 |
} |
244 |
|
245 |
if (MC_STAFFONLY & mc->flags) |
246 |
{ |
247 |
if (*buf) |
248 |
strcat (buf, " "); |
249 |
|
250 |
strcat (buf, "STAFFONLY"); |
251 |
} |
252 |
|
253 |
if (MC_KEEPTOPIC & mc->flags) |
254 |
{ |
255 |
if (*buf) |
256 |
strcat (buf, " "); |
257 |
|
258 |
strcat (buf, "KEEPTOPIC"); |
259 |
} |
260 |
|
261 |
if (MC_TOPICLOCK & mc->flags) |
262 |
{ |
263 |
if (*buf) |
264 |
strcat (buf, " "); |
265 |
|
266 |
strcat (buf, "TOPICLOCK"); |
267 |
} |
268 |
|
269 |
if (MC_GUARD & mc->flags) |
270 |
{ |
271 |
if (*buf) |
272 |
strcat (buf, " "); |
273 |
|
274 |
strcat (buf, "GUARD"); |
275 |
|
276 |
if (chansvs.fantasy && !mc->find_metadata ("disable_fantasy")) |
277 |
strcat (buf, " FANTASY"); |
278 |
} |
279 |
|
280 |
if (*buf) |
281 |
command_success_nodata (si, _("Flags : %s"), buf); |
282 |
|
283 |
if (has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:mark:setter"))) |
284 |
{ |
285 |
char const * const setter = md->value; |
286 |
time_t ts; |
287 |
|
288 |
md = mc->find_metadata ("private:mark:reason"); |
289 |
char const * const reason = md != NULL ? md->value : "unknown"; |
290 |
|
291 |
md = mc->find_metadata ("private:mark:timestamp"); |
292 |
ts = md != NULL ? atoi (md->value) : 0; |
293 |
|
294 |
tm = *localtime (&ts); |
295 |
strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); |
296 |
|
297 |
command_success_nodata (si, _("%s was \2MARKED\2 by %s on %s (%s)"), mc->name, setter, strfbuf, reason); |
298 |
} |
299 |
|
300 |
if (has_priv (si, PRIV_CHAN_AUSPEX) && (MC_INHABIT & mc->flags)) |
301 |
command_success_nodata (si, _("%s is temporarily holding this channel."), chansvs.nick); |
302 |
|
303 |
if (has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:close:closer"))) |
304 |
{ |
305 |
char const * const setter = md->value; |
306 |
time_t ts; |
307 |
|
308 |
md = mc->find_metadata ("private:close:reason"); |
309 |
char const * const reason = md != NULL ? md->value : "unknown"; |
310 |
|
311 |
md = mc->find_metadata ("private:close:timestamp"); |
312 |
ts = md != NULL ? atoi (md->value) : 0; |
313 |
|
314 |
tm = *localtime (&ts); |
315 |
strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); |
316 |
|
317 |
command_success_nodata (si, _("%s was \2CLOSED\2 by %s on %s (%s)"), mc->name, setter, strfbuf, reason); |
318 |
} |
319 |
|
320 |
mc->callback.info (mc, si); |
321 |
|
322 |
command_success_nodata (si, _("\2*** End of Info ***\2")); |
323 |
logcommand (si, CMDLOG_GET, "%s INFO", mc->name); |
324 |
} |