1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides the /check command to retrieve information on a user, channel, or IP address */
20 class CommandCheck : public Command
23 CommandCheck(Module* parent) : Command(parent,"CHECK", 1)
25 flags_needed = 'o'; syntax = "<nickname>|<ip>|<hostmask>|<channel> <server>";
28 std::string timestring(time_t time)
31 struct tm *mytime = gmtime(&time);
32 strftime(timebuf, 59, "%Y-%m-%d %H:%M:%S UTC (%s)", mytime);
33 return std::string(timebuf);
36 void dumpExt(User* user, std::string checkstr, Extensible* ext)
38 std::stringstream dumpkeys;
39 for(Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); i++)
41 ExtensionItem* item = i->first;
42 std::string value = item->serialize(FORMAT_USER, ext, i->second);
44 user->SendText(checkstr + " meta:" + item->key + " " + value);
45 else if (!item->key.empty())
46 dumpkeys << " " << item->key;
48 if (!dumpkeys.str().empty())
49 user->SendText(checkstr + " metadata", dumpkeys);
52 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
54 if (parameters.size() > 1 && parameters[1] != ServerInstance->Config->ServerName.c_str())
60 std::string chliststr;
62 checkstr = std::string(":") + ServerInstance->Config->ServerName + " 304 " + std::string(user->nick) + " :CHECK";
64 targuser = ServerInstance->FindNick(parameters[0]);
65 targchan = ServerInstance->FindChan(parameters[0]);
68 * Syntax of a /check reply:
69 * :server.name 304 target :CHECK START <target>
70 * :server.name 304 target :CHECK <field> <value>
71 * :server.name 304 target :CHECK END
74 user->SendText(checkstr + " START " + parameters[0]);
78 /* /check on a user */
79 user->SendText(checkstr + " nuh " + targuser->GetFullHost());
80 user->SendText(checkstr + " realnuh " + targuser->GetFullRealHost());
81 user->SendText(checkstr + " realname " + targuser->fullname);
82 user->SendText(checkstr + " modes +" + targuser->FormatModes());
83 user->SendText(checkstr + " snomasks +" + targuser->FormatNoticeMasks());
84 user->SendText(checkstr + " server " + targuser->server);
85 user->SendText(checkstr + " uid " + targuser->uuid);
86 user->SendText(checkstr + " signon " + timestring(targuser->signon));
87 user->SendText(checkstr + " nickts " + timestring(targuser->age));
88 if (IS_LOCAL(targuser))
89 user->SendText(checkstr + " lastmsg " + timestring(targuser->idle_lastmsg));
91 if (IS_AWAY(targuser))
94 user->SendText(checkstr + " awaytime " + timestring(targuser->awaytime));
95 user->SendText(checkstr + " awaymsg " + targuser->awaymsg);
98 if (IS_OPER(targuser))
100 /* user is an oper of type ____ */
101 user->SendText(checkstr + " opertype " + targuser->oper->NameStr());
104 LocalUser* loctarg = IS_LOCAL(targuser);
107 user->SendText(checkstr + " clientaddr " + irc::sockets::satouser(loctarg->client_sa));
108 user->SendText(checkstr + " serveraddr " + irc::sockets::satouser(loctarg->server_sa));
110 std::string classname = loctarg->GetClass()->name;
111 if (!classname.empty())
112 user->SendText(checkstr + " connectclass " + classname);
115 user->SendText(checkstr + " onip " + targuser->GetIPString());
117 for (UCListIter i = targuser->chans.begin(); i != targuser->chans.end(); i++)
120 chliststr.append(c->GetPrefixChar(targuser)).append(c->name).append(" ");
123 std::stringstream dump(chliststr);
125 user->SendText(checkstr + " onchans", dump);
127 dumpExt(user, checkstr, targuser);
131 /* /check on a channel */
132 user->SendText(checkstr + " timestamp " + timestring(targchan->age));
134 if (targchan->topic[0] != 0)
136 /* there is a topic, assume topic related information exists */
137 user->SendText(checkstr + " topic " + targchan->topic);
138 user->SendText(checkstr + " topic_setby " + targchan->setby);
139 user->SendText(checkstr + " topic_setat " + timestring(targchan->topicset));
142 user->SendText(checkstr + " modes " + targchan->ChanModes(true));
143 user->SendText(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
145 /* now the ugly bit, spool current members of a channel. :| */
147 const UserMembList *ulist= targchan->GetUsers();
149 /* note that unlike /names, we do NOT check +i vs in the channel */
150 for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
154 * Unlike Asuka, I define a clone as coming from the same host. --w00t
156 snprintf(tmpbuf, MAXBUF, "%-3lu %s%s (%s@%s) %s ", ServerInstance->Users->GlobalCloneCount(i->first), targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(), i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str());
157 user->SendText(checkstr + " member " + tmpbuf);
160 dumpExt(user, checkstr, targchan);
164 /* /check on an IP address, or something that doesn't exist */
167 /* hostname or other */
168 for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++)
170 if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map))
172 /* host or vhost matches mask */
173 user->SendText(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
176 else if (InspIRCd::MatchCIDR(a->second->GetIPString(), parameters[0]))
179 user->SendText(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
183 user->SendText(checkstr + " matches " + ConvToStr(x));
186 user->SendText(checkstr + " END " + parameters[0]);
191 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
193 if (parameters.size() > 1)
194 return ROUTE_OPT_UCAST(parameters[1]);
195 return ROUTE_LOCALONLY;
200 class ModuleCheck : public Module
203 CommandCheck mycommand;
205 ModuleCheck() : mycommand(this)
207 ServerInstance->AddCommand(&mycommand);
216 return Version("CHECK command, view user/channel details", VF_VENDOR|VF_OPTCOMMON);
220 MODULE_INIT(ModuleCheck)