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 std::set<std::string> meta_seen;
24 CommandCheck (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"CHECK", "o", 1)
26 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
29 std::string timestring(time_t time)
32 struct tm *mytime = gmtime(&time);
33 strftime(timebuf, 59, "%Y-%m-%d %H:%M:%S UTC (%s)", mytime);
34 return std::string(timebuf);
37 void dumpExtra(User* user, std::string checkstr, Extensible* ext)
39 std::deque<std::string> extlist;
40 ext->GetExtList(extlist);
41 std::stringstream dumpkeys;
42 for(std::deque<std::string>::iterator i = extlist.begin(); i != extlist.end(); i++)
44 if (meta_seen.find(*i) == meta_seen.end())
45 dumpkeys << " " << *i;
48 if (!dumpkeys.str().empty())
49 ServerInstance->DumpText(user,checkstr + " metadata ", dumpkeys);
52 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
57 std::string chliststr;
59 checkstr = "304 " + std::string(user->nick) + " :CHECK";
61 targuser = ServerInstance->FindNick(parameters[0]);
62 targchan = ServerInstance->FindChan(parameters[0]);
65 * Syntax of a /check reply:
66 * :server.name 304 target :CHECK START <target>
67 * :server.name 304 target :CHECK <field> <value>
68 * :server.name 304 target :CHECK END
71 user->WriteServ(checkstr + " START " + parameters[0]);
75 /* /check on a user */
76 user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
77 user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
78 user->WriteServ(checkstr + " realname " + targuser->fullname);
79 user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
80 user->WriteServ(checkstr + " snomasks +" + targuser->FormatNoticeMasks());
81 user->WriteServ(checkstr + " server " + targuser->server);
82 user->WriteServ(checkstr + " uid " + targuser->uuid);
83 user->WriteServ(checkstr + " signon " + timestring(targuser->signon));
84 user->WriteServ(checkstr + " nickts " + timestring(targuser->age));
85 if (IS_LOCAL(targuser))
86 user->WriteServ(checkstr + " lastmsg " + timestring(targuser->idle_lastmsg));
88 if (IS_AWAY(targuser))
91 user->WriteServ(checkstr + " awaytime " + timestring(targuser->awaytime));
92 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
95 if (IS_OPER(targuser))
97 /* user is an oper of type ____ */
98 user->WriteServ(checkstr + " opertype " + irc::Spacify(targuser->oper.c_str()));
101 if (IS_LOCAL(targuser))
103 user->WriteServ(checkstr + " clientaddr " + irc::sockets::satouser(&targuser->client_sa));
104 user->WriteServ(checkstr + " serveraddr " + irc::sockets::satouser(&targuser->server_sa));
106 std::string classname = targuser->GetClass()->name;
107 if (!classname.empty())
108 user->WriteServ(checkstr + " connectclass " + classname);
111 user->WriteServ(checkstr + " onip " + targuser->GetIPString());
113 chliststr = targuser->ChannelList(targuser);
114 std::stringstream dump(chliststr);
116 ServerInstance->DumpText(user,checkstr + " onchans ", dump);
118 FOREACH_MOD_I(ServerInstance,I_OnSyncUser,OnSyncUser(targuser,creator,(void*)user));
119 dumpExtra(user, checkstr, targuser);
123 /* /check on a channel */
124 user->WriteServ(checkstr + " timestamp " + timestring(targchan->age));
126 if (targchan->topic[0] != 0)
128 /* there is a topic, assume topic related information exists */
129 user->WriteServ(checkstr + " topic " + targchan->topic);
130 user->WriteServ(checkstr + " topic_setby " + targchan->setby);
131 user->WriteServ(checkstr + " topic_setat " + timestring(targchan->topicset));
134 user->WriteServ(checkstr + " modes " + targchan->ChanModes(true));
135 user->WriteServ(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
137 /* now the ugly bit, spool current members of a channel. :| */
139 CUList *ulist= targchan->GetUsers();
141 /* note that unlike /names, we do NOT check +i vs in the channel */
142 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
146 * Unlike Asuka, I define a clone as coming from the same host. --w00t
148 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());
149 user->WriteServ(checkstr + " member " + tmpbuf);
152 FOREACH_MOD_I(ServerInstance,I_OnSyncChannel,OnSyncChannel(targchan,creator,(void*)user));
153 dumpExtra(user, checkstr, targchan);
157 /* /check on an IP address, or something that doesn't exist */
160 /* hostname or other */
161 for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++)
163 if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map))
165 /* host or vhost matches mask */
166 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
169 else if (InspIRCd::MatchCIDR(a->second->GetIPString(), parameters[0]))
172 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
176 user->WriteServ(checkstr + " matches " + ConvToStr(x));
179 user->WriteServ(checkstr + " END " + parameters[0]);
181 return CMD_LOCALONLY;
186 class ModuleCheck : public Module
189 CommandCheck mycommand;
191 ModuleCheck(InspIRCd* Me) : Module(Me), mycommand(Me, this)
193 ServerInstance->AddCommand(&mycommand);
196 virtual ~ModuleCheck()
200 virtual Version GetVersion()
202 return Version("$Id$", VF_VENDOR, API_VERSION);
205 virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string& name, const std::string& value)
207 User* user = static_cast<User*>(opaque);
208 user->WriteServ("304 " + std::string(user->nick) + " :CHECK meta:" + name + " " + value);
209 mycommand.meta_seen.insert(name);
212 virtual std::string ProtoTranslate(Extensible* item)
214 User* u = dynamic_cast<User*>(item);
215 Channel* c = dynamic_cast<Channel*>(item);
224 MODULE_INIT(ModuleCheck)