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
25 CommandCheck (InspIRCd* Instance, Module* parent) : Command(Instance,"CHECK", "o", 1), Parent(parent)
27 this->source = "m_check.so";
28 syntax = "<nickname>|<ip>|<hostmask>|<channel>";
31 std::string timestring(time_t time)
34 struct tm *mytime = gmtime(&time);
35 strftime(timebuf, 59, "%Y-%m-%d %H:%M:%S UTC (%s)", mytime);
36 return std::string(timebuf);
39 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
44 std::string chliststr;
46 checkstr = "304 " + std::string(user->nick) + " :CHECK";
48 targuser = ServerInstance->FindNick(parameters[0]);
49 targchan = ServerInstance->FindChan(parameters[0]);
52 * Syntax of a /check reply:
53 * :server.name 304 target :CHECK START <target>
54 * :server.name 304 target :CHECK <field> <value>
55 * :server.name 304 target :CHECK END
58 user->WriteServ(checkstr + " START " + parameters[0]);
62 /* /check on a user */
63 user->WriteServ(checkstr + " nuh " + targuser->GetFullHost());
64 user->WriteServ(checkstr + " realnuh " + targuser->GetFullRealHost());
65 user->WriteServ(checkstr + " realname " + targuser->fullname);
66 user->WriteServ(checkstr + " modes +" + targuser->FormatModes());
67 user->WriteServ(checkstr + " snomasks +" + targuser->FormatNoticeMasks());
68 user->WriteServ(checkstr + " server " + targuser->server);
69 user->WriteServ(checkstr + " uid " + targuser->uuid);
70 user->WriteServ(checkstr + " signon " + timestring(targuser->signon));
71 user->WriteServ(checkstr + " nickts " + timestring(targuser->age));
72 if (IS_LOCAL(targuser))
73 user->WriteServ(checkstr + " lastmsg " + timestring(targuser->idle_lastmsg));
75 if (IS_AWAY(targuser))
78 user->WriteServ(checkstr + " awaytime " + timestring(targuser->awaytime));
79 user->WriteServ(checkstr + " awaymsg " + targuser->awaymsg);
82 if (IS_OPER(targuser))
84 /* user is an oper of type ____ */
85 user->WriteServ(checkstr + " opertype " + irc::Spacify(targuser->oper.c_str()));
88 user->WriteServ(checkstr + " onip " + targuser->GetIPString());
89 if (IS_LOCAL(targuser))
91 user->WriteServ(checkstr + " onport " + ConvToStr(targuser->GetServerPort()));
92 std::string classname = targuser->GetClass()->name;
93 if (!classname.empty())
94 user->WriteServ(checkstr + " connectclass " + classname);
97 chliststr = targuser->ChannelList(targuser);
98 std::stringstream dump(chliststr);
100 ServerInstance->DumpText(user,checkstr + " onchans ", dump);
102 FOREACH_MOD_I(ServerInstance,I_OnSyncUser,OnSyncUser(targuser,Parent,(void*)user));
106 /* /check on a channel */
107 user->WriteServ(checkstr + " timestamp " + timestring(targchan->age));
109 if (targchan->topic[0] != 0)
111 /* there is a topic, assume topic related information exists */
112 user->WriteServ(checkstr + " topic " + targchan->topic);
113 user->WriteServ(checkstr + " topic_setby " + targchan->setby);
114 user->WriteServ(checkstr + " topic_setat " + timestring(targchan->topicset));
117 user->WriteServ(checkstr + " modes " + targchan->ChanModes(true));
118 user->WriteServ(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
120 /* now the ugly bit, spool current members of a channel. :| */
122 CUList *ulist= targchan->GetUsers();
124 /* note that unlike /names, we do NOT check +i vs in the channel */
125 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
129 * Unlike Asuka, I define a clone as coming from the same host. --w00t
131 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());
132 user->WriteServ(checkstr + " member " + tmpbuf);
135 FOREACH_MOD_I(ServerInstance,I_OnSyncChannel,OnSyncChannel(targchan,Parent,(void*)user));
139 /* /check on an IP address, or something that doesn't exist */
142 /* hostname or other */
143 for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++)
145 if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map))
147 /* host or vhost matches mask */
148 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
151 else if (InspIRCd::MatchCIDR(a->second->GetIPString(), parameters[0]))
154 user->WriteServ(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
158 user->WriteServ(checkstr + " matches " + ConvToStr(x));
161 user->WriteServ(checkstr + " END " + parameters[0]);
163 return CMD_LOCALONLY;
168 class ModuleCheck : public Module
171 CommandCheck mycommand;
173 ModuleCheck(InspIRCd* Me) : Module(Me), mycommand(Me, this)
175 ServerInstance->AddCommand(&mycommand);
178 virtual ~ModuleCheck()
182 virtual Version GetVersion()
184 return Version("$Id$", VF_VENDOR, API_VERSION);
187 virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string& name, const std::string& value)
189 User* user = static_cast<User*>(opaque);
190 user->WriteServ("304 " + std::string(user->nick) + " :CHECK meta:" + name + " " + value);
191 mycommand.md_sent = true;
194 virtual std::string ProtoTranslate(Extensible* item)
196 User* u = dynamic_cast<User*>(item);
197 Channel* c = dynamic_cast<Channel*>(item);
206 MODULE_INIT(ModuleCheck)