]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_securelist.cpp
Merge insp20
[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
24 class ModuleSecureList : public Module
25 {
26         std::vector<std::string> allowlist;
27         time_t WaitTime;
28
29  public:
30         Version GetVersion() CXX11_OVERRIDE
31         {
32                 return Version("Disallows /LIST for recently connected clients to hinder spam bots", VF_VENDOR);
33         }
34
35         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
36         {
37                 allowlist.clear();
38
39                 ConfigTagList tags = ServerInstance->Config->ConfTags("securehost");
40                 for (ConfigIter i = tags.first; i != tags.second; ++i)
41                         allowlist.push_back(i->second->getString("exception"));
42
43                 WaitTime = ServerInstance->Config->ConfValue("securelist")->getInt("waittime", 60);
44         }
45
46
47         /*
48          * OnPreCommand()
49          *   Intercept the LIST command.
50          */
51         ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
52         {
53                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
54                 if (!validated)
55                         return MOD_RES_PASSTHRU;
56
57                 if ((command == "LIST") && (ServerInstance->Time() < (user->signon+WaitTime)) && (!user->IsOper()))
58                 {
59                         /* Normally wouldnt be allowed here, are they exempt? */
60                         for (std::vector<std::string>::iterator x = allowlist.begin(); x != allowlist.end(); x++)
61                                 if (InspIRCd::Match(user->MakeHost(), *x, ascii_case_insensitive_map))
62                                         return MOD_RES_PASSTHRU;
63
64                         /* Not exempt, BOOK EM DANNO! */
65                         user->WriteNotice("*** You cannot list within the first " + ConvToStr(WaitTime) + " seconds of connecting. Please try again later.");
66                         /* Some clients (e.g. mIRC, various java chat applets) muck up if they don't
67                          * receive these numerics whenever they send LIST, so give them an empty LIST to mull over.
68                          */
69                         user->WriteNumeric(RPL_LISTSTART, "Channel", "Users Name");
70                         user->WriteNumeric(RPL_LISTEND, "End of channel list.");
71                         return MOD_RES_DENY;
72                 }
73                 return MOD_RES_PASSTHRU;
74         }
75
76         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
77         {
78                 tokens["SECURELIST"];
79         }
80 };
81
82 MODULE_INIT(ModuleSecureList)