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