X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_check.cpp;h=714f0bddd86b073575231226c417396d1d20577d;hb=HEAD;hp=ddac033c1088ce65916aef450f3ce56238088509;hpb=f0debf907a36846e3b48767e9797880135a4583b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index ddac033c1..714f0bddd 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -1,10 +1,15 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2020 Matt Schatz + * Copyright (C) 2013-2016 Attila Molnar + * Copyright (C) 2013, 2017-2021 Sadie Powell + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2010 Craig Edwards * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2007 Dennis Friis - * Copyright (C) 2006-2007 Robin Burchell - * Copyright (C) 2006 Craig Edwards + * Copyright (C) 2006-2008 Robin Burchell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -30,9 +35,18 @@ enum class CheckContext { + private: User* const user; const std::string& target; + std::string FormatTime(time_t ts) + { + std::string timestr(InspIRCd::TimeString(ts, "%Y-%m-%d %H:%M:%S UTC (", true)); + timestr.append(ConvToStr(ts)); + timestr.push_back(')'); + return timestr; + } + public: CheckContext(User* u, const std::string& targetstr) : user(u) @@ -51,18 +65,28 @@ class CheckContext user->WriteRemoteNumeric(RPL_CHECK, type, text); } + void Write(const std::string& type, time_t ts) + { + user->WriteRemoteNumeric(RPL_CHECK, type, FormatTime(ts)); + } + User* GetUser() const { return user; } - void DumpListMode(const ListModeBase::ModeList* list) + void DumpListMode(ListModeBase* mode, Channel* chan) { + const ListModeBase::ModeList* list = mode->GetList(chan); if (!list) return; - CheckContext::List modelist(*this, "modelist"); for (ListModeBase::ModeList::const_iterator i = list->begin(); i != list->end(); ++i) - modelist.Add(i->mask); - - modelist.Flush(); + { + CheckContext::List listmode(*this, "listmode"); + listmode.Add(ConvToStr(mode->GetModeChar())); + listmode.Add(i->mask); + listmode.Add(i->setter); + listmode.Add(FormatTime(i->time)); + listmode.Flush(); + } } void DumpExt(Extensible* ext) @@ -71,7 +95,7 @@ class CheckContext for(Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); ++i) { ExtensionItem* item = i->first; - std::string value = item->serialize(FORMAT_USER, ext, i->second); + std::string value = item->ToHuman(ext, i->second); if (!value.empty()) Write("meta:" + item->name, value); else if (!item->name.empty()) @@ -109,32 +133,44 @@ class CommandCheck : public Command return ret; } - public: - CommandCheck(Module* parent) - : Command(parent,"CHECK", 1) - , snomaskmode(parent, "snomask") + static std::string GetAllowedOperOnlyModes(LocalUser* user, ModeType modetype) { - flags_needed = 'o'; syntax = "||| "; + std::string ret; + const ModeParser::ModeHandlerMap& modes = ServerInstance->Modes.GetModes(modetype); + for (ModeParser::ModeHandlerMap::const_iterator i = modes.begin(); i != modes.end(); ++i) + { + const ModeHandler* const mh = i->second; + if ((mh->NeedsOper()) && (user->HasModePermission(mh))) + ret.push_back(mh->GetModeChar()); + } + return ret; } - std::string timestring(time_t time) + static std::string GetAllowedOperOnlySnomasks(LocalUser* user) { - char timebuf[60]; - struct tm *mytime = gmtime(&time); - strftime(timebuf, 59, "%Y-%m-%d %H:%M:%S UTC (", mytime); - std::string ret(timebuf); - ret.append(ConvToStr(time)).push_back(')'); + std::string ret; + for (unsigned char sno = 'A'; sno <= 'z'; ++sno) + if (ServerInstance->SNO->IsSnomaskUsable(sno) && user->HasSnomaskPermission(sno)) + ret.push_back(sno); return ret; } - CmdResult Handle (const std::vector ¶meters, User *user) + public: + CommandCheck(Module* parent) + : Command(parent,"CHECK", 1) + , snomaskmode(parent, "snomask") + { + flags_needed = 'o'; + syntax = "||| []"; + } + + CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE { - if (parameters.size() > 1 && parameters[1] != ServerInstance->Config->ServerName) + if (parameters.size() > 1 && !irc::equals(parameters[1], ServerInstance->Config->ServerName)) return CMD_SUCCESS; User *targuser; Channel *targchan; - std::string chliststr; targuser = ServerInstance->FindNick(parameters[0]); targchan = ServerInstance->FindChan(parameters[0]); @@ -155,20 +191,20 @@ class CommandCheck : public Command /* /check on a user */ context.Write("nuh", targuser->GetFullHost()); context.Write("realnuh", targuser->GetFullRealHost()); - context.Write("realname", targuser->fullname); - context.Write("modes", std::string("+") + targuser->FormatModes()); + context.Write("realname", targuser->GetRealName()); + context.Write("modes", targuser->GetModeLetters()); context.Write("snomasks", GetSnomasks(targuser)); context.Write("server", targuser->server->GetName()); context.Write("uid", targuser->uuid); - context.Write("signon", timestring(targuser->signon)); - context.Write("nickts", timestring(targuser->age)); + context.Write("signon", targuser->signon); + context.Write("nickts", targuser->age); if (loctarg) - context.Write("lastmsg", timestring(loctarg->idle_lastmsg)); + context.Write("lastmsg", loctarg->idle_lastmsg); if (targuser->IsAway()) { /* user is away */ - context.Write("awaytime", timestring(targuser->awaytime)); + context.Write("awaytime", targuser->awaytime); context.Write("awaymsg", targuser->awaymsg); } @@ -179,27 +215,11 @@ class CommandCheck : public Command context.Write("opertype", oper->name); if (loctarg) { - std::string umodes; - std::string cmodes; - for(char c='A'; c <= 'z'; c++) - { - ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_USER); - if (mh && mh->NeedsOper() && loctarg->HasModePermission(mh)) - umodes.push_back(c); - mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL); - if (mh && mh->NeedsOper() && loctarg->HasModePermission(mh)) - cmodes.push_back(c); - } - context.Write("modeperms", "user=" + umodes + " channel=" + cmodes); - - CheckContext::List opcmdlist(context, "commandperms"); - for (OperInfo::PrivSet::const_iterator i = oper->AllowedOperCommands.begin(); i != oper->AllowedOperCommands.end(); ++i) - opcmdlist.Add(*i); - opcmdlist.Flush(); - CheckContext::List privlist(context, "permissions"); - for (OperInfo::PrivSet::const_iterator i = oper->AllowedPrivs.begin(); i != oper->AllowedPrivs.end(); ++i) - privlist.Add(*i); - privlist.Flush(); + context.Write("chanmodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_CHANNEL)); + context.Write("usermodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_USER)); + context.Write("snomaskperms", GetAllowedOperOnlySnomasks(loctarg)); + context.Write("commandperms", oper->AllowedOperCommands.ToString()); + context.Write("permissions", oper->AllowedPrivs.ToString()); } } @@ -211,6 +231,8 @@ class CommandCheck : public Command std::string classname = loctarg->GetClass()->name; if (!classname.empty()) context.Write("connectclass", classname); + + context.Write("exempt", loctarg->exempt ? "yes" : "no"); } else context.Write("onip", targuser->GetIPString()); @@ -219,13 +241,7 @@ class CommandCheck : public Command for (User::ChanList::iterator i = targuser->chans.begin(); i != targuser->chans.end(); i++) { Membership* memb = *i; - Channel* c = memb->chan; - char prefix = memb->GetPrefixChar(); - if (prefix) - chliststr.push_back(prefix); - chliststr.append(c->name); - chanlist.Add(chliststr); - chliststr.clear(); + chanlist.Add(memb->GetAllPrefixChars() + memb->chan->name); } chanlist.Flush(); @@ -235,14 +251,14 @@ class CommandCheck : public Command else if (targchan) { /* /check on a channel */ - context.Write("timestamp", timestring(targchan->age)); + context.Write("createdat", targchan->age); if (!targchan->topic.empty()) { /* there is a topic, assume topic related information exists */ context.Write("topic", targchan->topic); context.Write("topic_setby", targchan->setby); - context.Write("topic_setat", timestring(targchan->topicset)); + context.Write("topic_setat", targchan->topicset); } context.Write("modes", targchan->ChanModes(true)); @@ -256,17 +272,17 @@ class CommandCheck : public Command for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i) { /* - * Unlike Asuka, I define a clone as coming from the same host. --w00t - */ + * Unlike Asuka, I define a clone as coming from the same host. --w00t + */ const UserManager::CloneCounts& clonecount = ServerInstance->Users->GetCloneCounts(i->first); - context.Write("member", InspIRCd::Format("%-3u %s%s (%s@%s) %s ", clonecount.global, - i->second->GetAllPrefixChars(), i->first->nick.c_str(), - i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str())); + context.Write("member", InspIRCd::Format("%u %s%s (%s)", clonecount.global, + i->second->GetAllPrefixChars().c_str(), i->first->GetFullHost().c_str(), + i->first->GetRealName().c_str())); } const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes(); for (ModeParser::ListModeList::const_iterator i = listmodes.begin(); i != listmodes.end(); ++i) - context.DumpListMode((*i)->GetList(targchan)); + context.DumpListMode(*i, targchan); context.DumpExt(targchan); } @@ -279,16 +295,16 @@ class CommandCheck : public Command const user_hash& users = ServerInstance->Users->GetUsers(); for (user_hash::const_iterator a = users.begin(); a != users.end(); ++a) { - if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map)) + if (InspIRCd::Match(a->second->GetRealHost(), parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->GetDisplayedHost(), parameters[0], ascii_case_insensitive_map)) { /* host or vhost matches mask */ - context.Write("match", ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->fullname); + context.Write("match", ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->GetRealName()); } /* IP address */ else if (InspIRCd::MatchCIDR(a->second->GetIPString(), parameters[0])) { /* same IP. */ - context.Write("match", ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->fullname); + context.Write("match", ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->GetRealName()); } } @@ -299,7 +315,7 @@ class CommandCheck : public Command return CMD_SUCCESS; } - RouteDescriptor GetRouting(User* user, const std::vector& parameters) + RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE { if ((parameters.size() > 1) && (parameters[1].find('.') != std::string::npos)) return ROUTE_OPT_UCAST(parameters[1]); @@ -317,7 +333,7 @@ class ModuleCheck : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("CHECK command, view user, channel, IP address or hostname information", VF_VENDOR|VF_OPTCOMMON); + return Version("Adds the /CHECK command which allows server operators to look up details about a channel, user, IP address, or hostname.", VF_VENDOR|VF_OPTCOMMON); } };