1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
|
/*
* Copyright (c) 2005-2006 William Pitcock, et al.
* Rights to this code are as documented in doc/LICENSE.
*
* This file contains code for the NickServ INFO functions.
*
*/
#include "atheme.h"
DECLARE_MODULE_V1
(
"nickserv/info", false, _modinit, _moddeinit,
PACKAGE_STRING,
VENDOR_STRING
);
static void ns_cmd_info(sourceinfo_t *si, int parc, char *parv[]);
command_t ns_info = { "INFO", N_("Displays information on registrations."), AC_NONE, 2, ns_cmd_info, { .path = "nickserv/info" } };
void _modinit(module_t *m)
{
service_named_bind_command("nickserv", &ns_info);
}
void _moddeinit(module_unload_intent_t intent)
{
service_named_unbind_command("nickserv", &ns_info);
}
static void ns_cmd_info(sourceinfo_t *si, int parc, char *parv[])
{
myuser_t *mu;
mynick_t *mn = NULL;
myuser_name_t *mun;
user_t *u = NULL;
bool recognized = false;
const char *name = parv[0];
char buf[BUFSIZE], strfbuf[BUFSIZE], lastlogin[BUFSIZE], *p;
size_t buflen;
time_t registered;
struct tm tm, tm2;
metadata_t *md;
mowgli_node_t *n;
mowgli_patricia_iteration_state_t state;
const char *vhost;
const char *vhost_timestring;
const char *vhost_assigner;
time_t vhost_time;
bool has_user_auspex;
bool hide_info;
hook_user_req_t req;
hook_info_noexist_req_t noexist_req;
/* On IRC, default the name to something.
* Not currently documented.
*/
if (!name && si->su)
{
if (!nicksvs.no_nick_ownership)
name = si->su->nick;
else if (si->smu)
name = entity(si->smu)->name;
}
if (!name)
{
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO");
command_fail(si, fault_needmoreparams, _("Syntax: INFO <nickname>"));
return;
}
noexist_req.si = si;
noexist_req.nick = name;
has_user_auspex = has_priv(si, PRIV_USER_AUSPEX);
if (!(mu = myuser_find_ext(name)))
{
if (has_user_auspex && (mun = myuser_name_find(name)) != NULL)
{
const char *setter;
const char *reason;
time_t ts;
md = metadata_find(mun, "private:mark:setter");
setter = md != NULL ? md->value : "unknown";
md = metadata_find(mun, "private:mark:reason");
reason = md != NULL ? md->value : "unknown";
md = metadata_find(mun, "private:mark:timestamp");
ts = md != NULL ? atoi(md->value) : 0;
tm = *localtime(&ts);
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered anymore, but was marked by %s on %s (%s)."), mun->name, setter, strfbuf, reason);
hook_call_user_info_noexist(&noexist_req);
}
else {
hook_call_user_info_noexist(&noexist_req);
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), name);
}
return;
}
hide_info = use_account_private && mu->flags & MU_PRIVATE &&
mu != si->smu && !has_user_auspex;
if (!nicksvs.no_nick_ownership)
{
mn = mynick_find(*name == '=' ? name + 1 : name);
if (mn != NULL && mn->owner != mu)
mn = NULL;
if (mn == NULL)
mn = mynick_find(entity(mu)->name);
u = user_find_named(mn->nick);
if (u != NULL && u->myuser != mu)
{
if (myuser_access_verify(u, mu))
recognized = true;
u = NULL;
}
}
if (mn != NULL)
command_success_nodata(si, _("Information on \2%s\2 (account \2%s\2):"), mn->nick, entity(mu)->name);
else
command_success_nodata(si, _("Information on \2%s\2:"), entity(mu)->name);
registered = mn != NULL ? mn->registered : mu->registered;
tm = *localtime(®istered);
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
command_success_nodata(si, _("Registered : %s (%s ago)"), strfbuf, time_ago(registered));
/* show account's time if it's different from nick's time */
if (mu->registered != registered)
{
tm = *localtime(&mu->registered);
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
command_success_nodata(si, _("User reg. : %s (%s ago)"), strfbuf, time_ago(mu->registered));
}
if (config_options.show_entity_id || has_user_auspex)
command_success_nodata(si, _("Entity ID : %s"), entity(mu)->id);
md = metadata_find(mu, "private:usercloak");
vhost = md ? md->value : NULL;
md = metadata_find(mu, "private:usercloak-timestamp");
vhost_timestring = md ? md->value : NULL;
md = metadata_find(mu, "private:usercloak-assigner");
vhost_assigner = md ? md->value : NULL;
if (!hide_info && (md = metadata_find(mu, "private:host:vhost")))
{
mowgli_strlcpy(buf, md->value, sizeof buf);
if (vhost != NULL)
{
p = strchr(buf, '@');
if (p == NULL)
p = buf;
else
p++;
mowgli_strlcpy(p, vhost, sizeof buf - (p - buf));
}
command_success_nodata(si, _("Last addr : %s"), buf);
}
if ((vhost || vhost_timestring || vhost_assigner) && (si->smu == mu || has_user_auspex))
{
buf[0] = '\0';
buflen = 0;
if (vhost_timestring && (vhost || has_user_auspex))
{
vhost_time = atoi(vhost_timestring);
tm2 = *localtime(&vhost_time);
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm2);
buflen += snprintf(buf + buflen, BUFSIZE - buflen, _(" on %s (%s ago)"), strfbuf, time_ago(vhost_time));
}
if (has_user_auspex && vhost_assigner)
buflen += snprintf(buf + buflen, BUFSIZE - buflen, _(" by %s"), vhost_assigner);
if (vhost && !buf[0])
command_success_nodata(si, _("vHost : %s"), vhost);
else if (vhost && buf[0])
command_success_nodata(si, _("vHost : %s (assigned%s)"), vhost, buf);
else if (!vhost && buf[0])
command_success_nodata(si, _("vHost : unassigned%s"), buf);
}
if (has_user_auspex)
{
if ((md = metadata_find(mu, "private:host:actual")))
command_success_nodata(si, _("Real addr : %s"), md->value);
}
if (recognized)
command_success_nodata(si, _("Recognized : now (matches access list)"));
/* show nick's lastseen/online, if we have a nick */
if (u != NULL)
command_success_nodata(si, _("Last seen : now"));
else if (mn != NULL)
{
tm2 = *localtime(&mn->lastseen);
strftime(lastlogin, sizeof lastlogin, TIME_FORMAT, &tm2);
if (hide_info)
command_success_nodata(si, _("Last seen : (about %d weeks ago)"), (int)((CURRTIME - mn->lastseen) / 604800));
else
command_success_nodata(si, _("Last seen : %s (%s ago)"), lastlogin, time_ago(mn->lastseen));
}
/* if noone is logged in to this account, show account's lastseen,
* unless we have a nick and it quit at the same time as the account
*/
if (MOWGLI_LIST_LENGTH(&mu->logins) == 0)
{
tm2 = *localtime(&mu->lastlogin);
strftime(lastlogin, sizeof lastlogin, TIME_FORMAT, &tm2);
if (mn == NULL)
{
if (hide_info)
command_success_nodata(si, _("Last seen : (about %d weeks ago)"), (int)((CURRTIME - mu->lastlogin) / 604800));
else
command_success_nodata(si, _("Last seen : %s (%s ago)"), lastlogin, time_ago(mu->lastlogin));
}
else if (mn->lastseen != mu->lastlogin)
{
if (hide_info)
command_success_nodata(si, _("User seen : (about %d weeks ago)"), (int)((CURRTIME - mu->lastlogin) / 604800));
else
command_success_nodata(si, _("User seen : %s (%s ago)"), lastlogin, time_ago(mu->lastlogin));
}
}
/* someone is logged in to this account
* if they're privileged, show them the sessions
*/
else if (mu == si->smu || has_user_auspex)
{
buf[0] = '\0';
MOWGLI_ITER_FOREACH(n, mu->logins.head)
{
if (strlen(buf) > 80)
{
command_success_nodata(si, _("Logins from: %s"), buf);
buf[0] = '\0';
}
if (buf[0])
mowgli_strlcat(buf, " ", sizeof buf);
mowgli_strlcat(buf, ((user_t *)(n->data))->nick, sizeof buf);
}
if (buf[0])
command_success_nodata(si, _("Logins from: %s"), buf);
}
/* tell them this account is online, but not which nick
* unless we have already told them above
*/
else if (u == NULL)
{
if (mn != NULL)
command_success_nodata(si, _("User seen : now"));
else
command_success_nodata(si, _("Last seen : now"));
}
if (!nicksvs.no_nick_ownership)
{
/* list registered nicks if privileged */
if (mu == si->smu || has_user_auspex)
{
buf[0] = '\0';
MOWGLI_ITER_FOREACH(n, mu->nicks.head)
{
if (strlen(buf) > 80)
{
command_success_nodata(si, _("Nicks : %s"), buf);
buf[0] = '\0';
}
if (buf[0])
mowgli_strlcat(buf, " ", sizeof buf);
mowgli_strlcat(buf, ((mynick_t *)(n->data))->nick, sizeof buf);
}
if (buf[0])
command_success_nodata(si, _("Nicks : %s"), buf);
}
}
if (!(mu->flags & MU_HIDEMAIL)
|| (si->smu == mu || has_user_auspex))
command_success_nodata(si, _("Email : %s%s"), mu->email,
(mu->flags & MU_HIDEMAIL) ? " (hidden)": "");
MOWGLI_PATRICIA_FOREACH(md, &state, object(mu)->metadata)
{
if (!strncmp(md->name, "private:", 8))
continue;
command_success_nodata(si, _("Metadata : %s = %s"),
md->name, md->value);
}
*buf = '\0';
if (MU_HIDEMAIL & mu->flags)
strcat(buf, "HideMail");
if (MU_HOLD & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "Hold");
}
if (MU_NEVEROP & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "NeverOp");
}
if (MU_NOOP & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "NoOp");
}
if (MU_NOMEMO & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "NoMemo");
}
if (MU_EMAILMEMOS & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "EMailMemos");
}
if (MU_NEVERGROUP & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "NeverGroup");
}
if (use_account_private && MU_PRIVATE & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "Private");
}
if (MU_REGNOLIMIT & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "RegNoLimit");
}
if (MU_NOGREET & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "NoGreet");
}
if (MU_NOPASSWORD & mu->flags)
{
if (*buf)
strcat(buf, ", ");
strcat(buf, "NoPassword");
}
if (*buf)
command_success_nodata(si, _("Flags : %s"), buf);
#ifdef ENABLE_NLS
if (mu == si->smu || has_user_auspex)
command_success_nodata(si, _("Language : %s"),
language_get_name(mu->language));
#endif
if (mu->soper && (mu == si->smu || has_priv(si, PRIV_VIEWPRIVS)))
{
command_success_nodata(si, _("Oper class : %s"), mu->soper->operclass ? mu->soper->operclass->name : mu->soper->classname);
}
if (mu == si->smu || has_user_auspex || has_priv(si, PRIV_CHAN_AUSPEX))
{
chanacs_t *ca;
int founder = 0, other = 0;
MOWGLI_ITER_FOREACH(n, entity(mu)->chanacs.head)
{
ca = n->data;
if (ca->level & CA_FOUNDER)
founder++;
else if (ca->level != CA_AKICK)
other++;
}
command_success_nodata(si, _("Channels : %d founder, %d other"), founder, other);
}
if (has_user_auspex && (md = metadata_find(mu, "private:freeze:freezer")))
{
const char *setter = md->value;
const char *reason;
time_t ts;
md = metadata_find(mu, "private:freeze:reason");
reason = md != NULL ? md->value : "unknown";
md = metadata_find(mu, "private:freeze:timestamp");
ts = md != NULL ? atoi(md->value) : 0;
tm = *localtime(&ts);
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
command_success_nodata(si, _("%s was \2FROZEN\2 by %s on %s (%s)"), entity(mu)->name, setter, strfbuf, reason);
}
else if (metadata_find(mu, "private:freeze:freezer"))
command_success_nodata(si, _("%s has been frozen by the %s administration."), entity(mu)->name, me.netname);
if (has_user_auspex && (md = metadata_find(mu, "private:mark:setter")))
{
const char *setter = md->value;
const char *reason;
time_t ts;
md = metadata_find(mu, "private:mark:reason");
reason = md != NULL ? md->value : "unknown";
md = metadata_find(mu, "private:mark:timestamp");
ts = md != NULL ? atoi(md->value) : 0;
tm = *localtime(&ts);
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
command_success_nodata(si, _("%s was \2MARKED\2 by %s on %s (%s)"), entity(mu)->name, setter, strfbuf, reason);
}
if (MU_WAITAUTH & mu->flags)
command_success_nodata(si, _("%s has \2NOT COMPLETED\2 registration verification"), entity(mu)->name);
if ((mu == si->smu || has_user_auspex) &&
(md = metadata_find(mu, "private:verify:emailchg:newemail")))
{
const char *newemail = md->value;
time_t ts;
md = metadata_find(mu, "private:verify:emailchg:timestamp");
ts = md != NULL ? atoi(md->value) : 0;
tm = *localtime(&ts);
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm);
command_success_nodata(si, _("%s has requested an email address change to %s on %s"), entity(mu)->name, newemail, strfbuf);
}
req.si = si;
req.mu = mu;
req.mn = mn;
hook_call_user_info(&req);
command_success_nodata(si, _("*** \2End of Info\2 ***"));
logcommand(si, CMDLOG_GET, "INFO: \2%s\2", mn != NULL ? mn->nick : entity(mu)->name);
}
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
* vim:ts=8
* vim:sw=8
* vim:noexpandtab
*/
|