2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2005 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/>.
25 class ModuleDenyChannels : public Module
27 ChanModeReference redirectmode;
31 : redirectmode(this, "redirect")
35 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
37 /* check for redirect validity and loops/chains */
38 ConfigTagList tags = ServerInstance->Config->ConfTags("badchan");
39 for (ConfigIter i = tags.first; i != tags.second; ++i)
41 std::string name = i->second->getString("name");
42 std::string redirect = i->second->getString("redirect");
44 if (!redirect.empty())
47 if (!ServerInstance->IsChannel(redirect))
50 status.srcuser->WriteNotice("Invalid badchan redirect '" + redirect + "'");
51 throw ModuleException("Invalid badchan redirect, not a channel");
54 for (ConfigIter j = tags.first; j != tags.second; ++j)
56 if (InspIRCd::Match(redirect, j->second->getString("name")))
58 bool goodchan = false;
59 ConfigTagList goodchans = ServerInstance->Config->ConfTags("goodchan");
60 for (ConfigIter k = goodchans.first; k != goodchans.second; ++k)
62 if (InspIRCd::Match(redirect, k->second->getString("name")))
68 /* <badchan:redirect> is a badchan */
70 status.srcuser->WriteNotice("Badchan " + name + " redirects to badchan " + redirect);
71 throw ModuleException("Badchan redirect loop");
79 Version GetVersion() CXX11_OVERRIDE
81 return Version("Implements config tags which allow blocking of joins to channels", VF_VENDOR);
85 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
87 ConfigTagList tags = ServerInstance->Config->ConfTags("badchan");
88 for (ConfigIter j = tags.first; j != tags.second; ++j)
90 if (InspIRCd::Match(cname, j->second->getString("name")))
92 if (user->IsOper() && j->second->getBool("allowopers"))
94 return MOD_RES_PASSTHRU;
98 std::string reason = j->second->getString("reason");
99 std::string redirect = j->second->getString("redirect");
101 ConfigTagList goodchans = ServerInstance->Config->ConfTags("goodchan");
102 for (ConfigIter i = goodchans.first; i != goodchans.second; ++i)
104 if (InspIRCd::Match(cname, i->second->getString("name")))
106 return MOD_RES_PASSTHRU;
110 if (ServerInstance->IsChannel(redirect))
112 /* simple way to avoid potential loops: don't redirect to +L channels */
113 Channel *newchan = ServerInstance->FindChan(redirect);
114 if ((!newchan) || (!newchan->IsModeSet(redirectmode)))
116 user->WriteNumeric(926, "%s :Channel %s is forbidden, redirecting to %s: %s", cname.c_str(),cname.c_str(),redirect.c_str(), reason.c_str());
117 Channel::JoinUser(user, redirect);
122 user->WriteNumeric(926, "%s :Channel %s is forbidden: %s", cname.c_str(),cname.c_str(),reason.c_str());
127 return MOD_RES_PASSTHRU;
131 MODULE_INIT(ModuleDenyChannels)