2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2014 Adam <Adam@anope.org>
6 * Copyright (C) 2013, 2015, 2017-2018 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012-2016 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
9 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2008 Geoff Bricker <geoff.bricker@gmail.com>
12 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
15 * This file is part of InspIRCd. InspIRCd is free software: you can
16 * redistribute it and/or modify it under the terms of the GNU General Public
17 * License as published by the Free Software Foundation, version 2.
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include "modules/stats.h"
31 #include "modules/who.h"
32 #include "modules/whois.h"
34 /** Handles user mode +H
36 class HideOper : public SimpleUserModeHandler
41 HideOper(Module* Creator) : SimpleUserModeHandler(Creator, "hideoper", 'H')
47 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
49 if (SimpleUserModeHandler::OnModeChange(source, dest, channel, parameter, adding) == MODEACTION_DENY)
50 return MODEACTION_DENY;
57 return MODEACTION_ALLOW;
63 , public Stats::EventListener
64 , public Who::EventListener
65 , public Whois::LineEventListener
73 : Stats::EventListener(this)
74 , Who::EventListener(this)
75 , Whois::LineEventListener(this)
81 Version GetVersion() CXX11_OVERRIDE
83 return Version("Adds user mode H (hideoper) which hides the server operator status of a user from unprivileged users.", VF_VENDOR);
86 void OnUserQuit(User* user, const std::string&, const std::string&) CXX11_OVERRIDE
88 if (user->IsModeSet(hm))
92 ModResult OnNumeric(User* user, const Numeric::Numeric& numeric) CXX11_OVERRIDE
94 if (numeric.GetNumeric() != RPL_LUSEROP || active || user->HasPrivPermission("users/auspex"))
95 return MOD_RES_PASSTHRU;
97 // If there are no visible operators then we shouldn't send the numeric.
98 size_t opercount = ServerInstance->Users->all_opers.size() - hm.opercount;
102 user->WriteNumeric(RPL_LUSEROP, opercount, "operator(s) online");
108 ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
110 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
111 * person doing the WHOIS is not an oper
113 if (numeric.GetNumeric() != 313)
114 return MOD_RES_PASSTHRU;
116 if (!whois.GetTarget()->IsModeSet(hm))
117 return MOD_RES_PASSTHRU;
119 if (!whois.GetSource()->HasPrivPermission("users/auspex"))
122 return MOD_RES_PASSTHRU;
125 ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE
127 if (user->IsModeSet(hm) && !source->HasPrivPermission("users/auspex"))
129 // Hide the line completely if doing a "/who * o" query
130 if (request.flags['o'])
134 if (!request.GetFieldIndex('f', flag_index))
135 return MOD_RES_PASSTHRU;
137 // hide the "*" that marks the user as an oper from the /WHO line
138 // #chan ident localhost insp22.test nick H@ :0 Attila
139 if (numeric.GetParams().size() <= flag_index)
140 return MOD_RES_PASSTHRU;
142 std::string& param = numeric.GetParams()[flag_index];
143 const std::string::size_type pos = param.find('*');
144 if (pos != std::string::npos)
147 return MOD_RES_PASSTHRU;
150 ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
152 if (stats.GetSymbol() != 'P')
153 return MOD_RES_PASSTHRU;
155 unsigned int count = 0;
156 const UserManager::OperList& opers = ServerInstance->Users->all_opers;
157 for (UserManager::OperList::const_iterator i = opers.begin(); i != opers.end(); ++i)
160 if (!oper->server->IsULine() && (stats.GetSource()->IsOper() || !oper->IsModeSet(hm)))
162 LocalUser* lu = IS_LOCAL(oper);
163 const std::string idle = lu ? InspIRCd::DurationString(ServerInstance->Time() - lu->idle_lastmsg) : "unavailable";
164 stats.AddRow(249, InspIRCd::Format("%s (%s@%s) Idle: %s", oper->nick.c_str(),
165 oper->ident.c_str(), oper->GetDisplayedHost().c_str(), idle.c_str()));
169 stats.AddRow(249, ConvToStr(count)+" OPER(s)");
175 MODULE_INIT(ModuleHideOper)