]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
Some more text fixes and improvements (#1618).
[user/henk/code/inspircd.git] / src / modules / m_securelist.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23 #include "modules/account.h"
24
25 typedef std::vector<std::string> AllowList;
26
27 class ModuleSecureList : public Module
28 {
29         AllowList allowlist;
30         bool exemptregistered;
31         unsigned int WaitTime;
32
33  public:
34         Version GetVersion() CXX11_OVERRIDE
35         {
36                 return Version("Disallows the LIST command for recently connected clients to hinder spam bots", VF_VENDOR);
37         }
38
39         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
40         {
41                 AllowList newallows;
42
43                 ConfigTagList tags = ServerInstance->Config->ConfTags("securehost");
44                 for (ConfigIter i = tags.first; i != tags.second; ++i)
45                 {
46                         std::string host = i->second->getString("exception");
47                         if (host.empty())
48                                 throw ModuleException("<securehost:exception> is a required field at " + i->second->getTagLocation());
49                         newallows.push_back(host);
50                 }
51
52                 ConfigTag* tag = ServerInstance->Config->ConfValue("securelist");
53
54                 exemptregistered = tag->getBool("exemptregistered");
55                 WaitTime = tag->getDuration("waittime", 60, 1);
56                 allowlist.swap(newallows);
57         }
58
59
60         /*
61          * OnPreCommand()
62          *   Intercept the LIST command.
63          */
64         ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE
65         {
66                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
67                 if (!validated)
68                         return MOD_RES_PASSTHRU;
69
70                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!user->IsOper()))
71                 {
72                         /* Normally wouldnt be allowed here, are they exempt? */
73                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
74                                 if (InspIRCd::Match(user->MakeHost(), *x, ascii_case_insensitive_map))
75                                         return MOD_RES_PASSTHRU;
76
77                         const AccountExtItem* ext = GetAccountExtItem();
78                         if (exemptregistered && ext && ext->get(user))
79                                 return MOD_RES_PASSTHRU;
80
81                         /* Not exempt, BOOK EM DANNO! */
82                         user->WriteNotice("*** You cannot list within the first " + ConvToStr(WaitTime) + " seconds of connecting. Please try again later.");
83                         /* Some clients (e.g. mIRC, various java chat applets) muck up if they don't
84                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
85                          */
86                         user->WriteNumeric(RPL_LISTSTART, "Channel", "Users Name");
87                         user->WriteNumeric(RPL_LISTEND, "End of channel list.");
88                         return MOD_RES_DENY;
89                 }
90                 return MOD_RES_PASSTHRU;
91         }
92
93         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
94         {
95                 tokens["SECURELIST"];
96         }
97 };
98
99 MODULE_INIT(ModuleSecureList)