2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2006-2007 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class CommandCheck : public Command
30 ChanModeReference ban;
31 UserModeReference snomaskmode;
33 std::string GetSnomasks(User* user)
37 ret = snomaskmode->GetUserParameter(user);
45 CommandCheck(Module* parent)
46 : Command(parent,"CHECK", 1)
48 , snomaskmode(parent, "snomask")
50 flags_needed = 'o'; syntax = "<nickname>|<ip>|<hostmask>|<channel> <server>";
53 std::string timestring(time_t time)
56 struct tm *mytime = gmtime(&time);
57 strftime(timebuf, 59, "%Y-%m-%d %H:%M:%S UTC (%s)", mytime);
58 return std::string(timebuf);
61 void dumpExt(User* user, const std::string& checkstr, Extensible* ext)
63 std::stringstream dumpkeys;
64 for(Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); i++)
66 ExtensionItem* item = i->first;
67 std::string value = item->serialize(FORMAT_USER, ext, i->second);
69 user->SendText(checkstr + " meta:" + item->name + " " + value);
70 else if (!item->name.empty())
71 dumpkeys << " " << item->name;
73 if (!dumpkeys.str().empty())
74 user->SendText(checkstr + " metadata", dumpkeys);
77 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
79 if (parameters.size() > 1 && parameters[1] != ServerInstance->Config->ServerName.c_str())
85 std::string chliststr;
87 checkstr = ":" + ServerInstance->Config->ServerName + " 304 " + user->nick + " :CHECK";
89 targuser = ServerInstance->FindNick(parameters[0]);
90 targchan = ServerInstance->FindChan(parameters[0]);
93 * Syntax of a /check reply:
94 * :server.name 304 target :CHECK START <target>
95 * :server.name 304 target :CHECK <field> <value>
96 * :server.name 304 target :CHECK END
99 user->SendText(checkstr + " START " + parameters[0]);
103 LocalUser* loctarg = IS_LOCAL(targuser);
104 /* /check on a user */
105 user->SendText(checkstr + " nuh " + targuser->GetFullHost());
106 user->SendText(checkstr + " realnuh " + targuser->GetFullRealHost());
107 user->SendText(checkstr + " realname " + targuser->fullname);
108 user->SendText(checkstr + " modes +" + targuser->FormatModes());
109 user->SendText(checkstr + " snomasks " + GetSnomasks(targuser));
110 user->SendText(checkstr + " server " + targuser->server);
111 user->SendText(checkstr + " uid " + targuser->uuid);
112 user->SendText(checkstr + " signon " + timestring(targuser->signon));
113 user->SendText(checkstr + " nickts " + timestring(targuser->age));
115 user->SendText(checkstr + " lastmsg " + timestring(loctarg->idle_lastmsg));
117 if (targuser->IsAway())
120 user->SendText(checkstr + " awaytime " + timestring(targuser->awaytime));
121 user->SendText(checkstr + " awaymsg " + targuser->awaymsg);
124 if (targuser->IsOper())
126 OperInfo* oper = targuser->oper;
127 /* user is an oper of type ____ */
128 user->SendText(checkstr + " opertype " + oper->name);
133 for(char c='A'; c < 'z'; c++)
135 ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_USER);
136 if (mh && mh->NeedsOper() && loctarg->HasModePermission(c, MODETYPE_USER))
138 mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL);
139 if (mh && mh->NeedsOper() && loctarg->HasModePermission(c, MODETYPE_CHANNEL))
142 user->SendText(checkstr + " modeperms user=" + umodes + " channel=" + cmodes);
144 for(std::set<std::string>::iterator i = oper->AllowedOperCommands.begin(); i != oper->AllowedOperCommands.end(); i++)
146 opcmds.push_back(' ');
149 std::stringstream opcmddump(opcmds);
150 user->SendText(checkstr + " commandperms", opcmddump);
152 for(std::set<std::string>::iterator i = oper->AllowedPrivs.begin(); i != oper->AllowedPrivs.end(); i++)
154 privs.push_back(' ');
157 std::stringstream privdump(privs);
158 user->SendText(checkstr + " permissions", privdump);
164 user->SendText(checkstr + " clientaddr " + irc::sockets::satouser(loctarg->client_sa));
165 user->SendText(checkstr + " serveraddr " + irc::sockets::satouser(loctarg->server_sa));
167 std::string classname = loctarg->GetClass()->name;
168 if (!classname.empty())
169 user->SendText(checkstr + " connectclass " + classname);
172 user->SendText(checkstr + " onip " + targuser->GetIPString());
174 for (UCListIter i = targuser->chans.begin(); i != targuser->chans.end(); i++)
177 chliststr.append(c->GetPrefixChar(targuser)).append(c->name).append(" ");
180 std::stringstream dump(chliststr);
182 user->SendText(checkstr + " onchans", dump);
184 dumpExt(user, checkstr, targuser);
188 /* /check on a channel */
189 user->SendText(checkstr + " timestamp " + timestring(targchan->age));
191 if (targchan->topic[0] != 0)
193 /* there is a topic, assume topic related information exists */
194 user->SendText(checkstr + " topic " + targchan->topic);
195 user->SendText(checkstr + " topic_setby " + targchan->setby);
196 user->SendText(checkstr + " topic_setat " + timestring(targchan->topicset));
199 user->SendText(checkstr + " modes " + targchan->ChanModes(true));
200 user->SendText(checkstr + " membercount " + ConvToStr(targchan->GetUserCounter()));
202 /* now the ugly bit, spool current members of a channel. :| */
204 const UserMembList *ulist= targchan->GetUsers();
206 /* note that unlike /names, we do NOT check +i vs in the channel */
207 for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
210 * Unlike Asuka, I define a clone as coming from the same host. --w00t
212 user->SendText("%s member %-3lu %s%s (%s@%s) %s ",
213 checkstr.c_str(), ServerInstance->Users->GlobalCloneCount(i->first),
214 targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(),
215 i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str());
218 // We know that the mode handler for bans is in the core and is derived from ListModeBase
219 ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
220 banlm->DoSyncChannel(targchan, creator, user);
222 // Show other listmodes as well
223 FOREACH_MOD(OnSyncChannel, (targchan,creator,user));
224 dumpExt(user, checkstr, targchan);
228 /* /check on an IP address, or something that doesn't exist */
231 /* hostname or other */
232 for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++)
234 if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map))
236 /* host or vhost matches mask */
237 user->SendText(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->fullname);
240 else if (InspIRCd::MatchCIDR(a->second->GetIPString(), parameters[0]))
243 user->SendText(checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->fullname);
247 user->SendText(checkstr + " matches " + ConvToStr(x));
250 user->SendText(checkstr + " END " + parameters[0]);
255 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
257 if (parameters.size() > 1)
258 return ROUTE_OPT_UCAST(parameters[1]);
259 return ROUTE_LOCALONLY;
263 class ModuleCheck : public Module
265 CommandCheck mycommand;
267 ModuleCheck() : mycommand(this)
271 void init() CXX11_OVERRIDE
273 ServerInstance->Modules->AddService(mycommand);
276 void ProtoSendMode(void* uv, TargetTypeFlags, void*, const std::vector<std::string>& result, const std::vector<TranslateType>&)
278 User* user = (User*)uv;
279 std::string checkstr(":");
280 checkstr.append(ServerInstance->Config->ServerName);
281 checkstr.append(" 304 ");
282 checkstr.append(user->nick);
283 checkstr.append(" :CHECK modelist");
284 for(unsigned int i=0; i < result.size(); i++)
286 checkstr.append(" ");
287 checkstr.append(result[i]);
289 user->SendText(checkstr);
292 Version GetVersion() CXX11_OVERRIDE
294 return Version("CHECK command, view user, channel, IP address or hostname information", VF_VENDOR|VF_OPTCOMMON);
298 MODULE_INIT(ModuleCheck)